#include "configd.h"
#include "session.h"
__private_extern__
int
__SCDynamicStoreAddValue(SCDynamicStoreRef store, CFStringRef key, CFDataRef value)
{
int sc_status = kSCStatusOK;
SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
CFDataRef tempValue;
SC_trace(_configd_trace, "%s%s : %5d : %@\n",
"add ",
storePrivate->useSessionKeys ? "t " : " ",
storePrivate->server,
key);
sc_status = __SCDynamicStoreCopyValue(store, key, &tempValue, TRUE);
switch (sc_status) {
case kSCStatusNoKey :
break;
case kSCStatusOK :
CFRelease(tempValue);
sc_status = kSCStatusKeyExists;
goto done;
default :
#ifdef DEBUG
SC_log(LOG_DEBUG, "__SCDynamicStoreCopyValue() failed: %s", SCErrorString(sc_status));
#endif
goto done;
}
sc_status = __SCDynamicStoreSetValue(store, key, value, TRUE);
__SCDynamicStorePush();
done:
return sc_status;
}
__private_extern__
kern_return_t
_configadd(mach_port_t server,
xmlData_t keyRef,
mach_msg_type_number_t keyLen,
xmlData_t dataRef,
mach_msg_type_number_t dataLen,
int *newInstance,
int *sc_status,
audit_token_t audit_token)
{
CFStringRef key = NULL;
CFDataRef data = NULL;
serverSessionRef mySession;
*sc_status = kSCStatusOK;
if (!_SCUnserializeString(&key, NULL, (void *)keyRef, keyLen)) {
*sc_status = kSCStatusFailed;
goto done;
}
if (!_SCUnserializeData(&data, (void *)dataRef, dataLen)) {
*sc_status = kSCStatusFailed;
}
if (*sc_status != kSCStatusOK) {
goto done;
}
if (!isA_CFString(key)) {
*sc_status = kSCStatusInvalidArgument;
goto done;
}
mySession = getSession(server);
if (mySession == NULL) {
mySession = tempSession(server, CFSTR("SCDynamicStoreAddValue"), audit_token);
if (mySession == NULL) {
*sc_status = kSCStatusNoStoreSession;
goto done;
}
}
if (!hasWriteAccess(mySession, key)) {
*sc_status = kSCStatusAccessError;
goto done;
}
*sc_status = __SCDynamicStoreAddValue(mySession->store, key, data);
if (*sc_status == kSCStatusOK) {
*newInstance = 0;
}
done :
if (key != NULL) CFRelease(key);
if (data != NULL) CFRelease(data);
return KERN_SUCCESS;
}
__private_extern__
kern_return_t
_configadd_s(mach_port_t server,
xmlData_t keyRef,
mach_msg_type_number_t keyLen,
xmlData_t dataRef,
mach_msg_type_number_t dataLen,
int *newInstance,
int *sc_status)
{
CFDataRef data = NULL;
CFStringRef key = NULL;
serverSessionRef mySession;
SCDynamicStorePrivateRef storePrivate;
Boolean useSessionKeys;
*sc_status = kSCStatusOK;
if (!_SCUnserializeString(&key, NULL, (void *)keyRef, keyLen)) {
*sc_status = kSCStatusFailed;
}
if (!_SCUnserializeData(&data, (void *)dataRef, dataLen)) {
*sc_status = kSCStatusFailed;
}
if (*sc_status != kSCStatusOK) {
goto done;
}
if (!isA_CFString(key)) {
*sc_status = kSCStatusInvalidArgument;
goto done;
}
mySession = getSession(server);
if (mySession == NULL) {
*sc_status = kSCStatusNoStoreSession;
goto done;
}
if (!hasWriteAccess(mySession, key)) {
*sc_status = kSCStatusAccessError;
goto done;
}
storePrivate = (SCDynamicStorePrivateRef)mySession->store;
useSessionKeys = storePrivate->useSessionKeys;
storePrivate->useSessionKeys = TRUE;
*sc_status = __SCDynamicStoreAddValue(mySession->store, key, data);
if (*sc_status == kSCStatusOK) {
*newInstance = 0;
}
storePrivate->useSessionKeys = useSessionKeys;
done :
if (key != NULL) CFRelease(key);
if (data != NULL) CFRelease(data);
return KERN_SUCCESS;
}