aboutsummaryrefslogtreecommitdiffstats
path: root/scd/command.c
diff options
context:
space:
mode:
Diffstat (limited to 'scd/command.c')
-rw-r--r--scd/command.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/scd/command.c b/scd/command.c
index fa1d46ce1..a44378d43 100644
--- a/scd/command.c
+++ b/scd/command.c
@@ -70,6 +70,10 @@
&& (c)->reader_slot == locked_session->ctrl_backlink->reader_slot)
+/* Flag indicating that the reader has been disabled. */
+static int reader_disabled;
+
+
/* This structure is used to keep track of open readers (slots). */
struct slot_status_s
{
@@ -305,7 +309,7 @@ do_reset (ctrl_t ctrl, int send_reset)
{
if (apdu_reset (slot))
{
- slot_table[slot].reset_failed = 1;
+ slot_table[slot].valid = 0;
}
application_notify_card_reset (slot);
}
@@ -394,7 +398,23 @@ get_reader_slot (void)
/* Try to open the reader. */
if (ss->slot == -1)
- ss->slot = apdu_open_reader (opt.reader_port);
+ {
+ int no_service_flag;
+ ss->slot = apdu_open_reader (opt.reader_port, &no_service_flag);
+
+ /* If we still don't have a slot, we have no readers.
+ Invalidate for now until a reader is attached. */
+ if(ss->slot == -1)
+ {
+ ss->valid = 0;
+ }
+
+ if (no_service_flag)
+ {
+ log_info ("no card services - disabling scdaemon\n");
+ reader_disabled = 1;
+ }
+ }
/* Return the slot_table index. */
return 0;
@@ -409,6 +429,9 @@ open_card (ctrl_t ctrl, const char *apptype)
gpg_error_t err;
int slot;
+ if (reader_disabled)
+ return gpg_error (GPG_ERR_NOT_OPERATIONAL);
+
/* If we ever got a card not present error code, return that. Only
the SERIALNO command and a reset are able to clear from that
state. */
@@ -441,7 +464,7 @@ open_card (ctrl_t ctrl, const char *apptype)
slot = get_reader_slot ();
ctrl->reader_slot = slot;
if (slot == -1)
- err = gpg_error (GPG_ERR_CARD);
+ err = gpg_error (reader_disabled? GPG_ERR_NOT_OPERATIONAL: GPG_ERR_CARD);
else
{
/* Fixme: We should move the apdu_connect call to
@@ -495,7 +518,7 @@ cmd_serialno (assuan_context_t ctx, char *line)
time_t stamp;
/* Clear the remove flag so that the open_card is able to reread it. */
- if (ctrl->server_local->card_removed)
+ if (!reader_disabled && ctrl->server_local->card_removed)
{
if ( IS_LOCKED (ctrl) )
return gpg_error (GPG_ERR_LOCKED);
@@ -1993,7 +2016,7 @@ scd_command_handler (ctrl_t ctrl, int fd)
BUG ();
sl->next_session = ctrl->server_local->next_session;
}
- stopme = ctrl->server_local->stopme;
+ stopme = ctrl->server_local->stopme || reader_disabled;
xfree (ctrl->server_local);
ctrl->server_local = NULL;
@@ -2175,6 +2198,8 @@ update_reader_status_file (int set_card_removed_flag)
if (sw_apdu == SW_HOST_NO_READER)
{
/* Most likely the _reader_ has been unplugged. */
+ apdu_close_reader(ss->slot);
+ ss->valid = 0;
status = 0;
changed = ss->changed;
}