2 * Copyright (c) 2002-2006 Apple Computer, 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
;
256 __loadSecurity(void) {
257 static void *image
= NULL
;
259 const char *framework
= "/System/Library/Frameworks/Security.framework/Versions/A/Security";
261 const char *suffix
= getenv("DYLD_IMAGE_SUFFIX");
262 char path
[MAXPATHLEN
];
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
);
269 image
= dlopen(framework
, RTLD_LAZY
| RTLD_LOCAL
);
272 return (void *)image
;
276 __private_extern__ OSStatus
277 _AuthorizationMakeExternalForm(AuthorizationRef authorization
, AuthorizationExternalForm
*extForm
)
279 #undef AuthorizationMakeExternalForm
280 static typeof (AuthorizationMakeExternalForm
) *dyfunc
= NULL
;
282 void *image
= __loadSecurity();
283 if (image
) dyfunc
= dlsym(image
, "AuthorizationMakeExternalForm");
285 return dyfunc
? dyfunc(authorization
, extForm
) : -1;
288 __private_extern__ OSStatus
289 _SecAccessCopySelectedACLList(SecAccessRef accessRef
, CSSM_ACL_AUTHORIZATION_TAG action
, CFArrayRef
*aclList
)
291 #undef SecAccessCopySelectedACLList
292 static typeof (SecAccessCopySelectedACLList
) *dyfunc
= NULL
;
294 void *image
= __loadSecurity();
295 if (image
) dyfunc
= dlsym(image
, "SecAccessCopySelectedACLList");
297 return dyfunc
? dyfunc(accessRef
, action
, aclList
) : -1;
300 __private_extern__ OSStatus
301 _SecAccessCreate(CFStringRef descriptor
, CFArrayRef trustedlist
, SecAccessRef
*accessRef
)
303 #undef SecAccessCreate
304 static typeof (SecAccessCreate
) *dyfunc
= NULL
;
306 void *image
= __loadSecurity();
307 if (image
) dyfunc
= dlsym(image
, "SecAccessCreate");
309 return dyfunc
? dyfunc(descriptor
, trustedlist
, accessRef
) : -1;
312 __private_extern__ OSStatus
313 _SecAccessCreateFromOwnerAndACL(const CSSM_ACL_OWNER_PROTOTYPE
*owner
, uint32 aclCount
, const CSSM_ACL_ENTRY_INFO
*acls
, SecAccessRef
*accessRef
)
315 #undef SecAccessCreateFromOwnerAndACL
316 static typeof (SecAccessCreateFromOwnerAndACL
) *dyfunc
= NULL
;
318 void *image
= __loadSecurity();
319 if (image
) dyfunc
= dlsym(image
, "SecAccessCreateFromOwnerAndACL");
321 return dyfunc
? dyfunc(owner
, aclCount
, acls
, accessRef
) : -1;
324 __private_extern__ OSStatus
325 _SecKeychainCopyDomainDefault(SecPreferencesDomain domain
, SecKeychainRef
*keychain
)
327 #undef SecKeychainCopyDomainDefault
328 static typeof (SecKeychainCopyDomainDefault
) *dyfunc
= NULL
;
330 void *image
= __loadSecurity();
331 if (image
) dyfunc
= dlsym(image
, "SecKeychainCopyDomainDefault");
333 return dyfunc
? dyfunc(domain
, keychain
) : -1;
336 __private_extern__ OSStatus
337 _SecKeychainGetPreferenceDomain(SecPreferencesDomain
*domain
)
339 #undef SecKeychainGetPreferenceDomain
340 static typeof (SecKeychainGetPreferenceDomain
) *dyfunc
= NULL
;
342 void *image
= __loadSecurity();
343 if (image
) dyfunc
= dlsym(image
, "SecKeychainGetPreferenceDomain");
345 return dyfunc
? dyfunc(domain
) : -1;
348 __private_extern__ OSStatus
349 _SecKeychainOpen(const char *pathName
, SecKeychainRef
*keychain
)
351 #undef SecKeychainOpen
352 static typeof (SecKeychainOpen
) *dyfunc
= NULL
;
354 void *image
= __loadSecurity();
355 if (image
) dyfunc
= dlsym(image
, "SecKeychainOpen");
357 return dyfunc
? dyfunc(pathName
, keychain
) : -1;
360 __private_extern__ OSStatus
361 _SecKeychainSetDomainDefault(SecPreferencesDomain domain
, SecKeychainRef keychain
)
363 #undef SecKeychainSetDomainDefault
364 static typeof (SecKeychainSetDomainDefault
) *dyfunc
= NULL
;
366 void *image
= __loadSecurity();
367 if (image
) dyfunc
= dlsym(image
, "SecKeychainSetDomainDefault");
369 return dyfunc
? dyfunc(domain
, keychain
) : -1;
372 __private_extern__ OSStatus
373 _SecKeychainSetPreferenceDomain(SecPreferencesDomain domain
)
375 #undef SecKeychainSetPreferenceDomain
376 static typeof (SecKeychainSetPreferenceDomain
) *dyfunc
= NULL
;
378 void *image
= __loadSecurity();
379 if (image
) dyfunc
= dlsym(image
, "SecKeychainSetPreferenceDomain");
381 return dyfunc
? dyfunc(domain
) : -1;
384 __private_extern__ OSStatus
385 _SecKeychainItemCopyContent(SecKeychainItemRef itemRef
, SecItemClass
*itemClass
, SecKeychainAttributeList
*attrList
, UInt32
*length
, void **outData
)
387 #undef SecKeychainItemCopyContent
388 static typeof (SecKeychainItemCopyContent
) *dyfunc
= NULL
;
390 void *image
= __loadSecurity();
391 if (image
) dyfunc
= dlsym(image
, "SecKeychainItemCopyContent");
393 return dyfunc
? dyfunc(itemRef
, itemClass
, attrList
, length
, outData
) : -1;
396 __private_extern__ OSStatus
397 _SecKeychainItemCreateFromContent(SecItemClass itemClass
, SecKeychainAttributeList
*attrList
, UInt32 length
, const void *data
, SecKeychainRef keychainRef
, SecAccessRef initialAccess
, SecKeychainItemRef
*itemRef
)
399 #undef SecKeychainItemCreateFromContent
400 static typeof (SecKeychainItemCreateFromContent
) *dyfunc
= NULL
;
402 void *image
= __loadSecurity();
403 if (image
) dyfunc
= dlsym(image
, "SecKeychainItemCreateFromContent");
405 return dyfunc
? dyfunc(itemClass
, attrList
, length
, data
, keychainRef
, initialAccess
, itemRef
) : -1;
408 __private_extern__ OSStatus
409 _SecKeychainItemDelete(SecKeychainItemRef itemRef
)
411 #undef SecKeychainItemDelete
412 static typeof (SecKeychainItemDelete
) *dyfunc
= NULL
;
414 void *image
= __loadSecurity();
415 if (image
) dyfunc
= dlsym(image
, "SecKeychainItemDelete");
417 return dyfunc
? dyfunc(itemRef
) : -1;
420 __private_extern__ OSStatus
421 _SecKeychainItemFreeContent(SecKeychainAttributeList
*attrList
, void *data
)
423 #undef SecKeychainItemFreeContent
424 static typeof (SecKeychainItemFreeContent
) *dyfunc
= NULL
;
426 void *image
= __loadSecurity();
427 if (image
) dyfunc
= dlsym(image
, "SecKeychainItemFreeContent");
429 return dyfunc
? dyfunc(attrList
, data
) : -1;
432 __private_extern__ OSStatus
433 _SecKeychainItemModifyContent(SecKeychainItemRef itemRef
, const SecKeychainAttributeList
*attrList
, UInt32 length
, const void *data
)
435 #undef SecKeychainItemModifyContent
436 static typeof (SecKeychainItemModifyContent
) *dyfunc
= NULL
;
438 void *image
= __loadSecurity();
439 if (image
) dyfunc
= dlsym(image
, "SecKeychainItemModifyContent");
441 return dyfunc
? dyfunc(itemRef
, attrList
, length
, data
) : -1;
444 __private_extern__ OSStatus
445 _SecKeychainSearchCopyNext(SecKeychainSearchRef searchRef
, SecKeychainItemRef
*itemRef
)
447 #undef SecKeychainSearchCopyNext
448 static typeof (SecKeychainSearchCopyNext
) *dyfunc
= NULL
;
450 void *image
= __loadSecurity();
451 if (image
) dyfunc
= dlsym(image
, "SecKeychainSearchCopyNext");
453 return dyfunc
? dyfunc(searchRef
, itemRef
) : -1;
456 __private_extern__ OSStatus
457 _SecKeychainSearchCreateFromAttributes(CFTypeRef keychainOrArray
, SecItemClass itemClass
, const SecKeychainAttributeList
*attrList
, SecKeychainSearchRef
*searchRef
)
459 #undef SecKeychainSearchCreateFromAttributes
460 static typeof (SecKeychainSearchCreateFromAttributes
) *dyfunc
= NULL
;
462 void *image
= __loadSecurity();
463 if (image
) dyfunc
= dlsym(image
, "SecKeychainSearchCreateFromAttributes");
465 return dyfunc
? dyfunc(keychainOrArray
, itemClass
, attrList
, searchRef
) : -1;
468 __private_extern__ OSStatus
469 _SecTrustedApplicationCreateFromPath(const char *path
, SecTrustedApplicationRef
*app
)
471 #undef SecTrustedApplicationCreateFromPath
472 static typeof (SecTrustedApplicationCreateFromPath
) *dyfunc
= NULL
;
474 void *image
= __loadSecurity();
475 if (image
) dyfunc
= dlsym(image
, "SecTrustedApplicationCreateFromPath");
477 return dyfunc
? dyfunc(path
, app
) : -1;