2 * Copyright (c) 2003-2008, 2011-2015 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 * May 29, 2003 Allan Nathanson <ajn@apple.com>
32 #include <sys/param.h>
33 #include <sys/types.h>
37 #include <SystemConfiguration/SCPreferencesSetSpecific.h>
39 #include <Security/Authorization.h>
40 #endif /* !TARGET_OS_IPHONE */
47 /* -------------------- */
52 __loadSecurity(void) {
53 static void *image
= NULL
;
55 const char *framework
= "/System/Library/Frameworks/Security.framework/Security";
57 const char *suffix
= getenv("DYLD_IMAGE_SUFFIX");
58 char path
[MAXPATHLEN
];
60 strlcpy(path
, framework
, sizeof(path
));
61 if (suffix
) strlcat(path
, suffix
, sizeof(path
));
62 if (0 <= stat(path
, &statbuf
)) {
63 image
= dlopen(path
, RTLD_LAZY
| RTLD_LOCAL
);
65 image
= dlopen(framework
, RTLD_LAZY
| RTLD_LOCAL
);
73 _AuthorizationCreate(const AuthorizationRights
*rights
, const AuthorizationEnvironment
*environment
, AuthorizationFlags flags
, AuthorizationRef
*authorization
)
75 #undef AuthorizationCreate
76 static typeof (AuthorizationCreate
) *dyfunc
= NULL
;
78 void *image
= __loadSecurity();
79 if (image
) dyfunc
= dlsym(image
, "AuthorizationCreate");
81 return dyfunc
? dyfunc(rights
, environment
, flags
, authorization
) : -1;
83 #define AuthorizationCreate _AuthorizationCreate
87 _AuthorizationFree(AuthorizationRef authorization
, AuthorizationFlags flags
)
89 #undef AuthorizationFree
90 static typeof (AuthorizationFree
) *dyfunc
= NULL
;
92 void *image
= __loadSecurity();
93 if (image
) dyfunc
= dlsym(image
, "AuthorizationFree");
95 return dyfunc
? dyfunc(authorization
, flags
) : -1;
97 #define AuthorizationFree _AuthorizationFree
100 /* -------------------- */
104 _prefs_AuthorizationCreate()
106 AuthorizationRef authorization
= NULL
;
108 if (getenv("SCPREFERENCES_USE_ENTITLEMENTS") != NULL
) {
109 authorization
= kSCPreferencesUseEntitlementAuthorization
;
111 AuthorizationFlags flags
= kAuthorizationFlagDefaults
;
114 status
= AuthorizationCreate(NULL
,
115 kAuthorizationEmptyEnvironment
,
118 if (status
!= errAuthorizationSuccess
) {
121 CFSTR("AuthorizationCreate() failed: status = %d\n"),
127 return authorization
;
133 _prefs_AuthorizationFree(AuthorizationRef authorization
)
135 if (authorization
!= kSCPreferencesUseEntitlementAuthorization
) {
136 AuthorizationFree(authorization
, kAuthorizationFlagDefaults
);
137 // AuthorizationFree(authorization, kAuthorizationFlagDestroyRights);
143 #endif /* !TARGET_OS_IPHONE */
145 /* -------------------- */
148 __private_extern__ Boolean _prefs_changed
= FALSE
;
153 _prefs_open(CFStringRef name
, CFStringRef prefsID
)
155 CFMutableDictionaryRef options
= NULL
;
156 Boolean useHelper
= FALSE
;
157 Boolean useOptions
= FALSE
;
159 authorization
= NULL
;
161 if (geteuid() != 0) {
162 // if we need to use a helper
165 #if !TARGET_OS_IPHONE
166 authorization
= _prefs_AuthorizationCreate();
168 authorization
= kSCPreferencesUseEntitlementAuthorization
;
169 #endif /* !TARGET_OS_IPHONE */
172 if (getenv("SCPREFERENCES_REMOVE_WHEN_EMPTY") != NULL
) {
173 // if we have options
176 if (options
== NULL
) {
177 options
= CFDictionaryCreateMutable(NULL
,
179 &kCFTypeDictionaryKeyCallBacks
,
180 &kCFTypeDictionaryValueCallBacks
);
182 CFDictionarySetValue(options
, kSCPreferencesOptionRemoveWhenEmpty
, kCFBooleanTrue
);
185 if (!useHelper
&& !useOptions
) {
186 // if no helper/options needed
187 prefs
= SCPreferencesCreate(NULL
, name
, prefsID
);
188 } else if (!useOptions
) {
189 // if no options needed
190 prefs
= SCPreferencesCreateWithAuthorization(NULL
, name
, prefsID
, authorization
);
192 prefs
= SCPreferencesCreateWithOptions(NULL
, name
, prefsID
, authorization
, options
);
200 _prefs_changed
= FALSE
;
209 if (!SCPreferencesCommitChanges(prefs
)) {
211 case kSCStatusAccessError
:
212 SCPrint(TRUE
, stderr
, CFSTR("Permission denied.\n"));
217 CFSTR("SCPreferencesCommitChanges() failed: %s\n"),
218 SCErrorString(SCError()));
224 _prefs_changed
= FALSE
;
226 if (!SCPreferencesApplyChanges(prefs
)) {
229 CFSTR("SCPreferencesApplyChanges() failed: %s\n"),
230 SCErrorString(SCError()));
245 _prefs_changed
= FALSE
;
248 if (authorization
!= NULL
) {
249 #if !TARGET_OS_IPHONE
250 _prefs_AuthorizationFree(authorization
);
251 #else /* !TARGET_OS_IPHONE */
252 // Uh...if authorization isn't NULL, something went horribly wrong.
253 #endif /* !TARGET_OS_IPHONE */
254 authorization
= NULL
;
263 _prefs_commitRequired(int argc
, char **argv
, const char *command
)
265 if (_prefs_changed
) {
266 if ((currentInput
!= NULL
) &&
267 isatty(fileno(currentInput
->fp
)) &&
268 ((argc
< 1) || (strcmp(argv
[0], "!") != 0))
270 SCPrint(TRUE
, stdout
,
271 CFSTR("preference changes have not been committed\n"
272 "use \"commit\" to save changes"));
273 if (command
!= NULL
) {
274 SCPrint(TRUE
, stdout
,
275 CFSTR(" or \"%s !\" to abandon changes"),
278 SCPrint(TRUE
, stdout
, CFSTR("\n"));
282 SCPrint(TRUE
, stdout
, CFSTR("preference changes abandoned\n"));
289 /* -------------------- */
293 get_ComputerName(int argc
, char **argv
)
295 CFStringEncoding encoding
;
296 CFStringRef hostname
;
298 hostname
= SCDynamicStoreCopyComputerName(NULL
, &encoding
);
299 if (hostname
== NULL
) {
300 int sc_status
= SCError();
303 case kSCStatusNoKey
:
306 CFSTR("ComputerName: not set\n"));
311 CFSTR("SCDynamicStoreCopyComputerName() failed: %s\n"),
312 SCErrorString(SCError()));
318 SCPrint(TRUE
, stdout
, CFSTR("%@\n"), hostname
);
326 set_ComputerName(int argc
, char **argv
)
328 CFStringRef hostname
= NULL
;
331 ok
= _prefs_open(CFSTR("scutil --set ComputerName"), NULL
);
335 CFSTR("Could not open prefs: %s\n"),
336 SCErrorString(SCError()));
341 CFStringEncoding old_encoding
;
342 CFStringRef old_hostname
;
344 old_hostname
= SCDynamicStoreCopyComputerName(NULL
, &old_encoding
);
345 hostname
= _copyStringFromSTDIN(CFSTR("ComputerName"), old_hostname
);
346 if (old_hostname
) CFRelease(old_hostname
);
347 } else if (strlen(argv
[0]) > 0) {
348 hostname
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
351 ok
= SCPreferencesSetComputerName(prefs
, hostname
, kCFStringEncodingUTF8
);
352 if (hostname
!= NULL
) CFRelease(hostname
);
356 CFSTR("Could not open prefs: %s\n"),
357 SCErrorString(SCError()));
369 get_HostName(int argc
, char **argv
)
371 CFStringRef hostname
;
374 ok
= _prefs_open(CFSTR("scutil --get HostName"), NULL
);
378 CFSTR("SCPreferencesCreate() failed: %s\n"),
379 SCErrorString(SCError()));
383 hostname
= SCPreferencesGetHostName(prefs
);
384 if (hostname
== NULL
) {
385 int sc_status
= SCError();
388 case kSCStatusNoKey
:
391 CFSTR("HostName: not set\n"));
396 CFSTR("SCPreferencesGetHostName() failed: %s\n"),
397 SCErrorString(SCError()));
404 SCPrint(TRUE
, stdout
, CFSTR("%@\n"), hostname
);
411 set_HostName(int argc
, char **argv
)
413 CFStringRef hostname
= NULL
;
416 ok
= _prefs_open(CFSTR("scutil --set HostName"), NULL
);
420 CFSTR("Could not open prefs: %s\n"),
421 SCErrorString(SCError()));
426 hostname
= _copyStringFromSTDIN(CFSTR("HostName"), SCPreferencesGetHostName(prefs
));
427 } else if (strlen(argv
[0]) > 0) {
428 hostname
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
431 ok
= SCPreferencesSetHostName(prefs
, hostname
);
432 if (hostname
!= NULL
) CFRelease(hostname
);
436 CFSTR("SCPreferencesSetHostName() failed: %s\n"),
437 SCErrorString(SCError()));
449 get_LocalHostName(int argc
, char **argv
)
451 CFStringRef hostname
;
453 hostname
= SCDynamicStoreCopyLocalHostName(NULL
);
454 if (hostname
== NULL
) {
455 int sc_status
= SCError();
458 case kSCStatusNoKey
:
461 CFSTR("LocalHostName: not set\n"));
466 CFSTR("SCDynamicStoreCopyLocalHostName() failed: %s\n"),
467 SCErrorString(SCError()));
473 SCPrint(TRUE
, stdout
, CFSTR("%@\n"), hostname
);
481 set_LocalHostName(int argc
, char **argv
)
483 CFStringRef hostname
= NULL
;
486 ok
= _prefs_open(CFSTR("scutil --set LocalHostName"), NULL
);
490 CFSTR("Could not open prefs: %s\n"),
491 SCErrorString(SCError()));
496 CFStringRef old_hostname
;
498 old_hostname
= SCDynamicStoreCopyLocalHostName(NULL
);
499 hostname
= _copyStringFromSTDIN(CFSTR("LocalHostName"), old_hostname
);
500 if (old_hostname
) CFRelease(old_hostname
);
501 } else if (strlen(argv
[0]) > 0) {
502 hostname
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
505 ok
= SCPreferencesSetLocalHostName(prefs
, hostname
);
506 if (hostname
!= NULL
) CFRelease(hostname
);
510 CFSTR("SCPreferencesSetLocalHostName() failed: %s\n"),
511 SCErrorString(SCError()));
522 /* -------------------- */
525 typedef void (*pref_func
) (int argc
, char **argv
);
527 static const struct {
532 { "ComputerName", get_ComputerName
, set_ComputerName
},
533 { "HostName", get_HostName
, set_HostName
},
534 { "LocalHostName", get_LocalHostName
, set_LocalHostName
}
536 #define N_PREF_KEYS (sizeof(pref_keys) / sizeof(pref_keys[0]))
545 for (i
= 0; i
< (int)N_PREF_KEYS
; i
++) {
546 if (strcmp(pref
, pref_keys
[i
].pref
) == 0) {
557 do_getPref(char *pref
, int argc
, char **argv
)
564 (*pref_keys
[i
].get
)(argc
, argv
);
569 // Add support to parse out extended get
570 // ie. scutil --get <filename> <prefs path> <key>
572 do_prefs_open(argc
, argv
);
573 do_prefs_get(--argc
, ++argv
);
577 CFStringRef prefs_val
;
579 key
= CFStringCreateWithCString(NULL
, *(++argv
), kCFStringEncodingUTF8
);
580 prefs_val
= CFDictionaryGetValue(value
, key
);
583 if (prefs_val
!= NULL
) {
584 SCPrint(TRUE
, stdout
, CFSTR("%@\n"), prefs_val
);
590 // if path or key not found
598 do_setPref(char *pref
, int argc
, char **argv
)
604 (*pref_keys
[i
].set
)(argc
, argv
);
610 /* -------------------- */
623 do_prefs_open(int argc
, char **argv
)
626 CFStringRef prefsID
= NULL
;
629 if (_prefs_commitRequired(argc
, argv
, "close")) {
633 do_prefs_close(0, NULL
);
637 prefsID
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
640 ok
= _prefs_open(CFSTR("scutil --prefs"), prefsID
);
641 if (prefsID
!= NULL
) CFRelease(prefsID
);
645 CFSTR("Could not open prefs: %s\n"),
646 SCErrorString(SCError()));
656 do_prefs_lock(int argc
, char **argv
)
658 Boolean wait
= (argc
> 0) ? TRUE
: FALSE
;
660 if (!SCPreferencesLock(prefs
, wait
)) {
661 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
671 do_prefs_unlock(int argc
, char **argv
)
673 if (!SCPreferencesUnlock(prefs
)) {
674 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
684 do_prefs_commit(int argc
, char **argv
)
686 if (!SCPreferencesCommitChanges(prefs
)) {
687 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
691 _prefs_changed
= FALSE
;
698 do_prefs_apply(int argc
, char **argv
)
700 if (!SCPreferencesApplyChanges(prefs
)) {
701 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
710 do_prefs_close(int argc
, char **argv
)
712 if (_prefs_commitRequired(argc
, argv
, "close")) {
723 do_prefs_quit(int argc
, char **argv
)
725 if (_prefs_commitRequired(argc
, argv
, "quit")) {
731 termRequested
= TRUE
;
738 do_prefs_synchronize(int argc
, char **argv
)
740 SCPreferencesSynchronize(prefs
);
745 static CFComparisonResult
746 sort_paths(const void *p1
, const void *p2
, void *context
) {
747 CFStringRef path1
= (CFStringRef
)p1
;
748 CFStringRef path2
= (CFStringRef
)p2
;
749 return CFStringCompare(path1
, path2
, 0);
755 do_prefs_list(int argc
, char **argv
)
759 CFMutableArrayRef paths
= NULL
;
761 CFDictionaryRef entity
;
763 prefix
= CFStringCreateWithCString(NULL
,
764 (argc
>= 1) ? argv
[0] : "/",
765 kCFStringEncodingUTF8
);
767 entity
= SCPreferencesPathGetValue(prefs
, prefix
);
768 if (entity
== NULL
) {
769 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
773 paths
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
775 n
= isA_CFDictionary(entity
) ? CFDictionaryGetCount(entity
) : 0;
781 keys
= CFAllocatorAllocate(NULL
, n
* sizeof(CFStringRef
), 0);
782 vals
= CFAllocatorAllocate(NULL
, n
* sizeof(CFPropertyListRef
), 0);
783 CFDictionaryGetKeysAndValues(entity
, keys
, vals
);
784 for (i
= 0; i
< n
; i
++) {
785 if (isA_CFDictionary(vals
[i
])) {
786 CFArrayAppendValue(paths
, keys
[i
]);
789 CFAllocatorDeallocate(NULL
, keys
);
790 CFAllocatorDeallocate(NULL
, vals
);
793 n
= CFArrayGetCount(paths
);
794 CFArraySortValues(paths
,
800 for (i
= 0; i
< n
; i
++) {
803 CFSTR(" path [%d] = %@/%@\n"),
805 CFEqual(prefix
, CFSTR("/")) ? CFSTR("") : prefix
,
806 CFArrayGetValueAtIndex(paths
, i
));
809 SCPrint(TRUE
, stdout
, CFSTR(" no paths.\n"));
823 do_prefs_get(int argc
, char **argv
)
825 CFDictionaryRef dict
;
828 CFMutableDictionaryRef newDict
;
831 path
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
833 link
= SCPreferencesPathGetLink(prefs
, path
);
835 SCPrint(TRUE
, stdout
, CFSTR(" --> %@\n"), link
);
838 dict
= SCPreferencesPathGetValue(prefs
, path
);
841 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
845 newDict
= CFDictionaryCreateMutable(NULL
,
847 &kCFTypeDictionaryKeyCallBacks
,
848 &kCFTypeDictionaryValueCallBacks
);
850 // remove [path] children
851 n
= isA_CFDictionary(dict
) ? CFDictionaryGetCount(dict
) : 0;
857 keys
= CFAllocatorAllocate(NULL
, n
* sizeof(CFStringRef
), 0);
858 vals
= CFAllocatorAllocate(NULL
, n
* sizeof(CFPropertyListRef
), 0);
859 CFDictionaryGetKeysAndValues(dict
, keys
, vals
);
860 for (i
= 0; i
< n
; i
++) {
861 if (!isA_CFDictionary(vals
[i
])) {
862 CFDictionaryAddValue(newDict
, keys
[i
], vals
[i
]);
865 CFAllocatorDeallocate(NULL
, keys
);
866 CFAllocatorDeallocate(NULL
, vals
);
870 CFRelease(value
); /* we have new information, release the old */
881 do_prefs_set(int argc
, char **argv
)
883 CFDictionaryRef dict
;
884 CFMutableDictionaryRef newDict
= NULL
;
887 path
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
888 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, value
);
890 dict
= SCPreferencesPathGetValue(prefs
, path
);
894 // retain [path] children
895 n
= CFDictionaryGetCount(dict
);
901 keys
= CFAllocatorAllocate(NULL
, n
* sizeof(CFStringRef
), 0);
902 vals
= CFAllocatorAllocate(NULL
, n
* sizeof(CFPropertyListRef
), 0);
903 CFDictionaryGetKeysAndValues(dict
, keys
, vals
);
904 for (i
= 0; i
< n
; i
++) {
905 if (isA_CFDictionary(vals
[i
])) {
906 if (CFDictionaryContainsKey(newDict
, keys
[i
])) {
907 SCPrint(TRUE
, stdout
, CFSTR(" key %@ is already a path component and cannot be replaced\n"), keys
[i
]);
910 CFDictionaryAddValue(newDict
, keys
[i
], vals
[i
]);
913 CFAllocatorDeallocate(NULL
, keys
);
914 CFAllocatorDeallocate(NULL
, vals
);
916 } else if (SCError() == kSCStatusInvalidArgument
) {
917 SCPrint(TRUE
, stdout
, CFSTR(" a path component is not a dictionary\n"));
919 } else if (SCError() != kSCStatusNoKey
) {
920 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
929 link
= CFStringCreateWithCString(NULL
, argv
[1], kCFStringEncodingUTF8
);
930 ok
= SCPreferencesPathSetLink(prefs
, path
, link
);
933 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
938 if (!SCPreferencesPathSetValue(prefs
, path
, newDict
)) {
939 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
944 _prefs_changed
= TRUE
;
956 do_prefs_remove(int argc
, char **argv
)
960 path
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
962 if (!SCPreferencesPathRemoveValue(prefs
, path
)) {
963 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
967 _prefs_changed
= TRUE
;
976 on_off_str(Boolean on
)
978 return (on
? "on" : "off");
981 /* -------------------- */
983 #include "IPMonitorControlPrefs.h"
987 do_log(char * log
, int argc
, char **argv
)
989 if (strcmp(log
, "IPMonitor")) {
993 printf("IPMonitor log is %s\n",
994 on_off_str(IPMonitorControlPrefsIsVerbose()));
997 Boolean verbose
= FALSE
;
999 if (strcasecmp(argv
[0], "on") == 0) {
1002 else if (strcasecmp(argv
[0], "off") == 0) {
1006 fprintf(stderr
, "%s invalid, must be 'on' or 'off'\n",
1010 if (IPMonitorControlPrefsSetVerbose(verbose
) == FALSE
) {
1011 fprintf(stderr
, "failed to set preferences\n");
1020 /* -------------------- */
1022 static SCNetworkInterfaceRef
1023 copy_configured_interface(SCPreferencesRef prefs
, CFStringRef if_name
)
1025 SCNetworkSetRef current_set
= NULL
;
1028 SCNetworkInterfaceRef ret_if
= NULL
;
1029 CFArrayRef services
= NULL
;
1031 if (prefs
== NULL
) {
1034 current_set
= SCNetworkSetCopyCurrent(prefs
);
1035 if (current_set
== NULL
) {
1038 services
= SCNetworkSetCopyServices(current_set
);
1039 if (services
== NULL
) {
1043 count
= CFArrayGetCount(services
);
1044 for (i
= 0; i
< count
; i
++) {
1045 CFStringRef this_if_name
;
1046 SCNetworkInterfaceRef this_if
;
1047 SCNetworkServiceRef s
;
1049 s
= (SCNetworkServiceRef
)CFArrayGetValueAtIndex(services
, i
);
1050 if (SCNetworkServiceGetEnabled(s
) == FALSE
) {
1051 /* skip disabled services */
1054 this_if
= SCNetworkServiceGetInterface(s
);
1055 if (this_if
== NULL
) {
1058 this_if_name
= SCNetworkInterfaceGetBSDName(this_if
);
1059 if (this_if_name
== NULL
) {
1062 if (CFEqual(this_if_name
, if_name
)) {
1070 if (current_set
!= NULL
) {
1071 CFRelease(current_set
);
1073 if (services
!= NULL
) {
1074 CFRelease(services
);
1080 disable_until_needed_usage(void)
1082 fprintf(stderr
, "usage: scutil --disable-until-needed <ifname> [ on | off ]\n");
1086 #include <SystemConfiguration/SCNetworkConfigurationPrivate.h>
1090 do_disable_until_needed(int argc
, char **argv
)
1092 const char * if_name
;
1093 CFStringRef if_name_cf
;
1094 SCNetworkInterfaceRef net_if
;
1099 if (argc
< 1 || argc
> 2) {
1100 disable_until_needed_usage();
1108 const char * on_off
= argv
[1];
1111 if (strcasecmp(on_off
, "on") == 0) {
1114 else if (strcasecmp(on_off
, "off") == 0) {
1118 disable_until_needed_usage();
1122 ok
= _prefs_open(CFSTR("scutil --disable-until-needed"), NULL
);
1126 CFSTR("Could not open prefs: %s\n"),
1127 SCErrorString(SCError()));
1130 if_name_cf
= CFStringCreateWithCStringNoCopy(NULL
,
1132 kCFStringEncodingASCII
,
1134 net_if
= copy_configured_interface(prefs
, if_name_cf
);
1135 if (net_if
== NULL
) {
1136 fprintf(stderr
, "%s is not configured\n", if_name
);
1140 if (SCNetworkInterfaceSetDisableUntilNeeded(net_if
, on
) == FALSE
) {
1141 fprintf(stderr
, "failed to turn disable-until-needed %s\n",
1148 on
= SCNetworkInterfaceGetDisableUntilNeeded(net_if
);
1149 printf("%s disable-until-needed is %s\n", if_name
, on_off_str(on
));