]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCDGet.c
configd-963.260.1.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCDGet.c
1 /*
2 * Copyright (c) 2000-2005, 2009-2011, 2013, 2016, 2017 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*
25 * Modification History
26 *
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
29 *
30 * March 24, 2000 Allan Nathanson <ajn@apple.com>
31 * - initial revision
32 */
33
34 #include "SCDynamicStoreInternal.h"
35 #include "config.h" /* MiG generated file */
36
37
38 CFDictionaryRef
39 SCDynamicStoreCopyMultiple(SCDynamicStoreRef store,
40 CFArrayRef keys,
41 CFArrayRef patterns)
42 {
43 SCDynamicStorePrivateRef storePrivate;
44 kern_return_t status;
45 CFDataRef xmlKeys = NULL; /* keys (XML serialized) */
46 xmlData_t myKeysRef = NULL; /* keys (serialized) */
47 CFIndex myKeysLen = 0;
48 CFDataRef xmlPatterns = NULL; /* patterns (XML serialized) */
49 xmlData_t myPatternsRef = NULL; /* patterns (serialized) */
50 CFIndex myPatternsLen = 0;
51 xmlDataOut_t xmlDictRef = NULL; /* dict (serialized) */
52 mach_msg_type_number_t xmlDictLen = 0;
53 CFDictionaryRef dict = NULL; /* dict (un-serialized) */
54 CFDictionaryRef expDict = NULL; /* dict (un-serialized / expanded) */
55 int sc_status;
56
57 if (store == NULL) {
58 store = __SCDynamicStoreNullSession();
59 if (store == NULL) {
60 /* sorry, you must provide a session */
61 _SCErrorSet(kSCStatusNoStoreSession);
62 return NULL;
63 }
64 }
65
66 storePrivate = (SCDynamicStorePrivateRef)store;
67 if (storePrivate->server == MACH_PORT_NULL) {
68 _SCErrorSet(kSCStatusNoStoreServer);
69 return NULL; /* you must have an open session to play */
70 }
71
72 /* serialize the keys */
73 if (keys != NULL) {
74 if (!_SCSerialize(keys, &xmlKeys, (void **)&myKeysRef, &myKeysLen)) {
75 _SCErrorSet(kSCStatusFailed);
76 return NULL;
77 }
78 }
79
80 /* serialize the patterns */
81 if (patterns != NULL) {
82 if (!_SCSerialize(patterns, &xmlPatterns, (void **)&myPatternsRef, &myPatternsLen)) {
83 if (xmlKeys != NULL) CFRelease(xmlKeys);
84 _SCErrorSet(kSCStatusFailed);
85 return NULL;
86 }
87 }
88
89 #ifdef VERBOSE_ACTIVITY_LOGGING
90 os_activity_scope(storePrivate->activity);
91 #endif // VERBOSE_ACTIVITY_LOGGING
92
93 retry :
94
95 /* send the keys and patterns, fetch the associated result from the server */
96 status = configget_m(storePrivate->server,
97 myKeysRef,
98 (mach_msg_type_number_t)myKeysLen,
99 myPatternsRef,
100 (mach_msg_type_number_t)myPatternsLen,
101 &xmlDictRef,
102 &xmlDictLen,
103 (int *)&sc_status);
104
105 if (__SCDynamicStoreCheckRetryAndHandleError(store,
106 status,
107 &sc_status,
108 "SCDynamicStoreCopyMultiple configget_m()")) {
109 goto retry;
110 }
111
112 /* clean up */
113 if (xmlKeys != NULL) CFRelease(xmlKeys);
114 if (xmlPatterns != NULL) CFRelease(xmlPatterns);
115
116 if (sc_status != kSCStatusOK) {
117 if (xmlDictRef != NULL) {
118 (void) vm_deallocate(mach_task_self(), (vm_address_t)xmlDictRef, xmlDictLen);
119 }
120 _SCErrorSet(sc_status);
121 return NULL;
122 }
123
124 /* un-serialize the dictionary */
125 if (!_SCUnserialize((CFPropertyListRef *)&dict, NULL, xmlDictRef, xmlDictLen)) {
126 _SCErrorSet(kSCStatusFailed);
127 return NULL;
128 }
129
130 expDict = _SCUnserializeMultiple(dict);
131 CFRelease(dict);
132
133 return expDict;
134 }
135
136
137 CFPropertyListRef
138 SCDynamicStoreCopyValue(SCDynamicStoreRef store, CFStringRef key)
139 {
140 SCDynamicStorePrivateRef storePrivate;
141 kern_return_t status;
142 CFDataRef utfKey; /* key (XML serialized) */
143 xmlData_t myKeyRef; /* key (serialized) */
144 CFIndex myKeyLen;
145 xmlDataOut_t xmlDataRef = NULL; /* data (serialized) */
146 mach_msg_type_number_t xmlDataLen = 0;
147 CFPropertyListRef data; /* data (un-serialized) */
148 int newInstance;
149 int sc_status;
150
151 if (store == NULL) {
152 store = __SCDynamicStoreNullSession();
153 if (store == NULL) {
154 /* sorry, you must provide a session */
155 _SCErrorSet(kSCStatusNoStoreSession);
156 return NULL;
157 }
158 }
159
160 storePrivate = (SCDynamicStorePrivateRef)store;
161 if (storePrivate->server == MACH_PORT_NULL) {
162 _SCErrorSet(kSCStatusNoStoreServer);
163 return NULL; /* you must have an open session to play */
164 }
165
166 /* serialize the key */
167 if (!_SCSerializeString(key, &utfKey, (void **)&myKeyRef, &myKeyLen)) {
168 _SCErrorSet(kSCStatusFailed);
169 return NULL;
170 }
171
172 #ifdef VERBOSE_ACTIVITY_LOGGING
173 os_activity_scope(storePrivate->activity);
174 #endif // VERBOSE_ACTIVITY_LOGGING
175
176 retry :
177
178 /* send the key & fetch the associated data from the server */
179 status = configget(storePrivate->server,
180 myKeyRef,
181 (mach_msg_type_number_t)myKeyLen,
182 &xmlDataRef,
183 &xmlDataLen,
184 &newInstance,
185 (int *)&sc_status);
186
187 if (__SCDynamicStoreCheckRetryAndHandleError(store,
188 status,
189 &sc_status,
190 "SCDynamicStoreCopyValue configget()")) {
191 goto retry;
192 }
193
194 /* clean up */
195 CFRelease(utfKey);
196
197 if (sc_status != kSCStatusOK) {
198 if (xmlDataRef != NULL) {
199 (void) vm_deallocate(mach_task_self(), (vm_address_t)xmlDataRef, xmlDataLen);
200 }
201 _SCErrorSet(sc_status);
202 return NULL;
203 }
204
205 /* un-serialize the data */
206 if (!_SCUnserialize(&data, NULL, xmlDataRef, xmlDataLen)) {
207 _SCErrorSet(kSCStatusFailed);
208 return NULL;
209 }
210
211 return data;
212 }