]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/dy_framework.c
configd-212.2.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / dy_framework.c
1 /*
2 * Copyright (c) 2002-2006 Apple Computer, 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 static void *
256 __loadSecurity(void) {
257 static void *image = NULL;
258 if (NULL == image) {
259 const char *framework = "/System/Library/Frameworks/Security.framework/Versions/A/Security";
260 struct stat statbuf;
261 const char *suffix = getenv("DYLD_IMAGE_SUFFIX");
262 char path[MAXPATHLEN];
263
264 strlcpy(path, framework, sizeof(path));
265 if (suffix) strlcat(path, suffix, sizeof(path));
266 if (0 <= stat(path, &statbuf)) {
267 image = dlopen(path, RTLD_LAZY | RTLD_LOCAL);
268 } else {
269 image = dlopen(framework, RTLD_LAZY | RTLD_LOCAL);
270 }
271 }
272 return (void *)image;
273 }
274
275
276 __private_extern__ OSStatus
277 _AuthorizationMakeExternalForm(AuthorizationRef authorization, AuthorizationExternalForm *extForm)
278 {
279 #undef AuthorizationMakeExternalForm
280 static typeof (AuthorizationMakeExternalForm) *dyfunc = NULL;
281 if (!dyfunc) {
282 void *image = __loadSecurity();
283 if (image) dyfunc = dlsym(image, "AuthorizationMakeExternalForm");
284 }
285 return dyfunc ? dyfunc(authorization, extForm) : -1;
286 }
287
288 __private_extern__ OSStatus
289 _SecAccessCopySelectedACLList(SecAccessRef accessRef, CSSM_ACL_AUTHORIZATION_TAG action, CFArrayRef *aclList)
290 {
291 #undef SecAccessCopySelectedACLList
292 static typeof (SecAccessCopySelectedACLList) *dyfunc = NULL;
293 if (!dyfunc) {
294 void *image = __loadSecurity();
295 if (image) dyfunc = dlsym(image, "SecAccessCopySelectedACLList");
296 }
297 return dyfunc ? dyfunc(accessRef, action, aclList) : -1;
298 }
299
300 __private_extern__ OSStatus
301 _SecAccessCreate(CFStringRef descriptor, CFArrayRef trustedlist, SecAccessRef *accessRef)
302 {
303 #undef SecAccessCreate
304 static typeof (SecAccessCreate) *dyfunc = NULL;
305 if (!dyfunc) {
306 void *image = __loadSecurity();
307 if (image) dyfunc = dlsym(image, "SecAccessCreate");
308 }
309 return dyfunc ? dyfunc(descriptor, trustedlist, accessRef) : -1;
310 }
311
312 __private_extern__ OSStatus
313 _SecAccessCreateFromOwnerAndACL(const CSSM_ACL_OWNER_PROTOTYPE *owner, uint32 aclCount, const CSSM_ACL_ENTRY_INFO *acls, SecAccessRef *accessRef)
314 {
315 #undef SecAccessCreateFromOwnerAndACL
316 static typeof (SecAccessCreateFromOwnerAndACL) *dyfunc = NULL;
317 if (!dyfunc) {
318 void *image = __loadSecurity();
319 if (image) dyfunc = dlsym(image, "SecAccessCreateFromOwnerAndACL");
320 }
321 return dyfunc ? dyfunc(owner, aclCount, acls, accessRef) : -1;
322 }
323
324 __private_extern__ OSStatus
325 _SecKeychainCopyDomainDefault(SecPreferencesDomain domain, SecKeychainRef *keychain)
326 {
327 #undef SecKeychainCopyDomainDefault
328 static typeof (SecKeychainCopyDomainDefault) *dyfunc = NULL;
329 if (!dyfunc) {
330 void *image = __loadSecurity();
331 if (image) dyfunc = dlsym(image, "SecKeychainCopyDomainDefault");
332 }
333 return dyfunc ? dyfunc(domain, keychain) : -1;
334 }
335
336 __private_extern__ OSStatus
337 _SecKeychainGetPreferenceDomain(SecPreferencesDomain *domain)
338 {
339 #undef SecKeychainGetPreferenceDomain
340 static typeof (SecKeychainGetPreferenceDomain) *dyfunc = NULL;
341 if (!dyfunc) {
342 void *image = __loadSecurity();
343 if (image) dyfunc = dlsym(image, "SecKeychainGetPreferenceDomain");
344 }
345 return dyfunc ? dyfunc(domain) : -1;
346 }
347
348 __private_extern__ OSStatus
349 _SecKeychainOpen(const char *pathName, SecKeychainRef *keychain)
350 {
351 #undef SecKeychainOpen
352 static typeof (SecKeychainOpen) *dyfunc = NULL;
353 if (!dyfunc) {
354 void *image = __loadSecurity();
355 if (image) dyfunc = dlsym(image, "SecKeychainOpen");
356 }
357 return dyfunc ? dyfunc(pathName, keychain) : -1;
358 }
359
360 __private_extern__ OSStatus
361 _SecKeychainSetDomainDefault(SecPreferencesDomain domain, SecKeychainRef keychain)
362 {
363 #undef SecKeychainSetDomainDefault
364 static typeof (SecKeychainSetDomainDefault) *dyfunc = NULL;
365 if (!dyfunc) {
366 void *image = __loadSecurity();
367 if (image) dyfunc = dlsym(image, "SecKeychainSetDomainDefault");
368 }
369 return dyfunc ? dyfunc(domain, keychain) : -1;
370 }
371
372 __private_extern__ OSStatus
373 _SecKeychainSetPreferenceDomain(SecPreferencesDomain domain)
374 {
375 #undef SecKeychainSetPreferenceDomain
376 static typeof (SecKeychainSetPreferenceDomain) *dyfunc = NULL;
377 if (!dyfunc) {
378 void *image = __loadSecurity();
379 if (image) dyfunc = dlsym(image, "SecKeychainSetPreferenceDomain");
380 }
381 return dyfunc ? dyfunc(domain) : -1;
382 }
383
384 __private_extern__ OSStatus
385 _SecKeychainItemCopyContent(SecKeychainItemRef itemRef, SecItemClass *itemClass, SecKeychainAttributeList *attrList, UInt32 *length, void **outData)
386 {
387 #undef SecKeychainItemCopyContent
388 static typeof (SecKeychainItemCopyContent) *dyfunc = NULL;
389 if (!dyfunc) {
390 void *image = __loadSecurity();
391 if (image) dyfunc = dlsym(image, "SecKeychainItemCopyContent");
392 }
393 return dyfunc ? dyfunc(itemRef, itemClass, attrList, length, outData) : -1;
394 }
395
396 __private_extern__ OSStatus
397 _SecKeychainItemCreateFromContent(SecItemClass itemClass, SecKeychainAttributeList *attrList, UInt32 length, const void *data, SecKeychainRef keychainRef, SecAccessRef initialAccess, SecKeychainItemRef *itemRef)
398 {
399 #undef SecKeychainItemCreateFromContent
400 static typeof (SecKeychainItemCreateFromContent) *dyfunc = NULL;
401 if (!dyfunc) {
402 void *image = __loadSecurity();
403 if (image) dyfunc = dlsym(image, "SecKeychainItemCreateFromContent");
404 }
405 return dyfunc ? dyfunc(itemClass, attrList, length, data, keychainRef, initialAccess, itemRef) : -1;
406 }
407
408 __private_extern__ OSStatus
409 _SecKeychainItemDelete(SecKeychainItemRef itemRef)
410 {
411 #undef SecKeychainItemDelete
412 static typeof (SecKeychainItemDelete) *dyfunc = NULL;
413 if (!dyfunc) {
414 void *image = __loadSecurity();
415 if (image) dyfunc = dlsym(image, "SecKeychainItemDelete");
416 }
417 return dyfunc ? dyfunc(itemRef) : -1;
418 }
419
420 __private_extern__ OSStatus
421 _SecKeychainItemFreeContent(SecKeychainAttributeList *attrList, void *data)
422 {
423 #undef SecKeychainItemFreeContent
424 static typeof (SecKeychainItemFreeContent) *dyfunc = NULL;
425 if (!dyfunc) {
426 void *image = __loadSecurity();
427 if (image) dyfunc = dlsym(image, "SecKeychainItemFreeContent");
428 }
429 return dyfunc ? dyfunc(attrList, data) : -1;
430 }
431
432 __private_extern__ OSStatus
433 _SecKeychainItemModifyContent(SecKeychainItemRef itemRef, const SecKeychainAttributeList *attrList, UInt32 length, const void *data)
434 {
435 #undef SecKeychainItemModifyContent
436 static typeof (SecKeychainItemModifyContent) *dyfunc = NULL;
437 if (!dyfunc) {
438 void *image = __loadSecurity();
439 if (image) dyfunc = dlsym(image, "SecKeychainItemModifyContent");
440 }
441 return dyfunc ? dyfunc(itemRef, attrList, length, data) : -1;
442 }
443
444 __private_extern__ OSStatus
445 _SecKeychainSearchCopyNext(SecKeychainSearchRef searchRef, SecKeychainItemRef *itemRef)
446 {
447 #undef SecKeychainSearchCopyNext
448 static typeof (SecKeychainSearchCopyNext) *dyfunc = NULL;
449 if (!dyfunc) {
450 void *image = __loadSecurity();
451 if (image) dyfunc = dlsym(image, "SecKeychainSearchCopyNext");
452 }
453 return dyfunc ? dyfunc(searchRef, itemRef) : -1;
454 }
455
456 __private_extern__ OSStatus
457 _SecKeychainSearchCreateFromAttributes(CFTypeRef keychainOrArray, SecItemClass itemClass, const SecKeychainAttributeList *attrList, SecKeychainSearchRef *searchRef)
458 {
459 #undef SecKeychainSearchCreateFromAttributes
460 static typeof (SecKeychainSearchCreateFromAttributes) *dyfunc = NULL;
461 if (!dyfunc) {
462 void *image = __loadSecurity();
463 if (image) dyfunc = dlsym(image, "SecKeychainSearchCreateFromAttributes");
464 }
465 return dyfunc ? dyfunc(keychainOrArray, itemClass, attrList, searchRef) : -1;
466 }
467
468 __private_extern__ OSStatus
469 _SecTrustedApplicationCreateFromPath(const char *path, SecTrustedApplicationRef *app)
470 {
471 #undef SecTrustedApplicationCreateFromPath
472 static typeof (SecTrustedApplicationCreateFromPath) *dyfunc = NULL;
473 if (!dyfunc) {
474 void *image = __loadSecurity();
475 if (image) dyfunc = dlsym(image, "SecTrustedApplicationCreateFromPath");
476 }
477 return dyfunc ? dyfunc(path, app) : -1;
478 }
479