Ticket #14: pam_pkcs11-0.5.3-daemon-init.patch

File pam_pkcs11-0.5.3-daemon-init.patch, 2.8 KB (added by alon.barlev@…, 4 years ago)

A patch to C_Initialize at proper place

  • src/common/pkcs11.c

    diff -urNp pam_pkcs11-0.5.3/src/common/pkcs11.c pam_pkcs11-0.5.3.new/src/common/pkcs11.c
    old new  
    8282 
    8383  /* initialise the module */ 
    8484  rv = h->fl->C_Initialize(NULL); 
    85   if (rv != CKR_OK) { 
     85  if (rv == CKR_OK) 
     86    h->should_finalize = 1; 
     87  else if (rv != CKR_CRYPTOKI_ALREADY_INITIALIZED) { 
    8688    set_error("C_Initialize() failed: %x", rv); 
    8789    return -1; 
    8890  } 
     
    170172{ 
    171173  /* finalise pkcs #11 module */ 
    172174  if (h->fl != NULL) 
    173     h->fl->C_Finalize(NULL); 
     175    if (h->should_finalize) 
     176            h->fl->C_Finalize(NULL); 
    174177  /* unload the module */ 
    175178  if (h->module_handle != NULL) 
    176179    dlclose(h->module_handle); 
  • src/common/pkcs11.h

    diff -urNp pam_pkcs11-0.5.3/src/common/pkcs11.h pam_pkcs11-0.5.3.new/src/common/pkcs11.h
    old new  
    136136typedef struct { 
    137137  void *module_handle; 
    138138  CK_FUNCTION_LIST_PTR fl; 
     139  int should_finalize; 
    139140  slot_t *slots;  
    140141  CK_ULONG slot_count; 
    141142  CK_SESSION_HANDLE session; 
  • src/tools/pkcs11_eventmgr.c

    diff -urNp pam_pkcs11-0.5.3/src/tools/pkcs11_eventmgr.c pam_pkcs11-0.5.3.new/src/tools/pkcs11_eventmgr.c
    old new  
    283283        return 1; 
    284284    } 
    285285 
    286     /* open pkcs11 sesion */ 
    287     DBG("initialising pkcs #11 module..."); 
    288     rv = ph.fl->C_Initialize(NULL); 
    289     if (rv != 0) { 
    290         release_pkcs11_module(&ph); 
    291         DBG1("C_Initialize() failed: %d", rv); 
    292         return 1; 
    293     } 
    294  
    295286    /* put my self into background if flag is set */ 
    296287    if (daemonize) { 
    297288        DBG("Going to be daemon..."); 
     
    303294        } 
    304295    } 
    305296 
     297    /* open pkcs11 sesion */ 
     298    DBG("initialising pkcs #11 module..."); 
     299    rv = ph.fl->C_Initialize(NULL); 
     300    if (rv != 0) { 
     301        release_pkcs11_module(&ph); 
     302        if (ctx) scconf_free(ctx); 
     303        DBG1("C_Initialize() failed: %d", rv); 
     304        return 1; 
     305    } 
     306    ph.should_finalize = 1; 
     307 
    306308    /*  
    307309     * Wait endlessly for all events in the list of readers 
    308310     * We only stop in case of an error 
     
    324326           new_state = get_a_token(); 
    325327           if (new_state == CARD_ERROR) { 
    326328                DBG("Error trying to get a token"); 
    327                 break; 
     329                rv = ph.fl->C_Finalize(NULL); 
     330                rv = ph.fl->C_Initialize(NULL); 
     331                continue; 
    328332           } 
    329333           if (old_state == new_state ) { /* state unchanged */ 
    330334                /* on card not present, increase and check expire time */