Bugzilla – Attachment 891 Details for
Bug 7253
ThinLinc Client does not exit when smart card reader is disconnected
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
pkcs11 test program
test.c (text/x-csrc), 2.77 KB, created by
Henrik Andersson
on 2018-10-02 09:43:44 CEST
(
hide
)
Description:
pkcs11 test program
Filename:
MIME Type:
Creator:
Henrik Andersson
Created:
2018-10-02 09:43:44 CEST
Size:
2.77 KB
patch
obsolete
>#include <stdio.h> >#include <memory.h> >#include <dlfcn.h> >#include <stdlib.h> > >#include "pkcs11.h" > >typedef struct pkcs11_t >{ > CK_FUNCTION_LIST_PTR desc; > void *library; >} pkcs11_t; > > >static int pkcs11_init(pkcs11_t *pkcs11, const char *library) >{ > CK_RV rv; > CK_C_GetFunctionList func; > > memset(pkcs11, 0, sizeof(pkcs11_t)); > > if (!library) > { > fprintf(stderr, "Library == NULL\n"); > return 1; > } > > /* open library */ > pkcs11->library = dlopen(library, RTLD_LAZY); > if (!pkcs11->library) > { > fprintf(stderr, "Failed to open module: %s\n", dlerror()); > return 1; > } > > /* get function list */ > func = (CK_C_GetFunctionList)dlsym(pkcs11->library, "C_GetFunctionList"); > if (!func) > { > fprintf(stderr, "%s\n", dlerror()); > dlclose(pkcs11->library); > return 1; > } > > rv = func(&pkcs11->desc); > if (rv != CKR_OK) > { > fprintf(stderr, "Failed to initialize pkcs11 module\n"); > dlclose(pkcs11->library); > return 1; > } > > return 0; >} > >static int pkcs11_deinit(pkcs11_t *pkcs11) >{ > dlclose(pkcs11->library); >} > >int main(int argc, char **argv) >{ > pkcs11_t pkcs11; > CK_RV rv; > CK_ULONG i, slot_cnt; > CK_SLOT_ID_PTR slots; > CK_SLOT_INFO slot_info; > > if (pkcs11_init(&pkcs11, argv[1]) != 0) > exit(1); > > rv = pkcs11.desc->C_Initialize(NULL_PTR); > if (rv != CKR_OK) > { > fprintf(stderr, "C_Initialize() failed\n"); > pkcs11_deinit(&pkcs11); > exit(1); > } > > slots = NULL; > slot_cnt = 0; > > > while(1) > { > > /* Get number of slots available */ > rv = pkcs11.desc->C_GetSlotList(CK_TRUE, NULL, &slot_cnt); > if (rv != CKR_OK) > { > fprintf(stderr,"C_GetSlotList() failed to get count\n"); > pkcs11_deinit(&pkcs11); > exit(1); > } > > fprintf(stdout, "%lu slots available\n", slot_cnt); > > /* Get slots */ > if (slots) > free(slots); > > slots = malloc(sizeof(CK_SLOT_ID) * slot_cnt); > rv = pkcs11.desc->C_GetSlotList(CK_TRUE, slots, &slot_cnt); > if (rv != CKR_OK) > { > fprintf(stderr,"C_GetSlotList() failed\n"); > pkcs11_deinit(&pkcs11); > exit(1); > } > > sleep(5); > > fprintf(stderr, "Checking for events\n"); > > for (i = 0; i < slot_cnt; i++) > { > rv = pkcs11.desc->C_GetSlotInfo(slots[i], &slot_info); > if (rv != CKR_OK) > { > fprintf(stderr, "Slot is not available\n"); > continue; > } > > fprintf(stderr, "Slot %lu: %.32s, flags 0x%x\n", slots[i], slot_info.slotDescription, slot_info.flags); > > rv = pkcs11.desc->C_WaitForSlotEvent(CKF_DONT_BLOCK, &slots[i], NULL_PTR); > switch(rv) > { > case CKR_OK: > fprintf(stderr, " !! Event on slot %d !!\n", i); > break; > case CKR_NO_EVENT: > fprintf(stderr, " No event on slot %d\n", i); > break; > default: > fprintf(stderr, "C_WaitForSlotEvent() on slot %d failed result %x\n", i, rv); > break; > } > > } > } > > exit(0); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 7253
:
890
| 891