summaryrefslogtreecommitdiff
path: root/src/module.c
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2008-12-04 20:22:41 +0000
committerStef Walter <stef@memberwebs.com>2008-12-04 20:22:41 +0000
commite8fe761b0f44bc4ebe42dff3aecce811b7f6c312 (patch)
treefa70dc00a8b1295e7f67e6d2003842b4e8119e51 /src/module.c
parentc980526f600dcc010b7a930be5413e3c7a4a8e96 (diff)
Add basic module loading and printing of messages.
Diffstat (limited to 'src/module.c')
-rw-r--r--src/module.c44
1 files changed, 44 insertions, 0 deletions
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 <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;
+}