Commit 03ddbdd9 authored by Richard Levitte's avatar Richard Levitte
Browse files

Move another common functionality (reproduced so far with cut'n'paste)

to apps.c, and give it the hopefully descriptive name parse_yesno().
parent 5ebdb390
Loading
Loading
Loading
Loading
+30 −16
Original line number Diff line number Diff line
@@ -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 \
+1 −0
Original line number Diff line number Diff line
@@ -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);

+3 −17
Original line number Diff line number Diff line
@@ -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