#include "configd.h"
#include "configd_server.h"
#include "session.h"
#include <bsm/libbsm.h>
#include <sys/types.h>
#include <unistd.h>
__private_extern__
int
__SCDynamicStoreOpen(SCDynamicStoreRef *store, CFStringRef name)
{
*store = (SCDynamicStoreRef)__SCDynamicStoreCreatePrivate(NULL, name, NULL, NULL);
if (storeData == NULL) {
storeData = CFDictionaryCreateMutable(NULL,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
patternData = CFDictionaryCreateMutable(NULL,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
changedKeys = CFSetCreateMutable(NULL,
0,
&kCFTypeSetCallBacks);
deferredRemovals = CFSetCreateMutable(NULL,
0,
&kCFTypeSetCallBacks);
removedSessionKeys = CFSetCreateMutable(NULL,
0,
&kCFTypeSetCallBacks);
}
return kSCStatusOK;
}
__private_extern__
kern_return_t
_configopen(mach_port_t server,
xmlData_t nameRef,
mach_msg_type_number_t nameLen,
xmlData_t optionsRef,
mach_msg_type_number_t optionsLen,
mach_port_t *newServer,
int *sc_status,
audit_token_t audit_token)
{
serverSessionRef mySession;
CFStringRef name = NULL;
CFDictionaryRef options = NULL;
SCDynamicStorePrivateRef storePrivate;
CFBooleanRef useSessionKeys = NULL;
*newServer = MACH_PORT_NULL;
*sc_status = kSCStatusOK;
if (!_SCUnserializeString(&name, NULL, (void *)nameRef, nameLen)) {
*sc_status = kSCStatusFailed;
}
if ((optionsRef != NULL) && (optionsLen > 0)) {
if (!_SCUnserialize((CFPropertyListRef *)&options, NULL, (void *)optionsRef, optionsLen)) {
*sc_status = kSCStatusFailed;
}
}
if (*sc_status != kSCStatusOK) {
goto done;
}
if (!isA_CFString(name)) {
*sc_status = kSCStatusInvalidArgument;
goto done;
}
if (options != NULL) {
if (!isA_CFDictionary(options)) {
*sc_status = kSCStatusInvalidArgument;
goto done;
}
useSessionKeys = CFDictionaryGetValue(options, kSCDynamicStoreUseSessionKeys);
if (useSessionKeys != NULL) {
if (!isA_CFBoolean(useSessionKeys)) {
*sc_status = kSCStatusInvalidArgument;
goto done;
}
}
}
mySession = addClient(server, audit_token);
if (mySession == NULL) {
SC_log(LOG_NOTICE, "session is already open");
*sc_status = kSCStatusFailed;
goto done;
}
*newServer = mySession->key;
__MACH_PORT_DEBUG(TRUE, "*** _configopen (after addClient)", *newServer);
SC_trace("open : %5d : %@",
*newServer,
name);
*sc_status = __SCDynamicStoreOpen(&mySession->store, name);
storePrivate = (SCDynamicStorePrivateRef)mySession->store;
storePrivate->server = *newServer;
if (useSessionKeys != NULL) {
storePrivate->useSessionKeys = CFBooleanGetValue(useSessionKeys);
}
mySession->name = name;
done :
if (options != NULL) CFRelease(options);
return KERN_SUCCESS;
}