]> git.saurik.com Git - apple/configd.git/blobdiff - SystemConfiguration.fproj/dy_framework.c
configd-204.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / dy_framework.c
index f31634d3ed26140c1f6ba6bb88c277567fa4f645..421361dcfe8519717fe31d078e7151694072b69b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2002-2006 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/stat.h>
-#include <mach-o/dyld.h>
+#include <dlfcn.h>
 
 #include "dy_framework.h"
 
 
 static void *
 __loadIOKit(void) {
-       static const void *image = NULL;
+       static void *image = NULL;
        if (NULL == image) {
-               const char      *framework              = "/System/Library/Frameworks/IOKit.framework/IOKit";
+               const char      *framework              = "/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit";
                struct stat     statbuf;
                const char      *suffix                 = getenv("DYLD_IMAGE_SUFFIX");
                char            path[MAXPATHLEN];
 
-               strcpy(path, framework);
-               if (suffix) strcat(path, suffix);
+               strlcpy(path, framework, sizeof(path));
+               if (suffix) strlcat(path, suffix, sizeof(path));
                if (0 <= stat(path, &statbuf)) {
-                       image = NSAddImage(path, NSADDIMAGE_OPTION_NONE);
+                       image = dlopen(path, RTLD_LAZY | RTLD_LOCAL);
                } else {
-                       image = NSAddImage(framework, NSADDIMAGE_OPTION_NONE);
+                       image = dlopen(framework, RTLD_LAZY | RTLD_LOCAL);
                }
        }
        return (void *)image;
@@ -65,7 +65,7 @@ _IOBSDNameMatching(mach_port_t masterPort, unsigned int options, const char *bsd
        static typeof (IOBSDNameMatching) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadIOKit();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOBSDNameMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "IOBSDNameMatching");
        }
        return dyfunc ? dyfunc(masterPort, options, bsdName) : NULL;
 }
@@ -78,7 +78,7 @@ _IOIteratorNext(io_iterator_t iterator)
        static typeof (IOIteratorNext) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadIOKit();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOIteratorNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "IOIteratorNext");
        }
        return dyfunc ? dyfunc(iterator) : 0;
 }
@@ -91,7 +91,7 @@ _IOMasterPort(mach_port_t bootstrapPort, mach_port_t *masterPort)
        static typeof (IOMasterPort) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadIOKit();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOMasterPort", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "IOMasterPort");
        }
        return dyfunc ? dyfunc(bootstrapPort, masterPort) : KERN_FAILURE;
 }
@@ -104,7 +104,7 @@ _IOObjectConformsTo(io_object_t object, const io_name_t className)
        static typeof (IOObjectConformsTo) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadIOKit();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOObjectConformsTo", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "IOObjectConformsTo");
        }
        return dyfunc ? dyfunc(object, className) : FALSE;
 }
@@ -117,7 +117,7 @@ _IOObjectGetClass(io_object_t object, io_name_t className)
        static typeof (IOObjectGetClass) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadIOKit();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOObjectGetClass", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "IOObjectGetClass");
        }
        return dyfunc ? dyfunc(object, className) : FALSE;
 }
@@ -130,7 +130,7 @@ _IOObjectRelease(io_object_t object)
        static typeof (IOObjectRelease) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadIOKit();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOObjectRelease", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "IOObjectRelease");
        }
        return dyfunc ? dyfunc(object) : KERN_FAILURE;
 }
@@ -143,7 +143,7 @@ _IORegistryEntryCreateCFProperty(io_registry_entry_t entry, CFStringRef key, CFA
        static typeof (IORegistryEntryCreateCFProperty) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadIOKit();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryCreateCFProperty", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "IORegistryEntryCreateCFProperty");
        }
        return dyfunc ? dyfunc(entry, key, allocator, options) : NULL;
 }
@@ -156,7 +156,7 @@ _IORegistryEntryCreateCFProperties(io_registry_entry_t entry, CFMutableDictionar
        static typeof (IORegistryEntryCreateCFProperties) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadIOKit();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryCreateCFProperties", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "IORegistryEntryCreateCFProperties");
        }
        return dyfunc ? dyfunc(entry, properties, allocator, options) : KERN_FAILURE;
 }
@@ -169,7 +169,7 @@ _IORegistryEntryCreateIterator(mach_port_t masterPort, const io_name_t plane, IO
        static typeof (IORegistryEntryCreateIterator) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadIOKit();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryCreateIterator", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "IORegistryEntryCreateIterator");
        }
        return dyfunc ? dyfunc(masterPort, plane, options, iterator) : KERN_FAILURE;
 }
