From a5f60add6851c80e3e97d4c50c2855d3be97e589 Mon Sep 17 00:00:00 2001 From: Apple Date: Thu, 20 Jun 2002 01:37:08 +0000 Subject: [PATCH] configd-53.tar.gz --- Makefile | 3 +- Makefile.postamble | 4 + Makefile.preamble | 1 + PB.project | 2 +- SystemConfiguration.fproj/CustomInfo.plist | 2 +- SystemConfiguration.fproj/DeviceOnHold.c | 483 ++++++++++++++++++ SystemConfiguration.fproj/DeviceOnHold.h | 149 ++++++ SystemConfiguration.fproj/Makefile | 32 +- SystemConfiguration.fproj/Makefile.postamble | 2 +- SystemConfiguration.fproj/Makefile.preamble | 5 +- SystemConfiguration.fproj/PB.project | 18 +- SystemConfiguration.fproj/SCD.c | 157 +++--- SystemConfiguration.fproj/SCDAdd.c | 20 +- SystemConfiguration.fproj/SCDAddSession.c | 20 +- SystemConfiguration.fproj/SCDConsoleUser.c | 44 +- SystemConfiguration.fproj/SCDGet.c | 72 +-- SystemConfiguration.fproj/SCDHostName.c | 224 +++++++- SystemConfiguration.fproj/SCDList.c | 30 +- SystemConfiguration.fproj/SCDNotifierAdd.c | 11 +- SystemConfiguration.fproj/SCDNotifierCancel.c | 5 +- .../SCDNotifierGetChanges.c | 23 +- .../SCDNotifierInformViaCallback.c | 112 +++- SystemConfiguration.fproj/SCDNotifierList.c | 18 +- SystemConfiguration.fproj/SCDNotifierRemove.c | 9 +- SystemConfiguration.fproj/SCDNotify.c | 11 +- SystemConfiguration.fproj/SCDOpen.c | 32 +- SystemConfiguration.fproj/SCDPlugin.c | 343 +++++++++++++ SystemConfiguration.fproj/SCDPlugin.h | 44 ++ SystemConfiguration.fproj/SCDPrivate.c | 102 +++- SystemConfiguration.fproj/SCDRemove.c | 9 +- SystemConfiguration.fproj/SCDSet.c | 44 +- SystemConfiguration.fproj/SCDTouch.c | 9 +- .../SCDynamicStoreCopyDHCPInfo.h | 4 +- .../SCDynamicStoreCopySpecific.h | 36 +- SystemConfiguration.fproj/SCDynamicStoreKey.h | 27 +- SystemConfiguration.fproj/SCLocation.c | 83 +++ SystemConfiguration.fproj/SCNetwork.c | 12 +- SystemConfiguration.fproj/SCPList.c | 16 +- SystemConfiguration.fproj/SCPLock.c | 5 +- SystemConfiguration.fproj/SCPOpen.c | 30 +- SystemConfiguration.fproj/SCPPath.c | 454 ++++++++-------- SystemConfiguration.fproj/SCPreferencesPath.h | 4 +- .../SCPreferencesSetSpecific.h | 25 +- SystemConfiguration.fproj/SCPrivate.h | 31 +- SystemConfiguration.fproj/SCProxies.c | 21 +- SystemConfiguration.fproj/SCValidation.h | 11 +- .../SystemConfiguration.h | 4 +- SystemConfiguration.fproj/genSCPreferences.c | 83 ++- SystemConfiguration.fproj/moh.c | 207 ++++++++ SystemConfiguration.fproj/moh.h | 59 +++ SystemConfiguration.fproj/moh_msg.h | 63 +++ SystemConfiguration.fproj/ppp.c | 155 +++--- SystemConfiguration.fproj/ppp.h | 24 +- SystemConfiguration.fproj/ppp_msg.h | 6 +- configd.tproj/Makefile | 1 - configd.tproj/Makefile.preamble | 3 +- configd.tproj/PB.project | 123 +++-- configd.tproj/_SCD.c | 20 +- configd.tproj/_configadd.c | 52 +- configd.tproj/_configadd_s.c | 52 +- configd.tproj/_configclose.c | 12 +- configd.tproj/_configget.c | 138 ++--- configd.tproj/_configlist.c | 169 +++--- configd.tproj/_confignotify.c | 35 +- configd.tproj/_configopen.c | 28 +- configd.tproj/_configremove.c | 29 +- configd.tproj/_configset.c | 131 +---- configd.tproj/_configtouch.c | 31 +- configd.tproj/_configunlock.c | 106 ++-- configd.tproj/_notifyadd.c | 30 +- configd.tproj/_notifychanges.c | 28 +- configd.tproj/_notifyremove.c | 29 +- configd.tproj/_notifyviasignal.c | 4 +- configd.tproj/_snapshot.c | 12 +- configd.tproj/config.defs | 2 +- configd.tproj/configd.m | 45 +- configd.tproj/configd_server.c | 34 +- configd.tproj/notify.c | 4 +- configd.tproj/plugin_support.c | 46 +- preferences.xml | 139 +++++ scselect.tproj/Makefile | 1 - scselect.tproj/PB.project | 1 - scselect.tproj/scselect.c | 14 +- scutil.tproj/Makefile | 1 - scutil.tproj/PB.project | 1 - scutil.tproj/cache.c | 10 +- scutil.tproj/dictionary.c | 4 +- scutil.tproj/notify.c | 38 +- scutil.tproj/scutil.c | 8 +- scutil.tproj/scutil.h | 1 + 90 files changed, 3349 insertions(+), 1433 deletions(-) create mode 100644 SystemConfiguration.fproj/DeviceOnHold.c create mode 100644 SystemConfiguration.fproj/DeviceOnHold.h create mode 100644 SystemConfiguration.fproj/SCDPlugin.c create mode 100644 SystemConfiguration.fproj/SCLocation.c create mode 100644 SystemConfiguration.fproj/moh.c create mode 100644 SystemConfiguration.fproj/moh.h create mode 100644 SystemConfiguration.fproj/moh_msg.h create mode 100644 preferences.xml diff --git a/Makefile b/Makefile index 61c7f5a..1e2e8c8 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,8 @@ TOOLS = configd.tproj scselect.tproj scutil.tproj FRAMEWORK_SUBPROJECTS = SystemConfiguration.fproj -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble +OTHERSRCS = Makefile.preamble Makefile Makefile.postamble\ + preferences.xml MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles CODE_GEN_STYLE = DYNAMIC diff --git a/Makefile.postamble b/Makefile.postamble index b3af842..05b58f4 100644 --- a/Makefile.postamble +++ b/Makefile.postamble @@ -98,3 +98,7 @@ # owned by the top-level Makefile API and no context has been set up for where # derived files should go. # +SYSCONFIG_PREFS_DIR = /private/var/db/SystemConfiguration +install_extra: + $(MKDIRS) $(DSTROOT)$(SYSCONFIG_PREFS_DIR) + install -c -m 644 preferences.xml $(DSTROOT)$(SYSCONFIG_PREFS_DIR)/preferences.xml diff --git a/Makefile.preamble b/Makefile.preamble index 974c0ac..480f47f 100644 --- a/Makefile.preamble +++ b/Makefile.preamble @@ -135,3 +135,4 @@ # standard locations. NEXT_ROOT defaults to "C:/Apple" on Windows systems # and "" on other systems. DSTROOT = $(HOME) +AFTER_INSTALL = install_extra diff --git a/PB.project b/PB.project index 5726c0d..1be2515 100644 --- a/PB.project +++ b/PB.project @@ -2,7 +2,7 @@ DYNAMIC_CODE_GEN = YES; FILESTABLE = { H_FILES = (); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); + OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, preferences.xml); PRECOMPILED_HEADERS = (); PROJECT_HEADERS = (); PUBLIC_HEADERS = (); diff --git a/SystemConfiguration.fproj/CustomInfo.plist b/SystemConfiguration.fproj/CustomInfo.plist index 8be4e1f..1f6eaa3 100644 --- a/SystemConfiguration.fproj/CustomInfo.plist +++ b/SystemConfiguration.fproj/CustomInfo.plist @@ -1,5 +1,5 @@ { CFBundleName = "SystemConfiguration"; CFBundleIdentifier = "com.apple.SystemConfiguration"; - CFBundleShortVersionString = "1.1.0"; + CFBundleShortVersionString = "1.2.0"; } diff --git a/SystemConfiguration.fproj/DeviceOnHold.c b/SystemConfiguration.fproj/DeviceOnHold.c new file mode 100644 index 0000000..88079cf --- /dev/null +++ b/SystemConfiguration.fproj/DeviceOnHold.c @@ -0,0 +1,483 @@ +/* + * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This 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 OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * Modification History + * + * May 29, 2002 Roger Smith + * - initial revision + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#include "moh_msg.h" +#include "moh.h" +#include "DeviceOnHold.h" + + +#define kIODeviceSupportsHoldKey "DeviceSupportsHold" + + +static void * +__loadIOKit(void) { + static const void *image = NULL; + if (NULL == image) { + const char *framework = "/System/Library/Frameworks/IOKit.framework/IOKit"; + struct stat statbuf; + const char *suffix = getenv("DYLD_IMAGE_SUFFIX"); + char path[MAXPATHLEN]; + + strcpy(path, framework); + if (suffix) strcat(path, suffix); + if (0 <= stat(path, &statbuf)) { + image = NSAddImage(path, NSADDIMAGE_OPTION_NONE); + } else { + image = NSAddImage(framework, NSADDIMAGE_OPTION_NONE); + } + } + return (void *)image; +} + + +static io_object_t +_IOIteratorNext(io_iterator_t iterator) +{ + static io_object_t (*dyfunc)(io_iterator_t) = NULL; + if (!dyfunc) { + void *image = __loadIOKit(); + if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOIteratorNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND)); + } + return dyfunc ? dyfunc(iterator) : 0; +} +#define IOIteratorNext _IOIteratorNext + + +static kern_return_t +_IOMasterPort(mach_port_t bootstrapPort, mach_port_t *masterPort) +{ + static kern_return_t (*dyfunc)(mach_port_t, mach_port_t *) = NULL; + if (!dyfunc) { + void *image = __loadIOKit(); + if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOMasterPort", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND)); + } + return dyfunc ? dyfunc(bootstrapPort, masterPort) : KERN_FAILURE; +} +#define IOMasterPort _IOMasterPort + + +static kern_return_t +_IOObjectRelease(io_object_t object) +{ + static kern_return_t (*dyfunc)(io_object_t) = NULL; + if (!dyfunc) { + void *image = __loadIOKit(); + if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOObjectRelease", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND)); + } + return dyfunc ? dyfunc(object) : KERN_FAILURE; +} +#define IOObjectRelease _IOObjectRelease + + +static kern_return_t +_IORegistryEntryCreateCFProperties(io_registry_entry_t entry, CFMutableDictionaryRef *properties, CFAllocatorRef allocator, IOOptionBits options) +{ + static kern_return_t (*dyfunc)(io_registry_entry_t, CFMutableDictionaryRef *, CFAllocatorRef, IOOptionBits) = NULL; + if (!dyfunc) { + void *image = __loadIOKit(); + if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryCreateCFProperties", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND)); + } + return dyfunc ? dyfunc(entry, properties, allocator, options) : KERN_FAILURE; +} +#define IORegistryEntryCreateCFProperties _IORegistryEntryCreateCFProperties + + +static kern_return_t +_IORegistryEntryGetPath(io_registry_entry_t entry, const io_name_t plane, io_string_t path) +{ + static kern_return_t (*dyfunc)(io_registry_entry_t, const io_name_t, io_string_t) = NULL; + if (!dyfunc) { + void *image = __loadIOKit(); + if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryGetPath", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND)); + } + return dyfunc ? dyfunc(entry, plane, path) : KERN_FAILURE; +} +#define IORegistryEntryGetPath _IORegistryEntryGetPath + + +static kern_return_t +_IOServiceGetMatchingServices(mach_port_t masterPort, CFDictionaryRef matching, io_iterator_t *existing) +{ + static kern_return_t (*dyfunc)(mach_port_t, CFDictionaryRef, io_iterator_t *) = NULL; + if (!dyfunc) { + void *image = __loadIOKit(); + if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOServiceGetMatchingServices", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND)); + } + return dyfunc ? dyfunc(masterPort, matching, existing) : KERN_FAILURE; +} +#define IOServiceGetMatchingServices _IOServiceGetMatchingServices + + +static CFMutableDictionaryRef +_IOServiceMatching(const char *name) +{ + static CFMutableDictionaryRef (*dyfunc)(const char *) = NULL; + if (!dyfunc) { + void *image = __loadIOKit(); + if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOServiceMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND)); + } + return dyfunc ? dyfunc(name) : NULL; +} +#define IOServiceMatching _IOServiceMatching + + +typedef struct { + + /* base CFType information */ + CFRuntimeBase cfBase; + + /* device name (e.g. "modem") */ + CFStringRef name; + + int sock; + +} DeviceOnHoldPrivate, *DeviceOnHoldPrivateRef; + + +static CFStringRef +__DeviceOnHoldCopyDescription(CFTypeRef cf) +{ + CFAllocatorRef allocator = CFGetAllocator(cf); + CFMutableStringRef result; + + result = CFStringCreateMutable(allocator, 0); + CFStringAppendFormat(result, NULL, CFSTR(" {\n"), cf, allocator); + CFStringAppendFormat(result, NULL, CFSTR("}")); + + return result; +} + + +static void +__DeviceOnHoldDeallocate(CFTypeRef cf) +{ + DeviceOnHoldPrivateRef DeviceOnHoldPrivate = (DeviceOnHoldPrivateRef)cf; + + SCLog(_sc_verbose, LOG_DEBUG, CFSTR("__DeviceOnHoldDeallocate:")); + + /* release resources */ + if (DeviceOnHoldPrivate->name) CFRelease(DeviceOnHoldPrivate->name); + if (DeviceOnHoldPrivate->sock != -1) { + + } + + return; +} + + +static CFTypeID __kDeviceOnHoldTypeID = _kCFRuntimeNotATypeID; + + +static const CFRuntimeClass __DeviceOnHoldClass = { + 0, // version + "DeviceOnHold", // className + NULL, // init + NULL, // copy + __DeviceOnHoldDeallocate, // dealloc + NULL, // equal + NULL, // hash + NULL, // copyFormattingDesc + __DeviceOnHoldCopyDescription // copyDebugDesc +}; + + +static pthread_once_t initialized = PTHREAD_ONCE_INIT; + + +static void +__DeviceOnHoldInitialize(void) +{ + __kDeviceOnHoldTypeID = _CFRuntimeRegisterClass(&__DeviceOnHoldClass); + return; +} + + +DeviceOnHoldRef +__DeviceOnHoldCreatePrivate(CFAllocatorRef allocator) +{ + DeviceOnHoldPrivateRef devicePrivate; + UInt32 size; + + /* initialize runtime */ + pthread_once(&initialized, __DeviceOnHoldInitialize); + + /* allocate session */ + size = sizeof(DeviceOnHoldPrivate) - sizeof(CFRuntimeBase); + devicePrivate = (DeviceOnHoldPrivateRef)_CFRuntimeCreateInstance(allocator, + __kDeviceOnHoldTypeID, + size, + NULL); + if (!devicePrivate) { + return NULL; + } + + devicePrivate->name = NULL; + devicePrivate->sock = -1; + + return (DeviceOnHoldRef)devicePrivate; +} + + +/* + * TBD: We determine whether a device supports on hold capability by looking at + * the numeric property DeviceSupportsHold (1 - yes, 0 or no property - no). For + * the Apple Dash II internal modem we also use the property V92Modem to track + * this same capability. + */ + +Boolean +IsDeviceOnHoldSupported(CFStringRef deviceName, // "modem" + CFDictionaryRef options) +{ + CFMutableDictionaryRef deviceToMatch; + u_int32_t deviceSupportsHoldValue; + kern_return_t kr; + mach_port_t masterPort; + io_iterator_t matchingServices; + CFNumberRef num; + CFMutableDictionaryRef properties; + Boolean result = FALSE; + io_service_t service; + + if (CFStringCompare(deviceName, CFSTR("modem"), NULL) == kCFCompareEqualTo) { + kr = IOMasterPort(MACH_PORT_NULL, &masterPort); + if (kr != KERN_SUCCESS) { + goto errorExit; + } + + deviceToMatch = IOServiceMatching("InternalModemSupport"); + if (!deviceToMatch) { + goto errorExit; + } + + kr = IOServiceGetMatchingServices(masterPort, deviceToMatch, &matchingServices); + if (kr != KERN_SUCCESS) { + goto errorExit; + } + + for ( ; service = IOIteratorNext(matchingServices) ; IOObjectRelease(service)) { + io_string_t path; + + kr = IORegistryEntryGetPath(service, kIOServicePlane, path); + assert( kr == KERN_SUCCESS ); + + // grab a copy of the properties + kr = IORegistryEntryCreateCFProperties(service, &properties, kCFAllocatorDefault, kNilOptions); + assert( kr == KERN_SUCCESS ); + + num = CFDictionaryGetValue(properties, CFSTR(kIODeviceSupportsHoldKey)); + if (isA_CFNumber(num)) { + CFNumberGetValue(num, kCFNumberSInt32Type, &deviceSupportsHoldValue); + if (deviceSupportsHoldValue == 1) { + result = TRUE; + } + } + + CFRelease(properties); + } + + IOObjectRelease(matchingServices); + } + + // Note: The issue for the general case is how to go from the SystemConfiguration + // dynamic store to the actual driver. The devicesupportshold property is not + // copied the either of the setup/state descriptions so the caller would need + // to know the exact driver they are searching for. + + return result; + + errorExit: + + return FALSE; +} + + +DeviceOnHoldRef +DeviceOnHoldCreate(CFAllocatorRef allocator, + CFStringRef deviceName, // "modem" + CFDictionaryRef options) +{ + DeviceOnHoldRef device = NULL; + DeviceOnHoldPrivateRef devicePrivate; + int status; + + if (CFStringCompare(deviceName, CFSTR("modem"), NULL) != kCFCompareEqualTo) { + return NULL; + } + + device = __DeviceOnHoldCreatePrivate(allocator); + if (!device) { + return NULL; + } + + devicePrivate = (DeviceOnHoldPrivateRef)device; + + status = MOHInit(&devicePrivate->sock, deviceName); + if (status != 0) { + CFRelease(device); + return NULL; + } + + devicePrivate->name = CFRetain(deviceName); + + return device; +} + + + +int32_t +DeviceOnHoldGetStatus(DeviceOnHoldRef device) +{ + DeviceOnHoldPrivateRef devicePrivate = (DeviceOnHoldPrivateRef)device; + int err; + u_long link = 1; + void *replyBuf; + u_long replyBufLen; + int32_t result = -1; + + if (!device) { + return -1; + } + + if (devicePrivate->sock == -1) { + return -1; + } + + err = MOHExec(devicePrivate->sock, + link, + MOH_SESSION_GET_STATUS, + NULL, + 0, + &replyBuf, + &replyBufLen); + + if (err != 0) { + return -1; + } + + if (replyBufLen == sizeof(result)) { + result = *(int32_t *)replyBuf; + } + + if (replyBuf) CFAllocatorDeallocate(NULL, replyBuf); + return result; +} + + +Boolean +DeviceOnHoldSuspend(DeviceOnHoldRef device) +{ + DeviceOnHoldPrivateRef devicePrivate = (DeviceOnHoldPrivateRef)device; + int err; + u_long link = 1; + void *replyBuf; + u_long replyBufLen; + Boolean result = FALSE; + + if (!device) { + return FALSE; + } + + if (devicePrivate->sock == -1) { + return FALSE; + } + + err = MOHExec(devicePrivate->sock, + link, + MOH_PUT_SESSION_ON_HOLD, + NULL, + 0, + &replyBuf, + &replyBufLen); + + if (err != 0) { + return -1; + } + + if (replyBufLen == sizeof(result)) { + result = (*(int32_t *)replyBuf) ? TRUE : FALSE; + } + + if (replyBuf) CFAllocatorDeallocate(NULL, replyBuf); + return result; +} + + +Boolean +DeviceOnHoldResume(DeviceOnHoldRef device) +{ + DeviceOnHoldPrivateRef devicePrivate = (DeviceOnHoldPrivateRef)device; + int err; + u_long link = 1; + void *replyBuf; + u_long replyBufLen; + Boolean result = FALSE; + + if (!device) { + return FALSE; + } + + if (devicePrivate->sock == -1) { + return FALSE; + } + + err = MOHExec(devicePrivate->sock, + link, + MOH_RESUME_SESSION_ON_HOLD,NULL, + 0, + &replyBuf, + &replyBufLen); + + if (err != 0) { + return -1; + } + + if (replyBufLen == sizeof(result)) { + result = (*(int32_t *)replyBuf) ? TRUE : FALSE; + } + + if (replyBuf) CFAllocatorDeallocate(NULL, replyBuf); + return result; +} diff --git a/SystemConfiguration.fproj/DeviceOnHold.h b/SystemConfiguration.fproj/DeviceOnHold.h new file mode 100644 index 0000000..effb404 --- /dev/null +++ b/SystemConfiguration.fproj/DeviceOnHold.h @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This 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 OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + + +#ifndef _DEVICEONHOLD_H +#define _DEVICEONHOLD_H + +#include +#include + + +/*! + @enum + @discussion Returned status codes from DeviceOnHoldGetStatus() + + @constant kDeviceIdle + @constant kDeviceConnecting + @constant kDeviceDataConnectionActive + @constant kDeviceDataConnectionOnHold + @constant kDeviceDisconnecting +*/ +enum +{ + kDeviceIdle = 0, + kDeviceConnecting, + kDeviceDataConnectionActive, + kDeviceDataConnectionOnHold, + kDeviceDisconnecting +}; + + +/*! + @typedef DeviceOnHoldRef + @discussion This is the handle to a specific device + which is used by the DeviceOnHold APIs. + */ +typedef const struct __DeviceOnHoldRef * DeviceOnHoldRef; + + +__BEGIN_DECLS + + +/*! + @function IsDeviceOnHoldSupported + @discussion Determines whether a device has the capability to have + a connection placed "on hold". + + This function determines whether the device specified supports + the "on hold" capabality. + + @param devname A CFStringRef that represents the device being queried. + @param options A CFDictionaryRef of various options for the device. + @result TRUE if device supports "on hold". + + */ +Boolean +IsDeviceOnHoldSupported ( + CFStringRef devname, // e.g. "modem" + CFDictionaryRef options + ); + +/*! + @function DeviceOnHoldCreate + @discussion Creates a DeviceOnHoldRef for the specified device supports. + + This function creates a DeviceOnHoldRef handle which will be used + in all subsequent calls to the "on hold" API's. + + @param allocator A CFAllocatorRef. + @param devname A CFStringRef that represents the device being queried. + @param options A CFDictionaryRef of various options for the device. + @result DeviceOnHoldRef to pass to subsequent device hold api's. + + */ +DeviceOnHoldRef +DeviceOnHoldCreate ( + CFAllocatorRef allocator, + CFStringRef devname, // e.g. "modem" + CFDictionaryRef options + ); + + +/*! + @function DeviceOnHoldGetStatus + @discussion Returns the "on hold" status of the device. + + @param deviceRef A DeviceOnHoldRef. + @result The status of device. + + */ +int32_t +DeviceOnHoldGetStatus ( + DeviceOnHoldRef deviceRef + ); + + +/*! + @function DeviceOnHoldSuspend + @discussion Tells the device to go "on hold". + + This function will signal the deviceRef to suspend operations + + @param deviceRef A DeviceOnHoldRef. + @result Boolean if call succeeded. + + */ +Boolean +DeviceOnHoldSuspend ( + DeviceOnHoldRef deviceRef + ); + +/*! + @function DeviceOnHoldResume + @discussion Tells the device to resume. + + This function will signal the deviceRef to resume operations + + @param deviceRef A DeviceOnHoldRef. + @result Boolean if call succeeded. + + */ +Boolean +DeviceOnHoldResume ( + DeviceOnHoldRef deviceRef + ); + +__END_DECLS + +#endif /* _DEVICEONHOLD_H */ + diff --git a/SystemConfiguration.fproj/Makefile b/SystemConfiguration.fproj/Makefile index 7235655..d7fbd90 100644 --- a/SystemConfiguration.fproj/Makefile +++ b/SystemConfiguration.fproj/Makefile @@ -20,20 +20,21 @@ HFILES = SystemConfiguration.h SCPrivate.h SCDPlugin.h config_types.h\ SCPreferencesPath.h SCPreferencesSetSpecific.h SCNetwork.h\ SCValidation.h ppp_msg.h ppp.h v1Compatibility.h SCD.h\ SCDKeys.h SCP.h SCPPath.h SCDConsoleUser.h SCDHostName.h\ - DHCPClientPreferences.h SCDynamicStoreCopyDHCPInfo.h - -CFILES = SCD.c SCDKeys.c SCDPrivate.c SCDOpen.c SCDLock.c SCDUnlock.c\ - SCDList.c SCDAdd.c SCDAddSession.c SCDGet.c SCDSet.c\ - SCDRemove.c SCDTouch.c SCDNotify.c SCDNotifierSetKeys.c\ - SCDNotifierList.c SCDNotifierAdd.c SCDNotifierRemove.c\ - SCDNotifierGetChanges.c SCDNotifierWait.c\ + DHCPClientPreferences.h SCDynamicStoreCopyDHCPInfo.h moh_msg.h\ + moh.h DeviceOnHold.h + +CFILES = SCD.c SCDKeys.c SCDPrivate.c SCDPlugin.c SCDOpen.c SCDLock.c\ + SCDUnlock.c SCDList.c SCDAdd.c SCDAddSession.c SCDGet.c\ + SCDSet.c SCDRemove.c SCDTouch.c SCDNotify.c\ + SCDNotifierSetKeys.c SCDNotifierList.c SCDNotifierAdd.c\ + SCDNotifierRemove.c SCDNotifierGetChanges.c SCDNotifierWait.c\ SCDNotifierInformViaCallback.c SCDNotifierInformViaMachPort.c\ SCDNotifierInformViaFD.c SCDNotifierInformViaSignal.c\ SCDNotifierCancel.c SCDSnapshot.c SCP.c SCPOpen.c SCPLock.c\ SCPUnlock.c SCPList.c SCPGet.c SCPAdd.c SCPSet.c SCPRemove.c\ SCPCommit.c SCPApply.c SCPPath.c SCDConsoleUser.c\ - SCDHostName.c SCNetwork.c SCProxies.c ppp.c v1Compatibility.c\ - DHCP.c + SCDHostName.c SCLocation.c SCNetwork.c SCProxies.c ppp.c\ + v1Compatibility.c DHCP.c moh.c DeviceOnHold.c OTHERSRCS = Makefile.preamble Makefile Makefile.postamble m.template\ h.template config.defs genSCPreferences.c CustomInfo.plist @@ -52,22 +53,21 @@ DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) -NEXTSTEP_PB_CFLAGS = -DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS FRAMEWORKS = -framework CoreFoundation PUBLIC_HEADERS = SystemConfiguration.h SCDynamicStore.h\ SCDynamicStoreKey.h SCDynamicStoreCopySpecific.h\ SCPreferences.h SCPreferencesPath.h\ - SCPreferencesSetSpecific.h SCNetwork.h + SCPreferencesSetSpecific.h SCNetwork.h\ + DHCPClientPreferences.h SCDynamicStoreCopyDHCPInfo.h -PROJECT_HEADERS = SystemConfiguration.h SCPrivate.h config_types.h\ - SCDynamicStoreInternal.h SCDynamicStore.h\ - SCDynamicStorePrivate.h SCDynamicStoreKey.h\ - SCDynamicStoreCopySpecific.h\ +PROJECT_HEADERS = SCPrivate.h config_types.h SCDynamicStoreInternal.h\ + SCDynamicStore.h SCDynamicStorePrivate.h\ + SCDynamicStoreKey.h SCDynamicStoreCopySpecific.h\ SCDynamicStoreSetSpecificPrivate.h\ SCPreferencesInternal.h SCPreferences.h\ SCPreferencesPrivate.h SCPreferencesPath.h\ SCPreferencesSetSpecific.h SCNetwork.h SCValidation.h\ - v1Compatibility.h + SystemConfiguration.h v1Compatibility.h diff --git a/SystemConfiguration.fproj/Makefile.postamble b/SystemConfiguration.fproj/Makefile.postamble index 575e099..cb82712 100644 --- a/SystemConfiguration.fproj/Makefile.postamble +++ b/SystemConfiguration.fproj/Makefile.postamble @@ -119,4 +119,4 @@ genSCFiles: /tmp/genSCFiles cfile > /tmp/SCSchemaDefinitions.c dhcp: DHCP.c - cc -Wall -DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS -DTEST_DHCPCLIENT_PREFERENCES -g -o dhcp DHCP.c -framework CoreFoundation -framework SystemConfiguration + cc -Wall -DTEST_DHCPCLIENT_PREFERENCES -g -o dhcp DHCP.c -framework CoreFoundation -framework SystemConfiguration diff --git a/SystemConfiguration.fproj/Makefile.preamble b/SystemConfiguration.fproj/Makefile.preamble index ac3fc04..feba1ec 100644 --- a/SystemConfiguration.fproj/Makefile.preamble +++ b/SystemConfiguration.fproj/Makefile.preamble @@ -137,7 +137,7 @@ OTHER_GENERATED_OFILES = $(VERS_OFILE) # DSTROOT = $(HOME) # Additional flags for MiG generated files -OTHER_PROJECT_HEADERS += config.defs config.h +OTHER_PRIVATE_HEADERS += config.defs config.h OTHER_PRIVATE_HEADERS += SCPrivate.h OTHER_PRIVATE_HEADERS += SCDynamicStorePrivate.h @@ -145,8 +145,7 @@ OTHER_PRIVATE_HEADERS += SCDynamicStoreSetSpecificPrivate.h OTHER_PRIVATE_HEADERS += SCPreferencesPrivate.h OTHER_PRIVATE_HEADERS += SCValidation.h OTHER_PRIVATE_HEADERS += SCDPlugin.h -OTHER_PRIVATE_HEADERS += SCDynamicStoreCopyDHCPInfo.h -OTHER_PRIVATE_HEADERS += DHCPClientPreferences.h +OTHER_PRIVATE_HEADERS += DeviceOnHold.h # # XXX INSTALL V1 COMPATIBILITY HEADERS XXX diff --git a/SystemConfiguration.fproj/PB.project b/SystemConfiguration.fproj/PB.project index 8c1c394..4b815ad 100644 --- a/SystemConfiguration.fproj/PB.project +++ b/SystemConfiguration.fproj/PB.project @@ -33,12 +33,16 @@ SCDConsoleUser.h, SCDHostName.h, DHCPClientPreferences.h, - SCDynamicStoreCopyDHCPInfo.h + SCDynamicStoreCopyDHCPInfo.h, + moh_msg.h, + moh.h, + DeviceOnHold.h ); OTHER_LINKED = ( SCD.c, SCDKeys.c, SCDPrivate.c, + SCDPlugin.c, SCDOpen.c, SCDLock.c, SCDUnlock.c, @@ -76,11 +80,14 @@ SCPPath.c, SCDConsoleUser.c, SCDHostName.c, + SCLocation.c, SCNetwork.c, SCProxies.c, ppp.c, v1Compatibility.c, - DHCP.c + DHCP.c, + moh.c, + DeviceOnHold.c ); OTHER_SOURCES = ( Makefile.preamble, @@ -94,7 +101,6 @@ ); PRECOMPILED_HEADERS = (); PROJECT_HEADERS = ( - SystemConfiguration.h, SCPrivate.h, config_types.h, SCDynamicStoreInternal.h, @@ -110,6 +116,7 @@ SCPreferencesSetSpecific.h, SCNetwork.h, SCValidation.h, + SystemConfiguration.h, v1Compatibility.h ); PUBLIC_HEADERS = ( @@ -120,14 +127,15 @@ SCPreferences.h, SCPreferencesPath.h, SCPreferencesSetSpecific.h, - SCNetwork.h + SCNetwork.h, + DHCPClientPreferences.h, + SCDynamicStoreCopyDHCPInfo.h ); SUBPROJECTS = (); }; LANGUAGE = English; MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; NEXTSTEP_BUILDTOOL = /usr/bin/gnumake; - NEXTSTEP_COMPILEROPTIONS = "-DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS"; NEXTSTEP_INSTALLDIR = "$(SYSTEM_LIBRARY_DIR)/Frameworks"; NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; diff --git a/SystemConfiguration.fproj/SCD.c b/SystemConfiguration.fproj/SCD.c index 4a480dc..b476211 100644 --- a/SystemConfiguration.fproj/SCD.c +++ b/SystemConfiguration.fproj/SCD.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -53,6 +53,7 @@ static const struct sc_errmsg { { kSCStatusInvalidArgument, "Invalid argument" }, { kSCStatusKeyExists, "Key already defined" }, { kSCStatusLocked, "Lock already held" }, + { kSCStatusMaxLink, "Maximum link count exceeded" }, { kSCStatusNeedLock, "Lock required for this operation" }, { kSCStatusNoStoreServer, "Configuration daemon not (no longer) available" }, { kSCStatusNoStoreSession, "Configuration daemon session not active" }, @@ -84,7 +85,7 @@ _SCCopyDescription(void *info, CFDictionaryRef formatOptions) CFTypeID type = CFGetTypeID(info); if (!formatOptions || - !CFDictionaryGetValueIfPresent(formatOptions, CFSTR("PREFIX1"), (void **)&prefix1)) { + !CFDictionaryGetValueIfPresent(formatOptions, CFSTR("PREFIX1"), (const void **)&prefix1)) { prefix1 = CFSTR(""); } @@ -153,7 +154,7 @@ _SCCopyDescription(void *info, CFDictionaryRef formatOptions) } if (!formatOptions || - !CFDictionaryGetValueIfPresent(formatOptions, CFSTR("PREFIX2"), (void **)&prefix2)) { + !CFDictionaryGetValueIfPresent(formatOptions, CFSTR("PREFIX2"), (const void **)&prefix2)) { prefix2 = CFStringCreateCopy(NULL, prefix1); } @@ -167,7 +168,7 @@ _SCCopyDescription(void *info, CFDictionaryRef formatOptions) } if (type == CFArrayGetTypeID()) { - void **elements; + const void **elements; CFIndex i; CFIndex nElements; CFMutableStringRef str; @@ -176,42 +177,44 @@ _SCCopyDescription(void *info, CFDictionaryRef formatOptions) CFStringAppendFormat(str, formatOptions, CFSTR("%@ {"), prefix1); nElements = CFArrayGetCount(info); - elements = CFAllocatorAllocate(NULL, nElements * sizeof(CFTypeRef), 0); - CFArrayGetValues(info, CFRangeMake(0, nElements), elements); - for (i=0; i 0) { + elements = CFAllocatorAllocate(NULL, nElements * sizeof(CFTypeRef), 0); + CFArrayGetValues(info, CFRangeMake(0, nElements), elements); + for (i=0; i {"), prefix1); nElements = CFDictionaryGetCount(info); - keys = CFAllocatorAllocate(NULL, nElements * sizeof(CFTypeRef), 0); - values = CFAllocatorAllocate(NULL, nElements * sizeof(CFTypeRef), 0); - CFDictionaryGetKeysAndValues(info, keys, values); - for (i=0; i 0) { + keys = CFAllocatorAllocate(NULL, nElements * sizeof(CFTypeRef), 0); + values = CFAllocatorAllocate(NULL, nElements * sizeof(CFTypeRef), 0); + CFDictionaryGetKeysAndValues(info, keys, values); + for (i=0; iserver, diff --git a/SystemConfiguration.fproj/SCDAddSession.c b/SystemConfiguration.fproj/SCDAddSession.c index d470876..897f67f 100644 --- a/SystemConfiguration.fproj/SCDAddSession.c +++ b/SystemConfiguration.fproj/SCDAddSession.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -68,14 +68,18 @@ SCDynamicStoreAddTemporaryValue(SCDynamicStoreRef store, CFStringRef key, CFProp return FALSE; } - /* serialize the key and data */ - xmlKey = CFPropertyListCreateXMLData(NULL, key); - myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey); - myKeyLen = CFDataGetLength(xmlKey); + /* serialize the key */ + if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) { + _SCErrorSet(kSCStatusFailed); + return FALSE; + } - xmlData = CFPropertyListCreateXMLData(NULL, value); - myDataRef = (xmlData_t)CFDataGetBytePtr(xmlData); - myDataLen = CFDataGetLength(xmlData); + /* serialize the data */ + if (!_SCSerialize(value, &xmlData, (void **)&myDataRef, &myDataLen)) { + CFRelease(xmlKey); + _SCErrorSet(kSCStatusFailed); + return FALSE; + } /* send the key & data to the server */ status = configadd_s(storePrivate->server, diff --git a/SystemConfiguration.fproj/SCDConsoleUser.c b/SystemConfiguration.fproj/SCDConsoleUser.c index 900db51..1eb518a 100644 --- a/SystemConfiguration.fproj/SCDConsoleUser.c +++ b/SystemConfiguration.fproj/SCDConsoleUser.c @@ -31,8 +31,8 @@ */ #include -#include #include +#include CFStringRef SCDynamicStoreKeyCreateConsoleUser(CFAllocatorRef allocator) @@ -53,21 +53,22 @@ SCDynamicStoreCopyConsoleUser(SCDynamicStoreRef store, CFStringRef consoleUser = NULL; CFDictionaryRef dict = NULL; CFStringRef key; - SCDynamicStoreRef mySession = store; + Boolean tempSession = FALSE; if (!store) { - mySession = SCDynamicStoreCreate(NULL, - CFSTR("SCDynamicStoreCopyConsoleUser"), - NULL, - NULL); - if (!mySession) { + store = SCDynamicStoreCreate(NULL, + CFSTR("SCDynamicStoreCopyConsoleUser"), + NULL, + NULL); + if (!store) { SCLog(_sc_verbose, LOG_INFO, CFSTR("SCDynamicStoreCreate() failed")); return NULL; } + tempSession = TRUE; } key = SCDynamicStoreKeyCreateConsoleUser(NULL); - dict = SCDynamicStoreCopyValue(mySession, key); + dict = SCDynamicStoreCopyValue(store, key); CFRelease(key); if (!isA_CFDictionary(dict)) { _SCErrorSet(kSCStatusNoKey); @@ -109,8 +110,8 @@ SCDynamicStoreCopyConsoleUser(SCDynamicStoreRef store, done : - if (!store && mySession) CFRelease(mySession); - if (dict) CFRelease(dict); + if (tempSession) CFRelease(store); + if (dict) CFRelease(dict); return consoleUser; } @@ -125,23 +126,24 @@ SCDynamicStoreSetConsoleUser(SCDynamicStoreRef store, CFStringRef consoleUser; CFMutableDictionaryRef dict = NULL; CFStringRef key = SCDynamicStoreKeyCreateConsoleUser(NULL); - SCDynamicStoreRef mySession = store; CFNumberRef num; Boolean ok = TRUE; + Boolean tempSession = FALSE; if (!store) { - mySession = SCDynamicStoreCreate(NULL, - CFSTR("SCDynamicStoreSetConsoleUser"), - NULL, - NULL); - if (!mySession) { + store = SCDynamicStoreCreate(NULL, + CFSTR("SCDynamicStoreSetConsoleUser"), + NULL, + NULL); + if (!store) { SCLog(_sc_verbose, LOG_INFO, CFSTR("SCDynamicStoreCreate() failed")); return FALSE; } + tempSession = TRUE; } if (user == NULL) { - ok = SCDynamicStoreRemoveValue(mySession, key); + ok = SCDynamicStoreRemoveValue(store, key); goto done; } @@ -162,12 +164,12 @@ SCDynamicStoreSetConsoleUser(SCDynamicStoreRef store, CFDictionarySetValue(dict, kSCPropUsersConsoleUserGID, num); CFRelease(num); - ok = SCDynamicStoreSetValue(mySession, key, dict); + ok = SCDynamicStoreSetValue(store, key, dict); done : - if (dict) CFRelease(dict); - if (key) CFRelease(key); - if (!store && mySession) CFRelease(mySession); + if (dict) CFRelease(dict); + if (key) CFRelease(key); + if (tempSession) CFRelease(store); return ok; } diff --git a/SystemConfiguration.fproj/SCDGet.c b/SystemConfiguration.fproj/SCDGet.c index 7cccb61..299fd00 100644 --- a/SystemConfiguration.fproj/SCDGet.c +++ b/SystemConfiguration.fproj/SCDGet.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -54,10 +54,8 @@ SCDynamicStoreCopyMultiple(SCDynamicStoreRef store, CFIndex myPatternsLen = 0; xmlDataOut_t xmlDictRef; /* dict (serialized) */ CFIndex xmlDictLen; - CFDataRef xmlDict; /* dict (XML serialized) */ - CFDictionaryRef dict; /* dict (un-serialized) */ + CFDictionaryRef dict = NULL; /* dict (un-serialized) */ int sc_status; - CFStringRef xmlError; SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreCopyMultiple:")); SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" keys = %@"), keys); @@ -76,16 +74,19 @@ SCDynamicStoreCopyMultiple(SCDynamicStoreRef store, /* serialize the keys */ if (keys) { - xmlKeys = CFPropertyListCreateXMLData(NULL, keys); - myKeysRef = (xmlData_t)CFDataGetBytePtr(xmlKeys); - myKeysLen = CFDataGetLength(xmlKeys); + if (!_SCSerialize(keys, &xmlKeys, (void **)&myKeysRef, &myKeysLen)) { + _SCErrorSet(kSCStatusFailed); + return NULL; + } } /* serialize the patterns */ if (patterns) { - xmlPatterns = CFPropertyListCreateXMLData(NULL, patterns); - myPatternsRef = (xmlData_t)CFDataGetBytePtr(xmlPatterns); - myPatternsLen = CFDataGetLength(xmlPatterns); + if (!_SCSerialize(patterns, &xmlPatterns, (void **)&myPatternsRef, &myPatternsLen)) { + CFRelease(xmlKeys); + _SCErrorSet(kSCStatusFailed); + return NULL; + } } /* send the keys and patterns, fetch the associated result from the server */ @@ -121,25 +122,8 @@ SCDynamicStoreCopyMultiple(SCDynamicStoreRef store, return NULL; } - /* un-serialize the dict, return a value associated with the key */ - xmlDict = CFDataCreate(NULL, xmlDictRef, xmlDictLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)xmlDictRef, xmlDictLen); - if (status != KERN_SUCCESS) { - SCLog(_sc_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - dict = CFPropertyListCreateFromXMLData(NULL, - xmlDict, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlDict); - if (!dict) { - if (xmlError) { - SCLog(_sc_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() dict: %@"), - xmlError); - CFRelease(xmlError); - } + /* un-serialize the dictionary */ + if (!_SCUnserialize((CFPropertyListRef *)&dict, xmlDictRef, xmlDictLen)) { _SCErrorSet(kSCStatusFailed); return NULL; } @@ -160,11 +144,9 @@ SCDynamicStoreCopyValue(SCDynamicStoreRef store, CFStringRef key) CFIndex myKeyLen; xmlDataOut_t xmlDataRef; /* data (serialized) */ CFIndex xmlDataLen; - CFDataRef xmlData; /* data (XML serialized) */ CFPropertyListRef data; /* data (un-serialized) */ int newInstance; int sc_status; - CFStringRef xmlError; SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreCopyValue:")); SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" key = %@"), key); @@ -181,9 +163,10 @@ SCDynamicStoreCopyValue(SCDynamicStoreRef store, CFStringRef key) } /* serialize the key */ - xmlKey = CFPropertyListCreateXMLData(NULL, key); - myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey); - myKeyLen = CFDataGetLength(xmlKey); + if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) { + _SCErrorSet(kSCStatusFailed); + return NULL; + } /* send the key & fetch the associated data from the server */ status = configget(storePrivate->server, @@ -216,25 +199,8 @@ SCDynamicStoreCopyValue(SCDynamicStoreRef store, CFStringRef key) return NULL; } - /* un-serialize the data, return a value associated with the key */ - xmlData = CFDataCreate(NULL, xmlDataRef, xmlDataLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)xmlDataRef, xmlDataLen); - if (status != KERN_SUCCESS) { - SCLog(_sc_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - data = CFPropertyListCreateFromXMLData(NULL, - xmlData, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlData); - if (!data) { - if (xmlError) { - SCLog(_sc_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() data: %@"), - xmlError); - CFRelease(xmlError); - } + /* un-serialize the data */ + if (!_SCUnserialize(&data, xmlDataRef, xmlDataLen)) { _SCErrorSet(kSCStatusFailed); return NULL; } diff --git a/SystemConfiguration.fproj/SCDHostName.c b/SystemConfiguration.fproj/SCDHostName.c index b4ad826..23ec5d4 100644 --- a/SystemConfiguration.fproj/SCDHostName.c +++ b/SystemConfiguration.fproj/SCDHostName.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -51,21 +51,22 @@ SCDynamicStoreCopyComputerName(SCDynamicStoreRef store, CFDictionaryRef dict = NULL; CFStringRef key; CFStringRef name = NULL; - SCDynamicStoreRef mySession = store; + Boolean tempSession = FALSE; if (!store) { - mySession = SCDynamicStoreCreate(NULL, - CFSTR("SCDynamicStoreCopyComputerName"), - NULL, - NULL); - if (!mySession) { + store = SCDynamicStoreCreate(NULL, + CFSTR("SCDynamicStoreCopyComputerName"), + NULL, + NULL); + if (!store) { SCLog(_sc_verbose, LOG_INFO, CFSTR("SCDynamicStoreCreate() failed")); return NULL; } + tempSession = TRUE; } key = SCDynamicStoreKeyCreateComputerName(NULL); - dict = SCDynamicStoreCopyValue(mySession, key); + dict = SCDynamicStoreCopyValue(store, key); CFRelease(key); if (!dict) { goto done; @@ -96,8 +97,8 @@ SCDynamicStoreCopyComputerName(SCDynamicStoreRef store, done : - if (!store && mySession) CFRelease(mySession); - if (dict) CFRelease(dict); + if (tempSession) CFRelease(store); + if (dict) CFRelease(dict); return name; } @@ -113,7 +114,7 @@ SCPreferencesSetComputerName(SCPreferencesRef session, Boolean ok = FALSE; CFStringRef path = NULL; - if (CFGetTypeID(name) != CFStringGetTypeID()) { + if (!isA_CFString(name)) { _SCErrorSet(kSCStatusInvalidArgument); return FALSE; } @@ -150,3 +151,204 @@ SCPreferencesSetComputerName(SCPreferencesRef session, return ok; } + + +CFStringRef +SCDynamicStoreKeyCreateHostNames(CFAllocatorRef allocator) +{ + return SCDynamicStoreKeyCreate(allocator, + CFSTR("%@/%@/%@"), + kSCDynamicStoreDomainSetup, + kSCCompNetwork, + kSCCompHostNames); +} + + +CFStringRef +SCDynamicStoreCopyLocalHostName(SCDynamicStoreRef store) +{ + CFDictionaryRef dict = NULL; + CFStringRef key; + CFStringRef name = NULL; + Boolean tempSession = FALSE; + + if (!store) { + store = SCDynamicStoreCreate(NULL, + CFSTR("SCDynamicStoreCopyLocalHostName"), + NULL, + NULL); + if (!store) { + SCLog(_sc_verbose, LOG_INFO, CFSTR("SCDynamicStoreCreate() failed")); + return NULL; + } + tempSession = TRUE; + } + + key = SCDynamicStoreKeyCreateHostNames(NULL); + dict = SCDynamicStoreCopyValue(store, key); + CFRelease(key); + if (!dict) { + goto done; + } + if (!isA_CFDictionary(dict)) { + _SCErrorSet(kSCStatusNoKey); + goto done; + } + + name = isA_CFString(CFDictionaryGetValue(dict, kSCPropNetLocalHostName)); + if (!name) { + _SCErrorSet(kSCStatusNoKey); + goto done; + } + CFRetain(name); + + done : + + if (tempSession) CFRelease(store); + if (dict) CFRelease(dict); + return name; +} + + +Boolean +_SC_stringIsValidDNSName(const char *name) +{ + int i; + int len = strlen(name); + char prev = '\0'; + const char *scan; + + if (len == 0) { + return FALSE; + } + + for (scan = name, i = 0; i < len; i++, scan++) { + char ch = *scan; + char next = *(scan + 1); + + if (prev == '.' || prev == '\0') { + if (isalpha(ch) == 0) { + return FALSE; + } + } else if (next == '\0' || next == '.') { + if (isalnum(ch) == 0) { + return FALSE; + } + } else if (isalnum(ch) == 0) { + switch (ch) { + case '.': + case '-': + if (prev == '.' || prev == '-') { + return FALSE; + } + break; + default: + return FALSE; + break; + } + } + prev = ch; + } + + return TRUE; +} + +Boolean +_SC_CFStringIsValidDNSName(CFStringRef name) +{ + Boolean clean = FALSE; + CFIndex len; + char *str = NULL; + + if (!isA_CFString(name)) { + goto failed; + } + + len = CFStringGetLength(name) + 1; + if (len == 0) { + goto failed; + } + + str = CFAllocatorAllocate(NULL, len, 0); + if (str == NULL) { + goto failed; + } + + if (!CFStringGetCString(name, str, len, kCFStringEncodingASCII)) { + goto failed; + } + + clean = _SC_stringIsValidDNSName(str); + + failed: + + if (str) CFAllocatorDeallocate(NULL, str); + return clean; +} + + +Boolean +SCPreferencesSetLocalHostName(SCPreferencesRef session, + CFStringRef name) +{ + CFDictionaryRef dict; + CFMutableDictionaryRef newDict = NULL; + Boolean ok = FALSE; + CFStringRef path = NULL; + + if (name) { + if (!isA_CFString(name)) { + _SCErrorSet(kSCStatusInvalidArgument); + return FALSE; + } + + if (CFStringGetLength(name) == 0) { + name = NULL; + } + } + + if (name && !_SC_CFStringIsValidDNSName(name)) { + _SCErrorSet(kSCStatusInvalidArgument); + return FALSE; + } + + path = CFStringCreateWithFormat(NULL, + NULL, + CFSTR("/%@/%@/%@"), + kSCPrefSystem, + kSCCompNetwork, + kSCCompHostNames); + + dict = SCPreferencesPathGetValue(session, path); + if (dict) { + newDict = CFDictionaryCreateMutableCopy(NULL, 0, dict); + } else { + newDict = CFDictionaryCreateMutable(NULL, + 0, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + } + + if (name) { + CFDictionarySetValue(newDict, kSCPropNetLocalHostName, name); + } else { + CFDictionaryRemoveValue(newDict, kSCPropNetLocalHostName); + } + + if (CFDictionaryGetCount(newDict) > 0) { + ok = SCPreferencesPathSetValue(session, path, newDict); + if (!ok) { + SCLog(_sc_verbose, LOG_ERR, CFSTR("SCPreferencesPathSetValue() failed")); + } + } else { + ok = SCPreferencesPathRemoveValue(session, path); + if (!ok) { + SCLog(_sc_verbose, LOG_ERR, CFSTR("SCPreferencesPathRemoveValue() failed")); + } + } + + if (path) CFRelease(path); + if (newDict) CFRelease(newDict); + + return ok; +} diff --git a/SystemConfiguration.fproj/SCDList.c b/SystemConfiguration.fproj/SCDList.c index 85055cd..e21798b 100644 --- a/SystemConfiguration.fproj/SCDList.c +++ b/SystemConfiguration.fproj/SCDList.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -46,12 +46,10 @@ SCDynamicStoreCopyKeyList(SCDynamicStoreRef store, CFStringRef pattern) CFDataRef xmlPattern; /* serialized pattern */ xmlData_t myPatternRef; CFIndex myPatternLen; - CFDataRef xmlData; /* data (XML serialized) */ xmlDataOut_t xmlDataRef; /* serialized data */ int xmlDataLen; int sc_status; CFArrayRef allKeys; - CFStringRef xmlError; SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreCopyKeyList:")); SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" pattern = %@"), pattern); @@ -68,9 +66,10 @@ SCDynamicStoreCopyKeyList(SCDynamicStoreRef store, CFStringRef pattern) } /* serialize the pattern */ - xmlPattern = CFPropertyListCreateXMLData(NULL, pattern); - myPatternRef = (xmlData_t)CFDataGetBytePtr(xmlPattern); - myPatternLen = CFDataGetLength(xmlPattern); + if (!_SCSerialize(pattern, &xmlPattern, (void **)&myPatternRef, &myPatternLen)) { + _SCErrorSet(kSCStatusFailed); + return NULL; + } /* send the pattern & fetch the associated data from the server */ status = configlist(storePrivate->server, @@ -104,24 +103,7 @@ SCDynamicStoreCopyKeyList(SCDynamicStoreRef store, CFStringRef pattern) } /* un-serialize the list of keys */ - xmlData = CFDataCreate(NULL, xmlDataRef, xmlDataLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)xmlDataRef, xmlDataLen); - if (status != KERN_SUCCESS) { - SCLog(_sc_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - allKeys = CFPropertyListCreateFromXMLData(NULL, - xmlData, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlData); - if (!allKeys) { - if (xmlError) { - SCLog(_sc_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() list: %@"), - xmlError); - CFRelease(xmlError); - } + if (!_SCUnserialize((CFPropertyListRef *)&allKeys, xmlDataRef, xmlDataLen)) { _SCErrorSet(kSCStatusFailed); return NULL; } diff --git a/SystemConfiguration.fproj/SCDNotifierAdd.c b/SystemConfiguration.fproj/SCDNotifierAdd.c index 392ca27..3a8cd55 100644 --- a/SystemConfiguration.fproj/SCDNotifierAdd.c +++ b/SystemConfiguration.fproj/SCDNotifierAdd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -84,11 +84,12 @@ SCDynamicStoreAddWatchedKey(SCDynamicStoreRef store, CFStringRef key, Boolean is } /* serialize the key */ - xmlKey = CFPropertyListCreateXMLData(NULL, key); - myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey); - myKeyLen = CFDataGetLength(xmlKey); + if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) { + _SCErrorSet(kSCStatusFailed); + return FALSE; + } - /* send the key & data to the server */ + /* send the key to the server */ status = notifyadd(storePrivate->server, myKeyRef, myKeyLen, diff --git a/SystemConfiguration.fproj/SCDNotifierCancel.c b/SystemConfiguration.fproj/SCDNotifierCancel.c index e1a236b..890b089 100644 --- a/SystemConfiguration.fproj/SCDNotifierCancel.c +++ b/SystemConfiguration.fproj/SCDNotifierCancel.c @@ -64,9 +64,8 @@ SCDynamicStoreNotifyCancel(SCDynamicStoreRef store) /* if no notifications have been registered */ return TRUE; case Using_NotifierInformViaRunLoop : - /* once activated, a RunLoop notifier cannot be cancelled */ - _SCErrorSet(kSCStatusNotifierActive); - return FALSE; + CFRunLoopSourceInvalidate(storePrivate->rls); + return TRUE; case Using_NotifierInformViaCallback : SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" cancel callback runloop source")); diff --git a/SystemConfiguration.fproj/SCDNotifierGetChanges.c b/SystemConfiguration.fproj/SCDNotifierGetChanges.c index 71ecfb2..f139ee1 100644 --- a/SystemConfiguration.fproj/SCDNotifierGetChanges.c +++ b/SystemConfiguration.fproj/SCDNotifierGetChanges.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -43,12 +43,10 @@ SCDynamicStoreCopyNotifiedKeys(SCDynamicStoreRef store) { SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store; kern_return_t status; - CFDataRef xmlData; /* data (XML serialized) */ xmlDataOut_t xmlDataRef; /* serialized data */ int xmlDataLen; int sc_status; CFArrayRef allKeys; - CFStringRef xmlError; SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreCopyNotifiedKeys:")); @@ -89,24 +87,7 @@ SCDynamicStoreCopyNotifiedKeys(SCDynamicStoreRef store) } /* un-serialize the list of keys which have changed */ - xmlData = CFDataCreate(NULL, xmlDataRef, xmlDataLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)xmlDataRef, xmlDataLen); - if (status != KERN_SUCCESS) { - SCLog(_sc_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - allKeys = CFPropertyListCreateFromXMLData(NULL, - xmlData, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlData); - if (!allKeys) { - if (xmlError) { - SCLog(_sc_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() list: %@"), - xmlError); - CFRelease(xmlError); - } + if (!_SCUnserialize((CFPropertyListRef *)&allKeys, xmlDataRef, xmlDataLen)) { _SCErrorSet(kSCStatusFailed); return NULL; } diff --git a/SystemConfiguration.fproj/SCDNotifierInformViaCallback.c b/SystemConfiguration.fproj/SCDNotifierInformViaCallback.c index 9b1cf56..2a4385e 100644 --- a/SystemConfiguration.fproj/SCDNotifierInformViaCallback.c +++ b/SystemConfiguration.fproj/SCDNotifierInformViaCallback.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -107,7 +107,12 @@ SCDynamicStoreNotifyCallback(SCDynamicStoreRef store, mach_port_t port; mach_port_t oldNotify; int sc_status; - CFMachPortContext context = { 0, (void *)store, NULL, NULL, NULL }; + CFMachPortContext context = { 0 + , (void *)store + , CFRetain + , CFRelease + , NULL + }; SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreNotifyCallback:")); @@ -217,10 +222,12 @@ rlsCallback(CFMachPortRef port, void *msg, CFIndex size, void *info) /* remove the run loop source(s) */ CFRunLoopSourceInvalidate(storePrivate->callbackRunLoopSource); CFRelease(storePrivate->callbackRunLoopSource); + storePrivate->callbackRunLoopSource = NULL; /* invalidate port */ CFMachPortInvalidate(storePrivate->callbackPort); CFRelease(storePrivate->callbackPort); + storePrivate->callbackPort = NULL; return; } @@ -231,6 +238,16 @@ rlsCallback(CFMachPortRef port, void *msg, CFIndex size, void *info) } +static void +rlsPortInvalidate(CFMachPortRef mp, void *info) { + mach_port_t port = CFMachPortGetPort(mp); + + // A simple deallocate won't get rid of all the references we've accumulated + SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" invalidate = %d"), port); + mach_port_destroy(mach_task_self(), port); +} + + static void rlsSchedule(void *info, CFRunLoopRef rl, CFStringRef mode) { @@ -240,7 +257,12 @@ rlsSchedule(void *info, CFRunLoopRef rl, CFStringRef mode) SCLog(_sc_verbose, LOG_DEBUG, CFSTR("schedule notifications for mode %@"), mode); if (storePrivate->rlsRefs++ == 0) { - CFMachPortContext context = { 0, (void *)store, NULL, NULL, NULL }; + CFMachPortContext context = { 0 + , (void *)store + , CFRetain + , CFRelease + , NULL + }; mach_port_t oldNotify; mach_port_t port; int sc_status; @@ -296,6 +318,7 @@ rlsSchedule(void *info, CFRunLoopRef rl, CFStringRef mode) } storePrivate->callbackPort = CFMachPortCreateWithPort(NULL, port, rlsCallback, &context, NULL); + CFMachPortSetInvalidationCallBack(storePrivate->callbackPort, rlsPortInvalidate); storePrivate->callbackRunLoopSource = CFMachPortCreateRunLoopSource(NULL, storePrivate->callbackPort, 0); } @@ -313,6 +336,7 @@ rlsCancel(void *info, CFRunLoopRef rl, CFStringRef mode) SCLog(_sc_verbose, LOG_DEBUG, CFSTR("cancel notifications for mode %@"), mode); CFRunLoopRemoveSource(rl, storePrivate->callbackRunLoopSource, mode); + if (--storePrivate->rlsRefs == 0) { int sc_status; kern_return_t status; @@ -321,10 +345,12 @@ rlsCancel(void *info, CFRunLoopRef rl, CFStringRef mode) /* remove the run loop source */ CFRelease(storePrivate->callbackRunLoopSource); + storePrivate->callbackRunLoopSource = NULL; /* invalidate port */ CFMachPortInvalidate(storePrivate->callbackPort); CFRelease(storePrivate->callbackPort); + storePrivate->callbackPort = NULL; status = notifycancel(storePrivate->server, (int *)&sc_status); if (status != KERN_SUCCESS) { @@ -351,6 +377,11 @@ rlsPerform(void *info) SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" executing notifiction function")); changedKeys = SCDynamicStoreCopyNotifiedKeys(store); + if (!changedKeys) { + /* something happened to the server */ + return; + } + rlsFunction = storePrivate->rlsFunction; if (NULL != storePrivate->rlsContext.retain) { @@ -360,7 +391,7 @@ rlsPerform(void *info) context_info = storePrivate->rlsContext.info; context_release = NULL; } - (*rlsFunction)(store, changedKeys, storePrivate->rlsContext.info); + (*rlsFunction)(store, changedKeys, context_info); if (context_release) { context_release(context_info); } @@ -370,12 +401,45 @@ rlsPerform(void *info) } +static CFTypeRef +rlsRetain(CFTypeRef cf) +{ + SCDynamicStoreRef store = (SCDynamicStoreRef)cf; + SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store; + + if (storePrivate->notifyStatus != Using_NotifierInformViaRunLoop) { + /* mark RLS active */ + storePrivate->notifyStatus = Using_NotifierInformViaRunLoop; + /* keep a reference to the store */ + CFRetain(store); + } + + return cf; +} + +static void +rlsRelease(CFTypeRef cf) +{ + SCDynamicStoreRef store = (SCDynamicStoreRef)cf; + SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store; + + /* mark RLS inactive */ + storePrivate->notifyStatus = NotifierNotRegistered; + storePrivate->rls = NULL; + + /* release our reference to the store */ + CFRelease(store); + + return; +} + + CFRunLoopSourceRef SCDynamicStoreCreateRunLoopSource(CFAllocatorRef allocator, SCDynamicStoreRef store, CFIndex order) { - SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store; + SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store; SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreCreateRunLoopSource:")); @@ -394,8 +458,7 @@ SCDynamicStoreCreateRunLoopSource(CFAllocatorRef allocator, switch (storePrivate->notifyStatus) { case NotifierNotRegistered : case Using_NotifierInformViaRunLoop : - /* set notifier active */ - storePrivate->notifyStatus = Using_NotifierInformViaRunLoop; + /* OK to enable runloop notification */ break; default : /* sorry, you can only have one notification registered at once */ @@ -403,23 +466,28 @@ SCDynamicStoreCreateRunLoopSource(CFAllocatorRef allocator, return NULL; } - if (!storePrivate->rls) { - CFRunLoopSourceContext context; - - context.version = 0; - context.info = (void *)store; - context.retain = (const void *(*)(const void *))CFRetain; - context.release = (void (*)(const void *))CFRelease; - context.copyDescription = (CFStringRef (*)(const void *))CFCopyDescription; - context.equal = (Boolean (*)(const void *, const void *))CFEqual; - context.hash = (CFHashCode (*)(const void *))CFHash; - context.schedule = rlsSchedule; - context.cancel = rlsCancel; - context.perform = rlsPerform; + if (storePrivate->rls) { + CFRetain(storePrivate->rls); + } else { + CFRunLoopSourceContext context = { 0 // version + , (void *)store // info + , rlsRetain // retain + , rlsRelease // release + , CFCopyDescription // copyDescription + , CFEqual // equal + , CFHash // hash + , rlsSchedule // schedule + , rlsCancel // cancel + , rlsPerform // perform + }; storePrivate->rls = CFRunLoopSourceCreate(allocator, order, &context); } - return (CFRunLoopSourceRef)CFRetain(storePrivate->rls); -} + if (!storePrivate->rls) { + _SCErrorSet(kSCStatusFailed); + return NULL; + } + return storePrivate->rls; +} diff --git a/SystemConfiguration.fproj/SCDNotifierList.c b/SystemConfiguration.fproj/SCDNotifierList.c index 2e006d3..35fee92 100644 --- a/SystemConfiguration.fproj/SCDNotifierList.c +++ b/SystemConfiguration.fproj/SCDNotifierList.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -42,23 +42,21 @@ SCDynamicStoreCopyWatchedKeyList(SCDynamicStoreRef store, Boolean isRegex) { SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store; CFIndex keyCnt; - void **keyRefs; + CFSetRef keys; + const void **keyRefs; CFArrayRef watchedKeys = NULL; SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreCopyWatchedKeyList:")); - if (isRegex) { - keyCnt = CFSetGetCount(storePrivate->reKeys); + keys = isRegex ? storePrivate->reKeys : storePrivate->keys; + keyCnt = CFSetGetCount(keys); + if (keyCnt > 0) { keyRefs = CFAllocatorAllocate(NULL, keyCnt * sizeof(CFStringRef), 0); - CFSetGetValues(storePrivate->reKeys, keyRefs); + CFSetGetValues(keys, keyRefs); watchedKeys = CFArrayCreate(NULL, keyRefs, keyCnt, &kCFTypeArrayCallBacks); CFAllocatorDeallocate(NULL, keyRefs); } else { - keyCnt = CFSetGetCount(storePrivate->keys); - keyRefs = CFAllocatorAllocate(NULL, keyCnt * sizeof(CFStringRef), 0); - CFSetGetValues(storePrivate->keys, keyRefs); - watchedKeys = CFArrayCreate(NULL, keyRefs, keyCnt, &kCFTypeArrayCallBacks); - CFAllocatorDeallocate(NULL, keyRefs); + watchedKeys = CFArrayCreate(NULL, NULL, 0, &kCFTypeArrayCallBacks); } return watchedKeys; diff --git a/SystemConfiguration.fproj/SCDNotifierRemove.c b/SystemConfiguration.fproj/SCDNotifierRemove.c index 7cc92a9..8a56811 100644 --- a/SystemConfiguration.fproj/SCDNotifierRemove.c +++ b/SystemConfiguration.fproj/SCDNotifierRemove.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -85,9 +85,10 @@ SCDynamicStoreRemoveWatchedKey(SCDynamicStoreRef store, CFStringRef key, Boolean } /* serialize the key */ - xmlKey = CFPropertyListCreateXMLData(NULL, key); - myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey); - myKeyLen = CFDataGetLength(xmlKey); + if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) { + _SCErrorSet(kSCStatusFailed); + return FALSE; + } /* send the key to the server */ status = notifyremove(storePrivate->server, diff --git a/SystemConfiguration.fproj/SCDNotify.c b/SystemConfiguration.fproj/SCDNotify.c index e16481c..f634973 100644 --- a/SystemConfiguration.fproj/SCDNotify.c +++ b/SystemConfiguration.fproj/SCDNotify.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -61,10 +61,11 @@ SCDynamicStoreNotifyValue(SCDynamicStoreRef store, return FALSE; } - /* serialize the key */ - xmlKey = CFPropertyListCreateXMLData(NULL, key); - myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey); - myKeyLen = CFDataGetLength(xmlKey); + /* serialize the key */ + if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) { + _SCErrorSet(kSCStatusFailed); + return FALSE; + } /* send the key to the server */ status = confignotify(storePrivate->server, diff --git a/SystemConfiguration.fproj/SCDOpen.c b/SystemConfiguration.fproj/SCDOpen.c index ce71d42..d78ac73 100644 --- a/SystemConfiguration.fproj/SCDOpen.c +++ b/SystemConfiguration.fproj/SCDOpen.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -30,6 +30,7 @@ * - initial revision */ +#include #include #include #include @@ -67,8 +68,9 @@ __SCDynamicStoreDeallocate(CFTypeRef cf) (void) pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldThreadState); /* Remove notification keys */ - if ((keyCnt = CFSetGetCount(storePrivate->keys)) > 0) { - void **watchedKeys; + keyCnt = CFSetGetCount(storePrivate->keys); + if (keyCnt > 0) { + const void **watchedKeys; CFArrayRef keysToRemove; CFIndex i; @@ -85,8 +87,9 @@ __SCDynamicStoreDeallocate(CFTypeRef cf) } /* Remove regex notification keys */ - if ((keyCnt = CFSetGetCount(storePrivate->reKeys)) > 0) { - void **watchedKeys; + keyCnt = CFSetGetCount(storePrivate->reKeys); + if (keyCnt > 0) { + const void **watchedKeys; CFArrayRef keysToRemove; CFIndex i; @@ -141,10 +144,10 @@ static CFTypeID __kSCDynamicStoreTypeID = _kCFRuntimeNotATypeID; static const CFRuntimeClass __SCDynamicStoreClass = { 0, // version - "SCDynamicStore", // className + "SCDynamicStore", // className NULL, // init NULL, // copy - __SCDynamicStoreDeallocate, // dealloc + __SCDynamicStoreDeallocate, // dealloc NULL, // equal NULL, // hash NULL, // copyFormattingDesc @@ -246,6 +249,7 @@ SCDynamicStoreCreate(CFAllocatorRef allocator, kern_return_t status; mach_port_t bootstrap_port; mach_port_t server; + char *server_name; CFDataRef xmlName; /* serialized name */ xmlData_t myNameRef; CFIndex myNameLen; @@ -268,7 +272,12 @@ SCDynamicStoreCreate(CFAllocatorRef allocator, return NULL; } - status = bootstrap_look_up(bootstrap_port, SCD_SERVER, &server); + server_name = getenv("SCD_SERVER"); + if (!server_name) { + server_name = SCD_SERVER; + } + + status = bootstrap_look_up(bootstrap_port, server_name, &server); switch (status) { case BOOTSTRAP_SUCCESS : /* service currently registered, "a good thing" (tm) */ @@ -289,9 +298,10 @@ SCDynamicStoreCreate(CFAllocatorRef allocator, } /* serialize the name */ - xmlName = CFPropertyListCreateXMLData(NULL, name); - myNameRef = (xmlData_t)CFDataGetBytePtr(xmlName); - myNameLen = CFDataGetLength(xmlName); + if (!_SCSerialize(name, &xmlName, (void **)&myNameRef, &myNameLen)) { + _SCErrorSet(kSCStatusFailed); + return NULL; + } /* open a new session with the server */ status = configopen(server, myNameRef, myNameLen, &storePrivate->server, (int *)&sc_status); diff --git a/SystemConfiguration.fproj/SCDPlugin.c b/SystemConfiguration.fproj/SCDPlugin.c new file mode 100644 index 0000000..419e35b --- /dev/null +++ b/SystemConfiguration.fproj/SCDPlugin.c @@ -0,0 +1,343 @@ +/* + * Copyright (c) 2001 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This 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 OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * Modification History + * + * October 12, 2001 Allan Nathanson + * - initial revision + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + + +typedef struct childInfo *childInfoRef; + +struct childInfo { + pid_t pid; + SCDPluginExecCallBack callout; + void *context; + int status; + struct rusage rusage; + childInfoRef next; +}; + + +/* + * Mach port used to notify runloop when a child process + * has been reaped. + */ +static CFMachPortRef childReaped = NULL; + +/* + * The following dictionaries contain information about child + * processes, reaped processes, and any associated callback + * information. + * + * Important: Access to these dictionaries should only be + * made when in a SIGCHLD handler (or when the + * childLock mutex is held *AND* the signal + * has been blocked). + */ +static childInfoRef activeChildren = NULL; +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; + + +static inline void +blockSignal() +{ + sigset_t mask = sigmask(SIGCHLD); + + // block SIGCHLD + if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1) { + perror("sigprocmask(SIG_BLOCK)"); + } + + return; +} + + +static inline void +unblockSignal() +{ + sigset_t mask = sigmask(SIGCHLD); + + // unblock SIGCHLD + if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1) { + perror("sigprocmask(SIG_UNBLOCK)"); + } + + return; +} + + +static void +reaper(int sigraised) +{ + mach_msg_empty_send_t msg; + mach_msg_option_t options; + kern_return_t status; + + /* + * block additional SIGCHLD's until current children have + * been reaped. + */ + blockSignal(); + + /* + * send message to indicate that at least one child is ready + * to be reaped. + */ + msg.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0); + msg.header.msgh_size = sizeof(msg); + msg.header.msgh_remote_port = CFMachPortGetPort(childReaped); + msg.header.msgh_local_port = MACH_PORT_NULL; + msg.header.msgh_id = 0; + options = MACH_SEND_TIMEOUT; + status = mach_msg(&msg.header, /* msg */ + MACH_SEND_MSG|options, /* options */ + msg.header.msgh_size, /* send_size */ + 0, /* rcv_size */ + MACH_PORT_NULL, /* rcv_name */ + 0, /* timeout */ + MACH_PORT_NULL); /* notify */ + + return; +} + + +static void +childrenReaped(CFMachPortRef port, void *msg, CFIndex size, void *info) +{ + pid_t pid = 0; + childInfoRef reapedChildren = NULL; + + do { + struct rusage rusage; + int status; + + pid = wait4(-1, &status, WNOHANG, &rusage); + switch (pid) { + case -1 : // if error + if (errno != ECHILD) { + perror("wait4"); + } + break; + + case 0 : // if no more children + break; + + default : { + childInfoRef last; + childInfoRef this; + + // grab the activeChildren mutex + pthread_mutex_lock(&lock); + + last = NULL; + this = activeChildren; + while (this) { + if (this->pid == pid) { + /* save exit status & usage */ + this->status = status; + this->rusage = rusage; + + /* remove from activeChildren */ + if (last) { + last->next = this->next; + } else { + activeChildren = this->next; + } + + /* add to reapedChildren */ + this->next = reapedChildren; + reapedChildren = this; + + break; + } else { + /* if not this child */ + last = this; + this = this->next; + } + } + + // release the activeChildren mutex + pthread_mutex_unlock(&lock); + + break; + } + } + } while (pid > 0); + + /* + * we need to know about any new children waiting to be reaped so + * re-enable the SIGCHLD handler. + + */ + unblockSignal(); + + while (reapedChildren) { + childInfoRef child = reapedChildren; + + reapedChildren = reapedChildren->next; + (*child->callout)(child->pid, + child->status, + &child->rusage, + child->context); + CFAllocatorDeallocate(NULL, child); + } + + return; +} + + +void +_SCDPluginExecInit() +{ + struct sigaction act; + CFRunLoopSourceRef rls; + + // create the "a child has been reaped" notification port + childReaped = CFMachPortCreate(NULL, childrenReaped, NULL, NULL); + + // set queue limit + { + mach_port_limits_t limits; + kern_return_t status; + + limits.mpl_qlimit = 1; + status = mach_port_set_attributes(mach_task_self(), + CFMachPortGetPort(childReaped), + MACH_PORT_LIMITS_INFO, + (mach_port_info_t)&limits, + MACH_PORT_LIMITS_INFO_COUNT); + if (status != KERN_SUCCESS) { + perror("mach_port_set_attributes"); + } + } + + // add to our runloop + rls = CFMachPortCreateRunLoopSource(NULL, childReaped, 0); + CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode); + CFRelease(rls); + + // enable signal handler + act.sa_handler = reaper; + sigemptyset(&act.sa_mask); + act.sa_flags = SA_RESTART|SA_NOCLDSTOP; + if (sigaction(SIGCHLD, &act, NULL) == -1) { + perror("sigaction"); + } + + return; +} + + +pid_t +_SCDPluginExecCommand(SCDPluginExecCallBack callout, + void *context, + uid_t uid, + gid_t gid, + const char *path, + char * const argv[]) +{ + pid_t pid; + + // grab the activeChildren mutex + pthread_mutex_lock(&lock); + + pid = fork(); + switch (pid) { + case -1 : { /* if error */ + + int status; + + status = errno; + printf("fork() failed: %s", strerror(status)); + errno = status; + break; + } + + case 0 : { /* if child */ + + uid_t curUID = geteuid(); + gid_t curGID = getegid(); + int i; + int status; + + if (curUID != uid) { + (void) setuid(uid); + } + + if (curGID != gid) { + (void) setgid(gid); + } + + /* close any open FDs */ + for (i = getdtablesize()-1; i>=0; i--) close(i); + open("/dev/null", O_RDWR, 0); + dup(0); + dup(0); + + /* execute requested command */ + (void) execv(path, argv); + + /* if the execv failed */ + status = W_EXITCODE(errno, 0); + _exit (WEXITSTATUS(status)); + } + + default : { /* if parent */ + + if (callout) { + childInfoRef child; + + // create child process info + child = CFAllocatorAllocate(NULL, sizeof(struct childInfo), 0); + bzero(child, sizeof(struct childInfo)); + child->pid = pid; + child->callout = callout; + child->context = context; + + // add the new child to the activeChildren list + child->next = activeChildren; + activeChildren = child; + } + break; + } + } + + // release the activeChildren mutex + pthread_mutex_unlock(&lock); + + return pid; +} diff --git a/SystemConfiguration.fproj/SCDPlugin.h b/SystemConfiguration.fproj/SCDPlugin.h index e0cf531..9933eb9 100644 --- a/SystemConfiguration.fproj/SCDPlugin.h +++ b/SystemConfiguration.fproj/SCDPlugin.h @@ -24,6 +24,9 @@ #define _SCDPLUGIN_H #include +#include +#include +#include #include @@ -82,8 +85,49 @@ typedef void (*SCDynamicStoreBundleStartFunction) (const char *bundleName, typedef void (*SCDynamicStoreBundlePrimeFunction) (); +/*! + @typedef SCDPluginExecCallBack + @discussion Type of the callback function used when a child process + started by a plug-in has exited. + @param pid The process id of the child which has exited. + @param status The exit status of the child which has exited. + @param rusage A summary of the resources used by the child process + and all its children. + @param context The callback argument specified on the call + to _SCDPluginExecCommand(). + */ +typedef void (*SCDPluginExecCallBack) (pid_t pid, + int status, + struct rusage *rusage, + void *context); + + __BEGIN_DECLS +/*! + @function _SCDPluginExecCommand + @discussion Starts a child process. + @param callout The function to be called when the child + process exits. A NULL value can be specified if no + callouts are desired. + @param context A argument which will be passed + to the callout function. + @param uid The desired user id of the child process. + @param gid The desired group id of the child process. + @param path The command to be executed. + @param argv The arguments to be passed to the child process. + @result The process ID of the child. + */ +pid_t +_SCDPluginExecCommand ( + SCDPluginExecCallBack callout, + void *context, + uid_t uid, + gid_t gid, + const char *path, + char * const argv[] + ); + __END_DECLS #endif /* _SCDPLUGIN_H */ diff --git a/SystemConfiguration.fproj/SCDPrivate.c b/SystemConfiguration.fproj/SCDPrivate.c index 8e0b6ba..9ce2fd2 100644 --- a/SystemConfiguration.fproj/SCDPrivate.c +++ b/SystemConfiguration.fproj/SCDPrivate.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -38,6 +38,106 @@ #include #include +Boolean +_SCSerialize(CFPropertyListRef obj, + CFDataRef *xml, + void **dataRef, + CFIndex *dataLen) +{ + CFDataRef myXml; + + if (!obj) { + /* if no object to serialize */ + return FALSE; + } + + if (!xml && !(dataRef && dataLen)) { + /* if not keeping track of allocated space */ + return FALSE; + } + + myXml = CFPropertyListCreateXMLData(NULL, obj); + if (!myXml) { + SCLog(TRUE, LOG_ERR, CFSTR("CFPropertyListCreateXMLData() failed")); + if (xml) *xml = NULL; + if (dataRef) *dataRef = NULL; + if (dataLen) *dataLen = 0; + return FALSE; + } + + if (xml) { + *xml = myXml; + if (dataRef) { + *dataRef = (void *)CFDataGetBytePtr(myXml); + } + if (dataLen) { + *dataLen = CFDataGetLength(myXml); + } + } else { + kern_return_t status; + + *dataLen = CFDataGetLength(myXml); + status = vm_allocate(mach_task_self(), (void *)dataRef, *dataLen, TRUE); + if (status != KERN_SUCCESS) { + SCLog(TRUE, + LOG_ERR, + CFSTR("vm_allocate(): %s"), + mach_error_string(status)); + CFRelease(myXml); + *dataRef = NULL; + *dataLen = 0; + return FALSE; + } + + bcopy((char *)CFDataGetBytePtr(myXml), *dataRef, *dataLen); + CFRelease(myXml); + } + + return TRUE; +} + + +Boolean +_SCUnserialize(CFPropertyListRef *obj, + void *dataRef, + CFIndex dataLen) +{ + kern_return_t status; + CFDataRef xml; + CFStringRef xmlError; + + if (!obj) { + return FALSE; + } + + xml = CFDataCreate(NULL, (void *)dataRef, dataLen); + status = vm_deallocate(mach_task_self(), (vm_address_t)dataRef, dataLen); + if (status != KERN_SUCCESS) { + SCLog(_sc_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); + /* non-fatal???, proceed */ + } + *obj = CFPropertyListCreateFromXMLData(NULL, + xml, + kCFPropertyListImmutable, + &xmlError); + CFRelease(xml); + + if (!obj) { + if (xmlError) { + SCLog(TRUE, + LOG_ERR, + CFSTR("CFPropertyListCreateFromXMLData() failed: %@"), + xmlError); + CFRelease(xmlError); + } + _SCErrorSet(kSCStatusFailed); + return FALSE; + } + + return TRUE; +} + + void __showMachPortStatus() { diff --git a/SystemConfiguration.fproj/SCDRemove.c b/SystemConfiguration.fproj/SCDRemove.c index 0f08ccc..1051fee 100644 --- a/SystemConfiguration.fproj/SCDRemove.c +++ b/SystemConfiguration.fproj/SCDRemove.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -64,9 +64,10 @@ SCDynamicStoreRemoveValue(SCDynamicStoreRef store, CFStringRef key) } /* serialize the key */ - xmlKey = CFPropertyListCreateXMLData(NULL, key); - myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey); - myKeyLen = CFDataGetLength(xmlKey); + if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) { + _SCErrorSet(kSCStatusFailed); + return FALSE; + } /* send the key to the server */ status = configremove(storePrivate->server, diff --git a/SystemConfiguration.fproj/SCDSet.c b/SystemConfiguration.fproj/SCDSet.c index da4fd4c..01efa6c 100644 --- a/SystemConfiguration.fproj/SCDSet.c +++ b/SystemConfiguration.fproj/SCDSet.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -75,23 +75,29 @@ SCDynamicStoreSetMultiple(SCDynamicStoreRef store, /* serialize the key/value pairs to set*/ if (keysToSet) { - xmlSet = CFPropertyListCreateXMLData(NULL, keysToSet); - mySetRef = (xmlData_t)CFDataGetBytePtr(xmlSet); - mySetLen = CFDataGetLength(xmlSet); + if (!_SCSerialize(keysToSet, &xmlSet, (void **)&mySetRef, &mySetLen)) { + _SCErrorSet(kSCStatusFailed); + return NULL; + } } /* serialize the keys to remove */ if (keysToRemove) { - xmlRemove = CFPropertyListCreateXMLData(NULL, keysToRemove); - myRemoveRef = (xmlData_t)CFDataGetBytePtr(xmlRemove); - myRemoveLen = CFDataGetLength(xmlRemove); + if (!_SCSerialize(keysToRemove, &xmlRemove, (void **)&myRemoveRef, &myRemoveLen)) { + if (xmlSet) CFRelease(xmlSet); + _SCErrorSet(kSCStatusFailed); + return NULL; + } } /* serialize the keys to notify */ if (keysToNotify) { - xmlNotify = CFPropertyListCreateXMLData(NULL, keysToNotify); - myNotifyRef = (xmlData_t)CFDataGetBytePtr(xmlNotify); - myNotifyLen = CFDataGetLength(xmlNotify); + if (!_SCSerialize(keysToNotify, &xmlNotify, (void **)&myNotifyRef, &myNotifyLen)) { + if (xmlSet) CFRelease(xmlSet); + if (xmlRemove) CFRelease(xmlRemove); + _SCErrorSet(kSCStatusFailed); + return NULL; + } } /* send the keys and patterns, fetch the associated result from the server */ @@ -156,14 +162,18 @@ SCDynamicStoreSetValue(SCDynamicStoreRef store, CFStringRef key, CFPropertyListR return FALSE; } - /* serialize the key and data */ - xmlKey = CFPropertyListCreateXMLData(NULL, key); - myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey); - myKeyLen = CFDataGetLength(xmlKey); + /* serialize the key */ + if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) { + _SCErrorSet(kSCStatusFailed); + return NULL; + } - xmlData = CFPropertyListCreateXMLData(NULL, value); - myDataRef = (xmlData_t)CFDataGetBytePtr(xmlData); - myDataLen = CFDataGetLength(xmlData); + /* serialize the data */ + if (!_SCSerialize(value, &xmlData, (void **)&myDataRef, &myDataLen)) { + CFRelease(xmlKey); + _SCErrorSet(kSCStatusFailed); + return NULL; + } /* send the key & data to the server, get new instance id */ status = configset(storePrivate->server, diff --git a/SystemConfiguration.fproj/SCDTouch.c b/SystemConfiguration.fproj/SCDTouch.c index ac3d6c4..24b1e75 100644 --- a/SystemConfiguration.fproj/SCDTouch.c +++ b/SystemConfiguration.fproj/SCDTouch.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -64,9 +64,10 @@ SCDynamicStoreTouchValue(SCDynamicStoreRef store, CFStringRef key) } /* serialize the key */ - xmlKey = CFPropertyListCreateXMLData(NULL, key); - myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey); - myKeyLen = CFDataGetLength(xmlKey); + if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) { + _SCErrorSet(kSCStatusFailed); + return FALSE; + } /* send the key to the server */ status = configtouch(storePrivate->server, diff --git a/SystemConfiguration.fproj/SCDynamicStoreCopyDHCPInfo.h b/SystemConfiguration.fproj/SCDynamicStoreCopyDHCPInfo.h index fa34138..d40ceb3 100644 --- a/SystemConfiguration.fproj/SCDynamicStoreCopyDHCPInfo.h +++ b/SystemConfiguration.fproj/SCDynamicStoreCopyDHCPInfo.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2001-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -67,7 +67,7 @@ SCDynamicStoreCopyDHCPInfo(SCDynamicStoreRef store, CFStringRef serviceID); data for. @result A non-NULL CFDataRef containing the option data, NULL otherwise. - + The return value must NOT be released. */ CFDataRef diff --git a/SystemConfiguration.fproj/SCDynamicStoreCopySpecific.h b/SystemConfiguration.fproj/SCDynamicStoreCopySpecific.h index 89ab3bf..7c63f27 100644 --- a/SystemConfiguration.fproj/SCDynamicStoreCopySpecific.h +++ b/SystemConfiguration.fproj/SCDynamicStoreCopySpecific.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -80,6 +80,40 @@ SCDynamicStoreCopyConsoleUser ( gid_t *gid ); +/*! + @function SCDynamicStoreCopyLocalHostName + @discussion Gets the current local host name. + + See SCDynamicStoreKeyCreateHostNames() for notification + key information. + @param store An SCDynamicStoreRef that should be used for communication + with the server. + If NULL, a temporary session will be used. + @result The current local host name; + NULL if the name has not been set or if an error was encountered. + You must release the returned value. + */ +CFStringRef +SCDynamicStoreCopyLocalHostName ( + SCDynamicStoreRef store + ); + +/*! + @function SCDynamicStoreCopyLocation + @discussion Gets the current "location" identifier. + @param store An SCDynamicStoreRef that should be used for communication + with the server. + If NULL, a temporary session will be used. + @result A string representing the current "location" identifier; + NULL if no "location" identifier has been defined or if an error + was encountered. + You must release the returned value. + */ +CFStringRef +SCDynamicStoreCopyLocation ( + SCDynamicStoreRef store + ); + /*! @function SCDynamicStoreCopyProxies @discussion Gets the current internet proxy settings. diff --git a/SystemConfiguration.fproj/SCDynamicStoreKey.h b/SystemConfiguration.fproj/SCDynamicStoreKey.h index aa76284..f1cb7f6 100644 --- a/SystemConfiguration.fproj/SCDynamicStoreKey.h +++ b/SystemConfiguration.fproj/SCDynamicStoreKey.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -115,6 +115,31 @@ SCDynamicStoreKeyCreateConsoleUser ( CFAllocatorRef allocator ); +/*! + @function SCDynamicStoreKeyCreateHostNames + @discussion Creates a key that can be used in conjunction with + SCDynamicStoreSetNotificationKeys() to receive + notifications when the HostNames entity changes. The + HostNames entity contains the LocalHostName. + @result A notification string for the HostNames entity. +*/ +CFStringRef +SCDynamicStoreKeyCreateHostNames ( + CFAllocatorRef allocator + ); + +/*! + @function SCDynamicStoreKeyCreateLocation + @discussion Creates a key that can be used in conjunction with + SCDynamicStoreSetNotificationKeys() to receive + notifications when the "location" identifier changes. + @result A notification string for the current "location" identifier. +*/ +CFStringRef +SCDynamicStoreKeyCreateLocation ( + CFAllocatorRef allocator + ); + /*! @function SCDynamicStoreKeyCreateProxies @discussion Creates a key that can be used by the SCDynamicStoreSetNotificationKeys() diff --git a/SystemConfiguration.fproj/SCLocation.c b/SystemConfiguration.fproj/SCLocation.c new file mode 100644 index 0000000..90ec0ac --- /dev/null +++ b/SystemConfiguration.fproj/SCLocation.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2001 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This 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 OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * Modification History + * + * Nov 28, 2001 Allan Nathanson + * - initial revision + */ + +#include +#include +#include + +CFStringRef +SCDynamicStoreKeyCreateLocation(CFAllocatorRef allocator) +{ + return CFRetain(kSCDynamicStoreDomainSetup); +} + + +CFStringRef +SCDynamicStoreCopyLocation(SCDynamicStoreRef store) +{ + CFDictionaryRef dict = NULL; + CFStringRef key; + CFStringRef location = NULL; + Boolean tempSession = FALSE; + + if (!store) { + store = SCDynamicStoreCreate(NULL, + CFSTR("SCDynamicStoreCopyLocation"), + NULL, + NULL); + if (!store) { + SCLog(_sc_verbose, LOG_INFO, CFSTR("SCDynamicStoreCreate() failed")); + return NULL; + } + tempSession = TRUE; + } + + key = SCDynamicStoreKeyCreateLocation(NULL); + dict = SCDynamicStoreCopyValue(store, key); + CFRelease(key); + if (!isA_CFDictionary(dict)) { + _SCErrorSet(kSCStatusNoKey); + goto done; + } + + location = CFDictionaryGetValue(dict, kSCDynamicStorePropSetupCurrentSet); + if (!isA_CFString(location)) { + _SCErrorSet(kSCStatusNoKey); + goto done; + } + + CFRetain(location); + + done : + + if (tempSession) CFRelease(store); + if (dict) CFRelease(dict); + + return location; +} diff --git a/SystemConfiguration.fproj/SCNetwork.c b/SystemConfiguration.fproj/SCNetwork.c index b413ec8..0d35172 100644 --- a/SystemConfiguration.fproj/SCNetwork.c +++ b/SystemConfiguration.fproj/SCNetwork.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -817,6 +817,9 @@ checkAddress(SCDynamicStoreRef store, case PPP_RUNNING : /* if we're really UP and RUNNING */ break; + case PPP_ONHOLD : + /* if we're effectively UP and RUNNING */ + break; case PPP_IDLE : /* if we're not connected at all */ SCLog(_sc_debug, LOG_INFO, CFSTR(" PPP link idle, dial-on-traffic to connect")); @@ -1160,8 +1163,10 @@ SCNetworkCheckReachabilityByName(const char *nodename, Boolean haveDNS = FALSE; int i; Boolean ok = TRUE; +#ifdef CHECK_IPV6_REACHABILITY struct addrinfo *res = NULL; struct addrinfo *resP; +#endif /* CHECK_IPV6_REACHABILITY */ CFArrayRef serviceOrder = NULL; SCDynamicStoreRef store = NULL; @@ -1235,6 +1240,8 @@ SCNetworkCheckReachabilityByName(const char *nodename, /* * resolve the nodename into an address */ + +#ifdef CHECK_IPV6_REACHABILITY i = getaddrinfo(nodename, NULL, NULL, &res); if (i != 0) { SCLog(_sc_verbose, LOG_ERR, @@ -1297,6 +1304,7 @@ SCNetworkCheckReachabilityByName(const char *nodename, LOG_INFO, CFSTR("getaddrinfo() returned no addresses, try gethostbyname()")); #endif /* DEBUG */ +#endif /* CHECK_IPV6_REACHABILITY */ h = gethostbyname(nodename); if (h && h->h_length) { @@ -1403,7 +1411,9 @@ SCNetworkCheckReachabilityByName(const char *nodename, _CheckReachabilityFree(config, active, serviceOrder, defaultRoute); if (store) CFRelease(store); +#ifdef CHECK_IPV6_REACHABILITY if (res) freeaddrinfo(res); +#endif /* CHECK_IPV6_REACHABILITY */ return ok; } diff --git a/SystemConfiguration.fproj/SCPList.c b/SystemConfiguration.fproj/SCPList.c index d66ed6e..e0306d9 100644 --- a/SystemConfiguration.fproj/SCPList.c +++ b/SystemConfiguration.fproj/SCPList.c @@ -1,5 +1,5 @@ /* - * Copyright(c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright(c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -41,15 +41,19 @@ SCPreferencesCopyKeyList(SCPreferencesRef session) CFArrayRef keys; SCPreferencesPrivateRef sessionPrivate = (SCPreferencesPrivateRef)session; CFIndex prefsCnt; - void **prefsKeys; + const void **prefsKeys; SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCPreferencesCopyKeyList:")); prefsCnt = CFDictionaryGetCount(sessionPrivate->prefs); - prefsKeys = CFAllocatorAllocate(allocator, prefsCnt * sizeof(CFStringRef), 0); - CFDictionaryGetKeysAndValues(sessionPrivate->prefs, prefsKeys, NULL); - keys = CFArrayCreate(allocator, prefsKeys, prefsCnt, &kCFTypeArrayCallBacks); - CFAllocatorDeallocate(allocator, prefsKeys); + if (prefsCnt > 0) { + prefsKeys = CFAllocatorAllocate(allocator, prefsCnt * sizeof(CFStringRef), 0); + CFDictionaryGetKeysAndValues(sessionPrivate->prefs, prefsKeys, NULL); + keys = CFArrayCreate(allocator, prefsKeys, prefsCnt, &kCFTypeArrayCallBacks); + CFAllocatorDeallocate(allocator, prefsKeys); + } else { + keys = CFArrayCreate(allocator, NULL, 0, &kCFTypeArrayCallBacks); + } SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" keys = %@"), keys); diff --git a/SystemConfiguration.fproj/SCPLock.c b/SystemConfiguration.fproj/SCPLock.c index a153f33..c96d016 100644 --- a/SystemConfiguration.fproj/SCPLock.c +++ b/SystemConfiguration.fproj/SCPLock.c @@ -1,5 +1,5 @@ /* - * Copyright(c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright(c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -197,7 +197,8 @@ SCPreferencesLock(SCPreferencesRef session, Boolean wait) /* synchronize this sessions prefs/signature */ newPrivate = (SCPreferencesPrivateRef)newPrefs; CFRelease(sessionPrivate->prefs); - sessionPrivate->prefs = CFRetain(newPrivate->prefs); + sessionPrivate->prefs = newPrivate->prefs; + CFRetain(sessionPrivate->prefs); CFRelease(sessionPrivate->signature); sessionPrivate->signature = CFRetain(newPrivate->signature); CFRelease(newPrefs); diff --git a/SystemConfiguration.fproj/SCPOpen.c b/SystemConfiguration.fproj/SCPOpen.c index 6a13925..b24a006 100644 --- a/SystemConfiguration.fproj/SCPOpen.c +++ b/SystemConfiguration.fproj/SCPOpen.c @@ -1,5 +1,5 @@ /* - * Copyright(c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright(c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -32,6 +32,7 @@ #include #include +#include #include "SCPreferencesInternal.h" #include @@ -208,6 +209,8 @@ __SCPreferencesCreate(CFAllocatorRef allocator, prefsPrivate->signature = __SCPSignatureFromStatbuf(&statBuf); if (statBuf.st_size > 0) { + CFDictionaryRef dict; + /* * extract property list */ @@ -224,18 +227,17 @@ __SCPreferencesCreate(CFAllocatorRef allocator, /* * load preferences */ - prefsPrivate->prefs = (CFMutableDictionaryRef) - CFPropertyListCreateFromXMLData(NULL, - xmlData, - kCFPropertyListMutableContainers, - &xmlError); + dict = CFPropertyListCreateFromXMLData(NULL, + xmlData, + kCFPropertyListImmutable, + &xmlError); CFRelease(xmlData); - if (!prefsPrivate->prefs) { + if (!dict) { /* corrupt prefs file, start fresh */ if (xmlError) { - SCLog(_sc_verbose, LOG_DEBUG, - CFSTR("_SCPOpen CFPropertyListCreateFromXMLData(): %@"), - xmlError); + SCLog(TRUE, LOG_ERR, + CFSTR("_SCPOpen CFPropertyListCreateFromXMLData(): %@"), + xmlError); CFRelease(xmlError); } goto create_2; @@ -244,13 +246,15 @@ __SCPreferencesCreate(CFAllocatorRef allocator, /* * make sure that we've got a dictionary */ - if (CFGetTypeID(prefsPrivate->prefs) != CFDictionaryGetTypeID()) { + if (!isA_CFDictionary(dict)) { /* corrupt prefs file, start fresh */ SCLog(_sc_verbose, LOG_DEBUG, CFSTR("_SCPOpen CFGetTypeID(): not a dictionary.")); - CFRelease(prefsPrivate->prefs); - prefsPrivate->prefs = NULL; + CFRelease(dict); goto create_2; } + + prefsPrivate->prefs = CFDictionaryCreateMutableCopy(NULL, 0, dict); + CFRelease(dict); } create_2 : diff --git a/SystemConfiguration.fproj/SCPPath.c b/SystemConfiguration.fproj/SCPPath.c index ea2c3f4..40b351f 100644 --- a/SystemConfiguration.fproj/SCPPath.c +++ b/SystemConfiguration.fproj/SCPPath.c @@ -1,5 +1,5 @@ /* - * Copyright(c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright(c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -31,7 +31,11 @@ */ #include +#include #include +#include "SCPreferencesInternal.h" + +#define MAXLINKS 8 static CFArrayRef normalizePath(CFStringRef path) @@ -71,59 +75,217 @@ normalizePath(CFStringRef path) } -static int -getPath(SCPreferencesRef session, CFStringRef path, CFMutableDictionaryRef *entity) +static Boolean +getPath(SCPreferencesRef session, CFStringRef path, CFDictionaryRef *entity) { + CFStringRef element; CFArrayRef elements; CFIndex i; + CFStringRef link; CFIndex nElements; - int status = kSCStatusFailed; - CFMutableDictionaryRef value = NULL; + CFIndex nLinks = 0; + Boolean ok = FALSE; + SCPreferencesPrivateRef sessionPrivate = (SCPreferencesPrivateRef)session; + CFDictionaryRef value = NULL; elements = normalizePath(path); if (elements == NULL) { - return kSCStatusNoKey; - } - - /* get preferences key */ - value = (CFMutableDictionaryRef)SCPreferencesGetValue(session, - CFArrayGetValueAtIndex(elements, 0)); - if (!value) { - status = kSCStatusNoKey; - goto done; + _SCErrorSet(kSCStatusNoKey); + return FALSE; } - if (CFGetTypeID(value) != CFDictionaryGetTypeID()) { - status = kSCStatusNoKey; - goto done; - } + restart : nElements = CFArrayGetCount(elements); - for (i=1; iaccessed = TRUE; + value = CFDictionaryGetValue(sessionPrivate->prefs, + CFArrayGetValueAtIndex(elements, 0)); + } else { + value = CFDictionaryGetValue(value, element); + } if (value == NULL) { - /* if (parent) path component does not exist */ - status = kSCStatusNoKey; + /* if path component does not exist */ + _SCErrorSet(kSCStatusNoKey); goto done; } - if (CFGetTypeID(value) != CFDictionaryGetTypeID()) { - status = kSCStatusNoKey; + if (!isA_CFDictionary(value)) { + /* if path component not a dictionary */ + _SCErrorSet(kSCStatusNoKey); goto done; } + if ((i < nElements-1) && + CFDictionaryGetValueIfPresent(value, kSCResvLink, (const void **)&link)) { + /* + * if not the last path component and this + * element is a link + */ + CFArrayRef linkElements; + CFMutableArrayRef newElements; + + if (++nLinks > MAXLINKS) { + /* if we are chasing our tail */ + _SCErrorSet(kSCStatusMaxLink); + goto done; + } + + linkElements = normalizePath(link); + if (linkElements == NULL) { + /* if the link is bad */ + _SCErrorSet(kSCStatusNoKey); + goto done; + } + + newElements = CFArrayCreateMutableCopy(NULL, 0, linkElements); + CFArrayAppendArray(newElements, + elements, + CFRangeMake(i+1, nElements-i-1)); + CFRelease(elements); + elements = newElements; + + goto restart; + } } *entity = value; - status = kSCStatusOK; + ok = TRUE; done : CFRelease(elements); - return status; + return ok; +} + + +static Boolean +setPath(SCPreferencesRef session, CFStringRef path, CFDictionaryRef entity) +{ + CFStringRef element; + CFArrayRef elements; + CFIndex i; + CFStringRef link; + CFIndex nElements; + CFIndex nLinks = 0; + CFDictionaryRef newEntity = NULL; + CFDictionaryRef node = NULL; + CFMutableArrayRef nodes; + Boolean ok = FALSE; + SCPreferencesPrivateRef sessionPrivate = (SCPreferencesPrivateRef)session; + + elements = normalizePath(path); + if (elements == NULL) { + _SCErrorSet(kSCStatusNoKey); + return FALSE; + } + + restart : + + nElements = CFArrayGetCount(elements); + nodes = CFArrayCreateMutable(NULL, nElements-1, &kCFTypeArrayCallBacks); + for (i=0; iaccessed = TRUE; + node = CFDictionaryGetValue(sessionPrivate->prefs, element); + } else { + node = CFDictionaryGetValue(node, element); + + } + + if (node) { + /* if path component exists */ + CFArrayAppendValue(nodes, node); + } else { + /* if path component does not exist */ + node = CFDictionaryCreate(NULL, + NULL, + NULL, + 0, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + CFArrayAppendValue(nodes, node); + CFRelease(node); + } + + if (!isA_CFDictionary(node)) { + _SCErrorSet(kSCStatusNoKey); + goto done; + } + + if ((i < nElements-1) && + CFDictionaryGetValueIfPresent(node, kSCResvLink, (const void **)&link)) { + /* + * if not the last path component and this + * element is a link + */ + CFArrayRef linkElements; + CFMutableArrayRef newElements; + + if (++nLinks > MAXLINKS) { + /* if we are chasing our tail */ + _SCErrorSet(kSCStatusMaxLink); + goto done; + } + + linkElements = normalizePath(link); + if (linkElements == NULL) { + /* if the link is bad */ + _SCErrorSet(kSCStatusNoKey); + goto done; + } + + newElements = CFArrayCreateMutableCopy(NULL, 0, linkElements); + CFArrayAppendArray(newElements, + elements, + CFRangeMake(i+1, nElements-i-1)); + CFRelease(elements); + elements = newElements; + + CFRelease(nodes); + goto restart; + } + } + + if (entity) { + newEntity = CFRetain(entity); + } + for (i=nElements-1; i>=0; i--) { + element = CFArrayGetValueAtIndex(elements, i); + if (i == 0) { + if (newEntity) { + CFDictionarySetValue(sessionPrivate->prefs, element, newEntity); + } else { + CFDictionaryRemoveValue(sessionPrivate->prefs, element); + } + sessionPrivate->changed = TRUE; + ok = TRUE; + } else { + CFMutableDictionaryRef newNode; + + node = CFArrayGetValueAtIndex(nodes, i-1); + newNode = CFDictionaryCreateMutableCopy(NULL, 0, node); + if (newEntity) { + CFDictionarySetValue(newNode, element, newEntity); + CFRelease(newEntity); + } else { + CFDictionaryRemoveValue(newNode, element); + } + newEntity = newNode; + } + } + if (newEntity) { + CFRelease(newEntity); + } + + done : + + CFRelease(nodes); + CFRelease(elements); + return ok; } @@ -131,84 +293,47 @@ CFStringRef SCPreferencesPathCreateUniqueChild(SCPreferencesRef session, CFStringRef prefix) { - int status; - CFMutableDictionaryRef value; + CFStringRef child; CFStringRef newPath = NULL; - Boolean newValue = FALSE; - CFIndex i; CFMutableDictionaryRef newDict = NULL; + CFUUIDRef uuid; + CFDictionaryRef entity; SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCPreferencesPathCreateUniqueChild:")); SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" prefix = %@"), prefix); - status = getPath(session, prefix, &value); - switch (status) { - case kSCStatusOK : - break; - case kSCStatusNoKey : - value = CFDictionaryCreateMutable(NULL, - 0, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); - newValue = TRUE; - break; - default : + if (getPath(session, prefix, &entity)) { + // if prefix path exists + if (CFDictionaryContainsKey(entity, kSCResvLink)) { + /* the path is a link... */ + _SCErrorSet(kSCStatusFailed); return NULL; - } - - if (CFGetTypeID(value) != CFDictionaryGetTypeID()) { - /* if specified path is not a dictionary */ - status = kSCStatusNoKey; - goto error; - } - - if (CFDictionaryContainsKey(value, kSCResvLink)) { - /* the path is a link... */ - status = kSCStatusFailed; - goto error; - } - - i = 0; - while (TRUE) { - CFStringRef pathComponent; - Boolean found; - - pathComponent = CFStringCreateWithFormat(NULL, NULL, CFSTR("%d"), i); - found = CFDictionaryContainsKey(value, pathComponent); - CFRelease(pathComponent); - - if (!found) { - /* if we've identified the next unique key */ - newPath = CFStringCreateWithFormat(NULL, - NULL, - CFSTR("%@/%i"), - prefix, - i); - break; } - i++; + } else if (SCError() != kSCStatusNoKey) { + // if any error except for a missing prefix path component + return NULL; } + uuid = CFUUIDCreate(NULL); + child = CFUUIDCreateString(NULL, uuid); + newPath = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/%@"), prefix, child); + CFRelease(child); + CFRelease(uuid); + /* save the new dictionary */ newDict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - if (!SCPreferencesPathSetValue(session, newPath, newDict)) { - goto error; + if (setPath(session, newPath, newDict)) { + SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" child = %@"), newPath); + } else { + CFRelease(newPath); + newPath = NULL; } CFRelease(newDict); - SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" child = %@"), newPath); - if (newValue) CFRelease(value); return newPath; - - error : - - if (newDict) CFRelease(newDict); - if (newValue) CFRelease(value); - if (newPath) CFRelease(newPath); - return NULL; } @@ -216,28 +341,23 @@ CFDictionaryRef SCPreferencesPathGetValue(SCPreferencesRef session, CFStringRef path) { - int status; - CFMutableDictionaryRef entity; - CFStringRef entityLink; + CFDictionaryRef entity; + CFStringRef entityLink; SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCPreferencesPathGetValue:")); SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" path = %@"), path); - status = getPath(session, path, &entity); - if (status != kSCStatusOK) { + if (!getPath(session, path, &entity)) { return NULL; } -/* XXXX Add code here to chase multiple links XXXXX */ - - if ((CFGetTypeID(entity) == CFDictionaryGetTypeID()) && - (CFDictionaryGetValueIfPresent(entity, kSCResvLink, (void **)&entityLink))) { - /* if this is a dictionary AND it is a link */ - status = getPath(session, entityLink, &entity); - if (status != kSCStatusOK) { - /* if it was a bad link */ - return NULL; - } + if (isA_CFDictionary(entity) && + (CFDictionaryGetValueIfPresent(entity, kSCResvLink, (const void **)&entityLink))) { + /* if this is a dictionary AND it is a link */ + if (!getPath(session, entityLink, &entity)) { + /* if it was a bad link */ + return NULL; + } } SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" value = %@"), entity); @@ -249,21 +369,19 @@ CFStringRef SCPreferencesPathGetLink(SCPreferencesRef session, CFStringRef path) { - int status; - CFMutableDictionaryRef entity; - CFStringRef entityLink; + CFDictionaryRef entity; + CFStringRef entityLink; SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCPreferencesPathGetLink:")); SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" path = %@"), path); - status = getPath(session, path, &entity); - if (status != kSCStatusOK) { + if (!getPath(session, path, &entity)) { return NULL; } - if ((CFGetTypeID(entity) == CFDictionaryGetTypeID()) && - (CFDictionaryGetValueIfPresent(entity, kSCResvLink, (void **)&entityLink))) { - /* if this is a dictionary AND it is a link */ + if (isA_CFDictionary(entity) && + (CFDictionaryGetValueIfPresent(entity, kSCResvLink, (const void **)&entityLink))) { + /* if this is a dictionary AND it is a link */ SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" link = %@"), entityLink); return entityLink; } @@ -277,72 +395,18 @@ SCPreferencesPathSetValue(SCPreferencesRef session, CFStringRef path, CFDictionaryRef value) { - CFMutableDictionaryRef element; - CFArrayRef elements = NULL; - CFIndex i; - CFIndex nElements; - Boolean newRoot = FALSE; Boolean ok; - CFMutableDictionaryRef root = NULL; SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCPreferencesPathSetValue:")); SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" path = %@"), path); SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" value = %@"), value); - elements = normalizePath(path); - if (elements == NULL) { - _SCErrorSet(kSCStatusNoKey); + if (!value) { + _SCErrorSet(kSCStatusInvalidArgument); return FALSE; } - /* get preferences key */ - root = (CFMutableDictionaryRef)SCPreferencesGetValue(session, - CFArrayGetValueAtIndex(elements, 0)); - if (!root) { - root = CFDictionaryCreateMutable(NULL, - 0, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); - newRoot = TRUE; - } - - nElements = CFArrayGetCount(elements); - if (nElements == 1) { - /* if we are only updating the data associated with the preference key */ - if (newRoot) { - CFRelease(root); - newRoot = FALSE; - } - root = (CFMutableDictionaryRef)value; - } - - element = root; - for (i=1; i 1) { - CFDictionarySetValue(element, - CFArrayGetValueAtIndex(elements, nElements-1), - value); - } - ok = SCPreferencesSetValue(session, CFArrayGetValueAtIndex(elements, 0), root); - if (newRoot) CFRelease(root); - CFRelease(elements); + ok = setPath(session, path, value); return ok; } @@ -353,18 +417,29 @@ SCPreferencesPathSetLink(SCPreferencesRef session, CFStringRef link) { CFMutableDictionaryRef dict; + CFDictionaryRef entity; Boolean ok; SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCPreferencesPathSetLink:")); SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" path = %@"), path); SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" link = %@"), link); + if (!link) { + _SCErrorSet(kSCStatusInvalidArgument); + return FALSE; + } + + if (!getPath(session, link, &entity)) { + // if bad link + return FALSE; + } + dict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFDictionaryAddValue(dict, kSCResvLink, link); - ok = SCPreferencesPathSetValue(session, path, dict); + ok = setPath(session, path, dict); CFRelease(dict); return ok; @@ -375,54 +450,25 @@ Boolean SCPreferencesPathRemoveValue(SCPreferencesRef session, CFStringRef path) { - CFMutableDictionaryRef element; CFArrayRef elements = NULL; - CFIndex i; - CFIndex nElements; Boolean ok = FALSE; - CFMutableDictionaryRef root = NULL; + CFDictionaryRef value; SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCPreferencesPathRemoveValue:")); SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" path = %@"), path); + if (!getPath(session, path, &value)) { + // if no such path + return FALSE; + } + elements = normalizePath(path); if (elements == NULL) { _SCErrorSet(kSCStatusNoKey); return FALSE; } - /* get preferences key */ - root = (CFMutableDictionaryRef)SCPreferencesGetValue(session, - CFArrayGetValueAtIndex(elements, 0)); - if (!root) { - goto done; - } - - nElements = CFArrayGetCount(elements); - if (nElements == 1) { - /* if we are removing the data associated with the preference key */ - ok = SCPreferencesRemoveValue(session, CFArrayGetValueAtIndex(elements, 0)); - goto done; - } - - element = root; - for (i=1; i -#include #include +#include CFStringRef SCDynamicStoreKeyCreateProxies(CFAllocatorRef allocator) @@ -45,22 +45,23 @@ SCDynamicStoreCopyProxies(SCDynamicStoreRef store) { CFDictionaryRef dict = NULL; CFStringRef key; - SCDynamicStoreRef mySession = store; CFDictionaryRef proxies = NULL; + Boolean tempSession = FALSE; if (!store) { - mySession = SCDynamicStoreCreate(NULL, - CFSTR("SCDynamicStoreCopyConsoleUser"), - NULL, - NULL); - if (!mySession) { + store = SCDynamicStoreCreate(NULL, + CFSTR("SCDynamicStoreCopyConsoleUser"), + NULL, + NULL); + if (!store) { SCLog(_sc_verbose, LOG_INFO, CFSTR("SCDynamicStoreCreate() failed")); return NULL; } + tempSession = TRUE; } key = SCDynamicStoreKeyCreateProxies(NULL); - dict = SCDynamicStoreCopyValue(mySession, key); + dict = SCDynamicStoreCopyValue(store, key); CFRelease(key); if (!isA_CFDictionary(dict)) { _SCErrorSet(kSCStatusNoKey); @@ -71,7 +72,7 @@ SCDynamicStoreCopyProxies(SCDynamicStoreRef store) done : - if (!store && mySession) CFRelease(mySession); - if (dict) CFRelease(dict); + if (tempSession) CFRelease(store); + if (dict) CFRelease(dict); return proxies; } diff --git a/SystemConfiguration.fproj/SCValidation.h b/SystemConfiguration.fproj/SCValidation.h index 09f1aaf..272cdc5 100644 --- a/SystemConfiguration.fproj/SCValidation.h +++ b/SystemConfiguration.fproj/SCValidation.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2001-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -104,6 +104,15 @@ isA_CFString(CFTypeRef obj) return (isA_CFType(obj, CFStringGetTypeID())); } + +Boolean +_SC_stringIsValidDNSName (const char *name); + + +Boolean +_SC_CFStringIsValidDNSName (CFStringRef name); + + __END_DECLS #endif /* _SCVALIDATION_H */ diff --git a/SystemConfiguration.fproj/SystemConfiguration.h b/SystemConfiguration.fproj/SystemConfiguration.h index 13b8503..3467ba6 100644 --- a/SystemConfiguration.fproj/SystemConfiguration.h +++ b/SystemConfiguration.fproj/SystemConfiguration.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -65,6 +65,7 @@ @constant kSCStatusNoConfigFile Configuration file not found @constant kSCStatusNoLink No such link @constant kSCStatusStale Write attempted on stale version of object + @constant kSCStatusMaxLink Maximum link count exceeded @constant kSCStatusReachabilityUnknown A determination could not be made regarding the reachability @@ -99,6 +100,7 @@ enum { kSCStatusNoConfigFile = 3003, /* Configuration file not found */ kSCStatusNoLink = 3004, /* No such link */ kSCStatusStale = 3005, /* Write attempted on stale version of object */ + kSCStatusMaxLink = 3006, /* Maximum link count exceeded */ /* * SCNetwork status codes */ diff --git a/SystemConfiguration.fproj/genSCPreferences.c b/SystemConfiguration.fproj/genSCPreferences.c index c4eb32f..cc54958 100644 --- a/SystemConfiguration.fproj/genSCPreferences.c +++ b/SystemConfiguration.fproj/genSCPreferences.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -41,12 +41,13 @@ */ #include #include +#include #include #include char copyright_string[] = "/*\n" -" * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.\n" +" * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.\n" " *\n" " * @APPLE_LICENSE_HEADER_START@\n" " * \n" @@ -72,7 +73,7 @@ typedef enum { COMMENT, OBSOLETE, REGULAR, - DEFINE , + DEFINE, FUTURE, END } controlType; @@ -99,6 +100,7 @@ typedef enum { #define CFARRAY_CFNUMBER "CFArray[CFNumber]" #define CFARRAY_CFSTRING "CFArray[CFString]" #define CFBOOLEAN "CFBoolean" +#define CFDATA "CFData" #define CFDICTIONARY "CFDictionary" #define CFNUMBER "CFNumber" #define CFNUMBER_BOOL "CFNumber (0 or 1)" @@ -108,6 +110,7 @@ typedef enum { #define ADDRESSES "Addresses" #define AIRPORT "AirPort" #define ALERT "Alert" +#define ALLOWNETCREATION "AllowNetCreation" #define ALTERNATEREMOTEADDRESS "AlternateRemoteAddress" #define ANYREGEX "AnyRegex" #define APPLETALK "AppleTalk" @@ -118,6 +121,8 @@ typedef enum { #define BROADCAST "Broadcast" #define BROADCASTADDRESSES "BroadcastAddresses" #define BROADCASTSERVERTAG "BroadcastServerTag" +#define CALLWAITINGAUDIBLEALERT "CallWaitingAudibleAlert" +#define CCP "CCP" #define CHAP "CHAP" #define COMM "Comm" #define COMPRESSIONACFIELD "CompressionACField" @@ -127,20 +132,26 @@ typedef enum { #define CONFIGMETHOD "ConfigMethod" #define CONNECTDELAY "ConnectDelay" #define CONNECTIONSCRIPT "ConnectionScript" +#define CONNECTSPEED "ConnectSpeed" +#define CONNECTTIME "ConnectTime" #define CONSOLEUSER "ConsoleUser" #define CURRENTSET "CurrentSet" #define DATACOMPRESSION "DataCompression" #define DEFAULTSERVERTAG "DefaultServerTag" #define DEFAULTZONE "DefaultZone" #define DESTADDRESSES "DestAddresses" +#define DETACHING "Detaching" +#define DEVICE "Device" #define DEVICENAME "DeviceName" #define DHCP "DHCP" #define DHCPCLIENTID "DHCPClientID" #define DIALMODE "DialMode" #define DIALONDEMAND "DialOnDemand" +#define DISCONNECTONANSWER "DisconnectOnAnswer" #define DISCONNECTONIDLE "DisconnectOnIdle" #define DISCONNECTONIDLETIMER "DisconnectOnIdleTimer" #define DISCONNECTONLOGOUT "DisconnectOnLogout" +#define DISCONNECTONSLEEP "DisconnectOnSleep" #define DISPLAYTERMINALWINDOW "DisplayTerminalWindow" #define DNS "DNS" #define DOMAIN "Domain" @@ -149,6 +160,7 @@ typedef enum { #define ECHOENABLED "EchoEnabled" #define ECHOFAILURE "EchoFailure" #define ECHOINTERVAL "EchoInterval" +#define ENABLED "Enabled" #define ENCODING "Encoding" #define ENCRYPTION "Encryption" #define ERRORCORRECTION "ErrorCorrection" @@ -165,6 +177,8 @@ typedef enum { #define GOPHERPORT "GopherPort" #define GOPHERPROXY "GopherProxy" #define HARDWARE "Hardware" +#define HOLD "Hold" +#define HOSTNAMES "HostNames" #define HTTPENABLE "HTTPEnable" #define HTTPPORT "HTTPPort" #define HTTPPROXY "HTTPProxy" @@ -182,9 +196,13 @@ typedef enum { #define IPCP "IPCP" #define IPV4 "IPv4" #define IPV6 "IPv6" +#define JOINMODE "JoinMode" +#define LASTCAUSE "LastCause" #define LASTUPDATED "LastUpdated" #define LCP "LCP" #define LINK "Link" +#define LINKLOCAL "LinkLocal" +#define LOCALHOSTNAME "LocalHostName" #define LOGFILE "Logfile" #define MACADDRESS "MACAddress" #define MANUAL "Manual" @@ -196,18 +214,24 @@ typedef enum { #define NETINFO "NetInfo" #define NETWORK "Network" #define NETWORKID "NetworkID" +#define NETWORKRANGE "NetworkRange" #define NETWORKSERVICES "NetworkServices" #define NIS "NIS" #define NODE "Node" #define NODEID "NodeID" +#define NOTE "Note" +#define OVERRIDEPRIMARY "OverridePrimary" #define PAP "PAP" #define PASSWORD "Password" #define PLUGIN "Plugin" +#define PLUGINS "Plugins" #define POWERENABLED "PowerEnabled" #define PPP "PPP" #define PPPOE "PPPoE" #define PPPOVERRIDEPRIMARY "PPPOverridePrimary" #define PPPSERIAL "PPPSerial" +#define PPTP "PPTP" +#define PREFERRED "Preferred" #define PREFERREDNETWORK "PreferredNetwork" #define PREFS "Prefs" #define PRIMARYINTERFACE "PrimaryInterface" @@ -216,15 +240,19 @@ typedef enum { #define PROXIES "Proxies" #define PULSEDIAL "PulseDial" #define RECEIVEACCM "ReceiveACCM" +#define RECENT "Recent" #define REDIALCOUNT "RedialCount" #define REDIALENABLED "RedialEnabled" #define REDIALINTERVAL "RedialInterval" +#define REMINDER "Reminder" +#define REMINDERTIME "ReminderTime" #define REMOTEADDRESS "RemoteAddress" #define ROOTSEPARATOR "RootSeparator" #define ROUTER "Router" #define RTSPENABLE "RTSPEnable" #define RTSPPORT "RTSPPort" #define RTSPPROXY "RTSPProxy" +#define SAVEPASSWORDS "SavePasswords" #define SEARCHDOMAINS "SearchDomains" #define SEEDNETWORKRANGE "SeedNetworkRange" #define SEEDROUTER "SeedRouter" @@ -244,14 +272,18 @@ typedef enum { #define SPEAKER "Speaker" #define SPEED "Speed" #define STATE "State" +#define STATUS "Status" +#define STRONGEST "Strongest" #define SUBNETMASKS "SubnetMasks" #define SUBTYPE "SubType" +#define SUPPORTSMODEMONHOLD "SupportsModemOnHold" #define SYSTEM "System" #define TERMINALSCRIPT "TerminalScript" #define TRANSMITACCM "TransmitACCM" #define TYPE "Type" #define UID "UID" #define USERDEFINEDNAME "UserDefinedName" +#define USE "Use" #define USERS "Users" #define VERBOSELOGGING "VerboseLogging" #define WAITFORDIALTONE "WaitForDialTone" @@ -286,6 +318,7 @@ struct { { REGULAR, COMP, NETWORK, NULL, NULL }, { REGULAR, COMP, SERVICE, NULL, NULL }, { REGULAR, COMP, GLOBAL, NULL, NULL }, + { DEFINE , COMP, HOSTNAMES, NULL, NULL }, { REGULAR, COMP, INTERFACE, NULL, NULL }, { REGULAR, COMP, SYSTEM, NULL, NULL }, { REGULAR, COMP, USERS, NULL, NULL }, @@ -314,15 +347,32 @@ struct { { COMMENT, "", NULL, NULL, NULL }, { COMMENT, "/*\n * " KEY_PREFIX COMP NETWORK " Properties\n */", NULL }, + { DEFINE , NETPROP, OVERRIDEPRIMARY, NULL, CFNUMBER_BOOL }, { REGULAR, NETPROP, SERVICEORDER, NULL, CFARRAY_CFSTRING }, { REGULAR, NETPROP, PPPOVERRIDEPRIMARY, NULL, CFNUMBER_BOOL }, { COMMENT, "", NULL, NULL, NULL }, + { COMMENT, "/*\n * " KEY_PREFIX COMP NETWORK INTERFACE " Properties\n */", NULL }, + { DEFINE , NETPROP, INTERFACES, NULL, CFARRAY_CFSTRING }, + { COMMENT, "", NULL, NULL, NULL }, + + { COMMENT, "/*\n * " KEY_PREFIX COMP NETWORK HOSTNAMES " Properties\n */", NULL }, + { DEFINE , NETPROP, LOCALHOSTNAME, NULL, CFSTRING }, + { COMMENT, "", NULL, NULL, NULL }, + { COMMENT, "/*\n * " KEY_PREFIX NETENT AIRPORT " (Hardware) Entity Keys\n */", NULL, NULL, NULL }, - { REGULAR, NETPROP AIRPORT, POWERENABLED, NULL, CFNUMBER_BOOL }, - { REGULAR, NETPROP AIRPORT, AUTH PASSWORD, NULL, CFSTRING }, + { DEFINE , NETPROP AIRPORT, ALLOWNETCREATION, NULL, CFNUMBER_BOOL }, + { REGULAR, NETPROP AIRPORT, AUTH PASSWORD, NULL, CFDATA }, { REGULAR, NETPROP AIRPORT, AUTH PASSWORD ENCRYPTION, NULL, CFSTRING }, + { DEFINE , NETPROP AIRPORT, JOINMODE, NULL, CFSTRING }, + { REGULAR, NETPROP AIRPORT, POWERENABLED, NULL, CFNUMBER_BOOL }, { REGULAR, NETPROP AIRPORT, PREFERREDNETWORK, NULL, CFSTRING }, + { DEFINE , NETPROP AIRPORT, SAVEPASSWORDS, NULL, CFNUMBER_BOOL }, + { COMMENT, "", NULL, NULL, NULL }, + { COMMENT, "/* " KEY_PREFIX NETPROP AIRPORT JOINMODE " values */", NULL, NULL, NULL }, + { DEFINE , NETVAL AIRPORT JOINMODE, PREFERRED, NULL, NULL }, + { DEFINE , NETVAL AIRPORT JOINMODE, RECENT, NULL, NULL }, + { DEFINE , NETVAL AIRPORT JOINMODE, STRONGEST, NULL, NULL }, { COMMENT, "", NULL, NULL, NULL }, { COMMENT, "/*\n * " KEY_PREFIX NETENT APPLETALK " Entity Keys\n */", NULL, NULL, NULL }, @@ -331,6 +381,7 @@ struct { { REGULAR, NETPROP APPLETALK, CONFIGMETHOD, NULL, CFSTRING }, { REGULAR, NETPROP APPLETALK, DEFAULTZONE, NULL, CFSTRING }, { REGULAR, NETPROP APPLETALK, NETWORKID, NULL, CFNUMBER }, + { REGULAR, NETPROP APPLETALK, NETWORKRANGE, NULL, CFARRAY_CFNUMBER }, { REGULAR, NETPROP APPLETALK, NODEID, NULL, CFNUMBER }, { REGULAR, NETPROP APPLETALK, SEEDNETWORKRANGE, NULL, CFARRAY_CFNUMBER }, { REGULAR, NETPROP APPLETALK, SEEDZONES, NULL, CFARRAY_CFSTRING }, @@ -356,6 +407,7 @@ struct { { REGULAR, NETPROP INTERFACE, HARDWARE, NULL, CFSTRING }, { REGULAR, NETPROP INTERFACE, TYPE, NULL, CFSTRING }, { REGULAR, NETPROP INTERFACE, SUBTYPE, NULL, CFSTRING }, + { DEFINE , NETPROP INTERFACE, SUPPORTSMODEMONHOLD, NULL, CFNUMBER_BOOL }, { COMMENT, "", NULL, NULL, NULL }, { COMMENT, "/* " KEY_PREFIX NETPROP INTERFACE TYPE " values */", NULL, NULL, NULL }, { REGULAR, NETVAL INTERFACE TYPE, ETHERNET, NULL, NULL }, @@ -364,6 +416,7 @@ struct { { COMMENT, "/* " KEY_PREFIX NETPROP SERVICE SUBTYPE " values (for " PPP ") */", NULL, NULL, NULL }, { REGULAR, NETVAL INTERFACE SUBTYPE, PPPOE, NULL, NULL }, { REGULAR, NETVAL INTERFACE SUBTYPE, PPPSERIAL, NULL, NULL }, + { DEFINE , NETVAL INTERFACE SUBTYPE, PPTP, NULL, NULL }, { COMMENT, "", NULL, NULL, NULL }, { COMMENT, "/*\n * " KEY_PREFIX NETENT IPV4 " Entity Keys\n */", NULL, NULL, NULL }, @@ -379,6 +432,7 @@ struct { { REGULAR, NETVAL IPV4 CONFIGMETHOD, BOOTP, NULL, NULL }, { REGULAR, NETVAL IPV4 CONFIGMETHOD, DHCP, NULL, NULL }, { REGULAR, NETVAL IPV4 CONFIGMETHOD, INFORM, NULL, NULL }, + { REGULAR, NETVAL IPV4 CONFIGMETHOD, LINKLOCAL, NULL, NULL }, { REGULAR, NETVAL IPV4 CONFIGMETHOD, MANUAL, NULL, NULL }, { REGULAR, NETVAL IPV4 CONFIGMETHOD, PPP, NULL, NULL }, { COMMENT, "", NULL, NULL, NULL }, @@ -390,13 +444,21 @@ struct { { COMMENT, "/*\n * " KEY_PREFIX NETENT LINK " Entity Keys\n */", NULL, NULL, NULL }, { REGULAR, NETPROP LINK, ACTIVE, NULL, CFBOOLEAN }, + { DEFINE , NETPROP LINK, DETACHING, NULL, CFBOOLEAN }, { COMMENT, "", NULL, NULL, NULL }, { COMMENT, "/*\n * " KEY_PREFIX NETENT MODEM " (Hardware) Entity Keys\n */", NULL, NULL, NULL }, { REGULAR, NETPROP MODEM, CONNECTIONSCRIPT, NULL, CFSTRING }, + { DEFINE , NETPROP MODEM, CONNECTSPEED, NULL, CFNUMBER }, { DEFINE , NETPROP MODEM, DATACOMPRESSION, NULL, CFNUMBER_BOOL }, { REGULAR, NETPROP MODEM, DIALMODE, NULL, CFSTRING }, { DEFINE , NETPROP MODEM, ERRORCORRECTION, NULL, CFNUMBER_BOOL }, + { DEFINE , NETPROP MODEM, HOLD CALLWAITINGAUDIBLEALERT, NULL, CFNUMBER_BOOL }, + { DEFINE , NETPROP MODEM, HOLD DISCONNECTONANSWER, NULL, CFNUMBER_BOOL }, + { DEFINE , NETPROP MODEM, HOLD ENABLED, NULL, CFNUMBER_BOOL }, + { DEFINE , NETPROP MODEM, HOLD REMINDER, NULL, CFNUMBER_BOOL }, + { DEFINE , NETPROP MODEM, HOLD REMINDERTIME, NULL, CFNUMBER }, + { DEFINE , NETPROP MODEM, NOTE, NULL, CFSTRING }, { REGULAR, NETPROP MODEM, PULSEDIAL, NULL, CFNUMBER_BOOL }, { REGULAR, NETPROP MODEM, SPEAKER, NULL, CFNUMBER_BOOL }, { REGULAR, NETPROP MODEM, SPEED, NULL, CFNUMBER }, @@ -427,14 +489,21 @@ struct { { COMMENT, "", NULL, NULL, NULL }, { COMMENT, "/*\n * " KEY_PREFIX NETENT PPP " Entity Keys\n */", NULL, NULL, NULL }, + { DEFINE , NETPROP PPP, CONNECTTIME, NULL, CFNUMBER }, + { DEFINE , NETPROP PPP, DEVICE LASTCAUSE, NULL, CFNUMBER }, { REGULAR, NETPROP PPP, DIALONDEMAND, NULL, CFNUMBER_BOOL }, { REGULAR, NETPROP PPP, DISCONNECTONIDLE, NULL, CFNUMBER_BOOL }, { REGULAR, NETPROP PPP, DISCONNECTONIDLETIMER, NULL, CFNUMBER }, { REGULAR, NETPROP PPP, DISCONNECTONLOGOUT, NULL, CFNUMBER_BOOL }, + { DEFINE , NETPROP PPP, DISCONNECTONSLEEP, NULL, CFNUMBER_BOOL }, { REGULAR, NETPROP PPP, IDLEREMINDERTIMER, NULL, CFNUMBER }, { REGULAR, NETPROP PPP, IDLEREMINDER, NULL, CFNUMBER_BOOL }, + { DEFINE , NETPROP PPP, LASTCAUSE, NULL, CFNUMBER }, { REGULAR, NETPROP PPP, LOGFILE, NULL, CFSTRING }, + { DEFINE , NETPROP PPP, PLUGINS, NULL, CFARRAY_CFSTRING }, { DEFINE , NETPROP PPP, SESSIONTIMER, NULL, CFNUMBER }, + { DEFINE , NETPROP PPP, STATUS, NULL, CFSTRING }, + { DEFINE , NETPROP PPP, USE SESSIONTIMER, NULL, CFNUMBER_BOOL }, { REGULAR, NETPROP PPP, VERBOSELOGGING, NULL, CFNUMBER_BOOL }, { COMMENT, "", NULL, NULL, NULL }, @@ -457,6 +526,10 @@ struct { { REGULAR, NETPROP PPP, COMM REDIALINTERVAL, NULL, CFNUMBER }, { REGULAR, NETPROP PPP, COMM REMOTEADDRESS, NULL, CFSTRING }, { REGULAR, NETPROP PPP, COMM TERMINALSCRIPT, NULL, CFSTRING }, + { DEFINE , NETPROP PPP, COMM USE TERMINALSCRIPT, NULL, CFNUMBER_BOOL }, + + { COMMENT, "\n/* " CCP ": */", NULL, NULL, NULL }, + { DEFINE , NETPROP PPP, CCP ENABLED, NULL, CFNUMBER_BOOL }, { COMMENT, "\n/* " IPCP ": */", NULL, NULL, NULL }, { REGULAR, NETPROP PPP, IPCP COMPRESSIONVJ, NULL, CFNUMBER_BOOL }, diff --git a/SystemConfiguration.fproj/moh.c b/SystemConfiguration.fproj/moh.c new file mode 100644 index 0000000..659e470 --- /dev/null +++ b/SystemConfiguration.fproj/moh.c @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This 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 OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * Modification History + * + * May 29, 2002 Roger Smith + * - initial revision + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "moh.h" +#include "moh_msg.h" + +// Note: right now we are not currently using the deviceName. This could be the raw +// tty name such as "modem" since this is guaranteed to be unique in the /dev. +// We would use this deviceName to differientate between multiple MOH devices +// present in the system when we create the socket. + + +static int +readn(int ref, void *data, int len) +{ + int left = len; + int n; + void *p = data; + + while (left > 0) { + if ((n = read(ref, p, left)) < 0) { + if (errno != EINTR) { + return -1; + } + n = 0; + } else if (n == 0) { + break; /* EOF */ + } + + left -= n; + p += n; + } + return (len - left); +} + + +static int +writen(int ref, void *data, int len) +{ + int left = len; + int n; + void *p = data; + + while (left > 0) { + if ((n = write(ref, p, left)) <= 0) { + if (errno != EINTR) { + return -1; + } + n = 0; + } + left -= n; + p += n; + } + return len; +} + + +__private_extern__ +int +MOHInit(int *ref, CFStringRef deviceName) +{ + int sock; + int status; + struct sockaddr_un sun; + + sock = socket(AF_LOCAL, SOCK_STREAM, 0); + + bzero(&sun, sizeof(sun)); + sun.sun_family = AF_LOCAL; + strncpy(sun.sun_path, MOH_PATH, sizeof(sun.sun_path)); + + status = connect(sock, (struct sockaddr *)&sun, sizeof(sun)); + if (status < 0) { + return errno; + } + + *ref = sock; + return 0; +} + + +__private_extern__ +int +MOHDispose(int ref) +{ + if (close(ref) < 0) { + return errno; + } + return 0; +} + + +__private_extern__ +int +MOHExec(int ref, + u_long link, + u_int32_t cmd, + void *request, + u_long requestLen, + void **reply, + u_long *replyLen) +{ + struct moh_msg_hdr msg; + char *buf = NULL; + ssize_t n; + + bzero(&msg, sizeof(msg)); + msg.m_type = cmd; + msg.m_link = link; + msg.m_len = ((request != NULL) && (requestLen > 0)) ? requestLen : 0; + + // send the command + n = writen(ref, &msg, sizeof(msg)); + if (n == -1) { + SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec writen() failed: %s"), strerror(errno)); + return errno; + } else if (n != sizeof(msg)) { + SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec writen() failed: wrote=%d"), n); + return -1; + } + + if ((request != NULL) && (requestLen > 0)) { + n = writen(ref, request, requestLen); + if (n == -1) { + SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec writen() failed: %s"), strerror(errno)); + return errno; + } else if (n != requestLen) { + SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec writen() failed: wrote=%d"), n); + return -1; + } + } + + // always expect a reply + n = readn(ref, &msg, sizeof(msg)); + if (n == -1) { + SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec readn() failed: error=%s"), strerror(errno)); + return errno; + } else if (n != sizeof(msg)) { + SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec readn() failed: insufficent data, read=%d"), n); + return -1; + } + + if (msg.m_len) { + buf = CFAllocatorAllocate(NULL, msg.m_len, 0); + if (buf) { + // read reply + n = readn(ref, buf, msg.m_len); + if (n == -1) { + SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec readn() failed: error=%s"), strerror(errno)); + CFAllocatorDeallocate(NULL, buf); + return errno; + } else if (n != msg.m_len) { + SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec readn() failed: insufficent data, read=%d"), n); + CFAllocatorDeallocate(NULL, buf); + return -1; + } + } + } + + if (reply && replyLen) { + *reply = buf; + *replyLen = msg.m_len; + } else if (buf) { + // if additional returned data is unwanted + CFAllocatorDeallocate(NULL, buf); + } + + return msg.m_result; +} + diff --git a/SystemConfiguration.fproj/moh.h b/SystemConfiguration.fproj/moh.h new file mode 100644 index 0000000..57ee428 --- /dev/null +++ b/SystemConfiguration.fproj/moh.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This 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 OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * Modification History + * + */ + +#ifndef _MOH_H +#define _MOH_H + +#include +#include + +__BEGIN_DECLS + +int +MOHInit ( + int *ref, + CFStringRef deviceName + ); + +int +MOHDispose ( + int ref + ); + +int +MOHExec (int ref, + u_long link, + u_int32_t cmd, + void *request, + u_long requestLen, + void **reply, + u_long *replyLen + ); + +__END_DECLS + +#endif /* _MOH_H */ diff --git a/SystemConfiguration.fproj/moh_msg.h b/SystemConfiguration.fproj/moh_msg.h new file mode 100644 index 0000000..0a3bc0f --- /dev/null +++ b/SystemConfiguration.fproj/moh_msg.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This 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 OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#ifndef _MOH_MSG_H +#define _MOH_MSG_H + +#include + +/* local socket path */ +#define MOH_PATH "/tmp/.modemOnHold" +#define CURRENT_VERSION 1 + +/* MOH message paquets */ +struct moh_msg_hdr { + u_int32_t m_type; // type of the message + u_int32_t m_result; // error code of notification message + u_int32_t m_cookie; // user param + u_int32_t m_link; // link for this message + u_int32_t m_len; // len of the following data +}; + +struct moh_msg { + u_int32_t m_type; // type of the message + u_int32_t m_result; // error code of notification message + u_int32_t m_cookie; // user param, or error num for event + u_int32_t m_link; // link for this message + u_int32_t m_len; // len of the following data + u_char m_data[1]; // msg data sent or received +}; + +/* codes for MOH messages */ +enum { + /* API client commands */ + MOH_VERSION = 1, + MOH_DEVICE_SUPPORTS_HOLD, + MOH_SESSION_SUPPORTS_HOLD, + MOH_PUT_SESSION_ON_HOLD, + MOH_RESUME_SESSION_ON_HOLD, + MOH_SESSION_IS_ON_HOLD, + MOH_SESSION_GET_STATUS +}; + +#endif /* _MOH_MSG_H */ + diff --git a/SystemConfiguration.fproj/ppp.c b/SystemConfiguration.fproj/ppp.c index f0c109f..df05869 100644 --- a/SystemConfiguration.fproj/ppp.c +++ b/SystemConfiguration.fproj/ppp.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -20,6 +20,19 @@ * @APPLE_LICENSE_HEADER_END@ */ +/* + * Modification History + * + * Feb 28, 2002 Christophe Allie + * - socket API fixes + * + * Feb 10, 2001 Allan Nathanson + * - cleanup API + * + * Feb 2000 Christophe Allie + * - initial revision (as ppplib.c) + */ + #include #include #include @@ -34,6 +47,52 @@ #include "ppp_msg.h" #include "ppp.h" + +static int +readn(int ref, void *data, int len) +{ + int left = len; + int n; + void *p = data; + + while (left > 0) { + if ((n = read(ref, p, left)) < 0) { + if (errno != EINTR) { + return -1; + } + n = 0; + } else if (n == 0) { + break; /* EOF */ + } + + left -= n; + p += n; + } + return (len - left); +} + + +static int +writen(int ref, void *data, int len) +{ + int left = len; + int n; + void *p = data; + + while (left > 0) { + if ((n = write(ref, p, left)) <= 0) { + if (errno != EINTR) { + return -1; + } + n = 0; + } + left -= n; + p += n; + } + return len; +} + + __private_extern__ int PPPInit(int *ref) @@ -89,33 +148,25 @@ PPPExec(int ref, msg.m_len = ((request != NULL) && (requestLen > 0)) ? requestLen : 0; // send the command - n = write(ref, &msg, sizeof(msg)); - if (n == -1) { + if (writen(ref, &msg, sizeof(msg)) < 0) { SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec write() failed: %s"), strerror(errno)); return errno; - } else if (n != sizeof(msg)) { - SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec write() failed: wrote=%d"), n); - return -1; } if ((request != NULL) && (requestLen > 0)) { - n = write(ref, request, requestLen); - if (n == -1) { + if (writen(ref, request, requestLen) < 0) { SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec write() failed: %s"), strerror(errno)); return errno; - } else if (n != requestLen) { - SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec write() failed: wrote=%d"), n); - return -1; } } // always expect a reply - n = read(ref, &msg, sizeof(msg)); + n = readn(ref, &msg, sizeof(msg)); if (n == -1) { - SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec read() failed: error=%s"), strerror(errno)); + SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec readn() failed: error=%s"), strerror(errno)); return errno; } else if (n != sizeof(msg)) { - SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec read() failed: insufficent data, read=%d"), n); + SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec readn() failed: insufficent data, read=%d"), n); return -1; } @@ -123,13 +174,13 @@ PPPExec(int ref, buf = CFAllocatorAllocate(NULL, msg.m_len, 0); if (buf) { // read reply - n = read(ref, buf, msg.m_len); + n = readn(ref, buf, msg.m_len); if (n == -1) { - SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec read() failed: error=%s"), strerror(errno)); + SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec readn() failed: error=%s"), strerror(errno)); CFAllocatorDeallocate(NULL, buf); return errno; } else if (n != msg.m_len) { - SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec read() failed: insufficent data, read=%d"), n); + SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec readn() failed: insufficent data, read=%d"), n); CFAllocatorDeallocate(NULL, buf); return -1; } @@ -189,48 +240,6 @@ PPPDisconnect(int ref, u_long link) return status; } - - -int -PPPListen(int ref, u_long link) -{ - int status; - - status = PPPExec(ref, - link, - PPP_LISTEN, - NULL, - 0, - NULL, - NULL); - if (status != 0) { - SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec(PPP_LISTEN) failed: status = %d"), status); - return status; - } - - return status; -} - - -int -PPPApply(int ref, u_long link) -{ - int status; - - status = PPPExec(ref, - link, - PPP_APPLY, - NULL, - 0, - NULL, - NULL); - if (status != 0) { - SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec(PPP_APPLY) failed: status = %d"), status); - return status; - } - - return status; -} #endif /* NOT_NEEDED */ @@ -457,3 +466,31 @@ PPPStatus(int ref, u_long link, struct ppp_status **stat) return status; } + + +#ifdef NOT_NEEDED +__private_extern__ +int +PPPEnableEvents(int ref, u_long link, u_char enable) +{ + int status; + + status = PPPExec(ref, + link, + enable ? PPP_ENABLE_EVENT : PPP_DISABLE_EVENT, + NULL, + 0, + NULL, + NULL); + if (status != 0) { + SCLog(_sc_verbose, + LOG_ERR, + CFSTR("PPPExec(%s) failed: status = %d"), + enable ? "PPP_ENABLE_EVENT" : "PPP_DISABLE_EVENT", + status); + return status; + } + + return status; +} +#endif /* NOT_NEEDED */ diff --git a/SystemConfiguration.fproj/ppp.h b/SystemConfiguration.fproj/ppp.h index 33eee18..c1d18f8 100644 --- a/SystemConfiguration.fproj/ppp.h +++ b/SystemConfiguration.fproj/ppp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -20,6 +20,16 @@ * @APPLE_LICENSE_HEADER_END@ */ +/* + * Modification History + * + * Feb 10, 2001 Allan Nathanson + * - cleanup API + * + * Feb 2000 Christophe Allie + * - initial revision (as ppplib.h) + */ + #ifndef _PPP_H #define _PPP_H @@ -47,12 +57,6 @@ int PPPConnect (int ref, int PPPDisconnect (int ref, u_long link); - -int PPPListen (int ref, - u_long link); - -int PPPApply (int ref, - u_long link); #endif /* NOT_NEEDED */ int PPPGetNumberOfLinks (int ref, @@ -84,6 +88,12 @@ int PPPStatus (int ref, u_long link, struct ppp_status **stat); +#ifdef NOT_NEEDED +int PPPEnableEvents (int ref, + u_long link, + u_char enable); +#endif /* NOT_NEEDED */ + __END_DECLS #endif /* _PPP_H */ diff --git a/SystemConfiguration.fproj/ppp_msg.h b/SystemConfiguration.fproj/ppp_msg.h index 106817d..6d6d002 100644 --- a/SystemConfiguration.fproj/ppp_msg.h +++ b/SystemConfiguration.fproj/ppp_msg.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -168,7 +168,9 @@ enum { PPP_NETWORK, PPP_RUNNING, PPP_TERMINATE, - PPP_DISCONNECTLINK + PPP_DISCONNECTLINK, + PPP_HOLDOFF, + PPP_ONHOLD }; // events diff --git a/configd.tproj/Makefile b/configd.tproj/Makefile index 1579d6f..c7e4f8d 100644 --- a/configd.tproj/Makefile +++ b/configd.tproj/Makefile @@ -40,7 +40,6 @@ DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) -NEXTSTEP_PB_CFLAGS = -DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS FRAMEWORKS = -framework CoreFoundation -framework SystemConfiguration diff --git a/configd.tproj/Makefile.preamble b/configd.tproj/Makefile.preamble index b5e7557..027ceaa 100644 --- a/configd.tproj/Makefile.preamble +++ b/configd.tproj/Makefile.preamble @@ -136,6 +136,7 @@ OTHER_GENERATED_OFILES = $(VERS_OFILE) # and "" on other systems. # DSTROOT = $(HOME) -# Additional flags (MiG generated files) +# Additional flags (for MiG generated files) +ALL_MIGFLAGS = -F$(SYMROOT) OTHER_OFILES = configServer.o diff --git a/configd.tproj/PB.project b/configd.tproj/PB.project index 225a4c5..6534995 100644 --- a/configd.tproj/PB.project +++ b/configd.tproj/PB.project @@ -1,77 +1,76 @@ { - DYNAMIC_CODE_GEN = YES; + "DYNAMIC_CODE_GEN" = YES; FILESTABLE = { - FRAMEWORKS = (CoreFoundation.framework, SystemConfiguration.framework); + FRAMEWORKS = ("CoreFoundation.framework", "SystemConfiguration.framework"); FRAMEWORKSEARCH = (); HEADERSEARCH = (); - H_FILES = ( - configd.h, - _SCD.h, - configd_server.h, - notify_server.h, - plugin_support.h, - session.h, - notify.h + "H_FILES" = ( + "configd.h", + "_SCD.h", + "configd_server.h", + "notify_server.h", + "plugin_support.h", + "session.h", + "notify.h" ); - OTHER_LIBS = (objc); - OTHER_LINKED = ( - configd.m, - _SCD.c, - configd_server.c, - notify_server.c, - plugin_support.c, - session.c, - notify.c, - _configopen.c, - _configclose.c, - _configlock.c, - _configunlock.c, - _configlist.c, - _configadd.c, - _configadd_s.c, - _configget.c, - _configset.c, - _configremove.c, - _configtouch.c, - _confignotify.c, - _notifyadd.c, - _notifyremove.c, - _notifychanges.c, - _notifyviaport.c, - _notifyviafd.c, - _notifyviasignal.c, - _notifycancel.c, - _snapshot.c + "OTHER_LIBS" = (objc); + "OTHER_LINKED" = ( + "configd.m", + "_SCD.c", + "configd_server.c", + "notify_server.c", + "plugin_support.c", + "session.c", + "notify.c", + "_configopen.c", + "_configclose.c", + "_configlock.c", + "_configunlock.c", + "_configlist.c", + "_configadd.c", + "_configadd_s.c", + "_configget.c", + "_configset.c", + "_configremove.c", + "_configtouch.c", + "_confignotify.c", + "_notifyadd.c", + "_notifyremove.c", + "_notifychanges.c", + "_notifyviaport.c", + "_notifyviafd.c", + "_notifyviasignal.c", + "_notifycancel.c", + "_snapshot.c" ); - OTHER_SOURCES = ( - Makefile.preamble, + "OTHER_SOURCES" = ( + "Makefile.preamble", Makefile, - Makefile.postamble, - m.template, - h.template, - config.defs + "Makefile.postamble", + "m.template", + "h.template", + "config.defs" ); - PRECOMPILED_HEADERS = (); - PROJECT_HEADERS = (); - PUBLIC_HEADERS = (); + "PRECOMPILED_HEADERS" = (); + "PROJECT_HEADERS" = (); + "PUBLIC_HEADERS" = (); SUBPROJECTS = (); }; LANGUAGE = English; MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDTOOL = /usr/bin/gnumake; - NEXTSTEP_COMPILEROPTIONS = "-DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS"; - NEXTSTEP_INSTALLDIR = /usr/sbin; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_INSTALLDIR = /bin; - PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + "NEXTSTEP_BUILDTOOL" = "/usr/bin/gnumake"; + "NEXTSTEP_INSTALLDIR" = "/usr/sbin"; + "NEXTSTEP_JAVA_COMPILER" = "/usr/bin/javac"; + "NEXTSTEP_OBJCPLUS_COMPILER" = "/usr/bin/cc"; + "PDO_UNIX_BUILDTOOL" = "$NEXT_ROOT/Developer/bin/make"; + "PDO_UNIX_INSTALLDIR" = "/bin"; + "PDO_UNIX_JAVA_COMPILER" = "$(JDKBINDIR)/javac"; + "PDO_UNIX_OBJCPLUS_COMPILER" = "$(NEXTDEV_BIN)/gcc"; PROJECTNAME = configd; PROJECTTYPE = Tool; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_INSTALLDIR = /Library/Executables; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; + PROJECTVERSION = "2.8"; + "WINDOWS_BUILDTOOL" = "$NEXT_ROOT/Developer/Executables/make"; + "WINDOWS_INSTALLDIR" = "/Library/Executables"; + "WINDOWS_JAVA_COMPILER" = "$(JDKBINDIR)/javac.exe"; + "WINDOWS_OBJCPLUS_COMPILER" = "$(DEVDIR)/gcc"; } diff --git a/configd.tproj/_SCD.c b/configd.tproj/_SCD.c index 5d024af..b087f8d 100644 --- a/configd.tproj/_SCD.c +++ b/configd.tproj/_SCD.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -188,7 +188,7 @@ _addRegexWatcherByKey(const void *key, void *val, void *context) char reErrBuf[256]; int reErrStrLen; - if (CFDictionaryContainsKey(info, kSCDData) == FALSE) { + if (!CFDictionaryContainsKey(info, kSCDData)) { /* if no data (yet) */ return; } @@ -228,7 +228,7 @@ _addRegexWatcherByKey(const void *key, void *val, void *context) * * This is a CFDictionaryApplierFunction which will iterate over each session * defined in the "sessionData" dictionary. The arguments are the session - * key, it's associated session dictionary, , and the store key being added. + * key, it's associated session dictionary, and the store key being added. * * If an active session includes any regular expression keys which match the * key being added to the "storeData" dictionary then we mark this key as being @@ -246,11 +246,6 @@ _addRegexWatchersBySession(const void *key, void *val, void *context) CFArrayRef rData; CFIndex i; - if (info == NULL) { - /* if no dictionary for this session */ - return; - } - rKeys = CFDictionaryGetValue(info, kSCDRegexKeys); if (rKeys == NULL) { /* if no regex keys for this session */ @@ -418,8 +413,8 @@ _removeRegexWatcherByKey(const void *key, void *val, void *context) char reErrBuf[256]; int reErrStrLen; - if ((info == NULL) || (CFDictionaryContainsKey(info, kSCDWatchers) == FALSE)) { - /* no dictionary or no watchers */ + if (CFDictionaryContainsKey(info, kSCDWatchers) == FALSE) { + /* if no watchers */ return; } @@ -487,11 +482,6 @@ _removeRegexWatchersBySession(const void *key, void *val, void *context) CFArrayRef rData; CFIndex i; - if (info == NULL) { - /* if no dictionary for this session */ - return; - } - rKeys = CFDictionaryGetValue(info, kSCDRegexKeys); if (rKeys == NULL) { /* if no regex keys for this session */ diff --git a/configd.tproj/_configadd.c b/configd.tproj/_configadd.c index d06abd1..df828b7 100644 --- a/configd.tproj/_configadd.c +++ b/configd.tproj/_configadd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -101,13 +101,9 @@ _configadd(mach_port_t server, int *sc_status ) { - kern_return_t status; serverSessionRef mySession = getSession(server); - CFDataRef xmlKey; /* key (XML serialized) */ CFStringRef key; /* key (un-serialized) */ - CFDataRef xmlData; /* data (XML serialized) */ CFPropertyListRef data; /* data (un-serialized) */ - CFStringRef xmlError; SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Add key to configuration database.")); SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" server = %d"), server); @@ -115,50 +111,20 @@ _configadd(mach_port_t server, *sc_status = kSCStatusOK; /* un-serialize the key */ - xmlKey = CFDataCreate(NULL, keyRef, keyLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - key = CFPropertyListCreateFromXMLData(NULL, - xmlKey, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlKey); - if (!key) { - if (xmlError) { - SCLog(_configd_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() key: %@"), - xmlError); - CFRelease(xmlError); - } + if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) { *sc_status = kSCStatusFailed; - } else if (!isA_CFString(key)) { + } + + if (!isA_CFString(key)) { *sc_status = kSCStatusInvalidArgument; } /* un-serialize the data */ - xmlData = CFDataCreate(NULL, dataRef, dataLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)dataRef, dataLen); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - data = CFPropertyListCreateFromXMLData(NULL, - xmlData, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlData); - if (!data) { - if (xmlError) { - SCLog(_configd_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() data: %@"), - xmlError); - CFRelease(xmlError); - } + if (!_SCUnserialize((CFPropertyListRef *)&data, (void *)dataRef, dataLen)) { *sc_status = kSCStatusFailed; - } else if (!isA_CFPropertyList(data)) { + } + + if (!isA_CFPropertyList(data)) { *sc_status = kSCStatusInvalidArgument; } diff --git a/configd.tproj/_configadd_s.c b/configd.tproj/_configadd_s.c index c09c478..8c369b9 100644 --- a/configd.tproj/_configadd_s.c +++ b/configd.tproj/_configadd_s.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -120,13 +120,9 @@ _configadd_s(mach_port_t server, int *sc_status ) { - kern_return_t status; serverSessionRef mySession = getSession(server); - CFDataRef xmlKey; /* key (XML serialized) */ CFStringRef key; /* key (un-serialized) */ - CFDataRef xmlData; /* data (XML serialized) */ CFPropertyListRef data; /* data (un-serialized) */ - CFStringRef xmlError; SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Add (session) key to configuration database.")); SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" server = %d"), server); @@ -134,50 +130,20 @@ _configadd_s(mach_port_t server, *sc_status = kSCStatusOK; /* un-serialize the key */ - xmlKey = CFDataCreate(NULL, keyRef, keyLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - key = CFPropertyListCreateFromXMLData(NULL, - xmlKey, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlKey); - if (!key) { - if (xmlError) { - SCLog(_configd_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() key: %@"), - xmlError); - CFRelease(xmlError); - } + if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) { *sc_status = kSCStatusFailed; - } else if (!isA_CFString(key)) { + } + + if (!isA_CFString(key)) { *sc_status = kSCStatusInvalidArgument; } /* un-serialize the data */ - xmlData = CFDataCreate(NULL, dataRef, dataLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)dataRef, dataLen); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - data = CFPropertyListCreateFromXMLData(NULL, - xmlData, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlData); - if (!data) { - if (xmlError) { - SCLog(_configd_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() data: %@"), - xmlError); - CFRelease(xmlError); - } + if (!_SCUnserialize((CFPropertyListRef *)&data, (void *)dataRef, dataLen)) { *sc_status = kSCStatusFailed; - } else if (!isA_CFPropertyList(data)) { + } + + if (!isA_CFPropertyList(data)) { *sc_status = kSCStatusInvalidArgument; } diff --git a/configd.tproj/_configclose.c b/configd.tproj/_configclose.c index d623f85..810420c 100644 --- a/configd.tproj/_configclose.c +++ b/configd.tproj/_configclose.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -79,8 +79,9 @@ __SCDynamicStoreClose(SCDynamicStoreRef *store) } /* Remove notification keys */ - if ((keyCnt = CFSetGetCount(storePrivate->keys)) > 0) { - void **watchedKeys; + keyCnt = CFSetGetCount(storePrivate->keys); + if (keyCnt > 0) { + const void **watchedKeys; CFArrayRef keysToRemove; CFIndex i; @@ -97,8 +98,9 @@ __SCDynamicStoreClose(SCDynamicStoreRef *store) } /* Remove regex notification keys */ - if ((keyCnt = CFSetGetCount(storePrivate->reKeys)) > 0) { - void **watchedKeys; + keyCnt = CFSetGetCount(storePrivate->reKeys); + if (keyCnt > 0) { + const void **watchedKeys; CFArrayRef keysToRemove; CFIndex i; diff --git a/configd.tproj/_configget.c b/configd.tproj/_configget.c index 48bab88..c51edd3 100644 --- a/configd.tproj/_configget.c +++ b/configd.tproj/_configget.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -70,39 +70,25 @@ _configget(mach_port_t server, int *sc_status ) { - kern_return_t status; - serverSessionRef mySession = getSession(server); - CFDataRef xmlKey; /* key (XML serialized) */ CFStringRef key; /* key (un-serialized) */ - CFDataRef xmlData; /* data (XML serialized) */ + serverSessionRef mySession = getSession(server); + Boolean ok; CFPropertyListRef value; - CFStringRef xmlError; SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Get key from configuration database.")); SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" server = %d"), server); + *dataRef = NULL; + *dataLen = 0; + /* un-serialize the key */ - xmlKey = CFDataCreate(NULL, keyRef, keyLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - key = CFPropertyListCreateFromXMLData(NULL, - xmlKey, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlKey); - if (!key) { - if (xmlError) { - SCLog(_configd_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() key: %@"), - xmlError); - CFRelease(xmlError); - } + if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) { *sc_status = kSCStatusFailed; return KERN_SUCCESS; - } else if (!isA_CFString(key)) { + } + + if (!isA_CFString(key)) { + CFRelease(key); *sc_status = kSCStatusInvalidArgument; return KERN_SUCCESS; } @@ -110,31 +96,17 @@ _configget(mach_port_t server, *sc_status = __SCDynamicStoreCopyValue(mySession->store, key, &value); CFRelease(key); if (*sc_status != kSCStatusOK) { - *dataRef = NULL; - *dataLen = 0; return KERN_SUCCESS; } - /* - * serialize the data, copy it into an allocated buffer which will be - * released when it is returned as part of a Mach message. - */ - xmlData = CFPropertyListCreateXMLData(NULL, value); + /* serialize the data */ + ok = _SCSerialize(value, NULL, (void **)dataRef, (CFIndex *)dataLen); CFRelease(value); - *dataLen = CFDataGetLength(xmlData); - status = vm_allocate(mach_task_self(), (void *)dataRef, *dataLen, TRUE); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_allocate(): %s"), mach_error_string(status)); + if (!ok) { *sc_status = kSCStatusFailed; - CFRelease(xmlData); - *dataRef = NULL; - *dataLen = 0; return KERN_SUCCESS; } - bcopy((char *)CFDataGetBytePtr(xmlData), *dataRef, *dataLen); - CFRelease(xmlData); - /* * return the instance number associated with the returned data. */ @@ -206,72 +178,37 @@ _configget_m(mach_port_t server, mach_msg_type_number_t *dataLen, int *sc_status) { - kern_return_t status; - serverSessionRef mySession = getSession(server); CFArrayRef keys = NULL; /* keys (un-serialized) */ - CFArrayRef patterns = NULL; /* patterns (un-serialized) */ - CFDataRef xmlData; /* data (XML serialized) */ addSpecific myContext; + serverSessionRef mySession = getSession(server); + Boolean ok; + CFArrayRef patterns = NULL; /* patterns (un-serialized) */ SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Get key from configuration database.")); SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" server = %d"), server); + *dataRef = NULL; + *dataLen = 0; *sc_status = kSCStatusOK; if (keysRef && (keysLen > 0)) { - CFDataRef xmlKeys; /* keys (XML serialized) */ - CFStringRef xmlError; - /* un-serialize the keys */ - xmlKeys = CFDataCreate(NULL, keysRef, keysLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)keysRef, keysLen); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - keys = CFPropertyListCreateFromXMLData(NULL, - xmlKeys, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlKeys); - if (!keys) { - if (xmlError) { - SCLog(_configd_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() keys: %@"), - xmlError); - CFRelease(xmlError); - } + if (!_SCUnserialize((CFPropertyListRef *)&keys, (void *)keysRef, keysLen)) { *sc_status = kSCStatusFailed; - } else if (!isA_CFArray(keys)) { + } + + if (!isA_CFArray(keys)) { *sc_status = kSCStatusInvalidArgument; } } if (patternsRef && (patternsLen > 0)) { - CFDataRef xmlPatterns; /* patterns (XML serialized) */ - CFStringRef xmlError; - /* un-serialize the patterns */ - xmlPatterns = CFDataCreate(NULL, patternsRef, patternsLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)patternsRef, patternsLen); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - patterns = CFPropertyListCreateFromXMLData(NULL, - xmlPatterns, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlPatterns); - if (!patterns) { - if (xmlError) { - SCLog(_configd_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() patterns: %@"), - xmlError); - CFRelease(xmlError); - } + if (!_SCUnserialize((CFPropertyListRef *)&patterns, (void *)patternsRef, patternsLen)) { *sc_status = kSCStatusFailed; - } else if (!isA_CFArray(patterns)) { + } + + if (!isA_CFArray(patterns)) { *sc_status = kSCStatusInvalidArgument; } } @@ -279,8 +216,6 @@ _configget_m(mach_port_t server, if (*sc_status != kSCStatusOK) { if (keys) CFRelease(keys); if (patterns) CFRelease(patterns); - *dataRef = NULL; - *dataLen = 0; return KERN_SUCCESS; } @@ -306,26 +241,13 @@ _configget_m(mach_port_t server, CFRelease(patterns); } - /* - * serialize the dictionary of matching keys/patterns, copy it into an - * allocated buffer which will be released when it is returned as part - * of a Mach message. - */ - xmlData = CFPropertyListCreateXMLData(NULL, myContext.dict); + /* serialize the dictionary of matching keys/patterns */ + ok = _SCSerialize(myContext.dict, NULL, (void **)dataRef, (CFIndex *)dataLen); CFRelease(myContext.dict); - *dataLen = CFDataGetLength(xmlData); - status = vm_allocate(mach_task_self(), (void *)dataRef, *dataLen, TRUE); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_allocate(): %s"), mach_error_string(status)); + if (!ok) { *sc_status = kSCStatusFailed; - CFRelease(xmlData); - *dataRef = NULL; - *dataLen = 0; return KERN_SUCCESS; } - bcopy((char *)CFDataGetBytePtr(xmlData), *dataRef, *dataLen); - CFRelease(xmlData); - return KERN_SUCCESS; } diff --git a/configd.tproj/_configlist.c b/configd.tproj/_configlist.c index 6613f8a..da7a970 100644 --- a/configd.tproj/_configlist.c +++ b/configd.tproj/_configlist.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -38,8 +38,8 @@ __SCDynamicStoreCopyKeyList(SCDynamicStoreRef store, CFStringRef key, Boolean is { SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store; CFIndex storeCnt; - void **storeKeys; - void **storeValues; + const void **storeKeys; + const void **storeValues; CFMutableArrayRef keyArray; int i; CFStringRef storeStr; @@ -85,7 +85,7 @@ __SCDynamicStoreCopyKeyList(SCDynamicStoreRef store, CFStringRef key, Boolean is * compile the provided regular expression using the * provided isRegex. */ - regexBufLen = CFStringGetLength(regexStr)+1; + regexBufLen = CFStringGetLength(regexStr) + 1; regexBuf = CFAllocatorAllocate(NULL, regexBufLen, 0); ok = CFStringGetCString(regexStr, regexBuf, regexBufLen, kCFStringEncodingMacRoman); CFRelease(regexStr); @@ -108,66 +108,68 @@ __SCDynamicStoreCopyKeyList(SCDynamicStoreRef store, CFStringRef key, Boolean is } } - storeKeys = CFAllocatorAllocate(NULL, storeCnt * sizeof(CFStringRef), 0); - storeValues = CFAllocatorAllocate(NULL, storeCnt * sizeof(CFStringRef), 0); - CFDictionaryGetKeysAndValues(storeData, storeKeys, storeValues); - for (i=0; i 0) { + storeKeys = CFAllocatorAllocate(NULL, storeCnt * sizeof(CFStringRef), 0); + storeValues = CFAllocatorAllocate(NULL, storeCnt * sizeof(CFStringRef), 0); + CFDictionaryGetKeysAndValues(storeData, storeKeys, storeValues); + for (i=0; i 0)) { - CFDataRef xmlDict; /* key/value dictionary (XML serialized) */ - CFStringRef xmlError; - /* un-serialize the key/value pairs to set */ - xmlDict = CFDataCreate(NULL, dictRef, dictLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)dictRef, dictLen); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - dict = CFPropertyListCreateFromXMLData(NULL, - xmlDict, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlDict); - if (!dict) { - if (xmlError) { - SCLog(_configd_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() dict: %@"), - xmlError); - CFRelease(xmlError); - } + if (!_SCUnserialize((CFPropertyListRef *)&dict, (void *)dictRef, dictLen)) { *sc_status = kSCStatusFailed; - } else if (!isA_CFDictionary(dict)) { + } + + if (!isA_CFDictionary(dict)) { *sc_status = kSCStatusInvalidArgument; } } if (removeRef && (removeLen > 0)) { - CFDataRef xmlRemove; /* keys to remove (XML serialized) */ - CFStringRef xmlError; - /* un-serialize the keys to remove */ - xmlRemove = CFDataCreate(NULL, removeRef, removeLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)removeRef, removeLen); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - remove = CFPropertyListCreateFromXMLData(NULL, - xmlRemove, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlRemove); - if (!remove) { - if (xmlError) { - SCLog(_configd_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() remove: %@"), - xmlError); - CFRelease(xmlError); - } + if (!_SCUnserialize((CFPropertyListRef *)&remove, (void *)removeRef, removeLen)) { *sc_status = kSCStatusFailed; - } else if (!isA_CFArray(remove)) { + } + + if (!isA_CFArray(remove)) { *sc_status = kSCStatusInvalidArgument; } } if (notifyRef && (notifyLen > 0)) { - CFDataRef xmlNotify; /* keys to notify (XML serialized) */ - CFStringRef xmlError; - /* un-serialize the keys to notify */ - xmlNotify = CFDataCreate(NULL, notifyRef, notifyLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)notifyRef, notifyLen); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - notify = CFPropertyListCreateFromXMLData(NULL, - xmlNotify, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlNotify); - if (!notify) { - if (xmlError) { - SCLog(_configd_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() notify: %@"), - xmlError); - CFRelease(xmlError); - } + if (!_SCUnserialize((CFPropertyListRef *)¬ify, (void *)notifyRef, notifyLen)) { *sc_status = kSCStatusFailed; - } else if (!isA_CFArray(notify)) { + } + + if (!isA_CFArray(notify)) { *sc_status = kSCStatusInvalidArgument; } } diff --git a/configd.tproj/_configtouch.c b/configd.tproj/_configtouch.c index f241ad8..6835fbe 100644 --- a/configd.tproj/_configtouch.c +++ b/configd.tproj/_configtouch.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -70,7 +70,7 @@ __SCDynamicStoreTouchValue(SCDynamicStoreRef store, CFStringRef key) case kSCStatusOK : /* store entry exists */ - if (CFGetTypeID(value) == CFDateGetTypeID()) { + if (isA_CFDate(value)) { /* the value is a CFDate, update the time stamp */ CFRelease(value); value = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()); @@ -108,37 +108,20 @@ _configtouch(mach_port_t server, int *sc_status ) { - kern_return_t status; serverSessionRef mySession = getSession(server); - CFDataRef xmlKey; /* key (XML serialized) */ CFStringRef key; /* key (un-serialized) */ - CFStringRef xmlError; SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Touch key in configuration database.")); SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" server = %d"), server); /* un-serialize the key */ - xmlKey = CFDataCreate(NULL, keyRef, keyLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - key = CFPropertyListCreateFromXMLData(NULL, - xmlKey, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlKey); - if (!key) { - if (xmlError) { - SCLog(_configd_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() key: %@"), - xmlError); - CFRelease(xmlError); - } + if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) { *sc_status = kSCStatusFailed; return KERN_SUCCESS; - } else if (!isA_CFString(key)) { + } + + if (!isA_CFString(key)) { + CFRelease(key); *sc_status = kSCStatusInvalidArgument; return KERN_SUCCESS; } diff --git a/configd.tproj/_configunlock.c b/configd.tproj/_configunlock.c index 8cf247a..77a1d32 100644 --- a/configd.tproj/_configunlock.c +++ b/configd.tproj/_configunlock.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -40,9 +40,10 @@ static void _notifyWatchers() { CFIndex keyCnt; - void **keys; + const void **keys; - if ((keyCnt = CFSetGetCount(changedKeys)) == 0) + keyCnt = CFSetGetCount(changedKeys); + if (keyCnt == 0) return; /* if nothing to do */ keys = CFAllocatorAllocate(NULL, keyCnt * sizeof(CFStringRef), 0); @@ -51,7 +52,7 @@ _notifyWatchers() CFDictionaryRef dict; CFArrayRef sessionsWatchingKey; CFIndex watcherCnt; - void **watchers; + const void **watchers; CFDictionaryRef info; CFMutableDictionaryRef newInfo; CFArrayRef changes; @@ -69,52 +70,54 @@ _notifyWatchers() */ sessionsWatchingKey = CFDictionaryGetValue(dict, kSCDWatchers); watcherCnt = CFArrayGetCount(sessionsWatchingKey); - watchers = CFAllocatorAllocate(NULL, watcherCnt * sizeof(CFNumberRef), 0); - CFArrayGetValues(sessionsWatchingKey, - CFRangeMake(0, CFArrayGetCount(sessionsWatchingKey)), - watchers); - while (--watcherCnt >= 0) { - CFStringRef sessionKey; - - sessionKey = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@"), watchers[watcherCnt]); - info = CFDictionaryGetValue(sessionData, sessionKey); - if (info) { - newInfo = CFDictionaryCreateMutableCopy(NULL, 0, info); - } else { - newInfo = CFDictionaryCreateMutable(NULL, - 0, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); + if (watcherCnt > 0) { + watchers = CFAllocatorAllocate(NULL, watcherCnt * sizeof(CFNumberRef), 0); + CFArrayGetValues(sessionsWatchingKey, + CFRangeMake(0, CFArrayGetCount(sessionsWatchingKey)), + watchers); + while (--watcherCnt >= 0) { + CFStringRef sessionKey; + + sessionKey = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@"), watchers[watcherCnt]); + info = CFDictionaryGetValue(sessionData, sessionKey); + if (info) { + newInfo = CFDictionaryCreateMutableCopy(NULL, 0, info); + } else { + newInfo = CFDictionaryCreateMutable(NULL, + 0, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + } + + changes = CFDictionaryGetValue(newInfo, kSCDChangedKeys); + if (changes) { + newChanges = CFArrayCreateMutableCopy(NULL, 0, changes); + } else { + newChanges = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); + } + + if (CFArrayContainsValue(newChanges, + CFRangeMake(0, CFArrayGetCount(newChanges)), + (CFStringRef)keys[keyCnt]) == FALSE) { + CFArrayAppendValue(newChanges, (CFStringRef)keys[keyCnt]); + } + CFDictionarySetValue(newInfo, kSCDChangedKeys, newChanges); + CFRelease(newChanges); + CFDictionarySetValue(sessionData, sessionKey, newInfo); + CFRelease(newInfo); + CFRelease(sessionKey); + + /* + * flag this session as needing a kick + */ + if (needsNotification == NULL) + needsNotification = CFSetCreateMutable(NULL, + 0, + &kCFTypeSetCallBacks); + CFSetAddValue(needsNotification, watchers[watcherCnt]); } - - changes = CFDictionaryGetValue(newInfo, kSCDChangedKeys); - if (changes) { - newChanges = CFArrayCreateMutableCopy(NULL, 0, changes); - } else { - newChanges = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); - } - - if (CFArrayContainsValue(newChanges, - CFRangeMake(0, CFArrayGetCount(newChanges)), - (CFStringRef)keys[keyCnt]) == FALSE) { - CFArrayAppendValue(newChanges, (CFStringRef)keys[keyCnt]); - } - CFDictionarySetValue(newInfo, kSCDChangedKeys, newChanges); - CFRelease(newChanges); - CFDictionarySetValue(sessionData, sessionKey, newInfo); - CFRelease(newInfo); - CFRelease(sessionKey); - - /* - * flag this session as needing a kick - */ - if (needsNotification == NULL) - needsNotification = CFSetCreateMutable(NULL, - 0, - &kCFTypeSetCallBacks); - CFSetAddValue(needsNotification, watchers[watcherCnt]); + CFAllocatorDeallocate(NULL, watchers); } - CFAllocatorDeallocate(NULL, watchers); } CFAllocatorDeallocate(NULL, keys); @@ -132,9 +135,10 @@ static void _processDeferredRemovals() { CFIndex keyCnt; - void **keys; + const void **keys; - if ((keyCnt = CFSetGetCount(deferredRemovals)) == 0) + keyCnt = CFSetGetCount(deferredRemovals); + if (keyCnt == 0) return; /* if nothing to do */ keys = CFAllocatorAllocate(NULL, keyCnt * sizeof(CFStringRef), 0); @@ -142,7 +146,7 @@ _processDeferredRemovals() while (--keyCnt >= 0) { CFDictionaryApplyFunction(sessionData, (CFDictionaryApplierFunction)_removeRegexWatchersBySession, - keys[keyCnt]); + (void *)keys[keyCnt]); } CFAllocatorDeallocate(NULL, keys); diff --git a/configd.tproj/_notifyadd.c b/configd.tproj/_notifyadd.c index 56210cd..55b9268 100644 --- a/configd.tproj/_notifyadd.c +++ b/configd.tproj/_notifyadd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -179,6 +179,7 @@ __SCDynamicStoreAddWatchedKey(SCDynamicStoreRef store, CFStringRef key, Boolean CFRelease(newRData); CFDictionarySetValue(sessionData, sessionKey, newInfo); } + CFRelease(regexData); CFRelease(newInfo); CFRelease(sessionKey); } else { @@ -205,37 +206,20 @@ _notifyadd(mach_port_t server, int *sc_status ) { - kern_return_t status; serverSessionRef mySession = getSession(server); - CFDataRef xmlKey; /* key (XML serialized) */ CFStringRef key; /* key (un-serialized) */ - CFStringRef xmlError; SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Add notification key for this session.")); SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" server = %d"), server); /* un-serialize the key */ - xmlKey = CFDataCreate(NULL, keyRef, keyLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - key = CFPropertyListCreateFromXMLData(NULL, - xmlKey, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlKey); - if (!key) { - if (xmlError) { - SCLog(_configd_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() key: %@"), - xmlError); - CFRelease(xmlError); - } + if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) { *sc_status = kSCStatusFailed; return KERN_SUCCESS; - } else if (!isA_CFString(key)) { + } + + if (!isA_CFString(key)) { + CFRelease(key); *sc_status = kSCStatusInvalidArgument; return KERN_SUCCESS; } diff --git a/configd.tproj/_notifychanges.c b/configd.tproj/_notifychanges.c index 0cb0ed8..4d9595a 100644 --- a/configd.tproj/_notifychanges.c +++ b/configd.tproj/_notifychanges.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -80,40 +80,28 @@ _notifychanges(mach_port_t server, int *sc_status ) { - kern_return_t status; serverSessionRef mySession = getSession(server); CFArrayRef notifierKeys; /* array of CFStringRef's */ - CFDataRef xmlList; /* list (XML serialized) */ + Boolean ok; SCLog(_configd_verbose, LOG_DEBUG, CFSTR("List notification keys which have changed.")); SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" server = %d"), server); + *listRef = NULL; + *listLen = 0; + *sc_status = __SCDynamicStoreCopyNotifiedKeys(mySession->store, ¬ifierKeys); if (*sc_status != kSCStatusOK) { - *listRef = NULL; - *listLen = 0; return KERN_SUCCESS; } - /* - * serialize the array, copy it into an allocated buffer which will be - * released when it is returned as part of a Mach message. - */ - xmlList = CFPropertyListCreateXMLData(NULL, notifierKeys); + /* serialize the array of keys */ + ok = _SCSerialize(notifierKeys, NULL, (void **)listRef, (CFIndex *)listLen); CFRelease(notifierKeys); - *listLen = CFDataGetLength(xmlList); - status = vm_allocate(mach_task_self(), (void *)listRef, *listLen, TRUE); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_allocate(): %s"), mach_error_string(status)); - CFRelease(xmlList); - *listRef = NULL; - *listLen = 0; + if (!ok) { *sc_status = kSCStatusFailed; return KERN_SUCCESS; } - bcopy((char *)CFDataGetBytePtr(xmlList), *listRef, *listLen); - CFRelease(xmlList); - return KERN_SUCCESS; } diff --git a/configd.tproj/_notifyremove.c b/configd.tproj/_notifyremove.c index fb74607..5461ed9 100644 --- a/configd.tproj/_notifyremove.c +++ b/configd.tproj/_notifyremove.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -160,37 +160,20 @@ _notifyremove(mach_port_t server, int *sc_status ) { - kern_return_t status; serverSessionRef mySession = getSession(server); - CFDataRef xmlKey; /* key (XML serialized) */ CFStringRef key; /* key (un-serialized) */ - CFStringRef xmlError; SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Remove notification key for this session.")); SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" server = %d"), server); /* un-serialize the key */ - xmlKey = CFDataCreate(NULL, keyRef, keyLen); - status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen); - if (status != KERN_SUCCESS) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status)); - /* non-fatal???, proceed */ - } - key = CFPropertyListCreateFromXMLData(NULL, - xmlKey, - kCFPropertyListImmutable, - &xmlError); - CFRelease(xmlKey); - if (!key) { - if (xmlError) { - SCLog(_configd_verbose, LOG_DEBUG, - CFSTR("CFPropertyListCreateFromXMLData() key: %@"), - xmlError); - CFRelease(xmlError); - } + if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) { *sc_status = kSCStatusFailed; return KERN_SUCCESS; - } else if (!isA_CFString(key)) { + } + + if (!isA_CFString(key)) { + CFRelease(key); *sc_status = kSCStatusInvalidArgument; return KERN_SUCCESS; } diff --git a/configd.tproj/_notifyviasignal.c b/configd.tproj/_notifyviasignal.c index bbe43ee..7c9b35f 100644 --- a/configd.tproj/_notifyviasignal.c +++ b/configd.tproj/_notifyviasignal.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -54,7 +54,7 @@ __SCDynamicStoreNotifySignal(SCDynamicStoreRef store, pid_t pid, int sig) if (pid == getpid()) { /* sorry, you can't request that configd be signalled */ - return kSCStatusFailed; + return kSCStatusInvalidArgument; } if ((sig <= 0) || (sig > NSIG)) { diff --git a/configd.tproj/_snapshot.c b/configd.tproj/_snapshot.c index 68e8509..9f6764f 100644 --- a/configd.tproj/_snapshot.c +++ b/configd.tproj/_snapshot.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -69,6 +69,11 @@ __SCDynamicStoreSnapshot(SCDynamicStoreRef store) } xmlData = CFPropertyListCreateXMLData(NULL, storeData); + if (!xmlData) { + SCLog(TRUE, LOG_ERR, CFSTR("CFPropertyListCreateXMLData() failed")); + close(fd); + return kSCStatusFailed; + } (void) write(fd, CFDataGetBytePtr(xmlData), CFDataGetLength(xmlData)); (void) close(fd); CFRelease(xmlData); @@ -84,6 +89,11 @@ __SCDynamicStoreSnapshot(SCDynamicStoreRef store) /* Save a snapshot of the "session" data */ xmlData = CFPropertyListCreateXMLData(NULL, sessionData); + if (!xmlData) { + SCLog(TRUE, LOG_ERR, CFSTR("CFPropertyListCreateXMLData() failed")); + close(fd); + return kSCStatusFailed; + } (void) write(fd, CFDataGetBytePtr(xmlData), CFDataGetLength(xmlData)); (void) close(fd); CFRelease(xmlData); diff --git a/configd.tproj/config.defs b/configd.tproj/config.defs index cc2513a..0d4056a 100644 --- a/configd.tproj/config.defs +++ b/configd.tproj/config.defs @@ -15,4 +15,4 @@ * As such... IF YOU CHANGE THE ".defs" FILE, MAKE CLEAN! */ -#import "../SystemConfiguration.fproj/config.defs" \ No newline at end of file +#include diff --git a/configd.tproj/configd.m b/configd.tproj/configd.m index 55caa0b..3a4658f 100644 --- a/configd.tproj/configd.m +++ b/configd.tproj/configd.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -44,8 +44,8 @@ #include "configd_server.h" #include "plugin_support.h" -Boolean _configd_fork = TRUE; /* TRUE if process should be run in the background */ -Boolean _configd_verbose = FALSE; /* TRUE if verbose logging enabled */ +Boolean _configd_fork = TRUE; /* TRUE if process should be run in the background */ +Boolean _configd_verbose = FALSE; /* TRUE if verbose logging enabled */ CFMutableSetRef _plugins_exclude = NULL; /* bundle identifiers to exclude from loading */ CFMutableSetRef _plugins_verbose = NULL; /* bundle identifiers to enable verbose logging */ @@ -139,19 +139,47 @@ fork_child() (void) chdir("/"); - if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { + fd = open(_PATH_DEVNULL, O_RDWR, 0); + if (fd != -1) { + int ofd; + + // stdin (void) dup2(fd, STDIN_FILENO); + + // stdout, stderr + ofd = open("/var/log/configd.log", O_WRONLY|O_APPEND, 0); + if (ofd != -1) { + if (fd > STDIN_FILENO) { + (void) close(fd); + } + fd = ofd; + } (void) dup2(fd, STDOUT_FILENO); (void) dup2(fd, STDERR_FILENO); - if (fd > 2) + if (fd > STDERR_FILENO) { (void) close(fd); + } } return 0; } + +static void +writepid(void) +{ + FILE *fp; + + fp = fopen("/var/run/configd.pid", "w"); + if (fp != NULL) { + fprintf(fp, "%d\n", getpid()); + fclose(fp); + } +} + + int -main(int argc, const char *argv[]) +main(int argc, char * const argv[]) { Boolean loadBundles = TRUE; struct sigaction nact; @@ -224,6 +252,11 @@ main(int argc, const char *argv[]) /* now the child process, parent waits in fork_child */ } + /* record process id */ + if (testBundle == NULL) { + writepid(); + } + /* open syslog() facility */ if (_configd_fork) { int logopt = LOG_NDELAY|LOG_PID; diff --git a/configd.tproj/configd_server.c b/configd.tproj/configd_server.c index d589c69..c009c55 100644 --- a/configd.tproj/configd_server.c +++ b/configd.tproj/configd_server.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -199,9 +199,15 @@ configdCallback(CFMachPortRef port, void *msg, CFIndex size, void *info) boolean_t server_active() { - kern_return_t status; - mach_port_t bootstrap_port; boolean_t active; + mach_port_t bootstrap_port; + char *server_name; + kern_return_t status; + + server_name = getenv("SCD_SERVER"); + if (!server_name) { + server_name = SCD_SERVER; + } /* Getting bootstrap server port */ status = task_get_bootstrap_port(mach_task_self(), &bootstrap_port); @@ -212,12 +218,12 @@ server_active() } /* Check "configd" server status */ - status = bootstrap_status(bootstrap_port, SCD_SERVER, &active); + status = bootstrap_status(bootstrap_port, server_name, &active); switch (status) { case BOOTSTRAP_SUCCESS : if (active) { fprintf(stderr, "configd: '%s' server already active\n", - SCD_SERVER); + server_name); return TRUE; } break; @@ -234,10 +240,16 @@ server_active() void server_init() { - kern_return_t status; - mach_port_t bootstrap_port; boolean_t active; + mach_port_t bootstrap_port; CFRunLoopSourceRef rls; + char *server_name; + kern_return_t status; + + server_name = getenv("SCD_SERVER"); + if (!server_name) { + server_name = SCD_SERVER; + } /* Getting bootstrap server port */ status = task_get_bootstrap_port(mach_task_self(), &bootstrap_port); @@ -247,11 +259,11 @@ server_init() } /* Check "configd" server status */ - status = bootstrap_status(bootstrap_port, SCD_SERVER, &active); + status = bootstrap_status(bootstrap_port, server_name, &active); switch (status) { case BOOTSTRAP_SUCCESS : if (active) { - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("\"%s\" is currently active, exiting."), SCD_SERVER); + SCLog(_configd_verbose, LOG_DEBUG, CFSTR("\"%s\" is currently active, exiting."), server_name); exit (EX_UNAVAILABLE); } break; @@ -281,8 +293,8 @@ server_init() /* Create a session for the primary / new connection port */ (void) addSession(configd_port); - SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Registering service \"%s\""), SCD_SERVER); - status = bootstrap_register(bootstrap_port, SCD_SERVER, CFMachPortGetPort(configd_port)); + SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Registering service \"%s\""), server_name); + status = bootstrap_register(bootstrap_port, server_name, CFMachPortGetPort(configd_port)); switch (status) { case BOOTSTRAP_SUCCESS : /* service not currently registered, "a good thing" (tm) */ diff --git a/configd.tproj/notify.c b/configd.tproj/notify.c index 3248c92..37a3259 100644 --- a/configd.tproj/notify.c +++ b/configd.tproj/notify.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -41,7 +41,7 @@ void pushNotifications() { - void **sessionsToNotify; + const void **sessionsToNotify; CFIndex notifyCnt; int server; serverSessionRef theSession; diff --git a/configd.tproj/plugin_support.c b/configd.tproj/plugin_support.c index b511a89..1f92749 100644 --- a/configd.tproj/plugin_support.c +++ b/configd.tproj/plugin_support.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -43,6 +43,7 @@ #include "configd.h" #include +void _SCDPluginExecInit(); /* @@ -277,12 +278,12 @@ loadBundle(const void *value, void *context) { } if (!bundleVerbose) { - dict = CFBundleGetInfoDictionary(bundle); - if (isA_CFDictionary(dict)) { - CFBooleanRef bool; + dict = CFBundleGetInfoDictionary(bundle); + if (isA_CFDictionary(dict)) { + CFBooleanRef bVal; - bool = CFDictionaryGetValue(dict, kSCBundleVerbose); - if (isA_CFBoolean(bool) && CFBooleanGetValue(bool)) { + bVal = CFDictionaryGetValue(dict, kSCBundleVerbose); + if (isA_CFBoolean(bVal) && CFBooleanGetValue(bVal)) { bundleVerbose = TRUE; } } @@ -381,6 +382,8 @@ primeBundle(const void *value, void *context) { } +#ifdef DEBUG + static void timerCallback(CFRunLoopTimerRef timer, void *info) { @@ -390,6 +393,8 @@ timerCallback(CFRunLoopTimerRef timer, void *info) return; } +#endif /* DEBUG */ + static void sortBundles(CFMutableArrayRef orig) @@ -402,7 +407,7 @@ sortBundles(CFMutableArrayRef orig) Boolean inserted = FALSE; for (i = 0; i < CFArrayGetCount(orig); i++) { - CFBundleRef bundle1 = CFArrayGetValueAtIndex(orig, i); + CFBundleRef bundle1 = (CFBundleRef)CFArrayGetValueAtIndex(orig, i); CFStringRef bundleID1 = CFBundleGetIdentifier(bundle1); int count; CFDictionaryRef dict; @@ -426,7 +431,7 @@ sortBundles(CFMutableArrayRef orig) CFStringRef r = CFArrayGetValueAtIndex(requires, j); for (k = 0; k < CFArrayGetCount(new); k++) { - CFBundleRef bundle2 = CFArrayGetValueAtIndex(new, k); + CFBundleRef bundle2 = (CFBundleRef)CFArrayGetValueAtIndex(new, k); CFStringRef bundleID2 = CFBundleGetIdentifier(bundle2); if (bundleID2 && CFEqual(bundleID2, r)) { @@ -471,6 +476,9 @@ plugin_exec(void *arg) /* keep track of bundles */ allBundles = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); + /* allow plug-ins to exec child/helper processes */ + _SCDPluginExecInit(); + if (arg == NULL) { char path[MAXPATHLEN]; NSSearchPathEnumerationState state; @@ -569,20 +577,22 @@ plugin_exec(void *arg) primeBundle, NULL); +#ifdef DEBUG if (arg == NULL && (nLoaded > 0)) { CFRunLoopTimerRef timer; /* allocate a periodic event (to help show we're not blocking) */ - timer = CFRunLoopTimerCreate(NULL, /* allocator */ - CFAbsoluteTimeGetCurrent() + 1.0, /* fireDate */ - 60.0, /* interval */ - 0, /* flags */ - 0, /* order */ - timerCallback, /* callout */ - NULL); /* context */ - CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopDefaultMode); - CFRelease(timer); - } + timer = CFRunLoopTimerCreate(NULL, /* allocator */ + CFAbsoluteTimeGetCurrent() + 1.0, /* fireDate */ + 60.0, /* interval */ + 0, /* flags */ + 0, /* order */ + timerCallback, /* callout */ + NULL); /* context */ + CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopDefaultMode); + CFRelease(timer); + } +#endif /* DEBUG */ if (_configd_fork) { /* synchronize with parent process */ diff --git a/preferences.xml b/preferences.xml new file mode 100644 index 0000000..9138585 --- /dev/null +++ b/preferences.xml @@ -0,0 +1,139 @@ + + + + + CurrentSet + /Sets/0 + NetworkServices + + 0 + + AppleTalk + + ConfigMethod + Node + __INACTIVE__ + 1 + + DNS + + Ethernet + + + IPv4 + + ConfigMethod + DHCP + + Interface + + DeviceName + en0 + Hardware + Ethernet + Type + Ethernet + UserDefinedName + Built-in Ethernet + + PPP + + CommDisplayTerminalWindow + 0 + CommRedialCount + 1 + CommRedialEnabled + 1 + CommRedialInterval + 30 + DialOnDemand + 0 + DisconnectOnIdle + 1 + DisconnectOnIdleTimer + 600 + DisconnectOnLogout + 0 + IPCPCompressionVJ + 1 + IdleReminder + 1 + IdleReminderTimer + 900 + LCPEchoEnabled + 1 + LCPEchoFailure + 4 + LCPEchoInterval + 10 + Logfile + /tmp/ppp.log + VerboseLogging + 0 + __INACTIVE__ + 1 + + Proxies + + FTPEnable + 0 + FTPPassive + 1 + GopherEnable + 0 + HTTPEnable + 0 + HTTPSEnable + 0 + RTSPEnable + 0 + SOCKSEnable + 0 + + UserDefinedName + Built-in Ethernet + + + Sets + + 0 + + Network + + Global + + IPv4 + + PPPOverridePrimary + 0 + ServiceOrder + + 0 + + + NetInfo + + BindingMethods + + DHCP + + + + Service + + 0 + + __LINK__ + /NetworkServices/0 + + + + UserDefinedName + Automatic + + + System + + + + diff --git a/scselect.tproj/Makefile b/scselect.tproj/Makefile index 87fc31c..9bf1aa4 100644 --- a/scselect.tproj/Makefile +++ b/scselect.tproj/Makefile @@ -29,7 +29,6 @@ DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) -NEXTSTEP_PB_CFLAGS = -DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS FRAMEWORKS = -framework CoreFoundation -framework SystemConfiguration diff --git a/scselect.tproj/PB.project b/scselect.tproj/PB.project index 32e4349..7521741 100644 --- a/scselect.tproj/PB.project +++ b/scselect.tproj/PB.project @@ -13,7 +13,6 @@ LANGUAGE = English; MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; NEXTSTEP_BUILDTOOL = /usr/bin/gnumake; - NEXTSTEP_COMPILEROPTIONS = "-DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS"; NEXTSTEP_INSTALLDIR = /usr/sbin; NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; diff --git a/scselect.tproj/scselect.c b/scselect.tproj/scselect.c index 7abf11e..ec6b6a3 100644 --- a/scselect.tproj/scselect.c +++ b/scselect.tproj/scselect.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -61,8 +61,8 @@ main(int argc, char **argv) SCPreferencesRef session; CFDictionaryRef sets; CFIndex nSets; - void **setKeys; - void **setVals; + const void **setKeys = NULL; + const void **setVals = NULL; CFIndex i; /* process any arguments */ @@ -139,9 +139,11 @@ main(int argc, char **argv) } nSets = CFDictionaryGetCount(sets); - setKeys = CFAllocatorAllocate(NULL, nSets * sizeof(CFStringRef), 0); - setVals = CFAllocatorAllocate(NULL, nSets * sizeof(CFDictionaryRef), 0); - CFDictionaryGetKeysAndValues(sets, setKeys, setVals); + if (nSets > 0) { + setKeys = CFAllocatorAllocate(NULL, nSets * sizeof(CFStringRef), 0); + setVals = CFAllocatorAllocate(NULL, nSets * sizeof(CFDictionaryRef), 0); + CFDictionaryGetKeysAndValues(sets, setKeys, setVals); + } /* check for set with matching name */ for (i=0; i= NSIG) { @@ -358,7 +360,7 @@ do_notify_signal(int argc, char **argv) str = CFStringCreateMutable(NULL, 0); for (sig=1; sig 0) { - SCPrint(TRUE, stdout, CFSTR("%d> %s"), nesting, line); + SCPrint(TRUE, stdout, CFSTR("%d> %s\n"), nesting, line); } /* if requested, exit */ @@ -246,7 +246,7 @@ usage(const char *command) int -main(int argc, const char *argv[]) +main(int argc, char * const argv[]) { CFSocketContext context = { 0, stdin, NULL, NULL, NULL }; char *dest = NULL; @@ -285,7 +285,7 @@ main(int argc, const char *argv[]) case '?': default : usage(prog); - } + } argc -= optind; argv += optind; diff --git a/scutil.tproj/scutil.h b/scutil.tproj/scutil.h index ebeae2e..c853556 100644 --- a/scutil.tproj/scutil.h +++ b/scutil.tproj/scutil.h @@ -36,6 +36,7 @@ #include #include +#include #include -- 2.47.2