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
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Dan Williams <dcbw@redhat.com>
* Søren Sandmann <sandmann@daimi.au.dk>
* Copyright (C) 2007 - 2011 Red Hat, Inc.
*/
#include "src/core/nm-default-daemon.h"
#include "nms-ifcfg-rh-plugin.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "libnm-std-aux/c-list-util.h"
#include "libnm-glib-aux/nm-c-list.h"
#include "libnm-glib-aux/nm-io-utils.h"
#include "libnm-std-aux/nm-dbus-compat.h"
#include "nm-utils.h"
#include "libnm-core-intern/nm-core-internal.h"
#include "nm-config.h"
#include "nm-dbus-manager.h"
#include "settings/nm-settings-plugin.h"
#include "settings/nm-settings-utils.h"
#include "NetworkManagerUtils.h"
#include "nms-ifcfg-rh-storage.h"
#include "nms-ifcfg-rh-common.h"
#include "nms-ifcfg-rh-utils.h"
#include "nms-ifcfg-rh-reader.h"
#include "nms-ifcfg-rh-writer.h"
#define IFCFGRH1_BUS_NAME "com.redhat.ifcfgrh1"
#define IFCFGRH1_OBJECT_PATH "/com/redhat/ifcfgrh1"
#define IFCFGRH1_IFACE1_NAME "com.redhat.ifcfgrh1"
#define IFCFGRH1_IFACE1_METHOD_GET_IFCFG_DETAILS "GetIfcfgDetails"
/*****************************************************************************/
typedef struct {
NMConfig *config;
struct {
GDBusConnection *connection;
GCancellable *cancellable;
gulong signal_id;
guint regist_id;
} dbus;
NMSettUtilStorages storages;
GHashTable *unmanaged_specs;
GHashTable *unrecognized_specs;
} NMSIfcfgRHPluginPrivate;
struct _NMSIfcfgRHPlugin {
NMSettingsPlugin parent;
NMSIfcfgRHPluginPrivate _priv;
};
struct _NMSIfcfgRHPluginClass {
NMSettingsPluginClass parent;
};
G_DEFINE_TYPE(NMSIfcfgRHPlugin, nms_ifcfg_rh_plugin, NM_TYPE_SETTINGS_PLUGIN)
#define NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self) \
_NM_GET_PRIVATE(self, NMSIfcfgRHPlugin, NMS_IS_IFCFG_RH_PLUGIN, NMSettingsPlugin)
/*****************************************************************************/
#define _NMLOG_DOMAIN LOGD_SETTINGS
#define _NMLOG(level, ...) \
G_STMT_START \
{ \
nm_log((level), \
(_NMLOG_DOMAIN), \
NULL, \
NULL, \
"%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
"ifcfg-rh: " _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
} \
G_STMT_END
/*****************************************************************************/
static void _unhandled_specs_reset(NMSIfcfgRHPlugin *self);
static void _unhandled_specs_merge_storages(NMSIfcfgRHPlugin *self, NMSettUtilStorages *storages);
/*****************************************************************************/
static void
nm_assert_self(NMSIfcfgRHPlugin *self, gboolean unhandled_specs_consistent)
{
nm_assert(NMS_IS_IFCFG_RH_PLUGIN(self));
#if NM_MORE_ASSERTS > 5
{
NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
NMSIfcfgRHStorage *storage;
gsize n_uuid;
gs_unref_hashtable GHashTable *h_unmanaged = NULL;
gs_unref_hashtable GHashTable *h_unrecognized = NULL;
nm_assert(g_hash_table_size(priv->storages.idx_by_filename)
== c_list_length(&priv->storages._storage_lst_head));
h_unmanaged = g_hash_table_new(nm_str_hash, g_str_equal);
h_unrecognized = g_hash_table_new(nm_str_hash, g_str_equal);
n_uuid = 0;
c_list_for_each_entry (storage, &priv->storages._storage_lst_head, parent._storage_lst) {
const char *uuid;
const char *filename;
filename = nms_ifcfg_rh_storage_get_filename(storage);
nm_assert(filename && NM_STR_HAS_PREFIX(filename, IFCFG_DIR "/"));
uuid = nms_ifcfg_rh_storage_get_uuid_opt(storage);
nm_assert((!!uuid) + (!!storage->unmanaged_spec) + (!!storage->unrecognized_spec) == 1);
nm_assert(storage
== nm_sett_util_storages_lookup_by_filename(&priv->storages, filename));
if (uuid) {
NMSettUtilStorageByUuidHead *sbuh;
NMSettUtilStorageByUuidHead *sbuh2;
if (storage->connection)
nm_assert(nm_streq0(nm_connection_get_uuid(storage->connection), uuid));
if (!g_hash_table_lookup_extended(priv->storages.idx_by_uuid,
&uuid,
(gpointer *) &sbuh,
(gpointer *) &sbuh2))
nm_assert_not_reached();
nm_assert(sbuh);
nm_assert(nm_streq(uuid, sbuh->uuid));
nm_assert(sbuh == sbuh2);
nm_assert(c_list_contains(&sbuh->_storage_by_uuid_lst_head,
&storage->parent._storage_by_uuid_lst));
if (c_list_first(&sbuh->_storage_by_uuid_lst_head)
== &storage->parent._storage_by_uuid_lst)
n_uuid++;
} else if (storage->unmanaged_spec) {
nm_assert(strlen(storage->unmanaged_spec) > 0);
g_hash_table_add(h_unmanaged, storage->unmanaged_spec);
} else if (storage->unrecognized_spec) {
nm_assert(strlen(storage->unrecognized_spec) > 0);
g_hash_table_add(h_unrecognized, storage->unrecognized_spec);
} else
nm_assert_not_reached();
nm_assert(!storage->connection);
}
nm_assert(g_hash_table_size(priv->storages.idx_by_uuid) == n_uuid);
if (unhandled_specs_consistent) {
nm_assert(nm_utils_hashtable_same_keys(h_unmanaged, priv->unmanaged_specs));
nm_assert(nm_utils_hashtable_same_keys(h_unrecognized, priv->unrecognized_specs));
}
}
#endif
}
/*****************************************************************************/
static NMSIfcfgRHStorage *
_load_file(NMSIfcfgRHPlugin *self, const char *filename, GError **error)
{
NMSIfcfgRHStorage *ret = NULL;
gs_unref_object NMConnection *connection = NULL;
gs_free_error GError *load_error = NULL;
gs_free char *unhandled_spec = NULL;
gboolean load_error_ignore;
struct stat st;
if (stat(filename, &st) != 0) {
int errsv = errno;
if (error) {
nm_utils_error_set_errno(error, errsv, "failure to stat file \%s\": %s", filename);
} else
_LOGT("load[%s]: failure to stat file: %s", filename, nm_strerror_native(errsv));
return NULL;
}
connection = connection_from_file(filename, &unhandled_spec, &load_error, &load_error_ignore);
if (load_error) {
if (error) {
nm_utils_error_set(error,
NM_UTILS_ERROR_UNKNOWN,
"failure to read file \"%s\": %s",
filename,
load_error->message);
} else {
_NMLOG(load_error_ignore ? LOGL_TRACE : LOGL_WARN,
"load[%s]: failure to read file: %s",
filename,
load_error->message);
}
return NULL;
}
if (unhandled_spec) {
const char *unmanaged_spec;
const char *unrecognized_spec;
if (!nms_ifcfg_rh_utils_parse_unhandled_spec(unhandled_spec,
&unmanaged_spec,
&unrecognized_spec)) {
nm_utils_error_set(error,
NM_UTILS_ERROR_UNKNOWN,
"invalid unhandled spec \"%s\"",
unhandled_spec);
nm_assert_not_reached();
return NULL;
}
ret = nms_ifcfg_rh_storage_new_unhandled(self, filename, unmanaged_spec, unrecognized_spec);
} else {
ret = nms_ifcfg_rh_storage_new_connection(self,
filename,
g_steal_pointer(&connection),
&st.st_mtim);
}
return ret;
}
static void
_load_dir(NMSIfcfgRHPlugin *self, NMSettUtilStorages *storages)
{
gs_unref_hashtable GHashTable *dupl_filenames = NULL;
gs_free_error GError *local = NULL;
const char *f_filename;
GDir *dir;
dir = g_dir_open(IFCFG_DIR, 0, &local);
if (!dir) {
_LOGT("Could not read directory '%s': %s", IFCFG_DIR, local->message);
return;
}
dupl_filenames = g_hash_table_new_full(nm_str_hash, g_str_equal, NULL, g_free);
while ((f_filename = g_dir_read_name(dir))) {
gs_free char *full_path = NULL;
NMSIfcfgRHStorage *storage;
char *full_filename;
full_path = g_build_filename(IFCFG_DIR, f_filename, NULL);
full_filename = utils_detect_ifcfg_path(full_path, TRUE);
if (!full_filename)
continue;
if (!g_hash_table_add(dupl_filenames, full_filename))
continue;
nm_assert(!nm_sett_util_storages_lookup_by_filename(storages, full_filename));
storage = _load_file(self, full_filename, NULL);
if (storage)
nm_sett_util_storages_add_take(storages, storage);
}
g_dir_close(dir);
}
static void
_storages_consolidate(NMSIfcfgRHPlugin *self,
NMSettUtilStorages *storages_new,
gboolean replace_all,
GHashTable *storages_replaced,
NMSettingsPluginConnectionLoadCallback callback,
gpointer user_data)
{
NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
CList lst_conn_info_deleted = C_LIST_INIT(lst_conn_info_deleted);
gs_unref_ptrarray GPtrArray *storages_modified = NULL;
CList storages_deleted;
NMSIfcfgRHStorage *storage_safe;
NMSIfcfgRHStorage *storage_new;
NMSIfcfgRHStorage *storage_old;
NMSIfcfgRHStorage *storage;
guint i;
/* when we reload all files, we must signal add/update/modify of profiles one-by-one.
* NMSettings then goes ahead and emits further signals and a lot of things happen.
*
* So, first, emit an update of the unmanaged/unrecognized specs that contains *all*
* the unmanaged/unrecognized devices from before and after. Since both unmanaged/unrecognized
* specs have the meaning of "not doing something", it makes sense that we temporarily
* disable that action for the sum of before and after. */
_unhandled_specs_merge_storages(self, storages_new);
storages_modified = g_ptr_array_new_with_free_func(g_object_unref);
c_list_init(&storages_deleted);
c_list_for_each_entry (storage_old, &priv->storages._storage_lst_head, parent._storage_lst)
storage_old->dirty = TRUE;
c_list_for_each_entry_safe (storage_new,
storage_safe,
&storages_new->_storage_lst_head,
parent._storage_lst) {
storage_old = nm_sett_util_storages_lookup_by_filename(
&priv->storages,
nms_ifcfg_rh_storage_get_filename(storage_new));
nm_sett_util_storages_steal(storages_new, storage_new);
if (!storage_old || !nms_ifcfg_rh_storage_equal_type(storage_new, storage_old)) {
if (storage_old) {
nm_sett_util_storages_steal(&priv->storages, storage_old);
if (nms_ifcfg_rh_storage_get_uuid_opt(storage_old))
c_list_link_tail(&storages_deleted, &storage_old->parent._storage_lst);
else
nms_ifcfg_rh_storage_destroy(storage_old);
}
storage_new->dirty = FALSE;
nm_sett_util_storages_add_take(&priv->storages, storage_new);
g_ptr_array_add(storages_modified, g_object_ref(storage_new));
continue;
}
storage_old->dirty = FALSE;
nms_ifcfg_rh_storage_copy_content(storage_old, storage_new);
nms_ifcfg_rh_storage_destroy(storage_new);
g_ptr_array_add(storages_modified, g_object_ref(storage_old));
}
c_list_for_each_entry_safe (storage_old,
storage_safe,
&priv->storages._storage_lst_head,
parent._storage_lst) {
if (!storage_old->dirty)
continue;
if (replace_all
|| (storages_replaced && g_hash_table_contains(storages_replaced, storage_old))) {
nm_sett_util_storages_steal(&priv->storages, storage_old);
if (nms_ifcfg_rh_storage_get_uuid_opt(storage_old))
c_list_link_tail(&storages_deleted, &storage_old->parent._storage_lst);
else
nms_ifcfg_rh_storage_destroy(storage_old);
}
}
/* raise events. */
for (i = 0; i < storages_modified->len; i++) {
storage = storages_modified->pdata[i];
storage->dirty = TRUE;
}
for (i = 0; i < storages_modified->len; i++) {
gs_unref_object NMConnection *connection = NULL;
storage = storages_modified->pdata[i];
if (!storage->dirty) {
/* the entry is no longer dirty. In the meantime we already emitted
* another signal for it. */
continue;
}
storage->dirty = FALSE;
if (storage
!= nm_sett_util_storages_lookup_by_filename(
&priv->storages,
nms_ifcfg_rh_storage_get_filename(storage))) {
/* hm? The profile was deleted in the meantime? That is only possible
* if the signal handler called again into the plugin. In any case, the event
* was already emitted. Skip. */
continue;
}
connection = nms_ifcfg_rh_storage_steal_connection(storage);
if (!connection) {
nm_assert(!nms_ifcfg_rh_storage_get_uuid_opt(storage));
continue;
}
nm_assert(NM_IS_CONNECTION(connection));
nm_assert(nms_ifcfg_rh_storage_get_uuid_opt(storage));
callback(NM_SETTINGS_PLUGIN(self), NM_SETTINGS_STORAGE(storage), connection, user_data);
}
while (
(storage = c_list_first_entry(&storages_deleted, NMSIfcfgRHStorage, parent._storage_lst))) {
c_list_unlink(&storage->parent._storage_lst);
callback(NM_SETTINGS_PLUGIN(self), NM_SETTINGS_STORAGE(storage), NULL, user_data);
nms_ifcfg_rh_storage_destroy(storage);
}
}
/*****************************************************************************/
static void
load_connections(NMSettingsPlugin *plugin,
NMSettingsPluginConnectionLoadEntry *entries,
gsize n_entries,
NMSettingsPluginConnectionLoadCallback callback,
gpointer user_data)
{
NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(plugin);
NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
nm_auto_clear_sett_util_storages NMSettUtilStorages storages_new =
NM_SETT_UTIL_STORAGES_INIT(storages_new, nms_ifcfg_rh_storage_destroy);
gs_unref_hashtable GHashTable *dupl_filenames = NULL;
gs_unref_hashtable GHashTable *storages_replaced = NULL;
gs_unref_hashtable GHashTable *loaded_uuids = NULL;
const char *loaded_uuid;
GHashTableIter h_iter;
gsize i;
if (n_entries == 0)
return;
dupl_filenames = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, NULL);
loaded_uuids = g_hash_table_new(nm_str_hash, g_str_equal);
storages_replaced = g_hash_table_new_full(nm_direct_hash, NULL, g_object_unref, NULL);
for (i = 0; i < n_entries; i++) {
NMSettingsPluginConnectionLoadEntry *const entry = &entries[i];
gs_free_error GError *local = NULL;
const char *full_filename;
const char *uuid;
gs_free char *full_filename_keep = NULL;
NMSettingsPluginConnectionLoadEntry *dupl_content_entry;
gs_unref_object NMSIfcfgRHStorage *storage = NULL;
if (entry->handled)
continue;
if (entry->filename[0] != '/')
continue;
full_filename_keep = utils_detect_ifcfg_path(entry->filename, FALSE);
if (!full_filename_keep) {
if (nm_utils_file_is_in_path(entry->filename, IFCFG_DIR)) {
nm_utils_error_set(&entry->error,
NM_UTILS_ERROR_UNKNOWN,
("path is not a valid name for an ifcfg-rh file"));
entry->handled = TRUE;
}
continue;
}
if ((dupl_content_entry = g_hash_table_lookup(dupl_filenames, full_filename_keep))) {
/* we already visited this file. */
entry->handled = dupl_content_entry->handled;
if (dupl_content_entry->error) {
g_set_error_literal(&entry->error,
dupl_content_entry->error->domain,
dupl_content_entry->error->code,
dupl_content_entry->error->message);
}
continue;
}
entry->handled = TRUE;
full_filename = full_filename_keep;
if (!g_hash_table_insert(dupl_filenames, g_steal_pointer(&full_filename_keep), entry))
nm_assert_not_reached();
storage = _load_file(self, full_filename, &local);
if (!storage) {
if (nm_utils_file_stat(full_filename, NULL) == -ENOENT) {
NMSIfcfgRHStorage *storage2;
/* the file does not exist. We take that as indication to unload the file
* that was previously loaded... */
storage2 = nm_sett_util_storages_lookup_by_filename(&priv->storages, full_filename);
if (storage2)
g_hash_table_add(storages_replaced, g_object_ref(storage2));
continue;
}
g_propagate_error(&entry->error, g_steal_pointer(&local));
continue;
}
uuid = nms_ifcfg_rh_storage_get_uuid_opt(storage);
if (uuid)
g_hash_table_add(loaded_uuids, (char *) uuid);
nm_sett_util_storages_add_take(&storages_new, g_steal_pointer(&storage));
}
/* now we visit all UUIDs that are about to change... */
g_hash_table_iter_init(&h_iter, loaded_uuids);
while (g_hash_table_iter_next(&h_iter, (gpointer *) &loaded_uuid, NULL)) {
NMSIfcfgRHStorage *storage;
NMSettUtilStorageByUuidHead *sbuh;
sbuh = nm_sett_util_storages_lookup_by_uuid(&priv->storages, loaded_uuid);
if (!sbuh)
continue;
c_list_for_each_entry (storage,
&sbuh->_storage_by_uuid_lst_head,
parent._storage_by_uuid_lst) {
const char *full_filename = nms_ifcfg_rh_storage_get_filename(storage);
gs_unref_object NMSIfcfgRHStorage *storage_new = NULL;
gs_free_error GError *local = NULL;
if (g_hash_table_contains(dupl_filenames, full_filename)) {
/* already re-loaded. */
continue;
}
/* @storage has a UUID that was just loaded from disk, but we have an entry in cache.
* Reload that file too despite not being told to do so. The reason is to get
* the latest file timestamp so that we get the priorities right. */
storage_new = _load_file(self, full_filename, &local);
if (storage_new
&& !nm_streq0(loaded_uuid, nms_ifcfg_rh_storage_get_uuid_opt(storage_new))) {
/* the file now references a different UUID. We are not told to reload
* that file, so this means the existing storage (with the previous
* filename and UUID tuple) is no longer valid. */
g_clear_object(&storage_new);
}
g_hash_table_add(storages_replaced, g_object_ref(storage));
if (storage_new)
nm_sett_util_storages_add_take(&storages_new, g_steal_pointer(&storage_new));
}
}
nm_clear_pointer(&loaded_uuids, g_hash_table_destroy);
nm_clear_pointer(&dupl_filenames, g_hash_table_destroy);
_storages_consolidate(self, &storages_new, FALSE, storages_replaced, callback, user_data);
}
static void
reload_connections(NMSettingsPlugin *plugin,
NMSettingsPluginConnectionLoadCallback callback,
gpointer user_data)
{
NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(plugin);
nm_auto_clear_sett_util_storages NMSettUtilStorages storages_new =
NM_SETT_UTIL_STORAGES_INIT(storages_new, nms_ifcfg_rh_storage_destroy);
nm_assert_self(self, TRUE);
_load_dir(self, &storages_new);
_storages_consolidate(self, &storages_new, TRUE, NULL, callback, user_data);
nm_assert_self(self, FALSE);
}
static void
load_connections_done(NMSettingsPlugin *plugin)
{
NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(plugin);
/* at the beginning of a load, we emit a change signal for unmanaged/unrecognized
* specs that contain the sum of before and after (_unhandled_specs_merge_storages()).
*
* The idea is that while we emit signals about changes to connection, we have
* the sum of all unmanaged/unrecognized devices from before and after.
*
* This if triggered at the end, to reset the specs. */
_unhandled_specs_reset(self);
nm_assert_self(self, TRUE);
}
/*****************************************************************************/
static gboolean
add_connection(NMSettingsPlugin *plugin,
NMConnection *connection,
NMSettingsStorage **out_storage,
NMConnection **out_connection,
GError **error)
{
NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(plugin);
NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
gs_unref_object NMSIfcfgRHStorage *storage = NULL;
gs_unref_object NMConnection *reread = NULL;
gs_free char *full_filename = NULL;
GError *local = NULL;
gboolean reread_same;
struct timespec mtime;
nm_assert_self(self, TRUE);
nm_assert(NM_IS_CONNECTION(connection));
nm_assert(out_storage && !*out_storage);
nm_assert(out_connection && !*out_connection);
if (!nms_ifcfg_rh_writer_write_connection(
connection,
IFCFG_DIR,
NULL,
nm_sett_util_allow_filename_cb,
NM_SETT_UTIL_ALLOW_FILENAME_DATA(&priv->storages, NULL),
&full_filename,
&reread,
&reread_same,
&local)) {
_LOGT("commit: %s (%s): failed to add: %s",
nm_connection_get_uuid(connection),
nm_connection_get_id(connection),
local->message);
g_propagate_error(error, local);
return FALSE;
}
if (!reread || reread_same)
nm_g_object_ref_set(&reread, connection);
nm_assert(full_filename && full_filename[0] == '/');
_LOGT("commit: %s (%s) added as \"%s\"",
nm_connection_get_uuid(reread),
nm_connection_get_id(reread),
full_filename);
storage =
nms_ifcfg_rh_storage_new_connection(self,
full_filename,
g_steal_pointer(&reread),
nm_sett_util_stat_mtime(full_filename, FALSE, &mtime));
nm_sett_util_storages_add_take(&priv->storages, g_object_ref(storage));
*out_connection = nms_ifcfg_rh_storage_steal_connection(storage);
*out_storage = NM_SETTINGS_STORAGE(g_steal_pointer(&storage));
nm_assert_self(self, TRUE);
return TRUE;
}
static gboolean
update_connection(NMSettingsPlugin *plugin,
NMSettingsStorage *storage_x,
NMConnection *connection,
NMSettingsStorage **out_storage,
NMConnection **out_connection,
GError **error)
{
NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(plugin);
NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
NMSIfcfgRHStorage *storage = NMS_IFCFG_RH_STORAGE(storage_x);
const char *full_filename;
const char *uuid;
GError *local = NULL;
gs_unref_object NMConnection *reread = NULL;
gboolean reread_same;
struct timespec mtime;
nm_assert_self(self, TRUE);
nm_assert(NM_IS_CONNECTION(connection));
nm_assert(NMS_IS_IFCFG_RH_STORAGE(storage));
nm_assert(_nm_connection_verify(connection, NULL) == NM_SETTING_VERIFY_SUCCESS);
nm_assert(!error || !*error);
uuid = nms_ifcfg_rh_storage_get_uuid_opt(storage);
nm_assert(uuid && nm_streq0(uuid, nm_connection_get_uuid(connection)));
full_filename = nms_ifcfg_rh_storage_get_filename(storage);
nm_assert(full_filename);
nm_assert(storage == nm_sett_util_storages_lookup_by_filename(&priv->storages, full_filename));
if (!nms_ifcfg_rh_writer_write_connection(
connection,
IFCFG_DIR,
full_filename,
nm_sett_util_allow_filename_cb,
NM_SETT_UTIL_ALLOW_FILENAME_DATA(&priv->storages, full_filename),
NULL,
&reread,
&reread_same,
&local)) {
_LOGT("commit: failure to write %s (%s) to \"%s\": %s",
nm_connection_get_uuid(connection),
nm_connection_get_id(connection),
full_filename,
local->message);
g_propagate_error(error, local);
return FALSE;
}
if (!reread || reread_same)
nm_g_object_ref_set(&reread, connection);
_LOGT("commit: \"%s\": profile %s (%s) written",
full_filename,
uuid,
nm_connection_get_id(connection));
storage->stat_mtime = *nm_sett_util_stat_mtime(full_filename, FALSE, &mtime);
*out_storage = NM_SETTINGS_STORAGE(g_object_ref(storage));
*out_connection = g_steal_pointer(&reread);
nm_assert_self(self, TRUE);
return TRUE;
}
static gboolean
delete_connection(NMSettingsPlugin *plugin, NMSettingsStorage *storage_x, GError **error)
{
NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(plugin);
NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
NMSIfcfgRHStorage *storage = NMS_IFCFG_RH_STORAGE(storage_x);
const char *operation_message;
const char *full_filename;
nm_assert_self(self, TRUE);
nm_assert(!error || !*error);
nm_assert(NMS_IS_IFCFG_RH_STORAGE(storage));
full_filename = nms_ifcfg_rh_storage_get_filename(storage);
nm_assert(full_filename);
nm_assert(nms_ifcfg_rh_storage_get_uuid_opt(storage));
nm_assert(storage == nm_sett_util_storages_lookup_by_filename(&priv->storages, full_filename));
{
gs_free char *keyfile = utils_get_keys_path(full_filename);
gs_free char *routefile = utils_get_route_path(full_filename);
gs_free char *route6file = utils_get_route6_path(full_filename);
const char *const files[] = {full_filename, keyfile, routefile, route6file};
gboolean any_deleted = FALSE;
gboolean any_failure = FALSE;
int i;
for (i = 0; i < G_N_ELEMENTS(files); i++) {
int errsv;
if (unlink(files[i]) == 0) {
any_deleted = TRUE;
continue;
}
errsv = errno;
if (errsv == ENOENT)
continue;
_LOGW("commit: failure to delete file \"%s\": %s", files[i], nm_strerror_native(errsv));
any_failure = TRUE;
}
if (any_failure)
operation_message = "failed to delete files from disk";
else if (any_deleted)
operation_message = "deleted from disk";
else
operation_message = "does not exist on disk";
}
_LOGT("commit: deleted \"%s\", profile %s (%s)",
full_filename,
nms_ifcfg_rh_storage_get_uuid_opt(storage),
operation_message);
nm_sett_util_storages_steal(&priv->storages, storage);
nms_ifcfg_rh_storage_destroy(storage);
nm_assert_self(self, TRUE);
return TRUE;
}
/*****************************************************************************/
static void
_unhandled_specs_reset(NMSIfcfgRHPlugin *self)
{
NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
gs_unref_hashtable GHashTable *unmanaged_specs = NULL;
gs_unref_hashtable GHashTable *unrecognized_specs = NULL;
NMSIfcfgRHStorage *storage;
unmanaged_specs = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, NULL);
unrecognized_specs = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, NULL);
c_list_for_each_entry (storage, &priv->storages._storage_lst_head, parent._storage_lst) {
if (storage->unmanaged_spec)
g_hash_table_add(unmanaged_specs, g_strdup(storage->unmanaged_spec));
if (storage->unrecognized_spec)
g_hash_table_add(unrecognized_specs, g_strdup(storage->unrecognized_spec));
}
if (!nm_utils_hashtable_same_keys(unmanaged_specs, priv->unmanaged_specs)) {
g_hash_table_unref(priv->unmanaged_specs);
priv->unmanaged_specs = g_steal_pointer(&unmanaged_specs);
}
if (!nm_utils_hashtable_same_keys(unrecognized_specs, priv->unrecognized_specs)) {
g_hash_table_unref(priv->unrecognized_specs);
priv->unrecognized_specs = g_steal_pointer(&unrecognized_specs);
}
if (!unmanaged_specs)
_nm_settings_plugin_emit_signal_unmanaged_specs_changed(NM_SETTINGS_PLUGIN(self));
if (!unrecognized_specs)
_nm_settings_plugin_emit_signal_unrecognized_specs_changed(NM_SETTINGS_PLUGIN(self));
}
static void
_unhandled_specs_merge_storages(NMSIfcfgRHPlugin *self, NMSettUtilStorages *storages)
{
NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
gboolean unmanaged_changed = FALSE;
gboolean unrecognized_changed = FALSE;
NMSIfcfgRHStorage *storage;
c_list_for_each_entry (storage, &storages->_storage_lst_head, parent._storage_lst) {
if (storage->unmanaged_spec
&& !g_hash_table_contains(priv->unmanaged_specs, storage->unmanaged_spec)) {
unmanaged_changed = TRUE;
g_hash_table_add(priv->unmanaged_specs, g_strdup(storage->unmanaged_spec));
}
if (storage->unrecognized_spec
&& !g_hash_table_contains(priv->unrecognized_specs, storage->unrecognized_spec)) {
unrecognized_changed = TRUE;
g_hash_table_add(priv->unrecognized_specs, g_strdup(storage->unrecognized_spec));
}
}
if (unmanaged_changed)
_nm_settings_plugin_emit_signal_unmanaged_specs_changed(NM_SETTINGS_PLUGIN(self));
if (unrecognized_changed)
_nm_settings_plugin_emit_signal_unrecognized_specs_changed(NM_SETTINGS_PLUGIN(self));
}
static GSList *
_unhandled_specs_from_hashtable(GHashTable *hash)
{
gs_free const char **keys = NULL;
GSList *list = NULL;
guint i, l;
keys = nm_strdict_get_keys(hash, TRUE, &l);
for (i = l; i > 0;) {
i--;
list = g_slist_prepend(list, g_strdup(keys[i]));
}
return list;
}
static GSList *
get_unmanaged_specs(NMSettingsPlugin *plugin)
{
return _unhandled_specs_from_hashtable(
NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(plugin)->unmanaged_specs);
}
static GSList *
get_unrecognized_specs(NMSettingsPlugin *plugin)
{
return _unhandled_specs_from_hashtable(
NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(plugin)->unrecognized_specs);
}
/*****************************************************************************/
static void
impl_ifcfgrh_get_ifcfg_details(NMSIfcfgRHPlugin *self,
GDBusMethodInvocation *context,
const char *in_ifcfg)
{
NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
gs_free char *ifcfg_path = NULL;
NMSIfcfgRHStorage *storage;
const char *uuid;
const char *path;
if (in_ifcfg[0] != '/') {
g_dbus_method_invocation_return_error(context,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_INVALID_CONNECTION,
"ifcfg path '%s' is not absolute",
in_ifcfg);
return;
}
ifcfg_path = utils_detect_ifcfg_path(in_ifcfg, TRUE);
if (!ifcfg_path) {
g_dbus_method_invocation_return_error(context,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_INVALID_CONNECTION,
"ifcfg path '%s' is not an ifcfg base file",
in_ifcfg);
return;
}
storage = nm_sett_util_storages_lookup_by_filename(&priv->storages, ifcfg_path);
if (!storage) {
g_dbus_method_invocation_return_error(context,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_INVALID_CONNECTION,
"ifcfg file '%s' unknown",
in_ifcfg);
return;
}
uuid = nms_ifcfg_rh_storage_get_uuid_opt(storage);
if (!uuid) {
g_dbus_method_invocation_return_error(context,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_INVALID_CONNECTION,
"ifcfg file '%s' not managed by NetworkManager",
in_ifcfg);
return;
}
/* It is ugly that the ifcfg-rh plugin needs to call back into NMSettings this
* way.
* There are alternatives (like invoking a signal), but they are all significant
* extra code (and performance overhead). So the quick and dirty solution here
* is likely to be simpler than getting this right (also from point of readability!).
*/
path = nm_settings_get_dbus_path_for_uuid(nm_settings_get(), uuid);
if (!path) {
g_dbus_method_invocation_return_error(context,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_FAILED,
"unable to get the connection D-Bus path");
return;
}
g_dbus_method_invocation_return_value(context, g_variant_new("(so)", uuid, path));
}
/*****************************************************************************/
static void
_dbus_clear(NMSIfcfgRHPlugin *self)
{
NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
guint id;
nm_clear_g_signal_handler(priv->dbus.connection, &priv->dbus.signal_id);
nm_clear_g_cancellable(&priv->dbus.cancellable);
if ((id = nm_steal_int(&priv->dbus.regist_id))) {
if (!g_dbus_connection_unregister_object(priv->dbus.connection, id))
_LOGW("dbus: unexpected failure to unregister object");
}
g_clear_object(&priv->dbus.connection);
}
static void
_dbus_connection_closed(GDBusConnection *connection,
gboolean remote_peer_vanished,
GError *error,
gpointer user_data)
{
_LOGW("dbus: %s bus closed", IFCFGRH1_BUS_NAME);
_dbus_clear(NMS_IFCFG_RH_PLUGIN(user_data));
/* Retry or recover? */
}
static void
_method_call(GDBusConnection *connection,
const char *sender,
const char *object_path,
const char *interface_name,
const char *method_name,
GVariant *parameters,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(user_data);
if (nm_streq(interface_name, IFCFGRH1_IFACE1_NAME)) {
if (nm_streq(method_name, IFCFGRH1_IFACE1_METHOD_GET_IFCFG_DETAILS)) {
const char *ifcfg;
g_variant_get(parameters, "(&s)", &ifcfg);
impl_ifcfgrh_get_ifcfg_details(self, invocation, ifcfg);
return;
}
}
g_dbus_method_invocation_return_error(invocation,
G_DBUS_ERROR,
G_DBUS_ERROR_UNKNOWN_METHOD,
"Unknown method %s",
method_name);
}
static GDBusInterfaceInfo *const interface_info = NM_DEFINE_GDBUS_INTERFACE_INFO(
IFCFGRH1_IFACE1_NAME,
.methods = NM_DEFINE_GDBUS_METHOD_INFOS(
NM_DEFINE_GDBUS_METHOD_INFO(
IFCFGRH1_IFACE1_METHOD_GET_IFCFG_DETAILS,
.in_args = NM_DEFINE_GDBUS_ARG_INFOS(NM_DEFINE_GDBUS_ARG_INFO("ifcfg", "s"), ),
.out_args = NM_DEFINE_GDBUS_ARG_INFOS(NM_DEFINE_GDBUS_ARG_INFO("uuid", "s"),
NM_DEFINE_GDBUS_ARG_INFO("path", "o"), ), ), ), );
static void
_dbus_request_name_done(GObject *source_object, GAsyncResult *res, gpointer user_data)
{
GDBusConnection *connection = G_DBUS_CONNECTION(source_object);
NMSIfcfgRHPlugin *self;
NMSIfcfgRHPluginPrivate *priv;
gs_free_error GError *error = NULL;
gs_unref_variant GVariant *ret = NULL;
guint32 result;
ret = g_dbus_connection_call_finish(connection, res, &error);
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
return;
self = NMS_IFCFG_RH_PLUGIN(user_data);
priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
g_clear_object(&priv->dbus.cancellable);
if (!ret) {
_LOGW("dbus: couldn't acquire D-Bus service: %s", error->message);
_dbus_clear(self);
return;
}
g_variant_get(ret, "(u)", &result);
if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
_LOGW("dbus: couldn't acquire ifcfgrh1 D-Bus service (already taken)");
_dbus_clear(self);
return;
}
{
static const GDBusInterfaceVTable interface_vtable = {
.method_call = _method_call,
};
priv->dbus.regist_id = g_dbus_connection_register_object(
connection,
IFCFGRH1_OBJECT_PATH,
interface_info,
NM_UNCONST_PTR(GDBusInterfaceVTable, &interface_vtable),
self,
NULL,
&error);
if (!priv->dbus.regist_id) {
_LOGW("dbus: couldn't register D-Bus service: %s", error->message);
_dbus_clear(self);
return;
}
}
_LOGD("dbus: acquired D-Bus service %s and exported %s object",
IFCFGRH1_BUS_NAME,
IFCFGRH1_OBJECT_PATH);
}
static void
_dbus_create_done(GObject *source_object, GAsyncResult *res, gpointer user_data)
{
NMSIfcfgRHPlugin *self;
NMSIfcfgRHPluginPrivate *priv;
gs_free_error GError *error = NULL;
GDBusConnection *connection;
connection = g_dbus_connection_new_for_address_finish(res, &error);
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
return;
self = NMS_IFCFG_RH_PLUGIN(user_data);
priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
g_clear_object(&priv->dbus.cancellable);
if (!connection) {
_LOGW("dbus: couldn't initialize system bus: %s", error->message);
return;
}
priv->dbus.connection = connection;
priv->dbus.cancellable = g_cancellable_new();
priv->dbus.signal_id = g_signal_connect(priv->dbus.connection,
"closed",
G_CALLBACK(_dbus_connection_closed),
self);
g_dbus_connection_call(priv->dbus.connection,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"RequestName",
g_variant_new("(su)", IFCFGRH1_BUS_NAME, DBUS_NAME_FLAG_DO_NOT_QUEUE),
G_VARIANT_TYPE("(u)"),
G_DBUS_CALL_FLAGS_NONE,
-1,
priv->dbus.cancellable,
_dbus_request_name_done,
self);
}
static void
_dbus_setup(NMSIfcfgRHPlugin *self)
{
NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
gs_free char *address = NULL;
gs_free_error GError *error = NULL;
_dbus_clear(self);
if (!NM_MAIN_DBUS_CONNECTION_GET) {
_LOGW("dbus: don't use D-Bus for %s service", IFCFGRH1_BUS_NAME);
return;
}
/* We use a separate D-Bus connection so that org.freedesktop.NetworkManager and com.redhat.ifcfgrh1
* are exported by different connections. */
address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (address == NULL) {
_LOGW("dbus: failed getting address for system bus: %s", error->message);
return;
}
priv->dbus.cancellable = g_cancellable_new();
g_dbus_connection_new_for_address(address,
G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT
| G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
NULL,
priv->dbus.cancellable,
_dbus_create_done,
self);
}
static void
config_changed_cb(NMConfig *config,
NMConfigData *config_data,
NMConfigChangeFlags changes,
NMConfigData *old_data,
NMSIfcfgRHPlugin *self)
{
NMSIfcfgRHPluginPrivate *priv;
/* If the dbus connection for some reason is borked the D-Bus service
* won't be offered.
*
* On SIGHUP and SIGUSR1 try to re-connect to D-Bus. So in the unlikely
* event that the D-Bus connection is broken, that allows for recovery
* without need for restarting NetworkManager. */
if (!NM_FLAGS_ANY(changes, NM_CONFIG_CHANGE_CAUSE_SIGHUP | NM_CONFIG_CHANGE_CAUSE_SIGUSR1))
return;
priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
if (!priv->dbus.connection && !priv->dbus.cancellable)
_dbus_setup(self);
}
/*****************************************************************************/
static void
nms_ifcfg_rh_plugin_init(NMSIfcfgRHPlugin *self)
{
NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
priv->config = g_object_ref(nm_config_get());
priv->unmanaged_specs = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, NULL);
priv->unrecognized_specs = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, NULL);
priv->storages = (NMSettUtilStorages) NM_SETT_UTIL_STORAGES_INIT(priv->storages,
nms_ifcfg_rh_storage_destroy);
}
static void
constructed(GObject *object)
{
NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(object);
NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
G_OBJECT_CLASS(nms_ifcfg_rh_plugin_parent_class)->constructed(object);
g_signal_connect(priv->config,
NM_CONFIG_SIGNAL_CONFIG_CHANGED,
G_CALLBACK(config_changed_cb),
self);
_dbus_setup(self);
}
static void
dispose(GObject *object)
{
NMSIfcfgRHPlugin *self = NMS_IFCFG_RH_PLUGIN(object);
NMSIfcfgRHPluginPrivate *priv = NMS_IFCFG_RH_PLUGIN_GET_PRIVATE(self);
if (priv->config)
g_signal_handlers_disconnect_by_func(priv->config, config_changed_cb, self);
/* FIXME(shutdown) we need a stop method so that we can unregistering the D-Bus service
* when NMSettings is shutting down, and not when the instance gets destroyed. */
_dbus_clear(self);
nm_sett_util_storages_clear(&priv->storages);
g_clear_object(&priv->config);
G_OBJECT_CLASS(nms_ifcfg_rh_plugin_parent_class)->dispose(object);
nm_clear_pointer(&priv->unmanaged_specs, g_hash_table_destroy);
nm_clear_pointer(&priv->unrecognized_specs, g_hash_table_destroy);
}
static void
nms_ifcfg_rh_plugin_class_init(NMSIfcfgRHPluginClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
NMSettingsPluginClass *plugin_class = NM_SETTINGS_PLUGIN_CLASS(klass);
object_class->constructed = constructed;
object_class->dispose = dispose;
plugin_class->plugin_name = "ifcfg-rh";
plugin_class->get_unmanaged_specs = get_unmanaged_specs;
plugin_class->get_unrecognized_specs = get_unrecognized_specs;
plugin_class->reload_connections = reload_connections;
plugin_class->load_connections = load_connections;
plugin_class->load_connections_done = load_connections_done;
plugin_class->add_connection = add_connection;
plugin_class->update_connection = update_connection;
plugin_class->delete_connection = delete_connection;
}
/*****************************************************************************/
G_MODULE_EXPORT NMSettingsPlugin *
nm_settings_plugin_factory(void)
{
return g_object_new(NMS_TYPE_IFCFG_RH_PLUGIN, NULL);
}
|