Changeset 269


Ignore:
Timestamp:
05/15/07 07:18:24 (5 years ago)
Author:
ludovic.rousseau
Message:

C_Initalize should be called after each fork

The pkcs11_eventmgr first C_Initialize then becomes a daemon... The
PKCS#11 standard states that after fork the user must call C_Initialize
again, in order to allow proper library initialization at new process.

Also, don't quit on major errors... try to reinitialize.

Closes ticket #14. Thanks to Alon Bar-Lev for the patch

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/common/pkcs11_lib.c

    r255 r269  
    618618  void *module_handle; 
    619619  CK_FUNCTION_LIST_PTR fl; 
     620  int should_finalize; 
    620621  slot_t *slots; 
    621622  CK_ULONG slot_count; 
     
    715716  if (flag) rv = h->fl->C_Initialize((CK_VOID_PTR) &initArgs); 
    716717  else      rv = h->fl->C_Initialize(NULL); 
    717   if (rv != CKR_OK) { 
     718  if (rv == CKR_OK) 
     719    h->should_finalize = 1; 
     720  else if (rv != CKR_CRYPTOKI_ALREADY_INITIALIZED) { 
    718721    set_error("C_Initialize() failed: %x", rv); 
    719722    return -1; 
     
    804807  /* finalise pkcs #11 module */ 
    805808  if (h->fl != NULL) 
    806     h->fl->C_Finalize(NULL); 
     809    if (h->should_finalize) 
     810      h->fl->C_Finalize(NULL); 
    807811  /* unload the module */ 
    808812  if (h->module_handle != NULL) 
  • trunk/src/tools/pkcs11_eventmgr.c

    r243 r269  
    7474  void *module_handle; 
    7575  CK_FUNCTION_LIST_PTR fl; 
     76  int should_finalize; 
    7677  slot_t *slots; 
    7778  CK_ULONG slot_count; 
     
    510511    } 
    511512 
    512     /* open pkcs11 sesion */ 
    513     DBG("initialising pkcs #11 module..."); 
    514     rv = ph->fl->C_Initialize(NULL); 
    515     if (rv != 0) { 
    516         release_pkcs11_module(ph); 
    517         DBG1("C_Initialize() failed: %d", rv); 
    518         return 1; 
    519     } 
    520  
    521513    /* put my self into background if flag is set */ 
    522514    if (daemonize) { 
     
    529521        } 
    530522    } 
     523 
     524    /* open pkcs11 sesion */ 
     525    DBG("initialising pkcs #11 module..."); 
     526    rv = ph->fl->C_Initialize(NULL); 
     527    if (rv != 0) { 
     528        release_pkcs11_module(ph); 
     529        if (ctx) 
     530          scconf_free(ctx); 
     531        DBG1("C_Initialize() failed: %d", rv); 
     532        return 1; 
     533    } 
     534    ph->should_finalize = 1; 
    531535 
    532536    /*  
     
    551555           if (new_state == CARD_ERROR) { 
    552556                DBG("Error trying to get a token"); 
     557                rv = ph->fl->C_Finalize(NULL); 
     558                rv = ph->fl->C_Initialize(NULL); 
    553559                break; 
    554560           } 
Note: See TracChangeset for help on using the changeset viewer.