X-Git-Url: https://git.saurik.com/apple/configd.git/blobdiff_plain/dbf6a266c384fc8b55e00a396eebe5cb62e21547..HEAD:/configd.tproj/_snapshot.c diff --git a/configd.tproj/_snapshot.c b/configd.tproj/_snapshot.c index 22b2326..854d36c 100644 --- a/configd.tproj/_snapshot.c +++ b/configd.tproj/_snapshot.c @@ -1,15 +1,15 @@ /* - * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2006, 2009-2011, 2015, 2018, 2019 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ - * + * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. - * + * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, @@ -17,7 +17,7 @@ * 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@ */ @@ -38,16 +38,17 @@ #include "configd.h" #include "configd_server.h" #include "session.h" +#include "plugin_support.h" -#define SNAPSHOT_PATH_STORE _PATH_VARTMP "configd-store.xml" -#define SNAPSHOT_PATH_PATTERN _PATH_VARTMP "configd-pattern.xml" -#define SNAPSHOT_PATH_SESSION _PATH_VARTMP "configd-session.xml" +#define SNAPSHOT_PATH_STATE _PATH_VARTMP "configd-state" +#define SNAPSHOT_PATH_STORE _PATH_VARTMP "configd-store.plist" +#define SNAPSHOT_PATH_PATTERN _PATH_VARTMP "configd-pattern.plist" #define N_QUICK 100 -static CFDictionaryRef +static CF_RETURNS_RETAINED CFDictionaryRef _expandStore(CFDictionaryRef storeData) { const void * keys_q[N_QUICK]; @@ -68,7 +69,7 @@ _expandStore(CFDictionaryRef storeData) oValues = CFAllocatorAllocate(NULL, nElements * sizeof(CFTypeRef), 0); nValues = CFAllocatorAllocate(NULL, nElements * sizeof(CFTypeRef), 0); } - bzero(nValues, nElements * sizeof(CFTypeRef)); + memset(nValues, 0, nElements * sizeof(CFTypeRef)); CFDictionaryGetKeysAndValues(storeData, keys, oValues); for (i = 0; i < nElements; i++) { @@ -78,11 +79,13 @@ _expandStore(CFDictionaryRef storeData) if (data) { CFPropertyListRef plist; + nValues[i] = CFDictionaryCreateMutableCopy(NULL, 0, oValues[i]); + if (!_SCUnserialize(&plist, data, NULL, 0)) { - goto done; + SC_log(LOG_NOTICE, "_SCUnserialize() failed, key=%@", keys[i]); + continue; } - nValues[i] = CFDictionaryCreateMutableCopy(NULL, 0, oValues[i]); CFDictionarySetValue((CFMutableDictionaryRef)nValues[i], kSCDData, plist); @@ -100,13 +103,11 @@ _expandStore(CFDictionaryRef storeData) &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - done : - if (nElements > 0) { CFIndex i; for (i = 0; i < nElements; i++) { - if (nValues[i]) CFRelease(nValues[i]); + CFRelease(nValues[i]); } if (keys != keys_q) { @@ -124,32 +125,41 @@ __private_extern__ int __SCDynamicStoreSnapshot(SCDynamicStoreRef store) { +#pragma unused(store) CFDictionaryRef expandedStoreData; + FILE *f; int fd; - serverSessionRef mySession; - SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store; CFDataRef xmlData; - /* check credentials */ + /* Save a snapshot of configd's "state" */ - mySession = getSession(storePrivate->server); - if (mySession->callerEUID != 0) { - return kSCStatusAccessError; + (void) unlink(SNAPSHOT_PATH_STATE); + fd = open(SNAPSHOT_PATH_STATE, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644); + if (fd == -1) { + return kSCStatusFailed; + } + f = fdopen(fd, "w"); + if (f == NULL) { + return kSCStatusFailed; } + SCPrint(TRUE, f, CFSTR("Main [plug-in] thread :\n\n")); + SCPrint(TRUE, f, CFSTR("%@\n"), CFRunLoopGetCurrent()); + listSessions(f); + (void) fclose(f); /* Save a snapshot of the "store" data */ (void) unlink(SNAPSHOT_PATH_STORE); - fd = open(SNAPSHOT_PATH_STORE, O_WRONLY|O_CREAT|O_TRUNC, 0644); - if (fd < 0) { + fd = open(SNAPSHOT_PATH_STORE, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644); + if (fd == -1) { return kSCStatusFailed; } expandedStoreData = _expandStore(storeData); - xmlData = CFPropertyListCreateXMLData(NULL, expandedStoreData); + xmlData = CFPropertyListCreateData(NULL, expandedStoreData, kCFPropertyListXMLFormat_v1_0, 0, NULL); CFRelease(expandedStoreData); - if (!xmlData) { - SCLog(TRUE, LOG_ERR, CFSTR("__SCDynamicStoreSnapshot CFPropertyListCreateXMLData() failed")); + if (xmlData == NULL) { + SC_log(LOG_NOTICE, "CFPropertyListCreateData() failed"); close(fd); return kSCStatusFailed; } @@ -160,32 +170,14 @@ __SCDynamicStoreSnapshot(SCDynamicStoreRef store) /* Save a snapshot of the "pattern" data */ (void) unlink(SNAPSHOT_PATH_PATTERN); - fd = open(SNAPSHOT_PATH_PATTERN, O_WRONLY|O_CREAT|O_TRUNC, 0644); - if (fd < 0) { + fd = open(SNAPSHOT_PATH_PATTERN, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644); + if (fd == -1) { return kSCStatusFailed; } - xmlData = CFPropertyListCreateXMLData(NULL, patternData); - if (!xmlData) { - SCLog(TRUE, LOG_ERR, CFSTR("__SCDynamicStoreSnapshot CFPropertyListCreateXMLData() failed")); - close(fd); - return kSCStatusFailed; - } - (void) write(fd, CFDataGetBytePtr(xmlData), CFDataGetLength(xmlData)); - (void) close(fd); - CFRelease(xmlData); - - /* Save a snapshot of the "session" data */ - - (void) unlink(SNAPSHOT_PATH_SESSION); - fd = open(SNAPSHOT_PATH_SESSION, O_WRONLY|O_CREAT|O_TRUNC, 0644); - if (fd < 0) { - return kSCStatusFailed; - } - - xmlData = CFPropertyListCreateXMLData(NULL, sessionData); - if (!xmlData) { - SCLog(TRUE, LOG_ERR, CFSTR("__SCDynamicStoreSnapshot CFPropertyListCreateXMLData() failed")); + xmlData = CFPropertyListCreateData(NULL, patternData, kCFPropertyListXMLFormat_v1_0, 0, NULL); + if (xmlData == NULL) { + SC_log(LOG_NOTICE, "CFPropertyListCreateData() failed"); close(fd); return kSCStatusFailed; } @@ -199,13 +191,21 @@ __SCDynamicStoreSnapshot(SCDynamicStoreRef store) __private_extern__ kern_return_t -_snapshot(mach_port_t server, int *sc_status) +_snapshot(mach_port_t server, int *sc_status, audit_token_t audit_token) { - serverSessionRef mySession = getSession(server); + serverSessionRef mySession; + + mySession = getSession(server); + if (mySession == NULL) { + mySession = tempSession(server, CFSTR("SCDynamicStoreSnapshot"), audit_token); + if (mySession == NULL) { + /* you must have an open session to play */ + return kSCStatusNoStoreSession; + } + } - if (!mySession) { - *sc_status = kSCStatusNoStoreSession; /* you must have an open session to play */ - return KERN_SUCCESS; + if (!hasRootAccess(mySession)) { + return kSCStatusAccessError; } *sc_status = __SCDynamicStoreSnapshot(mySession->store);