#include "configd.h"
#include "session.h"
__private_extern__
int
__SCDynamicStoreRemoveValue(SCDynamicStoreRef store, CFStringRef key, Boolean internal)
{
CFDictionaryRef dict;
CFMutableDictionaryRef newDict;
SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
int sc_status = kSCStatusOK;
CFStringRef sessionKey;
SC_trace(_configd_trace, "%s : %5d : %@\n",
internal ? "*remove" : "remove ",
storePrivate->server,
key);
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);
if (CFDictionaryGetCount(newDict) > 0) {
CFDictionarySetValue(storeData, key, newDict);
} else {
CFDictionaryRemoveValue(storeData, key);
}
CFRelease(newDict);
if (!internal) {
__SCDynamicStorePush();
}
done:
return sc_status;
}
__private_extern__
kern_return_t
_configremove(mach_port_t server,
xmlData_t keyRef,
mach_msg_type_number_t keyLen,
int *sc_status,
audit_token_t audit_token)
{
CFStringRef key = NULL;
serverSessionRef mySession;
if (!_SCUnserializeString(&key, NULL, (void *)keyRef, keyLen)) {
*sc_status = kSCStatusFailed;
goto done;
}
if (!isA_CFString(key)) {
*sc_status = kSCStatusInvalidArgument;
goto done;
}
mySession = getSession(server);
if (mySession == NULL) {
mySession = tempSession(server, CFSTR("SCDynamicStoreRemoveValue"), audit_token);
if (mySession == NULL) {
*sc_status = kSCStatusNoStoreSession;
goto done;
}
}
if (!hasWriteAccess(mySession, key)) {
*sc_status = kSCStatusAccessError;
goto done;
}
*sc_status = __SCDynamicStoreRemoveValue(mySession->store, key, FALSE);
done :
if (key) CFRelease(key);
return KERN_SUCCESS;
}