From b73f4ef126bdead47262e29e47d159a89984d65f Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Tue, 19 Feb 2013 14:05:34 +0100 Subject: Add the log-calls module config option If 'log-calls = yes' is set then all the PKCS#11 modules are logged to stderr. --- p11-kit/modules.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'p11-kit/modules.c') diff --git a/p11-kit/modules.c b/p11-kit/modules.c index b124e0e..33ae3b9 100644 --- a/p11-kit/modules.c +++ b/p11-kit/modules.c @@ -43,6 +43,7 @@ #include "debug.h" #include "dict.h" #include "library.h" +#include "log.h" #include "message.h" #include "modules.h" #include "path.h" @@ -1662,16 +1663,13 @@ managed_create_inlock (Module *mod) static bool lookup_managed_option (Module *mod, + bool supported, const char *option, bool def_value) { const char *string; - bool supported; bool value; - /* Whether managed stuff is supported or not */ - supported = p11_virtual_can_wrap (); - string = module_get_option_inlock (NULL, option); if (!string) string = module_get_option_inlock (mod, option); @@ -1684,13 +1682,21 @@ lookup_managed_option (Module *mod, value = _p11_conf_parse_boolean (string, def_value); if (!supported && value != supported) { - /* - * This is because libffi dependency was not built. The libffi dependency - * is highly recommended and building without it results in a large loss - * of functionality. - */ - p11_message ("the '%s' option for module '%s' is not supported on this system", - option, mod->name); + if (!p11_virtual_can_wrap ()) { + /* + * This is because libffi dependency was not built. The libffi dependency + * is highly recommended and building without it results in a large loss + * of functionality. + */ + p11_message ("the '%s' option for module '%s' is not supported on this system", + option, mod->name); + } else { + /* + * This is because the module is running in unmanaged mode, so turn off the + */ + p11_message ("the '%s' option for module '%s' is only supported for managed modules", + option, mod->name); + } return false; } @@ -1755,19 +1761,29 @@ prepare_module_inlock_reentrant (Module *mod, p11_destroyer destroyer; p11_virtual *virt; bool is_managed; + bool with_log; assert (module != NULL); - if (flags & P11_KIT_MODULE_UNMANAGED) + if (flags & P11_KIT_MODULE_UNMANAGED) { is_managed = false; - else - is_managed = lookup_managed_option (mod, "managed", true); + with_log = false; + } else { + is_managed = lookup_managed_option (mod, p11_virtual_can_wrap (), "managed", true); + with_log = lookup_managed_option (mod, is_managed, "log-calls", false); + } if (is_managed) { virt = managed_create_inlock (mod); return_val_if_fail (virt != NULL, CKR_HOST_MEMORY); destroyer = managed_free_inlock; + /* Add the logger if configured */ + if (p11_log_force || with_log) { + virt = p11_log_subclass (virt, destroyer); + destroyer = p11_log_release; + } + *module = p11_virtual_wrap (virt, destroyer); return_val_if_fail (*module != NULL, CKR_GENERAL_ERROR); -- cgit v1.2.3