[Pkg-gnupg-commit] [gnupg2] 83/116: scd: Add "card_list" sub command for GETINFO.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Tue Jan 24 04:40:56 UTC 2017


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gnupg2.

commit 8b1f24a29ebc7651437c01990215a55b1136dae0
Author: NIIBE Yutaka <gniibe at fsij.org>
Date:   Wed Jan 18 15:19:38 2017 +0900

    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 at fsij.org>
---
 scd/app-common.h |  1 +
 scd/app.c        | 18 ++++++++++++++++++
 scd/command.c    | 18 ++++++++++++++----
 3 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/scd/app-common.h b/scd/app-common.h
index fb0fe55..7c6822f 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 06850d8..681acb8 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 dc854e3..cad8c6e 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;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list