1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
|
/*
* Copyright (C) 2010 Robert Ancell.
* Author: Robert Ancell <robert.ancell@canonical.com>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2 or version 3 of the License.
* See http://www.gnu.org/copyleft/lgpl.html the full text of the license.
*/
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <gio/gunixsocketaddress.h>
#include <security/pam_appl.h>
#include "lightdm/greeter.h"
/**
* SECTION:greeter
* @short_description: Make a connection to the LightDM daemon and authenticate users
* @include: lightdm.h
*
* #LightDMGreeter is an object that manages the connection to the LightDM server and provides common greeter functionality.
*
* An example of a simple greeter:
* |[
* int main ()
* {
* GMainLoop *main_loop;
* LightDMGreeter *greeter
*
* main_loop = g_main_loop_new ();
*
* greeter = lightdm_greeter_new ();
* g_object_connect (greeter, "show-prompt", G_CALLBACK (show_prompt_cb), NULL);
* g_object_connect (greeter, "authentication-complete", G_CALLBACK (authentication_complete_cb), NULL);
*
* // Connect to LightDM daemon
* if (!lightdm_greeter_connect_to_daemon_sync (greeter, NULL))
* return EXIT_FAILURE;
*
* // Start authentication
* lightdm_greeter_authenticate (greeter, NULL);
*
* g_main_loop_run (main_loop);
*
* return EXIT_SUCCESS;
* }
*
* static void show_prompt_cb (LightDMGreeter *greeter, const char *text, LightDMPromptType type)
* {
* // Show the user the message and prompt for some response
* gchar *secret = prompt_user (text, type);
*
* // Give the result to the user
* lightdm_greeter_respond (greeter, response);
* }
*
* static void authentication_complete_cb (LightDMGreeter *greeter)
* {
* // Start the session
* if (!lightdm_greeter_get_is_authenticated (greeter) ||
* !lightdm_greeter_start_session_sync (greeter, NULL))
* {
* // Failed authentication, try again
* lightdm_greeter_authenticate (greeter, NULL);
* }
* }
* ]|
*/
/**
* LightDMGreeter:
*
* #LightDMGreeter is an opaque data structure and can only be accessed
* using the provided functions.
*/
/**
* LightDMGreeterClass:
*
* Class structure for #LightDMGreeter.
*/
G_DEFINE_QUARK (lightdm_greeter_error, lightdm_greeter_error)
enum {
PROP_DEFAULT_SESSION_HINT = 1,
PROP_HIDE_USERS_HINT,
PROP_SHOW_MANUAL_LOGIN_HINT,
PROP_SHOW_REMOTE_LOGIN_HINT,
PROP_LOCK_HINT,
PROP_HAS_GUEST_ACCOUNT_HINT,
PROP_SELECT_USER_HINT,
PROP_SELECT_GUEST_HINT,
PROP_AUTOLOGIN_USER_HINT,
PROP_AUTOLOGIN_GUEST_HINT,
PROP_AUTOLOGIN_TIMEOUT_HINT,
PROP_AUTHENTICATION_USER,
PROP_IN_AUTHENTICATION,
PROP_IS_AUTHENTICATED,
PROP_AUTOLOGIN_SESSION_HINT,
};
enum {
SHOW_PROMPT,
SHOW_MESSAGE,
AUTHENTICATION_COMPLETE,
AUTOLOGIN_TIMER_EXPIRED,
IDLE,
RESET,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
typedef struct
{
/* API version the daemon is using */
guint32 api_version;
/* TRUE if the daemon can reuse this greeter */
gboolean resettable;
/* Socket connection to daemon */
GSocket *socket;
/* Channel to write to daemon */
GIOChannel *to_server_channel;
/* Channel to read from daemon */
GIOChannel *from_server_channel;
guint from_server_watch;
/* Data read from the daemon */
guint8 *read_buffer;
gsize n_read;
gsize n_responses_waiting;
GList *responses_received;
/* TRUE if have got a connect response */
gboolean connected;
/* Pending connect requests */
GList *connect_requests;
/* Pending start session requests */
GList *start_session_requests;
/* Pending ensure shared data dir requests */
GList *ensure_shared_data_dir_requests;
/* Hints provided by the daemon */
GHashTable *hints;
/* Timeout source to notify greeter to autologin */
guint autologin_timeout;
gchar *authentication_user;
gboolean in_authentication;
gboolean is_authenticated;
guint32 authenticate_sequence_number;
gboolean cancelling_authentication;
} LightDMGreeterPrivate;
G_DEFINE_TYPE (LightDMGreeter, lightdm_greeter, G_TYPE_OBJECT)
#define GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE ((obj), LIGHTDM_TYPE_GREETER, LightDMGreeterPrivate)
#define HEADER_SIZE 8
#define MAX_MESSAGE_LENGTH 1024
#define API_VERSION 1
/* Messages from the greeter to the server */
typedef enum
{
GREETER_MESSAGE_CONNECT = 0,
GREETER_MESSAGE_AUTHENTICATE,
GREETER_MESSAGE_AUTHENTICATE_AS_GUEST,
GREETER_MESSAGE_CONTINUE_AUTHENTICATION,
GREETER_MESSAGE_START_SESSION,
GREETER_MESSAGE_CANCEL_AUTHENTICATION,
GREETER_MESSAGE_SET_LANGUAGE,
GREETER_MESSAGE_AUTHENTICATE_REMOTE,
GREETER_MESSAGE_ENSURE_SHARED_DIR,
} GreeterMessage;
/* Messages from the server to the greeter */
typedef enum
{
SERVER_MESSAGE_CONNECTED = 0,
SERVER_MESSAGE_PROMPT_AUTHENTICATION,
SERVER_MESSAGE_END_AUTHENTICATION,
SERVER_MESSAGE_SESSION_RESULT,
SERVER_MESSAGE_SHARED_DIR_RESULT,
SERVER_MESSAGE_IDLE,
SERVER_MESSAGE_RESET,
SERVER_MESSAGE_CONNECTED_V2,
} ServerMessage;
/* Request sent to server */
typedef struct
{
GObject parent_instance;
LightDMGreeter *greeter;
GCancellable *cancellable;
GAsyncReadyCallback callback;
gpointer user_data;
gboolean complete;
gboolean result;
GError *error;
gchar *dir;
} Request;
typedef struct
{
GObjectClass parent_class;
} RequestClass;
GType request_get_type (void);
static void request_iface_init (GAsyncResultIface *iface);
#define REQUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), request_get_type (), Request))
G_DEFINE_TYPE_WITH_CODE (Request, request, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_RESULT, request_iface_init))
static gboolean from_server_cb (GIOChannel *source, GIOCondition condition, gpointer data);
GType
lightdm_greeter_error_get_type (void)
{
static GType enum_type = 0;
if (G_UNLIKELY(enum_type == 0)) {
static const GEnumValue values[] = {
{ LIGHTDM_GREETER_ERROR_COMMUNICATION_ERROR, "LIGHTDM_GREETER_ERROR_COMMUNICATION_ERROR", "communication-error" },
{ LIGHTDM_GREETER_ERROR_CONNECTION_FAILED, "LIGHTDM_GREETER_ERROR_CONNECTION_FAILED", "connection-failed" },
{ LIGHTDM_GREETER_ERROR_SESSION_FAILED, "LIGHTDM_GREETER_ERROR_SESSION_FAILED", "session-failed" },
{ LIGHTDM_GREETER_ERROR_NO_AUTOLOGIN, "LIGHTDM_GREETER_ERROR_NO_AUTOLOGIN", "no-autologin" },
{ LIGHTDM_GREETER_ERROR_INVALID_USER, "LIGHTDM_GREETER_ERROR_INVALID_USER", "invalid-user" },
{ 0, NULL, NULL }
};
enum_type = g_enum_register_static (g_intern_static_string ("LightDMGreeterError"), values);
}
return enum_type;
}
GType
lightdm_prompt_type_get_type (void)
{
static GType enum_type = 0;
if (G_UNLIKELY(enum_type == 0)) {
static const GEnumValue values[] = {
{ LIGHTDM_PROMPT_TYPE_QUESTION, "LIGHTDM_PROMPT_TYPE_QUESTION", "question" },
{ LIGHTDM_PROMPT_TYPE_SECRET, "LIGHTDM_PROMPT_TYPE_SECRET", "secret" },
{ 0, NULL, NULL }
};
enum_type = g_enum_register_static (g_intern_static_string ("LightDMPromptType"), values);
}
return enum_type;
}
GType
lightdm_message_type_get_type (void)
{
static GType enum_type = 0;
if (G_UNLIKELY(enum_type == 0)) {
static const GEnumValue values[] = {
{ LIGHTDM_MESSAGE_TYPE_INFO, "LIGHTDM_MESSAGE_TYPE_INFO", "info" },
{ LIGHTDM_MESSAGE_TYPE_ERROR, "LIGHTDM_MESSAGE_TYPE_ERROR", "error" },
{ 0, NULL, NULL }
};
enum_type = g_enum_register_static (g_intern_static_string ("LightDMMessageType"), values);
}
return enum_type;
}
/**
* lightdm_greeter_new:
*
* Create a new greeter.
*
* Return value: the new #LightDMGreeter
**/
LightDMGreeter *
lightdm_greeter_new (void)
{
return g_object_new (LIGHTDM_TYPE_GREETER, NULL);
}
/**
* lightdm_greeter_set_resettable:
* @greeter: A #LightDMGreeter
* @resettable: Whether the greeter wants to be reset instead of killed after the user logs in
*
* Set whether the greeter will be reset instead of killed after the user logs in.
* This must be called before lightdm_greeter_connect is called.
**/
void
lightdm_greeter_set_resettable (LightDMGreeter *greeter, gboolean resettable)
{
LightDMGreeterPrivate *priv;
g_return_if_fail (LIGHTDM_IS_GREETER (greeter));
priv = GET_PRIVATE (greeter);
g_return_if_fail (!priv->connected);
priv->resettable = resettable;
}
static Request *
request_new (LightDMGreeter *greeter, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
{
Request *request;
request = g_object_new (request_get_type (), NULL);
request->greeter = greeter;
if (cancellable)
request->cancellable = g_object_ref (cancellable);
request->callback = callback;
request->user_data = user_data;
return request;
}
static gboolean
request_callback_cb (gpointer data)
{
Request *request = data;
if (request->callback)
request->callback (G_OBJECT (request->greeter), G_ASYNC_RESULT (request), request->user_data);
g_object_unref (request);
return G_SOURCE_REMOVE;
}
static void
request_complete (Request *request)
{
request->complete = TRUE;
if (!request->callback)
return;
if (request->cancellable && g_cancellable_is_cancelled (request->cancellable))
return;
g_idle_add (request_callback_cb, g_object_ref (request));
}
static gboolean
timed_login_cb (gpointer data)
{
LightDMGreeter *greeter = data;
LightDMGreeterPrivate *priv = GET_PRIVATE (greeter);
priv->autologin_timeout = 0;
g_signal_emit (G_OBJECT (greeter), signals[AUTOLOGIN_TIMER_EXPIRED], 0);
return FALSE;
}
static guint32
int_length (void)
{
return 4;
}
static gboolean
write_int (guint8 *buffer, gint buffer_length, guint32 value, gsize *offset, GError **error)
{
if (*offset + 4 >= buffer_length)
{
g_set_error_literal (error, LIGHTDM_GREETER_ERROR, LIGHTDM_GREETER_ERROR_COMMUNICATION_ERROR,
"Not enough buffer space to write integer");
return FALSE;
}
buffer[*offset] = value >> 24;
buffer[*offset+1] = (value >> 16) & 0xFF;
buffer[*offset+2] = (value >> 8) & 0xFF;
buffer[*offset+3] = value & 0xFF;
*offset += 4;
return TRUE;
}
static gboolean
write_string (guint8 *buffer, gint buffer_length, const gchar *value, gsize *offset, GError **error)
{
gint length = 0;
if (value)
length = strlen (value);
if (!write_int (buffer, buffer_length, length, offset, error))
return FALSE;
if (*offset + length >= buffer_length)
{
g_set_error (error, LIGHTDM_GREETER_ERROR, LIGHTDM_GREETER_ERROR_COMMUNICATION_ERROR,
"Not enough buffer space to write string of length %d octets", length);
return FALSE;
}
if (value)
memcpy (buffer + *offset, value, length);
*offset += length;
return TRUE;
}
static guint32
read_int (guint8 *message, gsize message_length, gsize *offset)
{
guint32 value;
guint8 *buffer;
if (message_length - *offset < int_length ())
{
g_warning ("Not enough space for int, need %i, got %zi", int_length (), message_length - *offset);
return 0;
}
buffer = message + *offset;
value = buffer[0] << 24 | buffer[1] << 16 | buffer[2] << 8 | buffer[3];
*offset += int_length ();
return value;
}
static gchar *
read_string (guint8 *message, gsize message_length, gsize *offset)
{
guint32 length;
gchar *value;
length = read_int (message, message_length, offset);
if (message_length - *offset < length)
{
g_warning ("Not enough space for string, need %u, got %zu", length, message_length - *offset);
return g_strdup ("");
}
value = g_malloc (sizeof (gchar) * (length + 1));
memcpy (value, message + *offset, length);
value[length] = '\0';
*offset += length;
return value;
}
static guint32
string_length (const gchar *value)
{
if (value)
return int_length () + strlen (value);
else
return int_length ();
}
static gboolean
write_header (guint8 *buffer, gint buffer_length, guint32 id, guint32 length, gsize *offset, GError **error)
{
return write_int (buffer, buffer_length, id, offset, error) &&
write_int (buffer, buffer_length, length, offset, error);
}
static guint32
get_message_length (guint8 *message, gsize message_length)
{
gsize offset = 4;
return read_int (message, message_length, &offset);
}
static gboolean
connect_to_daemon (LightDMGreeter *greeter, GError **error)
{
LightDMGreeterPrivate *priv = GET_PRIVATE (greeter);
const gchar *to_server_fd, *from_server_fd, *pipe_path;
if (priv->to_server_channel || priv->from_server_channel)
return TRUE;
/* Use private connection if one exists */
to_server_fd = g_getenv ("LIGHTDM_TO_SERVER_FD");
from_server_fd = g_getenv ("LIGHTDM_FROM_SERVER_FD");
pipe_path = g_getenv ("LIGHTDM_GREETER_PIPE");
if (to_server_fd && from_server_fd)
{
priv->to_server_channel = g_io_channel_unix_new (atoi (to_server_fd));
priv->from_server_channel = g_io_channel_unix_new (atoi (from_server_fd));
}
else if (pipe_path)
{
GSocketAddress *address;
gboolean result;
priv->socket = g_socket_new (G_SOCKET_FAMILY_UNIX, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, error);
if (!priv->socket)
return FALSE;
address = g_unix_socket_address_new (pipe_path);
result = g_socket_connect (priv->socket, address, NULL, error);
g_object_unref (address);
if (!result)
return FALSE;
priv->from_server_channel = g_io_channel_unix_new (g_socket_get_fd (priv->socket));
priv->to_server_channel = g_io_channel_ref (priv->from_server_channel);
}
else
{
g_set_error_literal (error, LIGHTDM_GREETER_ERROR, LIGHTDM_GREETER_ERROR_CONNECTION_FAILED,
"Unable to determine socket to daemon");
return FALSE;
}
priv->from_server_watch = g_io_add_watch (priv->from_server_channel, G_IO_IN, from_server_cb, greeter);
if (!g_io_channel_set_encoding (priv->to_server_channel, NULL, error) ||
!g_io_channel_set_encoding (priv->from_server_channel, NULL, error))
return FALSE;
return TRUE;
}
static gboolean
send_message (LightDMGreeter *greeter, guint8 *message, gsize message_length, GError **error)
{
LightDMGreeterPrivate *priv = GET_PRIVATE (greeter);
gchar *data;
gsize data_length;
guint32 stated_length;
g_autoptr(GError) flush_error = NULL;
if (!connect_to_daemon (greeter, error))
return FALSE;
/* Double check that we're sending well-formed messages. If we say we're
sending more than we do, we end up DOS'ing lightdm as it waits for the
rest. If we say we're sending less than we do, we confuse the heck out
of lightdm, as it starts reading headers from the middle of our
messages. */
stated_length = HEADER_SIZE + get_message_length (message, message_length);
if (stated_length != message_length)
{
g_set_error (error, LIGHTDM_GREETER_ERROR, LIGHTDM_GREETER_ERROR_COMMUNICATION_ERROR,
"Refusing to write malformed packet to daemon: declared size is %u, but actual size is %zu",
stated_length, message_length);
return FALSE;
}
data = (gchar *) message;
data_length = message_length;
while (data_length > 0)
{
GIOStatus status;
gsize n_written;
g_autoptr(GError) write_error = NULL;
status = g_io_channel_write_chars (priv->to_server_channel, data, data_length, &n_written, &write_error);
if (write_error)
g_set_error (error, LIGHTDM_GREETER_ERROR, LIGHTDM_GREETER_ERROR_COMMUNICATION_ERROR,
"Failed to write to daemon: %s",
write_error->message);
if (status == G_IO_STATUS_AGAIN)
continue;
if (status != G_IO_STATUS_NORMAL)
return FALSE;
data_length -= n_written;
data += n_written;
}
g_debug ("Wrote %zi bytes to daemon", message_length);
if (!g_io_channel_flush (priv->to_server_channel, &flush_error))
{
g_set_error (error, LIGHTDM_GREETER_ERROR, LIGHTDM_GREETER_ERROR_COMMUNICATION_ERROR,
"Failed to write to daemon: %s",
flush_error->message);
return FALSE;
}
return TRUE;
}
static void
handle_connected (LightDMGreeter *greeter, gboolean v2, guint8 *message, gsize message_length, gsize *offset)
{
LightDMGreeterPrivate *priv = GET_PRIVATE (greeter);
g_autoptr(GString) debug_string = NULL;
int timeout;
Request *request;
debug_string = g_string_new ("Connected");
if (v2)
{
guint32 i, n_env;
gchar *version;
priv->api_version = read_int (message, message_length, offset);
g_string_append_printf (debug_string, " api=%u", priv->api_version);
version = read_string (message, message_length, offset);
g_string_append_printf (debug_string, " version=%s", version);
g_free (version);
n_env = read_int (message, message_length, offset);
for (i = 0; i < n_env; i++)
{
gchar *name, *value;
name = read_string (message, message_length, offset);
value = read_string (message, message_length, offset);
g_hash_table_insert (priv->hints, name, value);
g_string_append_printf (debug_string, " %s=%s", name, value);
}
}
else
{
gchar *version;
priv->api_version = 0;
version = read_string (message, message_length, offset);
g_string_append_printf (debug_string, " version=%s", version);
g_free (version);
while (*offset < message_length)
{
gchar *name, *value;
name = read_string (message, message_length, offset);
value = read_string (message, message_length, offset);
g_hash_table_insert (priv->hints, name, value);
g_string_append_printf (debug_string, " %s=%s", name, value);
}
}
priv->connected = TRUE;
g_debug ("%s", debug_string->str);
/* Set timeout for default login */
timeout = lightdm_greeter_get_autologin_timeout_hint (greeter);
if (timeout)
{
g_debug ("Setting autologin timer for %d seconds", timeout);
priv->autologin_timeout = g_timeout_add (timeout * 1000, timed_login_cb, greeter);
}
/* Notify asynchronous caller */
request = g_list_nth_data (priv->connect_requests, 0);
if (request)
{
request->result = TRUE;
request_complete (request);
priv->connect_requests = g_list_remove (priv->connect_requests, request);
g_object_unref (request);
}
}
static void
handle_prompt_authentication (LightDMGreeter *greeter, guint8 *message, gsize message_length, gsize *offset)
{
LightDMGreeterPrivate *priv = GET_PRIVATE (greeter);
guint32 sequence_number, n_messages, i;
gchar *username;
sequence_number = read_int (message, message_length, offset);
if (sequence_number != priv->authenticate_sequence_number)
{
g_debug ("Ignoring prompt authentication with invalid sequence number %d", sequence_number);
return;
}
if (priv->cancelling_authentication)
{
g_debug ("Ignoring prompt authentication as waiting for it to cancel");
return;
}
/* Update username */
username = read_string (message, message_length, offset);
if (strcmp (username, "") == 0)
{
g_free (username);
username = NULL;
}
g_free (priv->authentication_user);
priv->authentication_user = username;
g_list_free_full (priv->responses_received, g_free);
priv->responses_received = NULL;
priv->n_responses_waiting = 0;
n_messages = read_int (message, message_length, offset);
g_debug ("Prompt user with %d message(s)", n_messages);
for (i = 0; i < n_messages; i++)
{
int style;
gchar *text;
style = read_int (message, message_length, offset);
text = read_string (message, message_length, offset);
// FIXME: Should stop on prompts?
switch (style)
{
case PAM_PROMPT_ECHO_OFF:
priv->n_responses_waiting++;
g_signal_emit (G_OBJECT (greeter), signals[SHOW_PROMPT], 0, text, LIGHTDM_PROMPT_TYPE_SECRET);
break;
case PAM_PROMPT_ECHO_ON:
priv->n_responses_waiting++;
g_signal_emit (G_OBJECT (greeter), signals[SHOW_PROMPT], 0, text, LIGHTDM_PROMPT_TYPE_QUESTION);
break;
case PAM_ERROR_MSG:
g_signal_emit (G_OBJECT (greeter), signals[SHOW_MESSAGE], 0, text, LIGHTDM_MESSAGE_TYPE_ERROR);
break;
case PAM_TEXT_INFO:
g_signal_emit (G_OBJECT (greeter), signals[SHOW_MESSAGE], 0, text, LIGHTDM_MESSAGE_TYPE_INFO);
break;
}
g_free (text);
}
}
static void
handle_end_authentication (LightDMGreeter *greeter, guint8 *message, gsize message_length, gsize *offset)
{
LightDMGreeterPrivate *priv = GET_PRIVATE (greeter);
guint32 sequence_number, return_code;
gchar *username;
sequence_number = read_int (message, message_length, offset);
if (sequence_number != priv->authenticate_sequence_number)
{
g_debug ("Ignoring end authentication with invalid sequence number %d", sequence_number);
return;
}
username = read_string (message, message_length, offset);
return_code = read_int (message, message_length, offset);
g_debug ("Authentication complete for user %s with return code %d", username, return_code);
/* Update username */
if (strcmp (username, "") == 0)
{
g_free (username);
username = NULL;
}
g_free (priv->authentication_user);
priv->authentication_user = username;
priv->cancelling_authentication = FALSE;
priv->is_authenticated = (return_code == 0);
priv->in_authentication = FALSE;
g_signal_emit (G_OBJECT (greeter), signals[AUTHENTICATION_COMPLETE], 0);
}
static void
handle_idle (LightDMGreeter *greeter, guint8 *message, gsize message_length, gsize *offset)
{
g_signal_emit (G_OBJECT (greeter), signals[IDLE], 0);
}
static void
handle_reset (LightDMGreeter *greeter, guint8 *message, gsize message_length, gsize *offset)
{
LightDMGreeterPrivate *priv = GET_PRIVATE (greeter);
g_autoptr(GString) hint_string = NULL;
g_hash_table_remove_all (priv->hints);
hint_string = g_string_new ("");
while (*offset < message_length)
{
gchar *name, *value;
name = read_string (message, message_length, offset);
value = read_string (message, message_length, offset);
g_hash_table_insert (priv->hints, name, value);
g_string_append_printf (hint_string, " %s=%s", name, value);
}
g_debug ("Reset%s", hint_string->str);
g_signal_emit (G_OBJECT (greeter), signals[RESET], 0);
}
static void
handle_session_result (LightDMGreeter *greeter, guint8 *message, gsize message_length, gsize *offset)
{
LightDMGreeterPrivate *priv = GET_PRIVATE (greeter);
Request *request;
/* Notify asynchronous caller */
request = g_list_nth_data (priv->start_session_requests, 0);
if (request)
{
guint32 return_code;
return_code = read_int (message, message_length, offset);
if (return_code == 0)
request->result = TRUE;
else
request->error = g_error_new (LIGHTDM_GREETER_ERROR, LIGHTDM_GREETER_ERROR_SESSION_FAILED,
"Session returned error code %d", return_code);
request_complete (request);
priv->start_session_requests = g_list_remove (priv->start_session_requests, request);
g_object_unref (request);
}
}
static void
handle_shared_dir_result (LightDMGreeter *greeter, guint8 *message, gsize message_length, gsize *offset)
{
LightDMGreeterPrivate *priv = GET_PRIVATE (greeter);
Request *request;
/* Notify asynchronous caller */
request = g_list_nth_data (priv->ensure_shared_data_dir_requests, 0);
if (request)
{
request->dir = read_string (message, message_length, offset);
/* Blank data dir means invalid user */
if (g_strcmp0 (request->dir, "") == 0)
{
g_free (request->dir);
request->dir = NULL;
request->error = g_error_new (LIGHTDM_GREETER_ERROR, LIGHTDM_GREETER_ERROR_INVALID_USER,
"No such user");
}
request_complete (request);
priv->ensure_shared_data_dir_requests = g_list_remove (priv->ensure_shared_data_dir_requests, request);
g_object_unref (request);
}
}
static void
handle_message (LightDMGreeter *greeter, guint8 *message, gsize message_length)
{
gsize offset = 0;
guint32 id;
id = read_int (message, message_length, &offset);
read_int (message, message_length, &offset);
switch (id)
{
case SERVER_MESSAGE_CONNECTED:
handle_connected (greeter, FALSE, message, message_length, &offset);
break;
case SERVER_MESSAGE_PROMPT_AUTHENTICATION:
handle_prompt_authentication (greeter, message, message_length, &offset);
break;
case SERVER_MESSAGE_END_AUTHENTICATION:
handle_end_authentication (greeter, message, message_length, &offset);
break;
case SERVER_MESSAGE_SESSION_RESULT:
handle_session_result (greeter, message, message_length, &offset);
break;
case SERVER_MESSAGE_SHARED_DIR_RESULT:
handle_shared_dir_result (greeter, message, message_length, &offset);
break;
case SERVER_MESSAGE_IDLE:
handle_idle (greeter, message, message_length, &offset);
break;
case SERVER_MESSAGE_RESET:
handle_reset (greeter, message, message_length, &offset);
break;
case SERVER_MESSAGE_CONNECTED_V2:
handle_connected (greeter, TRUE, message, message_length, &offset);
break;
default:
g_warning ("Unknown message from server: %d", id);
break;
}
}
static gboolean
recv_message (LightDMGreeter *greeter, gboolean block, guint8 **message, gsize *length, GError **error)
{
LightDMGreeterPrivate *priv = GET_PRIVATE (greeter);
gsize n_to_read, n_read;
if (!connect_to_daemon (greeter, error))
return FALSE;
/* Read the header, or the whole message if we already have that */
n_to_read = HEADER_SIZE;
if (priv->n_read >= HEADER_SIZE)
n_to_read += get_message_length (priv->read_buffer, priv->n_read);
do
{
GIOStatus status;
g_autoptr(GError) read_error = NULL;
status = g_io_channel_read_chars (priv->from_server_channel,
(gchar *) priv->read_buffer + priv->n_read,
n_to_read - priv->n_read,
&n_read,
&read_error);
if (status == G_IO_STATUS_AGAIN)
{
if (block)
continue;
}
else if (status != G_IO_STATUS_NORMAL)
{
g_set_error (error, LIGHTDM_GREETER_ERROR, LIGHTDM_GREETER_ERROR_COMMUNICATION_ERROR,
"Failed to read from daemon: %s",
read_error->message);
return FALSE;
}
g_debug ("Read %zi bytes from daemon", n_read);
priv->n_read += n_read;
} while (priv->n_read < n_to_read && block);
/* Stop if haven't got all the data we want */
if (priv->n_read != n_to_read)
{
if (message)
*message = NULL;
if (length)
*length = 0;
return TRUE;
}
/* If have header, rerun for content */
if (priv->n_read == HEADER_SIZE)
{
n_to_read = get_message_length (priv->read_buffer, priv->n_read);
if (n_to_read > 0)
{
priv->read_buffer = g_realloc (priv->read_buffer, HEADER_SIZE + n_to_read);
return recv_message (greeter, block, message, length, error);
}
}
if (message)
*message = priv->read_buffer;
else
g_free (priv->read_buffer);
if (length)
*length = priv->n_read;
priv->read_buffer = g_malloc (priv->n_read);
priv->n_read = 0;
return TRUE;
}
static gboolean
from_server_cb (GIOChannel *source, GIOCondition condition, gpointer data)
{
LightDMGreeter *greeter = data;
g_autofree guint8 *message = NULL;
gsize message_length;
g_autoptr(GError) error = NULL;
/* Read one message and process it */
if (!recv_message (greeter, FALSE, &message, &message_length, &error))
{
// FIXME: Should push this up to the client somehow
g_warning ("Failed to read from daemon: %s\n", error->message);
return G_SOURCE_REMOVE;
}
if (message)
handle_message (greeter, message, message_length);
return G_SOURCE_CONTINUE;
}
static gboolean
send_connect (LightDMGreeter *greeter, gboolean resettable, GError **error)
{
guint8 message[MAX_MESSAGE_LENGTH];
gsize offset = 0;
g_debug ("Connecting to display manager...");
return write_header (message, MAX_MESSAGE_LENGTH, GREETER_MESSAGE_CONNECT, string_length (VERSION) + int_length () * 2, &offset, error) &&
write_string (message, MAX_MESSAGE_LENGTH, VERSION, &offset, error) &&
write_int (message, MAX_MESSAGE_LENGTH, resettable ? 1 : 0, &offset, error) &&
write_int (message, MAX_MESSAGE_LENGTH, API_VERSION, &offset, error) &&
send_message (greeter, message, offset, error);
}
static gboolean
send_start_session (LightDMGreeter *greeter, const gchar *session, GError **error)
{
guint8 message[MAX_MESSAGE_LENGTH];
gsize offset = 0;
if (session)
g_debug ("Starting session %s", session);
else
g_debug ("Starting default session");
return write_header (message, MAX_MESSAGE_LENGTH, GREETER_MESSAGE_START_SESSION, string_length (session), &offset, error) &&
write_string (message, MAX_MESSAGE_LENGTH, session, &offset, error) &&
send_message (greeter, message, offset, error);
}
static gboolean
send_ensure_shared_data_dir (LightDMGreeter *greeter, const gchar *username, GError **error)
{
guint8 message[MAX_MESSAGE_LENGTH];
gsize offset = 0;
g_debug ("Ensuring data directory for user %s", username);
return write_header (message, MAX_MESSAGE_LENGTH, GREETER_MESSAGE_ENSURE_SHARED_DIR, string_length (username), &offset, error) &&
write_string (message, MAX_MESSAGE_LENGTH, username, &offset, error) &&
send_message (greeter, message, offset, error);
}
/**
* lightdm_greeter_connect_to_daemon:
* @greeter: The greeter to connect
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @callback: (allow-none): A #GAsyncReadyCallback to call when completed or %NULL.
* @user_data: (allow-none): data to pass to the @callback or %NULL.
*
* Asynchronously connects the greeter to the display manager.
*
* When the operation is finished, @callback will be invoked. You can then call lightdm_greeter_connect_to_daemon_finish() to get the result of the operation.
*
* See lightdm_greeter_connect_to_daemon_sync() for the synchronous version.
**/
void
lightdm_greeter_connect_to_daemon (LightDMGreeter *greeter, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
{
LightDMGreeterPrivate *priv;
Request *request;
GError *error = NULL;
g_return_if_fail (LIGHTDM_IS_GREETER (greeter));
priv = GET_PRIVATE (greeter);
request = request_new (greeter, cancellable, callback, user_data);
if (send_connect (greeter, priv->resettable, &error))
priv->connect_requests = g_list_append (priv->connect_requests, request);
else
{
request->error = error;
request_complete (request);
g_object_unref (request);
}
}
/**
* lightdm_greeter_connect_to_daemon_finish:
* @greeter: The greeter the the request was done with
* @result: A #GAsyncResult.
* @error: return location for a #GError, or %NULL
*
* Finishes an operation started with lightdm_greeter_connect_to_daemon().
*
* Return value: #TRUE if successfully connected
**/
gboolean
lightdm_greeter_connect_to_daemon_finish (LightDMGreeter *greeter, GAsyncResult *result, GError **error)
{
Request *request = REQUEST (result);
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
if (request->error)
g_propagate_error (error, request->error);
return request->result;
}
/**
* lightdm_greeter_connect_to_daemon_sync:
* @greeter: The greeter to connect
* @error: return location for a #GError, or %NULL
*
* Connects the greeter to the display manager. Will block until connected.
*
* Return value: #TRUE if successfully connected
**/
gboolean
lightdm_greeter_connect_to_daemon_sync (LightDMGreeter *greeter, GError **error)
{
LightDMGreeterPrivate *priv;
Request *request;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
priv = GET_PRIVATE (greeter);
/* Read until we are connected */
if (!send_connect (greeter, priv->resettable, error))
return FALSE;
request = request_new (greeter, NULL, NULL, NULL);
priv->connect_requests = g_list_append (priv->connect_requests, g_object_ref (request));
do
{
guint8 *message;
gsize message_length;
if (!recv_message (greeter, TRUE, &message, &message_length, error))
return FALSE;
handle_message (greeter, message, message_length);
g_free (message);
} while (!request->complete);
return lightdm_greeter_connect_to_daemon_finish (greeter, G_ASYNC_RESULT (request), error);
}
/**
* lightdm_greeter_connect_sync:
* @greeter: The greeter to connect
* @error: return location for a #GError, or %NULL
*
* Connects the greeter to the display manager. Will block until connected.
*
* Return value: #TRUE if successfully connected
*
* Deprecated: 1.11.1: Use lightdm_greeter_connect_to_daemon_sync() instead
**/
gboolean
lightdm_greeter_connect_sync (LightDMGreeter *greeter, GError **error)
{
return lightdm_greeter_connect_to_daemon_sync (greeter, error);
}
/**
* lightdm_greeter_get_hint:
* @greeter: A #LightDMGreeter
* @name: The hint name to query.
*
* Get a hint.
*
* Return value: (nullable): The value for this hint or #NULL if not set.
**/
const gchar *
lightdm_greeter_get_hint (LightDMGreeter *greeter, const gchar *name)
{
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), NULL);
return g_hash_table_lookup (GET_PRIVATE (greeter)->hints, name);
}
/**
* lightdm_greeter_get_default_session_hint:
* @greeter: A #LightDMGreeter
*
* Get the default session to use.
*
* Return value: The session name
**/
const gchar *
lightdm_greeter_get_default_session_hint (LightDMGreeter *greeter)
{
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), NULL);
return lightdm_greeter_get_hint (greeter, "default-session");
}
/**
* lightdm_greeter_get_hide_users_hint:
* @greeter: A #LightDMGreeter
*
* Check if user accounts should be shown. If this is TRUE then the list of
* accounts should be taken from #LightDMUserList and displayed in the greeter
* for the user to choose from. Note that this list can be empty and it is
* recommended you show a method for the user to enter a username manually.
*
* If this option is shown the greeter should only allow these users to be
* chosen for login unless the manual login hint is set.
*
* Return value: #TRUE if the available users should not be shown.
*/
gboolean
lightdm_greeter_get_hide_users_hint (LightDMGreeter *greeter)
{
const gchar *value;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
value = lightdm_greeter_get_hint (greeter, "hide-users");
return g_strcmp0 (value, "true") == 0;
}
/**
* lightdm_greeter_get_show_manual_login_hint:
* @greeter: A #LightDMGreeter
*
* Check if a manual login option should be shown. If set the GUI
* should provide a way for a username to be entered manually.
* Without this hint a greeter which is showing a user list can
* limit logins to only those users.
*
* Return value: #TRUE if a manual login option should be shown.
*/
gboolean
lightdm_greeter_get_show_manual_login_hint (LightDMGreeter *greeter)
{
const gchar *value;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
value = lightdm_greeter_get_hint (greeter, "show-manual-login");
return g_strcmp0 (value, "true") == 0;
}
/**
* lightdm_greeter_get_show_remote_login_hint:
* @greeter: A #LightDMGreeter
*
* Check if a remote login option should be shown. If set the GUI
* should provide a way for a user to log into a remote desktop server.
*
* Return value: #TRUE if a remote login option should be shown.
*/
gboolean
lightdm_greeter_get_show_remote_login_hint (LightDMGreeter *greeter)
{
const gchar *value;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
value = lightdm_greeter_get_hint (greeter, "show-remote-login");
return g_strcmp0 (value, "true") == 0;
}
/**
* lightdm_greeter_get_lock_hint:
* @greeter: A #LightDMGreeter
*
* Check if the greeter is acting as a lock screen.
*
* Return value: #TRUE if the greeter was triggered by locking the seat.
*/
gboolean
lightdm_greeter_get_lock_hint (LightDMGreeter *greeter)
{
const gchar *value;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
value = lightdm_greeter_get_hint (greeter, "lock-screen");
return g_strcmp0 (value, "true") == 0;
}
/**
* lightdm_greeter_get_has_guest_account_hint:
* @greeter: A #LightDMGreeter
*
* Check if guest sessions are supported.
*
* Return value: #TRUE if guest sessions are supported.
*/
gboolean
lightdm_greeter_get_has_guest_account_hint (LightDMGreeter *greeter)
{
const gchar *value;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
value = lightdm_greeter_get_hint (greeter, "has-guest-account");
return g_strcmp0 (value, "true") == 0;
}
/**
* lightdm_greeter_get_select_user_hint:
* @greeter: A #LightDMGreeter
*
* Get the user to select by default.
*
* Return value: (nullable): A username or %NULL if no particular user should be selected.
*/
const gchar *
lightdm_greeter_get_select_user_hint (LightDMGreeter *greeter)
{
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), NULL);
return lightdm_greeter_get_hint (greeter, "select-user");
}
/**
* lightdm_greeter_get_select_guest_hint:
* @greeter: A #LightDMGreeter
*
* Check if the guest account should be selected by default.
*
* Return value: #TRUE if the guest account should be selected by default.
*/
gboolean
lightdm_greeter_get_select_guest_hint (LightDMGreeter *greeter)
{
const gchar *value;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
value = lightdm_greeter_get_hint (greeter, "select-guest");
return g_strcmp0 (value, "true") == 0;
}
/**
* lightdm_greeter_get_autologin_user_hint:
* @greeter: A #LightDMGreeter
*
* Get the user account to automatically log into when the timer expires.
*
* Return value: (nullable): The user account to automatically log into or %NULL if none configured.
*/
const gchar *
lightdm_greeter_get_autologin_user_hint (LightDMGreeter *greeter)
{
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), NULL);
return lightdm_greeter_get_hint (greeter, "autologin-user");
}
/**
* lightdm_greeter_get_autologin_session_hint:
* @greeter: A #LightDMGreeter
*
* Get the session used to automatically log into when the timer expires.
*
* Return value: (nullable): The session name or %NULL if configured to use the default.
*/
const gchar *
lightdm_greeter_get_autologin_session_hint (LightDMGreeter *greeter)
{
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), NULL);
return lightdm_greeter_get_hint (greeter, "autologin-session");
}
/**
* lightdm_greeter_get_autologin_guest_hint:
* @greeter: A #LightDMGreeter
*
* Check if the guest account should be automatically logged into when the timer expires.
*
* Return value: #TRUE if the guest account should be automatically logged into.
*/
gboolean
lightdm_greeter_get_autologin_guest_hint (LightDMGreeter *greeter)
{
const gchar *value;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
value = lightdm_greeter_get_hint (greeter, "autologin-guest");
return g_strcmp0 (value, "true") == 0;
}
/**
* lightdm_greeter_get_autologin_timeout_hint:
* @greeter: A #LightDMGreeter
*
* Get the number of seconds to wait before automatically logging in.
*
* Return value: The number of seconds to wait before automatically logging in or 0 for no timeout.
*/
gint
lightdm_greeter_get_autologin_timeout_hint (LightDMGreeter *greeter)
{
const gchar *value;
gint timeout = 0;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
value = lightdm_greeter_get_hint (greeter, "autologin-timeout");
if (value)
timeout = atoi (value);
if (timeout < 0)
timeout = 0;
return timeout;
}
/**
* lightdm_greeter_cancel_autologin:
* @greeter: A #LightDMGreeter
*
* Cancel the automatic login.
*/
void
lightdm_greeter_cancel_autologin (LightDMGreeter *greeter)
{
LightDMGreeterPrivate *priv;
g_return_if_fail (LIGHTDM_IS_GREETER (greeter));
priv = GET_PRIVATE (greeter);
if (priv->autologin_timeout)
g_source_remove (priv->autologin_timeout);
priv->autologin_timeout = 0;
}
/**
* lightdm_greeter_authenticate:
* @greeter: A #LightDMGreeter
* @username: (allow-none): A username or #NULL to prompt for a username.
* @error: return location for a #GError, or %NULL
*
* Starts the authentication procedure for a user.
*
* Return value: #TRUE if authentication request sent.
**/
gboolean
lightdm_greeter_authenticate (LightDMGreeter *greeter, const gchar *username, GError **error)
{
LightDMGreeterPrivate *priv;
guint8 message[MAX_MESSAGE_LENGTH];
gsize offset = 0;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
priv = GET_PRIVATE (greeter);
g_return_val_if_fail (priv->connected, FALSE);
priv->cancelling_authentication = FALSE;
priv->authenticate_sequence_number++;
priv->in_authentication = TRUE;
priv->is_authenticated = FALSE;
if (username != priv->authentication_user)
{
g_free (priv->authentication_user);
priv->authentication_user = g_strdup (username);
}
g_debug ("Starting authentication for user %s...", username);
return write_header (message, MAX_MESSAGE_LENGTH, GREETER_MESSAGE_AUTHENTICATE, int_length () + string_length (username), &offset, error) &&
write_int (message, MAX_MESSAGE_LENGTH, priv->authenticate_sequence_number, &offset, error) &&
write_string (message, MAX_MESSAGE_LENGTH, username, &offset, error) &&
send_message (greeter, message, offset, error);
}
/**
* lightdm_greeter_authenticate_as_guest:
* @greeter: A #LightDMGreeter
* @error: return location for a #GError, or %NULL
*
* Starts the authentication procedure for the guest user.
*
* Return value: #TRUE if authentication request sent.
**/
gboolean
lightdm_greeter_authenticate_as_guest (LightDMGreeter *greeter, GError **error)
{
LightDMGreeterPrivate *priv;
guint8 message[MAX_MESSAGE_LENGTH];
gsize offset = 0;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
priv = GET_PRIVATE (greeter);
g_return_val_if_fail (priv->connected, FALSE);
priv->cancelling_authentication = FALSE;
priv->authenticate_sequence_number++;
priv->in_authentication = TRUE;
priv->is_authenticated = FALSE;
g_free (priv->authentication_user);
priv->authentication_user = NULL;
g_debug ("Starting authentication for guest account...");
return write_header (message, MAX_MESSAGE_LENGTH, GREETER_MESSAGE_AUTHENTICATE_AS_GUEST, int_length (), &offset, error) &&
write_int (message, MAX_MESSAGE_LENGTH, priv->authenticate_sequence_number, &offset, error) &&
send_message (greeter, message, offset, error);
}
/**
* lightdm_greeter_authenticate_autologin:
* @greeter: A #LightDMGreeter
* @error: return location for a #GError, or %NULL
*
* Starts the authentication procedure for the automatic login user.
*
* Return value: #TRUE if authentication request sent.
**/
gboolean
lightdm_greeter_authenticate_autologin (LightDMGreeter *greeter, GError **error)
{
const gchar *user;
user = lightdm_greeter_get_autologin_user_hint (greeter);
if (lightdm_greeter_get_autologin_guest_hint (greeter))
return lightdm_greeter_authenticate_as_guest (greeter, error);
else if (user)
return lightdm_greeter_authenticate (greeter, user, error);
else
{
g_set_error_literal (error, LIGHTDM_GREETER_ERROR, LIGHTDM_GREETER_ERROR_NO_AUTOLOGIN,
"Can't authenticate autologin; autologin not configured");
return FALSE;
}
}
/**
* lightdm_greeter_authenticate_remote:
* @greeter: A #LightDMGreeter
* @session: The name of a remote session
* @username: (allow-none): A username of #NULL to prompt for a username.
* @error: return location for a #GError, or %NULL
*
* Start authentication for a remote session type.
*
* Return value: #TRUE if authentication request sent.
**/
gboolean
lightdm_greeter_authenticate_remote (LightDMGreeter *greeter, const gchar *session, const gchar *username, GError **error)
{
LightDMGreeterPrivate *priv;
guint8 message[MAX_MESSAGE_LENGTH];
gsize offset = 0;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
priv = GET_PRIVATE (greeter);
g_return_val_if_fail (priv->connected, FALSE);
priv->cancelling_authentication = FALSE;
priv->authenticate_sequence_number++;
priv->in_authentication = TRUE;
priv->is_authenticated = FALSE;
g_free (priv->authentication_user);
priv->authentication_user = NULL;
if (username)
g_debug ("Starting authentication for remote session %s as user %s...", session, username);
else
g_debug ("Starting authentication for remote session %s...", session);
return write_header (message, MAX_MESSAGE_LENGTH, GREETER_MESSAGE_AUTHENTICATE_REMOTE, int_length () + string_length (session) + string_length (username), &offset, error) &&
write_int (message, MAX_MESSAGE_LENGTH, priv->authenticate_sequence_number, &offset, error) &&
write_string (message, MAX_MESSAGE_LENGTH, session, &offset, error) &&
write_string (message, MAX_MESSAGE_LENGTH, username, &offset, error) &&
send_message (greeter, message, offset, error);
}
/**
* lightdm_greeter_respond:
* @greeter: A #LightDMGreeter
* @response: Response to a prompt
* @error: return location for a #GError, or %NULL
*
* Provide response to a prompt. May be one in a series.
*
* Return value: #TRUE if response sent.
**/
gboolean
lightdm_greeter_respond (LightDMGreeter *greeter, const gchar *response, GError **error)
{
LightDMGreeterPrivate *priv;
guint8 message[MAX_MESSAGE_LENGTH];
gsize offset = 0;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
g_return_val_if_fail (response != NULL, FALSE);
priv = GET_PRIVATE (greeter);
g_return_val_if_fail (priv->connected, FALSE);
g_return_val_if_fail (priv->n_responses_waiting > 0, FALSE);
priv->n_responses_waiting--;
priv->responses_received = g_list_append (priv->responses_received, g_strdup (response));
if (priv->n_responses_waiting == 0)
{
guint32 msg_length;
GList *iter;
g_debug ("Providing response to display manager");
msg_length = int_length ();
for (iter = priv->responses_received; iter; iter = iter->next)
msg_length += string_length ((gchar *)iter->data);
if (!write_header (message, MAX_MESSAGE_LENGTH, GREETER_MESSAGE_CONTINUE_AUTHENTICATION, msg_length, &offset, error) ||
!write_int (message, MAX_MESSAGE_LENGTH, g_list_length (priv->responses_received), &offset, error))
return FALSE;
for (iter = priv->responses_received; iter; iter = iter->next)
{
if (!write_string (message, MAX_MESSAGE_LENGTH, (gchar *)iter->data, &offset, error))
return FALSE;
}
if (!send_message (greeter, message, offset, error))
return FALSE;
g_list_free_full (priv->responses_received, g_free);
priv->responses_received = NULL;
}
return TRUE;
}
/**
* lightdm_greeter_cancel_authentication:
* @greeter: A #LightDMGreeter
* @error: return location for a #GError, or %NULL
*
* Cancel the current user authentication.
*
* Return value: #TRUE if cancel request sent.
**/
gboolean
lightdm_greeter_cancel_authentication (LightDMGreeter *greeter, GError **error)
{
LightDMGreeterPrivate *priv;
guint8 message[MAX_MESSAGE_LENGTH];
gsize offset = 0;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
priv = GET_PRIVATE (greeter);
g_return_val_if_fail (priv->connected, FALSE);
priv->cancelling_authentication = TRUE;
return write_header (message, MAX_MESSAGE_LENGTH, GREETER_MESSAGE_CANCEL_AUTHENTICATION, 0, &offset, error) &&
send_message (greeter, message, offset, error);
}
/**
* lightdm_greeter_get_in_authentication:
* @greeter: A #LightDMGreeter
*
* Checks if the greeter is in the process of authenticating.
*
* Return value: #TRUE if the greeter is authenticating a user.
**/
gboolean
lightdm_greeter_get_in_authentication (LightDMGreeter *greeter)
{
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
return GET_PRIVATE (greeter)->in_authentication;
}
/**
* lightdm_greeter_get_is_authenticated:
* @greeter: A #LightDMGreeter
*
* Checks if the greeter has successfully authenticated.
*
* Return value: #TRUE if the greeter is authenticated for login.
**/
gboolean
lightdm_greeter_get_is_authenticated (LightDMGreeter *greeter)
{
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
return GET_PRIVATE (greeter)->is_authenticated;
}
/**
* lightdm_greeter_get_authentication_user:
* @greeter: A #LightDMGreeter
*
* Get the user that is being authenticated.
*
* Return value: (nullable): The username of the authentication user being authenticated or #NULL if no authentication in progress.
*/
const gchar *
lightdm_greeter_get_authentication_user (LightDMGreeter *greeter)
{
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), NULL);
return GET_PRIVATE (greeter)->authentication_user;
}
/**
* lightdm_greeter_set_language:
* @greeter: A #LightDMGreeter
* @language: The language to use for this user in the form of a locale specification (e.g. "de_DE.UTF-8").
* @error: return location for a #GError, or %NULL
*
* Set the language for the currently authenticated user.
*
* Return value: #TRUE if set language request sent.
**/
gboolean
lightdm_greeter_set_language (LightDMGreeter *greeter, const gchar *language, GError **error)
{
LightDMGreeterPrivate *priv;
guint8 message[MAX_MESSAGE_LENGTH];
gsize offset = 0;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
priv = GET_PRIVATE (greeter);
g_return_val_if_fail (priv->connected, FALSE);
return write_header (message, MAX_MESSAGE_LENGTH, GREETER_MESSAGE_SET_LANGUAGE, string_length (language), &offset, error) &&
write_string (message, MAX_MESSAGE_LENGTH, language, &offset, error) &&
send_message (greeter, message, offset, error);
}
/**
* lightdm_greeter_start_session:
* @greeter: A #LightDMGreeter
* @session: (allow-none): The session to log into or #NULL to use the default.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @callback: (allow-none): A #GAsyncReadyCallback to call when completed or %NULL.
* @user_data: (allow-none): data to pass to the @callback or %NULL.
*
* Asynchronously start a session for the authenticated user.
*
* When the operation is finished, @callback will be invoked. You can then call lightdm_greeter_start_session_finish() to get the result of the operation.
*
* See lightdm_greeter_start_session_sync() for the synchronous version.
**/
void
lightdm_greeter_start_session (LightDMGreeter *greeter, const gchar *session, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
{
LightDMGreeterPrivate *priv;
Request *request;
GError *error = NULL;
g_return_if_fail (LIGHTDM_IS_GREETER (greeter));
priv = GET_PRIVATE (greeter);
request = request_new (greeter, cancellable, callback, user_data);
priv->start_session_requests = g_list_append (priv->start_session_requests, request);
if (!send_start_session (greeter, session, &error))
{
request->error = error;
request_complete (request);
}
}
/**
* lightdm_greeter_start_session_finish:
* @greeter: A #LightDMGreeter
* @result: A #GAsyncResult.
* @error: return location for a #GError, or %NULL
*
* Start a session for the authenticated user.
*
* Return value: TRUE if the session was started.
**/
gboolean
lightdm_greeter_start_session_finish (LightDMGreeter *greeter, GAsyncResult *result, GError **error)
{
Request *request = REQUEST (result);
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
if (request->error)
g_propagate_error (error, request->error);
return request->result;
}
/**
* lightdm_greeter_start_session_sync:
* @greeter: A #LightDMGreeter
* @session: (allow-none): The session to log into or #NULL to use the default.
* @error: return location for a #GError, or %NULL
*
* Start a session for the authenticated user.
*
* Return value: TRUE if the session was started.
**/
gboolean
lightdm_greeter_start_session_sync (LightDMGreeter *greeter, const gchar *session, GError **error)
{
LightDMGreeterPrivate *priv;
Request *request;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
priv = GET_PRIVATE (greeter);
g_return_val_if_fail (priv->connected, FALSE);
g_return_val_if_fail (priv->is_authenticated, FALSE);
/* Read until the session is started */
if (!send_start_session (greeter, session, error))
return FALSE;
request = request_new (greeter, NULL, NULL, NULL);
priv->start_session_requests = g_list_append (priv->start_session_requests, g_object_ref (request));
do
{
guint8 *message;
gsize message_length;
if (!recv_message (greeter, TRUE, &message, &message_length, error))
return FALSE;
handle_message (greeter, message, message_length);
g_free (message);
} while (!request->complete);
return lightdm_greeter_start_session_finish (greeter, G_ASYNC_RESULT (request), error);
}
/**
* lightdm_greeter_ensure_shared_data_dir:
* @greeter: A #LightDMGreeter
* @username: A username
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @callback: (allow-none): A #GAsyncReadyCallback to call when completed or %NULL.
* @user_data: (allow-none): data to pass to the @callback or %NULL.
*
* Ensure that a shared data dir for the given user is available. Both the
* greeter user and @username will have write access to that folder. The
* intention is that larger pieces of shared data would be stored there (files
* that the greeter creates but wants to give to a user -- like camera
* photos -- or files that the user creates but wants the greeter to
* see -- like contact avatars).
*
* LightDM will automatically create these if the user actually logs in, so
* greeters only need to call this method if they want to store something in
* the directory themselves.
**/
void
lightdm_greeter_ensure_shared_data_dir (LightDMGreeter *greeter, const gchar *username, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
{
LightDMGreeterPrivate *priv;
Request *request;
GError *error = NULL;
g_return_if_fail (LIGHTDM_IS_GREETER (greeter));
priv = GET_PRIVATE (greeter);
request = request_new (greeter, cancellable, callback, user_data);
priv->ensure_shared_data_dir_requests = g_list_append (priv->ensure_shared_data_dir_requests, request);
if (!send_ensure_shared_data_dir (greeter, username, &error))
{
request->error = error;
request_complete (request);
}
}
/**
* lightdm_greeter_ensure_shared_data_dir_finish:
* @result: A #GAsyncResult.
* @greeter: A #LightDMGreeter
* @error: return location for a #GError, or %NULL
*
* Function to call from lightdm_greeter_ensure_shared_data_dir callback.
*
* Return value: The path to the shared directory, free with g_free.
**/
gchar *
lightdm_greeter_ensure_shared_data_dir_finish (LightDMGreeter *greeter, GAsyncResult *result, GError **error)
{
Request *request = REQUEST (result);
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), NULL);
if (request->error)
g_propagate_error (error, request->error);
return g_strdup (request->dir);
}
/**
* lightdm_greeter_ensure_shared_data_dir_sync:
* @greeter: A #LightDMGreeter
* @username: A username
* @error: return location for a #GError, or %NULL
*
* Ensure that a shared data dir for the given user is available. Both the
* greeter user and @username will have write access to that folder. The
* intention is that larger pieces of shared data would be stored there (files
* that the greeter creates but wants to give to a user -- like camera
* photos -- or files that the user creates but wants the greeter to
* see -- like contact avatars).
*
* LightDM will automatically create these if the user actually logs in, so
* greeters only need to call this method if they want to store something in
* the directory themselves.
*
* Return value: The path to the shared directory, free with g_free.
**/
gchar *
lightdm_greeter_ensure_shared_data_dir_sync (LightDMGreeter *greeter, const gchar *username, GError **error)
{
LightDMGreeterPrivate *priv;
Request *request;
g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), NULL);
priv = GET_PRIVATE (greeter);
g_return_val_if_fail (priv->connected, NULL);
/* Read until a response */
if (!send_ensure_shared_data_dir (greeter, username, error))
return NULL;
request = request_new (greeter, NULL, NULL, NULL);
priv->ensure_shared_data_dir_requests = g_list_append (priv->ensure_shared_data_dir_requests, g_object_ref (request));
do
{
guint8 *message;
gsize message_length;
if (!recv_message (greeter, TRUE, &message, &message_length, error))
return FALSE;
handle_message (greeter, message, message_length);
g_free (message);
} while (!request->complete);
return lightdm_greeter_ensure_shared_data_dir_finish (greeter, G_ASYNC_RESULT (request), error);
}
static void
lightdm_greeter_init (LightDMGreeter *greeter)
{
LightDMGreeterPrivate *priv = GET_PRIVATE (greeter);
priv->read_buffer = g_malloc (HEADER_SIZE);
priv->hints = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
}
static void
lightdm_greeter_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
static void
lightdm_greeter_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
LightDMGreeter *self;
self = LIGHTDM_GREETER (object);
switch (prop_id) {
case PROP_DEFAULT_SESSION_HINT:
g_value_set_string (value, lightdm_greeter_get_default_session_hint (self));
break;
case PROP_HIDE_USERS_HINT:
g_value_set_boolean (value, lightdm_greeter_get_hide_users_hint (self));
break;
case PROP_SHOW_MANUAL_LOGIN_HINT:
g_value_set_boolean (value, lightdm_greeter_get_show_manual_login_hint (self));
break;
case PROP_SHOW_REMOTE_LOGIN_HINT:
g_value_set_boolean (value, lightdm_greeter_get_show_remote_login_hint (self));
break;
case PROP_LOCK_HINT:
g_value_set_boolean (value, lightdm_greeter_get_lock_hint (self));
break;
case PROP_HAS_GUEST_ACCOUNT_HINT:
g_value_set_boolean (value, lightdm_greeter_get_has_guest_account_hint (self));
break;
case PROP_SELECT_USER_HINT:
g_value_set_string (value, lightdm_greeter_get_select_user_hint (self));
break;
case PROP_SELECT_GUEST_HINT:
g_value_set_boolean (value, lightdm_greeter_get_select_guest_hint (self));
break;
case PROP_AUTOLOGIN_USER_HINT:
g_value_set_string (value, lightdm_greeter_get_autologin_user_hint (self));
break;
case PROP_AUTOLOGIN_SESSION_HINT:
g_value_set_string (value, lightdm_greeter_get_autologin_session_hint (self));
break;
case PROP_AUTOLOGIN_GUEST_HINT:
g_value_set_boolean (value, lightdm_greeter_get_autologin_guest_hint (self));
break;
case PROP_AUTOLOGIN_TIMEOUT_HINT:
g_value_set_int (value, lightdm_greeter_get_autologin_timeout_hint (self));
break;
case PROP_AUTHENTICATION_USER:
g_value_set_string (value, lightdm_greeter_get_authentication_user (self));
break;
case PROP_IN_AUTHENTICATION:
g_value_set_boolean (value, lightdm_greeter_get_in_authentication (self));
break;
case PROP_IS_AUTHENTICATED:
g_value_set_boolean (value, lightdm_greeter_get_is_authenticated (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
lightdm_greeter_finalize (GObject *object)
{
LightDMGreeter *self = LIGHTDM_GREETER (object);
LightDMGreeterPrivate *priv = GET_PRIVATE (self);
g_clear_object (&priv->socket);
if (priv->to_server_channel)
g_io_channel_unref (priv->to_server_channel);
if (priv->from_server_channel)
g_io_channel_unref (priv->from_server_channel);
if (priv->from_server_watch)
g_source_remove (priv->from_server_watch);
priv->from_server_watch = 0;
g_clear_pointer (&priv->read_buffer, g_free);
g_list_free_full (priv->responses_received, g_free);
priv->responses_received = NULL;
g_list_free_full (priv->connect_requests, g_object_unref);
priv->connect_requests = NULL;
g_list_free_full (priv->start_session_requests, g_object_unref);
priv->start_session_requests = NULL;
g_list_free_full (priv->ensure_shared_data_dir_requests, g_object_unref);
priv->ensure_shared_data_dir_requests = NULL;
g_clear_pointer (&priv->authentication_user, g_free);
g_hash_table_unref (priv->hints);
priv->hints = NULL;
G_OBJECT_CLASS (lightdm_greeter_parent_class)->finalize (object);
}
static void
lightdm_greeter_class_init (LightDMGreeterClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (LightDMGreeterPrivate));
object_class->set_property = lightdm_greeter_set_property;
object_class->get_property = lightdm_greeter_get_property;
object_class->finalize = lightdm_greeter_finalize;
g_object_class_install_property (object_class,
PROP_DEFAULT_SESSION_HINT,
g_param_spec_string ("default-session-hint",
"default-session-hint",
"Default session hint",
NULL,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_HIDE_USERS_HINT,
g_param_spec_boolean ("hide-users-hint",
"hide-users-hint",
"Hide users hint",
FALSE,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_SHOW_MANUAL_LOGIN_HINT,
g_param_spec_boolean ("show-manual-login-hint",
"show-manual-login-hint",
"Show manual login hint",
FALSE,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_SHOW_REMOTE_LOGIN_HINT,
g_param_spec_boolean ("show-remote-login-hint",
"show-remote-login-hint",
"Show remote login hint",
FALSE,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_LOCK_HINT,
g_param_spec_boolean ("lock-hint",
"lock-hint",
"Lock hint",
FALSE,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_HAS_GUEST_ACCOUNT_HINT,
g_param_spec_boolean ("has-guest-account-hint",
"has-guest-account-hint",
"Has guest account hint",
FALSE,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_SELECT_USER_HINT,
g_param_spec_string ("select-user-hint",
"select-user-hint",
"Select user hint",
NULL,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_SELECT_GUEST_HINT,
g_param_spec_boolean ("select-guest-hint",
"select-guest-hint",
"Select guest account hint",
FALSE,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_AUTOLOGIN_USER_HINT,
g_param_spec_string ("autologin-user-hint",
"autologin-user-hint",
"Autologin user hint",
NULL,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_AUTOLOGIN_SESSION_HINT,
g_param_spec_string ("autologin-session-hint",
"autologin-session-hint",
"Autologin session hint",
NULL,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_AUTOLOGIN_GUEST_HINT,
g_param_spec_boolean ("autologin-guest-hint",
"autologin-guest-hint",
"Autologin guest account hint",
FALSE,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_AUTOLOGIN_TIMEOUT_HINT,
g_param_spec_int ("autologin-timeout-hint",
"autologin-timeout-hint",
"Autologin timeout hint",
0, G_MAXINT, 0,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_AUTHENTICATION_USER,
g_param_spec_string ("authentication-user",
"authentication-user",
"The user being authenticated",
NULL,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_IN_AUTHENTICATION,
g_param_spec_boolean ("in-authentication",
"in-authentication",
"TRUE if a user is being authenticated",
FALSE,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_IS_AUTHENTICATED,
g_param_spec_boolean ("is-authenticated",
"is-authenticated",
"TRUE if the selected user is authenticated",
FALSE,
G_PARAM_READABLE));
/**
* LightDMGreeter::show-prompt:
* @greeter: A #LightDMGreeter
* @text: Prompt text
* @type: Prompt type
*
* The ::show-prompt signal gets emitted when the greeter should show a
* prompt to the user. The given text should be displayed and an input
* field for the user to provide a response.
*
* Call lightdm_greeter_respond() with the resultant input or
* lightdm_greeter_cancel_authentication() to abort the authentication.
**/
signals[SHOW_PROMPT] =
g_signal_new (LIGHTDM_GREETER_SIGNAL_SHOW_PROMPT,
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (LightDMGreeterClass, show_prompt),
NULL, NULL,
NULL,
G_TYPE_NONE, 2, G_TYPE_STRING, lightdm_prompt_type_get_type ());
/**
* LightDMGreeter::show-message:
* @greeter: A #LightDMGreeter
* @text: Message text
* @type: Message type
*
* The ::show-message signal gets emitted when the greeter
* should show a message to the user.
**/
signals[SHOW_MESSAGE] =
g_signal_new (LIGHTDM_GREETER_SIGNAL_SHOW_MESSAGE,
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (LightDMGreeterClass, show_message),
NULL, NULL,
NULL,
G_TYPE_NONE, 2, G_TYPE_STRING, lightdm_message_type_get_type ());
/**
* LightDMGreeter::authentication-complete:
* @greeter: A #LightDMGreeter
*
* The ::authentication-complete signal gets emitted when the greeter
* has completed authentication.
*
* Call lightdm_greeter_get_is_authenticated() to check if the authentication
* was successful.
**/
signals[AUTHENTICATION_COMPLETE] =
g_signal_new (LIGHTDM_GREETER_SIGNAL_AUTHENTICATION_COMPLETE,
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (LightDMGreeterClass, authentication_complete),
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
/**
* LightDMGreeter::autologin-timer-expired:
* @greeter: A #LightDMGreeter
*
* The ::timed-login signal gets emitted when the automatic login timer has expired.
* The application should then call lightdm_greeter_authenticate_autologin().
**/
signals[AUTOLOGIN_TIMER_EXPIRED] =
g_signal_new (LIGHTDM_GREETER_SIGNAL_AUTOLOGIN_TIMER_EXPIRED,
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (LightDMGreeterClass, autologin_timer_expired),
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
/**
* LightDMGreeter::idle:
* @greeter: A #LightDMGreeter
*
* The ::idle signal gets emitted when the user has logged in and the
* greeter is no longer needed.
*
* This signal only matters if the greeter has marked itself as
* resettable using lightdm_greeter_set_resettable().
**/
signals[IDLE] =
g_signal_new (LIGHTDM_GREETER_SIGNAL_IDLE,
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (LightDMGreeterClass, idle),
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
/**
* LightDMGreeter::reset:
* @greeter: A #LightDMGreeter
*
* The ::reset signal gets emitted when the user is returning to a greeter
* that was previously marked idle.
*
* This signal only matters if the greeter has marked itself as
* resettable using lightdm_greeter_set_resettable().
**/
signals[RESET] =
g_signal_new (LIGHTDM_GREETER_SIGNAL_RESET,
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (LightDMGreeterClass, reset),
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
}
static void
request_init (Request *request)
{
}
static void
request_finalize (GObject *object)
{
Request *request = REQUEST (object);
g_clear_object (&request->cancellable);
g_free (request->dir);
G_OBJECT_CLASS (request_parent_class)->finalize (object);
}
static void
request_class_init (RequestClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = request_finalize;
}
static gpointer
request_get_user_data (GAsyncResult *result)
{
return REQUEST (result)->user_data;
}
static GObject *
request_get_source_object (GAsyncResult *result)
{
return g_object_ref (G_OBJECT (REQUEST (result)->greeter));
}
static void
request_iface_init (GAsyncResultIface *iface)
{
iface->get_user_data = request_get_user_data;
iface->get_source_object = request_get_source_object;
}
|