/*
- * 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@
*
#include <SystemConfiguration/SystemConfiguration.h>
#include <SystemConfiguration/SCPrivate.h>
#include "SCPreferencesInternal.h"
+#include "SCNetworkConfigurationInternal.h"
#include <fcntl.h>
#include <pwd.h>
*/
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);
}
+__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)
{
{
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;
+}