2 * Copyright (c) 2000-2008, 2011, 2013, 2015, 2016 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>
42 __SCDynamicStoreCopyKeyList(SCDynamicStoreRef store
, CFStringRef key
, Boolean isRegex
, CFArrayRef
*subKeys
)
44 CFMutableArrayRef keyArray
;
46 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
48 CFDictionaryRef storeValue
;
50 SC_trace("list : %5d : %s : %@",
52 isRegex
? "pattern" : "key",
56 *subKeys
= patternCopyMatches(key
);
57 return (*subKeys
!= NULL
) ? kSCStatusOK
: kSCStatusFailed
;
60 storeCnt
= CFDictionaryGetCount(storeData
);
61 keyArray
= CFArrayCreateMutable(NULL
, storeCnt
, &kCFTypeArrayCallBacks
);
64 const void * storeKeys_q
[N_QUICK
];
65 const void ** storeKeys
= storeKeys_q
;
66 const void * storeValues_q
[N_QUICK
];
67 const void ** storeValues
= storeValues_q
;
69 if (storeCnt
> (CFIndex
)(sizeof(storeKeys_q
) / sizeof(CFStringRef
))) {
70 storeKeys
= CFAllocatorAllocate(NULL
, storeCnt
* sizeof(CFStringRef
), 0);
71 storeValues
= CFAllocatorAllocate(NULL
, storeCnt
* sizeof(CFStringRef
), 0);
74 CFDictionaryGetKeysAndValues(storeData
, storeKeys
, storeValues
);
75 for (i
= 0; i
< storeCnt
; i
++) {
76 storeStr
= (CFStringRef
)storeKeys
[i
];
77 storeValue
= (CFDictionaryRef
)storeValues
[i
];
79 * only return those keys which are prefixed by the
80 * provided key string and have data.
82 if (((CFStringGetLength(key
) == 0) || CFStringHasPrefix(storeStr
, key
)) &&
83 CFDictionaryContainsKey(storeValue
, kSCDData
)) {
84 CFArrayAppendValue(keyArray
, storeStr
);
88 if (storeKeys
!= storeKeys_q
) {
89 CFAllocatorDeallocate(NULL
, storeKeys
);
90 CFAllocatorDeallocate(NULL
, storeValues
);
94 *subKeys
= CFArrayCreateCopy(NULL
, keyArray
);
102 _configlist(mach_port_t server
,
103 xmlData_t keyRef
, /* raw XML bytes */
104 mach_msg_type_number_t keyLen
,
106 xmlDataOut_t
*listRef
, /* raw XML bytes */
107 mach_msg_type_number_t
*listLen
,
109 audit_token_t audit_token
)
111 CFStringRef key
= NULL
; /* key (un-serialized) */
113 serverSessionRef mySession
;
115 CFArrayRef subKeys
; /* array of CFStringRef's */
120 /* un-serialize the key */
121 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
122 *sc_status
= kSCStatusFailed
;
126 if (!isA_CFString(key
)) {
127 *sc_status
= kSCStatusInvalidArgument
;
131 mySession
= getSession(server
);
132 if (mySession
== NULL
) {
133 mySession
= tempSession(server
, CFSTR("SCDynamicStoreCopyKeyList"), audit_token
);
134 if (mySession
== NULL
) {
135 /* you must have an open session to play */
136 *sc_status
= kSCStatusNoStoreSession
;
141 *sc_status
= __SCDynamicStoreCopyKeyList(mySession
->store
, key
, isRegex
!= 0, &subKeys
);
142 if (*sc_status
!= kSCStatusOK
) {
146 /* serialize the list of keys */
147 ok
= _SCSerialize(subKeys
, NULL
, (void **)listRef
, &len
);
148 *listLen
= (mach_msg_type_number_t
)len
;
151 *sc_status
= kSCStatusFailed
;
157 if (key
) CFRelease(key
);