2 * Copyright (c) 2004-2007, 2009-2011, 2014, 2016, 2017 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * August 5, 2004 Allan Nathanson <ajn@apple.com>
36 #include "net_interface.h"
37 #include "net_protocol.h"
38 #include "net_service.h"
44 __private_extern__ CFMutableArrayRef new_interfaces
= NULL
;
46 __private_extern__ CFArrayRef interfaces
= NULL
;
47 __private_extern__ CFArrayRef services
= NULL
;
48 __private_extern__ CFArrayRef protocols
= NULL
;
49 __private_extern__ CFArrayRef sets
= NULL
;
51 __private_extern__ SCNetworkInterfaceRef net_interface
= NULL
;
52 __private_extern__ SCNetworkServiceRef net_service
= NULL
;
53 __private_extern__ SCNetworkProtocolRef net_protocol
= NULL
;
54 __private_extern__ SCNetworkSetRef net_set
= NULL
;
56 __private_extern__ CFNumberRef CFNumberRef_0
= NULL
;
57 __private_extern__ CFNumberRef CFNumberRef_1
= NULL
;
60 /* -------------------- */
64 CF_RETURNS_RETAINED CFNumberRef
65 _copy_number(const char *arg
)
69 if (sscanf(arg
, "%d", &val
) != 1) {
73 return CFNumberCreate(NULL
, kCFNumberIntType
, &val
);
77 /* -------------------- */
82 _find_option(const char *option
, optionsRef options
, const int nOptions
)
86 for (i
= 0; i
< nOptions
; i
++) {
87 if (strcasecmp(option
, options
[i
].option
) == 0) {
98 _find_selection(CFStringRef choice
, selections choices
[], unsigned int *flags
)
103 while (choices
[i
].selection
!= NULL
) {
104 if (CFStringCompare(choice
,
105 choices
[i
].selection
,
106 kCFCompareCaseInsensitive
) == kCFCompareEqualTo
) {
108 *flags
= choices
[i
].flags
;
121 _process_options(optionsRef options
, int nOptions
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
124 CFIndex optionIndex
= kCFNotFound
;
126 optionIndex
= _find_option(argv
[0], options
, nOptions
);
127 if (optionIndex
== kCFNotFound
) {
128 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
134 switch (options
[optionIndex
].type
) {
136 // all option processing is managed by the "handler"
139 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), options
[optionIndex
].info
);
143 selections
*choices
= (selections
*)options
[optionIndex
].info
;
148 SCPrint(TRUE
, stdout
,
149 CFSTR("%s not specified\n"),
150 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "selection");
154 choice
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
155 i
= _find_selection(choice
, choices
, &flags
);
158 if (i
!= kCFNotFound
) {
159 if (choices
[i
].flags
& selectionNotAvailable
) {
160 SCPrint(TRUE
, stdout
,
161 CFSTR("cannot select %s\n"),
162 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "selection");
166 if (choices
[i
].key
!= NULL
) {
167 CFDictionarySetValue(newConfiguration
,
168 *(options
[optionIndex
].key
),
171 CFDictionaryRemoveValue(newConfiguration
,
172 *(options
[optionIndex
].key
));
175 SCPrint(TRUE
, stdout
,
176 CFSTR("invalid %s\n"),
177 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "selection");
185 case isChooseMultiple
:
187 SCPrint(TRUE
, stdout
,
188 CFSTR("%s(s) not specified\n"),
189 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "selection");
193 if (strlen(argv
[0]) > 0) {
196 CFMutableArrayRef chosen
;
198 CFArrayRef str_array
;
200 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
201 str_array
= CFStringCreateArrayBySeparatingStrings(NULL
, str
, CFSTR(","));
204 chosen
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
206 n
= CFArrayGetCount(str_array
);
207 for (i
= 0; i
< n
; i
++) {
209 selections
*choices
= (selections
*)options
[optionIndex
].info
;
213 choice
= CFArrayGetValueAtIndex(str_array
, i
);
214 j
= _find_selection(choice
, choices
, &flags
);
216 if (j
!= kCFNotFound
) {
217 if (choices
[j
].flags
& selectionNotAvailable
) {
218 SCPrint(TRUE
, stdout
,
219 CFSTR("cannot select %s\n"),
220 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "selection");
221 CFArrayRemoveAllValues(chosen
);
225 CFArrayAppendValue(chosen
, *(choices
[j
].key
));
227 SCPrint(TRUE
, stdout
,
228 CFSTR("invalid %s\n"),
229 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "selection");
230 CFArrayRemoveAllValues(chosen
);
234 CFRelease(str_array
);
236 if (CFArrayGetCount(chosen
) > 0) {
237 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), chosen
);
239 CFDictionaryRemoveValue(newConfiguration
, *(options
[optionIndex
].key
));
243 CFDictionaryRemoveValue(newConfiguration
, *(options
[optionIndex
].key
));
251 SCPrint(TRUE
, stdout
,
252 CFSTR("%s not specified\n"),
253 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "enable/disable");
257 if ((strcasecmp(argv
[0], "disable") == 0) ||
258 (strcasecmp(argv
[0], "no" ) == 0) ||
259 (strcasecmp(argv
[0], "off" ) == 0) ||
260 (strcasecmp(argv
[0], "0" ) == 0)) {
261 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), kCFBooleanFalse
);
262 } else if ((strcasecmp(argv
[0], "enable") == 0) ||
263 (strcasecmp(argv
[0], "yes" ) == 0) ||
264 (strcasecmp(argv
[0], "on" ) == 0) ||
265 (strcasecmp(argv
[0], "1" ) == 0)) {
266 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), kCFBooleanTrue
);
267 } else if (strcmp(argv
[0], "") == 0) {
268 CFDictionaryRemoveValue(newConfiguration
, *(options
[optionIndex
].key
));
270 SCPrint(TRUE
, stdout
, CFSTR("invalid value\n"));
279 SCPrint(TRUE
, stdout
,
280 CFSTR("%s not specified\n"),
281 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "enable/disable");
285 if ((strcasecmp(argv
[0], "disable") == 0) ||
286 (strcasecmp(argv
[0], "no" ) == 0) ||
287 (strcasecmp(argv
[0], "off" ) == 0) ||
288 (strcasecmp(argv
[0], "0" ) == 0)) {
289 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), CFNumberRef_0
);
290 } else if ((strcasecmp(argv
[0], "enable") == 0) ||
291 (strcasecmp(argv
[0], "yes" ) == 0) ||
292 (strcasecmp(argv
[0], "on" ) == 0) ||
293 (strcasecmp(argv
[0], "1" ) == 0)) {
294 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), CFNumberRef_1
);
295 } else if (strcmp(argv
[0], "") == 0) {
296 CFDictionaryRemoveValue(newConfiguration
, *(options
[optionIndex
].key
));
298 SCPrint(TRUE
, stdout
, CFSTR("invalid value\n"));
307 SCPrint(TRUE
, stdout
,
308 CFSTR("%s not specified\n"),
309 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "value");
313 if (strlen(argv
[0]) > 0) {
316 num
= _copy_number(argv
[0]);
318 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), num
);
321 SCPrint(TRUE
, stdout
, CFSTR("invalid value\n"));
325 CFDictionaryRemoveValue(newConfiguration
, *(options
[optionIndex
].key
));
333 SCPrint(TRUE
, stdout
,
334 CFSTR("%s not specified\n"),
335 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "value");
339 if (strlen(argv
[0]) > 0) {
342 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
343 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), str
);
346 CFDictionaryRemoveValue(newConfiguration
, *(options
[optionIndex
].key
));
354 SCPrint(TRUE
, stdout
,
355 CFSTR("%s(s) not specified\n"),
356 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "value");
360 if (strlen(argv
[0]) > 0) {
362 CFArrayRef str_array
;
364 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
365 str_array
= CFStringCreateArrayBySeparatingStrings(NULL
, str
, CFSTR(","));
368 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), str_array
);
369 CFRelease(str_array
);
371 CFDictionaryRemoveValue(newConfiguration
, *(options
[optionIndex
].key
));
379 if (options
[optionIndex
].handler
!= NULL
) {
383 key
= options
[optionIndex
].key
!= NULL
? *(options
[optionIndex
].key
) : NULL
;
384 nArgs
= (*options
[optionIndex
].handler
)(key
,
385 options
[optionIndex
].description
,
386 options
[optionIndex
].info
,
403 /* -------------------- */
410 _show_entity(CFDictionaryRef entity
, CFStringRef prefix
)
413 const void * keys_q
[N_QUICK
];
414 const void ** keys
= keys_q
;
417 CFMutableArrayRef sorted
;
419 n
= CFDictionaryGetCount(entity
);
420 if (n
> (CFIndex
)(sizeof(keys_q
) / sizeof(CFTypeRef
))) {
421 keys
= CFAllocatorAllocate(NULL
, n
* sizeof(CFTypeRef
), 0);
423 CFDictionaryGetKeysAndValues(entity
, keys
, NULL
);
425 array
= CFArrayCreate(NULL
, keys
, n
, &kCFTypeArrayCallBacks
);
426 sorted
= CFArrayCreateMutableCopy(NULL
, n
, array
);
428 CFArraySortValues(sorted
,
430 (CFComparatorFunction
)CFStringCompare
,
434 for (i
= 0; i
< n
; i
++) {
438 key
= CFArrayGetValueAtIndex(sorted
, i
);
439 value
= CFDictionaryGetValue(entity
, key
);
440 if (isA_CFArray(value
)) {
442 CFIndex n
= CFArrayGetCount(value
);
444 SCPrint(TRUE
, stdout
, CFSTR("%@ %@ = ("), prefix
, key
);
445 for (i
= 0; i
< n
; i
++) {
448 val
= CFArrayGetValueAtIndex(value
, i
);
449 SCPrint(TRUE
, stdout
,
454 SCPrint(TRUE
, stdout
, CFSTR(")\n"));
456 SCPrint(TRUE
, stdout
, CFSTR("%@ %@ = %@\n"), prefix
, key
, value
);
462 if (keys
!= keys_q
) {
463 CFAllocatorDeallocate(NULL
, keys
);
470 /* -------------------- */
476 if (net_interface
!= NULL
) {
477 CFRelease(net_interface
);
478 net_interface
= NULL
;
481 if (net_service
!= NULL
) {
482 CFRelease(net_service
);
486 if (net_protocol
!= NULL
) {
487 CFRelease(net_protocol
);
491 if (net_set
!= NULL
) {
496 if (interfaces
!= NULL
) {
497 CFRelease(interfaces
);
501 if (services
!= NULL
) {
506 if (protocols
!= NULL
) {
507 CFRelease(protocols
);
516 if (new_interfaces
!= NULL
) {
517 CFRelease(new_interfaces
);
518 new_interfaces
= NULL
;
532 CFNumberRef_0
= CFNumberCreate(NULL
, kCFNumberIntType
, &zero
);
533 CFNumberRef_1
= CFNumberCreate(NULL
, kCFNumberIntType
, &one
);
541 do_net_open(int argc
, char **argv
)
544 CFStringRef prefsID
= NULL
;
547 if (_prefs_commitRequired(argc
, argv
, "close")) {
556 prefsID
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
559 ok
= _prefs_open(CFSTR("scutil --net"), prefsID
);
560 if (prefsID
!= NULL
) CFRelease(prefsID
);
564 CFSTR("Could not open prefs: %s\n"),
565 SCErrorString(SCError()));
569 net_set
= SCNetworkSetCopyCurrent(prefs
);
570 if (net_set
!= NULL
) {
573 setName
= SCNetworkSetGetName(net_set
);
574 if (setName
!= NULL
) {
575 SCPrint(TRUE
, stdout
, CFSTR("set \"%@\" selected\n"), setName
);
577 SCPrint(TRUE
, stdout
,
578 CFSTR("set ID \"%@\" selected\n"),
579 SCNetworkSetGetSetID(net_set
));
589 do_net_commit(int argc
, char **argv
)
593 if (!SCPreferencesCommitChanges(prefs
)) {
594 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
598 _prefs_changed
= FALSE
;
605 do_net_apply(int argc
, char **argv
)
609 if (!SCPreferencesApplyChanges(prefs
)) {
610 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
618 do_net_close(int argc
, char **argv
)
620 if (_prefs_commitRequired(argc
, argv
, "close")) {
633 do_net_quit(int argc
, char **argv
)
635 if (_prefs_commitRequired(argc
, argv
, "quit")) {
642 termRequested
= TRUE
;
647 /* -------------------- */
650 typedef void (*net_func
) (int argc
, char **argv
);
652 static const struct {
663 { "interfaces", NULL
, NULL
, NULL
,
664 NULL
, NULL
, show_interfaces
,
667 { "interface", create_interface
, NULL
, NULL
,
668 select_interface
, set_interface
, show_interface
,
671 { "services", NULL
, NULL
, NULL
,
672 NULL
, NULL
, show_services
,
675 { "service", create_service
, disable_service
, enable_service
,
676 select_service
, set_service
, show_service
,
679 { "protocols", NULL
, NULL
, NULL
,
680 NULL
, NULL
, show_protocols
,
683 { "protocol", create_protocol
, disable_protocol
, enable_protocol
,
684 select_protocol
, set_protocol
, show_protocol
,
687 { "sets", NULL
, NULL
, NULL
,
688 NULL
, NULL
, show_sets
,
691 { "set", create_set
, NULL
, NULL
,
692 select_set
, set_set
, show_set
,
696 #define N_NET_KEYS (sizeof(net_keys) / sizeof(net_keys[0]))
700 findNetKey(char *key
)
704 for (i
= 0; i
< (int)N_NET_KEYS
; i
++) {
705 if (strcmp(key
, net_keys
[i
].key
) == 0) {
714 /* -------------------- */
719 do_net_create(int argc
, char **argv
)
730 SCPrint(TRUE
, stderr
, CFSTR("create what?\n"));
734 if (net_keys
[i
].create
== NULL
) {
735 SCPrint(TRUE
, stderr
, CFSTR("create what?\n"));
739 (*net_keys
[i
].create
)(argc
, argv
);
746 do_net_disable(int argc
, char **argv
)
757 SCPrint(TRUE
, stderr
, CFSTR("disable what?\n"));
761 if (net_keys
[i
].disable
== NULL
) {
762 SCPrint(TRUE
, stderr
, CFSTR("disable what?\n"));
766 (*net_keys
[i
].disable
)(argc
, argv
);
773 do_net_enable(int argc
, char **argv
)
784 SCPrint(TRUE
, stderr
, CFSTR("enable what?\n"));
788 if (net_keys
[i
].enable
== NULL
) {
789 SCPrint(TRUE
, stderr
, CFSTR("enable what?\n"));
793 (*net_keys
[i
].enable
)(argc
, argv
);
799 do_net_migrate_perform(int argc
, char **argv
)
801 char * sourceConfiguration
= NULL
;
802 char * targetConfiguration
= NULL
;
803 char * currentConfiguration
= NULL
;
804 CFStringRef str
= NULL
;
805 CFURLRef sourceConfigurationURL
= NULL
;
806 CFURLRef targetConfigurationURL
= NULL
;
807 CFURLRef currentConfigurationURL
= NULL
;
808 CFArrayRef migrationFiles
= NULL
;
810 sourceConfiguration
= argv
[0];
811 targetConfiguration
= argv
[1];
814 currentConfiguration
= argv
[2];
817 SCPrint(_sc_debug
, stdout
, CFSTR("sourceConfiguration: %s\ntargetConfiguration: %s\ncurrentConfiguration: %s\n"),
818 sourceConfiguration
, targetConfiguration
, (currentConfiguration
!= NULL
) ? currentConfiguration
: "<current system>" );
820 str
= CFStringCreateWithCString(NULL
, sourceConfiguration
, kCFStringEncodingUTF8
);
821 sourceConfigurationURL
= CFURLCreateWithFileSystemPath(NULL
, str
, kCFURLPOSIXPathStyle
, TRUE
);
824 str
= CFStringCreateWithCString(NULL
, targetConfiguration
, kCFStringEncodingUTF8
);
825 targetConfigurationURL
= CFURLCreateWithFileSystemPath(NULL
, str
, kCFURLPOSIXPathStyle
, TRUE
);
828 if (currentConfiguration
!= NULL
) {
829 str
= CFStringCreateWithCString(NULL
, currentConfiguration
, kCFStringEncodingUTF8
);
830 currentConfigurationURL
= CFURLCreateWithFileSystemPath(NULL
, str
, kCFURLPOSIXPathStyle
, TRUE
);
834 migrationFiles
= _SCNetworkConfigurationPerformMigration(sourceConfigurationURL
, currentConfigurationURL
, targetConfigurationURL
, NULL
);
836 if (migrationFiles
!= NULL
) {
837 SCPrint(TRUE
, stdout
, CFSTR("Migration Successful: %@ \n"), migrationFiles
);
840 SCPrint(TRUE
, stdout
, CFSTR("Migration Unsuccessful \n"));
843 if (sourceConfigurationURL
!= NULL
) {
844 CFRelease(sourceConfigurationURL
);
846 if (targetConfigurationURL
!= NULL
) {
847 CFRelease(targetConfigurationURL
);
849 if (currentConfigurationURL
!= NULL
) {
850 CFRelease(currentConfigurationURL
);
852 if (migrationFiles
!= NULL
) {
853 CFRelease(migrationFiles
);
859 do_net_migrate_validate(int argc
, char **argv
)
862 char *configuration
= NULL
;
863 CFURLRef configurationURL
= NULL
;
864 char *expectedConfiguration
= NULL
;
865 CFURLRef expectedConfigurationURL
= NULL
;
866 Boolean isValid
= FALSE
;
867 CFStringRef str
= NULL
;
869 configuration
= argv
[0];
870 str
= CFStringCreateWithCString(NULL
, configuration
, kCFStringEncodingUTF8
);
871 configurationURL
= CFURLCreateWithFileSystemPath(NULL
, str
, kCFURLPOSIXPathStyle
, TRUE
);
874 expectedConfiguration
= argv
[1];
875 str
= CFStringCreateWithCString(NULL
, expectedConfiguration
, kCFStringEncodingUTF8
);
876 expectedConfigurationURL
= CFURLCreateWithFileSystemPath(NULL
, str
, kCFURLPOSIXPathStyle
, TRUE
);
879 isValid
= _SCNetworkMigrationAreConfigurationsIdentical(configurationURL
, expectedConfigurationURL
);
881 SCPrint(TRUE
, stdout
, CFSTR("Configuration at location %s %s\n"), configuration
, isValid
? "is valid" : "is NOT valid");
883 if (configurationURL
!= NULL
) {
884 CFRelease(configurationURL
);
886 if (expectedConfigurationURL
!= NULL
) {
887 CFRelease(expectedConfigurationURL
);
894 do_net_migrate(int argc
, char **argv
)
897 SCPrint(TRUE
, stdout
, CFSTR("do_net_migrate called, %d\n"), argc
);
903 if (strcmp(key
, "perform") == 0) {
904 do_net_migrate_perform(argc
, argv
);
905 } else if (strcmp(key
, "validate") == 0) {
906 do_net_migrate_validate(argc
, argv
);
908 SCPrint(TRUE
, stderr
, CFSTR("migrate what?\n"));
917 do_net_remove(int argc
, char **argv
)
928 SCPrint(TRUE
, stderr
, CFSTR("remove what?\n"));
932 if (net_keys
[i
].remove
== NULL
) {
933 SCPrint(TRUE
, stderr
, CFSTR("remove what?\n"));
937 (*net_keys
[i
].remove
)(argc
, argv
);
944 do_net_select(int argc
, char **argv
)
955 SCPrint(TRUE
, stderr
, CFSTR("select what?\n"));
959 if (*net_keys
[i
].select
== NULL
) {
960 SCPrint(TRUE
, stderr
, CFSTR("select what?\n"));
964 (*net_keys
[i
].select
)(argc
, argv
);
971 do_net_set(int argc
, char **argv
)
982 SCPrint(TRUE
, stderr
, CFSTR("set what?\n"));
986 (*net_keys
[i
].set
)(argc
, argv
);
993 do_net_show(int argc
, char **argv
)
1002 i
= findNetKey(key
);
1004 SCPrint(TRUE
, stderr
, CFSTR("show what?\n"));
1008 (*net_keys
[i
].show
)(argc
, argv
);
1015 do_net_update(int argc
, char **argv
)
1017 #pragma unused(argc)
1018 #pragma unused(argv)
1019 SCNetworkSetRef set
;
1020 Boolean setCreated
= FALSE
;
1021 Boolean setUpdated
= FALSE
;
1023 if (prefs
== NULL
) {
1024 SCPrint(TRUE
, stdout
, CFSTR("network configuration not open\n"));
1028 if (net_set
!= NULL
) {
1029 set
= CFRetain(net_set
);
1031 set
= SCNetworkSetCopyCurrent(prefs
);
1033 // if no "current" set, create a new/default ("Automatic") set
1034 set
= _SCNetworkSetCreateDefault(prefs
);
1036 SCPrint(TRUE
, stdout
,
1037 CFSTR("could not initialize \"Automatic\" set: %s\n"),
1038 SCErrorString(SCError()));
1042 if (net_set
!= NULL
) CFRelease(net_set
);
1055 setUpdated
= SCNetworkSetEstablishDefaultConfiguration(set
);
1057 CFStringRef setName
;
1059 _prefs_changed
= TRUE
;
1061 setName
= SCNetworkSetGetName(set
);
1062 if (setName
!= NULL
) {
1063 SCPrint(TRUE
, stdout
,
1064 CFSTR("set \"%@\" (%@) %supdated\n"),
1066 SCNetworkSetGetSetID(set
),
1067 setCreated
? "created, selected, and " : "");
1069 SCPrint(TRUE
, stdout
,
1070 CFSTR("set ID \"%@\" %supdated\n"),
1071 SCNetworkSetGetSetID(set
),
1072 setCreated
? "created, selected, and " : "");
1081 #include "SCPreferencesInternal.h"
1086 do_net_snapshot(int argc
, char **argv
)
1088 #pragma unused(argc)
1089 #pragma unused(argv)
1090 if (prefs
== NULL
) {
1091 SCPrint(TRUE
, stdout
, CFSTR("network configuration not open\n"));
1095 if (prefs
!= NULL
) {
1096 SCPreferencesPrivateRef prefsPrivate
= (SCPreferencesPrivateRef
)prefs
;
1098 if (prefsPrivate
->prefs
!= NULL
) {
1100 static int n_snapshot
= 0;
1104 asprintf(&path
, "/tmp/prefs_snapshot_%d", n_snapshot
++);
1106 fd
= open(path
, O_WRONLY
|O_CREAT
|O_TRUNC
|O_EXCL
, 0644);
1109 SCPrint(TRUE
, stdout
, CFSTR("could not write snapshot: open() failed : %s\n"), strerror(errno
));
1113 xmlData
= CFPropertyListCreateData(NULL
, prefsPrivate
->prefs
, kCFPropertyListXMLFormat_v1_0
, 0, NULL
);
1114 if (xmlData
!= NULL
) {
1115 (void) write(fd
, CFDataGetBytePtr(xmlData
), CFDataGetLength(xmlData
));
1118 SCPrint(TRUE
, stdout
, CFSTR("could not write snapshot: CFPropertyListCreateData() failed\n"));
1123 SCPrint(TRUE
, stdout
, CFSTR("prefs have not been accessed\n"));