qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jeremy White <jwhite@codeweavers.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v3 4/7] Add error checking to vcard_emul_options.
Date: Fri, 13 Mar 2015 14:45:21 -0500	[thread overview]
Message-ID: <1426275924-1904-5-git-send-email-jwhite@codeweavers.com> (raw)
In-Reply-To: <1426275924-1904-1-git-send-email-jwhite@codeweavers.com>

Also add an alias of 'nssemul' for the default card
of hw=yes hw_type=cac, and an alias of 'passthru' for
the new card type of hw=yes hw_type=passthru.

This allows the spice-gtk client to take a more human
friendly set of arguments and relay them through to this code.

Signed-off-by: Jeremy White <jwhite@codeweavers.com>
---
 libcacard/vcard_emul_nss.c |   49 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 38 insertions(+), 11 deletions(-)

diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index 950edee..49f0bdf 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -1113,17 +1113,13 @@ static VCardEmulOptions options;
  * and its length in "token_length". "token" will not be nul-terminated.
  * After calling the macro, "args" will be advanced to the beginning of
  * the next token.
- * This macro may call continue or break.
  */
 #define NEXT_TOKEN(token) \
             (token) = args; \
             args = strpbrk(args, ",)"); \
-            if (*args == 0) { \
-                break; \
-            } \
-            if (*args == ')') { \
-                args++; \
-                continue; \
+            if (*args == 0 || *args == ')') { \
+                fprintf(stderr, "Error: invalid soft specification.\n"); \
+                return NULL; \
             } \
             (token##_length) = args - (token); \
             args = strip(args+1);
@@ -1141,6 +1137,7 @@ vcard_emul_options(const char *args)
     do {
         args = strip(args); /* strip off the leading spaces */
         if (*args == ',') {
+            args++;
             continue;
         }
         /* soft=(slot_name,virt_name,emul_type,emul_flags,cert_1, (no eol)
@@ -1159,7 +1156,8 @@ vcard_emul_options(const char *args)
 
             args = strip(args + 5);
             if (*args != '(') {
-                continue;
+                fprintf(stderr, "Error: invalid soft specification.\n");
+                return NULL;
             }
             args = strip(args+1);
 
@@ -1170,11 +1168,17 @@ vcard_emul_options(const char *args)
             memcpy(type_str, type_params, type_params_length);
             type_str[type_params_length] = '\0';
             type = vcard_emul_type_from_string(type_str);
+            if (type == VCARD_EMUL_NONE) {
+                fprintf(stderr, "Error: invalid smartcard type '%s'.\n",
+                        type_str);
+                return NULL;
+            }
 
             NEXT_TOKEN(type_params)
 
             if (*args == 0) {
-                break;
+                fprintf(stderr, "Error: missing cert specification.\n");
+                return NULL;
             }
 
             if (opts->vreader_count >= reader_count) {
@@ -1214,6 +1218,11 @@ vcard_emul_options(const char *args)
         } else if (strncmp(args, "hw_type=", 8) == 0) {
             args = strip(args+8);
             opts->hw_card_type = vcard_emul_type_from_string(args);
+            if (opts->hw_card_type == VCARD_EMUL_NONE) {
+                fprintf(stderr, "Error: invalid smartcard type '%s'.\n",
+                        args);
+                return NULL;
+            }
             args = find_blank(args);
         /* hw_params= */
         } else if (strncmp(args, "hw_params=", 10) == 0) {
@@ -1227,7 +1236,8 @@ vcard_emul_options(const char *args)
             const char *db;
             args = strip(args+3);
             if (*args != '"') {
-                continue;
+                fprintf(stderr, "Error: you must quote the file path.\n");
+                return NULL;
             }
             args++;
             db = args;
@@ -1236,8 +1246,21 @@ vcard_emul_options(const char *args)
             if (*args != 0) {
                 args++;
             }
+        } else if (strncmp(args, "nssemul", 7) == 0) {
+            opts->hw_card_type = VCARD_EMUL_CAC;
+            opts->use_hw = PR_TRUE;
+            args = find_blank(args + 7);
+        /* nssemul */
+#if defined(CONFIG_SMARTCARD_PCSC)
+        } else if (strncmp(args, "passthru", 8) == 0) {
+            opts->hw_card_type = VCARD_EMUL_PASSTHRU;
+            opts->use_hw = PR_TRUE;
+            args = find_blank(args + 8);
+        /* passthru */
+#endif
         } else {
-            args = find_blank(args);
+            fprintf(stderr, "Error: Unknown smartcard specification.\n");
+            return NULL;
         }
     } while (*args != 0);
 
@@ -1253,6 +1276,10 @@ vcard_emul_usage(void)
 " use_hw=[yes|no]                 (default yes)\n"
 " hw_type={card_type_to_emulate}  (default CAC)\n"
 " hw_param={param_for_card}       (default \"\")\n"
+" nssemul                         (alias for use_hw=yes, hw_type=CAC)\n"
+#if defined(CONFIG_SMARTCARD_PCSC)
+" passthru                        (alias for use_hw=yes, hw_type=PASSTHRU)\n"
+#endif
 " soft=({slot_name},{vreader_name},{card_type_to_emulate},{params_for_card},\n"
 "       {cert1},{cert2},{cert3}    (default none)\n"
 "\n"
-- 
1.7.10.4

  parent reply	other threads:[~2015-03-13 19:45 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-13 19:45 [Qemu-devel] [PATCH v3 0/7] Add support for passthru cards to libcacard Jeremy White
2015-03-13 19:45 ` [Qemu-devel] [PATCH v3 1/7] Bug fix: delete the reader entry after queueing an event, not before Jeremy White
2015-03-25 15:12   ` Marc-André Lureau
2015-03-13 19:45 ` [Qemu-devel] [PATCH v3 2/7] Retrieve the correct TD byte when checking an ATR Jeremy White
2015-03-25 15:12   ` Marc-André Lureau
2015-03-13 19:45 ` [Qemu-devel] [PATCH v3 3/7] Add a configure check for libpcsclite, and an option to enable or disable it Jeremy White
2015-03-25 15:13   ` Marc-André Lureau
2015-03-13 19:45 ` Jeremy White [this message]
2015-03-25 15:13   ` [Qemu-devel] [PATCH v3 4/7] Add error checking to vcard_emul_options Marc-André Lureau
2015-03-13 19:45 ` [Qemu-devel] [PATCH v3 5/7] Add a VCARD_DIRECT implemention to the libcacard smartcard support Jeremy White
2015-03-25 15:13   ` Marc-André Lureau
2015-03-13 19:45 ` [Qemu-devel] [PATCH v3 6/7] Enable support for passthru (e.g. direct to pcsc) smart cards in the emul_options entry point in libcacard Jeremy White
2015-03-25 15:14   ` Marc-André Lureau
2015-03-13 19:45 ` [Qemu-devel] [PATCH v3 7/7] Remove the (broken) passthru option Jeremy White
2015-03-25 15:14   ` Marc-André Lureau
2015-03-13 20:11 ` [Qemu-devel] [PATCH v3 0/7] Add support for passthru cards to libcacard Patchew Tool
2015-03-16 16:22 ` Marc-André Lureau
2015-03-16 16:52   ` Jeremy White
2015-03-16 17:19     ` Paolo Bonzini
2015-03-25 15:15       ` Marc-André Lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426275924-1904-5-git-send-email-jwhite@codeweavers.com \
    --to=jwhite@codeweavers.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).