@@ -182,7 +182,7 @@ _IORegistryEntryGetName(io_registry_entry_t entry, io_name_t name)
        static typeof (IORegistryEntryGetName) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadIOKit();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryGetName", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "IORegistryEntryGetName");
        }
        return dyfunc ? dyfunc(entry, name) : KERN_FAILURE;
 }
@@ -195,7 +195,7 @@ _IORegistryEntryGetParentEntry(io_registry_entry_t entry, const io_name_t plane,
        static typeof (IORegistryEntryGetParentEntry) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadIOKit();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryGetParentEntry", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "IORegistryEntryGetParentEntry");
        }
        return dyfunc ? dyfunc(entry, plane, parent) : KERN_FAILURE;
 }
@@ -208,7 +208,7 @@ _IORegistryEntryGetPath(io_registry_entry_t entry, const io_name_t plane, io_str
        static typeof (IORegistryEntryGetPath) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadIOKit();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryGetPath", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "IORegistryEntryGetPath");
        }
        return dyfunc ? dyfunc(entry, plane, path) : KERN_FAILURE;
 }
@@ -221,7 +221,7 @@ _IORegistryEntrySearchCFProperty(io_registry_entry_t entry, const io_name_t plan
        static typeof (IORegistryEntrySearchCFProperty) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadIOKit();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntrySearchCFProperty", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "IORegistryEntrySearchCFProperty");
        }
        return dyfunc ? dyfunc(entry, plane, key, allocator, options) : NULL;
 }
@@ -234,7 +234,7 @@ _IOServiceGetMatchingServices(mach_port_t masterPort, CFDictionaryRef matching,
        static typeof (IOServiceGetMatchingServices) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadIOKit();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOServiceGetMatchingServices", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "IOServiceGetMatchingServices");
        }
        return dyfunc ? dyfunc(masterPort, matching, existing) : KERN_FAILURE;
 }
@@ -247,32 +247,140 @@ _IOServiceMatching(const char *name)
        static typeof (IOServiceMatching) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadIOKit();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOServiceMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "IOServiceMatching");
        }
        return dyfunc ? dyfunc(name) : NULL;
 }
 
 static void *
 __loadSecurity(void) {
-       static const void *image = NULL;
+       static void *image = NULL;
        if (NULL == image) {
-               const char      *framework              = "/System/Library/Frameworks/Security.framework/Security";
+               const char      *framework              = "/System/Library/Frameworks/Security.framework/Versions/A/Security";
                struct stat     statbuf;
                const char      *suffix                 = getenv("DYLD_IMAGE_SUFFIX");
                char            path[MAXPATHLEN];
 
-               strcpy(path, framework);
-               if (suffix) strcat(path, suffix);
+               strlcpy(path, framework, sizeof(path));
+               if (suffix) strlcat(path, suffix, sizeof(path));
                if (0 <= stat(path, &statbuf)) {
-                       image = NSAddImage(path, NSADDIMAGE_OPTION_NONE);
+                       image = dlopen(path, RTLD_LAZY | RTLD_LOCAL);
                } else {
-                       image = NSAddImage(framework, NSADDIMAGE_OPTION_NONE);
+                       image = dlopen(framework, RTLD_LAZY | RTLD_LOCAL);
                }
        }
        return (void *)image;
 }
 
 
