From: Richard Levitte Date: Fri, 28 Nov 2003 14:45:09 +0000 (+0000) Subject: Move another common functionality (reproduced so far with cut'n'paste) X-Git-Tag: BEN_FIPS_TEST_4^2~11^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=03ddbdd9b99ea60d0967b831ffc1fe93ae7f9792;p=openssl Move another common functionality (reproduced so far with cut'n'paste) to apps.c, and give it the hopefully descriptive name parse_yesno(). --- diff --git a/apps/apps.c b/apps/apps.c index 8e3f5cdac4..6e72f1183d 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -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 \ diff --git a/apps/apps.h b/apps/apps.h index 2b49770dfb..7edafa4244 100644 --- a/apps/apps.h +++ b/apps/apps.h @@ -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); diff --git a/apps/ca.c b/apps/ca.c index 7d10d825b1..0b33811172 100644 --- a/apps/ca.c +++ b/apps/ca.c @@ -131,6 +131,7 @@ #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