<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>Builtin</key>
<true/>
<key>Requires</key>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>Requires</key>
<array>
<string>com.apple.SystemConfiguration.IPConfiguration</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>Builtin</key>
<true/>
</dict>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>Requires</key>
<array>
<string>com.apple.SystemConfiguration.InterfaceNamer</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>Requires</key>
<array>
<string>com.apple.SystemConfiguration.ATconfig</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>Requires</key>
<array>
<string>com.apple.SystemConfiguration.InterfaceNamer</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>Builtin</key>
<true/>
</dict>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>Builtin</key>
<true/>
<key>Requires</key>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>CFBundleVersion</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>CFPlugInDynamicRegistration</key>
<string>NO</string>
<key>CFPlugInFactories</key>
CFUUIDRef _factoryID;
UInt32 _refCount;
+ Boolean no_user_intervention;
+
CFRunLoopSourceRef monitorRls;
CFMutableSetRef knownInterfaces;
return;
}
+
static void
notify_add(MyType *myInstance)
{
}
+static void
+notify_configure(MyType *myInstance)
+{
+ AuthorizationRef authorization = NULL;
+ CFIndex i;
+ CFIndex n;
+ Boolean ok;
+ SCPreferencesRef prefs = NULL;
+ SCNetworkSetRef set = NULL;
+
+ if (geteuid() == 0) {
+ prefs = SCPreferencesCreate(NULL, CFSTR("SCMonitor"), NULL);
+ } else {
+ AuthorizationFlags flags = kAuthorizationFlagDefaults;
+ OSStatus status;
+
+ status = AuthorizationCreate(NULL,
+ kAuthorizationEmptyEnvironment,
+ flags,
+ &authorization);
+ if (status != errAuthorizationSuccess) {
+ SCLog(TRUE, LOG_ERR,
+ CFSTR("AuthorizationCreate() failed: status = %d\n"),
+ status);
+ return;
+ }
+
+ prefs = SCPreferencesCreateWithAuthorization(NULL, CFSTR("SCMonitor"), NULL, authorization);
+ }
+
+ set = SCNetworkSetCopyCurrent(prefs);
+ if (set == NULL) {
+ set = SCNetworkSetCreate(prefs);
+ if (set == NULL) {
+ goto done;
+ }
+ }
+
+ n = CFArrayGetCount(myInstance->userInterfaces);
+ for (i = 0; i < n; i++) {
+ SCNetworkInterfaceRef interface;
+
+ interface = CFArrayGetValueAtIndex(myInstance->userInterfaces, i);
+ ok = SCNetworkSetEstablishDefaultInterfaceConfiguration(set, interface);
+ if (ok) {
+ CFStringRef name;
+
+ name = SCNetworkInterfaceGetLocalizedDisplayName(interface);
+ SCLog(TRUE, LOG_NOTICE, CFSTR("add service for %@"), name);
+ }
+ }
+
+ ok = SCPreferencesCommitChanges(prefs);
+ if (!ok) {
+ SCLog(TRUE, LOG_ERR,
+ CFSTR("SCPreferencesCommitChanges() failed: %s\n"),
+ SCErrorString(SCError()));
+ goto done;
+ }
+
+ ok = SCPreferencesApplyChanges(prefs);
+ if (!ok) {
+ SCLog(TRUE, LOG_ERR,
+ CFSTR("SCPreferencesApplyChanges() failed: %s\n"),
+ SCErrorString(SCError()));
+ goto done;
+ }
+
+ done :
+
+ if (set != NULL) {
+ CFRelease(set);
+ set = NULL;
+ }
+
+ if (prefs != NULL) {
+ CFRelease(prefs);
+ prefs = NULL;
+ }
+
+ if (authorization != NULL) {
+ AuthorizationFree(authorization, kAuthorizationFlagDefaults);
+ // AuthorizationFree(authorization, kAuthorizationFlagDestroyRights);
+ authorization = NULL;
+ }
+
+ CFRelease(myInstance->userInterfaces);
+ myInstance->userInterfaces = NULL;
+
+ return;
+}
+
+
static void
updateInterfaceList(SCDynamicStoreRef store, CFArrayRef changes, void * arg)
{
done :
- // post notification
if (myInstance->userInterfaces != NULL) {
- notify_add(myInstance);
+ if (myInstance->no_user_intervention) {
+ // add network services for new interfaces
+ notify_configure(myInstance);
+ } else {
+ // post notification
+ notify_add(myInstance);
+ }
}
if (set != NULL) CFRelease(set);
static void
watcher_add(MyType *myInstance)
{
+ CFBundleRef bundle;
SCDynamicStoreContext context = { 0, (void *)myInstance, NULL, NULL, NULL };
CFDictionaryRef dict;
CFStringRef key;
CFArrayRef keys;
SCDynamicStoreRef store;
+ bundle = CFBundleGetBundleWithIdentifier(MY_BUNDLE_ID);
+ if (bundle != NULL) {
+ CFDictionaryRef info;
+ CFBooleanRef user_intervention;
+
+ info = CFBundleGetInfoDictionary(bundle);
+ user_intervention = CFDictionaryGetValue(info, CFSTR("User Intervention"));
+ if (isA_CFBoolean(user_intervention)) {
+ myInstance->no_user_intervention = !CFBooleanGetValue(user_intervention);
+ }
+ }
+
store = SCDynamicStoreCreate(NULL, CFSTR("SCMonitor"), updateInterfaceList, &context);
if (store == NULL) {
SCLog(TRUE, LOG_ERR,
<key>CFBundleExecutable</key>
<string>SystemConfiguration</string>
<key>CFBundleGetInfoString</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>CFBundleIdentifier</key>
<string>com.apple.SystemConfiguration</string>
<key>CFBundleInfoDictionaryVersion</key>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1.9.1</string>
+ <string>1.9.2</string>
</dict>
</plist>
/*
- * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
#pragma mark ComputerName
+static CFStringRef
+_SCPreferencesCopyComputerName(SCPreferencesRef prefs,
+ CFStringEncoding *nameEncoding)
+{
+ CFDictionaryRef dict;
+ CFStringRef name = NULL;
+ CFStringRef path;
+ Boolean tempPrefs = FALSE;
+
+ if (prefs == NULL) {
+ prefs = SCPreferencesCreate(NULL, CFSTR("_SCPreferencesCopyComputerName"), NULL);
+ if (prefs == NULL) {
+ return NULL;
+ }
+ tempPrefs = TRUE;
+ }
+
+ path = CFStringCreateWithFormat(NULL,
+ NULL,
+ CFSTR("/%@/%@"),
+ kSCPrefSystem,
+ kSCCompSystem);
+ dict = SCPreferencesPathGetValue(prefs, path);
+ CFRelease(path);
+
+ if (dict != NULL) {
+ if (isA_CFDictionary(dict)) {
+ name = CFDictionaryGetValue(dict, kSCPropSystemComputerName);
+ name = isA_CFString(name);
+ if (name != NULL) {
+ CFRetain(name);
+ }
+ }
+
+ if (nameEncoding != NULL) {
+ CFNumberRef num;
+
+ num = CFDictionaryGetValue(dict,
+ kSCPropSystemComputerNameEncoding);
+ if (isA_CFNumber(num)) {
+ CFNumberGetValue(num, kCFNumberIntType, nameEncoding);
+ } else {
+ *nameEncoding = CFStringGetSystemEncoding();
+ }
+ }
+ }
+
+ if (tempPrefs) CFRelease(prefs);
+ if (name == NULL) {
+ _SCErrorSet(kSCStatusNoKey);
+ }
+ return name;
+}
+
+
CFStringRef
SCDynamicStoreKeyCreateComputerName(CFAllocatorRef allocator)
{
dict = SCDynamicStoreCopyValue(store, key);
CFRelease(key);
if (dict == NULL) {
+ /*
+ * Let's try looking in the preferences.plist file until
+ * (a) we add an API to retrieve the name regardless of
+ * where it is stored and
+ * (b) this API is deprecated
+ */
+ name = _SCPreferencesCopyComputerName(NULL, nameEncoding);
goto done;
}
if (!isA_CFDictionary(dict)) {
Boolean ok;
CFStringRef path;
- if (!isA_CFString(name)) {
- _SCErrorSet(kSCStatusInvalidArgument);
- return FALSE;
+ if (name != NULL) {
+ CFIndex len;
+
+ if (!isA_CFString(name)) {
+ _SCErrorSet(kSCStatusInvalidArgument);
+ return FALSE;
+ }
+
+ len = CFStringGetLength(name);
+ if (len == 0) {
+ name = NULL;
+ }
}
path = CFStringCreateWithFormat(NULL,
&kCFTypeDictionaryValueCallBacks);
}
- CFDictionarySetValue(newDict, kSCPropSystemComputerName, name);
+ if ((name != NULL) && (CFStringGetLength(name) > 0)) {
+ CFDictionarySetValue(newDict, kSCPropSystemComputerName, name);
- num = CFNumberCreate(NULL, kCFNumberSInt32Type, &encoding);
- CFDictionarySetValue(newDict, kSCPropSystemComputerNameEncoding, num);
- CFRelease(num);
+ num = CFNumberCreate(NULL, kCFNumberSInt32Type, &encoding);
+ CFDictionarySetValue(newDict, kSCPropSystemComputerNameEncoding, num);
+ CFRelease(num);
- CFDictionaryRemoveValue(newDict, kSCPropSystemComputerNameRegion);
- if (encoding == kCFStringEncodingMacRoman) {
- UInt32 userEncoding = 0;
- UInt32 userRegion = 0;
+ CFDictionaryRemoveValue(newDict, kSCPropSystemComputerNameRegion);
+ if (encoding == kCFStringEncodingMacRoman) {
+ UInt32 userEncoding = 0;
+ UInt32 userRegion = 0;
- __CFStringGetUserDefaultEncoding(&userEncoding, &userRegion);
- if ((userEncoding == kCFStringEncodingMacRoman) && (userRegion != 0)) {
- num = CFNumberCreate(NULL, kCFNumberSInt32Type, &userRegion);
- CFDictionarySetValue(newDict, kSCPropSystemComputerNameRegion, num);
- CFRelease(num);
+ __CFStringGetUserDefaultEncoding(&userEncoding, &userRegion);
+ if ((userEncoding == kCFStringEncodingMacRoman) && (userRegion != 0)) {
+ num = CFNumberCreate(NULL, kCFNumberSInt32Type, &userRegion);
+ CFDictionarySetValue(newDict, kSCPropSystemComputerNameRegion, num);
+ CFRelease(num);
+ }
}
+ } else {
+ CFDictionaryRemoveValue(newDict, kSCPropSystemComputerName);
+ CFDictionaryRemoveValue(newDict, kSCPropSystemComputerNameEncoding);
+ CFDictionaryRemoveValue(newDict, kSCPropSystemComputerNameRegion);
}
- ok = SCPreferencesPathSetValue(prefs, path, newDict);
+ if (CFDictionaryGetCount(newDict) > 0) {
+ ok = SCPreferencesPathSetValue(prefs, path, newDict);
+ } else {
+ ok = SCPreferencesPathRemoveValue(prefs, path);
+ }
CFRelease(path);
CFRelease(newDict);
#pragma mark LocalHostName
+static CFStringRef
+_SCPreferencesCopyLocalHostName(SCPreferencesRef prefs)
+{
+ CFDictionaryRef dict;
+ CFStringRef name = NULL;
+ CFStringRef path;
+ Boolean tempPrefs = FALSE;
+
+ if (prefs == NULL) {
+ prefs = SCPreferencesCreate(NULL, CFSTR("_SCPreferencesCopyLocalHostName"), NULL);
+ if (prefs == NULL) {
+ return NULL;
+ }
+ tempPrefs = TRUE;
+ }
+
+ path = CFStringCreateWithFormat(NULL,
+ NULL,
+ CFSTR("/%@/%@/%@"),
+ kSCPrefSystem,
+ kSCCompNetwork,
+ kSCCompHostNames);
+ dict = SCPreferencesPathGetValue(prefs, path);
+ CFRelease(path);
+
+ if (dict != NULL) {
+ if (isA_CFDictionary(dict)) {
+ name = CFDictionaryGetValue(dict, kSCPropNetLocalHostName);
+ name = isA_CFString(name);
+ if (name != NULL) {
+ CFRetain(name);
+ }
+ }
+ }
+
+ if (tempPrefs) CFRelease(prefs);
+ if (name == NULL) {
+ _SCErrorSet(kSCStatusNoKey);
+ }
+ return name;
+}
+
+
CFStringRef
SCDynamicStoreKeyCreateHostNames(CFAllocatorRef allocator)
{
dict = SCDynamicStoreCopyValue(store, key);
CFRelease(key);
if (dict == NULL) {
+ /*
+ * Let's try looking in the preferences.plist file until
+ * (a) we add an API to retrieve the name regardless of
+ * where it is stored and
+ * (b) this API is deprecated
+ */
+ name = _SCPreferencesCopyLocalHostName(NULL);
goto done;
}
if (!isA_CFDictionary(dict)) {
/*
- * Copyright (c) 2003-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2003-2008 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
/* target host name */
const char *name;
+ const char *serv;
+ struct addrinfo hints;
CFArrayRef resolvedAddress; /* CFArray[CFData] */
int resolvedAddressError;
break;
}
case reachabilityTypeName : {
- CFStringAppendFormat(result, NULL, CFSTR("name = %s"), targetPrivate->name);
+ if ((targetPrivate->name != NULL)) {
+ CFStringAppendFormat(result, NULL, CFSTR("name = %s"), targetPrivate->name);
+ }
+ if ((targetPrivate->serv != NULL)) {
+ CFStringAppendFormat(result, NULL, CFSTR("%sserv = %s"),
+ targetPrivate->name != NULL ? ", " : "",
+ targetPrivate->serv);
+ }
if ((targetPrivate->resolvedAddress != NULL) || (targetPrivate->resolvedAddressError != NETDB_SUCCESS)) {
if (targetPrivate->resolvedAddress != NULL) {
if (isA_CFArray(targetPrivate->resolvedAddress)) {
if (targetPrivate->name != NULL)
CFAllocatorDeallocate(NULL, (void *)targetPrivate->name);
+ if (targetPrivate->serv != NULL)
+ CFAllocatorDeallocate(NULL, (void *)targetPrivate->serv);
+
if (targetPrivate->resolvedAddress != NULL)
CFRelease(targetPrivate->resolvedAddress);
pthread_mutex_init(&targetPrivate->lock, NULL);
targetPrivate->name = NULL;
+ targetPrivate->serv = NULL;
+ bzero(&targetPrivate->hints, sizeof(targetPrivate->hints));
+ targetPrivate->hints.ai_flags = AI_ADDRCONFIG;
+#ifdef AI_PARALLEL
+ targetPrivate->hints.ai_flags |= AI_PARALLEL;
+#endif /* AI_PARALLEL */
targetPrivate->resolvedAddress = NULL;
targetPrivate->resolvedAddressError = NETDB_SUCCESS;
}
+SCNetworkReachabilityRef
+SCNetworkReachabilityCreateWithOptions(CFAllocatorRef allocator,
+ CFDictionaryRef options)
+{
+ CFDataRef data;
+ struct addrinfo *hints = NULL;
+ CFStringRef nodename;
+ CFStringRef servname;
+ SCNetworkReachabilityPrivateRef targetPrivate;
+
+ if (!isA_CFDictionary(options)) {
+ _SCErrorSet(kSCStatusInvalidArgument);
+ return NULL;
+ }
+
+ nodename = CFDictionaryGetValue(options, kSCNetworkReachabilityOptionNodeName);
+ if ((nodename != NULL) &&
+ (!isA_CFString(nodename) || (CFStringGetLength(nodename) == 0))) {
+ _SCErrorSet(kSCStatusInvalidArgument);
+ return NULL;
+ }
+ servname = CFDictionaryGetValue(options, kSCNetworkReachabilityOptionServName);
+ if ((servname != NULL) &&
+ (!isA_CFString(servname) || (CFStringGetLength(servname) == 0))) {
+ _SCErrorSet(kSCStatusInvalidArgument);
+ return NULL;
+ }
+ data = CFDictionaryGetValue(options, kSCNetworkReachabilityOptionHints);
+ if (data != NULL) {
+ if (!isA_CFData(data) || (CFDataGetLength(data) != sizeof(targetPrivate->hints))) {
+ _SCErrorSet(kSCStatusInvalidArgument);
+ return NULL;
+ }
+
+ hints = (struct addrinfo *)CFDataGetBytePtr(data);
+ if ((hints->ai_addrlen != 0) ||
+ (hints->ai_addr != NULL) ||
+ (hints->ai_canonname != NULL) ||
+ (hints->ai_next != NULL)) {
+ _SCErrorSet(kSCStatusInvalidArgument);
+ return NULL;
+ }
+ }
+ if ((nodename == NULL) && (servname == NULL)) {
+ _SCErrorSet(kSCStatusInvalidArgument);
+ return NULL;
+ }
+
+ targetPrivate = __SCNetworkReachabilityCreatePrivate(allocator);
+ if (targetPrivate == NULL) {
+ return NULL;
+ }
+ targetPrivate->type = reachabilityTypeName;
+ targetPrivate->flags |= kSCNetworkFlagsFirstResolvePending;
+ if (nodename != NULL) {
+ targetPrivate->name = _SC_cfstring_to_cstring(nodename, NULL, 0, kCFStringEncodingUTF8);
+ }
+ if (servname != NULL) {
+ targetPrivate->serv = _SC_cfstring_to_cstring(servname, NULL, 0, kCFStringEncodingUTF8);
+ }
+ if (hints != NULL) {
+ bcopy(hints, &targetPrivate->hints, sizeof(targetPrivate->hints));
+ }
+
+ return (SCNetworkReachabilityRef)targetPrivate;
+}
+
+
CFTypeID
SCNetworkReachabilityGetTypeID(void)
{
}
if ((targetPrivate->resolvedAddress != NULL) || (targetPrivate->resolvedAddressError != NETDB_SUCCESS)) {
- if (targetPrivate->resolvedAddress != NULL) {
+ if (isA_CFArray(targetPrivate->resolvedAddress)) {
return CFRetain(targetPrivate->resolvedAddress);
} else {
/* if status is known but no resolved addresses to return */
Boolean
-_SC_checkResolverReachability(SCDynamicStoreRef *storeP,
- SCNetworkConnectionFlags *flags,
- Boolean *haveDNS,
- const char * nodename)
+_SC_checkResolverReachability(SCDynamicStoreRef *storeP,
+ SCNetworkConnectionFlags *flags,
+ Boolean *haveDNS,
+ const char * nodename,
+ const char * servname)
{
dns_resolver_t *default_resolver;
dns_configuration_t *dns;
*flags = kSCNetworkFlagsReachable;
*haveDNS = FALSE;
- len = strlen(fqdn);
+ len = (nodename != NULL) ? strlen(nodename) : 0;
if (len == 0) {
- // if no nodename, return not reachable
- *flags = 0;
+ if ((servname == NULL) || (strlen(servname) == 0)) {
+ // if no nodename or servname, return not reachable
+ *flags = 0;
+ }
return ok;
}
goto done;
}
- ok = _SC_checkResolverReachability(storeP, flags, haveDNS, ptr_name);
+ ok = _SC_checkResolverReachability(storeP, flags, haveDNS, ptr_name, NULL);
done :
return CFStringCreateWithFormat(NULL,
NULL,
- CFSTR("<getaddrinfo_async_start reply MP> {name = %s, target = %p}"),
- targetPrivate->name ? targetPrivate->name : "?",
+ CFSTR("<getaddrinfo_async_start reply MP> {%s%s%s%s%s, target = %p}"),
+ targetPrivate->name != NULL ? "name = " : "",
+ targetPrivate->name != NULL ? targetPrivate->name : "",
+ targetPrivate->name != NULL && targetPrivate->serv != NULL ? ", " : "",
+ targetPrivate->serv != NULL ? "serv = " : "",
+ targetPrivate->serv != NULL ? targetPrivate->serv : "",
target);
}
, replyMPCopyDescription
};
int error;
- struct addrinfo hints;
CFIndex i;
CFIndex n;
mach_port_t port;
(void) gettimeofday(&targetPrivate->dnsQueryStart, NULL);
- bzero(&hints, sizeof(hints));
- hints.ai_flags = AI_ADDRCONFIG;
-#ifdef AI_PARALLEL
- hints.ai_flags |= AI_PARALLEL;
-#endif /* AI_PARALLEL */
-
error = getaddrinfo_async_start(&port,
targetPrivate->name,
- NULL,
- &hints,
+ targetPrivate->serv,
+ &targetPrivate->hints,
__SCNetworkReachabilityCallbackSetResolvedAddress,
(void *)target);
if (error != 0) {
case reachabilityTypeName : {
struct timeval dnsQueryStart;
int error;
- struct addrinfo hints;
SCNetworkConnectionFlags ns_flags;
struct addrinfo *res;
ok = _SC_checkResolverReachability(storeP,
&ns_flags,
&targetPrivate->haveDNS,
- targetPrivate->name);
+ targetPrivate->name,
+ targetPrivate->serv);
if (!ok) {
/* if we could not get DNS server info */
goto error;
break;
}
- SCLog(_sc_debug, LOG_INFO, CFSTR("start DNS query for \"%s\""), targetPrivate->name);
+ SCLog(_sc_debug, LOG_INFO,
+ CFSTR("start DNS query for %s%s%s%s%s"),
+ targetPrivate->name != NULL ? "name = " : "",
+ targetPrivate->name != NULL ? targetPrivate->name : "",
+ targetPrivate->name != NULL && targetPrivate->serv != NULL ? ", " : "",
+ targetPrivate->serv != NULL ? "serv = " : "",
+ targetPrivate->serv != NULL ? targetPrivate->serv : "");
/*
* initiate an async DNS query
break;
}
- SCLog(_sc_debug, LOG_INFO, CFSTR("check DNS for \"%s\""), targetPrivate->name);
+ SCLog(_sc_debug, LOG_INFO,
+ CFSTR("check DNS for %s%s%s%s%s"),
+ targetPrivate->name != NULL ? "name = " : "",
+ targetPrivate->name != NULL ? targetPrivate->name : "",
+ targetPrivate->name != NULL && targetPrivate->serv != NULL ? ", " : "",
+ targetPrivate->serv != NULL ? "serv = " : "",
+ targetPrivate->serv != NULL ? targetPrivate->serv : "");
/*
* OK, all of the DNS name servers are available. Let's
(void) gettimeofday(&dnsQueryStart, NULL);
}
- bzero(&hints, sizeof(hints));
- hints.ai_flags = AI_ADDRCONFIG;
-#ifdef AI_PARALLEL
- hints.ai_flags |= AI_PARALLEL;
-#endif /* AI_PARALLEL */
-
- error = getaddrinfo(targetPrivate->name, NULL, &hints, &res);
+ error = getaddrinfo(targetPrivate->name,
+ targetPrivate->serv,
+ &targetPrivate->hints,
+ &res);
__log_query_time(((error == 0) && (res != NULL)),// if successful query
FALSE, // sync
ok = _SC_checkResolverReachability(&store,
&ns_flags,
&targetPrivate->haveDNS,
- targetPrivate->name);
+ targetPrivate->name,
+ targetPrivate->serv);
if (!ok || (rankReachability(ns_flags) < 2)) {
/* if DNS servers are not reachable */
dnsChanged = TRUE;
/*
- * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
extern Boolean _sc_verbose; /* TRUE if verbose logging enabled */
extern Boolean _sc_log; /* TRUE if SCLog() output goes to syslog */
+/*!
+ @group SCNetworkReachabilityCreateWithOptions #defines
+ @discussion The following defines the keys and values that can
+ be passed to the SCNetworkReachabilityCreateWithOptions
+ API.
+ */
+
+/*!
+ @constant kSCNetworkReachabilityOptionNodeName
+ @discussion A CFString that will be passed to getaddrinfo(3). An acceptable
+ value is either a valid host name or a numeric host address string
+ consisting of a dotted decimal IPv4 address or an IPv6 address.
+ */
+#define kSCNetworkReachabilityOptionNodeName CFSTR("nodename")
+
+/*!
+ @constant kSCNetworkReachabilityOptionServName
+ @discussion A CFString that will be passed to getaddrinfo(3). An acceptable
+ value is either a decimal port number or a service name listed in
+ services(5).
+ */
+#define kSCNetworkReachabilityOptionServName CFSTR("servname")
+
+/*!
+ @constant kSCNetworkReachabilityOptionHints
+ @discussion A CFData wrapping a "struct addrinfo" that will be passed to
+ getaddrinfo(3). The caller can supply any of the ai_family,
+ ai_socktype, ai_protocol, and ai_flags structure elements. All
+ other elements must be 0 or the null pointer.
+ */
+#define kSCNetworkReachabilityOptionHints CFSTR("hints")
+
+/*!
+ @group
+ */
+
__BEGIN_DECLS
/*!
CFStringRef formatString,
...);
+/*!
+ @function SCNetworkReachabilityCreateWithOptions
+ @discussion Creates a reference to a specified network host. The
+ options allow the caller to specify the node name and/or
+ the service name. This reference can be used later to
+ monitor the reachability of the target host.
+ @param allocator The CFAllocator that should be used to allocate
+ memory for the SCNetworkReachability object.
+ This parameter may be NULL in which case the current
+ default CFAllocator is used. If this reference is not
+ a valid CFAllocator, the behavior is undefined.
+ @param options A CFDictionary containing options specifying the
+ network host. The options reflect the arguments that would
+ be passed to getaddrinfo().
+ */
+SCNetworkReachabilityRef
+SCNetworkReachabilityCreateWithOptions (CFAllocatorRef allocator,
+ CFDictionaryRef options);
+
/*
* DOS encoding/codepage
*/
/*
- * Copyright (c) 2000, 2001, 2003, 2004, 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000, 2001, 2003, 2004, 2006, 2007 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
return KERN_SUCCESS;
}
+ /*
+ * Remove send and receive right
+ */
+ mach_port_mod_refs(mach_task_self(), mySession->key, MACH_PORT_RIGHT_SEND , -1);
+ mach_port_mod_refs(mach_task_self(), mySession->key, MACH_PORT_RIGHT_RECEIVE, -1);
+
/*
* Remove the session entry.
*/
/*
- * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
int *sc_status,
audit_token_t audit_token)
{
- CFMachPortContext context = { 0
- , (void *)1
- , NULL
- , NULL
- , openMPCopyDescription
- };
CFDictionaryRef info;
- CFMachPortRef mp;
serverSessionRef mySession;
CFStringRef name = NULL; /* name (un-serialized) */
CFMutableDictionaryRef newInfo;
- serverSessionRef newSession;
mach_port_t oldNotify;
CFDictionaryRef options = NULL; /* options (un-serialized) */
CFStringRef sessionKey;
}
mySession = getSession(server);
- if (mySession->store != NULL) {
+ if ((mySession != NULL) && (mySession->store != NULL)) {
#ifdef DEBUG
SCLog(TRUE, LOG_DEBUG, CFSTR("_configopen(): session is already open."));
#endif /* DEBUG */
goto done;
}
- /* Create the server port for this session */
- mp = CFMachPortCreate(NULL, configdCallback, &context, NULL);
-
- /* return the newly allocated port to be used for this session */
- *newServer = CFMachPortGetPort(mp);
-
/*
* establish the new session
*/
- newSession = addSession(mp);
+ mySession = addSession(MACH_PORT_NULL, openMPCopyDescription);
+ *newServer = mySession->key;
/*
* get the credentials associated with the caller.
*/
audit_token_to_au32(audit_token,
NULL, // auidp
- &newSession->callerEUID, // euid
+ &mySession->callerEUID, // euid
NULL, // egid
NULL, // ruid
NULL, // rgid
NULL); // tid
/* Create and add a run loop source for the port */
- newSession->serverRunLoopSource = CFMachPortCreateRunLoopSource(NULL, mp, 0);
+ mySession->serverRunLoopSource = CFMachPortCreateRunLoopSource(NULL, mySession->serverPort, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(),
- newSession->serverRunLoopSource,
+ mySession->serverRunLoopSource,
kCFRunLoopDefaultMode);
if (_configd_trace) {
name);
}
- *sc_status = __SCDynamicStoreOpen(&newSession->store, name);
- storePrivate = (SCDynamicStorePrivateRef)newSession->store;
+ *sc_status = __SCDynamicStoreOpen(&mySession->store, name);
+ storePrivate = (SCDynamicStorePrivateRef)mySession->store;
/*
* Make the server port accessible to the framework routines.
server_init(mach_port_t restart_service_port,
Boolean enableRestart)
{
- CFMachPortContext context = { 0
- , (void *)1
- , NULL
- , NULL
- , serverMPCopyDescription
- };
-
+ serverSessionRef mySession;
CFRunLoopSourceRef rls;
char *service_name;
mach_port_t service_port = restart_service_port;
/* ... and make sure that the global "bootstrap_port" is also unpriviledged */
bootstrap_port = unpriv_bootstrap_port;
- /* Create the primary / new connection port */
- configd_port = CFMachPortCreateWithPort(NULL, service_port, configdCallback, &context, NULL);
+ /* Create the primary / new connection port and backing session */
+ mySession = addSession(service_port, serverMPCopyDescription);
+ configd_port = mySession->serverPort;
/*
* Create and add a run loop source for the port and add this source
CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, CFSTR("locked"));
CFRelease(rls);
- /* Create a session for the primary / new connection port */
- (void) addSession(configd_port);
-
return;
}
/*
- * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2004, 2007 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
Request->not_header.msgh_local_port);
cleanupSession(Request->not_header.msgh_local_port);
- (void) mach_port_mod_refs(mach_task_self(),
- Request->not_header.msgh_local_port,
- MACH_PORT_RIGHT_RECEIVE, -1);
-
Reply->Head.msgh_bits = 0;
Reply->Head.msgh_remote_port = MACH_PORT_NULL;
Reply->RetCode = KERN_SUCCESS;
/*
- * Copyright (c) 2000, 2001, 2003-2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000, 2001, 2003-2005, 2007 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
__private_extern__
serverSessionRef
-addSession(CFMachPortRef server)
+addSession(mach_port_t server, CFStringRef (*copyDescription)(const void *info))
{
- int i;
- int n = -1;
+ CFMachPortContext context = { 0, NULL, NULL, NULL, NULL };
+ int n = -1;
if (nSessions <= 0) {
/* new session (actually, the first) found */
n = 0;
nSessions = 1;
} else {
+ int i;
+
for (i = 0; i < nSessions; i++) {
if (sessions[i] == NULL) {
/* found an empty slot, use it */
n = i;
+ break;
}
}
/* new session identified */
// allocate a new session for this server
sessions[n] = malloc(sizeof(serverSession));
- sessions[n]->key = CFMachPortGetPort(server);
- sessions[n]->serverPort = server;
- sessions[n]->serverRunLoopSource = NULL;
- sessions[n]->store = NULL;
+ bzero(sessions[n], sizeof(serverSession));
+
+ // create server port
+ context.info = sessions[n];
+ context.copyDescription = copyDescription;
+
+ if (server == MACH_PORT_NULL) {
+ // SCDynamicStore client ports
+ (void) mach_port_allocate(mach_task_self(),
+ MACH_PORT_RIGHT_RECEIVE,
+ &server);
+ (void) mach_port_insert_right(mach_task_self(),
+ server,
+ server,
+ MACH_MSG_TYPE_MAKE_SEND);
+ }
+ sessions[n]->key = server;
+ sessions[n]->serverPort = CFMachPortCreateWithPort(NULL,
+ server,
+ configdCallback,
+ &context,
+ NULL);
+// sessions[n]->serverRunLoopSource = NULL;
+// sessions[n]->store = NULL;
sessions[n]->callerEUID = 1; /* not "root" */
return sessions[n];
*/
(void) __SCDynamicStoreClose(&thisSession->store, TRUE);
+ /*
+ * Our send right has already been removed. Remove our
+ * receive right.
+ */
+ mach_port_mod_refs(mach_task_self(),
+ thisSession->key,
+ MACH_PORT_RIGHT_RECEIVE,
+ -1);
+
/*
* Lastly, remove the session entry.
*/
/*
- * Copyright (c) 2000, 2001, 2005, 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000, 2001, 2005-2007 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
serverSessionRef getSession (mach_port_t server);
-serverSessionRef addSession (CFMachPortRef server);
+serverSessionRef addSession (mach_port_t server,
+ CFStringRef (*copyDescription)(const void *info));
void removeSession (mach_port_t server);
1508E39F07552B6A0062B350 /* atconfig.c in Sources */ = {isa = PBXBuildFile; fileRef = 159D53C707528B36004F8947 /* atconfig.c */; settings = {COMPILER_FLAGS = "-Wno-deprecated-declarations"; }; };
1508E3A007552B6B0062B350 /* cfManager.c in Sources */ = {isa = PBXBuildFile; fileRef = 159D53C507528B36004F8947 /* cfManager.c */; };
1508E3A107552B720062B350 /* cache.c in Sources */ = {isa = PBXBuildFile; fileRef = 159D53CA07528B36004F8947 /* cache.c */; };
+ 150D7E1E0D16DC6C00AF4BED /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1520A3DE0846B2DC0010B584 /* Security.framework */; };
1520A3870846829A0010B584 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15CB6A6F05C0722B0099E85F /* CoreFoundation.framework */; };
1520A3D0084682A30010B584 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15DAD6C807591A1A0084A6ED /* SystemConfiguration.framework */; };
1520A3DF0846B2DD0010B584 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1520A3DE0846B2DC0010B584 /* Security.framework */; };
isa = PBXContainerItemProxy;
containerPortal = 15CB6A7705C0722B0099E85F /* Project object */;
proxyType = 1;
- remoteGlobalIDString = 151F5D990CCE98E50093AC3B /* SCMonitor */;
+ remoteGlobalIDString = 151F5D990CCE98E50093AC3B;
remoteInfo = SCMonitor;
};
1520A385084681350010B584 /* PBXContainerItemProxy */ = {
15FC13180CCF74740013872C /* CoreFoundation.framework in Frameworks */,
15E517680CCFBCD0008FFE82 /* SystemConfiguration.framework in Frameworks */,
15FEE80E0CCFD341001312F9 /* ApplicationServices.framework in Frameworks */,
+ 150D7E1E0D16DC6C00AF4BED /* Security.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
buildSettings = {
COPY_PHASE_STRIP = NO;
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 210;
+ DYLIB_CURRENT_VERSION = 212.2;
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES;
INSTALLHDRS_COPY_PHASE = YES;
INSTALL_MODE_FLAG = "a-w,a+rX";
buildSettings = {
COPY_PHASE_STRIP = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 210;
+ DYLIB_CURRENT_VERSION = 212.2;
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES;
INSTALLHDRS_COPY_PHASE = YES;
INSTALL_MODE_FLAG = "a-w,a+rX";
isa = XCBuildConfiguration;
buildSettings = {
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 210;
+ DYLIB_CURRENT_VERSION = 212.2;
INSTALLHDRS_COPY_PHASE = YES;
INSTALL_MODE_FLAG = "a-w,a+rX";
INSTALL_PATH = /usr/local/lib;
buildSettings = {
COPY_PHASE_STRIP = NO;
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 210;
+ DYLIB_CURRENT_VERSION = 212.2;
FRAMEWORK_SEARCH_PATHS = "$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks";
HEADER_SEARCH_PATHS = "$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders";
INFOPLIST_FILE = SystemConfiguration.fproj/Info.plist;
buildSettings = {
COPY_PHASE_STRIP = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 210;
+ DYLIB_CURRENT_VERSION = 212.2;
FRAMEWORK_SEARCH_PATHS = "$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks";
HEADER_SEARCH_PATHS = "$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders";
INFOPLIST_FILE = SystemConfiguration.fproj/Info.plist;
isa = XCBuildConfiguration;
buildSettings = {
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 210;
+ DYLIB_CURRENT_VERSION = 212.2;
FRAMEWORK_SEARCH_PATHS = "$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks";
HEADER_SEARCH_PATHS = "$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders";
INFOPLIST_FILE = SystemConfiguration.fproj/Info.plist;
156EB63F0905594A00EEF749 /* Development */ = {
isa = XCBuildConfiguration;
buildSettings = {
- CURRENT_PROJECT_VERSION = 210;
+ CURRENT_PROJECT_VERSION = 212.2;
DEAD_CODE_STRIPPING = YES;
INSTALL_GROUP = wheel;
INSTALL_MODE_FLAG = "u+s,ugo-w,o+rX";
156EB6400905594A00EEF749 /* Deployment */ = {
isa = XCBuildConfiguration;
buildSettings = {
- CURRENT_PROJECT_VERSION = 210;
+ CURRENT_PROJECT_VERSION = 212.2;
DEAD_CODE_STRIPPING = YES;
INSTALL_GROUP = wheel;
INSTALL_MODE_FLAG = "u+s,ugo-w,o+rX";
156EB6410905594A00EEF749 /* Default */ = {
isa = XCBuildConfiguration;
buildSettings = {
- CURRENT_PROJECT_VERSION = 210;
+ CURRENT_PROJECT_VERSION = 212.2;
DEAD_CODE_STRIPPING = YES;
INSTALL_GROUP = wheel;
INSTALL_MODE_FLAG = "u+s,ugo-w,o+rX";
/*
- * Copyright (c) 2003-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2003-2008 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
SCErrorString(SCError()));
break;
}
- _prefs_close();
exit (1);
}
SCPrint(TRUE, stdout, CFSTR("%@\n"), hostname);
CFRelease(hostname);
- _prefs_close();
+
exit(0);
}