+__private_extern__ OSStatus
+_AuthorizationMakeExternalForm(AuthorizationRef authorization, AuthorizationExternalForm *extForm)
+{
+       #undef AuthorizationMakeExternalForm
+       static typeof (AuthorizationMakeExternalForm) *dyfunc = NULL;
+       if (!dyfunc) {
+               void *image = __loadSecurity();
+               if (image) dyfunc = dlsym(image, "AuthorizationMakeExternalForm");
+       }
+       return dyfunc ? dyfunc(authorization, extForm) : -1;
+}
+
+__private_extern__ OSStatus
+_SecAccessCopySelectedACLList(SecAccessRef accessRef, CSSM_ACL_AUTHORIZATION_TAG action, CFArrayRef *aclList)
+{
+       #undef SecAccessCopySelectedACLList
+       static typeof (SecAccessCopySelectedACLList) *dyfunc = NULL;
+       if (!dyfunc) {
+               void *image = __loadSecurity();
+               if (image) dyfunc = dlsym(image, "SecAccessCopySelectedACLList");
+       }
+       return dyfunc ? dyfunc(accessRef, action, aclList) : -1;
+}
+
+__private_extern__ OSStatus
+_SecAccessCreate(CFStringRef descriptor, CFArrayRef trustedlist, SecAccessRef *accessRef)
+{
+       #undef SecAccessCreate
+       static typeof (SecAccessCreate) *dyfunc = NULL;
+       if (!dyfunc) {
+               void *image = __loadSecurity();
+               if (image) dyfunc = dlsym(image, "SecAccessCreate");
+       }
+       return dyfunc ? dyfunc(descriptor, trustedlist, accessRef) : -1;
+}
+
+__private_extern__ OSStatus
+_SecAccessCreateFromOwnerAndACL(const CSSM_ACL_OWNER_PROTOTYPE *owner, uint32 aclCount, const CSSM_ACL_ENTRY_INFO *acls, SecAccessRef *accessRef)
+{
+       #undef SecAccessCreateFromOwnerAndACL
+       static typeof (SecAccessCreateFromOwnerAndACL) *dyfunc = NULL;
+       if (!dyfunc) {
+               void *image = __loadSecurity();
+               if (image) dyfunc = dlsym(image, "SecAccessCreateFromOwnerAndACL");
+       }
+       return dyfunc ? dyfunc(owner, aclCount, acls, accessRef) : -1;
+}
+
+__private_extern__ OSStatus
+_SecKeychainCopyDomainDefault(SecPreferencesDomain domain, SecKeychainRef *keychain)
+{
+       #undef SecKeychainCopyDomainDefault
+       static typeof (SecKeychainCopyDomainDefault) *dyfunc = NULL;
+       if (!dyfunc) {
+               void *image = __loadSecurity();
+               if (image) dyfunc = dlsym(image, "SecKeychainCopyDomainDefault");
+       }
+       return dyfunc ? dyfunc(domain, keychain) : -1;
+}
+
+__private_extern__ OSStatus
+_SecKeychainGetPreferenceDomain(SecPreferencesDomain *domain)
+{
+       #undef SecKeychainGetPreferenceDomain
+       static typeof (SecKeychainGetPreferenceDomain) *dyfunc = NULL;
+       if (!dyfunc) {
+               void *image = __loadSecurity();
+               if (image) dyfunc = dlsym(image, "SecKeychainGetPreferenceDomain");
+       }
+       return dyfunc ? dyfunc(domain) : -1;
+}
+
+__private_extern__ OSStatus
+_SecKeychainOpen(const char *pathName, SecKeychainRef *keychain)
+{
+       #undef SecKeychainOpen
+       static typeof (SecKeychainOpen) *dyfunc = NULL;
+       if (!dyfunc) {
+               void *image = __loadSecurity();
+               if (image) dyfunc = dlsym(image, "SecKeychainOpen");
+       }
+       return dyfunc ? dyfunc(pathName, keychain) : -1;
+}
+
+__private_extern__ OSStatus
+_SecKeychainSetDomainDefault(SecPreferencesDomain domain, SecKeychainRef keychain)
+{
+       #undef SecKeychainSetDomainDefault
+       static typeof (SecKeychainSetDomainDefault) *dyfunc = NULL;
+       if (!dyfunc) {
+               void *image = __loadSecurity();
+               if (image) dyfunc = dlsym(image, "SecKeychainSetDomainDefault");
+       }
+       return dyfunc ? dyfunc(domain, keychain) : -1;
+}
+
+__private_extern__ OSStatus
+_SecKeychainSetPreferenceDomain(SecPreferencesDomain domain)
+{
+       #undef SecKeychainSetPreferenceDomain
+       static typeof (SecKeychainSetPreferenceDomain) *dyfunc = NULL;
+       if (!dyfunc) {
+               void *image = __loadSecurity();
+               if (image) dyfunc = dlsym(image, "SecKeychainSetPreferenceDomain");
+       }
+       return dyfunc ? dyfunc(domain) : -1;
+}
+
 __private_extern__ OSStatus
 _SecKeychainItemCopyContent(SecKeychainItemRef itemRef, SecItemClass *itemClass, SecKeychainAttributeList *attrList, UInt32 *length, void **outData)
 {
@@ -280,11 +388,59 @@ _SecKeychainItemCopyContent(SecKeychainItemRef itemRef, SecItemClass *itemClass,
        static typeof (SecKeychainItemCopyContent) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadSecurity();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_SecKeychainItemCopyContent", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "SecKeychainItemCopyContent");
        }
        return dyfunc ? dyfunc(itemRef, itemClass, attrList, length, outData) : -1;
 }
 
