]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/dy_framework.c
configd-84.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / dy_framework.c
1 /*
2 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26 /*
27 * Modification History
28 *
29 * October 31, 2000 Allan Nathanson <ajn@apple.com>
30 * - initial revision
31 */
32
33
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/stat.h>
37 #include <mach-o/dyld.h>
38
39 #include "dy_framework.h"
40
41
42 static void *
43 __loadIOKit(void) {
44 static const void *image = NULL;
45 if (NULL == image) {
46 const char *framework = "/System/Library/Frameworks/IOKit.framework/IOKit";
47 struct stat statbuf;
48 const char *suffix = getenv("DYLD_IMAGE_SUFFIX");
49 char path[MAXPATHLEN];
50
51 strcpy(path, framework);
52 if (suffix) strcat(path, suffix);
53 if (0 <= stat(path, &statbuf)) {
54 image = NSAddImage(path, NSADDIMAGE_OPTION_NONE);
55 } else {
56 image = NSAddImage(framework, NSADDIMAGE_OPTION_NONE);
57 }
58 }
59 return (void *)image;
60 }
61
62
63 __private_extern__ CFMutableDictionaryRef
64 _IOBSDNameMatching(mach_port_t masterPort, unsigned int options, const char *bsdName)
65 {
66 static CFMutableDictionaryRef (*dyfunc)(mach_port_t, unsigned int, const char *) = NULL;
67 if (!dyfunc) {
68 void *image = __loadIOKit();
69 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOBSDNameMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
70 }
71 return dyfunc ? dyfunc(masterPort, options, bsdName) : NULL;
72 }
73
74
75 __private_extern__ io_object_t
76 _IOIteratorNext(io_iterator_t iterator)
77 {
78 static io_object_t (*dyfunc)(io_iterator_t) = NULL;
79 if (!dyfunc) {
80 void *image = __loadIOKit();
81 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOIteratorNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
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 static kern_return_t (*dyfunc)(mach_port_t, mach_port_t *) = NULL;
91 if (!dyfunc) {
92 void *image = __loadIOKit();
93 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOMasterPort", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
94 }
95 return dyfunc ? dyfunc(bootstrapPort, masterPort) : KERN_FAILURE;
96 }
97
98
99 __private_extern__ kern_return_t
100 _IOObjectRelease(io_object_t object)
101 {
102 static kern_return_t (*dyfunc)(io_object_t) = NULL;
103 if (!dyfunc) {
104 void *image = __loadIOKit();
105 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOObjectRelease", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
106 }
107 return dyfunc ? dyfunc(object) : KERN_FAILURE;
108 }
109
110
111 __private_extern__ CFTypeRef
112 _IORegistryEntryCreateCFProperty(io_registry_entry_t entry, CFStringRef key, CFAllocatorRef allocator, IOOptionBits options)
113 {
114 static CFTypeRef (*dyfunc)(io_registry_entry_t, CFStringRef, CFAllocatorRef, IOOptionBits) = NULL;
115 if (!dyfunc) {
116 void *image = __loadIOKit();
117 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryCreateCFProperty", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
118 }
119 return dyfunc ? dyfunc(entry, key, allocator, options) : NULL;
120 }
121
122
123 __private_extern__ kern_return_t
124 _IORegistryEntryCreateCFProperties(io_registry_entry_t entry, CFMutableDictionaryRef *properties, CFAllocatorRef allocator, IOOptionBits options)
125 {
126 static kern_return_t (*dyfunc)(io_registry_entry_t, CFMutableDictionaryRef *, CFAllocatorRef, IOOptionBits) = NULL;
127 if (!dyfunc) {
128 void *image = __loadIOKit();
129 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryCreateCFProperties", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
130 }
131 return dyfunc ? dyfunc(entry, properties, allocator, options) : KERN_FAILURE;
132 }
133
134
135 __private_extern__ kern_return_t
136 _IORegistryEntryGetParentEntry(io_registry_entry_t entry, const io_name_t plane, io_registry_entry_t *parent)
137 {
138 static kern_return_t (*dyfunc)(io_registry_entry_t, const io_name_t, io_registry_entry_t *) = NULL;
139 if (!dyfunc) {
140 void *image = __loadIOKit();
141 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryGetParentEntry", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
142 }
143 return dyfunc ? dyfunc(entry, plane, parent) : NULL;
144 }
145
146
147 __private_extern__ kern_return_t
148 _IORegistryEntryGetPath(io_registry_entry_t entry, const io_name_t plane, io_string_t path)
149 {
150 static kern_return_t (*dyfunc)(io_registry_entry_t, const io_name_t, io_string_t) = NULL;
151 if (!dyfunc) {
152 void *image = __loadIOKit();
153 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryGetPath", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
154 }
155 return dyfunc ? dyfunc(entry, plane, path) : KERN_FAILURE;
156 }
157
158
159 __private_extern__ kern_return_t
160 _IOServiceGetMatchingServices(mach_port_t masterPort, CFDictionaryRef matching, io_iterator_t *existing)
161 {
162 static kern_return_t (*dyfunc)(mach_port_t, CFDictionaryRef, io_iterator_t *) = NULL;
163 if (!dyfunc) {
164 void *image = __loadIOKit();
165 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOServiceGetMatchingServices", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
166 }
167 return dyfunc ? dyfunc(masterPort, matching, existing) : KERN_FAILURE;
168 }
169
170
171 __private_extern__ CFMutableDictionaryRef
172 _IOServiceMatching(const char *name)
173 {
174 static CFMutableDictionaryRef (*dyfunc)(const char *) = NULL;
175 if (!dyfunc) {
176 void *image = __loadIOKit();
177 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOServiceMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
178 }
179 return dyfunc ? dyfunc(name) : NULL;
180 }
181
182 static void *
183 __loadSecurity(void) {
184 static const void *image = NULL;
185 if (NULL == image) {
186 const char *framework = "/System/Library/Frameworks/Security.framework/Security";
187 struct stat statbuf;
188 const char *suffix = getenv("DYLD_IMAGE_SUFFIX");
189 char path[MAXPATHLEN];
190
191 strcpy(path, framework);
192 if (suffix) strcat(path, suffix);
193 if (0 <= stat(path, &statbuf)) {
194 image = NSAddImage(path, NSADDIMAGE_OPTION_NONE);
195 } else {
196 image = NSAddImage(framework, NSADDIMAGE_OPTION_NONE);
197 }
198 }
199 return (void *)image;
200 }
201
202
203 __private_extern__ OSStatus
204 _SecKeychainItemCopyContent(SecKeychainItemRef itemRef, SecItemClass *itemClass, SecKeychainAttributeList *attrList, UInt32 *length, void **outData)
205 {
206 static OSStatus (*dyfunc)(SecKeychainItemRef, SecItemClass *, SecKeychainAttributeList *, UInt32 *, void **) = NULL;
207 if (!dyfunc) {
208 void *image = __loadSecurity();
209 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_SecKeychainItemCopyContent", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
210 }
211 return dyfunc ? dyfunc(itemRef, itemClass, attrList, length, outData) : -1;
212 }
213
214 __private_extern__ OSStatus
215 _SecKeychainSearchCopyNext(SecKeychainSearchRef searchRef, SecKeychainItemRef *itemRef)
216 {
217 static OSStatus (*dyfunc)(SecKeychainSearchRef, SecKeychainItemRef *) = NULL;
218 if (!dyfunc) {
219 void *image = __loadSecurity();
220 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_SecKeychainSearchCopyNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
221 }
222 return dyfunc ? dyfunc(searchRef, itemRef) : -1;
223 }
224
225 __private_extern__ OSStatus
226 _SecKeychainSearchCreateFromAttributes(CFTypeRef keychainOrArray, SecItemClass itemClass, const SecKeychainAttributeList *attrList, SecKeychainSearchRef *searchRef)
227 {
228 static OSStatus (*dyfunc)(CFTypeRef, SecItemClass, const SecKeychainAttributeList *, SecKeychainSearchRef *) = NULL;
229 if (!dyfunc) {
230 void *image = __loadSecurity();
231 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_SecKeychainSearchCreateFromAttributes", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
232 }
233 return dyfunc ? dyfunc(keychainOrArray, itemClass, attrList, searchRef) : -1;
234 }