2 * Copyright (c) 2004-2007, 2009-2011, 2014, 2016 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 CFDictionarySetValue(newConfiguration
,
167 *(options
[optionIndex
].key
),
170 SCPrint(TRUE
, stdout
,
171 CFSTR("invalid %s\n"),
172 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "selection");
180 case isChooseMultiple
:
182 SCPrint(TRUE
, stdout
,
183 CFSTR("%s(s) not specified\n"),
184 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "selection");
188 if (strlen(argv
[0]) > 0) {
191 CFMutableArrayRef chosen
;
193 CFArrayRef str_array
;
195 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
196 str_array
= CFStringCreateArrayBySeparatingStrings(NULL
, str
, CFSTR(","));
199 chosen
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
201 n
= CFArrayGetCount(str_array
);
202 for (i
= 0; i
< n
; i
++) {
204 selections
*choices
= (selections
*)options
[optionIndex
].info
;
208 choice
= CFArrayGetValueAtIndex(str_array
, i
);
209 j
= _find_selection(choice
, choices
, &flags
);
211 if (j
!= kCFNotFound
) {
212 if (choices
[j
].flags
& selectionNotAvailable
) {
213 SCPrint(TRUE
, stdout
,
214 CFSTR("cannot select %s\n"),
215 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "selection");
216 CFArrayRemoveAllValues(chosen
);
220 CFArrayAppendValue(chosen
, *(choices
[j
].key
));
222 SCPrint(TRUE
, stdout
,
223 CFSTR("invalid %s\n"),
224 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "selection");
225 CFArrayRemoveAllValues(chosen
);
229 CFRelease(str_array
);
231 if (CFArrayGetCount(chosen
) > 0) {
232 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), chosen
);
234 CFDictionaryRemoveValue(newConfiguration
, *(options
[optionIndex
].key
));
238 CFDictionaryRemoveValue(newConfiguration
, *(options
[optionIndex
].key
));
246 SCPrint(TRUE
, stdout
,
247 CFSTR("%s not specified\n"),
248 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "enable/disable");
252 if ((strcasecmp(argv
[0], "disable") == 0) ||
253 (strcasecmp(argv
[0], "no" ) == 0) ||
254 (strcasecmp(argv
[0], "off" ) == 0) ||
255 (strcasecmp(argv
[0], "0" ) == 0)) {
256 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), kCFBooleanFalse
);
257 } else if ((strcasecmp(argv
[0], "enable") == 0) ||
258 (strcasecmp(argv
[0], "yes" ) == 0) ||
259 (strcasecmp(argv
[0], "on" ) == 0) ||
260 (strcasecmp(argv
[0], "1" ) == 0)) {
261 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), kCFBooleanTrue
);
262 } else if (strcmp(argv
[0], "") == 0) {
263 CFDictionaryRemoveValue(newConfiguration
, *(options
[optionIndex
].key
));
265 SCPrint(TRUE
, stdout
, CFSTR("invalid value\n"));
274 SCPrint(TRUE
, stdout
,
275 CFSTR("%s not specified\n"),
276 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "enable/disable");
280 if ((strcasecmp(argv
[0], "disable") == 0) ||
281 (strcasecmp(argv
[0], "no" ) == 0) ||
282 (strcasecmp(argv
[0], "off" ) == 0) ||
283 (strcasecmp(argv
[0], "0" ) == 0)) {
284 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), CFNumberRef_0
);
285 } else if ((strcasecmp(argv
[0], "enable") == 0) ||
286 (strcasecmp(argv
[0], "yes" ) == 0) ||
287 (strcasecmp(argv
[0], "on" ) == 0) ||
288 (strcasecmp(argv
[0], "1" ) == 0)) {
289 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), CFNumberRef_1
);
290 } else if (strcmp(argv
[0], "") == 0) {
291 CFDictionaryRemoveValue(newConfiguration
, *(options
[optionIndex
].key
));
293 SCPrint(TRUE
, stdout
, CFSTR("invalid value\n"));
302 SCPrint(TRUE
, stdout
,
303 CFSTR("%s not specified\n"),
304 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "value");
308 if (strlen(argv
[0]) > 0) {
311 num
= _copy_number(argv
[0]);
313 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), num
);
316 SCPrint(TRUE
, stdout
, CFSTR("invalid value\n"));
320 CFDictionaryRemoveValue(newConfiguration
, *(options
[optionIndex
].key
));
328 SCPrint(TRUE
, stdout
,
329 CFSTR("%s not specified\n"),
330 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "value");
334 if (strlen(argv
[0]) > 0) {
337 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
338 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), str
);
341 CFDictionaryRemoveValue(newConfiguration
, *(options
[optionIndex
].key
));
349 SCPrint(TRUE
, stdout
,
350 CFSTR("%s(s) not specified\n"),
351 options
[optionIndex
].description
!= NULL
? options
[optionIndex
].description
: "value");
355 if (strlen(argv
[0]) > 0) {
357 CFArrayRef str_array
;
359 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
360 str_array
= CFStringCreateArrayBySeparatingStrings(NULL
, str
, CFSTR(","));
363 CFDictionarySetValue(newConfiguration
, *(options
[optionIndex
].key
), str_array
);
364 CFRelease(str_array
);
366 CFDictionaryRemoveValue(newConfiguration
, *(options
[optionIndex
].key
));
374 if (options
[optionIndex
].handler
!= NULL
) {
378 key
= options
[optionIndex
].key
!= NULL
? *(options
[optionIndex
].key
) : NULL
;
379 nArgs
= (*options
[optionIndex
].handler
)(key
,
380 options
[optionIndex
].description
,
381 options
[optionIndex
].info
,
398 /* -------------------- */
405 _show_entity(CFDictionaryRef entity
, CFStringRef prefix
)
408 const void * keys_q
[N_QUICK
];
409 const void ** keys
= keys_q
;
412 CFMutableArrayRef sorted
;
414 n
= CFDictionaryGetCount(entity
);
415 if (n
> (CFIndex
)(sizeof(keys_q
) / sizeof(CFTypeRef
))) {
416 keys
= CFAllocatorAllocate(NULL
, n
* sizeof(CFTypeRef
), 0);
418 CFDictionaryGetKeysAndValues(entity
, keys
, NULL
);
420 array
= CFArrayCreate(NULL
, keys
, n
, &kCFTypeArrayCallBacks
);
421 sorted
= CFArrayCreateMutableCopy(NULL
, n
, array
);
423 CFArraySortValues(sorted
,
425 (CFComparatorFunction
)CFStringCompare
,
429 for (i
= 0; i
< n
; i
++) {
433 key
= CFArrayGetValueAtIndex(sorted
, i
);
434 value
= CFDictionaryGetValue(entity
, key
);
435 if (isA_CFArray(value
)) {
437 CFIndex n
= CFArrayGetCount(value
);
439 SCPrint(TRUE
, stdout
, CFSTR("%@ %@ = ("), prefix
, key
);
440 for (i
= 0; i
< n
; i
++) {
443 val
= CFArrayGetValueAtIndex(value
, i
);
444 SCPrint(TRUE
, stdout
,
449 SCPrint(TRUE
, stdout
, CFSTR(")\n"));
451 SCPrint(TRUE
, stdout
, CFSTR("%@ %@ = %@\n"), prefix
, key
, value
);
457 if (keys
!= keys_q
) {
458 CFAllocatorDeallocate(NULL
, keys
);
465 /* -------------------- */
471 if (net_interface
!= NULL
) {
472 CFRelease(net_interface
);
473 net_interface
= NULL
;
476 if (net_service
!= NULL
) {
477 CFRelease(net_service
);
481 if (net_protocol
!= NULL
) {
482 CFRelease(net_protocol
);
486 if (net_set
!= NULL
) {
491 if (interfaces
!= NULL
) {
492 CFRelease(interfaces
);
496 if (services
!= NULL
) {
501 if (protocols
!= NULL
) {
502 CFRelease(protocols
);
511 if (new_interfaces
!= NULL
) {
512 CFRelease(new_interfaces
);
513 new_interfaces
= NULL
;
527 CFNumberRef_0
= CFNumberCreate(NULL
, kCFNumberIntType
, &zero
);
528 CFNumberRef_1
= CFNumberCreate(NULL
, kCFNumberIntType
, &one
);
536 do_net_open(int argc
, char **argv
)
539 CFStringRef prefsID
= NULL
;
542 if (_prefs_commitRequired(argc
, argv
, "close")) {
551 prefsID
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
554 ok
= _prefs_open(CFSTR("scutil --net"), prefsID
);
555 if (prefsID
!= NULL
) CFRelease(prefsID
);
559 CFSTR("Could not open prefs: %s\n"),
560 SCErrorString(SCError()));
564 net_set
= SCNetworkSetCopyCurrent(prefs
);
565 if (net_set
!= NULL
) {
568 setName
= SCNetworkSetGetName(net_set
);
569 if (setName
!= NULL
) {
570 SCPrint(TRUE
, stdout
, CFSTR("set \"%@\" selected\n"), setName
);
572 SCPrint(TRUE
, stdout
,
573 CFSTR("set ID \"%@\" selected\n"),
574 SCNetworkSetGetSetID(net_set
));
584 do_net_commit(int argc
, char **argv
)
586 if (!SCPreferencesCommitChanges(prefs
)) {
587 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
591 _prefs_changed
= FALSE
;
598 do_net_apply(int argc
, char **argv
)
600 if (!SCPreferencesApplyChanges(prefs
)) {
601 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
609 do_net_close(int argc
, char **argv
)
611 if (_prefs_commitRequired(argc
, argv
, "close")) {
624 do_net_quit(int argc
, char **argv
)
626 if (_prefs_commitRequired(argc
, argv
, "quit")) {
633 termRequested
= TRUE
;
638 /* -------------------- */
641 typedef void (*net_func
) (int argc
, char **argv
);
643 static const struct {
654 { "interfaces", NULL
, NULL
, NULL
,
655 NULL
, NULL
, show_interfaces
,
658 { "interface", create_interface
, NULL
, NULL
,
659 select_interface
, set_interface
, show_interface
,
662 { "services", NULL
, NULL
, NULL
,
663 NULL
, NULL
, show_services
,
666 { "service", create_service
, disable_service
, enable_service
,
667 select_service
, set_service
, show_service
,
670 { "protocols", NULL
, NULL
, NULL
,
671 NULL
, NULL
, show_protocols
,
674 { "protocol", create_protocol
, disable_protocol
, enable_protocol
,
675 select_protocol
, set_protocol
, show_protocol
,
678 { "sets", NULL
, NULL
, NULL
,
679 NULL
, NULL
, show_sets
,
682 { "set", create_set
, NULL
, NULL
,
683 select_set
, set_set
, show_set
,
687 #define N_NET_KEYS (sizeof(net_keys) / sizeof(net_keys[0]))
691 findNetKey(char *key
)
695 for (i
= 0; i
< (int)N_NET_KEYS
; i
++) {
696 if (strcmp(key
, net_keys
[i
].key
) == 0) {
705 /* -------------------- */
710 do_net_create(int argc
, char **argv
)
721 SCPrint(TRUE
, stderr
, CFSTR("create what?\n"));
725 if (net_keys
[i
].create
== NULL
) {
726 SCPrint(TRUE
, stderr
, CFSTR("create what?\n"));
730 (*net_keys
[i
].create
)(argc
, argv
);
737 do_net_disable(int argc
, char **argv
)
748 SCPrint(TRUE
, stderr
, CFSTR("disable what?\n"));
752 if (net_keys
[i
].disable
== NULL
) {
753 SCPrint(TRUE
, stderr
, CFSTR("disable what?\n"));
757 (*net_keys
[i
].disable
)(argc
, argv
);
764 do_net_enable(int argc
, char **argv
)
775 SCPrint(TRUE
, stderr
, CFSTR("enable what?\n"));
779 if (net_keys
[i
].enable
== NULL
) {
780 SCPrint(TRUE
, stderr
, CFSTR("enable what?\n"));
784 (*net_keys
[i
].enable
)(argc
, argv
);
790 do_net_migrate_perform(int argc
, char **argv
)
792 char * sourceConfiguration
= NULL
;
793 char * targetConfiguration
= NULL
;
794 char * currentConfiguration
= NULL
;
795 CFStringRef str
= NULL
;
796 CFURLRef sourceConfigurationURL
= NULL
;
797 CFURLRef targetConfigurationURL
= NULL
;
798 CFURLRef currentConfigurationURL
= NULL
;
799 CFArrayRef migrationFiles
= NULL
;
801 sourceConfiguration
= argv
[0];
802 targetConfiguration
= argv
[1];
805 currentConfiguration
= argv
[2];
808 SCPrint(_sc_debug
, stdout
, CFSTR("sourceConfiguration: %s\ntargetConfiguration: %s\ncurrentConfiguration: %s\n"),
809 sourceConfiguration
, targetConfiguration
, (currentConfiguration
!= NULL
) ? currentConfiguration
: "<current system>" );
811 str
= CFStringCreateWithCString(NULL
, sourceConfiguration
, kCFStringEncodingUTF8
);
812 sourceConfigurationURL
= CFURLCreateWithFileSystemPath(NULL
, str
, kCFURLPOSIXPathStyle
, TRUE
);
815 str
= CFStringCreateWithCString(NULL
, targetConfiguration
, kCFStringEncodingUTF8
);
816 targetConfigurationURL
= CFURLCreateWithFileSystemPath(NULL
, str
, kCFURLPOSIXPathStyle
, TRUE
);
819 if (currentConfiguration
!= NULL
) {
820 str
= CFStringCreateWithCString(NULL
, currentConfiguration
, kCFStringEncodingUTF8
);
821 currentConfigurationURL
= CFURLCreateWithFileSystemPath(NULL
, str
, kCFURLPOSIXPathStyle
, TRUE
);
825 migrationFiles
= _SCNetworkConfigurationPerformMigration(sourceConfigurationURL
, currentConfigurationURL
, targetConfigurationURL
, NULL
);
827 if (migrationFiles
!= NULL
) {
828 SCPrint(TRUE
, stdout
, CFSTR("Migration Successful: %@ \n"), migrationFiles
);
831 SCPrint(TRUE
, stdout
, CFSTR("Migration Unsuccessful \n"));
834 if (sourceConfigurationURL
!= NULL
) {
835 CFRelease(sourceConfigurationURL
);
837 if (targetConfigurationURL
!= NULL
) {
838 CFRelease(targetConfigurationURL
);
840 if (currentConfigurationURL
!= NULL
) {
841 CFRelease(currentConfigurationURL
);
843 if (migrationFiles
!= NULL
) {
844 CFRelease(migrationFiles
);
850 do_net_migrate_validate(int argc
, char **argv
)
852 char *configuration
= NULL
;
853 CFURLRef configurationURL
= NULL
;
854 char *expectedConfiguration
= NULL
;
855 CFURLRef expectedConfigurationURL
= NULL
;
856 Boolean isValid
= FALSE
;
857 CFStringRef str
= NULL
;
859 configuration
= argv
[0];
860 str
= CFStringCreateWithCString(NULL
, configuration
, kCFStringEncodingUTF8
);
861 configurationURL
= CFURLCreateWithFileSystemPath(NULL
, str
, kCFURLPOSIXPathStyle
, TRUE
);
864 expectedConfiguration
= argv
[1];
865 str
= CFStringCreateWithCString(NULL
, expectedConfiguration
, kCFStringEncodingUTF8
);
866 expectedConfigurationURL
= CFURLCreateWithFileSystemPath(NULL
, str
, kCFURLPOSIXPathStyle
, TRUE
);
869 isValid
= _SCNetworkMigrationAreConfigurationsIdentical(configurationURL
, expectedConfigurationURL
);
871 SCPrint(TRUE
, stdout
, CFSTR("Configuration at location %s %s\n"), configuration
, isValid
? "is valid" : "is NOT valid");
873 if (configurationURL
!= NULL
) {
874 CFRelease(configurationURL
);
876 if (expectedConfigurationURL
!= NULL
) {
877 CFRelease(expectedConfigurationURL
);
884 do_net_migrate(int argc
, char **argv
)
887 SCPrint(TRUE
, stdout
, CFSTR("do_net_migrate called, %d\n"), argc
);
893 if (strncmp(key
, "perform", strlen(key
)) == 0) {
894 do_net_migrate_perform(argc
, argv
);
896 else if (strncmp(key
, "validate", strlen(key
)) == 0) {
897 do_net_migrate_validate(argc
, argv
);
900 SCPrint(TRUE
, stderr
, CFSTR("migrate what?\n"));
909 do_net_remove(int argc
, char **argv
)
920 SCPrint(TRUE
, stderr
, CFSTR("remove what?\n"));
924 if (net_keys
[i
].remove
== NULL
) {
925 SCPrint(TRUE
, stderr
, CFSTR("remove what?\n"));
929 (*net_keys
[i
].remove
)(argc
, argv
);
936 do_net_select(int argc
, char **argv
)
947 SCPrint(TRUE
, stderr
, CFSTR("select what?\n"));
951 if (*net_keys
[i
].select
== NULL
) {
952 SCPrint(TRUE
, stderr
, CFSTR("select what?\n"));
956 (*net_keys
[i
].select
)(argc
, argv
);
963 do_net_set(int argc
, char **argv
)
974 SCPrint(TRUE
, stderr
, CFSTR("set what?\n"));
978 (*net_keys
[i
].set
)(argc
, argv
);
985 do_net_show(int argc
, char **argv
)
996 SCPrint(TRUE
, stderr
, CFSTR("show what?\n"));
1000 (*net_keys
[i
].show
)(argc
, argv
);
1007 do_net_update(int argc
, char **argv
)
1009 SCNetworkSetRef set
;
1010 Boolean setCreated
= FALSE
;
1011 Boolean setUpdated
= FALSE
;
1013 if (prefs
== NULL
) {
1014 SCPrint(TRUE
, stdout
, CFSTR("network configuration not open\n"));
1018 if (net_set
!= NULL
) {
1019 set
= CFRetain(net_set
);
1021 set
= SCNetworkSetCopyCurrent(prefs
);
1023 // if no "current" set, create a new/default ("Automatic") set
1024 set
= _SCNetworkSetCreateDefault(prefs
);
1026 SCPrint(TRUE
, stdout
,
1027 CFSTR("could not initialize \"Automatic\" set: %s\n"),
1028 SCErrorString(SCError()));
1032 if (net_set
!= NULL
) CFRelease(net_set
);
1045 setUpdated
= SCNetworkSetEstablishDefaultConfiguration(set
);
1047 CFStringRef setName
;
1049 _prefs_changed
= TRUE
;
1051 setName
= SCNetworkSetGetName(set
);
1052 if (setName
!= NULL
) {
1053 SCPrint(TRUE
, stdout
,
1054 CFSTR("set \"%@\" (%@) %supdated\n"),
1056 SCNetworkSetGetSetID(set
),
1057 setCreated
? "created, selected, and " : "");
1059 SCPrint(TRUE
, stdout
,
1060 CFSTR("set ID \"%@\" %supdated\n"),
1061 SCNetworkSetGetSetID(set
),
1062 setCreated
? "created, selected, and " : "");
1071 #include "SCPreferencesInternal.h"
1076 do_net_snapshot(int argc
, char **argv
)
1078 if (prefs
== NULL
) {
1079 SCPrint(TRUE
, stdout
, CFSTR("network configuration not open\n"));
1083 if (prefs
!= NULL
) {
1084 SCPreferencesPrivateRef prefsPrivate
= (SCPreferencesPrivateRef
)prefs
;
1086 if (prefsPrivate
->prefs
!= NULL
) {
1088 static int n_snapshot
= 0;
1092 asprintf(&path
, "/tmp/prefs_snapshot_%d", n_snapshot
++);
1094 fd
= open(path
, O_WRONLY
|O_CREAT
|O_TRUNC
|O_EXCL
, 0644);
1097 SCPrint(TRUE
, stdout
, CFSTR("could not write snapshot: open() failed : %s\n"), strerror(errno
));
1101 xmlData
= CFPropertyListCreateData(NULL
, prefsPrivate
->prefs
, kCFPropertyListXMLFormat_v1_0
, 0, NULL
);
1102 if (xmlData
!= NULL
) {
1103 (void) write(fd
, CFDataGetBytePtr(xmlData
), CFDataGetLength(xmlData
));
1106 SCPrint(TRUE
, stdout
, CFSTR("could not write snapshot: CFPropertyListCreateData() failed\n"));
1111 SCPrint(TRUE
, stdout
, CFSTR("prefs have not been accessed\n"));