+__private_extern__ OSStatus
+_SecKeychainItemCreateFromContent(SecItemClass itemClass, SecKeychainAttributeList *attrList, UInt32 length, const void *data, SecKeychainRef keychainRef, SecAccessRef initialAccess, SecKeychainItemRef *itemRef)
+{
+       #undef SecKeychainItemCreateFromContent
+       static typeof (SecKeychainItemCreateFromContent) *dyfunc = NULL;
+       if (!dyfunc) {
+               void *image = __loadSecurity();
+               if (image) dyfunc = dlsym(image, "SecKeychainItemCreateFromContent");
+       }
+       return dyfunc ? dyfunc(itemClass, attrList, length, data, keychainRef, initialAccess, itemRef) : -1;
+}
+
+__private_extern__ OSStatus
+_SecKeychainItemDelete(SecKeychainItemRef itemRef)
+{
+       #undef SecKeychainItemDelete
+       static typeof (SecKeychainItemDelete) *dyfunc = NULL;
+       if (!dyfunc) {
+               void *image = __loadSecurity();
+               if (image) dyfunc = dlsym(image, "SecKeychainItemDelete");
+       }
+       return dyfunc ? dyfunc(itemRef) : -1;
+}
+
+__private_extern__ OSStatus
+_SecKeychainItemFreeContent(SecKeychainAttributeList *attrList, void *data)
+{
+       #undef SecKeychainItemFreeContent
+       static typeof (SecKeychainItemFreeContent) *dyfunc = NULL;
+       if (!dyfunc) {
+               void *image = __loadSecurity();
+               if (image) dyfunc = dlsym(image, "SecKeychainItemFreeContent");
+       }
+       return dyfunc ? dyfunc(attrList, data) : -1;
+}
+
+__private_extern__ OSStatus
+_SecKeychainItemModifyContent(SecKeychainItemRef itemRef, const SecKeychainAttributeList *attrList, UInt32 length, const void *data)
+{
+       #undef SecKeychainItemModifyContent
+       static typeof (SecKeychainItemModifyContent) *dyfunc = NULL;
+       if (!dyfunc) {
+               void *image = __loadSecurity();
+               if (image) dyfunc = dlsym(image, "SecKeychainItemModifyContent");
+       }
+       return dyfunc ? dyfunc(itemRef, attrList, length, data) : -1;
+}
+
 __private_extern__ OSStatus
 _SecKeychainSearchCopyNext(SecKeychainSearchRef searchRef, SecKeychainItemRef *itemRef)
 {
@@ -292,7 +448,7 @@ _SecKeychainSearchCopyNext(SecKeychainSearchRef searchRef, SecKeychainItemRef *i
        static typeof (SecKeychainSearchCopyNext) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadSecurity();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_SecKeychainSearchCopyNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "SecKeychainSearchCopyNext");
        }
        return dyfunc ? dyfunc(searchRef, itemRef) : -1;
 }
@@ -304,7 +460,20 @@ _SecKeychainSearchCreateFromAttributes(CFTypeRef keychainOrArray, SecItemClass i
        static typeof (SecKeychainSearchCreateFromAttributes) *dyfunc = NULL;
        if (!dyfunc) {
                void *image = __loadSecurity();
-               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_SecKeychainSearchCreateFromAttributes", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+               if (image) dyfunc = dlsym(image, "SecKeychainSearchCreateFromAttributes");
        }
        return dyfunc ? dyfunc(keychainOrArray, itemClass, attrList, searchRef) : -1;
 }
+
+__private_extern__ OSStatus
+_SecTrustedApplicationCreateFromPath(const char *path, SecTrustedApplicationRef *app)
+{
+       #undef SecTrustedApplicationCreateFromPath
+       static typeof (SecTrustedApplicationCreateFromPath) *dyfunc = NULL;
+       if (!dyfunc) {
+               void *image = __loadSecurity();
+               if (image) dyfunc = dlsym(image, "SecTrustedApplicationCreateFromPath");
+       }
+       return dyfunc ? dyfunc(path, app) : -1;
+}
+