2 * Copyright (c) 2006-2018 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) gettimeofday(&ptrQueryStart
, NULL
);
617 (void) SCNetworkReachabilitySetCallback(ptrTarget
, ptr_query_callback
, NULL
);
618 (void) SCNetworkReachabilityScheduleWithRunLoop(ptrTarget
, rl
, kCFRunLoopDefaultMode
);
625 smb_update_configuration(CFRunLoopTimerRef _timer
, void *info
)
627 #pragma unused(_timer)
628 CFStringRef address
= NULL
;
629 CFDictionaryRef dict
;
631 CFStringRef serviceID
= NULL
;
632 SCDynamicStoreRef store
= (SCDynamicStoreRef
)info
;
634 // get network configuration
635 dict
= smb_copy_global_configuration(store
);
637 // use NetBIOS name from network configuration (if available)
638 name
= CFDictionaryGetValue(dict
, kSCPropNetSMBNetBIOSName
);
639 if ((name
!= NULL
) && _SC_CFStringIsValidNetBIOSName(name
)) {
640 my_log(LOG_INFO
, "NetBIOS name (network configuration) = %@", name
);
644 // get primary service ID
645 serviceID
= copy_primary_service(store
);
646 if (serviceID
== NULL
) {
647 // if no primary service
651 // get DNS name associated with primary IP, if available
652 address
= copy_primary_ip(store
, serviceID
);
653 if (address
!= NULL
) {
656 // start reverse DNS query using primary IP address
657 ok
= ptr_query_start(address
);
666 // get local (multicast DNS) name, if available
668 name
= SCDynamicStoreCopyLocalHostName(store
);
670 if (_SC_CFStringIsValidNetBIOSName(name
)) {
671 CFMutableDictionaryRef newDict
;
673 my_log(LOG_INFO
, "NetBIOS name (multicast DNS) = %@", name
);
674 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
675 CFDictionarySetValue(newDict
, kSCPropNetSMBNetBIOSName
, name
);
684 // get "default" name
685 name
= copy_default_name();
687 CFMutableDictionaryRef newDict
;
689 my_log(LOG_INFO
, "NetBIOS name (default) = %@", name
);
690 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
691 CFDictionarySetValue(newDict
, kSCPropNetSMBNetBIOSName
, name
);
699 // update SMB configuration
700 smb_set_configuration(store
, dict
);
704 if (address
!= NULL
) CFRelease(address
);
705 if (dict
!= NULL
) CFRelease(dict
);
706 if (serviceID
!= NULL
) CFRelease(serviceID
);
709 CFRunLoopTimerInvalidate(timer
);
719 configuration_changed(SCDynamicStoreRef store
, CFArrayRef changedKeys
, void *info
)
721 #pragma unused(changedKeys)
723 CFRunLoopTimerContext context
= { 0, (void *)store
, CFRetain
, CFRelease
, NULL
};
724 CFAbsoluteTime time_boot
;
725 CFAbsoluteTime time_now
;
727 // if active, cancel any in-progress attempt to resolve the primary IP address
729 if (ptrTarget
!= NULL
) {
733 // if active, cancel any queued configuration change
735 CFRunLoopTimerInvalidate(timer
);
740 // queue configuration change
741 time_boot
= boottime() + SMB_STARTUP_DELAY
;
742 time_now
= CFAbsoluteTimeGetCurrent() + SMB_DEBOUNCE_DELAY
;
744 timer
= CFRunLoopTimerCreate(NULL
,
745 time_now
> time_boot
? time_now
: time_boot
,
749 smb_update_configuration
,
751 CFRunLoopAddTimer(rl
, timer
, kCFRunLoopDefaultMode
);
759 load_smb_configuration(Boolean verbose
)
761 #pragma unused(verbose)
763 CFMutableArrayRef keys
= NULL
;
764 dispatch_block_t notify_block
;
766 CFMutableArrayRef patterns
= NULL
;
769 /* initialize a few globals */
770 queue
= dispatch_queue_create(SMB_CONFIGURATION_QUEUE
, NULL
);
773 "dispatch_queue_create() failed");
777 store
= SCDynamicStoreCreate(NULL
, CFSTR("smb-configuration"), configuration_changed
, NULL
);
780 "SCDynamicStoreCreate() failed: %s",
781 SCErrorString(SCError()));
785 /* establish notification keys and patterns */
787 keys
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
788 patterns
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
790 /* ...watch for SMB configuration changes */
791 key
= SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL
,
792 kSCDynamicStoreDomainState
,
794 CFArrayAppendValue(keys
, key
);
797 /* ...watch for ComputerName changes */
798 key
= SCDynamicStoreKeyCreateComputerName(NULL
);
799 CFArrayAppendValue(keys
, key
);
802 /* ...watch for local (multicast DNS) hostname changes */
803 key
= SCDynamicStoreKeyCreateHostNames(NULL
);
804 CFArrayAppendValue(keys
, key
);
807 /* register the keys/patterns */
808 ok
= SCDynamicStoreSetNotificationKeys(store
, keys
, patterns
);
813 "SCDynamicStoreSetNotificationKeys() failed: %s",
814 SCErrorString(SCError()));
818 rl
= CFRunLoopGetCurrent();
819 rls
= SCDynamicStoreCreateRunLoopSource(NULL
, store
, 0);
822 "SCDynamicStoreCreateRunLoopSource() failed: %s",
823 SCErrorString(SCError()));
826 CFRunLoopAddSource(rl
, rls
, kCFRunLoopDefaultMode
);
828 /* ...watch for primary service/interface and DNS configuration changes */
833 key
= SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL
,
834 kSCDynamicStoreDomainState
,
836 changes
= CFArrayCreate(NULL
, (const void **)&key
, 1, &kCFTypeArrayCallBacks
);
837 (*configuration_changed
)(store
, changes
, NULL
);
843 status
= notify_register_dispatch(_SC_NOTIFY_NETWORK_CHANGE
,
847 #pragma unused(token)
848 CFRunLoopPerformBlock(rl
,
849 kCFRunLoopDefaultMode
,
853 if (status
!= NOTIFY_STATUS_OK
) {
854 my_log(LOG_ERR
, "notify_register_dispatch() failed: %u", status
);
863 CFRunLoopRemoveSource(rl
, rls
, kCFRunLoopDefaultMode
);
872 dispatch_release(queue
);
882 main(int argc
, char **argv
)
888 CFStringRef serviceID
;
889 SCDynamicStoreRef store
;
892 if ((argc
> 1) && (strcmp(argv
[1], "-d") == 0)) {
898 store
= SCDynamicStoreCreate(NULL
, CFSTR("smb-configuration"), NULL
, NULL
);
900 SCPrint(TRUE
, stdout
,
901 CFSTR("SCDynamicStoreCreate() failed: %s\n"),
902 SCErrorString(SCError()));
906 // get "default" name
907 name
= copy_default_name();
909 SCPrint(TRUE
, stdout
, CFSTR("default name = %@\n"), name
);
913 // get primary service
914 serviceID
= copy_primary_service(store
);
915 if (serviceID
!= NULL
) {
916 SCPrint(TRUE
, stdout
, CFSTR("primary service ID = %@\n"), serviceID
);
918 SCPrint(TRUE
, stdout
, CFSTR("No primary service\n"));
922 if ((argc
== (2+1)) && (argv
[1][0] == 's')) {
923 if (serviceID
!= NULL
) CFRelease(serviceID
);
924 serviceID
= CFStringCreateWithCString(NULL
, argv
[2], kCFStringEncodingUTF8
);
925 SCPrint(TRUE
, stdout
, CFSTR("alternate service ID = %@\n"), serviceID
);
928 // get primary IP address
929 address
= copy_primary_ip(store
, serviceID
);
930 CFRelease(serviceID
);
931 if (address
!= NULL
) {
932 SCPrint(TRUE
, stdout
, CFSTR("primary address = %@\n"), address
);
934 if ((argc
== (2+1)) && (argv
[1][0] == 'a')) {
935 if (address
!= NULL
) CFRelease(address
);
936 address
= CFStringCreateWithCString(NULL
, argv
[2], kCFStringEncodingUTF8
);
937 SCPrint(TRUE
, stdout
, CFSTR("alternate primary address = %@\n"), address
);
940 // start reverse DNS query using primary IP address
941 (void) ptr_query_start(address
);
947 smb_update_configuration(NULL
, (void *)store
);
956 _sc_verbose
= (argc
> 1) ? TRUE
: FALSE
;
958 load_smb_configuration((argc
> 1) ? TRUE
: FALSE
);