2 * Copyright (c) 2002-2008 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 * October 31, 2000 Allan Nathanson <ajn@apple.com>
32 #include <sys/types.h>
33 #include <sys/param.h>
37 #include "dy_framework.h"
42 static void *image
= NULL
;
44 const char *framework
= "/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit";
46 const char *suffix
= getenv("DYLD_IMAGE_SUFFIX");
47 char path
[MAXPATHLEN
];
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
);
54 image
= dlopen(framework
, RTLD_LAZY
| RTLD_LOCAL
);
61 __private_extern__ CFMutableDictionaryRef
62 _IOBSDNameMatching(mach_port_t masterPort
, unsigned int options
, const char *bsdName
)
64 #undef IOBSDNameMatching
65 static typeof (IOBSDNameMatching
) *dyfunc
= NULL
;
67 void *image
= __loadIOKit();
68 if (image
) dyfunc
= dlsym(image
, "IOBSDNameMatching");
70 return dyfunc
? dyfunc(masterPort
, options
, bsdName
) : NULL
;
74 __private_extern__ io_object_t
75 _IOIteratorNext(io_iterator_t iterator
)
78 static typeof (IOIteratorNext
) *dyfunc
= NULL
;
80 void *image
= __loadIOKit();
81 if (image
) dyfunc
= dlsym(image
, "IOIteratorNext");
83 return dyfunc
? dyfunc(iterator
) : 0;
87 __private_extern__ kern_return_t
88 _IOMasterPort(mach_port_t bootstrapPort
, mach_port_t
*masterPort
)
91 static typeof (IOMasterPort
) *dyfunc
= NULL
;
93 void *image
= __loadIOKit();
94 if (image
) dyfunc
= dlsym(image
, "IOMasterPort");
96 return dyfunc
? dyfunc(bootstrapPort
, masterPort
) : KERN_FAILURE
;
100 __private_extern__ boolean_t
101 _IOObjectConformsTo(io_object_t object
, const io_name_t className
)
103 #undef IOObjectConformsTo
104 static typeof (IOObjectConformsTo
) *dyfunc
= NULL
;
106 void *image
= __loadIOKit();
107 if (image
) dyfunc
= dlsym(image
, "IOObjectConformsTo");
109 return dyfunc
? dyfunc(object
, className
) : FALSE
;
113 __private_extern__ boolean_t
114 _IOObjectGetClass(io_object_t object
, io_name_t className
)
116 #undef IOObjectGetClass
117 static typeof (IOObjectGetClass
) *dyfunc
= NULL
;
119 void *image
= __loadIOKit();
120 if (image
) dyfunc
= dlsym(image
, "IOObjectGetClass");
122 return dyfunc
? dyfunc(object
, className
) : FALSE
;
126 __private_extern__ kern_return_t
127 _IOObjectRelease(io_object_t object
)
129 #undef IOObjectRelease
130 static typeof (IOObjectRelease
) *dyfunc
= NULL
;
132 void *image
= __loadIOKit();
133 if (image
) dyfunc
= dlsym(image
, "IOObjectRelease");
135 return dyfunc
? dyfunc(object
) : KERN_FAILURE
;
139 __private_extern__ CFTypeRef
140 _IORegistryEntryCreateCFProperty(io_registry_entry_t entry
, CFStringRef key
, CFAllocatorRef allocator
, IOOptionBits options
)
142 #undef IORegistryEntryCreateCFProperty
143 static typeof (IORegistryEntryCreateCFProperty
) *dyfunc
= NULL
;
145 void *image
= __loadIOKit();
146 if (image
) dyfunc
= dlsym(image
, "IORegistryEntryCreateCFProperty");
148 return dyfunc
? dyfunc(entry
, key
, allocator
, options
) : NULL
;
152 __private_extern__ kern_return_t
153 _IORegistryEntryCreateCFProperties(io_registry_entry_t entry
, CFMutableDictionaryRef
*properties
, CFAllocatorRef allocator
, IOOptionBits options
)
155 #undef IORegistryEntryCreateCFProperties
156 static typeof (IORegistryEntryCreateCFProperties
) *dyfunc
= NULL
;
158 void *image
= __loadIOKit();
159 if (image
) dyfunc
= dlsym(image
, "IORegistryEntryCreateCFProperties");
161 return dyfunc
? dyfunc(entry
, properties
, allocator
, options
) : KERN_FAILURE
;
165 __private_extern__ kern_return_t
166 _IORegistryEntryCreateIterator(mach_port_t masterPort
, const io_name_t plane
, IOOptionBits options
, io_iterator_t
*iterator
)
168 #undef IORegistryEntryCreateIterator
169 static typeof (IORegistryEntryCreateIterator
) *dyfunc
= NULL
;
171 void *image
= __loadIOKit();
172 if (image
) dyfunc
= dlsym(image
, "IORegistryEntryCreateIterator");
174 return dyfunc
? dyfunc(masterPort
, plane
, options
, iterator
) : KERN_FAILURE
;
178 __private_extern__ kern_return_t
179 _IORegistryEntryGetName(io_registry_entry_t entry
, io_name_t name
)
181 #undef IORegistryEntryGetName
182 static typeof (IORegistryEntryGetName
) *dyfunc
= NULL
;
184 void *image
= __loadIOKit();
185 if (image
) dyfunc
= dlsym(image
, "IORegistryEntryGetName");
187 return dyfunc
? dyfunc(entry
, name
) : KERN_FAILURE
;
191 __private_extern__ kern_return_t
192 _IORegistryEntryGetParentEntry(io_registry_entry_t entry
, const io_name_t plane
, io_registry_entry_t
*parent
)
194 #undef IORegistryEntryGetParentEntry
195 static typeof (IORegistryEntryGetParentEntry
) *dyfunc
= NULL
;
197 void *image
= __loadIOKit();
198 if (image
) dyfunc
= dlsym(image
, "IORegistryEntryGetParentEntry");
200 return dyfunc
? dyfunc(entry
, plane
, parent
) : KERN_FAILURE
;
204 __private_extern__ kern_return_t
205 _IORegistryEntryGetPath(io_registry_entry_t entry
, const io_name_t plane
, io_string_t path
)
207 #undef IORegistryEntryGetPath
208 static typeof (IORegistryEntryGetPath
) *dyfunc
= NULL
;
210 void *image
= __loadIOKit();
211 if (image
) dyfunc
= dlsym(image
, "IORegistryEntryGetPath");
213 return dyfunc
? dyfunc(entry
, plane
, path
) : KERN_FAILURE
;
217 __private_extern__ CFTypeRef
218 _IORegistryEntrySearchCFProperty(io_registry_entry_t entry
, const io_name_t plane
, CFStringRef key
, CFAllocatorRef allocator
, IOOptionBits options
)
220 #undef IORegistryEntrySearchCFProperty
221 static typeof (IORegistryEntrySearchCFProperty
) *dyfunc
= NULL
;
223 void *image
= __loadIOKit();
224 if (image
) dyfunc
= dlsym(image
, "IORegistryEntrySearchCFProperty");
226 return dyfunc
? dyfunc(entry
, plane
, key
, allocator
, options
) : NULL
;
230 __private_extern__ kern_return_t
231 _IOServiceGetMatchingServices(mach_port_t masterPort
, CFDictionaryRef matching
, io_iterator_t
*existing
)
233 #undef IOServiceGetMatchingServices
234 static typeof (IOServiceGetMatchingServices
) *dyfunc
= NULL
;
236 void *image
= __loadIOKit();
237 if (image
) dyfunc
= dlsym(image
, "IOServiceGetMatchingServices");
239 return dyfunc
? dyfunc(masterPort
, matching
, existing
) : KERN_FAILURE
;
243 __private_extern__ CFMutableDictionaryRef
244 _IOServiceMatching(const char *name
)
246 #undef IOServiceMatching
247 static typeof (IOServiceMatching
) *dyfunc
= NULL
;
249 void *image
= __loadIOKit();
250 if (image
) dyfunc
= dlsym(image
, "IOServiceMatching");
252 return dyfunc
? dyfunc(name
) : NULL
;
255 #if !TARGET_OS_IPHONE
258 __loadSecurity(void) {
259 static void *image
= NULL
;
261 const char *framework
= "/System/Library/Frameworks/Security.framework/Versions/A/Security";
263 const char *suffix
= getenv("DYLD_IMAGE_SUFFIX");
264 char path
[MAXPATHLEN
];
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
);
271 image
= dlopen(framework
, RTLD_LAZY
| RTLD_LOCAL
);
274 return (void *)image
;
278 __private_extern__ OSStatus
279 _AuthorizationMakeExternalForm(AuthorizationRef authorization
, AuthorizationExternalForm
*extForm
)
281 #undef AuthorizationMakeExternalForm
282 static typeof (AuthorizationMakeExternalForm
) *dyfunc
= NULL
;
284 void *image
= __loadSecurity();
285 if (image
) dyfunc
= dlsym(image
, "AuthorizationMakeExternalForm");
287 return dyfunc
? dyfunc(authorization
, extForm
) : -1;
290 __private_extern__ OSStatus
291 _SecAccessCopySelectedACLList(SecAccessRef accessRef
, CSSM_ACL_AUTHORIZATION_TAG action
, CFArrayRef
*aclList
)
293 #undef SecAccessCopySelectedACLList
294 static typeof (SecAccessCopySelectedACLList
) *dyfunc
= NULL
;
296 void *image
= __loadSecurity();
297 if (image
) dyfunc
= dlsym(image
, "SecAccessCopySelectedACLList");
299 return dyfunc
? dyfunc(accessRef
, action
, aclList
) : -1;
302 __private_extern__ OSStatus
303 _SecAccessCreate(CFStringRef descriptor
, CFArrayRef trustedlist
, SecAccessRef
*accessRef
)
305 #undef SecAccessCreate
306 static typeof (SecAccessCreate
) *dyfunc
= NULL
;
308 void *image
= __loadSecurity();
309 if (image
) dyfunc
= dlsym(image
, "SecAccessCreate");
311 return dyfunc
? dyfunc(descriptor
, trustedlist
, accessRef
) : -1;
314 __private_extern__ OSStatus
315 _SecAccessCreateFromOwnerAndACL(const CSSM_ACL_OWNER_PROTOTYPE
*owner
, uint32 aclCount
, const CSSM_ACL_ENTRY_INFO
*acls
, SecAccessRef
*accessRef
)
317 #undef SecAccessCreateFromOwnerAndACL
318 static typeof (SecAccessCreateFromOwnerAndACL
) *dyfunc
= NULL
;
320 void *image
= __loadSecurity();
321 if (image
) dyfunc
= dlsym(image
, "SecAccessCreateFromOwnerAndACL");
323 return dyfunc
? dyfunc(owner
, aclCount
, acls
, accessRef
) : -1;
326 __private_extern__ OSStatus
327 _SecKeychainCopyDomainDefault(SecPreferencesDomain domain
, SecKeychainRef
*keychain
)
329 #undef SecKeychainCopyDomainDefault
330 static typeof (SecKeychainCopyDomainDefault
) *dyfunc
= NULL
;
332 void *image
= __loadSecurity();
333 if (image
) dyfunc
= dlsym(image
, "SecKeychainCopyDomainDefault");
335 return dyfunc
? dyfunc(domain
, keychain
) : -1;
338 __private_extern__ OSStatus
339 _SecKeychainGetPreferenceDomain(SecPreferencesDomain
*domain
)
341 #undef SecKeychainGetPreferenceDomain
342 static typeof (SecKeychainGetPreferenceDomain
) *dyfunc
= NULL
;
344 void *image
= __loadSecurity();
345 if (image
) dyfunc
= dlsym(image
, "SecKeychainGetPreferenceDomain");
347 return dyfunc
? dyfunc(domain
) : -1;
350 __private_extern__ OSStatus
351 _SecKeychainOpen(const char *pathName
, SecKeychainRef
*keychain
)
353 #undef SecKeychainOpen
354 static typeof (SecKeychainOpen
) *dyfunc
= NULL
;
356 void *image
= __loadSecurity();
357 if (image
) dyfunc
= dlsym(image
, "SecKeychainOpen");
359 return dyfunc
? dyfunc(pathName
, keychain
) : -1;
362 __private_extern__ OSStatus
363 _SecKeychainSetDomainDefault(SecPreferencesDomain domain
, SecKeychainRef keychain
)
365 #undef SecKeychainSetDomainDefault
366 static typeof (SecKeychainSetDomainDefault
) *dyfunc
= NULL
;
368 void *image
= __loadSecurity();
369 if (image
) dyfunc
= dlsym(image
, "SecKeychainSetDomainDefault");
371 return dyfunc
? dyfunc(domain
, keychain
) : -1;
374 __private_extern__ OSStatus
375 _SecKeychainSetPreferenceDomain(SecPreferencesDomain domain
)
377 #undef SecKeychainSetPreferenceDomain
378 static typeof (SecKeychainSetPreferenceDomain
) *dyfunc
= NULL
;
380 void *image
= __loadSecurity();
381 if (image
) dyfunc
= dlsym(image
, "SecKeychainSetPreferenceDomain");
383 return dyfunc
? dyfunc(domain
) : -1;
386 __private_extern__ OSStatus
387 _SecKeychainItemCopyContent(SecKeychainItemRef itemRef
, SecItemClass
*itemClass
, SecKeychainAttributeList
*attrList
, UInt32
*length
, void **outData
)
389 #undef SecKeychainItemCopyContent
390 static typeof (SecKeychainItemCopyContent
) *dyfunc
= NULL
;
392 void *image
= __loadSecurity();
393 if (image
) dyfunc
= dlsym(image
, "SecKeychainItemCopyContent");
395 return dyfunc
? dyfunc(itemRef
, itemClass
, attrList
, length
, outData
) : -1;
398 __private_extern__ OSStatus
399 _SecKeychainItemCreateFromContent(SecItemClass itemClass
, SecKeychainAttributeList
*attrList
, UInt32 length
, const void *data
, SecKeychainRef keychainRef
, SecAccessRef initialAccess
, SecKeychainItemRef
*itemRef
)
401 #undef SecKeychainItemCreateFromContent
402 static typeof (SecKeychainItemCreateFromContent
) *dyfunc
= NULL
;
404 void *image
= __loadSecurity();
405 if (image
) dyfunc
= dlsym(image
, "SecKeychainItemCreateFromContent");
407 return dyfunc
? dyfunc(itemClass
, attrList
, length
, data
, keychainRef
, initialAccess
, itemRef
) : -1;
410 __private_extern__ OSStatus
411 _SecKeychainItemDelete(SecKeychainItemRef itemRef
)
413 #undef SecKeychainItemDelete
414 static typeof (SecKeychainItemDelete
) *dyfunc
= NULL
;
416 void *image
= __loadSecurity();
417 if (image
) dyfunc
= dlsym(image
, "SecKeychainItemDelete");
419 return dyfunc
? dyfunc(itemRef
) : -1;
422 __private_extern__ OSStatus
423 _SecKeychainItemFreeContent(SecKeychainAttributeList
*attrList
, void *data
)
425 #undef SecKeychainItemFreeContent
426 static typeof (SecKeychainItemFreeContent
) *dyfunc
= NULL
;
428 void *image
= __loadSecurity();
429 if (image
) dyfunc
= dlsym(image
, "SecKeychainItemFreeContent");
431 return dyfunc
? dyfunc(attrList
, data
) : -1;
434 __private_extern__ OSStatus
435 _SecKeychainItemModifyContent(SecKeychainItemRef itemRef
, const SecKeychainAttributeList
*attrList
, UInt32 length
, const void *data
)
437 #undef SecKeychainItemModifyContent
438 static typeof (SecKeychainItemModifyContent
) *dyfunc
= NULL
;
440 void *image
= __loadSecurity();
441 if (image
) dyfunc
= dlsym(image
, "SecKeychainItemModifyContent");
443 return dyfunc
? dyfunc(itemRef
, attrList
, length
, data
) : -1;
446 __private_extern__ OSStatus
447 _SecKeychainSearchCopyNext(SecKeychainSearchRef searchRef
, SecKeychainItemRef
*itemRef
)
449 #undef SecKeychainSearchCopyNext
450 static typeof (SecKeychainSearchCopyNext
) *dyfunc
= NULL
;
452 void *image
= __loadSecurity();
453 if (image
) dyfunc
= dlsym(image
, "SecKeychainSearchCopyNext");
455 return dyfunc
? dyfunc(searchRef
, itemRef
) : -1;
458 __private_extern__ OSStatus
459 _SecKeychainSearchCreateFromAttributes(CFTypeRef keychainOrArray
, SecItemClass itemClass
, const SecKeychainAttributeList
*attrList
, SecKeychainSearchRef
*searchRef
)
461 #undef SecKeychainSearchCreateFromAttributes
462 static typeof (SecKeychainSearchCreateFromAttributes
) *dyfunc
= NULL
;
464 void *image
= __loadSecurity();
465 if (image
) dyfunc
= dlsym(image
, "SecKeychainSearchCreateFromAttributes");
467 return dyfunc
? dyfunc(keychainOrArray
, itemClass
, attrList
, searchRef
) : -1;
470 __private_extern__ OSStatus
471 _SecTrustedApplicationCreateFromPath(const char *path
, SecTrustedApplicationRef
*app
)
473 #undef SecTrustedApplicationCreateFromPath
474 static typeof (SecTrustedApplicationCreateFromPath
) *dyfunc
= NULL
;
476 void *image
= __loadSecurity();
477 if (image
) dyfunc
= dlsym(image
, "SecTrustedApplicationCreateFromPath");
479 return dyfunc
? dyfunc(path
, app
) : -1;
482 #endif // !TARGET_OS_IPHONE