#include "configd.h"
#include "session.h"
int
__SCDynamicStoreRemoveValue(SCDynamicStoreRef store, CFStringRef key)
{
SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
int sc_status = kSCStatusOK;
CFDictionaryRef dict;
CFMutableDictionaryRef newDict;
CFStringRef sessionKey;
SCLog(_configd_verbose, LOG_DEBUG, CFSTR("__SCDynamicStoreRemoveValue:"));
SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" key = %@"), key);
if (!store || (storePrivate->server == MACH_PORT_NULL)) {
return kSCStatusNoStoreSession;
}
sc_status = __SCDynamicStoreLock(store, TRUE);
if (sc_status != kSCStatusOK) {
return sc_status;
}
dict = CFDictionaryGetValue(storeData, key);
if ((dict == NULL) || (CFDictionaryContainsKey(dict, kSCDData) == FALSE)) {
sc_status = kSCStatusNoKey;
goto done;
}
newDict = CFDictionaryCreateMutableCopy(NULL, 0, dict);
CFSetAddValue(changedKeys, key);
CFSetAddValue(deferredRemovals, key);
sessionKey = CFDictionaryGetValue(newDict, kSCDSession);
if (sessionKey) {
CFStringRef removedKey;
CFDictionaryRemoveValue(newDict, kSCDSession);
removedKey = CFStringCreateWithFormat(NULL, 0, CFSTR("%@:%@"), sessionKey, key);
CFSetAddValue(removedSessionKeys, removedKey);
CFRelease(removedKey);
}
CFDictionaryRemoveValue(newDict, kSCDData);
CFDictionaryRemoveValue(newDict, kSCDInstance);
if (CFDictionaryGetCount(newDict) > 0) {
CFDictionarySetValue(storeData, key, newDict);
} else {
CFDictionaryRemoveValue(storeData, key);
}
CFRelease(newDict);
done:
__SCDynamicStoreUnlock(store, TRUE);
return sc_status;
}
kern_return_t
_configremove(mach_port_t server,
xmlData_t keyRef,
mach_msg_type_number_t keyLen,
int *sc_status
)
{
kern_return_t status;
serverSessionRef mySession = getSession(server);
CFDataRef xmlKey;
CFStringRef key;
CFStringRef xmlError;
SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Remove key from configuration database."));
SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" server = %d"), server);
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));
}
key = CFPropertyListCreateFromXMLData(NULL,
xmlKey,
kCFPropertyListImmutable,
&xmlError);
CFRelease(xmlKey);
if (!key) {
if (xmlError) {
SCLog(_configd_verbose, LOG_DEBUG,
CFSTR("CFPropertyListCreateFromXMLData() key: %@"),
xmlError);
CFRelease(xmlError);
}
*sc_status = kSCStatusFailed;
return KERN_SUCCESS;
} else if (!isA_CFString(key)) {
*sc_status = kSCStatusInvalidArgument;
return KERN_SUCCESS;
}
*sc_status = __SCDynamicStoreRemoveValue(mySession->store, key);
CFRelease(key);
return KERN_SUCCESS;
}