Changeset 3505

Show
Ignore:
Timestamp:
04/29/08 16:44:49 (7 months ago)
Author:
alonbl
Message:

pcsc_lock() should not open its own transaction if had an error

This casued upper layer to got the impression that the card was not removed.
The PKCS#11 code did not drop credentials and just used cached PIN.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/alonbl/pnp/src/libopensc/reader-pcsc.c

    r3494 r3505  
    645645        rv = priv->gpriv->SCardBeginTransaction(pslot->pcsc_card); 
    646646 
    647         if ((unsigned int)rv == SCARD_E_INVALID_HANDLE || (unsigned int)rv == SCARD_E_READER_UNAVAILABLE) { 
    648                 rv = pcsc_connect(reader, slot); 
    649                 if (rv != SCARD_S_SUCCESS) { 
    650                         PCSC_ERROR(reader->ctx, "SCardConnect failed", rv); 
     647        switch (rv) { 
     648                case SCARD_E_INVALID_HANDLE: 
     649                case SCARD_E_READER_UNAVAILABLE: 
     650                        rv = pcsc_connect(reader, slot); 
     651                        if (rv != SCARD_S_SUCCESS) { 
     652                                PCSC_ERROR(reader->ctx, "SCardConnect failed", rv); 
     653                                return pcsc_ret_to_error(rv); 
     654                        } 
     655                        /* return failure so that upper layers will be notified and try to lock again */ 
     656                        return SC_ERROR_READER_REATTACHED; 
     657                case SCARD_W_RESET_CARD: 
     658                        /* try to reconnect if the card was reset by some other application */ 
     659                        rv = pcsc_reconnect(reader, slot, 0); 
     660                        if (rv != SCARD_S_SUCCESS) { 
     661                                PCSC_ERROR(reader->ctx, "SCardReconnect failed", rv); 
     662                                return pcsc_ret_to_error(rv); 
     663                        } 
     664                        /* return failure so that upper layers will be notified and try to lock again */ 
     665                        return SC_ERROR_CARD_RESET; 
     666                case SCARD_S_SUCCESS: 
     667                        pslot->locked = 1; 
     668                        return SC_SUCCESS; 
     669                default: 
     670                        PCSC_ERROR(reader->ctx, "SCardBeginTransaction failed", rv); 
    651671                        return pcsc_ret_to_error(rv); 
    652                 } 
    653                 /* Now try to begin a new transaction after we reconnected and we fail if 
    654                  some other program was faster to lock the reader */ 
    655                 rv = priv->gpriv->SCardBeginTransaction(pslot->pcsc_card); 
    656         } 
    657  
    658         if ((unsigned int)rv == SCARD_W_RESET_CARD) { 
    659                 /* try to reconnect if the card was reset by some other application */ 
    660                 rv = pcsc_reconnect(reader, slot, 0); 
    661                 if (rv != SCARD_S_SUCCESS) { 
    662                         PCSC_ERROR(reader->ctx, "SCardReconnect failed", rv); 
    663                         return pcsc_ret_to_error(rv); 
    664                 } 
    665                 /* Now try to begin a new transaction after we reconnected and we fail if 
    666                  some other program was faster to lock the reader */ 
    667                 rv = priv->gpriv->SCardBeginTransaction(pslot->pcsc_card); 
    668         } 
    669  
    670         if (rv != SCARD_S_SUCCESS) { 
    671                 PCSC_ERROR(reader->ctx, "SCardBeginTransaction failed", rv); 
    672                 return pcsc_ret_to_error(rv); 
    673         } 
    674  
    675         pslot->locked = 1; 
    676          
    677         return SC_SUCCESS; 
     672        } 
    678673} 
    679674