X-Git-Url: https://git.saurik.com/apple/configd.git/blobdiff_plain/c387a05da0fa0df1d260acaa042ff33357016d94..ba83da554b37c2706d3991e01798c6f0390ad20d:/SystemConfiguration.fproj/SCNetworkConfigurationInternal.c diff --git a/SystemConfiguration.fproj/SCNetworkConfigurationInternal.c b/SystemConfiguration.fproj/SCNetworkConfigurationInternal.c index 14266e6..d9f1579 100644 --- a/SystemConfiguration.fproj/SCNetworkConfigurationInternal.c +++ b/SystemConfiguration.fproj/SCNetworkConfigurationInternal.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004,2005 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -72,20 +72,26 @@ __setPrefsConfiguration(SCPreferencesRef prefs, CFDictionaryRef config, Boolean keepInactive) { - CFMutableDictionaryRef newConfig; - Boolean ok; + CFMutableDictionaryRef newConfig = NULL; + Boolean ok = FALSE; - if (!isA_CFDictionary(config)) { - _SCErrorSet(kSCStatusInvalidArgument); - return FALSE; + if (config != NULL) { + if (!isA_CFDictionary(config)) { + _SCErrorSet(kSCStatusInvalidArgument); + return FALSE; + } + newConfig = CFDictionaryCreateMutableCopy(NULL, 0, config); + } else { + newConfig = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); } - newConfig = CFDictionaryCreateMutableCopy(NULL, 0, config); - if (keepInactive) { CFDictionaryRef curConfig; - // preserve enabled/disabled state + /* + * preserve enabled/disabled state + */ + curConfig = SCPreferencesPathGetValue(prefs, path); if (isA_CFDictionary(curConfig) && CFDictionaryContainsKey(curConfig, kSCResvInactive)) { // if currently disabled @@ -96,10 +102,22 @@ __setPrefsConfiguration(SCPreferencesRef prefs, } } - // set new configuration - ok = SCPreferencesPathSetValue(prefs, path, newConfig); + /* + * set new configuration + */ - CFRelease(newConfig); + if (CFDictionaryGetCount(newConfig) == 0) { + CFRelease(newConfig); + newConfig = NULL; + } + + if (newConfig == NULL) { + ok = SCPreferencesPathRemoveValue(prefs, path); + } else { + ok = SCPreferencesPathSetValue(prefs, path, newConfig); + } + + if (newConfig != NULL) CFRelease(newConfig); return ok; } @@ -127,7 +145,10 @@ __setPrefsEnabled(SCPreferencesRef prefs, CFMutableDictionaryRef newConfig = NULL; Boolean ok = FALSE; - // preserve current configuration + /* + * preserve current configuration + */ + curConfig = SCPreferencesPathGetValue(prefs, path); if (curConfig != NULL) { if (!isA_CFDictionary(curConfig)) { @@ -147,7 +168,10 @@ __setPrefsEnabled(SCPreferencesRef prefs, CFDictionarySetValue(newConfig, kSCResvInactive, kCFBooleanTrue); } - // update configuration + /* + * update configuration + */ + if (CFDictionaryGetCount(newConfig) == 0) { CFRelease(newConfig); newConfig = NULL; @@ -194,7 +218,7 @@ __copyTemplates() return NULL; } - // convert the XML data into a property list + /* convert the XML data into a property list */ templates = CFPropertyListCreateFromXMLData(NULL, xmlTemplates, kCFPropertyListImmutable, &xmlError); CFRelease(xmlTemplates); if (templates == NULL) {