diff options
author | tb <> | 2024-08-18 17:50:10 +0000 |
---|---|---|
committer | tb <> | 2024-08-18 17:50:10 +0000 |
commit | 85534b05cc2aca494a0262abef3f49a081303440 (patch) | |
tree | 0abfa975549988bff089cb11f72c31ecb25cd615 | |
parent | 6b27742b84442a18232c9aec1ac503960d170093 (diff) | |
download | openbsd-85534b05cc2aca494a0262abef3f49a081303440.tar.gz openbsd-85534b05cc2aca494a0262abef3f49a081303440.tar.bz2 openbsd-85534b05cc2aca494a0262abef3f49a081303440.zip |
conf_def.c: shuffle things into a slightly more sensible
Reduces upcoming diffs and avoids annoying prototypes.
-rw-r--r-- | src/lib/libcrypto/conf/conf_def.c | 149 |
1 files changed, 69 insertions, 80 deletions
diff --git a/src/lib/libcrypto/conf/conf_def.c b/src/lib/libcrypto/conf/conf_def.c index dbd2e6a2eb..de1212ad37 100644 --- a/src/lib/libcrypto/conf/conf_def.c +++ b/src/lib/libcrypto/conf/conf_def.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: conf_def.c,v 1.34 2024/04/09 13:56:30 beck Exp $ */ | 1 | /* $OpenBSD: conf_def.c,v 1.35 2024/08/18 17:50:10 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -80,57 +80,6 @@ static char *scan_quote(CONF *conf, char *p); | |||
80 | static char *scan_dquote(CONF *conf, char *p); | 80 | static char *scan_dquote(CONF *conf, char *p); |
81 | #define scan_esc(conf,p) (((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2))) | 81 | #define scan_esc(conf,p) (((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2))) |
82 | 82 | ||
83 | static CONF *def_create(CONF_METHOD *meth); | ||
84 | static int def_init_default(CONF *conf); | ||
85 | static int def_init_WIN32(CONF *conf); | ||
86 | static int def_destroy(CONF *conf); | ||
87 | static int def_destroy_data(CONF *conf); | ||
88 | static int def_load(CONF *conf, const char *name, long *eline); | ||
89 | static int def_load_bio(CONF *conf, BIO *bp, long *eline); | ||
90 | static int def_dump(const CONF *conf, BIO *bp); | ||
91 | static int def_is_number(const CONF *conf, char c); | ||
92 | static int def_to_int(const CONF *conf, char c); | ||
93 | |||
94 | static CONF_METHOD default_method = { | ||
95 | .name = "OpenSSL default", | ||
96 | .create = def_create, | ||
97 | .init = def_init_default, | ||
98 | .destroy = def_destroy, | ||
99 | .destroy_data = def_destroy_data, | ||
100 | .load_bio = def_load_bio, | ||
101 | .dump = def_dump, | ||
102 | .is_number = def_is_number, | ||
103 | .to_int = def_to_int, | ||
104 | .load = def_load | ||
105 | }; | ||
106 | |||
107 | static CONF_METHOD WIN32_method = { | ||
108 | "WIN32", | ||
109 | def_create, | ||
110 | def_init_WIN32, | ||
111 | def_destroy, | ||
112 | def_destroy_data, | ||
113 | def_load_bio, | ||
114 | def_dump, | ||
115 | def_is_number, | ||
116 | def_to_int, | ||
117 | def_load | ||
118 | }; | ||
119 | |||
120 | CONF_METHOD * | ||
121 | NCONF_default(void) | ||
122 | { | ||
123 | return &default_method; | ||
124 | } | ||
125 | LCRYPTO_ALIAS(NCONF_default); | ||
126 | |||
127 | CONF_METHOD * | ||
128 | NCONF_WIN32(void) | ||
129 | { | ||
130 | return &WIN32_method; | ||
131 | } | ||
132 | LCRYPTO_ALIAS(NCONF_WIN32); | ||
133 | |||
134 | static CONF * | 83 | static CONF * |
135 | def_create(CONF_METHOD *meth) | 84 | def_create(CONF_METHOD *meth) |
136 | { | 85 | { |
@@ -151,7 +100,7 @@ def_init_default(CONF *conf) | |||
151 | if (conf == NULL) | 100 | if (conf == NULL) |
152 | return 0; | 101 | return 0; |
153 | 102 | ||
154 | conf->meth = &default_method; | 103 | conf->meth = NCONF_default(); |
155 | conf->meth_data = CONF_type_default; | 104 | conf->meth_data = CONF_type_default; |
156 | conf->data = NULL; | 105 | conf->data = NULL; |
157 | 106 | ||
@@ -164,7 +113,7 @@ def_init_WIN32(CONF *conf) | |||
164 | if (conf == NULL) | 113 | if (conf == NULL) |
165 | return 0; | 114 | return 0; |
166 | 115 | ||
167 | conf->meth = &WIN32_method; | 116 | conf->meth = NCONF_WIN32(); |
168 | conf->meth_data = (void *)CONF_type_win32; | 117 | conf->meth_data = (void *)CONF_type_win32; |
169 | conf->data = NULL; | 118 | conf->data = NULL; |
170 | 119 | ||
@@ -172,16 +121,6 @@ def_init_WIN32(CONF *conf) | |||
172 | } | 121 | } |
173 | 122 | ||
174 | static int | 123 | static int |
175 | def_destroy(CONF *conf) | ||
176 | { | ||
177 | if (def_destroy_data(conf)) { | ||
178 | free(conf); | ||
179 | return 1; | ||
180 | } | ||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | static int | ||
185 | def_destroy_data(CONF *conf) | 124 | def_destroy_data(CONF *conf) |
186 | { | 125 | { |
187 | if (conf == NULL) | 126 | if (conf == NULL) |
@@ -191,24 +130,13 @@ def_destroy_data(CONF *conf) | |||
191 | } | 130 | } |
192 | 131 | ||
193 | static int | 132 | static int |
194 | def_load(CONF *conf, const char *name, long *line) | 133 | def_destroy(CONF *conf) |
195 | { | 134 | { |
196 | int ret; | 135 | if (def_destroy_data(conf)) { |
197 | BIO *in = NULL; | 136 | free(conf); |
198 | 137 | return 1; | |
199 | in = BIO_new_file(name, "rb"); | ||
200 | if (in == NULL) { | ||
201 | if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE) | ||
202 | CONFerror(CONF_R_NO_SUCH_FILE); | ||
203 | else | ||
204 | CONFerror(ERR_R_SYS_LIB); | ||
205 | return 0; | ||
206 | } | 138 | } |
207 | 139 | return 0; | |
208 | ret = def_load_bio(conf, in, line); | ||
209 | BIO_free(in); | ||
210 | |||
211 | return ret; | ||
212 | } | 140 | } |
213 | 141 | ||
214 | static int | 142 | static int |
@@ -416,6 +344,27 @@ err: | |||
416 | return (0); | 344 | return (0); |
417 | } | 345 | } |
418 | 346 | ||
347 | static int | ||
348 | def_load(CONF *conf, const char *name, long *line) | ||
349 | { | ||
350 | int ret; | ||
351 | BIO *in = NULL; | ||
352 | |||
353 | in = BIO_new_file(name, "rb"); | ||
354 | if (in == NULL) { | ||
355 | if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE) | ||
356 | CONFerror(CONF_R_NO_SUCH_FILE); | ||
357 | else | ||
358 | CONFerror(ERR_R_SYS_LIB); | ||
359 | return 0; | ||
360 | } | ||
361 | |||
362 | ret = def_load_bio(conf, in, line); | ||
363 | BIO_free(in); | ||
364 | |||
365 | return ret; | ||
366 | } | ||
367 | |||
419 | static void | 368 | static void |
420 | clear_comments(CONF *conf, char *p) | 369 | clear_comments(CONF *conf, char *p) |
421 | { | 370 | { |
@@ -698,3 +647,43 @@ def_to_int(const CONF *conf, char c) | |||
698 | { | 647 | { |
699 | return c - '0'; | 648 | return c - '0'; |
700 | } | 649 | } |
650 | |||
651 | static CONF_METHOD default_method = { | ||
652 | .name = "OpenSSL default", | ||
653 | .create = def_create, | ||
654 | .init = def_init_default, | ||
655 | .destroy = def_destroy, | ||
656 | .destroy_data = def_destroy_data, | ||
657 | .load_bio = def_load_bio, | ||
658 | .dump = def_dump, | ||
659 | .is_number = def_is_number, | ||
660 | .to_int = def_to_int, | ||
661 | .load = def_load | ||
662 | }; | ||
663 | |||
664 | static CONF_METHOD WIN32_method = { | ||
665 | "WIN32", | ||
666 | def_create, | ||
667 | def_init_WIN32, | ||
668 | def_destroy, | ||
669 | def_destroy_data, | ||
670 | def_load_bio, | ||
671 | def_dump, | ||
672 | def_is_number, | ||
673 | def_to_int, | ||
674 | def_load | ||
675 | }; | ||
676 | |||
677 | CONF_METHOD * | ||
678 | NCONF_default(void) | ||
679 | { | ||
680 | return &default_method; | ||
681 | } | ||
682 | LCRYPTO_ALIAS(NCONF_default); | ||
683 | |||
684 | CONF_METHOD * | ||
685 | NCONF_WIN32(void) | ||
686 | { | ||
687 | return &WIN32_method; | ||
688 | } | ||
689 | LCRYPTO_ALIAS(NCONF_WIN32); | ||