diff options
author | jsing <> | 2014-04-20 09:04:56 +0000 |
---|---|---|
committer | jsing <> | 2014-04-20 09:04:56 +0000 |
commit | bd6c37add950ea36b41baf03eb39a383da308088 (patch) | |
tree | 3bbbbcfdf498b9882728fadf15db366c75a077ef /src/lib/libcrypto/conf/conf_api.c | |
parent | 086ee6338cab147edaa9a69d977bc59c6983ae81 (diff) | |
download | openbsd-bd6c37add950ea36b41baf03eb39a383da308088.tar.gz openbsd-bd6c37add950ea36b41baf03eb39a383da308088.tar.bz2 openbsd-bd6c37add950ea36b41baf03eb39a383da308088.zip |
KNF.
Diffstat (limited to 'src/lib/libcrypto/conf/conf_api.c')
-rw-r--r-- | src/lib/libcrypto/conf/conf_api.c | 306 |
1 files changed, 158 insertions, 148 deletions
diff --git a/src/lib/libcrypto/conf/conf_api.c b/src/lib/libcrypto/conf/conf_api.c index f484000d0c..98e058dad4 100644 --- a/src/lib/libcrypto/conf/conf_api.c +++ b/src/lib/libcrypto/conf/conf_api.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -70,231 +70,241 @@ | |||
70 | #include <openssl/conf_api.h> | 70 | #include <openssl/conf_api.h> |
71 | 71 | ||
72 | static void value_free_hash_doall_arg(CONF_VALUE *a, | 72 | static void value_free_hash_doall_arg(CONF_VALUE *a, |
73 | LHASH_OF(CONF_VALUE) *conf); | 73 | LHASH_OF(CONF_VALUE) *conf); |
74 | static void value_free_stack_doall(CONF_VALUE *a); | 74 | static void value_free_stack_doall(CONF_VALUE *a); |
75 | static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_hash, CONF_VALUE, | 75 | static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_hash, CONF_VALUE, |
76 | LHASH_OF(CONF_VALUE)) | 76 | LHASH_OF(CONF_VALUE)) |
77 | static IMPLEMENT_LHASH_DOALL_FN(value_free_stack, CONF_VALUE) | 77 | static IMPLEMENT_LHASH_DOALL_FN(value_free_stack, CONF_VALUE) |
78 | 78 | ||
79 | /* Up until OpenSSL 0.9.5a, this was get_section */ | 79 | /* Up until OpenSSL 0.9.5a, this was get_section */ |
80 | CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section) | 80 | CONF_VALUE * |
81 | { | 81 | _CONF_get_section(const CONF *conf, const char *section) |
82 | CONF_VALUE *v,vv; | 82 | { |
83 | 83 | CONF_VALUE *v, vv; | |
84 | if ((conf == NULL) || (section == NULL)) return(NULL); | 84 | |
85 | vv.name=NULL; | 85 | if ((conf == NULL) || (section == NULL)) |
86 | vv.section=(char *)section; | 86 | return (NULL); |
87 | v=lh_CONF_VALUE_retrieve(conf->data,&vv); | 87 | vv.name = NULL; |
88 | return(v); | 88 | vv.section = (char *)section; |
89 | } | 89 | v = lh_CONF_VALUE_retrieve(conf->data, &vv); |
90 | return (v); | ||
91 | } | ||
90 | 92 | ||
91 | /* Up until OpenSSL 0.9.5a, this was CONF_get_section */ | 93 | /* Up until OpenSSL 0.9.5a, this was CONF_get_section */ |
92 | STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf, | 94 | STACK_OF(CONF_VALUE) * |
93 | const char *section) | 95 | _CONF_get_section_values(const CONF *conf, const char *section) |
94 | { | 96 | { |
95 | CONF_VALUE *v; | 97 | CONF_VALUE *v; |
96 | 98 | ||
97 | v=_CONF_get_section(conf,section); | 99 | v = _CONF_get_section(conf, section); |
98 | if (v != NULL) | 100 | if (v != NULL) |
99 | return((STACK_OF(CONF_VALUE) *)v->value); | 101 | return ((STACK_OF(CONF_VALUE) *)v->value); |
100 | else | 102 | else |
101 | return(NULL); | 103 | return (NULL); |
102 | } | 104 | } |
103 | 105 | ||
104 | int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value) | 106 | int |
105 | { | 107 | _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value) |
108 | { | ||
106 | CONF_VALUE *v = NULL; | 109 | CONF_VALUE *v = NULL; |
107 | STACK_OF(CONF_VALUE) *ts; | 110 | STACK_OF(CONF_VALUE) *ts; |
108 | 111 | ||
109 | ts = (STACK_OF(CONF_VALUE) *)section->value; | 112 | ts = (STACK_OF(CONF_VALUE) *)section->value; |
110 | 113 | ||
111 | value->section=section->section; | 114 | value->section = section->section; |
112 | if (!sk_CONF_VALUE_push(ts,value)) | 115 | if (!sk_CONF_VALUE_push(ts, value)) { |
113 | { | ||
114 | return 0; | 116 | return 0; |
115 | } | 117 | } |
116 | 118 | ||
117 | v = lh_CONF_VALUE_insert(conf->data, value); | 119 | v = lh_CONF_VALUE_insert(conf->data, value); |
118 | if (v != NULL) | 120 | if (v != NULL) { |
119 | { | 121 | (void)sk_CONF_VALUE_delete_ptr(ts, v); |
120 | (void)sk_CONF_VALUE_delete_ptr(ts,v); | ||
121 | free(v->name); | 122 | free(v->name); |
122 | free(v->value); | 123 | free(v->value); |
123 | free(v); | 124 | free(v); |
124 | } | ||
125 | return 1; | ||
126 | } | 125 | } |
126 | return 1; | ||
127 | } | ||
127 | 128 | ||
128 | char *_CONF_get_string(const CONF *conf, const char *section, const char *name) | 129 | char * |
129 | { | 130 | _CONF_get_string(const CONF *conf, const char *section, const char *name) |
130 | CONF_VALUE *v,vv; | 131 | { |
132 | CONF_VALUE *v, vv; | ||
131 | char *p; | 133 | char *p; |
132 | 134 | ||
133 | if (name == NULL) return(NULL); | 135 | if (name == NULL) |
134 | if (conf != NULL) | 136 | return (NULL); |
135 | { | 137 | if (conf != NULL) { |
136 | if (section != NULL) | 138 | if (section != NULL) { |
137 | { | 139 | vv.name = (char *)name; |
138 | vv.name=(char *)name; | 140 | vv.section = (char *)section; |
139 | vv.section=(char *)section; | 141 | v = lh_CONF_VALUE_retrieve(conf->data, &vv); |
140 | v=lh_CONF_VALUE_retrieve(conf->data,&vv); | 142 | if (v != NULL) |
141 | if (v != NULL) return(v->value); | 143 | return (v->value); |
142 | if (strcmp(section,"ENV") == 0) | 144 | if (strcmp(section, "ENV") == 0) { |
143 | { | 145 | p = getenv(name); |
144 | p=getenv(name); | 146 | if (p != NULL) |
145 | if (p != NULL) return(p); | 147 | return (p); |
146 | } | ||
147 | } | 148 | } |
148 | vv.section="default"; | 149 | } |
149 | vv.name=(char *)name; | 150 | vv.section = "default"; |
150 | v=lh_CONF_VALUE_retrieve(conf->data,&vv); | 151 | vv.name = (char *)name; |
152 | v = lh_CONF_VALUE_retrieve(conf->data, &vv); | ||
151 | if (v != NULL) | 153 | if (v != NULL) |
152 | return(v->value); | 154 | return (v->value); |
153 | else | 155 | else |
154 | return(NULL); | 156 | return (NULL); |
155 | } | 157 | } else |
156 | else | 158 | return (getenv(name)); |
157 | return(getenv(name)); | 159 | } |
158 | } | ||
159 | 160 | ||
160 | #if 0 /* There's no way to provide error checking with this function, so | 161 | #if 0 /* There's no way to provide error checking with this function, so |
161 | force implementors of the higher levels to get a string and read | 162 | force implementors of the higher levels to get a string and read |
162 | the number themselves. */ | 163 | the number themselves. */ |
163 | long _CONF_get_number(CONF *conf, char *section, char *name) | 164 | long |
164 | { | 165 | _CONF_get_number(CONF *conf, char *section, char *name) |
166 | { | ||
165 | char *str; | 167 | char *str; |
166 | long ret=0; | 168 | long ret = 0; |
167 | 169 | ||
168 | str=_CONF_get_string(conf,section,name); | 170 | str = _CONF_get_string(conf, section, name); |
169 | if (str == NULL) return(0); | 171 | if (str == NULL) |
170 | for (;;) | 172 | return (0); |
171 | { | 173 | for (;;) { |
172 | if (conf->meth->is_number(conf, *str)) | 174 | if (conf->meth->is_number(conf, *str)) |
173 | ret=ret*10+conf->meth->to_int(conf, *str); | 175 | ret = ret * 10 + conf->meth->to_int(conf, *str); |
174 | else | 176 | else |
175 | return(ret); | 177 | return (ret); |
176 | str++; | 178 | str++; |
177 | } | ||
178 | } | 179 | } |
180 | } | ||
179 | #endif | 181 | #endif |
180 | 182 | ||
181 | static unsigned long conf_value_hash(const CONF_VALUE *v) | 183 | static unsigned long |
182 | { | 184 | conf_value_hash(const CONF_VALUE *v) |
183 | return (lh_strhash(v->section)<<2)^lh_strhash(v->name); | 185 | { |
184 | } | 186 | return (lh_strhash(v->section) << 2) ^ lh_strhash(v->name); |
187 | } | ||
188 | |||
185 | static IMPLEMENT_LHASH_HASH_FN(conf_value, CONF_VALUE) | 189 | static IMPLEMENT_LHASH_HASH_FN(conf_value, CONF_VALUE) |
186 | 190 | ||
187 | static int conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b) | 191 | static int |
188 | { | 192 | conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b) |
193 | { | ||
189 | int i; | 194 | int i; |
190 | 195 | ||
191 | if (a->section != b->section) | 196 | if (a->section != b->section) { |
192 | { | 197 | i = strcmp(a->section, b->section); |
193 | i=strcmp(a->section,b->section); | 198 | if (i) |
194 | if (i) return(i); | 199 | return (i); |
195 | } | ||
196 | |||
197 | if ((a->name != NULL) && (b->name != NULL)) | ||
198 | { | ||
199 | i=strcmp(a->name,b->name); | ||
200 | return(i); | ||
201 | } | ||
202 | else if (a->name == b->name) | ||
203 | return(0); | ||
204 | else | ||
205 | return((a->name == NULL)?-1:1); | ||
206 | } | 200 | } |
201 | if ((a->name != NULL) && (b->name != NULL)) { | ||
202 | i = strcmp(a->name, b->name); | ||
203 | return (i); | ||
204 | } else if (a->name == b->name) | ||
205 | return (0); | ||
206 | else | ||
207 | return ((a->name == NULL)?-1 : 1); | ||
208 | } | ||
209 | |||
207 | static IMPLEMENT_LHASH_COMP_FN(conf_value, CONF_VALUE) | 210 | static IMPLEMENT_LHASH_COMP_FN(conf_value, CONF_VALUE) |
208 | 211 | ||
209 | int _CONF_new_data(CONF *conf) | 212 | int |
210 | { | 213 | _CONF_new_data(CONF *conf) |
211 | if (conf == NULL) | 214 | { |
212 | { | 215 | if (conf == NULL) { |
213 | return 0; | 216 | return 0; |
214 | } | 217 | } |
215 | if (conf->data == NULL) | 218 | if (conf->data == NULL) |
216 | if ((conf->data = lh_CONF_VALUE_new()) == NULL) | 219 | if ((conf->data = lh_CONF_VALUE_new()) == NULL) { |
217 | { | ||
218 | return 0; | 220 | return 0; |
219 | } | 221 | } |
220 | return 1; | 222 | return 1; |
221 | } | 223 | } |
222 | 224 | ||
223 | void _CONF_free_data(CONF *conf) | 225 | void |
224 | { | 226 | _CONF_free_data(CONF *conf) |
225 | if (conf == NULL || conf->data == NULL) return; | 227 | { |
228 | if (conf == NULL || conf->data == NULL) | ||
229 | return; | ||
226 | 230 | ||
227 | lh_CONF_VALUE_down_load(conf->data)=0; /* evil thing to make | 231 | lh_CONF_VALUE_down_load(conf->data) = 0; /* evil thing to make |
228 | * sure the 'free()' works as | 232 | * sure the 'free()' works as |
229 | * expected */ | 233 | * expected */ |
230 | lh_CONF_VALUE_doall_arg(conf->data, | 234 | lh_CONF_VALUE_doall_arg(conf->data, |
231 | LHASH_DOALL_ARG_FN(value_free_hash), | 235 | LHASH_DOALL_ARG_FN(value_free_hash), |
232 | LHASH_OF(CONF_VALUE), conf->data); | 236 | LHASH_OF(CONF_VALUE), conf->data); |
233 | 237 | ||
234 | /* We now have only 'section' entries in the hash table. | 238 | /* We now have only 'section' entries in the hash table. |
235 | * Due to problems with */ | 239 | * Due to problems with */ |
236 | 240 | ||
237 | lh_CONF_VALUE_doall(conf->data, LHASH_DOALL_FN(value_free_stack)); | 241 | lh_CONF_VALUE_doall(conf->data, LHASH_DOALL_FN(value_free_stack)); |
238 | lh_CONF_VALUE_free(conf->data); | 242 | lh_CONF_VALUE_free(conf->data); |
239 | } | 243 | } |
240 | 244 | ||
241 | static void value_free_hash_doall_arg(CONF_VALUE *a, LHASH_OF(CONF_VALUE) *conf) | 245 | static void |
242 | { | 246 | value_free_hash_doall_arg(CONF_VALUE *a, LHASH_OF(CONF_VALUE) *conf) |
247 | { | ||
243 | if (a->name != NULL) | 248 | if (a->name != NULL) |
244 | (void)lh_CONF_VALUE_delete(conf,a); | 249 | (void)lh_CONF_VALUE_delete(conf, a); |
245 | } | 250 | } |
246 | 251 | ||
247 | static void value_free_stack_doall(CONF_VALUE *a) | 252 | static void |
248 | { | 253 | value_free_stack_doall(CONF_VALUE *a) |
254 | { | ||
249 | CONF_VALUE *vv; | 255 | CONF_VALUE *vv; |
250 | STACK_OF(CONF_VALUE) *sk; | 256 | STACK_OF(CONF_VALUE) *sk; |
251 | int i; | 257 | int i; |
252 | 258 | ||
253 | if (a->name != NULL) return; | 259 | if (a->name != NULL) |
260 | return; | ||
254 | 261 | ||
255 | sk=(STACK_OF(CONF_VALUE) *)a->value; | 262 | sk = (STACK_OF(CONF_VALUE) *)a->value; |
256 | for (i=sk_CONF_VALUE_num(sk)-1; i>=0; i--) | 263 | for (i = sk_CONF_VALUE_num(sk) - 1; i >= 0; i--) { |
257 | { | 264 | vv = sk_CONF_VALUE_value(sk, i); |
258 | vv=sk_CONF_VALUE_value(sk,i); | ||
259 | free(vv->value); | 265 | free(vv->value); |
260 | free(vv->name); | 266 | free(vv->name); |
261 | free(vv); | 267 | free(vv); |
262 | } | 268 | } |
263 | if (sk != NULL) sk_CONF_VALUE_free(sk); | 269 | if (sk != NULL) |
270 | sk_CONF_VALUE_free(sk); | ||
264 | free(a->section); | 271 | free(a->section); |
265 | free(a); | 272 | free(a); |
266 | } | 273 | } |
267 | 274 | ||
268 | /* Up until OpenSSL 0.9.5a, this was new_section */ | 275 | /* Up until OpenSSL 0.9.5a, this was new_section */ |
269 | CONF_VALUE *_CONF_new_section(CONF *conf, const char *section) | 276 | CONF_VALUE * |
270 | { | 277 | _CONF_new_section(CONF *conf, const char *section) |
271 | STACK_OF(CONF_VALUE) *sk=NULL; | 278 | { |
272 | int ok=0,i; | 279 | STACK_OF(CONF_VALUE) *sk = NULL; |
273 | CONF_VALUE *v=NULL,*vv; | 280 | int ok = 0, i; |
274 | 281 | CONF_VALUE *v = NULL, *vv; | |
275 | if ((sk=sk_CONF_VALUE_new_null()) == NULL) | 282 | |
283 | if ((sk = sk_CONF_VALUE_new_null()) == NULL) | ||
276 | goto err; | 284 | goto err; |
277 | if ((v=malloc(sizeof(CONF_VALUE))) == NULL) | 285 | if ((v = malloc(sizeof(CONF_VALUE))) == NULL) |
278 | goto err; | 286 | goto err; |
279 | i=strlen(section)+1; | 287 | i = strlen(section) + 1; |
280 | if ((v->section=malloc(i)) == NULL) | 288 | if ((v->section = malloc(i)) == NULL) |
281 | goto err; | 289 | goto err; |
282 | 290 | ||
283 | memcpy(v->section,section,i); | 291 | memcpy(v->section, section, i); |
284 | v->name=NULL; | 292 | v->name = NULL; |
285 | v->value=(char *)sk; | 293 | v->value = (char *)sk; |
286 | 294 | ||
287 | vv=lh_CONF_VALUE_insert(conf->data,v); | 295 | vv = lh_CONF_VALUE_insert(conf->data, v); |
288 | OPENSSL_assert(vv == NULL); | 296 | OPENSSL_assert(vv == NULL); |
289 | ok=1; | 297 | ok = 1; |
298 | |||
290 | err: | 299 | err: |
291 | if (!ok) | 300 | if (!ok) { |
292 | { | 301 | if (sk != NULL) |
293 | if (sk != NULL) sk_CONF_VALUE_free(sk); | 302 | sk_CONF_VALUE_free(sk); |
294 | if (v != NULL) free(v); | 303 | if (v != NULL) |
295 | v=NULL; | 304 | free(v); |
296 | } | 305 | v = NULL; |
297 | return(v); | ||
298 | } | 306 | } |
307 | return (v); | ||
308 | } | ||
299 | 309 | ||
300 | IMPLEMENT_STACK_OF(CONF_VALUE) | 310 | IMPLEMENT_STACK_OF(CONF_VALUE) |