2 * Copyright (c) 2003-2008, 2011-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 * May 29, 2003 Allan Nathanson <ajn@apple.com>
33 #include <sys/param.h>
34 #include <sys/types.h>
41 #include "SCNetworkConfigurationInternal.h"
44 #include <Security/Authorization.h>
45 #endif /* !TARGET_OS_IPHONE */
48 /* -------------------- */
53 __loadSecurity(void) {
54 static void *image
= NULL
;
55 static dispatch_once_t once
;
57 dispatch_once(&once
, ^{
58 image
= _SC_dlopen("/System/Library/Frameworks/Security.framework/Security");
66 _AuthorizationCreate(const AuthorizationRights
*rights
, const AuthorizationEnvironment
*environment
, AuthorizationFlags flags
, AuthorizationRef
*authorization
)
68 #undef AuthorizationCreate
69 static typeof (AuthorizationCreate
) *dyfunc
= NULL
;
71 void *image
= __loadSecurity();
72 if (image
) dyfunc
= dlsym(image
, "AuthorizationCreate");
74 return dyfunc
? dyfunc(rights
, environment
, flags
, authorization
) : -1;
76 #define AuthorizationCreate _AuthorizationCreate
80 _AuthorizationFree(AuthorizationRef authorization
, AuthorizationFlags flags
)
82 #undef AuthorizationFree
83 static typeof (AuthorizationFree
) *dyfunc
= NULL
;
85 void *image
= __loadSecurity();
86 if (image
) dyfunc
= dlsym(image
, "AuthorizationFree");
88 return dyfunc
? dyfunc(authorization
, flags
) : -1;
90 #define AuthorizationFree _AuthorizationFree
93 /* -------------------- */
97 _prefs_AuthorizationCreate()
99 AuthorizationRef authorization
= NULL
;
101 if (getenv("SCPREFERENCES_USE_ENTITLEMENTS") != NULL
) {
102 authorization
= kSCPreferencesUseEntitlementAuthorization
;
104 AuthorizationFlags flags
= kAuthorizationFlagDefaults
;
107 status
= AuthorizationCreate(NULL
,
108 kAuthorizationEmptyEnvironment
,
111 if (status
!= errAuthorizationSuccess
) {
114 CFSTR("AuthorizationCreate() failed: status = %d\n"),
120 return authorization
;
126 _prefs_AuthorizationFree(AuthorizationRef authorization
)
128 if (authorization
!= kSCPreferencesUseEntitlementAuthorization
) {
129 AuthorizationFree(authorization
, kAuthorizationFlagDefaults
);
130 // AuthorizationFree(authorization, kAuthorizationFlagDestroyRights);
136 #endif /* !TARGET_OS_IPHONE */
138 /* -------------------- */
141 __private_extern__ Boolean _prefs_changed
= FALSE
;
146 _prefs_open(CFStringRef name
, CFStringRef prefsID
)
148 CFMutableDictionaryRef options
= NULL
;
149 Boolean useHelper
= FALSE
;
150 Boolean useOptions
= FALSE
;
152 authorization
= NULL
;
154 if (geteuid() != 0) {
155 // if we need to use a helper
158 #if !TARGET_OS_IPHONE
159 authorization
= _prefs_AuthorizationCreate();
161 authorization
= kSCPreferencesUseEntitlementAuthorization
;
162 #endif /* !TARGET_OS_IPHONE */
165 if (getenv("SCPREFERENCES_REMOVE_WHEN_EMPTY") != NULL
) {
166 // if we have options
169 if (options
== NULL
) {
170 options
= CFDictionaryCreateMutable(NULL
,
172 &kCFTypeDictionaryKeyCallBacks
,
173 &kCFTypeDictionaryValueCallBacks
);
175 CFDictionarySetValue(options
, kSCPreferencesOptionRemoveWhenEmpty
, kCFBooleanTrue
);
178 if (!useHelper
&& !useOptions
) {
179 // if no helper/options needed
180 prefs
= SCPreferencesCreate(NULL
, name
, prefsID
);
181 } else if (!useOptions
) {
182 // if no options needed
183 prefs
= SCPreferencesCreateWithAuthorization(NULL
, name
, prefsID
, authorization
);
185 prefs
= SCPreferencesCreateWithOptions(NULL
, name
, prefsID
, authorization
, options
);
193 _prefs_changed
= FALSE
;
202 if (!SCPreferencesCommitChanges(prefs
)) {
204 case kSCStatusAccessError
:
205 SCPrint(TRUE
, stderr
, CFSTR("Permission denied.\n"));
210 CFSTR("SCPreferencesCommitChanges() failed: %s\n"),
211 SCErrorString(SCError()));
217 _prefs_changed
= FALSE
;
219 if (!SCPreferencesApplyChanges(prefs
)) {
222 CFSTR("SCPreferencesApplyChanges() failed: %s\n"),
223 SCErrorString(SCError()));
238 _prefs_changed
= FALSE
;
241 if (authorization
!= NULL
) {
242 #if !TARGET_OS_IPHONE
243 _prefs_AuthorizationFree(authorization
);
244 #else /* !TARGET_OS_IPHONE */
245 // Uh...if authorization isn't NULL, something went horribly wrong.
246 #endif /* !TARGET_OS_IPHONE */
247 authorization
= NULL
;
256 _prefs_commitRequired(int argc
, char **argv
, const char *command
)
258 if (_prefs_changed
) {
259 if ((currentInput
!= NULL
) &&
260 isatty(fileno(currentInput
->fp
)) &&
261 ((argc
< 1) || (strcmp(argv
[0], "!") != 0))
263 SCPrint(TRUE
, stdout
,
264 CFSTR("preference changes have not been committed\n"
265 "use \"commit\" to save changes"));
266 if (command
!= NULL
) {
267 SCPrint(TRUE
, stdout
,
268 CFSTR(" or \"%s !\" to abandon changes"),
271 SCPrint(TRUE
, stdout
, CFSTR("\n"));
275 SCPrint(TRUE
, stdout
, CFSTR("preference changes abandoned\n"));
282 /* -------------------- */
286 get_ComputerName(int argc
, char **argv
)
288 CFStringEncoding encoding
;
289 CFStringRef hostname
;
291 hostname
= SCDynamicStoreCopyComputerName(NULL
, &encoding
);
292 if (hostname
== NULL
) {
293 int sc_status
= SCError();
296 case kSCStatusNoKey
:
299 CFSTR("ComputerName: not set\n"));
304 CFSTR("SCDynamicStoreCopyComputerName() failed: %s\n"),
305 SCErrorString(SCError()));
311 SCPrint(TRUE
, stdout
, CFSTR("%@\n"), hostname
);
319 set_ComputerName(int argc
, char **argv
)
321 CFStringRef hostname
= NULL
;
324 ok
= _prefs_open(CFSTR("scutil --set ComputerName"), NULL
);
328 CFSTR("Could not open prefs: %s\n"),
329 SCErrorString(SCError()));
334 CFStringEncoding old_encoding
;
335 CFStringRef old_hostname
;
337 old_hostname
= SCDynamicStoreCopyComputerName(NULL
, &old_encoding
);
338 hostname
= _copyStringFromSTDIN(CFSTR("ComputerName"), old_hostname
);
339 if (old_hostname
) CFRelease(old_hostname
);
340 } else if (strlen(argv
[0]) > 0) {
341 hostname
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
344 ok
= SCPreferencesSetComputerName(prefs
, hostname
, kCFStringEncodingUTF8
);
345 if (hostname
!= NULL
) CFRelease(hostname
);
349 CFSTR("Could not open prefs: %s\n"),
350 SCErrorString(SCError()));
362 get_HostName(int argc
, char **argv
)
364 CFStringRef hostname
;
367 ok
= _prefs_open(CFSTR("scutil --get HostName"), NULL
);
371 CFSTR("SCPreferencesCreate() failed: %s\n"),
372 SCErrorString(SCError()));
376 hostname
= SCPreferencesGetHostName(prefs
);
377 if (hostname
== NULL
) {
378 int sc_status
= SCError();
381 case kSCStatusNoKey
:
384 CFSTR("HostName: not set\n"));
389 CFSTR("SCPreferencesGetHostName() failed: %s\n"),
390 SCErrorString(SCError()));
397 SCPrint(TRUE
, stdout
, CFSTR("%@\n"), hostname
);
404 set_HostName(int argc
, char **argv
)
406 CFStringRef hostname
= NULL
;
409 ok
= _prefs_open(CFSTR("scutil --set HostName"), NULL
);
413 CFSTR("Could not open prefs: %s\n"),
414 SCErrorString(SCError()));
419 hostname
= _copyStringFromSTDIN(CFSTR("HostName"), SCPreferencesGetHostName(prefs
));
420 } else if (strlen(argv
[0]) > 0) {
421 hostname
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
424 ok
= SCPreferencesSetHostName(prefs
, hostname
);
425 if (hostname
!= NULL
) CFRelease(hostname
);
429 CFSTR("SCPreferencesSetHostName() failed: %s\n"),
430 SCErrorString(SCError()));
442 get_LocalHostName(int argc
, char **argv
)
444 CFStringRef hostname
;
446 hostname
= SCDynamicStoreCopyLocalHostName(NULL
);
447 if (hostname
== NULL
) {
448 int sc_status
= SCError();
451 case kSCStatusNoKey
:
454 CFSTR("LocalHostName: not set\n"));
459 CFSTR("SCDynamicStoreCopyLocalHostName() failed: %s\n"),
460 SCErrorString(SCError()));
466 SCPrint(TRUE
, stdout
, CFSTR("%@\n"), hostname
);
474 set_LocalHostName(int argc
, char **argv
)
476 CFStringRef hostname
= NULL
;
479 ok
= _prefs_open(CFSTR("scutil --set LocalHostName"), NULL
);
483 CFSTR("Could not open prefs: %s\n"),
484 SCErrorString(SCError()));
489 CFStringRef old_hostname
;
491 old_hostname
= SCDynamicStoreCopyLocalHostName(NULL
);
492 hostname
= _copyStringFromSTDIN(CFSTR("LocalHostName"), old_hostname
);
493 if (old_hostname
) CFRelease(old_hostname
);
494 } else if (strlen(argv
[0]) > 0) {
495 hostname
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
498 ok
= SCPreferencesSetLocalHostName(prefs
, hostname
);
499 if (hostname
!= NULL
) CFRelease(hostname
);
503 CFSTR("SCPreferencesSetLocalHostName() failed: %s\n"),
504 SCErrorString(SCError()));
515 /* -------------------- */
518 typedef void (*pref_func
) (int argc
, char **argv
);
520 static const struct {
525 { "ComputerName", get_ComputerName
, set_ComputerName
},
526 { "HostName", get_HostName
, set_HostName
},
527 { "LocalHostName", get_LocalHostName
, set_LocalHostName
}
529 #define N_PREF_KEYS (sizeof(pref_keys) / sizeof(pref_keys[0]))
538 for (i
= 0; i
< (int)N_PREF_KEYS
; i
++) {
539 if (strcmp(pref
, pref_keys
[i
].pref
) == 0) {
550 do_getPref(char *pref
, int argc
, char **argv
)
557 (*pref_keys
[i
].get
)(argc
, argv
);
562 // process extended get
563 // ie. scutil --get <filename> <prefs path> <key>
566 do_prefs_open(argc
, argv
);
567 if (SCError() != kSCStatusOK
) {
568 SCPrint(TRUE
, stderr
, CFSTR("%s\n"), SCErrorString(SCError()));
573 do_prefs_get(--argc
, ++argv
);
576 CFStringRef prefs_val
;
578 key
= CFStringCreateWithCString(NULL
, *(++argv
), kCFStringEncodingUTF8
);
579 prefs_val
= CFDictionaryGetValue(value
, key
);
582 if (prefs_val
!= NULL
) {
583 SCPrint(TRUE
, stdout
, CFSTR("%@\n"), prefs_val
);
589 // if path or key not found
597 do_setPref(char *pref
, int argc
, char **argv
)
603 (*pref_keys
[i
].set
)(argc
, argv
);
609 /* -------------------- */
622 do_prefs_open(int argc
, char **argv
)
625 CFStringRef prefsID
= NULL
;
628 if (_prefs_commitRequired(argc
, argv
, "close")) {
632 do_prefs_close(0, NULL
);
636 prefsID
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
639 ok
= _prefs_open(CFSTR("scutil --prefs"), prefsID
);
640 if (prefsID
!= NULL
) CFRelease(prefsID
);
644 CFSTR("Could not open prefs: %s\n"),
645 SCErrorString(SCError()));
655 do_prefs_lock(int argc
, char **argv
)
657 Boolean wait
= (argc
> 0) ? TRUE
: FALSE
;
659 if (!SCPreferencesLock(prefs
, wait
)) {
660 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
670 do_prefs_unlock(int argc
, char **argv
)
672 if (!SCPreferencesUnlock(prefs
)) {
673 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
683 do_prefs_commit(int argc
, char **argv
)
685 if (!SCPreferencesCommitChanges(prefs
)) {
686 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
690 _prefs_changed
= FALSE
;
697 do_prefs_apply(int argc
, char **argv
)
699 if (!SCPreferencesApplyChanges(prefs
)) {
700 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
709 do_prefs_close(int argc
, char **argv
)
711 if (_prefs_commitRequired(argc
, argv
, "close")) {
722 do_prefs_quit(int argc
, char **argv
)
724 if (_prefs_commitRequired(argc
, argv
, "quit")) {
730 termRequested
= TRUE
;
737 do_prefs_synchronize(int argc
, char **argv
)
739 SCPreferencesSynchronize(prefs
);
744 static CFComparisonResult
745 sort_paths(const void *p1
, const void *p2
, void *context
) {
746 CFStringRef path1
= (CFStringRef
)p1
;
747 CFStringRef path2
= (CFStringRef
)p2
;
748 return CFStringCompare(path1
, path2
, 0);
754 do_prefs_list(int argc
, char **argv
)
758 CFMutableArrayRef paths
= NULL
;
760 CFDictionaryRef entity
;
762 prefix
= CFStringCreateWithCString(NULL
,
763 (argc
>= 1) ? argv
[0] : "/",
764 kCFStringEncodingUTF8
);
766 entity
= SCPreferencesPathGetValue(prefs
, prefix
);
767 if (entity
== NULL
) {
768 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
772 paths
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
774 n
= isA_CFDictionary(entity
) ? CFDictionaryGetCount(entity
) : 0;
780 keys
= CFAllocatorAllocate(NULL
, n
* sizeof(CFStringRef
), 0);
781 vals
= CFAllocatorAllocate(NULL
, n
* sizeof(CFPropertyListRef
), 0);
782 CFDictionaryGetKeysAndValues(entity
, keys
, vals
);
783 for (i
= 0; i
< n
; i
++) {
784 if (isA_CFDictionary(vals
[i
])) {
785 CFArrayAppendValue(paths
, keys
[i
]);
788 CFAllocatorDeallocate(NULL
, keys
);
789 CFAllocatorDeallocate(NULL
, vals
);
792 n
= CFArrayGetCount(paths
);
793 CFArraySortValues(paths
,
799 for (i
= 0; i
< n
; i
++) {
802 CFSTR(" path [%d] = %@/%@\n"),
804 CFEqual(prefix
, CFSTR("/")) ? CFSTR("") : prefix
,
805 CFArrayGetValueAtIndex(paths
, i
));
808 SCPrint(TRUE
, stdout
, CFSTR(" no paths.\n"));
822 do_prefs_get(int argc
, char **argv
)
824 CFDictionaryRef dict
;
827 CFMutableDictionaryRef newDict
;
830 path
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
832 link
= SCPreferencesPathGetLink(prefs
, path
);
834 SCPrint(TRUE
, stdout
, CFSTR(" --> %@\n"), link
);
837 dict
= SCPreferencesPathGetValue(prefs
, path
);
840 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
844 newDict
= CFDictionaryCreateMutable(NULL
,
846 &kCFTypeDictionaryKeyCallBacks
,
847 &kCFTypeDictionaryValueCallBacks
);
849 // remove [path] children
850 n
= isA_CFDictionary(dict
) ? CFDictionaryGetCount(dict
) : 0;
856 keys
= CFAllocatorAllocate(NULL
, n
* sizeof(CFStringRef
), 0);
857 vals
= CFAllocatorAllocate(NULL
, n
* sizeof(CFPropertyListRef
), 0);
858 CFDictionaryGetKeysAndValues(dict
, keys
, vals
);
859 for (i
= 0; i
< n
; i
++) {
860 if (!isA_CFDictionary(vals
[i
])) {
861 CFDictionaryAddValue(newDict
, keys
[i
], vals
[i
]);
864 CFAllocatorDeallocate(NULL
, keys
);
865 CFAllocatorDeallocate(NULL
, vals
);
869 CFRelease(value
); /* we have new information, release the old */
880 do_prefs_set(int argc
, char **argv
)
882 CFDictionaryRef dict
;
883 CFMutableDictionaryRef newDict
= NULL
;
886 path
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
887 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, value
);
889 dict
= SCPreferencesPathGetValue(prefs
, path
);
893 // retain [path] children
894 n
= CFDictionaryGetCount(dict
);
900 keys
= CFAllocatorAllocate(NULL
, n
* sizeof(CFStringRef
), 0);
901 vals
= CFAllocatorAllocate(NULL
, n
* sizeof(CFPropertyListRef
), 0);
902 CFDictionaryGetKeysAndValues(dict
, keys
, vals
);
903 for (i
= 0; i
< n
; i
++) {
904 if (isA_CFDictionary(vals
[i
])) {
905 if (CFDictionaryContainsKey(newDict
, keys
[i
])) {
906 SCPrint(TRUE
, stdout
, CFSTR(" key %@ is already a path component and cannot be replaced\n"), keys
[i
]);
909 CFDictionaryAddValue(newDict
, keys
[i
], vals
[i
]);
912 CFAllocatorDeallocate(NULL
, keys
);
913 CFAllocatorDeallocate(NULL
, vals
);
915 } else if (SCError() == kSCStatusInvalidArgument
) {
916 SCPrint(TRUE
, stdout
, CFSTR(" a path component is not a dictionary\n"));
918 } else if (SCError() != kSCStatusNoKey
) {
919 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
928 link
= CFStringCreateWithCString(NULL
, argv
[1], kCFStringEncodingUTF8
);
929 ok
= SCPreferencesPathSetLink(prefs
, path
, link
);
932 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
937 if (!SCPreferencesPathSetValue(prefs
, path
, newDict
)) {
938 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
943 _prefs_changed
= TRUE
;
955 do_prefs_remove(int argc
, char **argv
)
959 path
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
961 if (!SCPreferencesPathRemoveValue(prefs
, path
)) {
962 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
966 _prefs_changed
= TRUE
;
975 on_off_str(Boolean on
)
977 return (on
? "on" : "off");
980 /* -------------------- */
982 #include "IPMonitorControlPrefs.h"
986 do_log(char * log
, int argc
, char **argv
)
988 Boolean verbose
= FALSE
;
990 if (strcmp(log
, "IPMonitor")) {
995 SCPrint(TRUE
, stdout
, CFSTR("IPMonitor log is %s\n"),
996 on_off_str(IPMonitorControlPrefsIsVerbose()));
1000 if ((strcasecmp(argv
[0], "disable") == 0) ||
1001 (strcasecmp(argv
[0], "no" ) == 0) ||
1002 (strcasecmp(argv
[0], "off" ) == 0) ||
1003 (strcasecmp(argv
[0], "0" ) == 0)) {
1005 } else if ((strcasecmp(argv
[0], "enable") == 0) ||
1006 (strcasecmp(argv
[0], "yes" ) == 0) ||
1007 (strcasecmp(argv
[0], "on" ) == 0) ||
1008 (strcasecmp(argv
[0], "1" ) == 0)) {
1011 SCPrint(TRUE
, stdout
, CFSTR("invalid value, must be 'on' or 'off'\n"));
1015 if (!IPMonitorControlPrefsSetVerbose(verbose
)) {
1016 SCPrint(TRUE
, stderr
, CFSTR("failed to set preferences\n"));
1025 /* -------------------- */
1027 static SCNetworkInterfaceRef
1028 copy_configured_interface(SCPreferencesRef prefs
, CFStringRef if_name
)
1030 SCNetworkSetRef current_set
= NULL
;
1033 SCNetworkInterfaceRef ret_if
= NULL
;
1034 CFArrayRef services
= NULL
;
1036 if (prefs
== NULL
) {
1039 current_set
= SCNetworkSetCopyCurrent(prefs
);
1040 if (current_set
== NULL
) {
1043 services
= SCNetworkSetCopyServices(current_set
);
1044 if (services
== NULL
) {
1048 count
= CFArrayGetCount(services
);
1049 for (i
= 0; i
< count
; i
++) {
1050 CFStringRef this_if_name
;
1051 SCNetworkInterfaceRef this_if
;
1052 SCNetworkServiceRef s
;
1054 s
= (SCNetworkServiceRef
)CFArrayGetValueAtIndex(services
, i
);
1055 if (!SCNetworkServiceGetEnabled(s
)) {
1056 /* skip disabled services */
1059 this_if
= SCNetworkServiceGetInterface(s
);
1060 if (this_if
== NULL
) {
1063 this_if_name
= SCNetworkInterfaceGetBSDName(this_if
);
1064 if (this_if_name
== NULL
) {
1067 if (CFEqual(this_if_name
, if_name
)) {
1075 if (current_set
!= NULL
) {
1076 CFRelease(current_set
);
1078 if (services
!= NULL
) {
1079 CFRelease(services
);
1085 disable_until_needed_usage(void)
1087 fprintf(stderr
, "usage: scutil --disable-until-needed <interfaceName> [on|off|default]\n");
1091 #include <SystemConfiguration/SCNetworkConfigurationPrivate.h>
1095 do_disable_until_needed(int argc
, char **argv
)
1097 const char * if_name
;
1098 CFStringRef if_name_cf
;
1099 SCNetworkInterfaceRef net_if
;
1101 const char * on_off
= "?";
1103 Boolean set_default
= FALSE
;
1104 Boolean set_value
= FALSE
;
1106 if (argc
< 1 || argc
> 2) {
1107 disable_until_needed_usage();
1113 if (strcasecmp(on_off
, "on") == 0) {
1115 } else if (strcasecmp(on_off
, "off") == 0) {
1117 } else if ((strcmp(on_off
, "") == 0) || (strcasecmp(on_off
, "default") == 0)) {
1121 disable_until_needed_usage();
1126 ok
= _prefs_open(CFSTR("scutil --disable-until-needed"), NULL
);
1130 CFSTR("Could not open prefs: %s\n"),
1131 SCErrorString(SCError()));
1134 if_name_cf
= CFStringCreateWithCStringNoCopy(NULL
,
1136 kCFStringEncodingASCII
,
1138 net_if
= copy_configured_interface(prefs
, if_name_cf
);
1139 if (net_if
== NULL
) {
1140 fprintf(stderr
, "%s is not configured\n", if_name
);
1145 ok
= SCNetworkInterfaceSetDisableUntilNeeded(net_if
, on
);
1147 ok
= __SCNetworkInterfaceSetDisableUntilNeededValue(net_if
, NULL
);
1150 fprintf(stderr
, "failed to turn disable-until-needed %s\n",
1156 on
= SCNetworkInterfaceGetDisableUntilNeeded(net_if
);
1157 printf("%s disable-until-needed is %s\n", if_name
, on_off_str(on
));