2 * Copyright (c) 2006-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 * June 26, 2006 Allan Nathanson <ajn@apple.com>
34 #include <sys/param.h>
35 #include <sys/types.h>
36 #include <sys/socket.h>
38 #include <sys/sysctl.h>
41 #include <net/if_dl.h>
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
44 #include <netdb_async.h>
46 #include <smb_server_prefs.h>
48 #include <CoreFoundation/CoreFoundation.h>
49 #include <CoreFoundation/CFStringDefaultEncoding.h> // for __CFStringGetInstallationEncodingAndRegion()
50 #include <SystemConfiguration/SystemConfiguration.h>
51 #include <SystemConfiguration/SCValidation.h>
52 #include <SystemConfiguration/SCPrivate.h>
55 #define my_log(__level, __format, ...) SCPrint(TRUE, stdout, CFSTR(__format "\n"), ## __VA_ARGS__)
57 #include "ip_plugin.h"
60 #define HW_MODEL_LEN 64 // Note: must be >= NETBIOS_NAME_LEN (below)
62 #define NETBIOS_NAME_LEN 16
64 #define SMB_STARTUP_DELAY 60.0
65 #define SMB_DEBOUNCE_DELAY 5.0
66 #define SMB_CONFIGURATION_QUEUE "com.apple.config.smb-configuration"
68 static SCDynamicStoreRef store
= NULL
;
69 static CFRunLoopRef rl
= NULL
;
70 static CFRunLoopSourceRef rls
= NULL
;
71 static dispatch_queue_t queue
= NULL
;
73 static int notify_token
= -1;
75 static struct timeval ptrQueryStart
;
76 static SCNetworkReachabilityRef ptrTarget
= NULL
;
78 static CFRunLoopTimerRef timer
= NULL
;
84 static CFAbsoluteTime bt
= 0;
87 int mib
[2] = { CTL_KERN
, KERN_BOOTTIME
};
89 size_t tv_len
= sizeof(tv
);
91 if (sysctl(mib
, sizeof(mib
) / sizeof(mib
[0]), &tv
, &tv_len
, NULL
, 0) == -1) {
92 my_log(LOG_ERR
, "sysctl() CTL_KERN/KERN_BOOTTIME failed: %s", strerror(errno
));
93 return kCFAbsoluteTimeIntervalSince1970
;
96 // Note: we need to convert from Unix time to CF time.
97 bt
= (CFTimeInterval
)tv
.tv_sec
- kCFAbsoluteTimeIntervalSince1970
;
98 bt
+= (1.0E-6 * (CFTimeInterval
)tv
.tv_usec
);
106 copy_default_name(void)
110 CFMutableStringRef str
;
113 model
= _SC_hw_model(TRUE
);
118 // start off with the [trunated] HW model
119 str
= CFStringCreateMutable(NULL
, 0);
120 CFStringAppend(str
, model
);
122 // truncate as needed
123 n
= CFStringGetLength(str
);
124 if (n
> (NETBIOS_NAME_LEN
- 1)) {
126 CFRangeMake(NETBIOS_NAME_LEN
, n
- (NETBIOS_NAME_LEN
- 1)),
128 n
= NETBIOS_NAME_LEN
- 1;
132 // if there is room for at least one byte (two hex characters)
133 // of the MAC address than append that to the NetBIOS name.
135 // NETBIOS_NAME_LEN max length
136 // -1 the last byte is reserved
139 if (n
< (NETBIOS_NAME_LEN
- 1 - 3)) {
140 SCNetworkInterfaceRef interface
;
142 interface
= _SCNetworkInterfaceCreateWithBSDName(NULL
, CFSTR("en0"),
143 kIncludeNoVirtualInterfaces
);
144 if (interface
!= NULL
) {
145 CFMutableStringRef en0_MAC
;
147 en0_MAC
= (CFMutableStringRef
)SCNetworkInterfaceGetHardwareAddressString(interface
);
148 if (en0_MAC
!= NULL
) {
151 // remove ":" characters from MAC address string
152 en0_MAC
= CFStringCreateMutableCopy(NULL
, 0, en0_MAC
);
153 CFStringFindAndReplace(en0_MAC
,
156 CFRangeMake(0, CFStringGetLength(en0_MAC
)),
160 // compute how may bytes (characters) to append
161 // ... and limit that number to 6
163 // NETBIOS_NAME_LEN max length
164 // -1 the last byte is reserved
168 n
= ((NETBIOS_NAME_LEN
- 1 - n
- 1) / 2) * 2;
173 // remove what we don't want
174 en0_MAC_len
= CFStringGetLength(en0_MAC
);
175 if (en0_MAC_len
> n
) {
176 CFStringDelete(en0_MAC
, CFRangeMake(0, en0_MAC_len
- n
));
180 CFStringAppendFormat(str
, NULL
, CFSTR("-%@"), en0_MAC
);
184 CFRelease(interface
);
188 CFStringUppercase(str
, NULL
);
193 static CFDictionaryRef
194 smb_copy_global_configuration(SCDynamicStoreRef store
)
196 CFDictionaryRef dict
;
199 key
= SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL
,
200 kSCDynamicStoreDomainState
,
202 dict
= SCDynamicStoreCopyValue(store
, key
);
206 if (isA_CFDictionary(dict
)) {
213 dict
= CFDictionaryCreate(NULL
, // allocator
217 &kCFTypeDictionaryKeyCallBacks
,
218 &kCFTypeDictionaryValueCallBacks
);
224 update_pref(SCPreferencesRef prefs
, CFStringRef key
, CFTypeRef newVal
, Boolean
*changed
)
228 curVal
= SCPreferencesGetValue(prefs
, key
);
229 if (!_SC_CFEqual(curVal
, newVal
)) {
230 if (newVal
!= NULL
) {
231 SCPreferencesSetValue(prefs
, key
, newVal
);
233 SCPreferencesRemoveValue(prefs
, key
);
244 smb_set_configuration(SCDynamicStoreRef store
, CFDictionaryRef dict
)
247 Boolean changed
= FALSE
;
248 UInt32 dosCodepage
= 0;
249 CFStringEncoding dosEncoding
= 0;
250 CFStringEncoding macEncoding
= kCFStringEncodingMacRoman
;
251 uint32_t macRegion
= 0;
253 SCPreferencesRef prefs
;
256 prefs
= SCPreferencesCreate(NULL
, CFSTR("smb-configuration"), CFSTR(kSMBPreferencesAppID
));
259 "smb_set_configuration: SCPreferencesCreate() failed: %s",
260 SCErrorString(SCError()));
264 ok
= SCPreferencesLock(prefs
, TRUE
);
267 "smb_set_configuration: SCPreferencesLock() failed: %s",
268 SCErrorString(SCError()));
272 // Server description
273 str
= SCDynamicStoreCopyComputerName(store
, &macEncoding
);
274 update_pref(prefs
, CFSTR(kSMBPrefServerDescription
), str
, &changed
);
278 if (macEncoding
== kCFStringEncodingMacRoman
) {
280 CFDictionaryRef dict
;
283 key
= SCDynamicStoreKeyCreateComputerName(NULL
);
284 dict
= SCDynamicStoreCopyValue(store
, key
);
287 if (isA_CFDictionary(dict
)) {
291 num
= CFDictionaryGetValue(dict
, kSCPropSystemComputerNameRegion
);
292 if (isA_CFNumber(num
) &&
293 CFNumberGetValue(num
, kCFNumberSInt32Type
, &val
)) {
294 macRegion
= (uint32_t)val
;
304 // Important: must have root acccess (eUID==0) to access the config file!
305 __CFStringGetInstallationEncodingAndRegion((uint32_t *)&macEncoding
, &macRegion
);
307 _SC_dos_encoding_and_codepage(macEncoding
, macRegion
, &dosEncoding
, &dosCodepage
);
308 str
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), (unsigned int)dosCodepage
);
310 update_pref(prefs
, CFSTR(kSMBPrefDOSCodePage
), str
, &changed
);
314 str
= CFDictionaryGetValue(dict
, kSCPropNetSMBNetBIOSName
);
315 str
= isA_CFString(str
);
316 update_pref(prefs
, CFSTR(kSMBPrefNetBIOSName
), str
, &changed
);
319 str
= CFDictionaryGetValue(dict
, kSCPropNetSMBNetBIOSNodeType
);
320 str
= isA_CFString(str
);
322 if (CFEqual(str
, kSCValNetSMBNetBIOSNodeTypeBroadcast
)) {
324 str
= CFSTR(kSMBPrefNetBIOSNodeBroadcast
);
325 } else if (CFEqual(str
, kSCValNetSMBNetBIOSNodeTypePeer
)) {
327 str
= CFSTR(kSMBPrefNetBIOSNodePeer
);
328 } else if (CFEqual(str
, kSCValNetSMBNetBIOSNodeTypeMixed
)) {
330 str
= CFSTR(kSMBPrefNetBIOSNodeMixed
);
331 } else if (CFEqual(str
, kSCValNetSMBNetBIOSNodeTypeHybrid
)) {
333 str
= CFSTR(kSMBPrefNetBIOSNodeHybrid
);
338 update_pref(prefs
, CFSTR(kSMBPrefNetBIOSNodeType
), str
, &changed
);
340 #ifdef ADD_NETBIOS_SCOPE
342 str
= CFDictionaryGetValue(dict
, kSCPropNetSMBNetBIOSScope
);
343 str
= isA_CFString(str
);
344 update_pref(prefs
, CFSTR(kSMBPrefNetBIOSScope
), str
, &changed
);
345 #endif // ADD_NETBIOS_SCOPE
348 array
= CFDictionaryGetValue(dict
, kSCPropNetSMBWINSAddresses
);
349 array
= isA_CFArray(array
);
350 update_pref(prefs
, CFSTR(kSMBPrefWINSServerAddressList
), array
, &changed
);
352 // Workgroup (or domain)
353 str
= CFDictionaryGetValue(dict
, kSCPropNetSMBWorkgroup
);
354 str
= isA_CFString(str
);
355 update_pref(prefs
, CFSTR(kSMBPrefWorkgroup
), str
, &changed
);
358 ok
= SCPreferencesCommitChanges(prefs
);
360 if ((SCError() != EROFS
)) {
362 "smb_set_configuration: SCPreferencesCommitChanges() failed: %s",
363 SCErrorString(SCError()));
368 ok
= SCPreferencesApplyChanges(prefs
);
371 "smb_set_configuration: SCPreferencesApplyChanges() failed: %s",
372 SCErrorString(SCError()));
379 (void) SCPreferencesUnlock(prefs
);
386 copy_primary_service(SCDynamicStoreRef store
)
388 CFDictionaryRef dict
;
390 CFStringRef serviceID
= NULL
;
392 key
= SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL
,
393 kSCDynamicStoreDomainState
,
395 dict
= SCDynamicStoreCopyValue(store
, key
);
399 if (isA_CFDictionary(dict
)) {
400 serviceID
= CFDictionaryGetValue(dict
, kSCDynamicStorePropNetPrimaryService
);
401 if (isA_CFString(serviceID
)) {
415 copy_primary_ip(SCDynamicStoreRef store
, CFStringRef serviceID
)
417 CFStringRef address
= NULL
;
418 CFDictionaryRef dict
;
421 key
= SCDynamicStoreKeyCreateNetworkServiceEntity(NULL
,
422 kSCDynamicStoreDomainState
,
425 dict
= SCDynamicStoreCopyValue(store
, key
);
429 if (isA_CFDictionary(dict
)) {
430 CFArrayRef addresses
;
432 addresses
= CFDictionaryGetValue(dict
, kSCPropNetIPv4Addresses
);
433 if (isA_CFArray(addresses
) && (CFArrayGetCount(addresses
) > 0)) {
434 address
= CFArrayGetValueAtIndex(addresses
, 0);
435 if (isA_CFString(address
)) {
452 if (ptrTarget
== NULL
) {
456 my_log(LOG_INFO
, "NetBIOS name: ptr query stop");
458 SCNetworkReachabilitySetCallback(ptrTarget
, NULL
, NULL
);
459 SCNetworkReachabilityUnscheduleFromRunLoop(ptrTarget
, rl
, kCFRunLoopDefaultMode
);
460 CFRelease(ptrTarget
);
468 ptr_query_callback(SCNetworkReachabilityRef target
, SCNetworkReachabilityFlags flags
, void *info
)
471 CFDictionaryRef dict
;
473 CFMutableDictionaryRef newDict
;
474 struct timeval ptrQueryComplete
;
475 struct timeval ptrQueryElapsed
;
477 (void) gettimeofday(&ptrQueryComplete
, NULL
);
478 timersub(&ptrQueryComplete
, &ptrQueryStart
, &ptrQueryElapsed
);
479 my_log(LOG_INFO
, "NetBIOS name: ptr query complete%s (query time = %ld.%3.3d)",
480 (flags
& kSCNetworkReachabilityFlagsReachable
) ? "" : ", host not found",
481 ptrQueryElapsed
.tv_sec
,
482 ptrQueryElapsed
.tv_usec
/ 1000);
484 // get network configuration
485 dict
= smb_copy_global_configuration(store
);
487 // use NetBIOS name from network configuration (if available)
488 name
= CFDictionaryGetValue(dict
, kSCPropNetSMBNetBIOSName
);
489 if ((name
!= NULL
) && _SC_CFStringIsValidNetBIOSName(name
)) {
490 my_log(LOG_INFO
, "NetBIOS name (network configuration) = %@", name
);
494 // use reverse DNS name, if available
497 if (flags
& kSCNetworkReachabilityFlagsReachable
) {
502 * if [reverse] DNS query was successful
504 hosts
= SCNetworkReachabilityCopyResolvedAddress(target
, &error_num
);
506 if (CFArrayGetCount(hosts
) > 0) {
508 CFMutableStringRef ptrName
;
511 name
= CFArrayGetValueAtIndex(hosts
, 0);
512 ptrName
= CFStringCreateMutableCopy(NULL
, 0, name
);
513 ptrLen
= CFStringGetLength(ptrName
);
514 if (CFStringFindWithOptions(ptrName
,
516 CFRangeMake(0, ptrLen
),
519 CFStringDelete(ptrName
,
520 CFRangeMake(range
.location
, ptrLen
- range
.location
));
528 if (_SC_CFStringIsValidNetBIOSName(name
)) {
529 my_log(LOG_INFO
, "NetBIOS name (reverse DNS query) = %@", name
);
535 // try local (multicast DNS) name, if available
536 name
= SCDynamicStoreCopyLocalHostName(store
);
538 if (_SC_CFStringIsValidNetBIOSName(name
)) {
539 my_log(LOG_INFO
, "NetBIOS name (multicast DNS) = %@", name
);
545 // use "default" name
546 name
= copy_default_name();
548 my_log(LOG_INFO
, "NetBIOS name (default) = %@", name
);
556 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
557 CFDictionarySetValue(newDict
, kSCPropNetSMBNetBIOSName
, name
);
564 // update SMB configuration
565 smb_set_configuration(store
, dict
);
579 ptr_query_start(CFStringRef address
)
583 struct sockaddr_in sin
;
584 struct sockaddr_in6 sin6
;
588 CFMutableDictionaryRef options
;
590 if (_SC_cfstring_to_cstring(address
, buf
, sizeof(buf
), kCFStringEncodingASCII
) == NULL
) {
591 my_log(LOG_ERR
, "could not convert [primary] address string");
595 if (_SC_string_to_sockaddr(buf
, AF_UNSPEC
, (void *)&addr
, sizeof(addr
)) == NULL
) {
596 my_log(LOG_ERR
, "could not convert [primary] address");
600 options
= CFDictionaryCreateMutable(NULL
,
602 &kCFTypeDictionaryKeyCallBacks
,
603 &kCFTypeDictionaryValueCallBacks
);
604 data
= CFDataCreate(NULL
, (const UInt8
*)&addr
.sa
, addr
.sa
.sa_len
);
605 CFDictionarySetValue(options
, kSCNetworkReachabilityOptionPTRAddress
, data
);
607 ptrTarget
= SCNetworkReachabilityCreateWithOptions(NULL
, options
);
609 if (ptrTarget
== NULL
) {
610 my_log(LOG_ERR
, "could not resolve [primary] address");
614 my_log(LOG_INFO
, "NetBIOS name: ptr query start");
616 (void) SCNetworkReachabilitySetCallback(ptrTarget
, ptr_query_callback
, NULL
);
617 (void) SCNetworkReachabilityScheduleWithRunLoop(ptrTarget
, rl
, kCFRunLoopDefaultMode
);
624 smb_update_configuration(CFRunLoopTimerRef _timer
, void *info
)
626 #pragma unused(_timer)
627 CFStringRef address
= NULL
;
628 CFDictionaryRef dict
;
630 CFStringRef serviceID
= NULL
;
631 SCDynamicStoreRef store
= (SCDynamicStoreRef
)info
;
633 // get network configuration
634 dict
= smb_copy_global_configuration(store
);
636 // use NetBIOS name from network configuration (if available)
637 name
= CFDictionaryGetValue(dict
, kSCPropNetSMBNetBIOSName
);
638 if ((name
!= NULL
) && _SC_CFStringIsValidNetBIOSName(name
)) {
639 my_log(LOG_INFO
, "NetBIOS name (network configuration) = %@", name
);
643 // get primary service ID
644 serviceID
= copy_primary_service(store
);
645 if (serviceID
== NULL
) {
646 // if no primary service
650 // get DNS name associated with primary IP, if available
651 address
= copy_primary_ip(store
, serviceID
);
652 if (address
!= NULL
) {
655 // start reverse DNS query using primary IP address
656 ok
= ptr_query_start(address
);
665 // get local (multicast DNS) name, if available
667 name
= SCDynamicStoreCopyLocalHostName(store
);
669 if (_SC_CFStringIsValidNetBIOSName(name
)) {
670 CFMutableDictionaryRef newDict
;
672 my_log(LOG_INFO
, "NetBIOS name (multicast DNS) = %@", name
);
673 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
674 CFDictionarySetValue(newDict
, kSCPropNetSMBNetBIOSName
, name
);
683 // get "default" name
684 name
= copy_default_name();
686 CFMutableDictionaryRef newDict
;
688 my_log(LOG_INFO
, "NetBIOS name (default) = %@", name
);
689 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
690 CFDictionarySetValue(newDict
, kSCPropNetSMBNetBIOSName
, name
);
698 // update SMB configuration
699 smb_set_configuration(store
, dict
);
703 if (address
!= NULL
) CFRelease(address
);
704 if (dict
!= NULL
) CFRelease(dict
);
705 if (serviceID
!= NULL
) CFRelease(serviceID
);
708 CFRunLoopTimerInvalidate(timer
);
718 configuration_changed(SCDynamicStoreRef store
, CFArrayRef changedKeys
, void *info
)
720 #pragma unused(changedKeys)
722 CFRunLoopTimerContext context
= { 0, (void *)store
, CFRetain
, CFRelease
, NULL
};
723 CFAbsoluteTime time_boot
;
724 CFAbsoluteTime time_now
;
726 // if active, cancel any in-progress attempt to resolve the primary IP address
728 if (ptrTarget
!= NULL
) {
732 // if active, cancel any queued configuration change
734 CFRunLoopTimerInvalidate(timer
);
739 // queue configuration change
740 time_boot
= boottime() + SMB_STARTUP_DELAY
;
741 time_now
= CFAbsoluteTimeGetCurrent() + SMB_DEBOUNCE_DELAY
;
743 timer
= CFRunLoopTimerCreate(NULL
,
744 time_now
> time_boot
? time_now
: time_boot
,
748 smb_update_configuration
,
750 CFRunLoopAddTimer(rl
, timer
, kCFRunLoopDefaultMode
);
758 load_smb_configuration(Boolean verbose
)
760 #pragma unused(verbose)
762 CFMutableArrayRef keys
= NULL
;
763 dispatch_block_t notify_block
;
765 CFMutableArrayRef patterns
= NULL
;
768 /* initialize a few globals */
769 queue
= dispatch_queue_create(SMB_CONFIGURATION_QUEUE
, NULL
);
772 "dispatch_queue_create() failed");
776 store
= SCDynamicStoreCreate(NULL
, CFSTR("smb-configuration"), configuration_changed
, NULL
);
779 "SCDynamicStoreCreate() failed: %s",
780 SCErrorString(SCError()));
784 /* establish notification keys and patterns */
786 keys
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
787 patterns
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
789 /* ...watch for SMB configuration changes */
790 key
= SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL
,
791 kSCDynamicStoreDomainState
,
793 CFArrayAppendValue(keys
, key
);
796 /* ...watch for ComputerName changes */
797 key
= SCDynamicStoreKeyCreateComputerName(NULL
);
798 CFArrayAppendValue(keys
, key
);
801 /* ...watch for local (multicast DNS) hostname changes */
802 key
= SCDynamicStoreKeyCreateHostNames(NULL
);
803 CFArrayAppendValue(keys
, key
);
806 /* register the keys/patterns */
807 ok
= SCDynamicStoreSetNotificationKeys(store
, keys
, patterns
);
812 "SCDynamicStoreSetNotificationKeys() failed: %s",
813 SCErrorString(SCError()));
817 rl
= CFRunLoopGetCurrent();
818 rls
= SCDynamicStoreCreateRunLoopSource(NULL
, store
, 0);
821 "SCDynamicStoreCreateRunLoopSource() failed: %s",
822 SCErrorString(SCError()));
825 CFRunLoopAddSource(rl
, rls
, kCFRunLoopDefaultMode
);
827 /* ...watch for primary service/interface and DNS configuration changes */
832 key
= SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL
,
833 kSCDynamicStoreDomainState
,
835 changes
= CFArrayCreate(NULL
, (const void **)&key
, 1, &kCFTypeArrayCallBacks
);
836 (*configuration_changed
)(store
, changes
, NULL
);
842 status
= notify_register_dispatch(_SC_NOTIFY_NETWORK_CHANGE
,
846 #pragma unused(token)
847 CFRunLoopPerformBlock(rl
,
848 kCFRunLoopDefaultMode
,
852 if (status
!= NOTIFY_STATUS_OK
) {
853 my_log(LOG_ERR
, "notify_register_dispatch() failed: %u", status
);
862 CFRunLoopRemoveSource(rl
, rls
, kCFRunLoopDefaultMode
);
871 dispatch_release(queue
);
881 main(int argc
, char **argv
)
887 CFStringRef serviceID
;
888 SCDynamicStoreRef store
;
891 if ((argc
> 1) && (strcmp(argv
[1], "-d") == 0)) {
897 store
= SCDynamicStoreCreate(NULL
, CFSTR("smb-configuration"), NULL
, NULL
);
899 SCPrint(TRUE
, stdout
,
900 CFSTR("SCDynamicStoreCreate() failed: %s\n"),
901 SCErrorString(SCError()));
905 // get "default" name
906 name
= copy_default_name();
908 SCPrint(TRUE
, stdout
, CFSTR("default name = %@\n"), name
);
912 // get primary service
913 serviceID
= copy_primary_service(store
);
914 if (serviceID
!= NULL
) {
915 SCPrint(TRUE
, stdout
, CFSTR("primary service ID = %@\n"), serviceID
);
917 SCPrint(TRUE
, stdout
, CFSTR("No primary service\n"));
921 if ((argc
== (2+1)) && (argv
[1][0] == 's')) {
922 if (serviceID
!= NULL
) CFRelease(serviceID
);
923 serviceID
= CFStringCreateWithCString(NULL
, argv
[2], kCFStringEncodingUTF8
);
924 SCPrint(TRUE
, stdout
, CFSTR("alternate service ID = %@\n"), serviceID
);
927 // get primary IP address
928 address
= copy_primary_ip(store
, serviceID
);
929 CFRelease(serviceID
);
930 if (address
!= NULL
) {
931 SCPrint(TRUE
, stdout
, CFSTR("primary address = %@\n"), address
);
933 if ((argc
== (2+1)) && (argv
[1][0] == 'a')) {
934 if (address
!= NULL
) CFRelease(address
);
935 address
= CFStringCreateWithCString(NULL
, argv
[2], kCFStringEncodingUTF8
);
936 SCPrint(TRUE
, stdout
, CFSTR("alternate primary address = %@\n"), address
);
939 // start reverse DNS query using primary IP address
940 (void) ptr_query_start(address
);
946 smb_update_configuration(NULL
, (void *)store
);
955 _sc_verbose
= (argc
> 1) ? TRUE
: FALSE
;
957 load_smb_configuration((argc
> 1) ? TRUE
: FALSE
);