continue looping over the readers if one fails during setup
also continues if a reader fails when selecting (no applet)
This commit is contained in:
+26
-25
@@ -165,39 +165,26 @@ ykpiv_rc ykpiv_connect(ykpiv_state *state, const char *wanted) {
|
||||
return YKPIV_PCSC_ERROR;
|
||||
}
|
||||
|
||||
reader_ptr = reader_buf;
|
||||
for(reader_ptr = reader_buf; *reader_ptr != '\0'; reader_ptr += strlen(reader_ptr) + 1) {
|
||||
if(wanted) {
|
||||
while(*reader_ptr != '\0') {
|
||||
if(strstr(reader_ptr, wanted)) {
|
||||
if(!strstr(reader_ptr, wanted)) {
|
||||
if(state->verbose) {
|
||||
fprintf(stderr, "using reader '%s' matching '%s'.\n", reader_ptr, wanted);
|
||||
fprintf(stderr, "skipping reader '%s' since it doesn't match '%s'.\n", reader_ptr, wanted);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
if(state->verbose) {
|
||||
fprintf(stderr, "skipping reader '%s' since it doesn't match.\n", reader_ptr);
|
||||
fprintf(stderr, "trying to connect to reader '%s'.\n", reader_ptr);
|
||||
}
|
||||
reader_ptr += strlen(reader_ptr) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(*reader_ptr == '\0') {
|
||||
if(state->verbose) {
|
||||
fprintf(stderr, "error: no useable reader found.\n");
|
||||
}
|
||||
SCardReleaseContext(state->context);
|
||||
return YKPIV_PCSC_ERROR;
|
||||
}
|
||||
|
||||
rc = SCardConnect(state->context, reader_ptr, SCARD_SHARE_SHARED,
|
||||
SCARD_PROTOCOL_T1, &state->card, &active_protocol);
|
||||
if(rc != SCARD_S_SUCCESS)
|
||||
{
|
||||
if(state->verbose) {
|
||||
fprintf(stderr, "error: SCardConnect failed, rc=%08lx\n", rc);
|
||||
fprintf(stderr, "SCardConnect failed, rc=%08lx\n", rc);
|
||||
}
|
||||
SCardReleaseContext(state->context);
|
||||
return YKPIV_PCSC_ERROR;
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
@@ -214,15 +201,29 @@ ykpiv_rc ykpiv_connect(ykpiv_state *state, const char *wanted) {
|
||||
memcpy(apdu.st.data, aid, sizeof(aid));
|
||||
|
||||
if((res = send_data(state, &apdu, data, &recv_len, &sw)) != YKPIV_OK) {
|
||||
return res;
|
||||
if(state->verbose) {
|
||||
fprintf(stderr, "Failed communicating with card: '%s'\n", ykpiv_strerror(res));
|
||||
}
|
||||
continue;
|
||||
} else if(sw == 0x9000) {
|
||||
return YKPIV_OK;
|
||||
} else {
|
||||
if(state->verbose) {
|
||||
fprintf(stderr, "Failed selecting applet: %04x\n", sw);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return YKPIV_APPLET_ERROR;
|
||||
if(*reader_ptr == '\0') {
|
||||
if(state->verbose) {
|
||||
fprintf(stderr, "error: no useable reader found.\n");
|
||||
}
|
||||
SCardReleaseContext(state->context);
|
||||
return YKPIV_PCSC_ERROR;
|
||||
}
|
||||
|
||||
return YKPIV_OK;
|
||||
return YKPIV_GENERIC_ERROR;
|
||||
}
|
||||
|
||||
ykpiv_rc ykpiv_transfer_data(ykpiv_state *state, const unsigned char *templ,
|
||||
|
||||
Reference in New Issue
Block a user