YKPIV: Make sure that context is established only if it is invalid.
This commit is contained in:
+10
-8
@@ -103,7 +103,7 @@ ykpiv_rc ykpiv_init(ykpiv_state **state, int verbose) {
|
|||||||
}
|
}
|
||||||
memset(s, 0, sizeof(ykpiv_state));
|
memset(s, 0, sizeof(ykpiv_state));
|
||||||
s->verbose = verbose;
|
s->verbose = verbose;
|
||||||
s->context = -1;
|
s->context = SCARD_E_INVALID_HANDLE;
|
||||||
*state = s;
|
*state = s;
|
||||||
return YKPIV_OK;
|
return YKPIV_OK;
|
||||||
}
|
}
|
||||||
@@ -120,9 +120,9 @@ ykpiv_rc ykpiv_disconnect(ykpiv_state *state) {
|
|||||||
state->card = 0;
|
state->card = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(state->context) {
|
if(SCardIsValidContext(state->context) == SCARD_S_SUCCESS) {
|
||||||
SCardReleaseContext(state->context);
|
SCardReleaseContext(state->context);
|
||||||
state->context = 0;
|
state->context = SCARD_E_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return YKPIV_OK;
|
return YKPIV_OK;
|
||||||
@@ -205,12 +205,14 @@ ykpiv_rc ykpiv_list_readers(ykpiv_state *state, char *readers, size_t *len) {
|
|||||||
unsigned long num_readers = 0;
|
unsigned long num_readers = 0;
|
||||||
long rc;
|
long rc;
|
||||||
|
|
||||||
rc = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &state->context);
|
if(SCardIsValidContext(state->context) != SCARD_S_SUCCESS) {
|
||||||
if (rc != SCARD_S_SUCCESS) {
|
rc = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &state->context);
|
||||||
if(state->verbose) {
|
if (rc != SCARD_S_SUCCESS) {
|
||||||
fprintf (stderr, "error: SCardEstablishContext failed, rc=%08lx\n", rc);
|
if(state->verbose) {
|
||||||
|
fprintf (stderr, "error: SCardEstablishContext failed, rc=%08lx\n", rc);
|
||||||
|
}
|
||||||
|
return YKPIV_PCSC_ERROR;
|
||||||
}
|
}
|
||||||
return YKPIV_PCSC_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = SCardListReaders(state->context, NULL, NULL, &num_readers);
|
rc = SCardListReaders(state->context, NULL, NULL, &num_readers);
|
||||||
|
|||||||
Reference in New Issue
Block a user