2 * Copyright (c) 2000-2006, 2008, 2011, 2013-2016, 2019 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
30 * March 24, 2000 Allan Nathanson <ajn@apple.com>
39 __SCDynamicStoreCopyValue(SCDynamicStoreRef store
, CFStringRef key
, CFDataRef
*value
, Boolean internal
)
41 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
44 SC_trace("%s : %5d : %@",
45 internal
? "*copy " : "copy ",
49 dict
= CFDictionaryGetValue(storeData
, key
);
50 if ((dict
== NULL
) || !CFDictionaryContainsKey(dict
, kSCDData
)) {
51 /* key doesn't exist (or data never defined) */
52 return kSCStatusNoKey
;
55 /* Return the data associated with the key */
56 *value
= CFRetain(CFDictionaryGetValue(dict
, kSCDData
));
63 _configget(mach_port_t server
,
64 xmlData_t keyRef
, /* raw XML bytes */
65 mach_msg_type_number_t keyLen
,
66 xmlDataOut_t
*dataRef
, /* raw XML bytes */
67 mach_msg_type_number_t
*dataLen
,
70 audit_token_t audit_token
)
72 CFStringRef key
= NULL
; /* key (un-serialized) */
74 serverSessionRef mySession
;
82 /* un-serialize the key */
83 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
84 *sc_status
= kSCStatusFailed
;
88 if (!isA_CFString(key
)) {
89 *sc_status
= kSCStatusInvalidArgument
;
93 mySession
= getSession(server
);
94 if (mySession
== NULL
) {
95 mySession
= tempSession(server
, CFSTR("SCDynamicStoreCopyValue"), audit_token
);
96 if (mySession
== NULL
) {
97 /* you must have an open session to play */
98 *sc_status
= kSCStatusNoStoreSession
;
103 *sc_status
= __SCDynamicStoreCopyValue(mySession
->store
, key
, &value
, FALSE
);
104 if (*sc_status
!= kSCStatusOK
) {
108 /* serialize the data */
109 ok
= _SCSerializeData(value
, (void **)dataRef
, &len
);
110 *dataLen
= (mach_msg_type_number_t
)len
;
113 *sc_status
= kSCStatusFailed
;
119 if (key
!= NULL
) CFRelease(key
);
124 * "context" argument for addSpecificKey() and addSpecificPattern()
127 SCDynamicStoreRef store
;
128 CFMutableDictionaryRef dict
;
129 } addSpecific
, *addSpecificRef
;
132 addSpecificKey(const void *value
, void *context
)
135 CFStringRef key
= (CFStringRef
)value
;
136 addSpecificRef myContextRef
= (addSpecificRef
)context
;
139 if (!isA_CFString(key
)) {
143 sc_status
= __SCDynamicStoreCopyValue(myContextRef
->store
, key
, &data
, TRUE
);
144 if (sc_status
== kSCStatusOK
) {
145 CFDictionaryAddValue(myContextRef
->dict
, key
, data
);
153 addSpecificPattern(const void *value
, void *context
)
155 CFStringRef pattern
= (CFStringRef
)value
;
156 addSpecificRef myContextRef
= (addSpecificRef
)context
;
160 if (!isA_CFString(pattern
)) {
164 sc_status
= __SCDynamicStoreCopyKeyList(myContextRef
->store
, pattern
, TRUE
, &keys
);
165 if (sc_status
== kSCStatusOK
) {
166 CFArrayApplyFunction(keys
,
167 CFRangeMake(0, CFArrayGetCount(keys
)),
178 __SCDynamicStoreCopyMultiple(SCDynamicStoreRef store
, CFArrayRef keys
, CFArrayRef patterns
, CFDictionaryRef
*values
)
180 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
181 addSpecific myContext
;
183 SC_trace("copy m : %5d : %ld keys, %ld patterns",
184 storePrivate
->server
,
185 keys
? CFArrayGetCount(keys
) : 0,
186 patterns
? CFArrayGetCount(patterns
) : 0);
188 myContext
.store
= store
;
189 myContext
.dict
= CFDictionaryCreateMutable(NULL
,
191 &kCFTypeDictionaryKeyCallBacks
,
192 &kCFTypeDictionaryValueCallBacks
);
195 CFArrayApplyFunction(keys
,
196 CFRangeMake(0, CFArrayGetCount(keys
)),
202 CFArrayApplyFunction(patterns
,
203 CFRangeMake(0, CFArrayGetCount(patterns
)),
208 /* Return the keys/values associated with the key */
209 *values
= myContext
.dict
;
216 _configget_m(mach_port_t server
,
218 mach_msg_type_number_t keysLen
,
219 xmlData_t patternsRef
,
220 mach_msg_type_number_t patternsLen
,
221 xmlDataOut_t
*dataRef
,
222 mach_msg_type_number_t
*dataLen
,
224 audit_token_t audit_token
)
226 CFDictionaryRef dict
= NULL
; /* keys/values (un-serialized) */
227 CFArrayRef keys
= NULL
; /* keys (un-serialized) */
229 serverSessionRef mySession
;
231 CFArrayRef patterns
= NULL
; /* patterns (un-serialized) */
236 *sc_status
= kSCStatusOK
;
238 if (keysRef
&& (keysLen
> 0)) {
239 /* un-serialize the keys */
240 if (!_SCUnserialize((CFPropertyListRef
*)&keys
, NULL
, (void *)keysRef
, keysLen
)) {
241 *sc_status
= kSCStatusFailed
;
245 if (patternsRef
&& (patternsLen
> 0)) {
246 /* un-serialize the patterns */
247 if (!_SCUnserialize((CFPropertyListRef
*)&patterns
, NULL
, (void *)patternsRef
, patternsLen
)) {
248 *sc_status
= kSCStatusFailed
;
252 if (*sc_status
!= kSCStatusOK
) {
256 if ((keys
!= NULL
) && !isA_CFArray(keys
)) {
257 *sc_status
= kSCStatusInvalidArgument
;
261 if ((patterns
!= NULL
) && !isA_CFArray(patterns
)) {
262 *sc_status
= kSCStatusInvalidArgument
;
266 mySession
= getSession(server
);
267 if (mySession
== NULL
) {
268 mySession
= tempSession(server
, CFSTR("SCDynamicStoreCopyMultiple"), audit_token
);
269 if (mySession
== NULL
) {
270 /* you must have an open session to play */
271 *sc_status
= kSCStatusNoStoreSession
;
276 /* fetch the requested information */
277 *sc_status
= __SCDynamicStoreCopyMultiple(mySession
->store
, keys
, patterns
, &dict
);
279 /* serialize the dictionary of matching keys/patterns */
280 ok
= _SCSerialize(dict
, NULL
, (void **)dataRef
, &len
);
281 *dataLen
= (mach_msg_type_number_t
)len
;
284 *sc_status
= kSCStatusFailed
;
289 if (keys
) CFRelease(keys
);
290 if (patterns
) CFRelease(patterns
);