From e8fe761b0f44bc4ebe42dff3aecce811b7f6c312 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Thu, 4 Dec 2008 20:22:41 +0000 Subject: Add basic module loading and printing of messages. --- src/module.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/module.c (limited to 'src/module.c') diff --git a/src/module.c b/src/module.c new file mode 100644 index 0000000..9815c21 --- /dev/null +++ b/src/module.c @@ -0,0 +1,44 @@ + +#include "config.h" + +#include "p11-tests.h" + +#include + +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; +} -- cgit v1.2.3