blob: 9815c21358114d02ee6e7ccc40107e9e862f3821 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include "config.h"
#include "p11-tests.h"
#include <dlfcn.h>
static void *module = NULL;
CK_FUNCTION_LIST_PTR p11_funcs = NULL;
void
p11t_module_load(const char *filename)
{
CK_C_GetFunctionList get_function_list;
CK_RV rv;
module = dlopen(filename, RTLD_NOW);
if(!module)
p11t_msg_fatal("couldn't open library: %s: %s", filename, dlerror());
/* Lookup the appropriate function in library */
get_function_list = (CK_C_GetFunctionList)dlsym (module, "C_GetFunctionList");
if(!get_function_list)
p11t_msg_fatal("couldn't find C_GetFunctionList function in library: %s: %s", filename, dlerror());
/* Get the function list */
rv = (get_function_list)(&p11_funcs);
if(rv != CKR_OK)
p11t_msg_fatal("couldn't get function list: %s", p11t_msg_rv(rv));
/* Make sure we have a compatible version */
if(p11_funcs->version.major != CRYPTOKI_VERSION_MAJOR)
p11t_msg_fatal("incompatible version of pkcs11 module: %d.%d",
(int)p11_funcs->version.major,
(int)p11_funcs->version.minor);
}
void
p11t_module_unload(void)
{
if(module)
dlclose(module);
module = NULL;
}
|