]> granicus.if.org Git - p11-kit/commitdiff
trust: Propagate library verbosity to module through init_args
authorDaiki Ueno <dueno@redhat.com>
Sun, 23 Dec 2018 13:11:00 +0000 (14:11 +0100)
committerDaiki Ueno <ueno@gnu.org>
Fri, 4 Jan 2019 14:12:04 +0000 (15:12 +0100)
Previously, even when the -v option is used with the 'trust' command,
the messages from p11-kit-trust.so module were suppressed because the
verbosity setting is not propagated to the module.

common/message.c
p11-kit/modules.c
p11-kit/p11-kit.h
trust/enumerate.c
trust/module.c
trust/p11-kit-trust.module

index f9d4f578af77c50b2342d6a2f87732928a1e654a..e439def7a73f397dff3dc284f9697016d0661df5 100644 (file)
@@ -58,7 +58,7 @@
 #include <stdio.h>
 #include <string.h>
 
-static bool print_messages = false;
+bool p11_print_messages = false;
 
 #ifdef HAVE_STRERROR_L
 locale_t p11_message_locale = (locale_t) 0;
@@ -148,7 +148,7 @@ p11_message (const char* msg,
        buffer[length] = 0;
 
        /* If printing is not disabled, just print out */
-       if (print_messages)
+       if (p11_print_messages)
                fprintf (stderr, "p11-kit: %s\n", buffer);
        else
                p11_debug_message (P11_DEBUG_LIB, "message: %s", buffer);
@@ -158,13 +158,13 @@ p11_message (const char* msg,
 void
 p11_message_quiet (void)
 {
-       print_messages = false;
+       p11_print_messages = false;
 }
 
 void
 p11_message_loud (void)
 {
-       print_messages = true;
+       p11_print_messages = true;
 }
 
 const char *
index cfc4daf91d57d20ea1d42a8e94f217f38ae33546..0299edab815190c36382a3d1cc80df005dcd4ae9 100644 (file)
@@ -306,6 +306,7 @@ free_module_unlocked (void *data)
        p11_dict_free (mod->config);
        free (mod->name);
        free (mod->filename);
+       free (mod->init_args.pReserved);
        free (mod);
 }
 
@@ -550,10 +551,12 @@ is_module_enabled_unlocked (const char *name,
 static CK_RV
 take_config_and_load_module_inlock (char **name,
                                     p11_dict **config,
-                                    bool critical)
+                                    bool critical,
+                                    bool verbose)
 {
        const char *filename = NULL;
        const char *remote = NULL;
+       char *init_reserved = NULL;
        CK_RV rv = CKR_OK;
        Module *mod;
 
@@ -591,7 +594,19 @@ take_config_and_load_module_inlock (char **name,
         * 'x-init-reserved' setting in the config. This only works with specific
         * PKCS#11 modules, and is non-standard use of that field.
         */
-       mod->init_args.pReserved = p11_dict_get (*config, "x-init-reserved");
+       init_reserved = p11_dict_get (*config, "x-init-reserved");
+       if (init_reserved) {
+               if (verbose) {
+                       init_reserved = strconcat (init_reserved, " verbose=yes", NULL);
+               } else {
+                       init_reserved = strdup (init_reserved);
+               }
+               if (init_reserved == NULL) {
+                       rv = CKR_HOST_MEMORY;
+                       goto out;
+               }
+       }
+       mod->init_args.pReserved = init_reserved;
 
        /* Take ownership of these variables */
        p11_dict_free (mod->config);
@@ -607,7 +622,7 @@ out:
 }
 
 static CK_RV
-load_registered_modules_unlocked (void)
+load_registered_modules_unlocked (int flags)
 {
        p11_dictiter iter;
        p11_dict *configs;
@@ -617,6 +632,7 @@ load_registered_modules_unlocked (void)
        int mode;
        CK_RV rv;
        bool critical;
+       bool verbose;
 
        if (gl.config)
                return CKR_OK;
@@ -652,7 +668,8 @@ load_registered_modules_unlocked (void)
 
                /* Is this a critical module, should abort loading of others? */
                critical = _p11_conf_parse_boolean (p11_dict_get (config, "critical"), false);
-               rv = take_config_and_load_module_inlock (&name, &config, critical);
+               verbose = (flags & P11_KIT_MODULE_VERBOSE) != 0;
+               rv = take_config_and_load_module_inlock (&name, &config, critical, verbose);
 
                /*
                 * These variables will be cleared if ownership is transeferred
@@ -858,7 +875,7 @@ initialize_registered_inlock_reentrant (void)
        if (rv != CKR_OK)
                return rv;
 
-       rv = load_registered_modules_unlocked ();
+       rv = load_registered_modules_unlocked (0);
        if (rv == CKR_OK) {
                p11_dict_iterate (gl.unmanaged_by_funcs, &iter);
                while (rv == CKR_OK && p11_dict_next (&iter, NULL, (void **)&mod)) {
@@ -1955,7 +1972,7 @@ p11_modules_load_inlock_reentrant (int flags,
        if (rv != CKR_OK)
                return rv;
 
-       rv = load_registered_modules_unlocked ();
+       rv = load_registered_modules_unlocked (flags);
        if (rv != CKR_OK)
                return rv;
 
index abf618b4ddfd37a62744c2ff7c51e76ffb63135c..cc89595e1a2ed9291831b77fdbb915bc29a20ba0 100644 (file)
@@ -57,7 +57,8 @@ enum {
        P11_KIT_MODULE_UNMANAGED = 1 << 0,
        P11_KIT_MODULE_CRITICAL = 1 << 1,
        P11_KIT_MODULE_TRUSTED = 1 << 2,
-       P11_KIT_MODULE_MASK = (1 << 3) - 1
+       P11_KIT_MODULE_VERBOSE = 1 << 3,
+       P11_KIT_MODULE_MASK = (1 << 4) - 1
 };
 
 typedef void        (* p11_kit_destroyer)                   (void *data);
index e197765fd0777fb161b0048051ef63e478262b65..0cef08922cf970f6df0fe0a0975e89a40a778762 100644 (file)
@@ -674,6 +674,8 @@ p11_enumerate_opt_purpose (p11_enumerate *ex,
        return true;
 }
 
+extern bool p11_print_messages;
+
 bool
 p11_enumerate_ready (p11_enumerate *ex,
                      const char *def_filter)
@@ -687,8 +689,13 @@ p11_enumerate_ready (p11_enumerate *ex,
         * We only "believe" the CKA_TRUSTED and CKA_X_DISTRUSTED attributes
         * we get from modules explicitly marked as containing trust-policy.
         */
-       if (!ex->modules)
-               ex->modules = p11_kit_modules_load_and_initialize (P11_KIT_MODULE_TRUSTED);
+       if (!ex->modules) {
+               int flags = P11_KIT_MODULE_TRUSTED;
+               if (p11_print_messages)
+                       flags |= P11_KIT_MODULE_VERBOSE;
+
+               ex->modules = p11_kit_modules_load_and_initialize (flags);
+       }
        if (!ex->modules)
                return false;
        if (ex->modules[0] == NULL)
index 24cda876c3b0bc6af4c7b97fe108451d8a679f57..0c16a39ea5809c196fa7cf5d374a16867ab8aacf 100644 (file)
@@ -287,6 +287,11 @@ parse_argument (char *arg,
                free (gl.paths);
                gl.paths = value ? strdup (value) : NULL;
 
+       } else if (strcmp (arg, "verbose") == 0) {
+               if (strcmp (value, "yes") == 0)
+                       p11_message_loud ();
+               else if (strcmp (value, "no") == 0)
+                       p11_message_quiet ();
        } else {
                p11_message ("unrecognized module argument: %s", arg);
        }
index 72122c39aedad68be89368103178879d5e77ddf0..a2a33066cc97576790885d0dce6e5d5be42b7877 100644 (file)
@@ -18,3 +18,7 @@ x-trust-lookup: pkcs11:library-description=PKCS%2311%20Kit%20Trust%20Module
 
 # Prevent this module being loaded by the proxy module
 disable-in: p11-kit-proxy
+
+# This will be overwritten by appending "verbose=yes", if the trust
+# command is called with the -v option.
+x-init-reserved: