static CK_RV perform_initialize (Initialize *args) { CK_FUNCTION_LIST_PTR funcs; GckModule *result; CK_RV rv; funcs = p11_kit_module_load (args->path, P11_KIT_MODULE_CRITICAL); if (funcs == NULL) { g_set_error (&args->error, GCK_ERROR, (int)CKR_GCK_MODULE_PROBLEM, _("Error loading PKCS#11 module: %s"), p11_kit_message ()); return CKR_GCK_MODULE_PROBLEM; } result = g_object_new (GCK_TYPE_MODULE, "functions", funcs, "path", args->path, NULL); /* Now initialize the module */ rv = p11_kit_module_initialize (funcs); if (rv != CKR_OK) { p11_kit_module_release (funcs); g_set_error (&args->error, GCK_ERROR, rv, _("Couldn’t initialize PKCS#11 module: %s"), gck_message_from_rv (rv)); g_object_unref (result); return rv; } result->pv->initialized = TRUE; args->result = result; return CKR_OK; }
static int anchor_store (int argc, char *argv[], bool *changed) { CK_ATTRIBUTE *attrs; CK_FUNCTION_LIST *module = NULL; CK_SESSION_HANDLE session; CK_OBJECT_HANDLE object; p11_array *anchors; int ret; int i; anchors = files_to_attrs (argc, argv); if (anchors == NULL) return 1; if (anchors->num == 0) { p11_message ("specify at least one anchor input file"); p11_array_free (anchors); return 2; } session = session_for_store (&module); if (session == 0UL) { p11_array_free (anchors); return 1; } for (i = 0, ret = 0; i < anchors->num; i++) { attrs = anchors->elem[i]; anchors->elem[i] = NULL; object = find_anchor (module, session, attrs); if (object == 0) { p11_debug ("don't yet have this anchor"); if (create_anchor (module, session, attrs)) { *changed = true; } else { ret = 1; break; } } else { p11_debug ("already have this anchor"); if (modify_anchor (module, session, object, attrs)) { *changed = true; } else { ret = 1; break; } } } p11_array_free (anchors); p11_kit_module_finalize (module); p11_kit_module_release (module); return ret; }
static void gck_module_finalize (GObject *obj) { GckModule *self = GCK_MODULE (obj); if (self->pv->initialized && self->pv->funcs) p11_kit_module_release (self->pv->funcs); self->pv->funcs = NULL; g_free (self->pv->path); self->pv->path = NULL; G_OBJECT_CLASS (gck_module_parent_class)->finalize (obj); }
static CK_SESSION_HANDLE session_for_store (CK_FUNCTION_LIST **module) { CK_SESSION_HANDLE session = 0UL; CK_FUNCTION_LIST **modules; bool found_read_only = false; char *name; int i; modules = p11_kit_modules_load (NULL, P11_KIT_MODULE_TRUSTED); if (modules == NULL) return 0; for (i = 0; modules[i] != NULL; i++) { if (session == 0UL) { name = p11_kit_module_get_name (modules[i]); session = session_for_store_on_module (name, modules[i], &found_read_only); if (session != 0UL) { *module = modules[i]; modules[i] = NULL; } free (name); } if (modules[i]) p11_kit_module_release (modules[i]); } if (session == 0UL) { if (found_read_only) p11_message ("no configured writable location to store anchors"); else p11_message ("no configured location to store anchors"); } free (modules); return session; }