summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stefw@collabora.co.uk>2011-07-06 16:31:06 +0200
committerStef Walter <stefw@collabora.co.uk>2011-07-06 16:31:06 +0200
commit98ba6f9ffb95c5473e5e32d296956e91c4fc2715 (patch)
treedf627292cb032dee3037c9eece78ca600393a159
parent883b3ee76c686d14bbc1f20b0805d733a0c227ad (diff)
downloadp11-kit-98ba6f9ffb95c5473e5e32d296956e91c4fc2715.tar.gz
List labels of all tokens in 'p11-kit -l'
-rw-r--r--tools/p11-kit.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/tools/p11-kit.c b/tools/p11-kit.c
index 298c56d..3d50955 100644
--- a/tools/p11-kit.c
+++ b/tools/p11-kit.c
@@ -56,8 +56,28 @@ usage (void)
}
static void
+print_token_info (CK_FUNCTION_LIST_PTR module, CK_SLOT_ID slot_id)
+{
+ CK_TOKEN_INFO info;
+ char *value;
+ CK_RV rv;
+
+ rv = (module->C_GetTokenInfo) (slot_id, &info);
+ if (rv != CKR_OK) {
+ warnx ("couldn't load module info: %s", p11_kit_strerror (rv));
+ return;
+ }
+
+ value = p11_kit_space_strdup (info.label, sizeof (info.label));
+ printf (" token: %s\n", value);
+ free (value);
+}
+
+static void
print_module_info (CK_FUNCTION_LIST_PTR module)
{
+ CK_SLOT_ID slot_list[256];
+ CK_ULONG i, count;
CK_INFO info;
char *value;
CK_RV rv;
@@ -70,13 +90,23 @@ print_module_info (CK_FUNCTION_LIST_PTR module)
value = p11_kit_space_strdup (info.libraryDescription,
sizeof (info.libraryDescription));
- printf ("\tlibrary-description: %s\n", value);
+ printf (" library-description: %s\n", value);
free (value);
value = p11_kit_space_strdup (info.manufacturerID,
sizeof (info.manufacturerID));
- printf ("\tlibrary-manufacturer: %s\n", value);
+ printf (" library-manufacturer: %s\n", value);
free (value);
+
+ count = sizeof (slot_list) / sizeof (slot_list[0]);
+ rv = (module->C_GetSlotList) (CK_TRUE, slot_list, &count);
+ if (rv != CKR_OK) {
+ warnx ("couldn't load module info: %s", p11_kit_strerror (rv));
+ return;
+ }
+
+ for (i = 0; i < count; i++)
+ print_token_info (module, slot_list[i]);
}
static int