No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / bind / dist / bin / pkcs11 / unix / unix.c
blob7fffec9a1a04a3340531077beef6e3a97eb585bf
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 /* Id: unix.c,v 1.4 2009/10/26 23:47:35 tbox Exp */
21 /* $Id */
23 /*! \file */
25 /* dynamic loader (ifndef FORCE_STATIC_PROVIDER) */
27 #include <dlfcn.h>
29 /* load PKCS11 dynamic object */
31 #ifndef PK11_LIB_LOCATION
32 #error "PK11_LIB_LOCATION is not set"
33 #endif
35 const char *pk11_libname = PK11_LIB_LOCATION;
37 void *hPK11 = NULL;
39 #define C_Initialize isc_C_Initialize
41 CK_RV
42 C_Initialize(CK_VOID_PTR pReserved);
44 CK_RV
45 C_Initialize(CK_VOID_PTR pReserved)
47 CK_C_Initialize sym;
49 hPK11 = dlopen(pk11_libname, RTLD_NOW);
51 if (hPK11 == NULL)
52 return 0xfe;
53 sym = (CK_C_Initialize)dlsym(hPK11, "C_Initialize");
54 if (sym == NULL)
55 return 0xff;
56 return (*sym)(pReserved);
59 #define C_Finalize isc_C_Finalize
61 CK_RV
62 C_Finalize(CK_VOID_PTR pReserved);
64 CK_RV
65 C_Finalize(CK_VOID_PTR pReserved)
67 CK_C_Finalize sym;
69 if (hPK11 == NULL)
70 return 0xfe;
71 sym = (CK_C_Finalize)dlsym(hPK11, "C_Finalize");
72 if (sym == NULL)
73 return 0xff;
74 return (*sym)(pReserved);
77 #define C_OpenSession isc_C_OpenSession
79 CK_RV
80 C_OpenSession(CK_SLOT_ID slotID,
81 CK_FLAGS flags,
82 CK_VOID_PTR pApplication,
83 CK_RV (*Notify) (CK_SESSION_HANDLE hSession,
84 CK_NOTIFICATION event,
85 CK_VOID_PTR pApplication),
86 CK_SESSION_HANDLE_PTR phSession);
88 CK_RV
89 C_OpenSession(CK_SLOT_ID slotID,
90 CK_FLAGS flags,
91 CK_VOID_PTR pApplication,
92 CK_RV (*Notify) (CK_SESSION_HANDLE hSession,
93 CK_NOTIFICATION event,
94 CK_VOID_PTR pApplication),
95 CK_SESSION_HANDLE_PTR phSession)
97 CK_C_OpenSession sym;
99 if (hPK11 == NULL)
100 hPK11 = dlopen(pk11_libname, RTLD_NOW);
101 if (hPK11 == NULL)
102 return 0xfe;
103 sym = (CK_C_OpenSession)dlsym(hPK11, "C_OpenSession");
104 if (sym == NULL)
105 return 0xff;
106 return (*sym)(slotID, flags, pApplication, Notify, phSession);
109 #define C_CloseSession isc_C_CloseSession
111 CK_RV
112 C_CloseSession(CK_SESSION_HANDLE hSession);
114 CK_RV
115 C_CloseSession(CK_SESSION_HANDLE hSession)
117 CK_C_CloseSession sym;
119 if (hPK11 == NULL)
120 return 0xfe;
121 sym = (CK_C_CloseSession)dlsym(hPK11, "C_CloseSession");
122 if (sym == NULL)
123 return 0xff;
124 return (*sym)(hSession);
127 #define C_Login isc_C_Login
129 CK_RV
130 C_Login(CK_SESSION_HANDLE hSession,
131 CK_USER_TYPE userType,
132 CK_CHAR_PTR pPin,
133 CK_ULONG usPinLen);
135 CK_RV
136 C_Login(CK_SESSION_HANDLE hSession,
137 CK_USER_TYPE userType,
138 CK_CHAR_PTR pPin,
139 CK_ULONG usPinLen)
141 CK_C_Login sym;
143 if (hPK11 == NULL)
144 return 0xfe;
145 sym = (CK_C_Login)dlsym(hPK11, "C_Login");
146 if (sym == NULL)
147 return 0xff;
148 return (*sym)(hSession, userType, pPin, usPinLen);
151 #define C_CreateObject isc_C_CreateObject
153 CK_RV
154 C_CreateObject(CK_SESSION_HANDLE hSession,
155 CK_ATTRIBUTE_PTR pTemplate,
156 CK_ULONG usCount,
157 CK_OBJECT_HANDLE_PTR phObject);
159 CK_RV
160 C_CreateObject(CK_SESSION_HANDLE hSession,
161 CK_ATTRIBUTE_PTR pTemplate,
162 CK_ULONG usCount,
163 CK_OBJECT_HANDLE_PTR phObject)
165 CK_C_CreateObject sym;
167 if (hPK11 == NULL)
168 return 0xfe;
169 sym = (CK_C_CreateObject)dlsym(hPK11, "C_CreateObject");
170 if (sym == NULL)
171 return 0xff;
172 return (*sym)(hSession, pTemplate, usCount, phObject);
175 #define C_DestroyObject isc_C_DestroyObject
177 CK_RV
178 C_DestroyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject);
180 CK_RV
181 C_DestroyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject)
183 CK_C_DestroyObject sym;
185 if (hPK11 == NULL)
186 return 0xfe;
187 sym = (CK_C_DestroyObject)dlsym(hPK11, "C_DestroyObject");
188 if (sym == NULL)
189 return 0xff;
190 return (*sym)(hSession, hObject);
193 #define C_GetAttributeValue isc_C_GetAttributeValue
195 CK_RV
196 C_GetAttributeValue(CK_SESSION_HANDLE hSession,
197 CK_OBJECT_HANDLE hObject,
198 CK_ATTRIBUTE_PTR pTemplate,
199 CK_ULONG usCount);
201 CK_RV
202 C_GetAttributeValue(CK_SESSION_HANDLE hSession,
203 CK_OBJECT_HANDLE hObject,
204 CK_ATTRIBUTE_PTR pTemplate,
205 CK_ULONG usCount)
207 CK_C_GetAttributeValue sym;
209 if (hPK11 == NULL)
210 return 0xfe;
211 sym = (CK_C_GetAttributeValue)dlsym(hPK11, "C_GetAttributeValue");
212 if (sym == NULL)
213 return 0xff;
214 return (*sym)(hSession, hObject, pTemplate, usCount);
217 #define C_SetAttributeValue isc_C_SetAttributeValue
219 CK_RV
220 C_SetAttributeValue(CK_SESSION_HANDLE hSession,
221 CK_OBJECT_HANDLE hObject,
222 CK_ATTRIBUTE_PTR pTemplate,
223 CK_ULONG usCount);
225 CK_RV
226 C_SetAttributeValue(CK_SESSION_HANDLE hSession,
227 CK_OBJECT_HANDLE hObject,
228 CK_ATTRIBUTE_PTR pTemplate,
229 CK_ULONG usCount)
231 CK_C_SetAttributeValue sym;
233 if (hPK11 == NULL)
234 return 0xfe;
235 sym = (CK_C_SetAttributeValue)dlsym(hPK11, "C_SetAttributeValue");
236 if (sym == NULL)
237 return 0xff;
238 return (*sym)(hSession, hObject, pTemplate, usCount);
241 #define C_FindObjectsInit isc_C_FindObjectsInit
243 CK_RV
244 C_FindObjectsInit(CK_SESSION_HANDLE hSession,
245 CK_ATTRIBUTE_PTR pTemplate,
246 CK_ULONG usCount);
248 CK_RV
249 C_FindObjectsInit(CK_SESSION_HANDLE hSession,
250 CK_ATTRIBUTE_PTR pTemplate,
251 CK_ULONG usCount)
253 CK_C_FindObjectsInit sym;
255 if (hPK11 == NULL)
256 return 0xfe;
257 sym = (CK_C_FindObjectsInit)dlsym(hPK11, "C_FindObjectsInit");
258 if (sym == NULL)
259 return 0xff;
260 return (*sym)(hSession, pTemplate, usCount);
263 #define C_FindObjects isc_C_FindObjects
265 CK_RV
266 C_FindObjects(CK_SESSION_HANDLE hSession,
267 CK_OBJECT_HANDLE_PTR phObject,
268 CK_ULONG usMaxObjectCount,
269 CK_ULONG_PTR pusObjectCount);
271 CK_RV
272 C_FindObjects(CK_SESSION_HANDLE hSession,
273 CK_OBJECT_HANDLE_PTR phObject,
274 CK_ULONG usMaxObjectCount,
275 CK_ULONG_PTR pusObjectCount)
277 CK_C_FindObjects sym;
279 if (hPK11 == NULL)
280 return 0xfe;
281 sym = (CK_C_FindObjects)dlsym(hPK11, "C_FindObjects");
282 if (sym == NULL)
283 return 0xff;
284 return (*sym)(hSession, phObject, usMaxObjectCount, pusObjectCount);
287 #define C_FindObjectsFinal isc_C_FindObjectsFinal
289 CK_RV
290 C_FindObjectsFinal(CK_SESSION_HANDLE hSession);
292 CK_RV
293 C_FindObjectsFinal(CK_SESSION_HANDLE hSession)
295 CK_C_FindObjectsFinal sym;
297 if (hPK11 == NULL)
298 return 0xfe;
299 sym = (CK_C_FindObjectsFinal)dlsym(hPK11, "C_FindObjectsFinal");
300 if (sym == NULL)
301 return 0xff;
302 return (*sym)(hSession);
305 #define C_GenerateKeyPair isc_C_GenerateKeyPair
307 CK_RV
308 C_GenerateKeyPair(CK_SESSION_HANDLE hSession,
309 CK_MECHANISM_PTR pMechanism,
310 CK_ATTRIBUTE_PTR pPublicKeyTemplate,
311 CK_ULONG usPublicKeyAttributeCount,
312 CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
313 CK_ULONG usPrivateKeyAttributeCount,
314 CK_OBJECT_HANDLE_PTR phPrivateKey,
315 CK_OBJECT_HANDLE_PTR phPublicKey);
317 CK_RV
318 C_GenerateKeyPair(CK_SESSION_HANDLE hSession,
319 CK_MECHANISM_PTR pMechanism,
320 CK_ATTRIBUTE_PTR pPublicKeyTemplate,
321 CK_ULONG usPublicKeyAttributeCount,
322 CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
323 CK_ULONG usPrivateKeyAttributeCount,
324 CK_OBJECT_HANDLE_PTR phPrivateKey,
325 CK_OBJECT_HANDLE_PTR phPublicKey)
327 CK_C_GenerateKeyPair sym;
329 if (hPK11 == NULL)
330 return 0xfe;
331 sym = (CK_C_GenerateKeyPair)dlsym(hPK11, "C_GenerateKeyPair");
332 if (sym == NULL)
333 return 0xff;
334 return (*sym)(hSession,
335 pMechanism,
336 pPublicKeyTemplate,
337 usPublicKeyAttributeCount,
338 pPrivateKeyTemplate,
339 usPrivateKeyAttributeCount,
340 phPrivateKey,
341 phPublicKey);