]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/dy_framework.c
configd-289.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / dy_framework.c
1 /*
2 * Copyright (c) 2002-2008 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 * October 31, 2000 Allan Nathanson <ajn@apple.com>
28 * - initial revision
29 */
30
31
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/stat.h>
35 #include <dlfcn.h>
36
37 #include "dy_framework.h"
38
39
40 static void *
41 __loadIOKit(void) {
42 static void *image = NULL;
43 if (NULL == image) {
44 const char *framework = "/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit";
45 struct stat statbuf;
46 const char *suffix = getenv("DYLD_IMAGE_SUFFIX");
47 char path[MAXPATHLEN];
48
49 strlcpy(path, framework, sizeof(path));
50 if (suffix) strlcat(path, suffix, sizeof(path));
51 if (0 <= stat(path, &statbuf)) {
52 image = dlopen(path, RTLD_LAZY | RTLD_LOCAL);
53 } else {
54 image = dlopen(framework, RTLD_LAZY | RTLD_LOCAL);
55 }
56 }
57 return (void *)image;
58 }
59
60
61 __private_extern__ CFMutableDictionaryRef
62 _IOBSDNameMatching(mach_port_t masterPort, unsigned int options, const char *bsdName)
63 {
64 #undef IOBSDNameMatching
65 static typeof (IOBSDNameMatching) *dyfunc = NULL;
66 if (!dyfunc) {
67 void *image = __loadIOKit();
68 if (image) dyfunc = dlsym(image, "IOBSDNameMatching");
69 }
70 return dyfunc ? dyfunc(masterPort, options, bsdName) : NULL;
71 }
72
73
74 __private_extern__ io_object_t
75 _IOIteratorNext(io_iterator_t iterator)
76 {
77 #undef IOIteratorNext
78 static typeof (IOIteratorNext) *dyfunc = NULL;
79 if (!dyfunc) {
80 void *image = __loadIOKit();
81 if (image) dyfunc = dlsym(image, "IOIteratorNext");
82 }
83 return dyfunc ? dyfunc(iterator) : 0;
84 }
85
86
87 __private_extern__ kern_return_t
88 _IOMasterPort(mach_port_t bootstrapPort, mach_port_t *masterPort)
89 {
90 #undef IOMasterPort
91 static typeof (IOMasterPort) *dyfunc = NULL;
92 if (!dyfunc) {
93 void *image = __loadIOKit();
94 if (image) dyfunc = dlsym(image, "IOMasterPort");
95 }
96 return dyfunc ? dyfunc(bootstrapPort, masterPort) : KERN_FAILURE;
97 }
98
99
100 __private_extern__ boolean_t
101 _IOObjectConformsTo(io_object_t object, const io_name_t className)
102 {
103 #undef IOObjectConformsTo
104 static typeof (IOObjectConformsTo) *dyfunc = NULL;
105 if (!dyfunc) {
106 void *image = __loadIOKit();
107 if (image) dyfunc = dlsym(image, "IOObjectConformsTo");
108 }
109 return dyfunc ? dyfunc(object, className) : FALSE;
110 }
111
112
113 __private_extern__ boolean_t
114 _IOObjectGetClass(io_object_t object, io_name_t className)
115 {
116 #undef IOObjectGetClass
117 static typeof (IOObjectGetClass) *dyfunc = NULL;
118 if (!dyfunc) {
119 void *image = __loadIOKit();
120 if (image) dyfunc = dlsym(image, "IOObjectGetClass");
121 }
122 return dyfunc ? dyfunc(object, className) : FALSE;
123 }
124
125
126 __private_extern__ kern_return_t
127 _IOObjectRelease(io_object_t object)
128 {
129 #undef IOObjectRelease
130 static typeof (IOObjectRelease) *dyfunc = NULL;
131 if (!dyfunc) {
132 void *image = __loadIOKit();
133 if (image) dyfunc = dlsym(image, "IOObjectRelease");
134 }
135 return dyfunc ? dyfunc(object) : KERN_FAILURE;
136 }
137
138
139 __private_extern__ CFTypeRef
140 _IORegistryEntryCreateCFProperty(io_registry_entry_t entry, CFStringRef key, CFAllocatorRef allocator, IOOptionBits options)
141 {
142 #undef IORegistryEntryCreateCFProperty
143 static typeof (IORegistryEntryCreateCFProperty) *dyfunc = NULL;
144 if (!dyfunc) {
145 void *image = __loadIOKit();
146 if (image) dyfunc = dlsym(image, "IORegistryEntryCreateCFProperty");
147 }
148 return dyfunc ? dyfunc(entry, key, allocator, options) : NULL;
149 }
150
151
152 __private_extern__ kern_return_t
153 _IORegistryEntryCreateCFProperties(io_registry_entry_t entry, CFMutableDictionaryRef *properties, CFAllocatorRef allocator, IOOptionBits options)
154 {
155 #undef IORegistryEntryCreateCFProperties
156 static typeof (IORegistryEntryCreateCFProperties) *dyfunc = NULL;
157 if (!dyfunc) {
158 void *image = __loadIOKit();
159 if (image) dyfunc = dlsym(image, "IORegistryEntryCreateCFProperties");
160 }
161 return dyfunc ? dyfunc(entry, properties, allocator, options) : KERN_FAILURE;
162 }
163
164
165 __private_extern__ kern_return_t
166 _IORegistryEntryCreateIterator(mach_port_t masterPort, const io_name_t plane, IOOptionBits options, io_iterator_t *iterator)
167 {
168 #undef IORegistryEntryCreateIterator
169 static typeof (IORegistryEntryCreateIterator) *dyfunc = NULL;
170 if (!dyfunc) {
171 void *image = __loadIOKit();
172 if (image) dyfunc = dlsym(image, "IORegistryEntryCreateIterator");
173 }
174 return dyfunc ? dyfunc(masterPort, plane, options, iterator) : KERN_FAILURE;
175 }
176
177
178 __private_extern__ kern_return_t
179 _IORegistryEntryGetName(io_registry_entry_t entry, io_name_t name)
180 {
181 #undef IORegistryEntryGetName
182 static typeof (IORegistryEntryGetName) *dyfunc = NULL;
183 if (!dyfunc) {
184 void *image = __loadIOKit();
185 if (image) dyfunc = dlsym(image, "IORegistryEntryGetName");
186 }
187 return dyfunc ? dyfunc(entry, name) : KERN_FAILURE;
188 }
189
190
191 __private_extern__ kern_return_t
192 _IORegistryEntryGetParentEntry(io_registry_entry_t entry, const io_name_t plane, io_registry_entry_t *parent)
193 {
194 #undef IORegistryEntryGetParentEntry
195 static typeof (IORegistryEntryGetParentEntry) *dyfunc = NULL;
196 if (!dyfunc) {
197 void *image = __loadIOKit();
198 if (image) dyfunc = dlsym(image, "IORegistryEntryGetParentEntry");
199 }
200 return dyfunc ? dyfunc(entry, plane, parent) : KERN_FAILURE;
201 }
202
203
204 __private_extern__ kern_return_t
205 _IORegistryEntryGetPath(io_registry_entry_t entry, const io_name_t plane, io_string_t path)
206 {
207 #undef IORegistryEntryGetPath
208 static typeof (IORegistryEntryGetPath) *dyfunc = NULL;
209 if (!dyfunc) {
210 void *image = __loadIOKit();
211 if (image) dyfunc = dlsym(image, "IORegistryEntryGetPath");
212 }
213 return dyfunc ? dyfunc(entry, plane, path) : KERN_FAILURE;
214 }
215
216
217 __private_extern__ CFTypeRef
218 _IORegistryEntrySearchCFProperty(io_registry_entry_t entry, const io_name_t plane, CFStringRef key, CFAllocatorRef allocator, IOOptionBits options)
219 {
220 #undef IORegistryEntrySearchCFProperty
221 static typeof (IORegistryEntrySearchCFProperty) *dyfunc = NULL;
222 if (!dyfunc) {
223 void *image = __loadIOKit();
224 if (image) dyfunc = dlsym(image, "IORegistryEntrySearchCFProperty");
225 }
226 return dyfunc ? dyfunc(entry, plane, key, allocator, options) : NULL;
227 }
228
229
230 __private_extern__ kern_return_t
231 _IOServiceGetMatchingServices(mach_port_t masterPort, CFDictionaryRef matching, io_iterator_t *existing)
232 {
233 #undef IOServiceGetMatchingServices
234 static typeof (IOServiceGetMatchingServices) *dyfunc = NULL;
235 if (!dyfunc) {
236 void *image = __loadIOKit();
237 if (image) dyfunc = dlsym(image, "IOServiceGetMatchingServices");
238 }
239 return dyfunc ? dyfunc(masterPort, matching, existing) : KERN_FAILURE;
240 }
241
242
243 __private_extern__ CFMutableDictionaryRef
244 _IOServiceMatching(const char *name)
245 {
246 #undef IOServiceMatching
247 static typeof (IOServiceMatching) *dyfunc = NULL;
248 if (!dyfunc) {
249 void *image = __loadIOKit();
250 if (image) dyfunc = dlsym(image, "IOServiceMatching");
251 }
252 return dyfunc ? dyfunc(name) : NULL;
253 }
254
255 #if !TARGET_OS_IPHONE
256
257 static void *
258 __loadSecurity(void) {
259 static void *image = NULL;
260 if (NULL == image) {
261 const char *framework = "/System/Library/Frameworks/Security.framework/Versions/A/Security";
262 struct stat statbuf;
263 const char *suffix = getenv("DYLD_IMAGE_SUFFIX");
264 char path[MAXPATHLEN];
265
266 strlcpy(path, framework, sizeof(path));
267 if (suffix) strlcat(path, suffix, sizeof(path));
268 if (0 <= stat(path, &statbuf)) {
269 image = dlopen(path, RTLD_LAZY | RTLD_LOCAL);
270 } else {
271 image = dlopen(framework, RTLD_LAZY | RTLD_LOCAL);
272 }
273 }
274 return (void *)image;
275 }
276
277
278 __private_extern__ OSStatus
279 _AuthorizationMakeExternalForm(AuthorizationRef authorization, AuthorizationExternalForm *extForm)
280 {
281 #undef AuthorizationMakeExternalForm
282 static typeof (AuthorizationMakeExternalForm) *dyfunc = NULL;
283 if (!dyfunc) {
284 void *image = __loadSecurity();
285 if (image) dyfunc = dlsym(image, "AuthorizationMakeExternalForm");
286 }
287 return dyfunc ? dyfunc(authorization, extForm) : -1;
288 }
289
290 __private_extern__ OSStatus
291 _SecAccessCopySelectedACLList(SecAccessRef accessRef, CSSM_ACL_AUTHORIZATION_TAG action, CFArrayRef *aclList)
292 {
293 #undef SecAccessCopySelectedACLList
294 static typeof (SecAccessCopySelectedACLList) *dyfunc = NULL;
295 if (!dyfunc) {
296 void *image = __loadSecurity();
297 if (image) dyfunc = dlsym(image, "SecAccessCopySelectedACLList");
298 }
299 return dyfunc ? dyfunc(accessRef, action, aclList) : -1;
300 }
301
302 __private_extern__ OSStatus
303 _SecAccessCreate(CFStringRef descriptor, CFArrayRef trustedlist, SecAccessRef *accessRef)
304 {
305 #undef SecAccessCreate
306 static typeof (SecAccessCreate) *dyfunc = NULL;
307 if (!dyfunc) {
308 void *image = __loadSecurity();
309 if (image) dyfunc = dlsym(image, "SecAccessCreate");
310 }
311 return dyfunc ? dyfunc(descriptor, trustedlist, accessRef) : -1;
312 }
313
314 __private_extern__ OSStatus
315 _SecAccessCreateFromOwnerAndACL(const CSSM_ACL_OWNER_PROTOTYPE *owner, uint32 aclCount, const CSSM_ACL_ENTRY_INFO *acls, SecAccessRef *accessRef)
316 {
317 #undef SecAccessCreateFromOwnerAndACL
318 static typeof (SecAccessCreateFromOwnerAndACL) *dyfunc = NULL;
319 if (!dyfunc) {
320 void *image = __loadSecurity();
321 if (image) dyfunc = dlsym(image, "SecAccessCreateFromOwnerAndACL");
322 }
323 return dyfunc ? dyfunc(owner, aclCount, acls, accessRef) : -1;
324 }
325
326 __private_extern__ OSStatus
327 _SecKeychainCopyDomainDefault(SecPreferencesDomain domain, SecKeychainRef *keychain)
328 {
329 #undef SecKeychainCopyDomainDefault
330 static typeof (SecKeychainCopyDomainDefault) *dyfunc = NULL;
331 if (!dyfunc) {
332 void *image = __loadSecurity();
333 if (image) dyfunc = dlsym(image, "SecKeychainCopyDomainDefault");
334 }
335 return dyfunc ? dyfunc(domain, keychain) : -1;
336 }
337
338 __private_extern__ OSStatus
339 _SecKeychainGetPreferenceDomain(SecPreferencesDomain *domain)
340 {
341 #undef SecKeychainGetPreferenceDomain
342 static typeof (SecKeychainGetPreferenceDomain) *dyfunc = NULL;
343 if (!dyfunc) {
344 void *image = __loadSecurity();
345 if (image) dyfunc = dlsym(image, "SecKeychainGetPreferenceDomain");
346 }
347 return dyfunc ? dyfunc(domain) : -1;
348 }
349
350 __private_extern__ OSStatus
351 _SecKeychainOpen(const char *pathName, SecKeychainRef *keychain)
352 {
353 #undef SecKeychainOpen
354 static typeof (SecKeychainOpen) *dyfunc = NULL;
355 if (!dyfunc) {
356 void *image = __loadSecurity();
357 if (image) dyfunc = dlsym(image, "SecKeychainOpen");
358 }
359 return dyfunc ? dyfunc(pathName, keychain) : -1;
360 }
361
362 __private_extern__ OSStatus
363 _SecKeychainSetDomainDefault(SecPreferencesDomain domain, SecKeychainRef keychain)
364 {
365 #undef SecKeychainSetDomainDefault
366 static typeof (SecKeychainSetDomainDefault) *dyfunc = NULL;
367 if (!dyfunc) {
368 void *image = __loadSecurity();
369 if (image) dyfunc = dlsym(image, "SecKeychainSetDomainDefault");
370 }
371 return dyfunc ? dyfunc(domain, keychain) : -1;
372 }
373
374 __private_extern__ OSStatus
375 _SecKeychainSetPreferenceDomain(SecPreferencesDomain domain)
376 {
377 #undef SecKeychainSetPreferenceDomain
378 static typeof (SecKeychainSetPreferenceDomain) *dyfunc = NULL;
379 if (!dyfunc) {
380 void *image = __loadSecurity();
381 if (image) dyfunc = dlsym(image, "SecKeychainSetPreferenceDomain");
382 }
383 return dyfunc ? dyfunc(domain) : -1;
384 }
385
386 __private_extern__ OSStatus
387 _SecKeychainItemCopyContent(SecKeychainItemRef itemRef, SecItemClass *itemClass, SecKeychainAttributeList *attrList, UInt32 *length, void **outData)
388 {
389 #undef SecKeychainItemCopyContent
390 static typeof (SecKeychainItemCopyContent) *dyfunc = NULL;
391 if (!dyfunc) {
392 void *image = __loadSecurity();
393 if (image) dyfunc = dlsym(image, "SecKeychainItemCopyContent");
394 }
395 return dyfunc ? dyfunc(itemRef, itemClass, attrList, length, outData) : -1;
396 }
397
398 __private_extern__ OSStatus
399 _SecKeychainItemCreateFromContent(SecItemClass itemClass, SecKeychainAttributeList *attrList, UInt32 length, const void *data, SecKeychainRef keychainRef, SecAccessRef initialAccess, SecKeychainItemRef *itemRef)
400 {
401 #undef SecKeychainItemCreateFromContent
402 static typeof (SecKeychainItemCreateFromContent) *dyfunc = NULL;
403 if (!dyfunc) {
404 void *image = __loadSecurity();
405 if (image) dyfunc = dlsym(image, "SecKeychainItemCreateFromContent");
406 }
407 return dyfunc ? dyfunc(itemClass, attrList, length, data, keychainRef, initialAccess, itemRef) : -1;
408 }
409
410 __private_extern__ OSStatus
411 _SecKeychainItemDelete(SecKeychainItemRef itemRef)
412 {
413 #undef SecKeychainItemDelete
414 static typeof (SecKeychainItemDelete) *dyfunc = NULL;
415 if (!dyfunc) {
416 void *image = __loadSecurity();
417 if (image) dyfunc = dlsym(image, "SecKeychainItemDelete");
418 }
419 return dyfunc ? dyfunc(itemRef) : -1;
420 }
421
422 __private_extern__ OSStatus
423 _SecKeychainItemFreeContent(SecKeychainAttributeList *attrList, void *data)
424 {
425 #undef SecKeychainItemFreeContent
426 static typeof (SecKeychainItemFreeContent) *dyfunc = NULL;
427 if (!dyfunc) {
428 void *image = __loadSecurity();
429 if (image) dyfunc = dlsym(image, "SecKeychainItemFreeContent");
430 }
431 return dyfunc ? dyfunc(attrList, data) : -1;
432 }
433
434 __private_extern__ OSStatus
435 _SecKeychainItemModifyContent(SecKeychainItemRef itemRef, const SecKeychainAttributeList *attrList, UInt32 length, const void *data)
436 {
437 #undef SecKeychainItemModifyContent
438 static typeof (SecKeychainItemModifyContent) *dyfunc = NULL;
439 if (!dyfunc) {
440 void *image = __loadSecurity();
441 if (image) dyfunc = dlsym(image, "SecKeychainItemModifyContent");
442 }
443 return dyfunc ? dyfunc(itemRef, attrList, length, data) : -1;
444 }
445
446 __private_extern__ OSStatus
447 _SecKeychainSearchCopyNext(SecKeychainSearchRef searchRef, SecKeychainItemRef *itemRef)
448 {
449 #undef SecKeychainSearchCopyNext
450 static typeof (SecKeychainSearchCopyNext) *dyfunc = NULL;
451 if (!dyfunc) {
452 void *image = __loadSecurity();
453 if (image) dyfunc = dlsym(image, "SecKeychainSearchCopyNext");
454 }
455 return dyfunc ? dyfunc(searchRef, itemRef) : -1;
456 }
457
458 __private_extern__ OSStatus
459 _SecKeychainSearchCreateFromAttributes(CFTypeRef keychainOrArray, SecItemClass itemClass, const SecKeychainAttributeList *attrList, SecKeychainSearchRef *searchRef)
460 {
461 #undef SecKeychainSearchCreateFromAttributes
462 static typeof (SecKeychainSearchCreateFromAttributes) *dyfunc = NULL;
463 if (!dyfunc) {
464 void *image = __loadSecurity();
465 if (image) dyfunc = dlsym(image, "SecKeychainSearchCreateFromAttributes");
466 }
467 return dyfunc ? dyfunc(keychainOrArray, itemClass, attrList, searchRef) : -1;
468 }
469
470 __private_extern__ OSStatus
471 _SecTrustedApplicationCreateFromPath(const char *path, SecTrustedApplicationRef *app)
472 {
473 #undef SecTrustedApplicationCreateFromPath
474 static typeof (SecTrustedApplicationCreateFromPath) *dyfunc = NULL;
475 if (!dyfunc) {
476 void *image = __loadSecurity();
477 if (image) dyfunc = dlsym(image, "SecTrustedApplicationCreateFromPath");
478 }
479 return dyfunc ? dyfunc(path, app) : -1;
480 }
481
482 #endif // !TARGET_OS_IPHONE