Blame SOURCES/opencryptoki-3.16.0-d2f137cce5e6efb123842509352c7c49f889c67f.patch

c87d79
commit d2f137cce5e6efb123842509352c7c49f889c67f
c87d79
Author: Ingo Franzki <ifranzki@linux.ibm.com>
c87d79
Date:   Thu Jul 22 15:55:02 2021 +0200
c87d79
c87d79
    pkcstok_migrate: Rework string quoting for opencryptoki.conf migration
c87d79
    
c87d79
    Due to the way the parser works, a slot description like
c87d79
    'description = "slot"' works, but not without quotes ('description = slot').
c87d79
    The word 'slot' is treated as a keyword if not quoted (besides other keywords,
c87d79
    too), so if the word 'slot' would appear in an unquoted string, the
c87d79
    configuration file would fail to parse.
c87d79
    
c87d79
    Always quote the value of 'description' and 'manufacturer'. Quote the
c87d79
    value of 'stdll', 'confname', and 'tokname' if it contains spaces, and
c87d79
    never quote the value of 'hwversion', 'firmwareversion', and 'tokversion'.
c87d79
    
c87d79
    Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
c87d79
c87d79
diff --git a/usr/sbin/pkcstok_migrate/pkcstok_migrate.c b/usr/sbin/pkcstok_migrate/pkcstok_migrate.c
c87d79
index a29dc8f7..853986e8 100644
c87d79
--- a/usr/sbin/pkcstok_migrate/pkcstok_migrate.c
c87d79
+++ b/usr/sbin/pkcstok_migrate/pkcstok_migrate.c
c87d79
@@ -2060,7 +2060,7 @@ done:
c87d79
  */
c87d79
 static int parseupdate_ockversion(void *private, const char *version)
c87d79
 {
c87d79
-	struct parseupdate *u = (struct parseupdate *)private;
c87d79
+    struct parseupdate *u = (struct parseupdate *)private;
c87d79
 
c87d79
     fprintf(u->f, "version %s", version);
c87d79
     return 0;
c87d79
@@ -2075,14 +2075,14 @@ static void parseupdate_disab_event_supp(void *private)
c87d79
 
c87d79
 static void parseupdate_eol(void *private)
c87d79
 {
c87d79
-	struct parseupdate *u = (struct parseupdate *)private;
c87d79
+    struct parseupdate *u = (struct parseupdate *)private;
c87d79
 
c87d79
     fputc('\n', u->f);
c87d79
 }
c87d79
 
c87d79
 static int parseupdate_begin_slot(void *private, int slot, int nl_before_begin)
c87d79
 {
c87d79
-	struct parseupdate *u = (struct parseupdate *)private;
c87d79
+    struct parseupdate *u = (struct parseupdate *)private;
c87d79
 
c87d79
     u->activeslot = (slot == u->slotnum);
c87d79
     if (nl_before_begin)
c87d79
@@ -2094,7 +2094,7 @@ static int parseupdate_begin_slot(void *private, int slot, int nl_before_begin)
c87d79
 
c87d79
 static int parseupdate_end_slot(void *private)
c87d79
 {
c87d79
-	struct parseupdate *u = (struct parseupdate *)private;
c87d79
+    struct parseupdate *u = (struct parseupdate *)private;
c87d79
 
c87d79
     if (u->activeslot)
c87d79
         fprintf(u->f, "  tokversion = 3.12\n");
c87d79
@@ -2105,19 +2105,32 @@ static int parseupdate_end_slot(void *private)
c87d79
 
c87d79
 static int parseupdate_key_str(void *private, int tok, const char *val)
c87d79
 {
c87d79
-	struct parseupdate *u = (struct parseupdate *)private;
c87d79
+    struct parseupdate *u = (struct parseupdate *)private;
c87d79
 
c87d79
-    if (tok != KW_HWVERSION && tok != KW_FWVERSION &&
c87d79
-        strchr(val, ' ') != NULL)
c87d79
+    switch (tok) {
c87d79
+    case KW_SLOTDESC:
c87d79
+    case KW_MANUFID:
c87d79
         fprintf(u->f, "  %s = \"%s\"", keyword_token_to_str(tok), val);
c87d79
-    else if (tok != KW_TOKVERSION)
c87d79
+        break;
c87d79
+    case KW_STDLL:
c87d79
+    case KW_CONFNAME:
c87d79
+    case KW_TOKNAME:
c87d79
+        if (strchr(val, ' ') != NULL)
c87d79
+            fprintf(u->f, "  %s = \"%s\"", keyword_token_to_str(tok), val);
c87d79
+        else
c87d79
+            fprintf(u->f, "  %s = %s", keyword_token_to_str(tok), val);
c87d79
+        break;
c87d79
+    case KW_HWVERSION:
c87d79
+    case KW_FWVERSION:
c87d79
         fprintf(u->f, "  %s = %s", keyword_token_to_str(tok), val);
c87d79
+        break;
c87d79
+	}
c87d79
     return 0;
c87d79
 }
c87d79
 
c87d79
 static int parseupdate_key_vers(void *private, int tok, unsigned int vers)
c87d79
 {
c87d79
-	struct parseupdate *u = (struct parseupdate *)private;
c87d79
+    struct parseupdate *u = (struct parseupdate *)private;
c87d79
 
c87d79
     if (tok == KW_TOKVERSION && !u->activeslot)
c87d79
         fprintf(u->f, "  %s = %d.%d", keyword_token_to_str(tok),
c87d79
@@ -2127,7 +2140,7 @@ static int parseupdate_key_vers(void *private, int tok, unsigned int vers)
c87d79
 
c87d79
 static void parseupdate_eolcomment(void *private, const char *comment)
c87d79
 {
c87d79
-	struct parseupdate *u = (struct parseupdate *)private;
c87d79
+    struct parseupdate *u = (struct parseupdate *)private;
c87d79
 
c87d79
     fprintf(u->f, "#%s", comment);
c87d79
 }