]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
the deprecated_config_file from 2.12.x was incorporated.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Mon, 1 Aug 2011 18:39:18 +0000 (20:39 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 2 Aug 2011 18:49:08 +0000 (20:49 +0200)
NEWS
lib/includes/gnutls/pkcs11.h
lib/pkcs11.c

diff --git a/NEWS b/NEWS
index eddafc46700cb8c64feb059085d5a69efe44a197..639fb20b71f31494bb5cc5d72cc8f5dfc312ac8e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,9 @@ See the end for copying conditions.
 
 * Version 3.0.1 (unreleased)
 
+** libgnutls: The config file at gnutls_pkcs11_init()
+is being read if provided.
+
 ** libgnutls: Verify that a certificate liste specified
 using gnutls_certificate_set_x509_key*(), is sorted
 according to TLS specification (from subject to issuer).
index 420674962c5c0e798db0f483a55ef046d3f3153c..b08d9bf630dd4eeddafb9a9d0b041b9f7cce3ea4 100644 (file)
@@ -57,7 +57,7 @@ typedef struct gnutls_pkcs11_obj_st *gnutls_pkcs11_obj_t;
  * load = /lib/yyy-pkcs11.so
  */
 
-int gnutls_pkcs11_init (unsigned int flags, void *unused);
+int gnutls_pkcs11_init (unsigned int flags, const char *deprecated_config_file);
 void gnutls_pkcs11_deinit (void);
 void gnutls_pkcs11_set_token_function (gnutls_pkcs11_token_callback_t fn,
                                        void *userdata);
index a547b2f549b1e30ebeafa8fb6711217f84450ee3..6e3df7d853f10ec8041130a2c4c5468fb439e31a 100644 (file)
@@ -417,13 +417,15 @@ static int init = 0;
 
 /* tries to load modules from /etc/gnutls/pkcs11.conf if it exists
  */
-static void _pkcs11_compat_init(void)
+static void _pkcs11_compat_init(const char* configfile)
 {
 FILE *fp;
 int ret;
 char line[512];
 const char *library;
-const char* configfile = "/etc/gnutls/pkcs11.conf";
+
+  if (configfile == NULL)
+    configfile = "/etc/gnutls/pkcs11.conf";
 
   fp = fopen (configfile, "r");
   if (fp == NULL)
@@ -461,10 +463,46 @@ const char* configfile = "/etc/gnutls/pkcs11.conf";
   return;
 }
 
+static int
+initialize_automatic_p11_kit (void)
+{
+  struct ck_function_list **modules;
+  const char *name;
+  ck_rv_t rv;
+  int i, ret;
+
+  rv = p11_kit_initialize_registered ();
+  if (rv != CKR_OK)
+    {
+      gnutls_assert ();
+      _gnutls_debug_log ("Cannot initialize registered module: %s\n",
+                         p11_kit_strerror (rv));
+      return GNUTLS_E_INTERNAL_ERROR;
+    }
+
+  initialized_registered = 1;
+
+  modules = p11_kit_registered_modules ();
+  for (i = 0; modules[i] != NULL; i++)
+    {
+      name = p11_kit_registered_module_to_name (modules[i]);
+      ret = pkcs11_add_module (name, modules[i]);
+      if (ret != 0)
+        {
+          gnutls_assert ();
+          _gnutls_debug_log ("Cannot add registered module: %s\n", name);
+        }
+    }
+
+  free (modules);
+  return 0;
+}
+
 /**
  * gnutls_pkcs11_init:
  * @flags: %GNUTLS_PKCS11_FLAG_MANUAL or %GNUTLS_PKCS11_FLAG_AUTO
- * @unused: unused must be set to NULL
+ * @deprecated_config_file: either NULL or the location of a deprecated
+ *     configuration file
  *
  * This function will initialize the PKCS 11 subsystem in gnutls. It will
  * read configuration files if %GNUTLS_PKCS11_FLAG_AUTO is used or allow
@@ -479,12 +517,9 @@ const char* configfile = "/etc/gnutls/pkcs11.conf";
  *   negative error value.
  **/
 int
-gnutls_pkcs11_init (unsigned int flags, void *unused)
+gnutls_pkcs11_init (unsigned int flags, const char *deprecated_config_file)
 {
-  struct ck_function_list **modules;
-  const char *name;
-  ck_rv_t rv;
-  int i, ret;
+  int ret = 0;
 
   if (init != 0)
     {
@@ -497,33 +532,14 @@ gnutls_pkcs11_init (unsigned int flags, void *unused)
     return 0;
   else if (flags == GNUTLS_PKCS11_FLAG_AUTO)
     {
-      rv = p11_kit_initialize_registered ();
-      if (rv != CKR_OK)
-        {
-          gnutls_assert ();
-          _gnutls_debug_log ("Cannot initialize registered module: %s\n",
-                             p11_kit_strerror (rv));
-          return GNUTLS_E_INTERNAL_ERROR;
-        }
+      if (deprecated_config_file == NULL)
+        ret = initialize_automatic_p11_kit ();
 
-      initialized_registered = 1;
+      _pkcs11_compat_init(deprecated_config_file);
 
-      modules = p11_kit_registered_modules ();
-      for (i = 0; modules[i] != NULL; i++)
-        {
-          name = p11_kit_registered_module_to_name (modules[i]);
-          ret = pkcs11_add_module (name, modules[i]);
-          if (ret != 0)
-            {
-              gnutls_assert ();
-              _gnutls_debug_log ("Cannot add registered module: %s\n", name);
-            }
-        }
-      free (modules);
-
-      _pkcs11_compat_init();
+      return ret;
     }
-
+  
   return 0;
 }