#include "configd.h"
#include "session.h"
__private_extern__
int
__SCDynamicStoreNotifyValue(SCDynamicStoreRef store, CFStringRef key, Boolean internal)
{
CFDictionaryRef dict;
Boolean newValue = FALSE;
SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
int sc_status = kSCStatusOK;
CFDataRef value;
SC_trace("%s : %5d : %@",
internal ? "*notify" : "notify ",
storePrivate->server,
key);
dict = CFDictionaryGetValue(storeData, key);
if (!dict || !CFDictionaryGetValueIfPresent(dict, kSCDData, (const void **)&value)) {
(void)_SCSerialize(kCFBooleanTrue, &value, NULL, NULL);
newValue = TRUE;
}
__SCDynamicStoreSetValue(store, key, value, TRUE);
if (newValue) {
__SCDynamicStoreRemoveValue(store, key, TRUE);
CFRelease(value);
}
if (!internal) {
__SCDynamicStorePush();
}
return sc_status;
}
__private_extern__
kern_return_t
_confignotify(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("SCDynamicStoreNotifyValue"), audit_token);
if (mySession == NULL) {
*sc_status = kSCStatusNoStoreSession;
goto done;
}
}
if (!hasWriteAccess(mySession, "notify", key)) {
*sc_status = kSCStatusAccessError;
goto done;
}
*sc_status = __SCDynamicStoreNotifyValue(mySession->store, key, FALSE);
done :
if (key) CFRelease(key);
return KERN_SUCCESS;
}