summaryrefslogtreecommitdiff
path: root/p11-kit/modules.c
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2013-03-07 18:53:50 +0100
committerStef Walter <stefw@gnome.org>2013-03-15 17:29:23 +0100
commit8fd55c8089c90b52f00e4ffad572d1b9da72e6ba (patch)
tree3b381718ede4745ef2f9e2f6cbca1283b0a2fe58 /p11-kit/modules.c
parent0e75a5ba8261955d4d75a38a528f79ff4edd5c21 (diff)
downloadp11-kit-8fd55c8089c90b52f00e4ffad572d1b9da72e6ba.tar.gz
p11-kit: New priority option and change trust-policy option
* Sort loaded modules appropriately using the 'priority' option. This allows us to have a predictable order for callers, when callers iterate through modules. * Modules default to having an 'priority' option of '0'. * If modules have the same order value, then sort by name. * The above assumes the role of ordering trust-policy sources. * Change the trust-policy option to a boolean * Some of this code will be rearranged when the managed branch is merged. https://bugs.freedesktop.org/show_bug.cgi?id=61978
Diffstat (limited to 'p11-kit/modules.c')
-rw-r--r--p11-kit/modules.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/p11-kit/modules.c b/p11-kit/modules.c
index eaa1564..7648167 100644
--- a/p11-kit/modules.c
+++ b/p11-kit/modules.c
@@ -896,6 +896,51 @@ p11_kit_finalize_registered (void)
return rv;
}
+static int
+compar_priority (const void *one,
+ const void *two)
+{
+ CK_FUNCTION_LIST_PTR f1 = *((CK_FUNCTION_LIST_PTR *)one);
+ CK_FUNCTION_LIST_PTR f2 = *((CK_FUNCTION_LIST_PTR *)two);
+ Module *m1, *m2;
+ const char *v1, *v2;
+ int o1, o2;
+
+ m1 = p11_dict_get (gl.modules, f1);
+ m2 = p11_dict_get (gl.modules, f2);
+ assert (m1 != NULL && m2 != NULL);
+
+ v1 = p11_dict_get (m1->config, "priority");
+ v2 = p11_dict_get (m2->config, "priority");
+
+ o1 = atoi (v1 ? v1 : "0");
+ o2 = atoi (v2 ? v2 : "0");
+
+ /* Priority is in descending order, highest first */
+ if (o1 != o2)
+ return o1 > o2 ? -1 : 1;
+
+ /*
+ * Otherwise use the names alphabetically in ascending order. This
+ * is really just to provide consistency between various loads of
+ * the configuration.
+ */
+ if (m1->name == m2->name)
+ return 0;
+ if (!m1->name)
+ return -1;
+ if (!m2->name)
+ return 1;
+ return strcmp (m1->name, m2->name);
+}
+
+static void
+sort_modules_by_priority (CK_FUNCTION_LIST_PTR *modules,
+ int count)
+{
+ qsort (modules, count, sizeof (CK_FUNCTION_LIST_PTR), compar_priority);
+}
+
CK_FUNCTION_LIST_PTR_PTR
_p11_kit_registered_modules_unlocked (void)
{
@@ -927,6 +972,8 @@ _p11_kit_registered_modules_unlocked (void)
result[i++] = mod->funcs;
}
}
+
+ sort_modules_by_priority (result, i);
}
return result;