Move another common functionality (reproduced so far with cut'n'paste)
authorRichard Levitte <levitte@openssl.org>
Fri, 28 Nov 2003 14:45:09 +0000 (14:45 +0000)
committerRichard Levitte <levitte@openssl.org>
Fri, 28 Nov 2003 14:45:09 +0000 (14:45 +0000)
to apps.c, and give it the hopefully descriptive name parse_yesno().

apps/apps.c
apps/apps.h
apps/ca.c

index 8e3f5cd..6e72f11 100644 (file)
@@ -1707,22 +1707,7 @@ CA_DB *load_index(char *dbfile, DB_ATTR *db_attr)
 #ifdef RL_DEBUG
                        BIO_printf(bio_err, "DEBUG[load_index]: unique_subject = \"%s\"\n", p);
 #endif
-                       switch(*p)
-                               {
-                       case 'f': /* false */
-                       case 'F': /* FALSE */
-                       case 'n': /* no */
-                       case 'N': /* NO */
-                               retdb->attributes.unique_subject = 0;
-                               break;
-                       case 't': /* true */
-                       case 'T': /* TRUE */
-                       case 'y': /* yes */
-                       case 'Y': /* YES */
-                       default:
-                               retdb->attributes.unique_subject = 1;
-                               break;
-                               }
+                       retdb->attributes.unique_subject = parse_yesno(p,1);
                        }
                }
 
@@ -1962,6 +1947,35 @@ void free_index(CA_DB *db)
                }
        }
 
+int parse_yesno(char *str, int def)
+       {
+       int ret = def;
+       if (str)
+               {
+               switch (*str)
+                       {
+               case 'f': /* false */
+               case 'F': /* FALSE */
+               case 'n': /* no */
+               case 'N': /* NO */
+               case '0': /* 0 */
+                       ret = 0;
+                       break;
+               case 't': /* true */
+               case 'T': /* TRUE */
+               case 'y': /* yes */
+               case 'Y': /* YES */
+               case '1': /* 1 */
+                       ret = 0;
+                       break;
+               default:
+                       ret = def;
+                       break;
+                       }
+               }
+       return ret;
+       }
+
 /*
  * subject is expected to be in the format /type0=value0/type1=value1/type2=...
  * where characters may be escaped by \
index 2b49770..7edafa4 100644 (file)
@@ -315,6 +315,7 @@ int save_index(char *dbfile, char *suffix, CA_DB *db);
 int rotate_index(char *dbfile, char *new_suffix, char *old_suffix);
 void free_index(CA_DB *db);
 int index_name_cmp(const char **a, const char **b);
+int parse_yesno(char *str, int def);
 
 X509_NAME *parse_name(char *str, long chtype, int multirdn);
 
index 7d10d82..0b33811 100644 (file)
--- a/apps/ca.c
+++ b/apps/ca.c
 #define ENV_NAMEOPT            "name_opt"
 #define ENV_CERTOPT            "cert_opt"
 #define ENV_EXTCOPY            "copy_extensions"
+#define ENV_UNIQUE_SUBJECT     "unique_subject"
 
 #define ENV_DATABASE           "database"
 
@@ -638,28 +639,13 @@ bad:
        app_RAND_load_file(randfile, bio_err, 0);
 
        db_attr.unique_subject = 1;
-       p = NCONF_get_string(conf, section, "unique_subject");
+       p = NCONF_get_string(conf, section, ENV_UNIQUE_SUBJECT);
        if (p)
                {
 #ifdef RL_DEBUG
                BIO_printf(bio_err, "DEBUG: unique_subject = \"%s\"\n", p);
 #endif
-               switch(*p)
-                       {
-               case 'f': /* false */
-               case 'F': /* FALSE */
-               case 'n': /* no */
-               case 'N': /* NO */
-                       db_attr.unique_subject = 0;
-                       break;
-               case 't': /* true */
-               case 'T': /* TRUE */
-               case 'y': /* yes */
-               case 'Y': /* YES */
-               default:
-                       db_attr.unique_subject = 1;
-                       break;
-                       }
+               db_attr.unique_subject = parse_yesno(p,1);
                }
 #ifdef RL_DEBUG
        else