]> granicus.if.org Git - p11-kit/commitdiff
List labels of all tokens in 'p11-kit -l'
authorStef Walter <stefw@collabora.co.uk>
Wed, 6 Jul 2011 14:31:06 +0000 (16:31 +0200)
committerStef Walter <stefw@collabora.co.uk>
Wed, 6 Jul 2011 14:31:06 +0000 (16:31 +0200)
tools/p11-kit.c

index 298c56d46bf141f560a8f0f03ba195a7a1ba3018..3d50955403bbf7ea2be4fe48377926f4e3c43751 100644 (file)
@@ -55,9 +55,29 @@ usage (void)
        exit (2);
 }
 
+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