]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/dy_framework.c
configd-84.6.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 * 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 <mach-o/dyld.h>
36
37 #include "dy_framework.h"
38
39
40 static void *
41 __loadIOKit(void) {
42 static const void *image = NULL;
43 if (NULL == image) {
44 const char *framework = "/System/Library/Frameworks/IOKit.framework/IOKit";
45 struct stat statbuf;
46 const char *suffix = getenv("DYLD_IMAGE_SUFFIX");
47 char path[MAXPATHLEN];
48
49 strcpy(path, framework);
50 if (suffix) strcat(path, suffix);
51 if (0 <= stat(path, &statbuf)) {
52 image = NSAddImage(path, NSADDIMAGE_OPTION_NONE);
53 } else {
54 image = NSAddImage(framework, NSADDIMAGE_OPTION_NONE);
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 static CFMutableDictionaryRef (*dyfunc)(mach_port_t, unsigned int, const char *) = NULL;
65 if (!dyfunc) {
66 void *image = __loadIOKit();
67 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOBSDNameMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
68 }
69 return dyfunc ? dyfunc(masterPort, options, bsdName) : NULL;
70 }
71
72
73 __private_extern__ io_object_t
74 _IOIteratorNext(io_iterator_t iterator)
75 {
76 static io_object_t (*dyfunc)(io_iterator_t) = NULL;
77 if (!dyfunc) {
78 void *image = __loadIOKit();
79 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOIteratorNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
80 }
81 return dyfunc ? dyfunc(iterator) : 0;
82 }
83
84
85 __private_extern__ kern_return_t
86 _IOMasterPort(mach_port_t bootstrapPort, mach_port_t *masterPort)
87 {
88 static kern_return_t (*dyfunc)(mach_port_t, mach_port_t *) = NULL;
89 if (!dyfunc) {
90 void *image = __loadIOKit();
91 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOMasterPort", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
92 }
93 return dyfunc ? dyfunc(bootstrapPort, masterPort) : KERN_FAILURE;
94 }
95
96
97 __private_extern__ kern_return_t
98 _IOObjectRelease(io_object_t object)
99 {
100 static kern_return_t (*dyfunc)(io_object_t) = NULL;
101 if (!dyfunc) {
102 void *image = __loadIOKit();
103 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOObjectRelease", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
104 }
105 return dyfunc ? dyfunc(object) : KERN_FAILURE;
106 }
107
108
109 __private_extern__ CFTypeRef
110 _IORegistryEntryCreateCFProperty(io_registry_entry_t entry, CFStringRef key, CFAllocatorRef allocator, IOOptionBits options)
111 {
112 static CFTypeRef (*dyfunc)(io_registry_entry_t, CFStringRef, CFAllocatorRef, IOOptionBits) = NULL;
113 if (!dyfunc) {
114 void *image = __loadIOKit();
115 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryCreateCFProperty", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
116 }
117 return dyfunc ? dyfunc(entry, key, allocator, options) : NULL;
118 }
119
120
121 __private_extern__ kern_return_t
122 _IORegistryEntryCreateCFProperties(io_registry_entry_t entry, CFMutableDictionaryRef *properties, CFAllocatorRef allocator, IOOptionBits options)
123 {
124 static kern_return_t (*dyfunc)(io_registry_entry_t, CFMutableDictionaryRef *, CFAllocatorRef, IOOptionBits) = NULL;
125 if (!dyfunc) {
126 void *image = __loadIOKit();
127 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryCreateCFProperties", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
128 }
129 return dyfunc ? dyfunc(entry, properties, allocator, options) : KERN_FAILURE;
130 }
131
132
133 __private_extern__ kern_return_t
134 _IORegistryEntryGetParentEntry(io_registry_entry_t entry, const io_name_t plane, io_registry_entry_t *parent)
135 {
136 static kern_return_t (*dyfunc)(io_registry_entry_t, const io_name_t, io_registry_entry_t *) = NULL;
137 if (!dyfunc) {
138 void *image = __loadIOKit();
139 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryGetParentEntry", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
140 }
141 return dyfunc ? dyfunc(entry, plane, parent) : NULL;
142 }
143
144
145 __private_extern__ kern_return_t
146 _IORegistryEntryGetPath(io_registry_entry_t entry, const io_name_t plane, io_string_t path)
147 {
148 static kern_return_t (*dyfunc)(io_registry_entry_t, const io_name_t, io_string_t) = NULL;
149 if (!dyfunc) {
150 void *image = __loadIOKit();
151 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryGetPath", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
152 }
153 return dyfunc ? dyfunc(entry, plane, path) : KERN_FAILURE;
154 }
155
156
157 __private_extern__ kern_return_t
158 _IOServiceGetMatchingServices(mach_port_t masterPort, CFDictionaryRef matching, io_iterator_t *existing)
159 {
160 static kern_return_t (*dyfunc)(mach_port_t, CFDictionaryRef, io_iterator_t *) = NULL;
161 if (!dyfunc) {
162 void *image = __loadIOKit();
163 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOServiceGetMatchingServices", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
164 }
165 return dyfunc ? dyfunc(masterPort, matching, existing) : KERN_FAILURE;
166 }
167
168
169 __private_extern__ CFMutableDictionaryRef
170 _IOServiceMatching(const char *name)
171 {
172 static CFMutableDictionaryRef (*dyfunc)(const char *) = NULL;
173 if (!dyfunc) {
174 void *image = __loadIOKit();
175 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOServiceMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
176 }
177 return dyfunc ? dyfunc(name) : NULL;
178 }
179
180 static void *
181 __loadSecurity(void) {
182 static const void *image = NULL;
183 if (NULL == image) {
184 const char *framework = "/System/Library/Frameworks/Security.framework/Security";
185 struct stat statbuf;
186 const char *suffix = getenv("DYLD_IMAGE_SUFFIX");
187 char path[MAXPATHLEN];
188
189 strcpy(path, framework);
190 if (suffix) strcat(path, suffix);
191 if (0 <= stat(path, &statbuf)) {
192 image = NSAddImage(path, NSADDIMAGE_OPTION_NONE);
193 } else {
194 image = NSAddImage(framework, NSADDIMAGE_OPTION_NONE);
195 }
196 }
197 return (void *)image;
198 }
199
200
201 __private_extern__ OSStatus
202 _SecKeychainItemCopyContent(SecKeychainItemRef itemRef, SecItemClass *itemClass, SecKeychainAttributeList *attrList, UInt32 *length, void **outData)
203 {
204 static OSStatus (*dyfunc)(SecKeychainItemRef, SecItemClass *, SecKeychainAttributeList *, UInt32 *, void **) = NULL;
205 if (!dyfunc) {
206 void *image = __loadSecurity();
207 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_SecKeychainItemCopyContent", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
208 }
209 return dyfunc ? dyfunc(itemRef, itemClass, attrList, length, outData) : -1;
210 }
211
212 __private_extern__ OSStatus
213 _SecKeychainSearchCopyNext(SecKeychainSearchRef searchRef, SecKeychainItemRef *itemRef)
214 {
215 static OSStatus (*dyfunc)(SecKeychainSearchRef, SecKeychainItemRef *) = NULL;
216 if (!dyfunc) {
217 void *image = __loadSecurity();
218 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_SecKeychainSearchCopyNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
219 }
220 return dyfunc ? dyfunc(searchRef, itemRef) : -1;
221 }
222
223 __private_extern__ OSStatus
224 _SecKeychainSearchCreateFromAttributes(CFTypeRef keychainOrArray, SecItemClass itemClass, const SecKeychainAttributeList *attrList, SecKeychainSearchRef *searchRef)
225 {
226 static OSStatus (*dyfunc)(CFTypeRef, SecItemClass, const SecKeychainAttributeList *, SecKeychainSearchRef *) = NULL;
227 if (!dyfunc) {
228 void *image = __loadSecurity();
229 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_SecKeychainSearchCreateFromAttributes", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
230 }
231 return dyfunc ? dyfunc(keychainOrArray, itemClass, attrList, searchRef) : -1;
232 }