]> git.saurik.com Git - apple/configd.git/blobdiff - SystemConfiguration.fproj/SCP.c
configd-699.1.5.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCP.c
index 344b4200e48699e0813e19339cdac07e36ae2f02..bc55bb00e49472d6f156d1d80d6585648d5f3a23 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2001, 2003-2005, 2007-2009, 2011 Apple Inc. All rights reserved.
+ * Copyright (c) 2000, 2001, 2003-2005, 2007-2009, 2011, 2014 Apple Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
@@ -34,6 +34,7 @@
 #include <SystemConfiguration/SystemConfiguration.h>
 #include <SystemConfiguration/SCPrivate.h>
 #include "SCPreferencesInternal.h"
+#include "SCNetworkConfigurationInternal.h"
 
 #include <fcntl.h>
 #include <pwd.h>
@@ -104,7 +105,15 @@ __SCPreferencesPath(CFAllocatorRef allocator,
         */
        pathStr = _SC_cfstring_to_cstring(path, NULL, 0, kCFStringEncodingASCII);
        if (pathStr == NULL) {
-               SCLog(_sc_verbose, LOG_DEBUG, CFSTR("could not convert path to C string"));
+               CFIndex pathLen;
+               
+               pathLen = CFStringGetMaximumSizeOfFileSystemRepresentation(path);
+               pathStr = CFAllocatorAllocate(NULL, pathLen, 0);                
+               if (CFStringGetFileSystemRepresentation(path, pathStr, pathLen) == FALSE) {
+                       SCLog(_sc_verbose, LOG_DEBUG, CFSTR("could not convert path to C string"));
+                       CFAllocatorDeallocate(NULL, pathStr);
+                       pathStr = NULL;
+               }
        }
 
        CFRelease(path);
@@ -112,6 +121,77 @@ __SCPreferencesPath(CFAllocatorRef allocator,
 }
 
 
+__private_extern__
+Boolean
+__SCPreferencesGetLimitSCNetworkConfiguration(SCPreferencesRef prefs)
+{
+       SCPreferencesPrivateRef prefsPrivate    = (SCPreferencesPrivateRef)prefs;
+
+       if (prefs == NULL) {
+               return FALSE;
+       }
+       return prefsPrivate->limit_SCNetworkConfiguration;
+}
+
+
+__private_extern__
+Boolean
+__SCPreferencesUsingDefaultPrefs(SCPreferencesRef prefs)
+{
+       char                    *curPath;
+       Boolean                 isDefault = FALSE;
+       SCPreferencesPrivateRef prefsPrivate = (SCPreferencesPrivateRef)prefs;
+
+       curPath = prefsPrivate->newPath ? prefsPrivate->newPath : prefsPrivate->path;
+       if (curPath != NULL) {
+               char*   defPath;
+
+               defPath = __SCPreferencesPath(NULL,
+                                             NULL,
+                                             (prefsPrivate->newPath == NULL));
+               if (defPath != NULL) {
+                       if (strcmp(curPath, defPath) == 0) {
+                               isDefault = TRUE;
+                       }
+                       CFAllocatorDeallocate(NULL, defPath);
+               }
+       }
+       return isDefault;
+}
+
+__private_extern__
+SCPreferencesRef
+__SCPreferencesCreateNIPrefsFromPrefs(SCPreferencesRef prefs)
+{
+       CFMutableStringRef newPath = NULL;
+       CFURLRef newURL = NULL;
+       SCPreferencesRef ni_prefs = NULL;
+       SCPreferencesPrivateRef prefsPrivate = (SCPreferencesPrivateRef)prefs;
+       char * prefsPath = __SCPreferencesPath(NULL, prefsPrivate->prefsID, FALSE);
+       
+       
+       newPath = CFStringCreateMutable(NULL, 0);
+       CFStringAppendFormat(newPath, NULL, CFSTR("%s"), prefsPath);
+       
+       CFStringFindAndReplace(newPath, PREFS_DEFAULT_CONFIG,
+                              NETWORK_INTERFACES_PREFS,
+                              CFRangeMake(0, CFStringGetLength(newPath)),
+                              kCFCompareBackwards);
+       
+       newURL = CFURLCreateWithFileSystemPath(NULL, newPath, kCFURLPOSIXPathStyle, FALSE);
+       if (CFURLResourceIsReachable(newURL, NULL) == FALSE) {
+               ni_prefs = __SCNetworkCreateDefaultNIPrefs(newPath);
+       }
+       else {
+               ni_prefs = SCPreferencesCreate(NULL, prefsPrivate->name, newPath);
+       }
+       CFAllocatorDeallocate(NULL, prefsPath);
+       CFRelease(newPath);
+       CFRelease(newURL);
+       
+       return ni_prefs;
+}
+
 CFDataRef
 SCPreferencesGetSignature(SCPreferencesRef prefs)
 {
@@ -183,3 +263,16 @@ SCDynamicStoreKeyCreatePreferences(CFAllocatorRef  allocator,
 {
        return _SCPNotificationKey(allocator, prefsID, keyType);
 }
+
+
+__private_extern__ void
+__SCPreferencesSetLimitSCNetworkConfiguration(SCPreferencesRef prefs,
+                                             Boolean           limit_SCNetworkConfiguration)
+{
+       SCPreferencesPrivateRef prefsPrivate    = (SCPreferencesPrivateRef)prefs;
+
+       if (prefs == NULL) {
+               return;
+       }
+       prefsPrivate->limit_SCNetworkConfiguration = limit_SCNetworkConfiguration;
+}