From 0e34683a6c4b037aa50ca0f97ddb9d5c4e499084 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 27 Nov 2020 11:14:30 +0100 Subject: scd: New getinfo sub-command apdu_strerror. * scd/apdu.c (apdu_strerror): Add missing status codes. * scd/command.c (cmd_getinfo): New sub-command apdu_strerror. -- This is quite handy for gpg-card's APDU command and avoids that we need to duplicate the mapping table or put it into a shared file. --- scd/command.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'scd/command.c') diff --git a/scd/command.c b/scd/command.c index 457347121..5bb52246b 100644 --- a/scd/command.c +++ b/scd/command.c @@ -1728,15 +1728,18 @@ static const char hlp_getinfo[] = " all_active_apps\n" " - Return a list of active apps on all inserted cards.\n" " cmd_has_option CMD OPT\n" - " - Returns OK if command CMD has option OPT.\n"; + " - Returns OK if command CMD has option OPT.\n" + " apdu_strerror NUMBER\n" + " - Return a string for a status word.\n"; static gpg_error_t cmd_getinfo (assuan_context_t ctx, char *line) { int rc = 0; + const char *s; if (!strcmp (line, "version")) { - const char *s = VERSION; + s = VERSION; rc = assuan_send_data (ctx, s, strlen (s)); } else if (!strcmp (line, "pid")) @@ -1780,8 +1783,7 @@ cmd_getinfo (assuan_context_t ctx, char *line) } else if (!strcmp (line, "socket_name")) { - const char *s = scd_get_socket_name (); - + s = scd_get_socket_name (); if (s) rc = assuan_send_data (ctx, s, strlen (s)); else @@ -1809,27 +1811,27 @@ cmd_getinfo (assuan_context_t ctx, char *line) else if (!strcmp (line, "reader_list")) { #ifdef HAVE_LIBUSB - char *s = ccid_get_reader_list (); + char *p = ccid_get_reader_list (); #else - char *s = NULL; + char *p = NULL; #endif - if (s) - rc = assuan_send_data (ctx, s, strlen (s)); + if (p) + rc = assuan_send_data (ctx, p, strlen (p)); else rc = gpg_error (GPG_ERR_NO_DATA); - xfree (s); + xfree (p); } else if (!strcmp (line, "deny_admin")) rc = opt.allow_admin? gpg_error (GPG_ERR_GENERAL) : 0; else if (!strcmp (line, "app_list")) { - char *s = get_supported_applications (); - if (s) - rc = assuan_send_data (ctx, s, strlen (s)); + char *p = get_supported_applications (); + if (p) + rc = assuan_send_data (ctx, p, strlen (p)); else rc = 0; - xfree (s); + xfree (p); } else if (!strcmp (line, "card_list")) { @@ -1850,6 +1852,12 @@ cmd_getinfo (assuan_context_t ctx, char *line) ctrl_t ctrl = assuan_get_pointer (ctx); rc = app_send_active_apps (NULL, ctrl); } + else if ((s=has_leading_keyword (line, "apdu_strerror"))) + { + unsigned long ul = strtoul (s, NULL, 0); + s = apdu_strerror (ul); + rc = assuan_send_data (ctx, s, strlen (s)); + } else rc = set_error (GPG_ERR_ASS_PARAMETER, "unknown value for WHAT"); return rc; -- cgit v1.2.3