[gcr] Port to new p11-kit managed style functions



commit 4df7ba55dace9eb785715d115bce1e5d1d4cd599
Author: Stef Walter <stefw gnome org>
Date:   Tue May 21 12:07:45 2013 +0200

    Port to new p11-kit managed style functions
    
    This bumps the dependency of p11-kit to 0.19.1

 configure.ac      |    2 +-
 gck/gck-module.c  |   44 +++++++++-----------------------------------
 gck/gck-modules.c |   14 ++++----------
 gcr/gcr-library.c |   12 ++++++------
 4 files changed, 20 insertions(+), 52 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2910390..cbb0bf8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -124,7 +124,7 @@ AC_CHECK_FUNCS(mlock)
 # --------------------------------------------------------------------
 # p11-kit
 
-PKG_CHECK_MODULES([P11_KIT], p11-kit-1 >= 0.6)
+PKG_CHECK_MODULES([P11_KIT], p11-kit-1 >= 0.19.0)
 AC_SUBST(P11_KIT_CFLAGS)
 AC_SUBST(P11_KIT_LIBS)
 
diff --git a/gck/gck-module.c b/gck/gck-module.c
index e5503fa..1808cab 100644
--- a/gck/gck-module.c
+++ b/gck/gck-module.c
@@ -29,6 +29,7 @@
 
 #include <glib/gi18n-lib.h>
 
+#define P11_KIT_FUTURE_UNSTABLE_API 1
 #include <p11-kit/p11-kit.h>
 
 #include <string.h>
@@ -90,7 +91,6 @@ enum {
 };
 
 struct _GckModulePrivate {
-       GModule *module;
        gchar *path;
        gboolean initialized;
        CK_FUNCTION_LIST_PTR funcs;
@@ -175,7 +175,7 @@ gck_module_dispose (GObject *obj)
 
        /* Must be careful when accessing funcs */
        if (finalize) {
-               rv = p11_kit_finalize_module (self->pv->funcs);
+               rv = p11_kit_module_finalize (self->pv->funcs);
                if (rv != CKR_OK) {
                        g_warning ("C_Finalize on module '%s' failed: %s",
                                   self->pv->path, gck_message_from_rv (rv));
@@ -190,15 +190,10 @@ 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;
 
-       if (self->pv->module) {
-               if (!g_module_close (self->pv->module))
-                       g_warning ("failed to close the pkcs11 module: %s",
-                                  g_module_error ());
-               self->pv->module = NULL;
-       }
-
        g_free (self->pv->path);
        self->pv->path = NULL;
 
@@ -339,47 +334,26 @@ typedef struct {
 static CK_RV
 perform_initialize (Initialize *args)
 {
-       CK_C_GetFunctionList get_function_list;
        CK_FUNCTION_LIST_PTR funcs;
-       GModule *module;
        GckModule *result;
        CK_RV rv;
 
-       /* Load the actual module */
-       module = g_module_open (args->path, 0);
-       if (!module) {
-               g_set_error (&args->error, GCK_ERROR, (int)CKR_GCK_MODULE_PROBLEM,
-                            _("Error loading PKCS#11 module: %s"), g_module_error ());
-               return CKR_GCK_MODULE_PROBLEM;
-       }
-
-       /* Get the entry point */
-       if (!g_module_symbol (module, "C_GetFunctionList", (void**)&get_function_list)) {
+       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,
-                            _("Invalid PKCS#11 module: %s"), g_module_error ());
-               g_module_close (module);
+                            _("Error loading PKCS#11 module: %s"), p11_kit_message ());
                return CKR_GCK_MODULE_PROBLEM;
        }
 
-       /* Get the function list */
-       rv = (get_function_list) (&funcs);
-       if (rv != CKR_OK) {
-               g_set_error (&args->error, GCK_ERROR, rv,
-                            _("Couldn't setup PKCS#11 module: %s"),
-                            gck_message_from_rv (rv));
-               g_module_close (module);
-               return rv;
-       }
-
        result = g_object_new (GCK_TYPE_MODULE,
                               "functions", funcs,
                               "path", args->path,
                               NULL);
-       result->pv->module = module;
 
        /* Now initialize the module */
-       rv = p11_kit_initialize_module (funcs);
+       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));
diff --git a/gck/gck-modules.c b/gck/gck-modules.c
index 06301e1..d55666c 100644
--- a/gck/gck-modules.c
+++ b/gck/gck-modules.c
@@ -55,20 +55,14 @@ perform_initialize_registered (InitializeRegistered *args)
 {
        GckModule *module;
        CK_FUNCTION_LIST_PTR *modules, *funcs;
-       const gchar *message;
-       CK_RV rv;
-
-       rv = p11_kit_initialize_registered ();
-       if (rv != CKR_OK) {
-               message = p11_kit_message ();
-               if (message == NULL)
-                       message = gck_message_from_rv (rv);
+
+       modules = p11_kit_modules_load_and_initialize (0);
+       if (modules == NULL) {
                g_set_error (&args->error, GCK_ERROR, (int)CKR_GCK_MODULE_PROBLEM,
-                            _("Couldn't initialize registered PKCS#11 modules: %s"), message);
-               return rv;
+                            _("Couldn't initialize registered PKCS#11 modules: %s"), p11_kit_message ());
+               return CKR_GCK_MODULE_PROBLEM;
        }
 
-       modules = p11_kit_registered_modules ();
        for (funcs = modules; *funcs; ++funcs) {
                module = _gck_module_new_initialized (*funcs);
                args->results = g_list_prepend (args->results, module);
diff --git a/gcr/gcr-library.c b/gcr/gcr-library.c
index a90b23a..c2b4644 100644
--- a/gcr/gcr-library.c
+++ b/gcr/gcr-library.c
@@ -159,19 +159,19 @@ initialize_uris (void)
 
        if (!initialized_uris) {
                /* Ask for the global x-trust-store option */
-               trust_store_uri = p11_kit_registered_option (NULL, "x-trust-store");
+               trust_store_uri = p11_kit_config_option (NULL, "x-trust-store");
                for (l = all_modules; !trust_store_uri && l != NULL; l = g_list_next (l)) {
-                       trust_store_uri = p11_kit_registered_option (gck_module_get_functions (l->data),
-                                                                    "x-trust-store");
+                       trust_store_uri = p11_kit_config_option (gck_module_get_functions (l->data),
+                                                                "x-trust-store");
                }
 
                uris = g_ptr_array_new ();
-               uri = p11_kit_registered_option (NULL, "x-trust-lookup");
+               uri = p11_kit_config_option (NULL, "x-trust-lookup");
                if (uri != NULL)
                        g_ptr_array_add (uris, uri);
                for (l = all_modules; l != NULL; l = g_list_next (l)) {
-                       uri = p11_kit_registered_option (gck_module_get_functions (l->data),
-                                                        "x-trust-lookup");
+                       uri = p11_kit_config_option (gck_module_get_functions (l->data),
+                                                    "x-trust-lookup");
                        if (uri != NULL)
                                g_ptr_array_add (uris, uri);
                }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]