#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; }