+ if (!isA_CFString(key)) {
+ return;
+ }
+
+ sc_status = __SCDynamicStoreCopyValue(myContextRef->store, key, &data);
+ if (sc_status == kSCStatusOK) {
+ CFDictionaryAddValue(myContextRef->dict, key, data);
+ CFRelease(data);
+ }
+
+ return;
+}
+
+static void
+addSpecificPattern(const void *value, void *context)
+{
+ CFStringRef pattern = (CFStringRef)value;
+ addSpecificRef myContextRef = (addSpecificRef)context;
+ int sc_status;
+ CFArrayRef keys;
+
+ if (!isA_CFString(pattern)) {
+ return;
+ }
+
+ sc_status = __SCDynamicStoreCopyKeyList(myContextRef->store, pattern, TRUE, &keys);
+ if (sc_status == kSCStatusOK) {
+ CFArrayApplyFunction(keys,
+ CFRangeMake(0, CFArrayGetCount(keys)),
+ addSpecificKey,
+ context);
+ CFRelease(keys);
+ }
+
+ return;
+}
+
+kern_return_t
+_configget_m(mach_port_t server,
+ xmlData_t keysRef,
+ mach_msg_type_number_t keysLen,
+ xmlData_t patternsRef,
+ mach_msg_type_number_t patternsLen,
+ xmlDataOut_t *dataRef,
+ mach_msg_type_number_t *dataLen,
+ int *sc_status)
+{
+ CFArrayRef keys = NULL; /* keys (un-serialized) */
+ addSpecific myContext;
+ serverSessionRef mySession = getSession(server);
+ Boolean ok;
+ CFArrayRef patterns = NULL; /* patterns (un-serialized) */
+
+ SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Get key from configuration database."));
+ SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" server = %d"), server);
+
+ *dataRef = NULL;
+ *dataLen = 0;
+ *sc_status = kSCStatusOK;
+
+ if (keysRef && (keysLen > 0)) {
+ /* un-serialize the keys */
+ if (!_SCUnserialize((CFPropertyListRef *)&keys, (void *)keysRef, keysLen)) {
+ *sc_status = kSCStatusFailed;
+ }
+
+ if (!isA_CFArray(keys)) {
+ *sc_status = kSCStatusInvalidArgument;
+ }
+ }
+
+ if (patternsRef && (patternsLen > 0)) {
+ /* un-serialize the patterns */
+ if (!_SCUnserialize((CFPropertyListRef *)&patterns, (void *)patternsRef, patternsLen)) {
+ *sc_status = kSCStatusFailed;
+ }
+
+ if (!isA_CFArray(patterns)) {
+ *sc_status = kSCStatusInvalidArgument;
+ }
+ }
+
+ if (*sc_status != kSCStatusOK) {
+ if (keys) CFRelease(keys);
+ if (patterns) CFRelease(patterns);
+ return KERN_SUCCESS;
+ }
+
+ myContext.store = mySession->store;
+ myContext.dict = CFDictionaryCreateMutable(NULL,
+ 0,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+
+ if (keys) {
+ CFArrayApplyFunction(keys,
+ CFRangeMake(0, CFArrayGetCount(keys)),
+ addSpecificKey,
+ &myContext);
+ CFRelease(keys);
+ }
+
+ if (patterns) {
+ CFArrayApplyFunction(patterns,
+ CFRangeMake(0, CFArrayGetCount(patterns)),
+ addSpecificPattern,
+ &myContext);
+ CFRelease(patterns);
+ }
+
+ /* serialize the dictionary of matching keys/patterns */
+ ok = _SCSerialize(myContext.dict, NULL, (void **)dataRef, (CFIndex *)dataLen);
+ CFRelease(myContext.dict);
+ if (!ok) {
+ *sc_status = kSCStatusFailed;
+ return KERN_SUCCESS;
+ }