summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2017-01-18 07:19:38 +0100
committerNIIBE Yutaka <gniibe@fsij.org>2017-01-18 07:19:38 +0100
commit8b1f24a29ebc7651437c01990215a55b1136dae0 (patch)
tree0993bc9774f78b0428143135806ec38a3004becf
parentbuild: Handle packages with dashes in --find-version. (diff)
downloadgnupg2-8b1f24a29ebc7651437c01990215a55b1136dae0.tar.xz
gnupg2-8b1f24a29ebc7651437c01990215a55b1136dae0.zip
scd: Add "card_list" sub command for GETINFO.
* scd/app.c (app_send_card_list): New. * scd/command.c (cmd_getinfo): Fix "status" sub command. Add "card_list" sub command. Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
-rw-r--r--scd/app-common.h1
-rw-r--r--scd/app.c18
-rw-r--r--scd/command.c18
3 files changed, 33 insertions, 4 deletions
diff --git a/scd/app-common.h b/scd/app-common.h
index fb0fe550a..7c6822fdd 100644
--- a/scd/app-common.h
+++ b/scd/app-common.h
@@ -123,6 +123,7 @@ size_t app_help_read_length_of_cert (int slot, int fid, size_t *r_certoff);
/*-- app.c --*/
app_t app_list_start (void);
void app_list_finish (void);
+void app_send_card_list (ctrl_t ctrl);
void app_dump_state (void);
void application_notify_card_reset (int slot);
diff --git a/scd/app.c b/scd/app.c
index 06850d87f..681acb822 100644
--- a/scd/app.c
+++ b/scd/app.c
@@ -1103,3 +1103,21 @@ app_list_finish (void)
{
npth_mutex_unlock (&app_list_lock);
}
+
+void
+app_send_card_list (ctrl_t ctrl)
+{
+ app_t a;
+ char buf[65];
+
+ npth_mutex_lock (&app_list_lock);
+ for (a = app_top; a; a = a->next)
+ {
+ if (DIM (buf) < 2 * a->serialnolen + 1)
+ continue;
+
+ bin2hex (a->serialno, a->serialnolen, buf);
+ send_status_direct (ctrl, "SERIALNO", buf);
+ }
+ npth_mutex_unlock (&app_list_lock);
+}
diff --git a/scd/command.c b/scd/command.c
index dc854e35d..cad8c6e39 100644
--- a/scd/command.c
+++ b/scd/command.c
@@ -1392,7 +1392,10 @@ static const char hlp_getinfo[] =
"\n"
"app_list - Return a list of supported applications. One\n"
" application per line, fields delimited by colons,\n"
- " first field is the name.";
+ " first field is the name.\n"
+ "\n"
+ "card_list - Return a list of serial numbers of active cards,\n"
+ " using a status response.";
static gpg_error_t
cmd_getinfo (assuan_context_t ctx, char *line)
{
@@ -1422,10 +1425,11 @@ cmd_getinfo (assuan_context_t ctx, char *line)
else if (!strcmp (line, "status"))
{
ctrl_t ctrl = assuan_get_pointer (ctx);
- app_t app = ctrl->app_ctx;
- char flag = 'r';
+ char flag;
- if (!ctrl->server_local->card_removed && app)
+ if (open_card (ctrl))
+ flag = 'r';
+ else
flag = 'u';
rc = assuan_send_data (ctx, &flag, 1);
@@ -1455,6 +1459,12 @@ cmd_getinfo (assuan_context_t ctx, char *line)
rc = 0;
xfree (s);
}
+ else if (!strcmp (line, "card_list"))
+ {
+ ctrl_t ctrl = assuan_get_pointer (ctx);
+
+ app_send_card_list (ctrl);
+ }
else
rc = set_error (GPG_ERR_ASS_PARAMETER, "unknown value for WHAT");
return rc;