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
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2011 Red Hat, Inc.
* Copyright (C) 2013 Thomas Bechtold <thomasbechtold@jpberlin.de>
*/
#include "nm-default.h"
#include "nm-config-data.h"
#include "nm-config.h"
#include "devices/nm-device.h"
#include "nm-core-internal.h"
#include "nm-keyfile/nm-keyfile-internal.h"
#include "nm-keyfile/nm-keyfile-utils.h"
/*****************************************************************************/
typedef struct {
char *group_name;
gboolean stop_match;
struct {
/* have a separate boolean field @has, because a @spec with
* value %NULL does not necessarily mean, that the property
* "match-device" was unspecified. */
gboolean has;
GSList *spec;
} match_device;
} MatchSectionInfo;
struct _NMGlobalDnsDomain {
char *name;
char **servers;
char **options;
};
struct _NMGlobalDnsConfig {
char **searches;
char **options;
GHashTable *domains;
const char **domain_list;
gboolean internal;
};
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_CONFIG_MAIN_FILE,
PROP_CONFIG_DESCRIPTION,
PROP_KEYFILE_USER,
PROP_KEYFILE_INTERN,
PROP_CONNECTIVITY_ENABLED,
PROP_CONNECTIVITY_URI,
PROP_CONNECTIVITY_INTERVAL,
PROP_CONNECTIVITY_RESPONSE,
PROP_NO_AUTO_DEFAULT,
);
typedef struct {
char *config_main_file;
char *config_description;
GKeyFile *keyfile;
GKeyFile *keyfile_user;
GKeyFile *keyfile_intern;
/* A zero-terminated list of pre-processed information from the
* [connection] sections. This is to speed up lookup. */
MatchSectionInfo *connection_infos;
/* A zero-terminated list of pre-processed information from the
* [device] sections. This is to speed up lookup. */
MatchSectionInfo *device_infos;
struct {
gboolean enabled;
char *uri;
char *response;
guint interval;
} connectivity;
int autoconnect_retries_default;
struct {
/* from /var/lib/NetworkManager/no-auto-default.state */
char **arr;
GSList *specs;
/* from main.no-auto-default setting in NetworkManager.conf. */
GSList *specs_config;
} no_auto_default;
GSList *ignore_carrier;
GSList *assume_ipv6ll_only;
char *dns_mode;
char *rc_manager;
NMGlobalDnsConfig *global_dns;
bool systemd_resolved:1;
} NMConfigDataPrivate;
struct _NMConfigData {
GObject parent;
NMConfigDataPrivate _priv;
};
struct _NMConfigDataClass {
GObjectClass parent;
};
G_DEFINE_TYPE (NMConfigData, nm_config_data, G_TYPE_OBJECT)
#define NM_CONFIG_DATA_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMConfigData, NM_IS_CONFIG_DATA)
/*****************************************************************************/
const char *
nm_config_data_get_config_main_file (const NMConfigData *self)
{
g_return_val_if_fail (self, NULL);
return NM_CONFIG_DATA_GET_PRIVATE (self)->config_main_file;
}
const char *
nm_config_data_get_config_description (const NMConfigData *self)
{
g_return_val_if_fail (self, NULL);
return NM_CONFIG_DATA_GET_PRIVATE (self)->config_description;
}
gboolean
nm_config_data_has_group (const NMConfigData *self, const char *group)
{
g_return_val_if_fail (NM_IS_CONFIG_DATA (self), FALSE);
g_return_val_if_fail (group && *group, FALSE);
return g_key_file_has_group (NM_CONFIG_DATA_GET_PRIVATE (self)->keyfile, group);
}
char *
nm_config_data_get_value (const NMConfigData *self, const char *group, const char *key, NMConfigGetValueFlags flags)
{
g_return_val_if_fail (NM_IS_CONFIG_DATA (self), NULL);
g_return_val_if_fail (group && *group, NULL);
g_return_val_if_fail (key && *key, NULL);
return nm_config_keyfile_get_value (NM_CONFIG_DATA_GET_PRIVATE (self)->keyfile, group, key, flags);
}
gboolean
nm_config_data_has_value (const NMConfigData *self, const char *group, const char *key, NMConfigGetValueFlags flags)
{
gs_free char *value = NULL;
g_return_val_if_fail (NM_IS_CONFIG_DATA (self), FALSE);
g_return_val_if_fail (group && *group, FALSE);
g_return_val_if_fail (key && *key, FALSE);
value = nm_config_keyfile_get_value (NM_CONFIG_DATA_GET_PRIVATE (self)->keyfile, group, key, flags);
return !!value;
}
int
nm_config_data_get_value_boolean (const NMConfigData *self, const char *group, const char *key, int default_value)
{
char *str;
int value = default_value;
g_return_val_if_fail (NM_IS_CONFIG_DATA (self), default_value);
g_return_val_if_fail (group && *group, default_value);
g_return_val_if_fail (key && *key, default_value);
/* when parsing the boolean, base it on the raw value from g_key_file_get_value(). */
str = nm_config_keyfile_get_value (NM_CONFIG_DATA_GET_PRIVATE (self)->keyfile, group, key, NM_CONFIG_GET_VALUE_RAW);
if (str) {
value = nm_config_parse_boolean (str, default_value);
g_free (str);
}
return value;
}
gint64
nm_config_data_get_value_int64 (const NMConfigData *self, const char *group, const char *key, guint base, gint64 min, gint64 max, gint64 fallback)
{
int errsv;
gint64 val;
char *str;
g_return_val_if_fail (NM_IS_CONFIG_DATA (self), fallback);
g_return_val_if_fail (group && *group, fallback);
g_return_val_if_fail (key && *key, fallback);
str = nm_config_keyfile_get_value (NM_CONFIG_DATA_GET_PRIVATE (self)->keyfile, group, key, NM_CONFIG_GET_VALUE_NONE);
val = _nm_utils_ascii_str_to_int64 (str, base, min, max, fallback);
if (str) {
errsv = errno;
g_free (str);
errno = errsv;
}
return val;
}
char **
nm_config_data_get_plugins (const NMConfigData *self, gboolean allow_default)
{
gs_free_error GError *error = NULL;
const NMConfigDataPrivate *priv;
char **list;
g_return_val_if_fail (self, NULL);
priv = NM_CONFIG_DATA_GET_PRIVATE (self);
list = g_key_file_get_string_list (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NULL, &error);
if ( nm_keyfile_error_is_not_found (error)
&& allow_default) {
gs_unref_keyfile GKeyFile *kf = nm_config_create_keyfile ();
/* let keyfile split the default string according to its own escaping rules. */
g_key_file_set_value (kf, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NM_CONFIG_DEFAULT_MAIN_PLUGINS);
list = g_key_file_get_string_list (kf, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NULL, NULL);
}
return _nm_utils_strv_cleanup (list, TRUE, TRUE, TRUE);
}
gboolean
nm_config_data_get_connectivity_enabled (const NMConfigData *self)
{
g_return_val_if_fail (self, FALSE);
return NM_CONFIG_DATA_GET_PRIVATE (self)->connectivity.enabled;
}
const char *
nm_config_data_get_connectivity_uri (const NMConfigData *self)
{
g_return_val_if_fail (self, NULL);
return NM_CONFIG_DATA_GET_PRIVATE (self)->connectivity.uri;
}
guint
nm_config_data_get_connectivity_interval (const NMConfigData *self)
{
g_return_val_if_fail (self, 0);
return NM_CONFIG_DATA_GET_PRIVATE (self)->connectivity.interval;
}
const char *
nm_config_data_get_connectivity_response (const NMConfigData *self)
{
g_return_val_if_fail (self != NULL, NULL);
return NM_CONFIG_DATA_GET_PRIVATE (self)->connectivity.response;
}
int
nm_config_data_get_autoconnect_retries_default (const NMConfigData *self)
{
g_return_val_if_fail (self, FALSE);
return NM_CONFIG_DATA_GET_PRIVATE (self)->autoconnect_retries_default;
}
const char *const*
nm_config_data_get_no_auto_default (const NMConfigData *self)
{
g_return_val_if_fail (self, FALSE);
return (const char *const*) NM_CONFIG_DATA_GET_PRIVATE (self)->no_auto_default.arr;
}
gboolean
nm_config_data_get_no_auto_default_for_device (const NMConfigData *self, NMDevice *device)
{
const NMConfigDataPrivate *priv;
g_return_val_if_fail (NM_IS_CONFIG_DATA (self), FALSE);
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
priv = NM_CONFIG_DATA_GET_PRIVATE (self);
return nm_device_spec_match_list (device, priv->no_auto_default.specs)
|| nm_device_spec_match_list (device, priv->no_auto_default.specs_config);
}
const char *
nm_config_data_get_dns_mode (const NMConfigData *self)
{
g_return_val_if_fail (self, NULL);
return NM_CONFIG_DATA_GET_PRIVATE (self)->dns_mode;
}
const char *
nm_config_data_get_rc_manager (const NMConfigData *self)
{
g_return_val_if_fail (self, NULL);
return NM_CONFIG_DATA_GET_PRIVATE (self)->rc_manager;
}
gboolean
nm_config_data_get_systemd_resolved (const NMConfigData *self)
{
g_return_val_if_fail (self, FALSE);
return NM_CONFIG_DATA_GET_PRIVATE (self)->systemd_resolved;
}
gboolean
nm_config_data_get_ignore_carrier (const NMConfigData *self, NMDevice *device)
{
gs_free char *value = NULL;
gboolean has_match;
int m;
g_return_val_if_fail (NM_IS_CONFIG_DATA (self), FALSE);
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
value = nm_config_data_get_device_config (self, NM_CONFIG_KEYFILE_KEY_DEVICE_IGNORE_CARRIER, device, &has_match);
if (has_match)
m = nm_config_parse_boolean (value, -1);
else
m = nm_device_spec_match_list_full (device, NM_CONFIG_DATA_GET_PRIVATE (self)->ignore_carrier, -1);
if (NM_IN_SET (m, TRUE, FALSE))
return m;
/* if ignore-carrier is not explicitly configed, then it depends on the device (type). */
return nm_device_ignore_carrier_by_default (device);
}
gboolean
nm_config_data_get_assume_ipv6ll_only (const NMConfigData *self, NMDevice *device)
{
g_return_val_if_fail (NM_IS_CONFIG_DATA (self), FALSE);
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
return nm_device_spec_match_list (device, NM_CONFIG_DATA_GET_PRIVATE (self)->assume_ipv6ll_only);
}
GKeyFile *
nm_config_data_clone_keyfile_intern (const NMConfigData *self)
{
const NMConfigDataPrivate *priv;
GKeyFile *keyfile;
g_return_val_if_fail (NM_IS_CONFIG_DATA (self), FALSE);
priv = NM_CONFIG_DATA_GET_PRIVATE (self);
keyfile = nm_config_create_keyfile ();
if (priv->keyfile_intern)
_nm_keyfile_copy (keyfile, priv->keyfile_intern);
return keyfile;
}
GKeyFile *
_nm_config_data_get_keyfile (const NMConfigData *self)
{
return NM_CONFIG_DATA_GET_PRIVATE (self)->keyfile;
}
GKeyFile *
_nm_config_data_get_keyfile_intern (const NMConfigData *self)
{
return NM_CONFIG_DATA_GET_PRIVATE (self)->keyfile_intern;
}
GKeyFile *
_nm_config_data_get_keyfile_user (const NMConfigData *self)
{
return NM_CONFIG_DATA_GET_PRIVATE (self)->keyfile_user;
}
/*****************************************************************************/
static NMAuthPolkitMode
nm_auth_polkit_mode_from_string (const char *str)
{
int as_bool;
if (!str)
return NM_AUTH_POLKIT_MODE_UNKNOWN;
if (nm_streq (str, "root-only"))
return NM_AUTH_POLKIT_MODE_ROOT_ONLY;
as_bool = _nm_utils_ascii_str_to_bool (str, -1);
if (as_bool != -1) {
return as_bool
? NM_AUTH_POLKIT_MODE_USE_POLKIT
: NM_AUTH_POLKIT_MODE_ALLOW_ALL;
}
return NM_AUTH_POLKIT_MODE_UNKNOWN;
}
static NMAuthPolkitMode
_config_data_get_main_auth_polkit (const NMConfigData *self,
gboolean *out_invalid_config)
{
NMAuthPolkitMode auth_polkit_mode;
const char *str;
str = nm_config_data_get_value (self,
NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_AUTH_POLKIT,
NM_CONFIG_GET_VALUE_STRIP
| NM_CONFIG_GET_VALUE_NO_EMPTY);
auth_polkit_mode = nm_auth_polkit_mode_from_string (str);
if (auth_polkit_mode == NM_AUTH_POLKIT_MODE_UNKNOWN) {
NM_SET_OUT (out_invalid_config, (str != NULL));
auth_polkit_mode = nm_auth_polkit_mode_from_string (NM_CONFIG_DEFAULT_MAIN_AUTH_POLKIT);
if (auth_polkit_mode == NM_AUTH_POLKIT_MODE_UNKNOWN) {
nm_assert_not_reached ();
auth_polkit_mode = NM_AUTH_POLKIT_MODE_ROOT_ONLY;
}
} else
NM_SET_OUT (out_invalid_config, FALSE);
return auth_polkit_mode;
}
NMAuthPolkitMode
nm_config_data_get_main_auth_polkit (const NMConfigData *self)
{
return _config_data_get_main_auth_polkit (self, NULL);
}
/*****************************************************************************/
/**
* nm_config_data_get_groups:
* @self: the #NMConfigData instance
*
* Returns: (transfer full): the list of groups in the configuration. The order
* of the section is undefined, as the configuration gets merged from multiple
* sources.
*/
char **
nm_config_data_get_groups (const NMConfigData *self)
{
g_return_val_if_fail (NM_IS_CONFIG_DATA (self), NULL);
return g_key_file_get_groups (NM_CONFIG_DATA_GET_PRIVATE (self)->keyfile, NULL);
}
char **
nm_config_data_get_keys (const NMConfigData *self, const char *group)
{
g_return_val_if_fail (NM_IS_CONFIG_DATA (self), NULL);
g_return_val_if_fail (group && *group, NULL);
return g_key_file_get_keys (NM_CONFIG_DATA_GET_PRIVATE (self)->keyfile, group, NULL, NULL);
}
/**
* nm_config_data_is_intern_atomic_group:
* @self:
* @group: name of the group to check.
*
* whether a configuration group @group exists and is entirely overwritten
* by internal configuration, i.e. whether it is an atomic group that is
* overwritten.
*
* It doesn't say, that there actually is a user setting that was overwritten. That
* means there could be no corresponding section defined in user configuration
* that required overwriting.
*
* Returns: %TRUE if @group exists and is an atomic group set via internal configuration.
*/
gboolean
nm_config_data_is_intern_atomic_group (const NMConfigData *self, const char *group)
{
const NMConfigDataPrivate *priv;
g_return_val_if_fail (NM_IS_CONFIG_DATA (self), FALSE);
g_return_val_if_fail (group && *group, FALSE);
priv = NM_CONFIG_DATA_GET_PRIVATE (self);
if ( !priv->keyfile_intern
|| !g_key_file_has_key (priv->keyfile_intern, group, NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS, NULL))
return FALSE;
/* we have a .was entry for the section. That means that the section would be overwritten
* from user configuration. But it doesn't mean that the merged configuration contains this
* groups, because the internal setting could hide the user section.
* Only return TRUE, if we actually have such a group in the merged configuration.*/
return g_key_file_has_group (priv->keyfile, group);
}
/*****************************************************************************/
static GKeyFile *
_merge_keyfiles (GKeyFile *keyfile_user, GKeyFile *keyfile_intern)
{
gs_strfreev char **groups = NULL;
guint g, k;
GKeyFile *keyfile;
gsize ngroups;
keyfile = nm_config_create_keyfile ();
if (keyfile_user)
_nm_keyfile_copy (keyfile, keyfile_user);
if (!keyfile_intern)
return keyfile;
groups = g_key_file_get_groups (keyfile_intern, &ngroups);
if (!groups)
return keyfile;
/* we must reverse the order of the connection settings so that we
* have lowest priority last. */
_nm_config_sort_groups (groups, ngroups);
for (g = 0; groups[g]; g++) {
const char *group = groups[g];
gs_strfreev char **keys = NULL;
gboolean is_intern, is_atomic = FALSE;
keys = g_key_file_get_keys (keyfile_intern, group, NULL, NULL);
if (!keys)
continue;
is_intern = g_str_has_prefix (group, NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN);
if ( !is_intern
&& g_key_file_has_key (keyfile_intern, group, NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS, NULL)) {
/* the entire section is atomically overwritten by @keyfile_intern. */
g_key_file_remove_group (keyfile, group, NULL);
is_atomic = TRUE;
}
for (k = 0; keys[k]; k++) {
const char *key = keys[k];
gs_free char *value = NULL;
if (is_atomic && strcmp (key, NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS) == 0)
continue;
if ( !is_intern && !is_atomic
&& NM_STR_HAS_PREFIX_WITH_MORE (key, NM_CONFIG_KEYFILE_KEYPREFIX_WAS)) {
const char *key_base = &key[NM_STRLEN (NM_CONFIG_KEYFILE_KEYPREFIX_WAS)];
if (!g_key_file_has_key (keyfile_intern, group, key_base, NULL))
g_key_file_remove_key (keyfile, group, key_base, NULL);
continue;
}
if (!is_intern && !is_atomic && NM_STR_HAS_PREFIX_WITH_MORE (key, NM_CONFIG_KEYFILE_KEYPREFIX_SET))
continue;
value = g_key_file_get_value (keyfile_intern, group, key, NULL);
g_key_file_set_value (keyfile, group, key, value);
}
}
return keyfile;
}
/*****************************************************************************/
static int
_nm_config_data_log_sort (const char **pa, const char **pb, gpointer dummy)
{
gboolean a_is_connection, b_is_connection;
gboolean a_is_device, b_is_device;
gboolean a_is_intern, b_is_intern;
gboolean a_is_main, b_is_main;
const char *a = *pa;
const char *b = *pb;
/* we sort intern groups to the end. */
a_is_intern = g_str_has_prefix (a, NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN);
b_is_intern = g_str_has_prefix (b, NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN);
if (a_is_intern && b_is_intern)
return 0;
if (a_is_intern)
return 1;
if (b_is_intern)
return -1;
/* we sort connection groups before intern groups (to the end). */
a_is_connection = a && g_str_has_prefix (a, NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION);
b_is_connection = b && g_str_has_prefix (b, NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION);
if (a_is_connection && b_is_connection) {
/* if both are connection groups, we want the explicit [connection] group first. */
a_is_connection = a[NM_STRLEN (NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION)] == '\0';
b_is_connection = b[NM_STRLEN (NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION)] == '\0';
if (a_is_connection != b_is_connection) {
if (a_is_connection)
return -1;
return 1;
}
/* the sections are ordered lowest-priority first. Reverse their order. */
return pa < pb ? 1 : -1;
}
if (a_is_connection && !b_is_connection)
return 1;
if (b_is_connection && !a_is_connection)
return -1;
/* we sort device groups before connection groups (to the end). */
a_is_device = a && g_str_has_prefix (a, NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE);
b_is_device = b && g_str_has_prefix (b, NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE);
if (a_is_device && b_is_device) {
/* if both are device groups, we want the explicit [device] group first. */
a_is_device = a[NM_STRLEN (NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE)] == '\0';
b_is_device = b[NM_STRLEN (NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE)] == '\0';
if (a_is_device != b_is_device) {
if (a_is_device)
return -1;
return 1;
}
/* the sections are ordered lowest-priority first. Reverse their order. */
return pa < pb ? 1 : -1;
}
if (a_is_device && !b_is_device)
return 1;
if (b_is_device && !a_is_device)
return -1;
a_is_main = nm_streq0 (a, "main");
b_is_main = nm_streq0 (b, "main");
if (a_is_main != b_is_main)
return a_is_main ? -1 : 1;
return g_strcmp0 (a, b);
}
static const struct {
const char *group;
const char *key;
const char *value;
} default_values[] = {
{ NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NM_CONFIG_DEFAULT_MAIN_PLUGINS },
{ NM_CONFIG_KEYFILE_GROUP_MAIN, "rc-manager", NM_CONFIG_DEFAULT_MAIN_RC_MANAGER },
{ NM_CONFIG_KEYFILE_GROUP_MAIN, NM_CONFIG_KEYFILE_KEY_MAIN_AUTH_POLKIT, NM_CONFIG_DEFAULT_MAIN_AUTH_POLKIT },
{ NM_CONFIG_KEYFILE_GROUP_MAIN, NM_CONFIG_KEYFILE_KEY_MAIN_DHCP, NM_CONFIG_DEFAULT_MAIN_DHCP },
{ NM_CONFIG_KEYFILE_GROUP_LOGGING, "backend", NM_CONFIG_DEFAULT_LOGGING_BACKEND },
{ NM_CONFIG_KEYFILE_GROUP_LOGGING, "audit", NM_CONFIG_DEFAULT_LOGGING_AUDIT },
};
void
nm_config_data_log (const NMConfigData *self,
const char *prefix,
const char *key_prefix,
const char *no_auto_default_file,
/* FILE* */ gpointer print_stream)
{
const NMConfigDataPrivate *priv;
gs_strfreev char **groups = NULL;
gsize ngroups;
guint g, k, i;
FILE *stream = print_stream;
gs_unref_ptrarray GPtrArray *groups_full = NULL;
gboolean print_default = !!stream;
g_return_if_fail (NM_IS_CONFIG_DATA (self));
if (!stream && !nm_logging_enabled (LOGL_DEBUG, LOGD_CORE))
return;
if (!prefix)
prefix = "";
if (!key_prefix)
key_prefix = "";
#define _LOG(stream, prefix, ...) \
G_STMT_START { \
if (!stream) \
_nm_log (LOGL_DEBUG, LOGD_CORE, 0, NULL, NULL, "%s"_NM_UTILS_MACRO_FIRST(__VA_ARGS__)"%s", prefix _NM_UTILS_MACRO_REST (__VA_ARGS__), ""); \
else \
fprintf (stream, "%s"_NM_UTILS_MACRO_FIRST(__VA_ARGS__)"%s", prefix _NM_UTILS_MACRO_REST (__VA_ARGS__), "\n"); \
} G_STMT_END
priv = NM_CONFIG_DATA_GET_PRIVATE (self);
groups = g_key_file_get_groups (priv->keyfile, &ngroups);
if (!groups)
ngroups = 0;
groups_full = g_ptr_array_sized_new (ngroups + 5);
if (ngroups) {
g_ptr_array_set_size (groups_full, ngroups);
memcpy (groups_full->pdata, groups, sizeof (groups[0]) * ngroups);
g_ptr_array_sort_with_data (groups_full, (GCompareDataFunc) _nm_config_data_log_sort, NULL);
}
if (print_default) {
for (g = 0; g < G_N_ELEMENTS (default_values); g++) {
const char *group = default_values[g].group;
gssize idx;
idx = nm_utils_array_find_binary_search ((gconstpointer *) groups_full->pdata,
sizeof (char *),
groups_full->len,
&group,
(GCompareDataFunc) _nm_config_data_log_sort,
NULL);
if (idx < 0)
g_ptr_array_insert (groups_full, (~idx), (gpointer) group);
}
}
if (!stream)
_LOG (stream, prefix, "config-data[%p]: %u groups", self, groups_full->len);
for (g = 0; g < groups_full->len; g++) {
const char *group = groups_full->pdata[g];
gs_strfreev char **keys = NULL;
gboolean is_atomic;
is_atomic = nm_config_data_is_intern_atomic_group (self, group);
_LOG (stream, prefix, "");
_LOG (stream, prefix, "[%s]%s", group, is_atomic && !stream ? " # atomic section" : "");
/* Print default values as comments */
if (print_default) {
for (i = 0; i < G_N_ELEMENTS (default_values); i++) {
if ( nm_streq (default_values[i].group, group)
&& !g_key_file_has_key (priv->keyfile, group, default_values[i].key, NULL)) {
_LOG (stream, prefix, "%s# %s=%s", key_prefix, default_values[i].key,
default_values[i].value);
}
}
}
keys = g_key_file_get_keys (priv->keyfile, group, NULL, NULL);
for (k = 0; keys && keys[k]; k++) {
const char *key = keys[k];
gs_free char *value = NULL;
value = g_key_file_get_value (priv->keyfile, group, key, NULL);
_LOG (stream, prefix, "%s%s=%s", key_prefix, key, value);
}
}
_LOG (stream, prefix, "");
_LOG (stream, prefix, "# no-auto-default file \"%s\"", no_auto_default_file);
{
gs_free char *msg = NULL;
msg = nm_utils_g_slist_strlist_join (priv->no_auto_default.specs, ",");
if (msg)
_LOG (stream, prefix, "# no-auto-default specs \"%s\"", msg);
}
#undef _LOG
}
/*****************************************************************************/
const char *const*
nm_global_dns_config_get_searches (const NMGlobalDnsConfig *dns_config)
{
g_return_val_if_fail (dns_config, NULL);
return (const char *const*) dns_config->searches;
}
const char *const *
nm_global_dns_config_get_options (const NMGlobalDnsConfig *dns_config)
{
g_return_val_if_fail (dns_config, NULL);
return (const char *const*) dns_config->options;
}
guint
nm_global_dns_config_get_num_domains (const NMGlobalDnsConfig *dns_config)
{
g_return_val_if_fail (dns_config, 0);
return dns_config->domains ? g_hash_table_size (dns_config->domains) : 0;
}
NMGlobalDnsDomain *
nm_global_dns_config_get_domain (const NMGlobalDnsConfig *dns_config, guint i)
{
NMGlobalDnsDomain *domain;
g_return_val_if_fail (dns_config, NULL);
g_return_val_if_fail (dns_config->domains, NULL);
g_return_val_if_fail (i < g_hash_table_size (dns_config->domains), NULL);
nm_assert (NM_PTRARRAY_LEN (dns_config->domain_list) == g_hash_table_size (dns_config->domains));
domain = g_hash_table_lookup (dns_config->domains, dns_config->domain_list[i]);
nm_assert (domain);
return domain;
}
NMGlobalDnsDomain *nm_global_dns_config_lookup_domain (const NMGlobalDnsConfig *dns_config, const char *name)
{
g_return_val_if_fail (dns_config, NULL);
g_return_val_if_fail (name, NULL);
return dns_config->domains ? g_hash_table_lookup (dns_config->domains, name) : NULL;
}
const char *
nm_global_dns_domain_get_name (const NMGlobalDnsDomain *domain)
{
g_return_val_if_fail (domain, NULL);
return (const char *) domain->name;
}
const char *const *
nm_global_dns_domain_get_servers (const NMGlobalDnsDomain *domain)
{
g_return_val_if_fail (domain, NULL);
return (const char *const *) domain->servers;
}
const char *const *
nm_global_dns_domain_get_options (const NMGlobalDnsDomain *domain)
{
g_return_val_if_fail (domain, NULL);
return (const char *const *) domain->options;
}
gboolean
nm_global_dns_config_is_internal (const NMGlobalDnsConfig *dns_config)
{
return dns_config->internal;
}
gboolean
nm_global_dns_config_is_empty (const NMGlobalDnsConfig *dns_config)
{
g_return_val_if_fail (dns_config, TRUE);
return !dns_config->searches
&& !dns_config->options
&& !dns_config->domain_list;
}
void
nm_global_dns_config_update_checksum (const NMGlobalDnsConfig *dns_config, GChecksum *sum)
{
NMGlobalDnsDomain *domain;
guint i, j;
guint8 v8;
g_return_if_fail (dns_config);
g_return_if_fail (sum);
v8 = NM_HASH_COMBINE_BOOLS (guint8,
!dns_config->searches,
!dns_config->options,
!dns_config->domain_list);
g_checksum_update (sum, (guchar *) &v8, 1);
if (dns_config->searches) {
for (i = 0; dns_config->searches[i]; i++)
g_checksum_update (sum, (guchar *) dns_config->searches[i], strlen (dns_config->searches[i]) + 1);
}
if (dns_config->options) {
for (i = 0; dns_config->options[i]; i++)
g_checksum_update (sum, (guchar *) dns_config->options[i], strlen (dns_config->options[i]) + 1);
}
if (dns_config->domain_list) {
for (i = 0; dns_config->domain_list[i]; i++) {
domain = g_hash_table_lookup (dns_config->domains, dns_config->domain_list[i]);
nm_assert (domain);
v8 = NM_HASH_COMBINE_BOOLS (guint8,
!domain->servers,
!domain->options);
g_checksum_update (sum, (guchar *) &v8, 1);
g_checksum_update (sum, (guchar *) domain->name, strlen (domain->name) + 1);
if (domain->servers) {
for (j = 0; domain->servers[j]; j++)
g_checksum_update (sum, (guchar *) domain->servers[j], strlen (domain->servers[j]) + 1);
}
if (domain->options) {
for (j = 0; domain->options[j]; j++)
g_checksum_update (sum, (guchar *) domain->options[j], strlen (domain->options[j]) + 1);
}
}
}
}
static void
global_dns_domain_free (NMGlobalDnsDomain *domain)
{
if (domain) {
g_free (domain->name);
g_strfreev (domain->servers);
g_strfreev (domain->options);
g_free (domain);
}
}
void
nm_global_dns_config_free (NMGlobalDnsConfig *dns_config)
{
if (dns_config) {
g_strfreev (dns_config->searches);
g_strfreev (dns_config->options);
g_free (dns_config->domain_list);
if (dns_config->domains)
g_hash_table_unref (dns_config->domains);
g_free (dns_config);
}
}
NMGlobalDnsConfig *
nm_config_data_get_global_dns_config (const NMConfigData *self)
{
g_return_val_if_fail (NM_IS_CONFIG_DATA (self), NULL);
return NM_CONFIG_DATA_GET_PRIVATE (self)->global_dns;
}
static void
global_dns_config_seal_domains (NMGlobalDnsConfig *dns_config)
{
nm_assert (dns_config);
nm_assert (dns_config->domains);
nm_assert (!dns_config->domain_list);
if (g_hash_table_size (dns_config->domains) == 0)
nm_clear_pointer (&dns_config->domains, g_hash_table_unref);
else
dns_config->domain_list = nm_utils_strdict_get_keys (dns_config->domains, TRUE, NULL);
}
static NMGlobalDnsConfig *
load_global_dns (GKeyFile *keyfile, gboolean internal)
{
NMGlobalDnsConfig *dns_config;
char *group, *domain_prefix;
gs_strfreev char **groups = NULL;
int g, i, j, domain_prefix_len;
gboolean default_found = FALSE;
char **strv;
group = internal
? NM_CONFIG_KEYFILE_GROUP_INTERN_GLOBAL_DNS
: NM_CONFIG_KEYFILE_GROUP_GLOBAL_DNS;
domain_prefix = internal
? NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN_GLOBAL_DNS_DOMAIN
: NM_CONFIG_KEYFILE_GROUPPREFIX_GLOBAL_DNS_DOMAIN;
domain_prefix_len = strlen (domain_prefix);
if (!nm_config_keyfile_has_global_dns_config (keyfile, internal))
return NULL;
dns_config = g_malloc0 (sizeof (NMGlobalDnsConfig));
dns_config->domains = g_hash_table_new_full (nm_str_hash, g_str_equal,
g_free, (GDestroyNotify) global_dns_domain_free);
strv = g_key_file_get_string_list (keyfile,
group,
NM_CONFIG_KEYFILE_KEY_GLOBAL_DNS_SEARCHES,
NULL, NULL);
if (strv) {
_nm_utils_strv_cleanup (strv, TRUE, TRUE, TRUE);
if (!strv[0])
g_free (strv);
else
dns_config->searches = strv;
}
strv = g_key_file_get_string_list (keyfile,
group,
NM_CONFIG_KEYFILE_KEY_GLOBAL_DNS_OPTIONS,
NULL, NULL);
if (strv) {
_nm_utils_strv_cleanup (strv, TRUE, TRUE, TRUE);
for (i = 0, j = 0; strv[i]; i++) {
if (_nm_utils_dns_option_validate (strv[i], NULL, NULL, TRUE, NULL))
strv[j++] = strv[i];
else
g_free (strv[i]);
}
if (j == 0)
g_free (strv);
else {
strv[j] = NULL;
dns_config->options = strv;
}
}
groups = g_key_file_get_groups (keyfile, NULL);
for (g = 0; groups[g]; g++) {
char *name;
char **servers = NULL, **options = NULL;
NMGlobalDnsDomain *domain;
if ( !g_str_has_prefix (groups[g], domain_prefix)
|| !groups[g][domain_prefix_len])
continue;
strv = g_key_file_get_string_list (keyfile,
groups[g],
NM_CONFIG_KEYFILE_KEY_GLOBAL_DNS_DOMAIN_SERVERS,
NULL, NULL);
if (strv) {
_nm_utils_strv_cleanup (strv, TRUE, TRUE, TRUE);
for (i = 0, j = 0; strv[i]; i++) {
if ( nm_utils_ipaddr_is_valid (AF_INET, strv[i])
|| nm_utils_ipaddr_is_valid (AF_INET6, strv[i]))
strv[j++] = strv[i];
else
g_free (strv[i]);
}
if (j == 0)
g_free (strv);
else {
strv[j] = NULL;
servers = strv;
}
}
if (!servers)
continue;
strv = g_key_file_get_string_list (keyfile,
groups[g],
NM_CONFIG_KEYFILE_KEY_GLOBAL_DNS_DOMAIN_OPTIONS,
NULL, NULL);
if (strv) {
options = _nm_utils_strv_cleanup (strv, TRUE, TRUE, TRUE);
if (!options[0])
nm_clear_g_free (&options);
}
name = strdup (&groups[g][domain_prefix_len]);
domain = g_malloc0 (sizeof (NMGlobalDnsDomain));
domain->name = name;
domain->servers = servers;
domain->options = options;
g_hash_table_insert (dns_config->domains, strdup (name), domain);
if (!strcmp (name, "*"))
default_found = TRUE;
}
if (!default_found) {
nm_log_dbg (LOGD_CORE, "%s global DNS configuration is missing default domain, ignore it",
internal ? "internal" : "user");
nm_global_dns_config_free (dns_config);
return NULL;
}
dns_config->internal = internal;
global_dns_config_seal_domains (dns_config);
return dns_config;
}
void
nm_global_dns_config_to_dbus (const NMGlobalDnsConfig *dns_config, GValue *value)
{
GVariantBuilder conf_builder, domains_builder, domain_builder;
guint i;
g_variant_builder_init (&conf_builder, G_VARIANT_TYPE ("a{sv}"));
if (!dns_config)
goto out;
if (dns_config->searches) {
g_variant_builder_add (&conf_builder, "{sv}", "searches",
g_variant_new_strv ((const char *const *) dns_config->searches, -1));
}
if (dns_config->options) {
g_variant_builder_add (&conf_builder, "{sv}", "options",
g_variant_new_strv ((const char *const *) dns_config->options, -1));
}
g_variant_builder_init (&domains_builder, G_VARIANT_TYPE ("a{sv}"));
if (dns_config->domain_list) {
for (i = 0; dns_config->domain_list[i]; i++) {
NMGlobalDnsDomain *domain;
domain = g_hash_table_lookup (dns_config->domains, dns_config->domain_list[i]);
g_variant_builder_init (&domain_builder, G_VARIANT_TYPE ("a{sv}"));
if (domain->servers) {
g_variant_builder_add (&domain_builder, "{sv}", "servers",
g_variant_new_strv ((const char *const *) domain->servers, -1));
}
if (domain->options) {
g_variant_builder_add (&domain_builder, "{sv}", "options",
g_variant_new_strv ((const char *const *) domain->options, -1));
}
g_variant_builder_add (&domains_builder, "{sv}", domain->name,
g_variant_builder_end (&domain_builder));
}
}
g_variant_builder_add (&conf_builder, "{sv}", "domains",
g_variant_builder_end (&domains_builder));
out:
g_value_take_variant (value, g_variant_builder_end (&conf_builder));
}
static NMGlobalDnsDomain *
global_dns_domain_from_dbus (char *name, GVariant *variant)
{
NMGlobalDnsDomain *domain;
GVariantIter iter;
char **strv, *key;
GVariant *val;
int i, j;
if (!g_variant_is_of_type (variant, G_VARIANT_TYPE ("a{sv}")))
return NULL;
domain = g_malloc0 (sizeof (NMGlobalDnsDomain));
domain->name = g_strdup (name);
g_variant_iter_init (&iter, variant);
while (g_variant_iter_next (&iter, "{&sv}", &key, &val)) {
if ( !g_strcmp0 (key, "servers")
&& g_variant_is_of_type (val, G_VARIANT_TYPE ("as"))) {
strv = g_variant_dup_strv (val, NULL);
_nm_utils_strv_cleanup (strv, TRUE, TRUE, TRUE);
for (i = 0, j = 0; strv && strv[i]; i++) {
if ( nm_utils_ipaddr_is_valid (AF_INET, strv[i])
|| nm_utils_ipaddr_is_valid (AF_INET6, strv[i]))
strv[j++] = strv[i];
else
g_free (strv[i]);
}
if (j == 0)
g_free (strv);
else {
strv[j] = NULL;
g_strfreev (domain->servers);
domain->servers = strv;
}
} else if ( !g_strcmp0 (key, "options")
&& g_variant_is_of_type (val, G_VARIANT_TYPE ("as"))) {
strv = g_variant_dup_strv (val, NULL);
g_strfreev (domain->options);
domain->options = _nm_utils_strv_cleanup (strv, TRUE, TRUE, TRUE);
if (!domain->options[0])
nm_clear_g_free (&domain->options);
}
g_variant_unref (val);
}
/* At least one server is required */
if (!domain->servers) {
global_dns_domain_free (domain);
return NULL;
}
return domain;
}
NMGlobalDnsConfig *
nm_global_dns_config_from_dbus (const GValue *value, GError **error)
{
NMGlobalDnsConfig *dns_config;
GVariant *variant, *val;
GVariantIter iter;
char **strv, *key;
int i, j;
if (!G_VALUE_HOLDS_VARIANT (value)) {
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
"invalid value type");
return NULL;
}
variant = g_value_get_variant (value);
if (!g_variant_is_of_type (variant, G_VARIANT_TYPE ("a{sv}"))) {
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
"invalid variant type");
return NULL;
}
dns_config = g_malloc0 (sizeof (NMGlobalDnsConfig));
dns_config->domains = g_hash_table_new_full (nm_str_hash, g_str_equal,
g_free, (GDestroyNotify) global_dns_domain_free);
g_variant_iter_init (&iter, variant);
while (g_variant_iter_next (&iter, "{&sv}", &key, &val)) {
if ( !g_strcmp0 (key, "searches")
&& g_variant_is_of_type (val, G_VARIANT_TYPE ("as"))) {
strv = g_variant_dup_strv (val, NULL);
dns_config->searches = _nm_utils_strv_cleanup (strv, TRUE, TRUE, TRUE);
} else if ( !g_strcmp0 (key, "options")
&& g_variant_is_of_type (val, G_VARIANT_TYPE ("as"))) {
strv = g_variant_dup_strv (val, NULL);
_nm_utils_strv_cleanup (strv, TRUE, TRUE, TRUE);
for (i = 0, j = 0; strv && strv[i]; i++) {
if (_nm_utils_dns_option_validate (strv[i], NULL, NULL, TRUE, NULL))
strv[j++] = strv[i];
else
g_free (strv[i]);
}
if (j == 0)
g_free (strv);
else {
strv[j] = NULL;
dns_config->options = strv;
}
} else if ( !g_strcmp0 (key, "domains")
&& g_variant_is_of_type (val, G_VARIANT_TYPE ("a{sv}"))) {
NMGlobalDnsDomain *domain;
GVariantIter domain_iter;
GVariant *v;
char *k;
g_variant_iter_init (&domain_iter, val);
while (g_variant_iter_next (&domain_iter, "{&sv}", &k, &v)) {
if (k) {
domain = global_dns_domain_from_dbus (k, v);
if (domain)
g_hash_table_insert (dns_config->domains, strdup (k), domain);
}
g_variant_unref (v);
}
}
g_variant_unref (val);
}
/* An empty value is valid and clears the internal configuration */
if ( !nm_global_dns_config_is_empty (dns_config)
&& !nm_global_dns_config_lookup_domain (dns_config, "*")) {
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
"Global DNS configuration is missing the default domain");
nm_global_dns_config_free (dns_config);
return NULL;
}
global_dns_config_seal_domains (dns_config);
return dns_config;
}
static gboolean
global_dns_equal (NMGlobalDnsConfig *old, NMGlobalDnsConfig *new)
{
NMGlobalDnsDomain *domain_old, *domain_new;
gpointer key, value_old, value_new;
GHashTableIter iter;
if (old == new)
return TRUE;
if (!old || !new)
return FALSE;
if ( !_nm_utils_strv_equal (old->options, new->options)
|| !_nm_utils_strv_equal (old->searches, new->searches))
return FALSE;
if ((!old->domains || !new->domains) && old->domains != new->domains)
return FALSE;
if (g_hash_table_size (old->domains) != g_hash_table_size (new->domains))
return FALSE;
g_hash_table_iter_init (&iter, old->domains);
while (g_hash_table_iter_next (&iter, &key, &value_old)) {
value_new = g_hash_table_lookup (new->domains, key);
if (!value_new)
return FALSE;
domain_old = value_old;
domain_new = value_new;
if ( !_nm_utils_strv_equal (domain_old->options, domain_new->options)
|| !_nm_utils_strv_equal (domain_old->servers, domain_new->servers))
return FALSE;
}
return TRUE;
}
/*****************************************************************************/
static const MatchSectionInfo *
_match_section_infos_lookup (const MatchSectionInfo *match_section_infos,
GKeyFile *keyfile,
const char *property,
NMDevice *device,
const NMPlatformLink *pllink,
const char *match_device_type,
char **out_value)
{
const char *match_dhcp_plugin;
if (!match_section_infos)
return NULL;
match_dhcp_plugin = nm_dhcp_manager_get_config (nm_dhcp_manager_get ());
for (; match_section_infos->group_name; match_section_infos++) {
char *value = NULL;
gboolean match;
/* FIXME: Here we use g_key_file_get_string(). This should be in sync with what keyfile-reader
* does.
*
* Unfortunately that is currently not possible because keyfile-reader does the two steps
* string_to_value(keyfile_to_string(keyfile)) in one. Optimally, keyfile library would
* expose both functions, and we would return here keyfile_to_string(keyfile).
* The caller then could convert the string to the proper value via string_to_value(value). */
value = g_key_file_get_string (keyfile, match_section_infos->group_name, property, NULL);
if (!value && !match_section_infos->stop_match)
continue;
if (match_section_infos->match_device.has) {
if (device)
match = nm_device_spec_match_list (device, match_section_infos->match_device.spec);
else if (pllink)
match = nm_match_spec_device_by_pllink (pllink, match_device_type, match_dhcp_plugin, match_section_infos->match_device.spec, FALSE);
else
match = FALSE;
} else
match = TRUE;
if (match) {
*out_value = value;
return match_section_infos;
}
g_free (value);
}
return NULL;
}
char *
nm_config_data_get_device_config (const NMConfigData *self,
const char *property,
NMDevice *device,
gboolean *has_match)
{
const NMConfigDataPrivate *priv;
const MatchSectionInfo *connection_info;
char *value = NULL;
NM_SET_OUT (has_match, FALSE);
g_return_val_if_fail (self, NULL);
g_return_val_if_fail (property && *property, NULL);
priv = NM_CONFIG_DATA_GET_PRIVATE (self);
connection_info = _match_section_infos_lookup (&priv->device_infos[0],
priv->keyfile,
property,
device,
NULL,
NULL,
&value);
NM_SET_OUT (has_match, !!connection_info);
return value;
}
char *
nm_config_data_get_device_config_by_pllink (const NMConfigData *self,
const char *property,
const NMPlatformLink *pllink,
const char *match_device_type,
gboolean *has_match)
{
const NMConfigDataPrivate *priv;
const MatchSectionInfo *connection_info;
char *value = NULL;
g_return_val_if_fail (self, NULL);
g_return_val_if_fail (property && *property, NULL);
priv = NM_CONFIG_DATA_GET_PRIVATE (self);
connection_info = _match_section_infos_lookup (&priv->device_infos[0],
priv->keyfile,
property,
NULL,
pllink,
match_device_type,
&value);
NM_SET_OUT (has_match, !!connection_info);
return value;
}
gboolean
nm_config_data_get_device_config_boolean (const NMConfigData *self,
const char *property,
NMDevice *device,
int val_no_match,
int val_invalid)
{
gs_free char *value = NULL;
gboolean has_match;
value = nm_config_data_get_device_config (self, property, device, &has_match);
if (!has_match)
return val_no_match;
return nm_config_parse_boolean (value, val_invalid);
}
char *
nm_config_data_get_connection_default (const NMConfigData *self,
const char *property,
NMDevice *device)
{
const NMConfigDataPrivate *priv;
char *value = NULL;
g_return_val_if_fail (self, NULL);
g_return_val_if_fail (property && *property, NULL);
g_return_val_if_fail (strchr (property, '.'), NULL);
priv = NM_CONFIG_DATA_GET_PRIVATE (self);
#if NM_MORE_ASSERTS > 10
{
const char **ptr;
for (ptr = __start_connection_defaults; ptr < __stop_connection_defaults; ptr++) {
if (nm_streq (property, *ptr))
break;
}
nm_assert (ptr < __stop_connection_defaults);
}
#endif
_match_section_infos_lookup (&priv->connection_infos[0],
priv->keyfile,
property,
device,
NULL,
NULL,
&value);
return value;
}
gint64
nm_config_data_get_connection_default_int64 (const NMConfigData *self,
const char *property,
NMDevice *device,
gint64 min,
gint64 max,
gint64 fallback)
{
gs_free char *value = NULL;
value = nm_config_data_get_connection_default (self, property, device);
return _nm_utils_ascii_str_to_int64 (value, 10, min, max, fallback);
}
static void
_get_connection_info_init (MatchSectionInfo *connection_info, GKeyFile *keyfile, char *group)
{
/* pass ownership of @group on... */
connection_info->group_name = group;
connection_info->match_device.spec = nm_config_get_match_spec (keyfile,
group,
NM_CONFIG_KEYFILE_KEY_MATCH_DEVICE,
&connection_info->match_device.has);
connection_info->stop_match = nm_config_keyfile_get_boolean (keyfile,
group,
NM_CONFIG_KEYFILE_KEY_STOP_MATCH,
FALSE);
}
static void
_match_section_infos_free (MatchSectionInfo *match_section_infos)
{
guint i;
if (!match_section_infos)
return;
for (i = 0; match_section_infos[i].group_name; i++) {
g_free (match_section_infos[i].group_name);
g_slist_free_full (match_section_infos[i].match_device.spec, g_free);
}
g_free (match_section_infos);
}
static MatchSectionInfo *
_match_section_infos_construct (GKeyFile *keyfile, const char *prefix)
{
char **groups;
gsize i, j, ngroups;
char *connection_tag = NULL;
MatchSectionInfo *match_section_infos = NULL;
/* get the list of existing [connection.\+]/[device.\+] sections.
*
* We expect the sections in their right order, with lowest priority
* first. Only exception is the (literal) [connection] section, which
* we will always reorder to the end. */
groups = g_key_file_get_groups (keyfile, &ngroups);
if (!groups)
return NULL;
if (ngroups > 0) {
gsize l = strlen (prefix);
for (i = 0, j = 0; i < ngroups; i++) {
if (g_str_has_prefix (groups[i], prefix)) {
if (groups[i][l] == '\0')
connection_tag = groups[i];
else
groups[j++] = groups[i];
} else
g_free (groups[i]);
}
ngroups = j;
}
if (ngroups == 0 && !connection_tag) {
g_free (groups);
return NULL;
}
match_section_infos = g_new0 (MatchSectionInfo, ngroups + 1 + (connection_tag ? 1 : 0));
for (i = 0; i < ngroups; i++) {
/* pass ownership of @group on... */
_get_connection_info_init (&match_section_infos[i], keyfile, groups[ngroups - i - 1]);
}
if (connection_tag) {
/* pass ownership of @connection_tag on... */
_get_connection_info_init (&match_section_infos[i], keyfile, connection_tag);
}
g_free (groups);
return match_section_infos;
}
/*****************************************************************************/
NMConfigChangeFlags
nm_config_data_diff (NMConfigData *old_data, NMConfigData *new_data)
{
NMConfigChangeFlags changes = NM_CONFIG_CHANGE_NONE;
NMConfigDataPrivate *priv_old, *priv_new;
g_return_val_if_fail (NM_IS_CONFIG_DATA (old_data), NM_CONFIG_CHANGE_NONE);
g_return_val_if_fail (NM_IS_CONFIG_DATA (new_data), NM_CONFIG_CHANGE_NONE);
priv_old = NM_CONFIG_DATA_GET_PRIVATE (old_data);
priv_new = NM_CONFIG_DATA_GET_PRIVATE (new_data);
if (!_nm_keyfile_equals (priv_old->keyfile_user, priv_new->keyfile_user, TRUE))
changes |= NM_CONFIG_CHANGE_VALUES | NM_CONFIG_CHANGE_VALUES_USER;
if (!_nm_keyfile_equals (priv_old->keyfile_intern, priv_new->keyfile_intern, TRUE))
changes |= NM_CONFIG_CHANGE_VALUES | NM_CONFIG_CHANGE_VALUES_INTERN;
if ( g_strcmp0 (nm_config_data_get_config_main_file (old_data), nm_config_data_get_config_main_file (new_data)) != 0
|| g_strcmp0 (nm_config_data_get_config_description (old_data), nm_config_data_get_config_description (new_data)) != 0)
changes |= NM_CONFIG_CHANGE_CONFIG_FILES;
if ( nm_config_data_get_connectivity_enabled (old_data) != nm_config_data_get_connectivity_enabled (new_data)
|| nm_config_data_get_connectivity_interval (old_data) != nm_config_data_get_connectivity_interval (new_data)
|| g_strcmp0 (nm_config_data_get_connectivity_uri (old_data), nm_config_data_get_connectivity_uri (new_data))
|| g_strcmp0 (nm_config_data_get_connectivity_response (old_data), nm_config_data_get_connectivity_response (new_data)))
changes |= NM_CONFIG_CHANGE_CONNECTIVITY;
if ( nm_utils_g_slist_strlist_cmp (priv_old->no_auto_default.specs, priv_new->no_auto_default.specs) != 0
|| nm_utils_g_slist_strlist_cmp (priv_old->no_auto_default.specs_config, priv_new->no_auto_default.specs_config) != 0)
changes |= NM_CONFIG_CHANGE_NO_AUTO_DEFAULT;
if (g_strcmp0 (nm_config_data_get_dns_mode (old_data), nm_config_data_get_dns_mode (new_data)))
changes |= NM_CONFIG_CHANGE_DNS_MODE;
if (g_strcmp0 (nm_config_data_get_rc_manager (old_data), nm_config_data_get_rc_manager (new_data)))
changes |= NM_CONFIG_CHANGE_RC_MANAGER;
if (!global_dns_equal (priv_old->global_dns, priv_new->global_dns))
changes |= NM_CONFIG_CHANGE_GLOBAL_DNS_CONFIG;
nm_assert (!NM_FLAGS_ANY (changes, NM_CONFIG_CHANGE_CAUSES));
return changes;
}
/*****************************************************************************/
void
nm_config_data_get_warnings (const NMConfigData *self,
GPtrArray *warnings)
{
gboolean invalid;
nm_assert (NM_IS_CONFIG_DATA (self));
nm_assert (warnings);
_config_data_get_main_auth_polkit (self, &invalid);
if (invalid) {
g_ptr_array_add (warnings,
g_strdup_printf ("invalid setting for %s.%s (should be one of \"true\", \"false\", \"root-only\")",
NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_AUTH_POLKIT));
}
}
/*****************************************************************************/
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NMConfigData *self = NM_CONFIG_DATA (object);
switch (prop_id) {
case PROP_CONFIG_MAIN_FILE:
g_value_set_string (value, nm_config_data_get_config_main_file (self));
break;
case PROP_CONFIG_DESCRIPTION:
g_value_set_string (value, nm_config_data_get_config_description (self));
break;
case PROP_CONNECTIVITY_ENABLED:
g_value_set_boolean (value, nm_config_data_get_connectivity_enabled (self));
break;
case PROP_CONNECTIVITY_URI:
g_value_set_string (value, nm_config_data_get_connectivity_uri (self));
break;
case PROP_CONNECTIVITY_INTERVAL:
g_value_set_uint (value, nm_config_data_get_connectivity_interval (self));
break;
case PROP_CONNECTIVITY_RESPONSE:
g_value_set_string (value, nm_config_data_get_connectivity_response (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
NMConfigData *self = NM_CONFIG_DATA (object);
NMConfigDataPrivate *priv = NM_CONFIG_DATA_GET_PRIVATE (self);
switch (prop_id) {
case PROP_CONFIG_MAIN_FILE:
/* construct-only */
priv->config_main_file = g_value_dup_string (value);
break;
case PROP_CONFIG_DESCRIPTION:
/* construct-only */
priv->config_description = g_value_dup_string (value);
break;
case PROP_KEYFILE_USER:
/* construct-only */
priv->keyfile_user = g_value_dup_boxed (value);
if ( priv->keyfile_user
&& !_nm_keyfile_has_values (priv->keyfile_user)) {
g_key_file_unref (priv->keyfile_user);
priv->keyfile_user = NULL;
}
break;
case PROP_KEYFILE_INTERN:
/* construct-only */
priv->keyfile_intern = g_value_dup_boxed (value);
if ( priv->keyfile_intern
&& !_nm_keyfile_has_values (priv->keyfile_intern)) {
g_key_file_unref (priv->keyfile_intern);
priv->keyfile_intern = NULL;
}
break;
case PROP_NO_AUTO_DEFAULT:
/* construct-only */
{
const char *const*value_arr_orig = g_value_get_boxed (value);
gs_free const char **value_arr = NULL;
GSList *specs = NULL;
gsize i, j;
gsize len;
len = NM_PTRARRAY_LEN (value_arr_orig);
/* sort entries, remove duplicates and empty words. */
value_arr = len == 0
? NULL
: nm_memdup (value_arr_orig, sizeof (const char *) * (len + 1));
nm_utils_strv_sort (value_arr, len);
_nm_utils_strv_cleanup ((char **) value_arr, FALSE, TRUE, TRUE);
len = NM_PTRARRAY_LEN (value_arr);
j = 0;
for (i = 0; i < len; i++) {
const char *s = value_arr[i];
gboolean is_mac;
char *spec;
if (NM_STR_HAS_PREFIX (s, NM_MATCH_SPEC_INTERFACE_NAME_TAG"="))
is_mac = FALSE;
else if (nm_utils_hwaddr_valid (s, -1))
is_mac = TRUE;
else {
/* we drop all lines that we don't understand. */
continue;
}
value_arr[j++] = s;
spec = is_mac
? g_strdup_printf (NM_MATCH_SPEC_MAC_TAG"%s", s)
: g_strdup (s);
specs = g_slist_prepend (specs, spec);
}
priv->no_auto_default.arr = nm_utils_strv_dup (value_arr, j, TRUE);
priv->no_auto_default.specs = g_slist_reverse (specs);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/*****************************************************************************/
static void
nm_config_data_init (NMConfigData *self)
{
}
static void
constructed (GObject *object)
{
NMConfigData *self = NM_CONFIG_DATA (object);
NMConfigDataPrivate *priv = NM_CONFIG_DATA_GET_PRIVATE (self);
char *str;
priv->keyfile = _merge_keyfiles (priv->keyfile_user, priv->keyfile_intern);
priv->connection_infos = _match_section_infos_construct (priv->keyfile, NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION);
priv->device_infos = _match_section_infos_construct (priv->keyfile, NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE);
priv->connectivity.enabled = nm_config_keyfile_get_boolean (priv->keyfile,
NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY,
NM_CONFIG_KEYFILE_KEY_CONNECTIVITY_ENABLED,
TRUE);
priv->connectivity.uri = nm_strstrip (g_key_file_get_string (priv->keyfile,
NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY,
NM_CONFIG_KEYFILE_KEY_CONNECTIVITY_URI,
NULL));
priv->connectivity.response = g_key_file_get_string (priv->keyfile,
NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY,
NM_CONFIG_KEYFILE_KEY_CONNECTIVITY_RESPONSE,
NULL);
str = nm_config_keyfile_get_value (priv->keyfile,
NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_AUTOCONNECT_RETRIES_DEFAULT,
NM_CONFIG_GET_VALUE_NONE);
priv->autoconnect_retries_default = _nm_utils_ascii_str_to_int64 (str, 10, 0, G_MAXINT32, 4);
g_free (str);
/* On missing config value, fallback to 300. On invalid value, disable connectivity checking by setting
* the interval to zero. */
str = g_key_file_get_string (priv->keyfile,
NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY,
NM_CONFIG_KEYFILE_KEY_CONNECTIVITY_INTERVAL,
NULL);
priv->connectivity.interval = _nm_utils_ascii_str_to_int64 (str, 10, 0, G_MAXUINT, NM_CONFIG_DEFAULT_CONNECTIVITY_INTERVAL);
g_free (str);
priv->dns_mode = nm_strstrip (g_key_file_get_string (priv->keyfile,
NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_DNS,
NULL));
priv->rc_manager = nm_strstrip (g_key_file_get_string (priv->keyfile,
NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_RC_MANAGER,
NULL));
priv->systemd_resolved = nm_config_keyfile_get_boolean (priv->keyfile,
NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_SYSTEMD_RESOLVED,
TRUE);
priv->ignore_carrier = nm_config_get_match_spec (priv->keyfile,
NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_IGNORE_CARRIER,
NULL);
priv->assume_ipv6ll_only = nm_config_get_match_spec (priv->keyfile,
NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_ASSUME_IPV6LL_ONLY,
NULL);
priv->no_auto_default.specs_config = nm_config_get_match_spec (priv->keyfile,
NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_NO_AUTO_DEFAULT,
NULL);
priv->global_dns = load_global_dns (priv->keyfile_user, FALSE);
if (!priv->global_dns)
priv->global_dns = load_global_dns (priv->keyfile_intern, TRUE);
G_OBJECT_CLASS (nm_config_data_parent_class)->constructed (object);
}
NMConfigData *
nm_config_data_new (const char *config_main_file,
const char *config_description,
const char *const*no_auto_default,
GKeyFile *keyfile_user,
GKeyFile *keyfile_intern)
{
return g_object_new (NM_TYPE_CONFIG_DATA,
NM_CONFIG_DATA_CONFIG_MAIN_FILE, config_main_file,
NM_CONFIG_DATA_CONFIG_DESCRIPTION, config_description,
NM_CONFIG_DATA_KEYFILE_USER, keyfile_user,
NM_CONFIG_DATA_KEYFILE_INTERN, keyfile_intern,
NM_CONFIG_DATA_NO_AUTO_DEFAULT, no_auto_default,
NULL);
}
NMConfigData *
nm_config_data_new_update_keyfile_intern (const NMConfigData *base, GKeyFile *keyfile_intern)
{
const NMConfigDataPrivate *priv = NM_CONFIG_DATA_GET_PRIVATE (base);
return g_object_new (NM_TYPE_CONFIG_DATA,
NM_CONFIG_DATA_CONFIG_MAIN_FILE, priv->config_main_file,
NM_CONFIG_DATA_CONFIG_DESCRIPTION, priv->config_description,
NM_CONFIG_DATA_KEYFILE_USER, priv->keyfile_user, /* the keyfile is unchanged. It's safe to share it. */
NM_CONFIG_DATA_KEYFILE_INTERN, keyfile_intern,
NM_CONFIG_DATA_NO_AUTO_DEFAULT, priv->no_auto_default.arr,
NULL);
}
NMConfigData *
nm_config_data_new_update_no_auto_default (const NMConfigData *base,
const char *const*no_auto_default)
{
const NMConfigDataPrivate *priv = NM_CONFIG_DATA_GET_PRIVATE (base);
return g_object_new (NM_TYPE_CONFIG_DATA,
NM_CONFIG_DATA_CONFIG_MAIN_FILE, priv->config_main_file,
NM_CONFIG_DATA_CONFIG_DESCRIPTION, priv->config_description,
NM_CONFIG_DATA_KEYFILE_USER, priv->keyfile_user, /* the keyfile is unchanged. It's safe to share it. */
NM_CONFIG_DATA_KEYFILE_INTERN, priv->keyfile_intern,
NM_CONFIG_DATA_NO_AUTO_DEFAULT, no_auto_default,
NULL);
}
static void
finalize (GObject *gobject)
{
NMConfigDataPrivate *priv = NM_CONFIG_DATA_GET_PRIVATE (gobject);
g_free (priv->config_main_file);
g_free (priv->config_description);
g_free (priv->connectivity.uri);
g_free (priv->connectivity.response);
g_slist_free_full (priv->no_auto_default.specs, g_free);
g_slist_free_full (priv->no_auto_default.specs_config, g_free);
g_strfreev (priv->no_auto_default.arr);
g_free (priv->dns_mode);
g_free (priv->rc_manager);
g_slist_free_full (priv->ignore_carrier, g_free);
g_slist_free_full (priv->assume_ipv6ll_only, g_free);
nm_global_dns_config_free (priv->global_dns);
_match_section_infos_free (priv->connection_infos);
_match_section_infos_free (priv->device_infos);
g_key_file_unref (priv->keyfile);
if (priv->keyfile_user)
g_key_file_unref (priv->keyfile_user);
if (priv->keyfile_intern)
g_key_file_unref (priv->keyfile_intern);
G_OBJECT_CLASS (nm_config_data_parent_class)->finalize (gobject);
}
static void
nm_config_data_class_init (NMConfigDataClass *config_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
object_class->constructed = constructed;
object_class->finalize = finalize;
object_class->get_property = get_property;
object_class->set_property = set_property;
obj_properties[PROP_CONFIG_MAIN_FILE] =
g_param_spec_string (NM_CONFIG_DATA_CONFIG_MAIN_FILE, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_CONFIG_DESCRIPTION] =
g_param_spec_string (NM_CONFIG_DATA_CONFIG_DESCRIPTION, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_KEYFILE_USER] =
g_param_spec_boxed (NM_CONFIG_DATA_KEYFILE_USER, "", "",
G_TYPE_KEY_FILE,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_KEYFILE_INTERN] =
g_param_spec_boxed (NM_CONFIG_DATA_KEYFILE_INTERN, "", "",
G_TYPE_KEY_FILE,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_CONNECTIVITY_ENABLED] =
g_param_spec_string (NM_CONFIG_DATA_CONNECTIVITY_ENABLED, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_CONNECTIVITY_URI] =
g_param_spec_string (NM_CONFIG_DATA_CONNECTIVITY_URI, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_CONNECTIVITY_INTERVAL] =
g_param_spec_uint (NM_CONFIG_DATA_CONNECTIVITY_INTERVAL, "", "",
0, G_MAXUINT, 0,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_CONNECTIVITY_RESPONSE] =
g_param_spec_string (NM_CONFIG_DATA_CONNECTIVITY_RESPONSE, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_NO_AUTO_DEFAULT] =
g_param_spec_boxed (NM_CONFIG_DATA_NO_AUTO_DEFAULT, "", "",
G_TYPE_STRV,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
}
|