From: tb Date: Sun, 18 Aug 2024 17:50:10 +0000 (+0000) Subject: conf_def.c: shuffle things into a slightly more sensible X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ff9a56beb703cdb8afa0f962747768e2ba264324;p=openbsd conf_def.c: shuffle things into a slightly more sensible Reduces upcoming diffs and avoids annoying prototypes. --- diff --git a/lib/libcrypto/conf/conf_def.c b/lib/libcrypto/conf/conf_def.c index dbd2e6a2eb3..de1212ad376 100644 --- a/lib/libcrypto/conf/conf_def.c +++ b/lib/libcrypto/conf/conf_def.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf_def.c,v 1.34 2024/04/09 13:56:30 beck Exp $ */ +/* $OpenBSD: conf_def.c,v 1.35 2024/08/18 17:50:10 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -80,57 +80,6 @@ static char *scan_quote(CONF *conf, char *p); static char *scan_dquote(CONF *conf, char *p); #define scan_esc(conf,p) (((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2))) -static CONF *def_create(CONF_METHOD *meth); -static int def_init_default(CONF *conf); -static int def_init_WIN32(CONF *conf); -static int def_destroy(CONF *conf); -static int def_destroy_data(CONF *conf); -static int def_load(CONF *conf, const char *name, long *eline); -static int def_load_bio(CONF *conf, BIO *bp, long *eline); -static int def_dump(const CONF *conf, BIO *bp); -static int def_is_number(const CONF *conf, char c); -static int def_to_int(const CONF *conf, char c); - -static CONF_METHOD default_method = { - .name = "OpenSSL default", - .create = def_create, - .init = def_init_default, - .destroy = def_destroy, - .destroy_data = def_destroy_data, - .load_bio = def_load_bio, - .dump = def_dump, - .is_number = def_is_number, - .to_int = def_to_int, - .load = def_load -}; - -static CONF_METHOD WIN32_method = { - "WIN32", - def_create, - def_init_WIN32, - def_destroy, - def_destroy_data, - def_load_bio, - def_dump, - def_is_number, - def_to_int, - def_load -}; - -CONF_METHOD * -NCONF_default(void) -{ - return &default_method; -} -LCRYPTO_ALIAS(NCONF_default); - -CONF_METHOD * -NCONF_WIN32(void) -{ - return &WIN32_method; -} -LCRYPTO_ALIAS(NCONF_WIN32); - static CONF * def_create(CONF_METHOD *meth) { @@ -151,7 +100,7 @@ def_init_default(CONF *conf) if (conf == NULL) return 0; - conf->meth = &default_method; + conf->meth = NCONF_default(); conf->meth_data = CONF_type_default; conf->data = NULL; @@ -164,23 +113,13 @@ def_init_WIN32(CONF *conf) if (conf == NULL) return 0; - conf->meth = &WIN32_method; + conf->meth = NCONF_WIN32(); conf->meth_data = (void *)CONF_type_win32; conf->data = NULL; return 1; } -static int -def_destroy(CONF *conf) -{ - if (def_destroy_data(conf)) { - free(conf); - return 1; - } - return 0; -} - static int def_destroy_data(CONF *conf) { @@ -191,24 +130,13 @@ def_destroy_data(CONF *conf) } static int -def_load(CONF *conf, const char *name, long *line) +def_destroy(CONF *conf) { - int ret; - BIO *in = NULL; - - in = BIO_new_file(name, "rb"); - if (in == NULL) { - if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE) - CONFerror(CONF_R_NO_SUCH_FILE); - else - CONFerror(ERR_R_SYS_LIB); - return 0; + if (def_destroy_data(conf)) { + free(conf); + return 1; } - - ret = def_load_bio(conf, in, line); - BIO_free(in); - - return ret; + return 0; } static int @@ -416,6 +344,27 @@ err: return (0); } +static int +def_load(CONF *conf, const char *name, long *line) +{ + int ret; + BIO *in = NULL; + + in = BIO_new_file(name, "rb"); + if (in == NULL) { + if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE) + CONFerror(CONF_R_NO_SUCH_FILE); + else + CONFerror(ERR_R_SYS_LIB); + return 0; + } + + ret = def_load_bio(conf, in, line); + BIO_free(in); + + return ret; +} + static void clear_comments(CONF *conf, char *p) { @@ -698,3 +647,43 @@ def_to_int(const CONF *conf, char c) { return c - '0'; } + +static CONF_METHOD default_method = { + .name = "OpenSSL default", + .create = def_create, + .init = def_init_default, + .destroy = def_destroy, + .destroy_data = def_destroy_data, + .load_bio = def_load_bio, + .dump = def_dump, + .is_number = def_is_number, + .to_int = def_to_int, + .load = def_load +}; + +static CONF_METHOD WIN32_method = { + "WIN32", + def_create, + def_init_WIN32, + def_destroy, + def_destroy_data, + def_load_bio, + def_dump, + def_is_number, + def_to_int, + def_load +}; + +CONF_METHOD * +NCONF_default(void) +{ + return &default_method; +} +LCRYPTO_ALIAS(NCONF_default); + +CONF_METHOD * +NCONF_WIN32(void) +{ + return &WIN32_method; +} +LCRYPTO_ALIAS(NCONF_WIN32);