summaryrefslogtreecommitdiff
path: root/p11-kit
diff options
context:
space:
mode:
authorStef Walter <stefw@collabora.co.uk>2011-08-30 21:17:41 +0200
committerStef Walter <stefw@collabora.co.uk>2011-08-30 21:17:41 +0200
commit21b64c68e6a5ffcae50f3561f6dec6ee943a006f (patch)
tree1955ce851df90b88ec163acf30a37d75fe0a2484 /p11-kit
parent25512ca5a03d723a84d6de67a7036188d08ec21b (diff)
Add 'critical' setting for modules
* When a module has critical set to 'yes', and that module fails to init then it aborts the entire init process. * Defaults to 'no'
Diffstat (limited to 'p11-kit')
-rw-r--r--p11-kit/conf.c18
-rw-r--r--p11-kit/conf.h3
-rw-r--r--p11-kit/modules.c7
3 files changed, 27 insertions, 1 deletions
diff --git a/p11-kit/conf.c b/p11-kit/conf.c
index 55e0268..1e2d880 100644
--- a/p11-kit/conf.c
+++ b/p11-kit/conf.c
@@ -608,3 +608,21 @@ _p11_conf_load_modules (int mode, const char *system_dir, const char *user_dir)
return configs;
}
+
+int
+_p11_conf_parse_boolean (const char *string,
+ int default_value)
+{
+ if (!string)
+ return default_value;
+
+ if (strcmp (string, "yes") == 0) {
+ return 1;
+ } else if (strcmp (string, "no") == 0) {
+ return 0;
+ } else {
+ _p11_message ("invalid setting '%s' defaulting to '%s'",
+ default_value ? "yes" : "no");
+ return default_value;
+ }
+}
diff --git a/p11-kit/conf.h b/p11-kit/conf.h
index dccaebf..30f078d 100644
--- a/p11-kit/conf.h
+++ b/p11-kit/conf.h
@@ -66,4 +66,7 @@ hashmap * _p11_conf_load_globals (const char *system_conf, const cha
hashmap * _p11_conf_load_modules (int user_mode, const char *system_dir,
const char *user_dir);
+int _p11_conf_parse_boolean (const char *string,
+ int default_value);
+
#endif /* __CONF_H__ */
diff --git a/p11-kit/modules.c b/p11-kit/modules.c
index d5dae32..33101fa 100644
--- a/p11-kit/modules.c
+++ b/p11-kit/modules.c
@@ -389,6 +389,7 @@ load_registered_modules_unlocked (void)
hashmap *config;
int mode;
CK_RV rv;
+ int critical;
if (gl.config)
return CKR_OK;
@@ -419,6 +420,9 @@ load_registered_modules_unlocked (void)
if (!hash_steal (configs, key, (void**)&name, (void**)&config))
assert (0 && "not reached");
+ /* Is this a critical module, should abort loading of others? */
+ critical = _p11_conf_parse_boolean (hash_get (config, "critical"), 0);
+
rv = take_config_and_load_module_unlocked (&name, &config);
/*
@@ -428,7 +432,8 @@ load_registered_modules_unlocked (void)
free (name);
hash_free (config);
- if (rv != CKR_OK) {
+ if (critical && rv != CKR_OK) {
+ _p11_message ("aborting initializationg because module '%s' was marked as critical");
hash_free (configs);
return rv;
}