Something went wrong. Try again.
Cider Isn't Darwin Emulation, Really
Something went wrong. Try again.
7.7 kB · 294 lines
C
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295/* * Copyright (c) 2000, 2001, 2003-2005, 2007-2009, 2011, 2014-2018 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */
/* * Modification History * * June 1, 2001 Allan Nathanson <ajn@apple.com> * - public API conversion * * November 9, 2000 Allan Nathanson <ajn@apple.com> * - initial revision */
#include "SCPreferencesInternal.h"#include "SCNetworkConfigurationInternal.h"
#include <fcntl.h>#include <pwd.h>#include <unistd.h>#include <sys/errno.h>#include <sys/param.h>
__private_extern__ CF_RETURNS_RETAINED CFDataRef__SCPSignatureFromStatbuf(const struct stat *statBuf){ CFMutableDataRef signature; SCPSignatureDataRef sig;
signature = CFDataCreateMutable(NULL, sizeof(SCPSignatureData)); CFDataSetLength(signature, sizeof(SCPSignatureData));
/* ALIGN: CFDataGetBytePtr aligns to at least 8 bytes */ sig = (SCPSignatureDataRef)(void *)CFDataGetBytePtr(signature);
sig->st_dev = statBuf->st_dev; sig->st_ino = statBuf->st_ino; sig->tv_sec = statBuf->st_mtimespec.tv_sec; sig->tv_nsec = statBuf->st_mtimespec.tv_nsec; sig->st_size = statBuf->st_size; return signature;}
__private_extern__ char *__SCPreferencesPath(CFAllocatorRef allocator, CFStringRef prefsID, Boolean useNewPrefs){ CFStringRef path = NULL; char *pathStr;
if (prefsID == NULL) { /* default preference ID */ path = CFStringCreateWithFormat(allocator, NULL, CFSTR("%@/%@"), useNewPrefs ? PREFS_DEFAULT_DIR : PREFS_DEFAULT_DIR_OLD, useNewPrefs ? PREFS_DEFAULT_CONFIG : PREFS_DEFAULT_CONFIG_OLD); } else if (CFStringHasPrefix(prefsID, CFSTR("/"))) { /* if absolute path */ path = CFStringCreateCopy(allocator, prefsID); } else { /* relative path */ path = CFStringCreateWithFormat(allocator, NULL, CFSTR("%@/%@"), useNewPrefs ? PREFS_DEFAULT_DIR : PREFS_DEFAULT_DIR_OLD, prefsID); if (useNewPrefs && CFStringHasSuffix(path, CFSTR(".xml"))) { CFMutableStringRef newPath;
newPath = CFStringCreateMutableCopy(allocator, 0, path); CFStringReplace(newPath, CFRangeMake(CFStringGetLength(newPath)-4, 4), CFSTR(".plist")); CFRelease(path); path = newPath; } }
/* * convert CFStringRef path to C-string path */ pathStr = _SC_cfstring_to_cstring(path, NULL, 0, kCFStringEncodingASCII); if (pathStr == NULL) { CFIndex pathLen;
pathLen = CFStringGetMaximumSizeOfFileSystemRepresentation(path); pathStr = CFAllocatorAllocate(NULL, pathLen, 0); if (!CFStringGetFileSystemRepresentation(path, pathStr, pathLen)) { SC_log(LOG_INFO, "could not convert path to C string"); CFAllocatorDeallocate(NULL, pathStr); pathStr = NULL; } }
CFRelease(path); return pathStr;}
__private_extern__Boolean__SCPreferencesGetLimitSCNetworkConfiguration(SCPreferencesRef prefs){ SCPreferencesPrivateRef prefsPrivate = (SCPreferencesPrivateRef)prefs;
if (prefs == NULL) { return FALSE; } return prefsPrivate->limit_SCNetworkConfiguration;}
__private_extern__off_t__SCPreferencesPrefsSize(SCPreferencesRef prefs){ SCPreferencesPrivateRef prefsPrivate = (SCPreferencesPrivateRef)prefs; SCPSignatureDataRef sig; CFDataRef signature;
signature = prefsPrivate->signature; if (signature == NULL) { return 0; }
sig = (SCPSignatureDataRef)(void *)CFDataGetBytePtr(signature); return sig->st_size;}
__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)) { ni_prefs = __SCNetworkCreateDefaultNIPrefs(newPath); } else { ni_prefs = SCPreferencesCreate(NULL, prefsPrivate->name, newPath); } CFAllocatorDeallocate(NULL, prefsPath); CFRelease(newPath); CFRelease(newURL);
return ni_prefs;}
CFDataRefSCPreferencesGetSignature(SCPreferencesRef prefs){ SCPreferencesPrivateRef prefsPrivate = (SCPreferencesPrivateRef)prefs;
if (prefs == NULL) { /* sorry, you must provide a session */ _SCErrorSet(kSCStatusNoPrefsSession); return NULL; }
__SCPreferencesAccess(prefs);
return prefsPrivate->signature;}
__private_extern__ CF_RETURNS_RETAINED CFStringRef_SCPNotificationKey(CFAllocatorRef allocator, CFStringRef prefsID, int keyType){ CFStringRef keyStr; char *path; CFStringRef pathStr; CFStringRef storeKey;
switch (keyType) { case kSCPreferencesKeyLock : keyStr = CFSTR("lock"); break; case kSCPreferencesKeyCommit : keyStr = CFSTR("commit"); break; case kSCPreferencesKeyApply : keyStr = CFSTR("apply"); break; default : return NULL; }
path = __SCPreferencesPath(allocator, prefsID, TRUE); if (path == NULL) { return NULL; }
pathStr = CFStringCreateWithCStringNoCopy(allocator, path, kCFStringEncodingASCII, kCFAllocatorNull);
storeKey = CFStringCreateWithFormat(allocator, NULL, CFSTR("%@%@:%@"), kSCDynamicStoreDomainPrefs, keyStr, pathStr);
CFRelease(pathStr); CFAllocatorDeallocate(NULL, path); return storeKey;}
CFStringRefSCDynamicStoreKeyCreatePreferences(CFAllocatorRef allocator, CFStringRef prefsID, SCPreferencesKeyType keyType){ 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;}