From 6d034b4e690f5685bd021f180be34577ec6672af Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 12 Feb 2008 09:14:35 +0000 Subject: [PATCH] configd-210.tar.gz --- Plugins/ATconfig/Info.plist | 6 +- Plugins/IPMonitor/Info.plist | 6 +- Plugins/InterfaceNamer/Info.plist | 6 +- Plugins/KernelEventMonitor/Info.plist | 6 +- Plugins/Kicker/Info.plist | 6 +- Plugins/LinkConfiguration/Info.plist | 6 +- Plugins/NetworkIdentification/Info.plist | 6 +- Plugins/PreferencesMonitor/Info.plist | 6 +- SCMonitor/English.lproj/Localizable.strings | Bin 0 -> 964 bytes SCMonitor/Info.plist | 40 ++ SCMonitor/monitor.c | 601 ++++++++++++++++++ .../English.lproj/NetworkInterface.strings | Bin 3236 -> 3552 bytes SystemConfiguration.fproj/Info.plist | 8 +- .../SCNetworkConfigurationInternal.h | 3 + .../SCNetworkConfigurationPrivate.h | 20 + .../SCNetworkInterface.c | 36 +- SystemConfiguration.fproj/SCNetworkService.c | 116 +++- SystemConfiguration.fproj/SCNetworkSet.c | 169 ++++- SystemConfiguration.fproj/SCPLock.c | 74 ++- SystemConfiguration.fproj/SCPOpen.c | 39 +- .../helper/SCHelper_client.h | 3 +- .../helper/SCHelper_server.c | 26 +- configd.xcodeproj/project.pbxproj | 167 ++++- scutil.tproj/commands.c | 3 + scutil.tproj/prefs.c | 9 + scutil.tproj/prefs.h | 3 +- 26 files changed, 1231 insertions(+), 134 deletions(-) create mode 100644 SCMonitor/English.lproj/Localizable.strings create mode 100644 SCMonitor/Info.plist create mode 100644 SCMonitor/monitor.c diff --git a/Plugins/ATconfig/Info.plist b/Plugins/ATconfig/Info.plist index 44bafb2..93463cf 100644 --- a/Plugins/ATconfig/Info.plist +++ b/Plugins/ATconfig/Info.plist @@ -1,5 +1,5 @@ - + CFBundleDevelopmentRegion @@ -15,11 +15,11 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.9.0 + 1.9.1 CFBundleSignature ???? CFBundleVersion - 0.0.1d1 + 1.9.1 Builtin Requires diff --git a/Plugins/IPMonitor/Info.plist b/Plugins/IPMonitor/Info.plist index deba332..34dd24f 100644 --- a/Plugins/IPMonitor/Info.plist +++ b/Plugins/IPMonitor/Info.plist @@ -1,5 +1,5 @@ - + CFBundleDevelopmentRegion @@ -15,11 +15,11 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.9.0 + 1.9.1 CFBundleSignature ???? CFBundleVersion - 0.0.1d1 + 1.9.1 Requires com.apple.SystemConfiguration.IPConfiguration diff --git a/Plugins/InterfaceNamer/Info.plist b/Plugins/InterfaceNamer/Info.plist index a0de58f..db1a7b0 100644 --- a/Plugins/InterfaceNamer/Info.plist +++ b/Plugins/InterfaceNamer/Info.plist @@ -1,5 +1,5 @@ - + CFBundleDevelopmentRegion @@ -15,11 +15,11 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.9.0 + 1.9.1 CFBundleSignature ???? CFBundleVersion - 0.0.1d1 + 1.9.1 Builtin diff --git a/Plugins/KernelEventMonitor/Info.plist b/Plugins/KernelEventMonitor/Info.plist index d0cb258..fa16b15 100644 --- a/Plugins/KernelEventMonitor/Info.plist +++ b/Plugins/KernelEventMonitor/Info.plist @@ -1,5 +1,5 @@ - + CFBundleDevelopmentRegion @@ -15,11 +15,11 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.9.0 + 1.9.1 CFBundleSignature ???? CFBundleVersion - 0.0.1d1 + 1.9.1 Requires com.apple.SystemConfiguration.InterfaceNamer diff --git a/Plugins/Kicker/Info.plist b/Plugins/Kicker/Info.plist index bc42eb3..5102cde 100644 --- a/Plugins/Kicker/Info.plist +++ b/Plugins/Kicker/Info.plist @@ -1,5 +1,5 @@ - + CFBundleDevelopmentRegion @@ -15,11 +15,11 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.9.0 + 1.9.1 CFBundleSignature ???? CFBundleVersion - 0.0.1d1 + 1.9.1 Requires com.apple.SystemConfiguration.ATconfig diff --git a/Plugins/LinkConfiguration/Info.plist b/Plugins/LinkConfiguration/Info.plist index abac7dc..34a5eff 100644 --- a/Plugins/LinkConfiguration/Info.plist +++ b/Plugins/LinkConfiguration/Info.plist @@ -1,5 +1,5 @@ - + CFBundleDevelopmentRegion @@ -15,11 +15,11 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.9.0 + 1.9.1 CFBundleSignature ???? CFBundleVersion - 0.0.1d1 + 1.9.1 Requires com.apple.SystemConfiguration.InterfaceNamer diff --git a/Plugins/NetworkIdentification/Info.plist b/Plugins/NetworkIdentification/Info.plist index 4a4623e..b7a9070 100644 --- a/Plugins/NetworkIdentification/Info.plist +++ b/Plugins/NetworkIdentification/Info.plist @@ -1,5 +1,5 @@ - + CFBundleDevelopmentRegion @@ -15,11 +15,11 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.9.0 + 1.9.1 CFBundleSignature ???? CFBundleVersion - 0.0.1d1 + 1.9.1 Builtin diff --git a/Plugins/PreferencesMonitor/Info.plist b/Plugins/PreferencesMonitor/Info.plist index d0b4485..0061104 100644 --- a/Plugins/PreferencesMonitor/Info.plist +++ b/Plugins/PreferencesMonitor/Info.plist @@ -1,5 +1,5 @@ - + CFBundleDevelopmentRegion @@ -15,11 +15,11 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.9.0 + 1.9.1 CFBundleSignature ???? CFBundleVersion - 0.0.1d1 + 1.9.1 Builtin Requires diff --git a/SCMonitor/English.lproj/Localizable.strings b/SCMonitor/English.lproj/Localizable.strings new file mode 100644 index 0000000000000000000000000000000000000000..bc1126f6f1db85db535961cc50786f2e528a5c72 GIT binary patch literal 964 zcmbu8K~DlP5QX2_U(s;zWK2984`d~B&_dKB2~k+YNLa$I`tQ|mT7km4iXqLmvz^Y& zoA=s}PaUbHt~zS#lKECcow4J>xL|JKahfaF`}bO56JH2WFS_h7TIo)+cOzGb`t+Q~#Zb5A9--m1)*81?3!G4KH+TVW^iPd)%nb6;iQGmqye + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + com.apple.SystemConfiguration.${EXECUTABLE_NAME} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${EXECUTABLE_NAME} + CFBundlePackageType + BNDL + CFBundleSignature + ???? + CFBundleShortVersionString + 1.9.1 + CFBundleVersion + 1.9.1 + CFPlugInDynamicRegistration + NO + CFPlugInFactories + + FB86416D-6164-2070-726F-70735C216EC0 + UserEventAgentFactory + + CFPlugInTypes + + FC86416D-6164-2070-726F-70735C216EC0 + + FB86416D-6164-2070-726F-70735C216EC0 + + + CFPlugInUnloadFunction + + + diff --git a/SCMonitor/monitor.c b/SCMonitor/monitor.c new file mode 100644 index 0000000..6ff25d6 --- /dev/null +++ b/SCMonitor/monitor.c @@ -0,0 +1,601 @@ +/* + * Copyright (c) 2007 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * Modification History + * + * October 24, 2007 Allan Nathanson + * - initial revision + */ + +#include +#include +#include +#include +#include +#include +#include +#include "UserEventAgentInterface.h" + +#define MY_BUNDLE_ID CFSTR("com.apple.SystemConfiguration.SCMonitor") +#define MY_ICON_PATH "/System/Library/PreferencePanes/Network.prefPane/Contents/Resources/Network.icns" + +#define NETWORK_PREF_APP "/System/Library/PreferencePanes/Network.prefPane" +#define NETWORK_PREF_CMD "New Interface" + +typedef struct { + UserEventAgentInterfaceStruct *_UserEventAgentInterface; + CFUUIDRef _factoryID; + UInt32 _refCount; + + CFRunLoopSourceRef monitorRls; + + CFMutableSetRef knownInterfaces; + + CFMutableArrayRef userInterfaces; + CFUserNotificationRef userNotification; + CFRunLoopSourceRef userRls; +} MyType; + +static CFMutableDictionaryRef notify_to_instance = NULL; + + +#pragma mark - +#pragma mark Watch for new [network] interfaces + + +static void +open_NetworkPrefPane(void) +{ + AEDesc aeDesc = { typeNull, NULL }; + CFArrayRef prefArray; + CFURLRef prefURL; + LSLaunchURLSpec prefSpec; + OSStatus status; + + prefURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, + CFSTR(NETWORK_PREF_APP), + kCFURLPOSIXPathStyle, + FALSE); + prefArray = CFArrayCreate(NULL, (const void **)&prefURL, 1, &kCFTypeArrayCallBacks); + CFRelease(prefURL); + + status = AECreateDesc('ptru', + (const void *)NETWORK_PREF_CMD, + strlen(NETWORK_PREF_CMD), + &aeDesc); + if (status != noErr) { + SCLog(TRUE, LOG_ERR, CFSTR("SCMonitor: AECreateDesc() failed: %d"), status); + } + + prefSpec.appURL = NULL; + prefSpec.itemURLs = prefArray; + prefSpec.passThruParams = &aeDesc; + prefSpec.launchFlags = kLSLaunchAsync | kLSLaunchDontAddToRecents; + prefSpec.asyncRefCon = NULL; + + status = LSOpenFromURLSpec(&prefSpec, NULL); + if (status != noErr) { + SCLog(TRUE, LOG_ERR, CFSTR("SCMonitor: LSOpenFromURLSpec() failed: %d"), status); + } + + CFRelease(prefArray); + if (aeDesc.descriptorType != typeNull) AEDisposeDesc(&aeDesc); + return; +} + + +static void +notify_remove(MyType *myInstance, Boolean cancel) +{ + if (myInstance->userInterfaces != NULL) { + CFRelease(myInstance->userInterfaces); + myInstance->userInterfaces = NULL; + } + + if (myInstance->userRls != NULL) { + CFRunLoopSourceInvalidate(myInstance->userRls); + CFRelease(myInstance->userRls); + myInstance->userRls = NULL; + } + + if (myInstance->userNotification != NULL) { + if (cancel) { + SInt32 status; + + status = CFUserNotificationCancel(myInstance->userNotification); + if (status != 0) { + SCLog(TRUE, LOG_ERR, + CFSTR("SCMonitor: CFUserNotificationCancel() failed, status=%d"), + status); + } + } + CFRelease(myInstance->userNotification); + myInstance->userNotification = NULL; + } + + return; +} + + +static void +notify_reply(CFUserNotificationRef userNotification, CFOptionFlags response_flags) +{ + MyType *myInstance = NULL; + + // get instance for notification + if (notify_to_instance != NULL) { + myInstance = (MyType *)CFDictionaryGetValue(notify_to_instance, userNotification); + if (myInstance != NULL) { + CFDictionaryRemoveValue(notify_to_instance, userNotification); + if (CFDictionaryGetCount(notify_to_instance) == 0) { + CFRelease(notify_to_instance); + notify_to_instance = NULL; + } + } + } + if (myInstance == NULL) { + SCLog(TRUE, LOG_ERR, CFSTR("SCMonitor: can't find user notification")); + return; + } + + // process response + switch (response_flags & 0x3) { + case kCFUserNotificationDefaultResponse: + // user asked to configure interface + open_NetworkPrefPane(); + break; + default: + // user cancelled + break; + } + + notify_remove(myInstance, FALSE); + return; +} + +static void +notify_add(MyType *myInstance) +{ + CFBundleRef bundle; + CFMutableDictionaryRef dict = NULL; + SInt32 error = 0; + CFIndex i; + CFMutableArrayRef message; + CFIndex n = CFArrayGetCount(myInstance->userInterfaces); + CFURLRef url = NULL; + + if (myInstance->userNotification != NULL) { + CFMutableArrayRef save = NULL; + + if (n > 0) { + CFRetain(myInstance->userInterfaces); + save = myInstance->userInterfaces; + } + notify_remove(myInstance, TRUE); + myInstance->userInterfaces = save; + if (n == 0) { + return; + } + } + + dict = CFDictionaryCreateMutable(NULL, + 0, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + + // set localization URL + bundle = CFBundleGetBundleWithIdentifier(MY_BUNDLE_ID); + if (bundle != NULL) { + url = CFBundleCopyBundleURL(bundle); + } + if (url != NULL) { + // set URL + CFDictionarySetValue(dict, kCFUserNotificationLocalizationURLKey, url); + CFRelease(url); + } else { + SCLog(TRUE, LOG_NOTICE, CFSTR("SCMonitor: can't find bundle")); + goto done; + } + + // set icon URL + url = CFURLCreateFromFileSystemRepresentation(NULL, + (const UInt8 *)MY_ICON_PATH, + strlen(MY_ICON_PATH), + FALSE); + if (url != NULL) { + CFDictionarySetValue(dict, kCFUserNotificationIconURLKey, url); + CFRelease(url); + } + + // header + CFDictionarySetValue(dict, + kCFUserNotificationAlertHeaderKey, + (n == 1) ? CFSTR("HEADER_1") : CFSTR("HEADER_N")); + + // message + message = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); + CFArrayAppendValue(message, + (n == 1) ? CFSTR("MESSAGE_S1") : CFSTR("MESSAGE_SN")); + for (i = 0; i < n; i++) { + SCNetworkInterfaceRef interface; + CFStringRef name; + + interface = CFArrayGetValueAtIndex(myInstance->userInterfaces, i); + name = SCNetworkInterfaceGetLocalizedDisplayName(interface); + if (n == 1) { + CFArrayAppendValue(message, name); + } else { + CFStringRef str; + + str = CFStringCreateWithFormat(NULL, NULL, CFSTR("\r\t%@"), name); + CFArrayAppendValue(message, str); + CFRelease(str); + } + } + CFArrayAppendValue(message, + (n == 1) ? CFSTR("MESSAGE_E1") : CFSTR("MESSAGE_EN")); + CFDictionarySetValue(dict, kCFUserNotificationAlertMessageKey, message); + CFRelease(message); + + // button titles + CFDictionaryAddValue(dict, kCFUserNotificationDefaultButtonTitleKey, CFSTR("OPEN_NP")); + CFDictionaryAddValue(dict, kCFUserNotificationAlternateButtonTitleKey, CFSTR("CANCEL")); + + // create and post notification + myInstance->userNotification = CFUserNotificationCreate(NULL, + 0, + kCFUserNotificationNoteAlertLevel, + &error, + dict); + if (myInstance->userNotification == NULL) { + SCLog(TRUE, LOG_ERR, CFSTR("SCMonitor: CFUserNotificationCreate() failed, %d"), error); + goto done; + } + + // establish callback + myInstance->userRls = CFUserNotificationCreateRunLoopSource(NULL, + myInstance->userNotification, + notify_reply, + 0); + if (myInstance->userRls == NULL) { + SCLog(TRUE, LOG_ERR, CFSTR("SCMonitor: CFUserNotificationCreateRunLoopSource() failed")); + CFRelease(myInstance->userNotification); + myInstance->userNotification = NULL; + goto done; + } + CFRunLoopAddSource(CFRunLoopGetCurrent(), myInstance->userRls, kCFRunLoopDefaultMode); + + // add instance for notification + if (notify_to_instance == NULL) { + notify_to_instance = CFDictionaryCreateMutable(NULL, + 0, + &kCFTypeDictionaryKeyCallBacks, + NULL); // no retain/release/... for values + } + CFDictionarySetValue(notify_to_instance, myInstance->userNotification, myInstance); + + done : + + if (dict != NULL) CFRelease(dict); + return; +} + + +static void +updateInterfaceList(SCDynamicStoreRef store, CFArrayRef changes, void * arg) +{ + CFIndex i; + CFArrayRef interfaces; + MyType *myInstance = (MyType *)arg; + CFIndex n; + SCPreferencesRef prefs; + CFMutableSetRef previouslyKnown = NULL; + SCNetworkSetRef set = NULL; + + prefs = SCPreferencesCreate(NULL, CFSTR("SCMonitor"), NULL); + if (prefs == NULL) { + return; + } + + set = SCNetworkSetCopyCurrent(prefs); + if (set == NULL) { + set = SCNetworkSetCreate(prefs); + if (set == NULL) { + goto done; + } + } + + previouslyKnown = CFSetCreateMutableCopy(NULL, 0, myInstance->knownInterfaces); + + interfaces = SCNetworkInterfaceCopyAll(); + if (interfaces != NULL) { + + n = CFArrayGetCount(interfaces); + for (i = 0; i < n; i++) { + CFStringRef bsdName; + SCNetworkInterfaceRef interface; + Boolean ok; + + interface = CFArrayGetValueAtIndex(interfaces, i); + bsdName = SCNetworkInterfaceGetBSDName(interface); + if (bsdName == NULL) { + // if no BSD name + continue; + } + + CFSetRemoveValue(previouslyKnown, bsdName); + + if (CFSetContainsValue(myInstance->knownInterfaces, bsdName)) { + // if known interface + continue; + } + + CFSetAddValue(myInstance->knownInterfaces, bsdName); + + ok = SCNetworkSetEstablishDefaultInterfaceConfiguration(set, interface); + if (ok) { + // this is a *new* interface + if (myInstance->userInterfaces == NULL) { + myInstance->userInterfaces = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); + } + CFArrayAppendValue(myInstance->userInterfaces, interface); + } + } + + CFRelease(interfaces); + } + + n = CFSetGetCount(previouslyKnown); + if (n > 0) { + const void * names_q[32]; + const void ** names = names_q; + + if (n > (CFIndex)(sizeof(names_q) / sizeof(CFTypeRef))) + names = CFAllocatorAllocate(NULL, n * sizeof(CFTypeRef), 0); + CFSetGetValues(previouslyKnown, names); + for (i = 0; i < n; i++) { + if (myInstance->userInterfaces != NULL) { + CFIndex j; + + j = CFArrayGetCount(myInstance->userInterfaces); + while (--j >= 0) { + CFStringRef bsdName; + SCNetworkInterfaceRef interface; + + interface = CFArrayGetValueAtIndex(myInstance->userInterfaces, j); + bsdName = SCNetworkInterfaceGetBSDName(interface); + if (CFEqual(bsdName, names[i])) { + // if we have previously posted a notification + // for this no-longer-present interface + CFArrayRemoveValueAtIndex(myInstance->userInterfaces, j); + } + } + } + + CFSetRemoveValue(myInstance->knownInterfaces, names[i]); + } + if (names != names_q) CFAllocatorDeallocate(NULL, names); + } + + done : + + // post notification + if (myInstance->userInterfaces != NULL) { + notify_add(myInstance); + } + + if (set != NULL) CFRelease(set); + CFRelease(prefs); + return; +} + + +static void +watcher_remove(MyType *myInstance) +{ + if (myInstance->monitorRls != NULL) { + CFRunLoopSourceInvalidate(myInstance->monitorRls); + CFRelease(myInstance->monitorRls); + myInstance->monitorRls = NULL; + } + + if (myInstance->knownInterfaces != NULL) { + CFRelease(myInstance->knownInterfaces); + myInstance->knownInterfaces = NULL; + } + + return; +} + + +static void +watcher_add(MyType *myInstance) +{ + SCDynamicStoreContext context = { 0, (void *)myInstance, NULL, NULL, NULL }; + CFDictionaryRef dict; + CFStringRef key; + CFArrayRef keys; + SCDynamicStoreRef store; + + store = SCDynamicStoreCreate(NULL, CFSTR("SCMonitor"), updateInterfaceList, &context); + if (store == NULL) { + SCLog(TRUE, LOG_ERR, + CFSTR("SCMonitor: SCDynamicStoreCreate() failed: %s"), + SCErrorString(SCError())); + return; + } + + key = SCDynamicStoreKeyCreateNetworkInterface(NULL, kSCDynamicStoreDomainState); + + // watch for changes to the list of network interfaces + keys = CFArrayCreate(NULL, (const void **)&key, 1, &kCFTypeArrayCallBacks); + SCDynamicStoreSetNotificationKeys(store, NULL, keys); + CFRelease(keys); + myInstance->monitorRls = SCDynamicStoreCreateRunLoopSource(NULL, store, 0); + CFRunLoopAddSource(CFRunLoopGetCurrent(), + myInstance->monitorRls, + kCFRunLoopDefaultMode); + + // initialize the list of known interfaces + myInstance->knownInterfaces = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks); + dict = SCDynamicStoreCopyValue(store, key); + if (dict != NULL) { + if (isA_CFDictionary(dict)) { + CFIndex i; + CFArrayRef interfaces; + CFIndex n; + + interfaces = CFDictionaryGetValue(dict, kSCPropNetInterfaces); + n = isA_CFArray(interfaces) ? CFArrayGetCount(interfaces) : 0; + for (i = 0; i < n; i++) { + CFStringRef bsdName; + + bsdName = CFArrayGetValueAtIndex(interfaces, i); + if (isA_CFString(bsdName)) { + CFSetAddValue(myInstance->knownInterfaces, bsdName); + } + } + } + + CFRelease(dict); + } + + CFRelease(key); + CFRelease(store); + return; +} + + +#pragma mark - +#pragma mark UserEventAgent stubs + + +static HRESULT +myQueryInterface(void *myInstance, REFIID iid, LPVOID *ppv) +{ + CFUUIDRef interfaceID = CFUUIDCreateFromUUIDBytes(NULL, iid); + + // Test the requested ID against the valid interfaces. + if (CFEqual(interfaceID, kUserEventAgentInterfaceID)) { + ((MyType *) myInstance)->_UserEventAgentInterface->AddRef(myInstance); + *ppv = myInstance; + CFRelease(interfaceID); + return S_OK; + } + + if (CFEqual(interfaceID, IUnknownUUID)) { + ((MyType *) myInstance)->_UserEventAgentInterface->AddRef(myInstance); + *ppv = myInstance; + CFRelease(interfaceID); + return S_OK; + } + + // Requested interface unknown, bail with error. + *ppv = NULL; + CFRelease(interfaceID); + return E_NOINTERFACE; +} + + +static ULONG +myAddRef(void *myInstance) +{ + ((MyType *) myInstance)->_refCount++; + return ((MyType *) myInstance)->_refCount; +} + + +static ULONG +myRelease(void *myInstance) +{ + ((MyType *) myInstance)->_refCount--; + if (((MyType *) myInstance)->_refCount == 0) { + CFUUIDRef factoryID = ((MyType *) myInstance)->_factoryID; + + if (factoryID != NULL) { + CFPlugInRemoveInstanceForFactory(factoryID); + CFRelease(factoryID); + + watcher_remove((MyType *)myInstance); + notify_remove((MyType *)myInstance, TRUE); + } + free(myInstance); + return 0; + } + + return ((MyType *) myInstance)->_refCount; +} + + +static void +myInstall(void *myInstance) +{ + watcher_add((MyType *)myInstance); + return; +} + + +static UserEventAgentInterfaceStruct UserEventAgentInterfaceFtbl = { + NULL, // Required padding for COM + myQueryInterface, // These three are the required COM functions + myAddRef, + myRelease, + myInstall // Interface implementation +}; + + +void * +UserEventAgentFactory(CFAllocatorRef allocator, CFUUIDRef typeID) +{ + MyType *newOne = NULL; + + if (CFEqual(typeID, kUserEventAgentTypeID)) { + newOne = (MyType *)malloc(sizeof(MyType)); + bzero(newOne, sizeof(*newOne)); + newOne->_UserEventAgentInterface = &UserEventAgentInterfaceFtbl; + newOne->_factoryID = (CFUUIDRef)CFRetain(kUserEventAgentFactoryID); + CFPlugInAddInstanceForFactory(kUserEventAgentFactoryID); + newOne->_refCount = 1; + } + + return newOne; +} + + +#ifdef MAIN +int +main(int argc, char **argv) +{ + MyType *newOne = (MyType *)malloc(sizeof(MyType)); + + _sc_log = FALSE; + _sc_verbose = (argc > 1) ? TRUE : FALSE; + + bzero(newOne, sizeof(*newOne)); + myInstall(newOne); + CFRunLoopRun(); + exit(0); + return (0); +} +#endif // MAIN diff --git a/SystemConfiguration.fproj/English.lproj/NetworkInterface.strings b/SystemConfiguration.fproj/English.lproj/NetworkInterface.strings index 1c9c12fce6b57f96ea0f6c9bf397693af2f1ee76..a297a9afed60a20ef619d1582ebee14edad70932 100644 GIT binary patch delta 242 zcmZ9F%?ZLl5QSe3kr0Glp_ft7D9O5;Cz(4c zG6FdXfr5(acg-&7DI7>w%y^LqSt;Tjwph_#_hBwt($r>|*vK2%)(`C0o0vAp{^W)M U1%q;S_j+)N)Yg6+4Jae0KQ - + CFBundleDevelopmentRegion @@ -7,7 +7,7 @@ CFBundleExecutable SystemConfiguration CFBundleGetInfoString - 1.9.0 + 1.9.1 CFBundleIdentifier com.apple.SystemConfiguration CFBundleInfoDictionaryVersion @@ -17,10 +17,10 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.9.0 + 1.9.1 CFBundleSignature ???? CFBundleVersion - 1.9.0 + 1.9.1 diff --git a/SystemConfiguration.fproj/SCNetworkConfigurationInternal.h b/SystemConfiguration.fproj/SCNetworkConfigurationInternal.h index f516c82..5203eb5 100644 --- a/SystemConfiguration.fproj/SCNetworkConfigurationInternal.h +++ b/SystemConfiguration.fproj/SCNetworkConfigurationInternal.h @@ -64,6 +64,9 @@ typedef struct { // prefs SCPreferencesRef prefs; + // name + CFStringRef name; + } SCNetworkServicePrivate, *SCNetworkServicePrivateRef; diff --git a/SystemConfiguration.fproj/SCNetworkConfigurationPrivate.h b/SystemConfiguration.fproj/SCNetworkConfigurationPrivate.h index a51cd29..9d00ed5 100644 --- a/SystemConfiguration.fproj/SCNetworkConfigurationPrivate.h +++ b/SystemConfiguration.fproj/SCNetworkConfigurationPrivate.h @@ -375,6 +375,26 @@ isA_SCNetworkSet(CFTypeRef obj) Boolean SCNetworkSetEstablishDefaultConfiguration (SCNetworkSetRef set); +/*! + @function SCNetworkSetEstablishDefaultInterfaceConfiguration + @discussion Updates a network set by adding services for + the specified network interface if is not currently + represented. + If the provided set contains one (or more) services, new + services will only be added for interfaces that are not + represented in *any* set. + Otherwise, new services will be added for interfaces that + are not represented in the provided set. + The new services are established with "default" configuration + options. + @param set The network set. + @param interface The network interface. + @result TRUE if the configuration was updated; FALSE if no + changes were required or if an error was encountered. + */ +Boolean +SCNetworkSetEstablishDefaultInterfaceConfiguration (SCNetworkSetRef set, + SCNetworkInterfaceRef interface); __END_DECLS diff --git a/SystemConfiguration.fproj/SCNetworkInterface.c b/SystemConfiguration.fproj/SCNetworkInterface.c index d695a6a..dd83453 100644 --- a/SystemConfiguration.fproj/SCNetworkInterface.c +++ b/SystemConfiguration.fproj/SCNetworkInterface.c @@ -1342,6 +1342,40 @@ processNetworkInterface(SCNetworkInterfacePrivateRef interfacePrivate, interfacePrivate->localized_arg2 = port_name; } } + } else if (CFEqual(provider, CFSTR("IOUSBDevice"))) { + CFTypeRef val; + + // check if a "Product Name" has been provided + val = IORegistryEntrySearchCFProperty(interface, + kIOServicePlane, + CFSTR(kIOPropertyProductNameKey), + NULL, + kIORegistryIterateRecursively | kIORegistryIterateParents); + if (val != NULL) { + CFStringRef productName; + + productName = IOCopyCFStringValue(val); + CFRelease(val); + + if (productName != NULL) { + if (CFStringGetLength(productName) > 0) { + // if we have a [somewhat reasonable?] product name + if (interfacePrivate->name != NULL) { + CFRelease(interfacePrivate->name); + } + interfacePrivate->name = CFRetain(productName); + if (interfacePrivate->localized_name != NULL) { + CFRelease(interfacePrivate->localized_name); + } + interfacePrivate->localized_name = copy_interface_string(bundle, productName, TRUE); + } + + CFRelease(productName); + } + } else { + interfacePrivate->localized_key = CFSTR("usb-ether"); + interfacePrivate->localized_arg1 = IODictionaryCopyCFStringValue(interface_dict, CFSTR(kIOBSDNameKey)); + } } CFRelease(provider); } @@ -1759,7 +1793,7 @@ processSerialInterface(SCNetworkInterfacePrivateRef interfacePrivate, if (interfacePrivate->localized_name != NULL) { CFRelease(interfacePrivate->localized_name); } - interfacePrivate->localized_name = CFRetain(productName); + interfacePrivate->localized_name = copy_interface_string(bundle, productName, TRUE); // if not provided, also check if the product name // matches a CCL script diff --git a/SystemConfiguration.fproj/SCNetworkService.c b/SystemConfiguration.fproj/SCNetworkService.c index 8245e5c..43725da 100644 --- a/SystemConfiguration.fproj/SCNetworkService.c +++ b/SystemConfiguration.fproj/SCNetworkService.c @@ -75,6 +75,9 @@ __SCNetworkServiceCopyDescription(CFTypeRef cf) CFStringAppendFormat(result, NULL, CFSTR(" {"), cf, allocator); CFStringAppendFormat(result, NULL, CFSTR("id = %@"), servicePrivate->serviceID); CFStringAppendFormat(result, NULL, CFSTR(", prefs = %p"), servicePrivate->prefs); + if (servicePrivate->name != NULL) { + CFStringAppendFormat(result, NULL, CFSTR(", name = %@"), servicePrivate->name); + } CFStringAppendFormat(result, NULL, CFSTR("}")); return result; @@ -89,8 +92,9 @@ __SCNetworkServiceDeallocate(CFTypeRef cf) /* release resources */ CFRelease(servicePrivate->serviceID); - if (servicePrivate->interface != NULL) CFRelease(servicePrivate->interface); + if (servicePrivate->interface != NULL) CFRelease(servicePrivate->interface); CFRelease(servicePrivate->prefs); + if (servicePrivate->name != NULL) CFRelease(servicePrivate->name); return; } @@ -157,6 +161,7 @@ __SCNetworkServiceCreatePrivate(CFAllocatorRef allocator, servicePrivate->prefs = CFRetain(prefs); servicePrivate->serviceID = CFStringCreateCopy(NULL, serviceID); servicePrivate->interface = (interface != NULL) ? CFRetain(interface) : NULL; + servicePrivate->name = NULL; return servicePrivate; } @@ -659,7 +664,7 @@ SCNetworkServiceCreate(SCPreferencesRef prefs, SCNetworkInterfaceRef interface) // update template for v.92 modems if ((overrides == NULL) && CFDictionaryGetValueIfPresent(config, - kSCPropNetModemConnectionScript, + kSCPropNetModemConnectionScript, (const void **)&script) && CFEqual(script, CFSTR("v.34 Personality")) && _SCNetworkInterfaceIsModemV92(interface)) { @@ -861,6 +866,10 @@ SCNetworkServiceGetName(SCNetworkServiceRef service) return NULL; } + if (servicePrivate->name != NULL) { + return servicePrivate->name; + } + path = SCPreferencesPathKeyCreateNetworkServiceEntity(NULL, // allocator servicePrivate->serviceID, // service NULL); // entity @@ -869,7 +878,9 @@ SCNetworkServiceGetName(SCNetworkServiceRef service) if (isA_CFDictionary(entity)) { name = CFDictionaryGetValue(entity, kSCPropUserDefinedName); - name = isA_CFString(name); + if (isA_CFString(name)) { + servicePrivate->name = CFRetain(name); + } } interface = SCNetworkServiceGetInterface(service); @@ -885,23 +896,48 @@ SCNetworkServiceGetName(SCNetworkServiceRef service) } if (interface != NULL) { - if (name != NULL) { - CFStringRef interface_name; + CFStringRef interface_name; + CFStringRef suffix = NULL; + if (servicePrivate->name != NULL) { interface_name = __SCNetworkInterfaceGetNonLocalizedDisplayName(interface); - if ((interface_name != NULL) && CFEqual(name, interface_name)) { - // if service name matches the [non-]localized - // interface name - name = NULL; + if (interface_name != NULL) { + if (CFEqual(name, interface_name)) { + // if service name matches the [non-]localized + // interface name + CFRelease(servicePrivate->name); + servicePrivate->name = NULL; + } else if (CFStringHasPrefix(name, interface_name)) { + CFIndex prefixLen = CFStringGetLength(interface_name); + CFIndex suffixLen = CFStringGetLength(name); + + suffix = CFStringCreateWithSubstring(NULL, + name, + CFRangeMake(prefixLen, suffixLen - prefixLen)); + CFRelease(servicePrivate->name); + servicePrivate->name = NULL; + } } } - if (name == NULL) { - name = SCNetworkInterfaceGetLocalizedDisplayName(interface); + if (servicePrivate->name == NULL) { + interface_name = SCNetworkInterfaceGetLocalizedDisplayName(interface); + if (interface_name != NULL) { + if (suffix != NULL) { + servicePrivate->name = CFStringCreateWithFormat(NULL, + NULL, + CFSTR("%@%@"), + interface_name, + suffix); + } else { + servicePrivate->name = CFRetain(interface_name); + } + } } + if (suffix != NULL) CFRelease(suffix); } - return name; + return servicePrivate->name; } @@ -1039,6 +1075,7 @@ SCNetworkServiceSetName(SCNetworkServiceRef service, CFStringRef name) CFDictionaryRef entity; Boolean ok = FALSE; CFStringRef path; + CFStringRef saveName = NULL; SCNetworkServicePrivateRef servicePrivate = (SCNetworkServicePrivateRef)service; if (!isA_SCNetworkService(service)) { @@ -1046,9 +1083,12 @@ SCNetworkServiceSetName(SCNetworkServiceRef service, CFStringRef name) return FALSE; } - if ((name != NULL) && !isA_CFString(name)) { - _SCErrorSet(kSCStatusInvalidArgument); - return FALSE; + if (name != NULL) { + if (!isA_CFString(name)) { + _SCErrorSet(kSCStatusInvalidArgument); + return FALSE; + } + saveName = CFRetain(name); } if (name != NULL) { @@ -1070,12 +1110,36 @@ SCNetworkServiceSetName(SCNetworkServiceRef service, CFStringRef name) CFStringRef interface_name; interface_name = SCNetworkInterfaceGetLocalizedDisplayName(interface); - if ((interface_name != NULL) && CFEqual(name, interface_name)) { - // if service name matches the localized interface name - // then store the non-localized name. - interface_name = __SCNetworkInterfaceGetNonLocalizedDisplayName(interface); - if (interface_name != NULL) { - name = interface_name; + if (interface_name != NULL) { + if (CFEqual(name, interface_name)) { + // if service name matches the localized interface name + // then store the non-localized name. + interface_name = __SCNetworkInterfaceGetNonLocalizedDisplayName(interface); + if (interface_name != NULL) { + CFRelease(saveName); + saveName = CFRetain(interface_name); + } + } else if (CFStringHasPrefix(name, interface_name)) { + CFIndex prefixLen = CFStringGetLength(interface_name); + CFStringRef suffix; + CFIndex suffixLen = CFStringGetLength(name); + + // if service name matches the localized interface name plus + // a few extra characters) then store the non-localized name with + // the same suffix. + suffix = CFStringCreateWithSubstring(NULL, + name, + CFRangeMake(prefixLen, suffixLen - prefixLen)); + interface_name = __SCNetworkInterfaceGetNonLocalizedDisplayName(interface); + if (interface_name != NULL) { + CFRelease(saveName); + saveName = CFStringCreateWithFormat(NULL, + NULL, + CFSTR("%@%@"), + interface_name, + suffix); + } + CFRelease(suffix); } } } @@ -1134,6 +1198,7 @@ SCNetworkServiceSetName(SCNetworkServiceRef service, CFStringRef name) * the "name" is not unique. */ CFRelease(sets); + if (saveName != NULL) CFRelease(saveName); _SCErrorSet(kSCStatusKeyExists); return FALSE; } @@ -1160,8 +1225,8 @@ SCNetworkServiceSetName(SCNetworkServiceRef service, CFStringRef name) CFMutableDictionaryRef newEntity; newEntity = CFDictionaryCreateMutableCopy(NULL, 0, entity); - if (name != NULL) { - CFDictionarySetValue(newEntity, kSCPropUserDefinedName, name); + if (saveName != NULL) { + CFDictionarySetValue(newEntity, kSCPropUserDefinedName, saveName); } else { CFDictionaryRemoveValue(newEntity, kSCPropUserDefinedName); } @@ -1169,6 +1234,11 @@ SCNetworkServiceSetName(SCNetworkServiceRef service, CFStringRef name) CFRelease(newEntity); } CFRelease(path); + if (saveName != NULL) CFRelease(saveName); + + if (servicePrivate->name != NULL) CFRelease(servicePrivate->name); + if (name != NULL) CFRetain(name); + servicePrivate->name = name; return ok; } diff --git a/SystemConfiguration.fproj/SCNetworkSet.c b/SystemConfiguration.fproj/SCNetworkSet.c index 922f7e0..1b29b18 100644 --- a/SystemConfiguration.fproj/SCNetworkSet.c +++ b/SystemConfiguration.fproj/SCNetworkSet.c @@ -770,7 +770,7 @@ SCNetworkSetGetName(SCNetworkSetRef set) } if (setPrivate->name != NULL) { - return setPrivate->name;; + return setPrivate->name; } path = SCPreferencesPathKeyCreateSet(NULL, setPrivate->setID); @@ -1173,21 +1173,62 @@ add_supported_interfaces(CFMutableArrayRef interface_list, SCNetworkInterfaceRef } -Boolean -SCNetworkSetEstablishDefaultConfiguration(SCNetworkSetRef set) +static CFStringRef +next_service_name(SCNetworkServiceRef service) +{ + CFArrayRef components; + CFIndex n; + CFStringRef name; + CFMutableArrayRef newComponents; + SInt32 suffix = 2; + + name = SCNetworkServiceGetName(service); + if (name == NULL) { + return NULL; + } + + components = CFStringCreateArrayBySeparatingStrings(NULL, name, CFSTR(" ")); + if (components != NULL) { + newComponents = CFArrayCreateMutableCopy(NULL, 0, components); + CFRelease(components); + } else { + newComponents = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); + CFArrayAppendValue(newComponents, name); + } + + n = CFArrayGetCount(newComponents); + if (n > 1) { + CFStringRef str; + + str = CFArrayGetValueAtIndex(newComponents, n - 1); + suffix = CFStringGetIntValue(str); + if (suffix++ > 0) { + CFArrayRemoveValueAtIndex(newComponents, n - 1); + } else { + suffix = 2; + } + } + + name = CFStringCreateWithFormat(NULL, NULL, CFSTR("%d"), suffix); + CFArrayAppendValue(newComponents, name); + CFRelease(name); + + name = CFStringCreateByCombiningStrings(NULL, newComponents, CFSTR(" ")); + CFRelease(newComponents); + + return name; +} + + +static Boolean +__SCNetworkSetEstablishDefaultConfigurationForInterfaces(SCNetworkSetRef set, CFArrayRef interfaces) { CFIndex i; - CFArrayRef interfaces; CFIndex n; Boolean ok = TRUE; CFArrayRef services; - Boolean setUpdated = FALSE; SCNetworkSetPrivateRef setPrivate = (SCNetworkSetPrivateRef)set; - - if (!isA_SCNetworkSet(set)) { - _SCErrorSet(kSCStatusInvalidArgument); - return FALSE; - } + Boolean updated = FALSE; // first, assume that we only want to add new services // for those interfaces that are not represented in the @@ -1202,7 +1243,6 @@ SCNetworkSetEstablishDefaultConfiguration(SCNetworkSetRef set) services = SCNetworkServiceCopyAll(setPrivate->prefs); } - interfaces = SCNetworkInterfaceCopyAll(); n = (interfaces != NULL) ? CFArrayGetCount(interfaces) : 0; for (i = 0; i < n; i++) { SCNetworkInterfaceRef interface; @@ -1247,19 +1287,57 @@ SCNetworkSetEstablishDefaultConfiguration(SCNetworkSetRef set) goto nextInterface; } - ok = SCNetworkSetAddService(set, service); - if (!ok) { - SCLog(TRUE, LOG_DEBUG, - CFSTR("could not add service for \"%@\": %s\n"), - SCNetworkInterfaceGetLocalizedDisplayName(interface), - SCErrorString(SCError())); - SCNetworkServiceRemove(service); - CFRelease(service); - goto nextInterface; + while (TRUE) { + CFStringRef newName; + + ok = SCNetworkSetAddService(set, service); + if (ok) { + break; + } + + if (SCError() != kSCStatusKeyExists) { + SCLog(TRUE, LOG_DEBUG, + CFSTR("could not add service for \"%@\": %s\n"), + SCNetworkInterfaceGetLocalizedDisplayName(interface), + SCErrorString(SCError())); + SCNetworkServiceRemove(service); + CFRelease(service); + goto nextInterface; + } + + // we have two interfaces with the same service + // name, acquire a new, hopefully unique, name + + newName = next_service_name(service); + if (newName == NULL) { + SCLog(TRUE, LOG_DEBUG, + CFSTR("could not set unique name for \"%@\": %s\n"), + SCNetworkInterfaceGetLocalizedDisplayName(interface), + SCErrorString(SCError())); + SCNetworkServiceRemove(service); + CFRelease(service); + goto nextInterface; + } + + ok = SCNetworkServiceSetName(service, newName); + CFRelease(newName); + if (ok) { + continue; + } + + if (SCError() != kSCStatusKeyExists) { + SCLog(TRUE, LOG_DEBUG, + CFSTR("could not set unique name for \"%@\": %s\n"), + SCNetworkInterfaceGetLocalizedDisplayName(interface), + SCErrorString(SCError())); + SCNetworkServiceRemove(service); + CFRelease(service); + goto nextInterface; + } } CFRelease(service); - setUpdated = TRUE; + updated = TRUE; } else { add_supported_interfaces(interface_list, interface); } @@ -1270,13 +1348,56 @@ SCNetworkSetEstablishDefaultConfiguration(SCNetworkSetRef set) } CFRelease(interface_list); } - if (interfaces != NULL) CFRelease(interfaces); if (services != NULL) CFRelease(services); - if (ok && !setUpdated) { + if (ok && !updated) { // if no changes were made _SCErrorSet(kSCStatusOK); } - return setUpdated; + return updated; +} + + +Boolean +SCNetworkSetEstablishDefaultConfiguration(SCNetworkSetRef set) +{ + CFArrayRef interfaces; + Boolean updated; + + if (!isA_SCNetworkSet(set)) { + _SCErrorSet(kSCStatusInvalidArgument); + return FALSE; + } + + interfaces = SCNetworkInterfaceCopyAll(); + updated = __SCNetworkSetEstablishDefaultConfigurationForInterfaces(set, interfaces); + if (interfaces != NULL) CFRelease(interfaces); + + return updated; +} + + +Boolean +SCNetworkSetEstablishDefaultInterfaceConfiguration(SCNetworkSetRef set, SCNetworkInterfaceRef interface) +{ + CFMutableArrayRef interfaces; + Boolean updated; + + if (!isA_SCNetworkSet(set)) { + _SCErrorSet(kSCStatusInvalidArgument); + return FALSE; + } + + if (!isA_SCNetworkInterface(interface)) { + _SCErrorSet(kSCStatusInvalidArgument); + return FALSE; + } + + interfaces = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); + CFArrayAppendValue(interfaces, interface); + updated = __SCNetworkSetEstablishDefaultConfigurationForInterfaces(set, interfaces); + CFRelease(interfaces); + + return updated; } diff --git a/SystemConfiguration.fproj/SCPLock.c b/SystemConfiguration.fproj/SCPLock.c index 493c1ec..0e6fcb3 100644 --- a/SystemConfiguration.fproj/SCPLock.c +++ b/SystemConfiguration.fproj/SCPLock.c @@ -200,7 +200,8 @@ SCPreferencesLock(SCPreferencesRef prefs, Boolean wait) char buf[32]; SCPreferencesPrivateRef prefsPrivate = (SCPreferencesPrivateRef)prefs; int sc_status = kSCStatusFailed; - struct stat statbuf; + struct stat statBuf; + struct stat statBuf2; if (prefs == NULL) { /* sorry, you must provide a session */ @@ -242,54 +243,52 @@ SCPreferencesLock(SCPreferencesRef prefs, Boolean wait) retry : - prefsPrivate->lockFD = open(prefsPrivate->lockPath, O_WRONLY|O_CREAT, 0644); + prefsPrivate->lockFD = open(prefsPrivate->lockPath, + wait ? O_WRONLY|O_CREAT|O_EXLOCK + : O_WRONLY|O_CREAT|O_EXLOCK|O_NONBLOCK, + 0644); if (prefsPrivate->lockFD == -1) { - if (errno == EROFS) { - goto locked; - } - - if ((errno == ENOENT) && - ((prefsPrivate->prefsID == NULL) || !CFStringHasPrefix(prefsPrivate->prefsID, CFSTR("/")))) { - int ret; - - // create parent (/Library/Preferences/SystemConfiguration) - ret = createParentDirectory(prefsPrivate->lockPath); - if (ret == 0) { - SCLog(TRUE, LOG_NOTICE, - CFSTR("created directory for \"%s\""), - prefsPrivate->newPath ? prefsPrivate->newPath : prefsPrivate->path); - goto retry; - } else if (errno == EROFS) { - goto locked; - } - } - - sc_status = errno; - SCLog(TRUE, LOG_ERR, - CFSTR("SCPreferencesLock open() failed: %s"), - strerror(errno)); - goto error; - } - - if (flock(prefsPrivate->lockFD, wait ? LOCK_EX : LOCK_EX|LOCK_NB) == -1) { switch (errno) { + case ENOENT : + if ((prefsPrivate->prefsID == NULL) || + !CFStringHasPrefix(prefsPrivate->prefsID, CFSTR("/"))) { + int ret; + + // create parent (/Library/Preferences/SystemConfiguration) + ret = createParentDirectory(prefsPrivate->lockPath); + if (ret == 0) { + SCLog(TRUE, LOG_NOTICE, + CFSTR("created directory for \"%s\""), + prefsPrivate->newPath ? prefsPrivate->newPath : prefsPrivate->path); + goto retry; + } else if (errno == EROFS) { + goto locked; + } + } + break; + case EROFS : + // if read-only filesystem + goto locked; case EWOULDBLOCK : // if already locked (and we are not blocking) sc_status = kSCStatusPrefsBusy; - break; + goto error; default : - sc_status = errno; - SCLog(TRUE, LOG_ERR, - CFSTR("SCPreferencesLock flock() failed: %s"), - strerror(errno)); break; } + sc_status = errno; + SCLog(TRUE, LOG_ERR, + CFSTR("SCPreferencesLock open() failed: %s"), + strerror(errno)); goto error; } - if (stat(prefsPrivate->lockPath, &statbuf) == -1) { - // if the lock file was unlinked + if ((stat(prefsPrivate->lockPath, &statBuf) == -1) || + (fstat(prefsPrivate->lockFD, &statBuf2) == -1) || + (statBuf.st_dev != statBuf2.st_dev) || + (statBuf.st_ino != statBuf2.st_ino)) { + // if the lock file was unlinked or re-created close(prefsPrivate->lockFD); prefsPrivate->lockFD = -1; goto retry; @@ -305,7 +304,6 @@ SCPreferencesLock(SCPreferencesRef prefs, Boolean wait) if (prefsPrivate->accessed) { CFDataRef currentSignature; Boolean match; - struct stat statBuf; /* * the preferences have been accessed since the diff --git a/SystemConfiguration.fproj/SCPOpen.c b/SystemConfiguration.fproj/SCPOpen.c index d8a1365..7ea1968 100644 --- a/SystemConfiguration.fproj/SCPOpen.c +++ b/SystemConfiguration.fproj/SCPOpen.c @@ -199,7 +199,6 @@ __SCPreferencesCreate_helper(SCPreferencesRef prefs) Boolean ok; SCPreferencesPrivateRef prefsPrivate = (SCPreferencesPrivateRef)prefs; uint32_t status = kSCStatusOK; - CFDataRef reply = NULL; // start helper prefsPrivate->helper = _SCHelperOpen(prefsPrivate->authorizationData); @@ -216,8 +215,6 @@ __SCPreferencesCreate_helper(SCPreferencesRef prefs) } // have the helper "open" the prefs - status = kSCStatusOK; - reply = NULL; ok = _SCHelperExec(prefsPrivate->helper, SCHELPER_MSG_PREFS_OPEN, data, @@ -271,8 +268,6 @@ __SCPreferencesAccess_helper(SCPreferencesRef prefs) } // have the helper "access" the prefs - status = kSCStatusOK; - reply = NULL; ok = _SCHelperExec(prefsPrivate->helper, SCHELPER_MSG_PREFS_ACCESS, NULL, @@ -853,6 +848,36 @@ SCPreferencesUnscheduleFromRunLoop(SCPreferencesRef prefs, } +static void +__SCPreferencesSynchronize_helper(SCPreferencesRef prefs) +{ + Boolean ok; + SCPreferencesPrivateRef prefsPrivate = (SCPreferencesPrivateRef)prefs; + uint32_t status = kSCStatusOK; + + if (prefsPrivate->helper == -1) { + // if no helper + return; + } + + // have the helper "synchronize" the prefs + ok = _SCHelperExec(prefsPrivate->helper, + SCHELPER_MSG_PREFS_SYNCHRONIZE, + NULL, + &status, + NULL); + if (!ok) { + // close helper + if (prefsPrivate->helper != -1) { + _SCHelperClose(prefsPrivate->helper); + prefsPrivate->helper = -1; + } + } + + return; +} + + void SCPreferencesSynchronize(SCPreferencesRef prefs) { @@ -864,6 +889,10 @@ SCPreferencesSynchronize(SCPreferencesRef prefs) return; } + if (prefsPrivate->authorizationData != NULL) { + __SCPreferencesSynchronize_helper(prefs); + } + if (prefsPrivate->prefs != NULL) { CFRelease(prefsPrivate->prefs); prefsPrivate->prefs = NULL; diff --git a/SystemConfiguration.fproj/helper/SCHelper_client.h b/SystemConfiguration.fproj/helper/SCHelper_client.h index 3842793..3fb24bb 100644 --- a/SystemConfiguration.fproj/helper/SCHelper_client.h +++ b/SystemConfiguration.fproj/helper/SCHelper_client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2005-2007 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -46,6 +46,7 @@ enum { SCHELPER_MSG_PREFS_APPLY, SCHELPER_MSG_PREFS_UNLOCK, SCHELPER_MSG_PREFS_CLOSE, + SCHELPER_MSG_PREFS_SYNCHRONIZE, // SCNetworkConfiguration SCHELPER_MSG_INTERFACE_REFRESH = 200, diff --git a/SystemConfiguration.fproj/helper/SCHelper_server.c b/SystemConfiguration.fproj/helper/SCHelper_server.c index 9231e08..7a8ca55 100644 --- a/SystemConfiguration.fproj/helper/SCHelper_server.c +++ b/SystemConfiguration.fproj/helper/SCHelper_server.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2005-2007 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -73,7 +73,7 @@ do_Auth(void *info, CFDataRef data, uint32_t *status, CFDataRef *reply) if (CFDataGetLength(data) == sizeof(extForm.bytes)) { OSStatus err; - memcpy(extForm.bytes, CFDataGetBytePtr(data), sizeof(extForm.bytes)); + bcopy(CFDataGetBytePtr(data), extForm.bytes, sizeof(extForm.bytes)); err = AuthorizationCreateFromExternalForm(&extForm, &authorization); if (err != errAuthorizationSuccess) { SCLog(TRUE, LOG_ERR, @@ -373,7 +373,6 @@ do_prefs_Access(void *info, CFDataRef data, uint32_t *status, CFDataRef *reply) *status = SCError(); } - SCPreferencesSynchronize(prefs); return TRUE; } @@ -453,7 +452,6 @@ do_prefs_Commit(void *info, CFDataRef data, uint32_t *status, CFDataRef *reply) *status = SCError(); } - SCPreferencesSynchronize(prefs); return TRUE; } @@ -526,6 +524,25 @@ do_prefs_Close(void *info, CFDataRef data, uint32_t *status, CFDataRef *reply) } +/* + * SYNCHRONIZE + * (in) data = N/A + * (out) status = kSCStatusOK + * (out) reply = N/A + */ +static Boolean +do_prefs_Synchronize(void *info, CFDataRef data, uint32_t *status, CFDataRef *reply) +{ + if (prefs == NULL) { + return FALSE; + } + + SCPreferencesSynchronize(prefs); + *status = kSCStatusOK; + return TRUE; +} + + static Boolean hasAuthorization() { @@ -589,6 +606,7 @@ static const struct helper { { SCHELPER_MSG_PREFS_APPLY, "PREFS apply", TRUE, do_prefs_Apply , NULL }, { SCHELPER_MSG_PREFS_UNLOCK, "PREFS unlock", FALSE, do_prefs_Unlock , NULL }, { SCHELPER_MSG_PREFS_CLOSE, "PREFS close", FALSE, do_prefs_Close , NULL }, + { SCHELPER_MSG_PREFS_SYNCHRONIZE, "PREFS synchronize", FALSE, do_prefs_Synchronize , NULL }, { SCHELPER_MSG_INTERFACE_REFRESH, "INTERFACE refresh", TRUE, do_interface_refresh , NULL }, diff --git a/configd.xcodeproj/project.pbxproj b/configd.xcodeproj/project.pbxproj index e1e8d3f..59f21e4 100644 --- a/configd.xcodeproj/project.pbxproj +++ b/configd.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 1558480607550D470046C2E9 /* PBXTargetDependency */, 1558480807550D470046C2E9 /* PBXTargetDependency */, 1558480A07550D470046C2E9 /* PBXTargetDependency */, + 150ECB3C0D0079280065E94D /* PBXTargetDependency */, ); name = configd_executables; productName = configd_executables; @@ -319,6 +320,11 @@ 15DAF2DC08466D4900D1B2BD /* SCHelper_client.c in Sources */ = {isa = PBXBuildFile; fileRef = 15DAF2D808466D4900D1B2BD /* SCHelper_client.c */; }; 15DAF2DF08466D4900D1B2BD /* helper_comm.h in Headers */ = {isa = PBXBuildFile; fileRef = 15DAF2D708466D4900D1B2BD /* helper_comm.h */; }; 15DAF2E108466D4900D1B2BD /* SCHelper_server.c in Sources */ = {isa = PBXBuildFile; fileRef = 15DAF2D908466D4900D1B2BD /* SCHelper_server.c */; }; + 15E517680CCFBCD0008FFE82 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15DAD6C807591A1A0084A6ED /* SystemConfiguration.framework */; }; + 15FC130B0CCEA59E0013872C /* monitor.c in Sources */ = {isa = PBXBuildFile; fileRef = 15FC130A0CCEA59E0013872C /* monitor.c */; }; + 15FC13180CCF74740013872C /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15CB6A6F05C0722B0099E85F /* CoreFoundation.framework */; }; + 15FEE80E0CCFD341001312F9 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15FEE80D0CCFD341001312F9 /* ApplicationServices.framework */; }; + 15FEE81F0CD03E75001312F9 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 15FEE8180CD03CBB001312F9 /* Localizable.strings */; }; F95B8A430B03E07A00993BA3 /* SCNetworkSignature.c in Sources */ = {isa = PBXBuildFile; fileRef = F95B8A420B03E07A00993BA3 /* SCNetworkSignature.c */; }; F95B8A460B03E09300993BA3 /* SCNetworkSignature.h in Headers */ = {isa = PBXBuildFile; fileRef = F95B8A440B03E09300993BA3 /* SCNetworkSignature.h */; settings = {ATTRIBUTES = (Private, ); }; }; F95B8A470B03E09300993BA3 /* SCNetworkSignaturePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = F95B8A450B03E09300993BA3 /* SCNetworkSignaturePrivate.h */; settings = {ATTRIBUTES = (Private, ); }; }; @@ -326,6 +332,13 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 150ECB3B0D0079280065E94D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 15CB6A7705C0722B0099E85F /* Project object */; + proxyType = 1; + remoteGlobalIDString = 151F5D990CCE98E50093AC3B /* SCMonitor */; + remoteInfo = SCMonitor; + }; 1520A385084681350010B584 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 15CB6A7705C0722B0099E85F /* Project object */; @@ -538,6 +551,7 @@ 1514D76D05C08A5F00757DC9 /* config_types.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = config_types.h; path = SystemConfiguration.fproj/config_types.h; sourceTree = SOURCE_ROOT; }; 151BDA2B05D9E28B00657BC7 /* SCPreferencesPathKey.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SCPreferencesPathKey.h; path = SystemConfiguration.fproj/SCPreferencesPathKey.h; sourceTree = SOURCE_ROOT; }; 151BDA5D05D9E2ED00657BC7 /* SCPreferencesPathKey.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = SCPreferencesPathKey.c; path = SystemConfiguration.fproj/SCPreferencesPathKey.c; sourceTree = SOURCE_ROOT; }; + 151F5D9A0CCE98E50093AC3B /* SCMonitor.plugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SCMonitor.plugin; sourceTree = BUILT_PRODUCTS_DIR; }; 151F63EC09328A3C0096DCC9 /* genSCPreferences */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = genSCPreferences; sourceTree = BUILT_PRODUCTS_DIR; }; 1520A3DE0846B2DC0010B584 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = /System/Library/Frameworks/Security.framework; sourceTree = ""; }; 1521FC5C060F296A003B28F5 /* dnsinfo_create.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = dnsinfo_create.c; path = dnsinfo/dnsinfo_create.c; sourceTree = SOURCE_ROOT; }; @@ -768,6 +782,8 @@ 15DC346C0711D49400A3311C /* net_service.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = net_service.h; sourceTree = ""; }; 15DC346D0711D49400A3311C /* net_set.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = net_set.c; sourceTree = ""; }; 15DC346E0711D49400A3311C /* net_set.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = net_set.h; sourceTree = ""; }; + 15FC12F20CCEA4F00013872C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = SCMonitor/Info.plist; sourceTree = ""; }; + 15FC130A0CCEA59E0013872C /* monitor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = monitor.c; path = SCMonitor/monitor.c; sourceTree = ""; }; 15FCAACF05FD0EBF00CB79E6 /* shared_dns_info_types.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = shared_dns_info_types.h; path = dnsinfo/shared_dns_info_types.h; sourceTree = SOURCE_ROOT; }; 15FCAAD005FD0EBF00CB79E6 /* shared_dns_info.defs */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.mig; name = shared_dns_info.defs; path = dnsinfo/shared_dns_info.defs; sourceTree = ""; }; 15FD71090754D628001CC321 /* Kicker.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Kicker.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -780,6 +796,8 @@ 15FD73970754DE49001CC321 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; path = Info.plist; sourceTree = ""; }; 15FD73EE0754DE62001CC321 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; path = Info.plist; sourceTree = ""; }; 15FD743E0754DE7A001CC321 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; path = Info.plist; sourceTree = ""; }; + 15FEE80D0CCFD341001312F9 /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = /System/Library/Frameworks/ApplicationServices.framework; sourceTree = ""; }; + 15FEE8160CD03CA3001312F9 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = SCMonitor/English.lproj/Localizable.strings; sourceTree = ""; }; 23C1E2B4062DD2C700835B54 /* pppcontroller_types.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = pppcontroller_types.h; path = /usr/local/include/ppp/pppcontroller_types.h; sourceTree = ""; }; 23C1E2B8062DD45900835B54 /* pppcontroller.defs */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.mig; name = pppcontroller.defs; path = SystemConfiguration.fproj/pppcontroller.defs; sourceTree = ""; }; 23C1E2BE062DD5DB00835B54 /* pppcontroller.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = pppcontroller.h; path = configd.build/SystemConfiguration.framework.build/DerivedSources/pppcontroller.h; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -796,6 +814,16 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 151F5D980CCE98E50093AC3B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 15FC13180CCF74740013872C /* CoreFoundation.framework in Frameworks */, + 15E517680CCFBCD0008FFE82 /* SystemConfiguration.framework in Frameworks */, + 15FEE80E0CCFD341001312F9 /* ApplicationServices.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 1547001B08455B98006787CE /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -928,6 +956,16 @@ name = "Initial Preferences"; sourceTree = ""; }; + 151F5DA80CCE995D0093AC3B /* SCMonitor */ = { + isa = PBXGroup; + children = ( + 15FC130A0CCEA59E0013872C /* monitor.c */, + 15FC12F20CCEA4F00013872C /* Info.plist */, + 15FEE8180CD03CBB001312F9 /* Localizable.strings */, + ); + name = SCMonitor; + sourceTree = ""; + }; 1547002E084561B4006787CE /* SCHelper */ = { isa = PBXGroup; children = ( @@ -1156,6 +1194,7 @@ 1582B36B05FD1A4D009C2750 /* DNSConfiguration */, 15CB690705C0722A0099E85F /* SystemConfiguration */, 1547002E084561B4006787CE /* SCHelper */, + 151F5DA80CCE995D0093AC3B /* SCMonitor */, 15CB69C205C0722B0099E85F /* configd */, 15CB6A2205C0722B0099E85F /* scselect */, 15CB6A3705C0722B0099E85F /* scutil */, @@ -1184,6 +1223,7 @@ 15DAD6C807591A1A0084A6ED /* SystemConfiguration.framework */, 15DAD5EE075913CE0084A6ED /* libdnsinfo.a */, 1547001D08455B98006787CE /* SCHelper */, + 151F5D9A0CCE98E50093AC3B /* SCMonitor.plugin */, 158ADCA60754ECC800124717 /* configd, scutil, scselect */, 158ADBFD0754ECB100124717 /* Plugins */, 151F63EC09328A3C0096DCC9 /* genSCPreferences */, @@ -1464,6 +1504,7 @@ isa = PBXGroup; children = ( 158AD9F80754EA2F00124717 /* AppleTalk.framework */, + 15FEE80D0CCFD341001312F9 /* ApplicationServices.framework */, 15CB6A6F05C0722B0099E85F /* CoreFoundation.framework */, 1543636A0752D03C00A8EC6C /* IOKit.framework */, 1520A3DE0846B2DC0010B584 /* Security.framework */, @@ -1690,6 +1731,23 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ + 151F5D990CCE98E50093AC3B /* SCMonitor */ = { + isa = PBXNativeTarget; + buildConfigurationList = 151F5D9F0CCE98E60093AC3B /* Build configuration list for PBXNativeTarget "SCMonitor" */; + buildPhases = ( + 151F5D960CCE98E50093AC3B /* Resources */, + 151F5D970CCE98E50093AC3B /* Sources */, + 151F5D980CCE98E50093AC3B /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = SCMonitor; + productName = SCMonitor; + productReference = 151F5D9A0CCE98E50093AC3B /* SCMonitor.plugin */; + productType = "com.apple.product-type.bundle"; + }; 151F63DA09328A3C0096DCC9 /* Schema */ = { isa = PBXNativeTarget; buildConfigurationList = 151F63DC09328A3C0096DCC9 /* Build configuration list for PBXNativeTarget "Schema" */; @@ -2112,6 +2170,7 @@ 151F63DA09328A3C0096DCC9 /* Schema */, 15DAD63F07591A1A0084A6ED /* SystemConfiguration.framework */, 1547001808455B98006787CE /* SCHelper */, + 151F5D990CCE98E50093AC3B /* SCMonitor */, 159D549F07529FFF004F8947 /* configd */, 1558481207550EC10046C2E9 /* scselect */, 155847430754FDCD0046C2E9 /* scutil */, @@ -2136,6 +2195,14 @@ /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 151F5D960CCE98E50093AC3B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 15FEE81F0CD03E75001312F9 /* Localizable.strings in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 15828AE30753B5F900AD4710 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -2319,6 +2386,14 @@ /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 151F5D970CCE98E50093AC3B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 15FC130B0CCEA59E0013872C /* monitor.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 1547001A08455B98006787CE /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -2555,6 +2630,11 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + 150ECB3C0D0079280065E94D /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 151F5D990CCE98E50093AC3B /* SCMonitor */; + targetProxy = 150ECB3B0D0079280065E94D /* PBXContainerItemProxy */; + }; 1520A386084681350010B584 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 1547001808455B98006787CE /* SCHelper */; @@ -2689,9 +2769,68 @@ name = Localizable.strings; sourceTree = ""; }; + 15FEE8180CD03CBB001312F9 /* Localizable.strings */ = { + isa = PBXVariantGroup; + children = ( + 15FEE8160CD03CA3001312F9 /* English */, + ); + name = Localizable.strings; + sourceTree = ""; + }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ + 151F5D9C0CCE98E60093AC3B /* Development */ = { + isa = XCBuildConfiguration; + buildSettings = { + COPY_PHASE_STRIP = NO; + FRAMEWORK_SEARCH_PATHS = "$(SYMROOT)"; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_MODEL_TUNING = G5; + GCC_OPTIMIZATION_LEVEL = 0; + INFOPLIST_FILE = "$(SRCROOT)/SCMonitor/Info.plist"; + INSTALL_MODE_FLAG = "a-w,a+rX"; + INSTALL_PATH = /System/Library/UserEventPlugins; + PRODUCT_NAME = SCMonitor; + WRAPPER_EXTENSION = plugin; + ZERO_LINK = YES; + }; + name = Development; + }; + 151F5D9D0CCE98E60093AC3B /* Deployment */ = { + isa = XCBuildConfiguration; + buildSettings = { + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + FRAMEWORK_SEARCH_PATHS = "$(SYMROOT)"; + GCC_ENABLE_FIX_AND_CONTINUE = NO; + GCC_MODEL_TUNING = G5; + INFOPLIST_FILE = "$(SRCROOT)/SCMonitor/Info.plist"; + INSTALL_MODE_FLAG = "a-w,a+rX"; + INSTALL_PATH = /System/Library/UserEventPlugins; + PRODUCT_NAME = SCMonitor; + WRAPPER_EXTENSION = plugin; + ZERO_LINK = NO; + }; + name = Deployment; + }; + 151F5D9E0CCE98E60093AC3B /* Default */ = { + isa = XCBuildConfiguration; + buildSettings = { + FRAMEWORK_SEARCH_PATHS = "$(SYMROOT)"; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_MODEL_TUNING = G5; + INFOPLIST_FILE = "$(SRCROOT)/SCMonitor/Info.plist"; + INSTALL_MODE_FLAG = "a-w,a+rX"; + INSTALL_PATH = /System/Library/UserEventPlugins; + PRODUCT_NAME = SCMonitor; + VALID_ARCHS = "i386 ppc"; + WRAPPER_EXTENSION = plugin; + ZERO_LINK = YES; + }; + name = Default; + }; 151F63DD09328A3C0096DCC9 /* Development */ = { isa = XCBuildConfiguration; buildSettings = { @@ -2749,7 +2888,7 @@ buildSettings = { COPY_PHASE_STRIP = NO; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 204; + DYLIB_CURRENT_VERSION = 210; GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES; INSTALLHDRS_COPY_PHASE = YES; INSTALL_MODE_FLAG = "a-w,a+rX"; @@ -2770,7 +2909,7 @@ buildSettings = { COPY_PHASE_STRIP = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 204; + DYLIB_CURRENT_VERSION = 210; GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES; INSTALLHDRS_COPY_PHASE = YES; INSTALL_MODE_FLAG = "a-w,a+rX"; @@ -2790,7 +2929,7 @@ isa = XCBuildConfiguration; buildSettings = { DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 204; + DYLIB_CURRENT_VERSION = 210; INSTALLHDRS_COPY_PHASE = YES; INSTALL_MODE_FLAG = "a-w,a+rX"; INSTALL_PATH = /usr/local/lib; @@ -2810,7 +2949,7 @@ buildSettings = { COPY_PHASE_STRIP = NO; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 204; + DYLIB_CURRENT_VERSION = 210; FRAMEWORK_SEARCH_PATHS = "$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks"; HEADER_SEARCH_PATHS = "$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders"; INFOPLIST_FILE = SystemConfiguration.fproj/Info.plist; @@ -2842,7 +2981,7 @@ buildSettings = { COPY_PHASE_STRIP = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 204; + DYLIB_CURRENT_VERSION = 210; FRAMEWORK_SEARCH_PATHS = "$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks"; HEADER_SEARCH_PATHS = "$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders"; INFOPLIST_FILE = SystemConfiguration.fproj/Info.plist; @@ -2873,7 +3012,7 @@ isa = XCBuildConfiguration; buildSettings = { DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 204; + DYLIB_CURRENT_VERSION = 210; FRAMEWORK_SEARCH_PATHS = "$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks"; HEADER_SEARCH_PATHS = "$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders"; INFOPLIST_FILE = SystemConfiguration.fproj/Info.plist; @@ -3879,7 +4018,7 @@ 156EB63F0905594A00EEF749 /* Development */ = { isa = XCBuildConfiguration; buildSettings = { - CURRENT_PROJECT_VERSION = 204; + CURRENT_PROJECT_VERSION = 210; DEAD_CODE_STRIPPING = YES; INSTALL_GROUP = wheel; INSTALL_MODE_FLAG = "u+s,ugo-w,o+rX"; @@ -3900,7 +4039,7 @@ 156EB6400905594A00EEF749 /* Deployment */ = { isa = XCBuildConfiguration; buildSettings = { - CURRENT_PROJECT_VERSION = 204; + CURRENT_PROJECT_VERSION = 210; DEAD_CODE_STRIPPING = YES; INSTALL_GROUP = wheel; INSTALL_MODE_FLAG = "u+s,ugo-w,o+rX"; @@ -3921,7 +4060,7 @@ 156EB6410905594A00EEF749 /* Default */ = { isa = XCBuildConfiguration; buildSettings = { - CURRENT_PROJECT_VERSION = 204; + CURRENT_PROJECT_VERSION = 210; DEAD_CODE_STRIPPING = YES; INSTALL_GROUP = wheel; INSTALL_MODE_FLAG = "u+s,ugo-w,o+rX"; @@ -4022,6 +4161,16 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 151F5D9F0CCE98E60093AC3B /* Build configuration list for PBXNativeTarget "SCMonitor" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 151F5D9C0CCE98E60093AC3B /* Development */, + 151F5D9D0CCE98E60093AC3B /* Deployment */, + 151F5D9E0CCE98E60093AC3B /* Default */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Default; + }; 151F63DC09328A3C0096DCC9 /* Build configuration list for PBXNativeTarget "Schema" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/scutil.tproj/commands.c b/scutil.tproj/commands.c index 0b20ebf..e50043a 100644 --- a/scutil.tproj/commands.c +++ b/scutil.tproj/commands.c @@ -299,6 +299,9 @@ const cmdInfo commands_prefs[] = { { "close", 0, 1, do_prefs_close, 2, 1, " close [!] : close current \"preference\" session" }, + { "synchronize",0, 1, do_prefs_synchronize, 2, 0, + " synchronize : synchronize a \"preferences\" session" }, + { "list", 0, 1, do_prefs_list, 4, 0, " list [path] : list preference paths" }, diff --git a/scutil.tproj/prefs.c b/scutil.tproj/prefs.c index 361cbc3..855de89 100644 --- a/scutil.tproj/prefs.c +++ b/scutil.tproj/prefs.c @@ -663,6 +663,15 @@ do_prefs_quit(int argc, char **argv) } +__private_extern__ +void +do_prefs_synchronize(int argc, char **argv) +{ + SCPreferencesSynchronize(prefs); + return; +} + + static CFComparisonResult sort_paths(const void *p1, const void *p2, void *context) { CFStringRef path1 = (CFStringRef)p1; diff --git a/scutil.tproj/prefs.h b/scutil.tproj/prefs.h index 27ae2cf..feb55be 100644 --- a/scutil.tproj/prefs.h +++ b/scutil.tproj/prefs.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2005, 2006 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2003, 2005-2007 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -58,6 +58,7 @@ void do_prefs_unlock (int argc, char **argv); void do_prefs_commit (int argc, char **argv); void do_prefs_apply (int argc, char **argv); void do_prefs_close (int argc, char **argv); +void do_prefs_synchronize (int argc, char **argv); void do_prefs_list (int argc, char **argv); void do_prefs_get (int argc, char **argv); -- 2.47.2