Blame SOURCES/opencryptoki-3.16.0-d2f137cce5e6efb123842509352c7c49f889c67f.patch

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