diff options
author | Rich Salz <rsalz@akamai.com> | 2015-05-28 19:52:55 +0200 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2015-05-28 23:28:33 +0200 |
commit | cc01d21756cc9c79231ef21039782c5fe42008a2 (patch) | |
tree | cb92584cc79d9994f9859b15c04a645d0b020389 /apps/apps.c | |
parent | PEM doc fixes (diff) | |
download | openssl-cc01d21756cc9c79231ef21039782c5fe42008a2.tar.xz openssl-cc01d21756cc9c79231ef21039782c5fe42008a2.zip |
RT3876: Only load config when needed
Create app_load_config(), a routine to load config file. Remove the
"always load config" from the main app. Change the places that used to
load config to call the new common routine.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'apps/apps.c')
-rw-r--r-- | apps/apps.c | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/apps/apps.c b/apps/apps.c index 593c036855..74646afae6 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -496,6 +496,33 @@ static char *app_get_pass(char *arg, int keepbio) return BUF_strdup(tpass); } +CONF *app_load_config(const char *filename) +{ + long errorline = -1; + CONF *conf; + int i; + BIO *in; + + in = bio_open_default(filename, "r"); + if (in == NULL) + return NULL; + + conf = NCONF_new(NULL); + i = NCONF_load_bio(conf, in, &errorline); + BIO_free(in); + if (i > 0) + return conf; + + if (errorline <= 0) + BIO_printf(bio_err, "%s: Can't load config file \"%s\"\n", + opt_getprog(), filename); + else + BIO_printf(bio_err, "%s: Error on line %ld of config file \"%s\"\n", + opt_getprog(), errorline, filename); + NCONF_free(conf); + return NULL; +} + int add_oid_section(CONF *conf) { char *p; @@ -1559,8 +1586,7 @@ CA_DB *load_index(char *dbfile, DB_ATTR *db_attr) TXT_DB *tmpdb = NULL; BIO *in; CONF *dbattr_conf = NULL; - char buf[1][BSIZE]; - long errorline = -1; + char buf[BSIZE]; in = BIO_new_file(dbfile, "r"); if (in == NULL) { @@ -1571,22 +1597,11 @@ CA_DB *load_index(char *dbfile, DB_ATTR *db_attr) goto err; #ifndef OPENSSL_SYS_VMS - BIO_snprintf(buf[0], sizeof buf[0], "%s.attr", dbfile); + BIO_snprintf(buf, sizeof buf, "%s.attr", dbfile); #else - BIO_snprintf(buf[0], sizeof buf[0], "%s-attr", dbfile); + BIO_snprintf(buf, sizeof buf, "%s-attr", dbfile); #endif - dbattr_conf = NCONF_new(NULL); - if (NCONF_load(dbattr_conf, buf[0], &errorline) <= 0) { - if (errorline > 0) { - BIO_printf(bio_err, - "error on line %ld of db attribute file '%s'\n", - errorline, buf[0]); - goto err; - } else { - NCONF_free(dbattr_conf); - dbattr_conf = NULL; - } - } + dbattr_conf = app_load_config(buf); retdb = app_malloc(sizeof(*retdb), "new DB"); retdb->db = tmpdb; |