diff options
Diffstat (limited to 'src/lib/libcrypto/conf/conf_def.c')
-rw-r--r-- | src/lib/libcrypto/conf/conf_def.c | 812 |
1 files changed, 400 insertions, 412 deletions
diff --git a/src/lib/libcrypto/conf/conf_def.c b/src/lib/libcrypto/conf/conf_def.c index 5ab995a5c0..22fe7a8f60 100644 --- a/src/lib/libcrypto/conf/conf_def.c +++ b/src/lib/libcrypto/conf/conf_def.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 |
@@ -72,7 +72,7 @@ | |||
72 | static char *eat_ws(CONF *conf, char *p); | 72 | static char *eat_ws(CONF *conf, char *p); |
73 | static char *eat_alpha_numeric(CONF *conf, char *p); | 73 | static char *eat_alpha_numeric(CONF *conf, char *p); |
74 | static void clear_comments(CONF *conf, char *p); | 74 | static void clear_comments(CONF *conf, char *p); |
75 | static int str_copy(CONF *conf,char *section,char **to, char *from); | 75 | static int str_copy(CONF *conf, char *section, char **to, char *from); |
76 | static char *scan_quote(CONF *conf, char *p); | 76 | static char *scan_quote(CONF *conf, char *p); |
77 | static char *scan_dquote(CONF *conf, char *p); | 77 | static char *scan_dquote(CONF *conf, char *p); |
78 | #define scan_esc(conf,p) (((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2))) | 78 | #define scan_esc(conf,p) (((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2))) |
@@ -101,7 +101,7 @@ static CONF_METHOD default_method = { | |||
101 | def_is_number, | 101 | def_is_number, |
102 | def_to_int, | 102 | def_to_int, |
103 | def_load | 103 | def_load |
104 | }; | 104 | }; |
105 | 105 | ||
106 | static CONF_METHOD WIN32_method = { | 106 | static CONF_METHOD WIN32_method = { |
107 | "WIN32", | 107 | "WIN32", |
@@ -114,33 +114,37 @@ static CONF_METHOD WIN32_method = { | |||
114 | def_is_number, | 114 | def_is_number, |
115 | def_to_int, | 115 | def_to_int, |
116 | def_load | 116 | def_load |
117 | }; | 117 | }; |
118 | 118 | ||
119 | CONF_METHOD *NCONF_default() | 119 | CONF_METHOD * |
120 | { | 120 | NCONF_default() |
121 | { | ||
121 | return &default_method; | 122 | return &default_method; |
122 | } | 123 | } |
123 | CONF_METHOD *NCONF_WIN32() | 124 | |
124 | { | 125 | CONF_METHOD * |
126 | NCONF_WIN32() | ||
127 | { | ||
125 | return &WIN32_method; | 128 | return &WIN32_method; |
126 | } | 129 | } |
127 | 130 | ||
128 | static CONF *def_create(CONF_METHOD *meth) | 131 | static CONF * |
129 | { | 132 | def_create(CONF_METHOD *meth) |
133 | { | ||
130 | CONF *ret; | 134 | CONF *ret; |
131 | 135 | ||
132 | ret = malloc(sizeof(CONF) + sizeof(unsigned short *)); | 136 | ret = malloc(sizeof(CONF) + sizeof(unsigned short *)); |
133 | if (ret) | 137 | if (ret) |
134 | if (meth->init(ret) == 0) | 138 | if (meth->init(ret) == 0) { |
135 | { | ||
136 | free(ret); | 139 | free(ret); |
137 | ret = NULL; | 140 | ret = NULL; |
138 | } | 141 | } |
139 | return ret; | 142 | return ret; |
140 | } | 143 | } |
141 | 144 | ||
142 | static int def_init_default(CONF *conf) | 145 | static int |
143 | { | 146 | def_init_default(CONF *conf) |
147 | { | ||
144 | if (conf == NULL) | 148 | if (conf == NULL) |
145 | return 0; | 149 | return 0; |
146 | 150 | ||
@@ -149,10 +153,11 @@ static int def_init_default(CONF *conf) | |||
149 | conf->data = NULL; | 153 | conf->data = NULL; |
150 | 154 | ||
151 | return 1; | 155 | return 1; |
152 | } | 156 | } |
153 | 157 | ||
154 | static int def_init_WIN32(CONF *conf) | 158 | static int |
155 | { | 159 | def_init_WIN32(CONF *conf) |
160 | { | ||
156 | if (conf == NULL) | 161 | if (conf == NULL) |
157 | return 0; | 162 | return 0; |
158 | 163 | ||
@@ -161,576 +166,559 @@ static int def_init_WIN32(CONF *conf) | |||
161 | conf->data = NULL; | 166 | conf->data = NULL; |
162 | 167 | ||
163 | return 1; | 168 | return 1; |
164 | } | 169 | } |
165 | 170 | ||
166 | static int def_destroy(CONF *conf) | 171 | static int |
167 | { | 172 | def_destroy(CONF *conf) |
168 | if (def_destroy_data(conf)) | 173 | { |
169 | { | 174 | if (def_destroy_data(conf)) { |
170 | free(conf); | 175 | free(conf); |
171 | return 1; | 176 | return 1; |
172 | } | ||
173 | return 0; | ||
174 | } | 177 | } |
178 | return 0; | ||
179 | } | ||
175 | 180 | ||
176 | static int def_destroy_data(CONF *conf) | 181 | static int |
177 | { | 182 | def_destroy_data(CONF *conf) |
183 | { | ||
178 | if (conf == NULL) | 184 | if (conf == NULL) |
179 | return 0; | 185 | return 0; |
180 | _CONF_free_data(conf); | 186 | _CONF_free_data(conf); |
181 | return 1; | 187 | return 1; |
182 | } | 188 | } |
183 | 189 | ||
184 | static int def_load(CONF *conf, const char *name, long *line) | 190 | static int |
185 | { | 191 | def_load(CONF *conf, const char *name, long *line) |
192 | { | ||
186 | int ret; | 193 | int ret; |
187 | BIO *in=NULL; | 194 | BIO *in = NULL; |
188 | 195 | ||
189 | in=BIO_new_file(name, "rb"); | 196 | in = BIO_new_file(name, "rb"); |
190 | if (in == NULL) | 197 | if (in == NULL) { |
191 | { | ||
192 | if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE) | 198 | if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE) |
193 | CONFerr(CONF_F_DEF_LOAD,CONF_R_NO_SUCH_FILE); | 199 | CONFerr(CONF_F_DEF_LOAD, CONF_R_NO_SUCH_FILE); |
194 | else | 200 | else |
195 | CONFerr(CONF_F_DEF_LOAD,ERR_R_SYS_LIB); | 201 | CONFerr(CONF_F_DEF_LOAD, ERR_R_SYS_LIB); |
196 | return 0; | 202 | return 0; |
197 | } | 203 | } |
198 | 204 | ||
199 | ret = def_load_bio(conf, in, line); | 205 | ret = def_load_bio(conf, in, line); |
200 | BIO_free(in); | 206 | BIO_free(in); |
201 | 207 | ||
202 | return ret; | 208 | return ret; |
203 | } | 209 | } |
204 | 210 | ||
205 | static int def_load_bio(CONF *conf, BIO *in, long *line) | 211 | static int |
206 | { | 212 | def_load_bio(CONF *conf, BIO *in, long *line) |
213 | { | ||
207 | /* The macro BUFSIZE conflicts with a system macro in VxWorks */ | 214 | /* The macro BUFSIZE conflicts with a system macro in VxWorks */ |
208 | #define CONFBUFSIZE 512 | 215 | #define CONFBUFSIZE 512 |
209 | int bufnum=0,i,ii; | 216 | int bufnum = 0, i, ii; |
210 | BUF_MEM *buff=NULL; | 217 | BUF_MEM *buff = NULL; |
211 | char *s,*p,*end; | 218 | char *s, *p, *end; |
212 | int again; | 219 | int again; |
213 | long eline=0; | 220 | long eline = 0; |
214 | char btmp[DECIMAL_SIZE(eline)+1]; | 221 | char btmp[DECIMAL_SIZE(eline) + 1]; |
215 | CONF_VALUE *v=NULL,*tv; | 222 | CONF_VALUE *v = NULL, *tv; |
216 | CONF_VALUE *sv=NULL; | 223 | CONF_VALUE *sv = NULL; |
217 | char *section=NULL,*buf; | 224 | char *section = NULL, *buf; |
218 | char *start,*psection,*pname; | 225 | char *start, *psection, *pname; |
219 | void *h = (void *)(conf->data); | 226 | void *h = (void *)(conf->data); |
220 | 227 | ||
221 | if ((buff=BUF_MEM_new()) == NULL) | 228 | if ((buff = BUF_MEM_new()) == NULL) { |
222 | { | 229 | CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_BUF_LIB); |
223 | CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_BUF_LIB); | ||
224 | goto err; | 230 | goto err; |
225 | } | 231 | } |
226 | 232 | ||
227 | section=(char *)malloc(10); | 233 | section = (char *)malloc(10); |
228 | if (section == NULL) | 234 | if (section == NULL) { |
229 | { | 235 | CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE); |
230 | CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_MALLOC_FAILURE); | ||
231 | goto err; | 236 | goto err; |
232 | } | 237 | } |
233 | strlcpy(section,"default",10); | 238 | strlcpy(section, "default",10); |
234 | 239 | ||
235 | if (_CONF_new_data(conf) == 0) | 240 | if (_CONF_new_data(conf) == 0) { |
236 | { | 241 | CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE); |
237 | CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_MALLOC_FAILURE); | ||
238 | goto err; | 242 | goto err; |
239 | } | 243 | } |
240 | 244 | ||
241 | sv=_CONF_new_section(conf,section); | 245 | sv = _CONF_new_section(conf, section); |
242 | if (sv == NULL) | 246 | if (sv == NULL) { |
243 | { | ||
244 | CONFerr(CONF_F_DEF_LOAD_BIO, | 247 | CONFerr(CONF_F_DEF_LOAD_BIO, |
245 | CONF_R_UNABLE_TO_CREATE_NEW_SECTION); | 248 | CONF_R_UNABLE_TO_CREATE_NEW_SECTION); |
246 | goto err; | 249 | goto err; |
247 | } | 250 | } |
248 | 251 | ||
249 | bufnum=0; | 252 | bufnum = 0; |
250 | again=0; | 253 | again = 0; |
251 | for (;;) | 254 | for (;;) { |
252 | { | 255 | if (!BUF_MEM_grow(buff, bufnum + CONFBUFSIZE)) { |
253 | if (!BUF_MEM_grow(buff,bufnum+CONFBUFSIZE)) | 256 | CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_BUF_LIB); |
254 | { | ||
255 | CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_BUF_LIB); | ||
256 | goto err; | 257 | goto err; |
257 | } | 258 | } |
258 | p= &(buff->data[bufnum]); | 259 | p = &(buff->data[bufnum]); |
259 | *p='\0'; | 260 | *p = '\0'; |
260 | BIO_gets(in, p, CONFBUFSIZE-1); | 261 | BIO_gets(in, p, CONFBUFSIZE - 1); |
261 | p[CONFBUFSIZE-1]='\0'; | 262 | p[CONFBUFSIZE - 1] = '\0'; |
262 | ii=i=strlen(p); | 263 | ii = i = strlen(p); |
263 | if (i == 0 && !again) break; | 264 | if (i == 0 && !again) |
264 | again=0; | 265 | break; |
265 | while (i > 0) | 266 | again = 0; |
266 | { | 267 | while (i > 0) { |
267 | if ((p[i-1] != '\r') && (p[i-1] != '\n')) | 268 | if ((p[i - 1] != '\r') && (p[i - 1] != '\n')) |
268 | break; | 269 | break; |
269 | else | 270 | else |
270 | i--; | 271 | i--; |
271 | } | 272 | } |
272 | /* we removed some trailing stuff so there is a new | 273 | /* we removed some trailing stuff so there is a new |
273 | * line on the end. */ | 274 | * line on the end. */ |
274 | if (ii && i == ii) | 275 | if (ii && i == ii) |
275 | again=1; /* long line */ | 276 | again = 1; /* long line */ |
276 | else | 277 | else { |
277 | { | 278 | p[i] = '\0'; |
278 | p[i]='\0'; | ||
279 | eline++; /* another input line */ | 279 | eline++; /* another input line */ |
280 | } | 280 | } |
281 | 281 | ||
282 | /* we now have a line with trailing \r\n removed */ | 282 | /* we now have a line with trailing \r\n removed */ |
283 | 283 | ||
284 | /* i is the number of bytes */ | 284 | /* i is the number of bytes */ |
285 | bufnum+=i; | 285 | bufnum += i; |
286 | 286 | ||
287 | v=NULL; | 287 | v = NULL; |
288 | /* check for line continuation */ | 288 | /* check for line continuation */ |
289 | if (bufnum >= 1) | 289 | if (bufnum >= 1) { |
290 | { | ||
291 | /* If we have bytes and the last char '\\' and | 290 | /* If we have bytes and the last char '\\' and |
292 | * second last char is not '\\' */ | 291 | * second last char is not '\\' */ |
293 | p= &(buff->data[bufnum-1]); | 292 | p = &(buff->data[bufnum - 1]); |
294 | if (IS_ESC(conf,p[0]) && | 293 | if (IS_ESC(conf, p[0]) && |
295 | ((bufnum <= 1) || !IS_ESC(conf,p[-1]))) | 294 | ((bufnum <= 1) || !IS_ESC(conf, p[-1]))) { |
296 | { | ||
297 | bufnum--; | 295 | bufnum--; |
298 | again=1; | 296 | again = 1; |
299 | } | ||
300 | } | 297 | } |
301 | if (again) continue; | 298 | } |
302 | bufnum=0; | 299 | if (again) |
303 | buf=buff->data; | 300 | continue; |
301 | bufnum = 0; | ||
302 | buf = buff->data; | ||
304 | 303 | ||
305 | clear_comments(conf, buf); | 304 | clear_comments(conf, buf); |
306 | s=eat_ws(conf, buf); | 305 | s = eat_ws(conf, buf); |
307 | if (IS_EOF(conf,*s)) continue; /* blank line */ | 306 | if (IS_EOF(conf, *s)) |
308 | if (*s == '[') | 307 | continue; /* blank line */ |
309 | { | 308 | if (*s == '[') { |
310 | char *ss; | 309 | char *ss; |
311 | 310 | ||
312 | s++; | 311 | s++; |
313 | start=eat_ws(conf, s); | 312 | start = eat_ws(conf, s); |
314 | ss=start; | 313 | ss = start; |
315 | again: | 314 | again: |
316 | end=eat_alpha_numeric(conf, ss); | 315 | end = eat_alpha_numeric(conf, ss); |
317 | p=eat_ws(conf, end); | 316 | p = eat_ws(conf, end); |
318 | if (*p != ']') | 317 | if (*p != ']') { |
319 | { | 318 | if (*p != '\0') { |
320 | if (*p != '\0') | 319 | ss = p; |
321 | { | ||
322 | ss=p; | ||
323 | goto again; | 320 | goto again; |
324 | } | 321 | } |
325 | CONFerr(CONF_F_DEF_LOAD_BIO, | 322 | CONFerr(CONF_F_DEF_LOAD_BIO, |
326 | CONF_R_MISSING_CLOSE_SQUARE_BRACKET); | 323 | CONF_R_MISSING_CLOSE_SQUARE_BRACKET); |
327 | goto err; | 324 | goto err; |
328 | } | 325 | } |
329 | *end='\0'; | 326 | *end = '\0'; |
330 | if (!str_copy(conf,NULL,§ion,start)) goto err; | 327 | if (!str_copy(conf, NULL, §ion, start)) |
331 | if ((sv=_CONF_get_section(conf,section)) == NULL) | 328 | goto err; |
332 | sv=_CONF_new_section(conf,section); | 329 | if ((sv = _CONF_get_section(conf, section)) == NULL) |
333 | if (sv == NULL) | 330 | sv = _CONF_new_section(conf, section); |
334 | { | 331 | if (sv == NULL) { |
335 | CONFerr(CONF_F_DEF_LOAD_BIO, | 332 | CONFerr(CONF_F_DEF_LOAD_BIO, |
336 | CONF_R_UNABLE_TO_CREATE_NEW_SECTION); | 333 | CONF_R_UNABLE_TO_CREATE_NEW_SECTION); |
337 | goto err; | 334 | goto err; |
338 | } | 335 | } |
339 | continue; | 336 | continue; |
337 | } else { | ||
338 | pname = s; | ||
339 | psection = NULL; | ||
340 | end = eat_alpha_numeric(conf, s); | ||
341 | if ((end[0] == ':') && (end[1] == ':')) { | ||
342 | *end = '\0'; | ||
343 | end += 2; | ||
344 | psection = pname; | ||
345 | pname = end; | ||
346 | end = eat_alpha_numeric(conf, end); | ||
340 | } | 347 | } |
341 | else | 348 | p = eat_ws(conf, end); |
342 | { | 349 | if (*p != '=') { |
343 | pname=s; | ||
344 | psection=NULL; | ||
345 | end=eat_alpha_numeric(conf, s); | ||
346 | if ((end[0] == ':') && (end[1] == ':')) | ||
347 | { | ||
348 | *end='\0'; | ||
349 | end+=2; | ||
350 | psection=pname; | ||
351 | pname=end; | ||
352 | end=eat_alpha_numeric(conf, end); | ||
353 | } | ||
354 | p=eat_ws(conf, end); | ||
355 | if (*p != '=') | ||
356 | { | ||
357 | CONFerr(CONF_F_DEF_LOAD_BIO, | 350 | CONFerr(CONF_F_DEF_LOAD_BIO, |
358 | CONF_R_MISSING_EQUAL_SIGN); | 351 | CONF_R_MISSING_EQUAL_SIGN); |
359 | goto err; | 352 | goto err; |
360 | } | 353 | } |
361 | *end='\0'; | 354 | *end = '\0'; |
362 | p++; | 355 | p++; |
363 | start=eat_ws(conf, p); | 356 | start = eat_ws(conf, p); |
364 | while (!IS_EOF(conf,*p)) | 357 | while (!IS_EOF(conf, *p)) |
365 | p++; | 358 | p++; |
366 | p--; | 359 | p--; |
367 | while ((p != start) && (IS_WS(conf,*p))) | 360 | while ((p != start) && (IS_WS(conf, *p))) |
368 | p--; | 361 | p--; |
369 | p++; | 362 | p++; |
370 | *p='\0'; | 363 | *p = '\0'; |
371 | 364 | ||
372 | if (!(v=(CONF_VALUE *)malloc(sizeof(CONF_VALUE)))) | 365 | if (!(v = (CONF_VALUE *)malloc(sizeof(CONF_VALUE)))) { |
373 | { | ||
374 | CONFerr(CONF_F_DEF_LOAD_BIO, | 366 | CONFerr(CONF_F_DEF_LOAD_BIO, |
375 | ERR_R_MALLOC_FAILURE); | 367 | ERR_R_MALLOC_FAILURE); |
376 | goto err; | 368 | goto err; |
377 | } | 369 | } |
378 | if (psection == NULL) psection=section; | 370 | if (psection == NULL) |
379 | v->name=(char *)malloc(strlen(pname)+1); | 371 | psection = section; |
380 | v->value=NULL; | 372 | v->name = (char *)malloc(strlen(pname) + 1); |
381 | if (v->name == NULL) | 373 | v->value = NULL; |
382 | { | 374 | if (v->name == NULL) { |
383 | CONFerr(CONF_F_DEF_LOAD_BIO, | 375 | CONFerr(CONF_F_DEF_LOAD_BIO, |
384 | ERR_R_MALLOC_FAILURE); | 376 | ERR_R_MALLOC_FAILURE); |
377 | goto err; | ||
378 | } | ||
379 | strlcpy(v->name, pname, strlen(pname) + 1); | ||
380 | if (!str_copy(conf, psection, &(v->value), start)) | ||
385 | goto err; | 381 | goto err; |
386 | } | ||
387 | strlcpy(v->name,pname,strlen(pname)+1); | ||
388 | if (!str_copy(conf,psection,&(v->value),start)) goto err; | ||
389 | 382 | ||
390 | if (strcmp(psection,section) != 0) | 383 | if (strcmp(psection, section) != 0) { |
391 | { | 384 | if ((tv = _CONF_get_section(conf, psection)) |
392 | if ((tv=_CONF_get_section(conf,psection)) | ||
393 | == NULL) | 385 | == NULL) |
394 | tv=_CONF_new_section(conf,psection); | 386 | tv = _CONF_new_section(conf, psection); |
395 | if (tv == NULL) | 387 | if (tv == NULL) { |
396 | { | ||
397 | CONFerr(CONF_F_DEF_LOAD_BIO, | 388 | CONFerr(CONF_F_DEF_LOAD_BIO, |
398 | CONF_R_UNABLE_TO_CREATE_NEW_SECTION); | 389 | CONF_R_UNABLE_TO_CREATE_NEW_SECTION); |
399 | goto err; | 390 | goto err; |
400 | } | ||
401 | } | 391 | } |
402 | else | 392 | } else |
403 | tv=sv; | 393 | tv = sv; |
404 | #if 1 | 394 | #if 1 |
405 | if (_CONF_add_string(conf, tv, v) == 0) | 395 | if (_CONF_add_string(conf, tv, v) == 0) { |
406 | { | ||
407 | CONFerr(CONF_F_DEF_LOAD_BIO, | 396 | CONFerr(CONF_F_DEF_LOAD_BIO, |
408 | ERR_R_MALLOC_FAILURE); | 397 | ERR_R_MALLOC_FAILURE); |
409 | goto err; | 398 | goto err; |
410 | } | 399 | } |
411 | #else | 400 | #else |
412 | v->section=tv->section; | 401 | v->section = tv->section; |
413 | if (!sk_CONF_VALUE_push(ts,v)) | 402 | if (!sk_CONF_VALUE_push(ts, v)) { |
414 | { | ||
415 | CONFerr(CONF_F_DEF_LOAD_BIO, | 403 | CONFerr(CONF_F_DEF_LOAD_BIO, |
416 | ERR_R_MALLOC_FAILURE); | 404 | ERR_R_MALLOC_FAILURE); |
417 | goto err; | 405 | goto err; |
418 | } | 406 | } |
419 | vv=(CONF_VALUE *)lh_insert(conf->data,v); | 407 | vv = (CONF_VALUE *)lh_insert(conf->data, v); |
420 | if (vv != NULL) | 408 | if (vv != NULL) { |
421 | { | 409 | sk_CONF_VALUE_delete_ptr(ts, vv); |
422 | sk_CONF_VALUE_delete_ptr(ts,vv); | ||
423 | free(vv->name); | 410 | free(vv->name); |
424 | free(vv->value); | 411 | free(vv->value); |
425 | free(vv); | 412 | free(vv); |
426 | } | ||
427 | #endif | ||
428 | v=NULL; | ||
429 | } | 413 | } |
414 | #endif | ||
415 | v = NULL; | ||
430 | } | 416 | } |
431 | if (buff != NULL) BUF_MEM_free(buff); | 417 | } |
432 | if (section != NULL) free(section); | 418 | if (buff != NULL) |
433 | return(1); | 419 | BUF_MEM_free(buff); |
420 | if (section != NULL) | ||
421 | free(section); | ||
422 | return (1); | ||
423 | |||
434 | err: | 424 | err: |
435 | if (buff != NULL) BUF_MEM_free(buff); | 425 | if (buff != NULL) |
436 | if (section != NULL) free(section); | 426 | BUF_MEM_free(buff); |
437 | if (line != NULL) *line=eline; | 427 | if (section != NULL) |
438 | snprintf(btmp,sizeof btmp,"%ld",eline); | 428 | free(section); |
439 | ERR_add_error_data(2,"line ",btmp); | 429 | if (line != NULL) |
440 | if ((h != conf->data) && (conf->data != NULL)) | 430 | *line = eline; |
441 | { | 431 | snprintf(btmp, sizeof btmp, "%ld", eline); |
432 | ERR_add_error_data(2, "line ", btmp); | ||
433 | if ((h != conf->data) && (conf->data != NULL)) { | ||
442 | CONF_free(conf->data); | 434 | CONF_free(conf->data); |
443 | conf->data=NULL; | 435 | conf->data = NULL; |
444 | } | ||
445 | if (v != NULL) | ||
446 | { | ||
447 | if (v->name != NULL) free(v->name); | ||
448 | if (v->value != NULL) free(v->value); | ||
449 | if (v != NULL) free(v); | ||
450 | } | ||
451 | return(0); | ||
452 | } | 436 | } |
453 | 437 | if (v != NULL) { | |
454 | static void clear_comments(CONF *conf, char *p) | 438 | if (v->name != NULL) |
455 | { | 439 | free(v->name); |
456 | for (;;) | 440 | if (v->value != NULL) |
457 | { | 441 | free(v->value); |
458 | if (IS_FCOMMENT(conf,*p)) | 442 | if (v != NULL) |
459 | { | 443 | free(v); |
460 | *p='\0'; | 444 | } |
445 | return (0); | ||
446 | } | ||
447 | |||
448 | static void | ||
449 | clear_comments(CONF *conf, char *p) | ||
450 | { | ||
451 | for (;;) { | ||
452 | if (IS_FCOMMENT(conf, *p)) { | ||
453 | *p = '\0'; | ||
461 | return; | 454 | return; |
462 | } | 455 | } |
463 | if (!IS_WS(conf,*p)) | 456 | if (!IS_WS(conf, *p)) { |
464 | { | ||
465 | break; | 457 | break; |
466 | } | ||
467 | p++; | ||
468 | } | 458 | } |
459 | p++; | ||
460 | } | ||
469 | 461 | ||
470 | for (;;) | 462 | for (;;) { |
471 | { | 463 | if (IS_COMMENT(conf, *p)) { |
472 | if (IS_COMMENT(conf,*p)) | 464 | *p = '\0'; |
473 | { | ||
474 | *p='\0'; | ||
475 | return; | 465 | return; |
476 | } | 466 | } |
477 | if (IS_DQUOTE(conf,*p)) | 467 | if (IS_DQUOTE(conf, *p)) { |
478 | { | 468 | p = scan_dquote(conf, p); |
479 | p=scan_dquote(conf, p); | ||
480 | continue; | 469 | continue; |
481 | } | 470 | } |
482 | if (IS_QUOTE(conf,*p)) | 471 | if (IS_QUOTE(conf, *p)) { |
483 | { | 472 | p = scan_quote(conf, p); |
484 | p=scan_quote(conf, p); | ||
485 | continue; | 473 | continue; |
486 | } | 474 | } |
487 | if (IS_ESC(conf,*p)) | 475 | if (IS_ESC(conf, *p)) { |
488 | { | 476 | p = scan_esc(conf, p); |
489 | p=scan_esc(conf,p); | ||
490 | continue; | 477 | continue; |
491 | } | 478 | } |
492 | if (IS_EOF(conf,*p)) | 479 | if (IS_EOF(conf, *p)) |
493 | return; | 480 | return; |
494 | else | 481 | else |
495 | p++; | 482 | p++; |
496 | } | ||
497 | } | 483 | } |
484 | } | ||
498 | 485 | ||
499 | static int str_copy(CONF *conf, char *section, char **pto, char *from) | 486 | static int |
500 | { | 487 | str_copy(CONF *conf, char *section, char **pto, char *from) |
501 | int q,r,rr=0,to=0,len=0; | 488 | { |
502 | char *s,*e,*rp,*p,*rrp,*np,*cp,v; | 489 | int q, r,rr = 0, to = 0, len = 0; |
490 | char *s, *e, *rp, *p, *rrp, *np, *cp, v; | ||
503 | BUF_MEM *buf; | 491 | BUF_MEM *buf; |
504 | 492 | ||
505 | if ((buf=BUF_MEM_new()) == NULL) return(0); | 493 | if ((buf = BUF_MEM_new()) == NULL) |
494 | return (0); | ||
506 | 495 | ||
507 | len=strlen(from)+1; | 496 | len = strlen(from) + 1; |
508 | if (!BUF_MEM_grow(buf,len)) goto err; | 497 | if (!BUF_MEM_grow(buf, len)) |
498 | goto err; | ||
509 | 499 | ||
510 | for (;;) | 500 | for (;;) { |
511 | { | 501 | if (IS_QUOTE(conf, *from)) { |
512 | if (IS_QUOTE(conf,*from)) | 502 | q = *from; |
513 | { | ||
514 | q= *from; | ||
515 | from++; | 503 | from++; |
516 | while (!IS_EOF(conf,*from) && (*from != q)) | 504 | while (!IS_EOF(conf, *from) && (*from != q)) { |
517 | { | 505 | if (IS_ESC(conf, *from)) { |
518 | if (IS_ESC(conf,*from)) | ||
519 | { | ||
520 | from++; | 506 | from++; |
521 | if (IS_EOF(conf,*from)) break; | 507 | if (IS_EOF(conf, *from)) |
522 | } | 508 | break; |
523 | buf->data[to++]= *(from++); | ||
524 | } | 509 | } |
525 | if (*from == q) from++; | 510 | buf->data[to++] = *(from++); |
526 | } | 511 | } |
527 | else if (IS_DQUOTE(conf,*from)) | 512 | if (*from == q) |
528 | { | 513 | from++; |
529 | q= *from; | 514 | } else if (IS_DQUOTE(conf, *from)) { |
515 | q = *from; | ||
530 | from++; | 516 | from++; |
531 | while (!IS_EOF(conf,*from)) | 517 | while (!IS_EOF(conf, *from)) { |
532 | { | 518 | if (*from == q) { |
533 | if (*from == q) | 519 | if (*(from + 1) == q) { |
534 | { | ||
535 | if (*(from+1) == q) | ||
536 | { | ||
537 | from++; | 520 | from++; |
538 | } | 521 | } else { |
539 | else | ||
540 | { | ||
541 | break; | 522 | break; |
542 | } | ||
543 | } | 523 | } |
544 | buf->data[to++]= *(from++); | ||
545 | } | 524 | } |
546 | if (*from == q) from++; | 525 | buf->data[to++] = *(from++); |
547 | } | 526 | } |
548 | else if (IS_ESC(conf,*from)) | 527 | if (*from == q) |
549 | { | 528 | from++; |
529 | } else if (IS_ESC(conf, *from)) { | ||
550 | from++; | 530 | from++; |
551 | v= *(from++); | 531 | v = *(from++); |
552 | if (IS_EOF(conf,v)) break; | 532 | if (IS_EOF(conf, v)) |
553 | else if (v == 'r') v='\r'; | 533 | break; |
554 | else if (v == 'n') v='\n'; | 534 | else if (v == 'r') |
555 | else if (v == 'b') v='\b'; | 535 | v = '\r'; |
556 | else if (v == 't') v='\t'; | 536 | else if (v == 'n') |
557 | buf->data[to++]= v; | 537 | v = '\n'; |
558 | } | 538 | else if (v == 'b') |
559 | else if (IS_EOF(conf,*from)) | 539 | v = '\b'; |
540 | else if (v == 't') | ||
541 | v = '\t'; | ||
542 | buf->data[to++] = v; | ||
543 | } else if (IS_EOF(conf, *from)) | ||
560 | break; | 544 | break; |
561 | else if (*from == '$') | 545 | else if (*from == '$') { |
562 | { | ||
563 | /* try to expand it */ | 546 | /* try to expand it */ |
564 | rrp=NULL; | 547 | rrp = NULL; |
565 | s= &(from[1]); | 548 | s = &(from[1]); |
566 | if (*s == '{') | 549 | if (*s == '{') |
567 | q='}'; | 550 | q = '}'; |
568 | else if (*s == '(') | 551 | else if (*s == '(') |
569 | q=')'; | 552 | q = ')'; |
570 | else q=0; | 553 | else |
554 | q = 0; | ||
571 | 555 | ||
572 | if (q) s++; | 556 | if (q) |
573 | cp=section; | 557 | s++; |
574 | e=np=s; | 558 | cp = section; |
575 | while (IS_ALPHA_NUMERIC(conf,*e)) | 559 | e = np = s; |
560 | while (IS_ALPHA_NUMERIC(conf, *e)) | ||
576 | e++; | 561 | e++; |
577 | if ((e[0] == ':') && (e[1] == ':')) | 562 | if ((e[0] == ':') && (e[1] == ':')) { |
578 | { | 563 | cp = np; |
579 | cp=np; | 564 | rrp = e; |
580 | rrp=e; | 565 | rr = *e; |
581 | rr= *e; | 566 | *rrp = '\0'; |
582 | *rrp='\0'; | 567 | e += 2; |
583 | e+=2; | 568 | np = e; |
584 | np=e; | 569 | while (IS_ALPHA_NUMERIC(conf, *e)) |
585 | while (IS_ALPHA_NUMERIC(conf,*e)) | ||
586 | e++; | 570 | e++; |
587 | } | 571 | } |
588 | r= *e; | 572 | r = *e; |
589 | *e='\0'; | 573 | *e = '\0'; |
590 | rp=e; | 574 | rp = e; |
591 | if (q) | 575 | if (q) { |
592 | { | 576 | if (r != q) { |
593 | if (r != q) | 577 | CONFerr(CONF_F_STR_COPY, |
594 | { | 578 | CONF_R_NO_CLOSE_BRACE); |
595 | CONFerr(CONF_F_STR_COPY,CONF_R_NO_CLOSE_BRACE); | ||
596 | goto err; | 579 | goto err; |
597 | } | ||
598 | e++; | ||
599 | } | 580 | } |
581 | e++; | ||
582 | } | ||
600 | /* So at this point we have | 583 | /* So at this point we have |
601 | * np which is the start of the name string which is | 584 | * np which is the start of the name string which is |
602 | * '\0' terminated. | 585 | * '\0' terminated. |
603 | * cp which is the start of the section string which is | 586 | * cp which is the start of the section string which is |
604 | * '\0' terminated. | 587 | * '\0' terminated. |
605 | * e is the 'next point after'. | 588 | * e is the 'next point after'. |
606 | * r and rr are the chars replaced by the '\0' | 589 | * r and rr are the chars replaced by the '\0' |
607 | * rp and rrp is where 'r' and 'rr' came from. | 590 | * rp and rrp is where 'r' and 'rr' came from. |
608 | */ | 591 | */ |
609 | p=_CONF_get_string(conf,cp,np); | 592 | p = _CONF_get_string(conf, cp, np); |
610 | if (rrp != NULL) *rrp=rr; | 593 | if (rrp != NULL) |
611 | *rp=r; | 594 | *rrp = rr; |
612 | if (p == NULL) | 595 | *rp = r; |
613 | { | 596 | if (p == NULL) { |
614 | CONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE); | 597 | CONFerr(CONF_F_STR_COPY, |
598 | CONF_R_VARIABLE_HAS_NO_VALUE); | ||
615 | goto err; | 599 | goto err; |
616 | } | 600 | } |
617 | BUF_MEM_grow_clean(buf,(strlen(p)+buf->length-(e-from))); | 601 | BUF_MEM_grow_clean(buf, |
602 | (strlen(p) + buf->length - (e - from))); | ||
618 | while (*p) | 603 | while (*p) |
619 | buf->data[to++]= *(p++); | 604 | buf->data[to++] = *(p++); |
620 | 605 | ||
621 | /* Since we change the pointer 'from', we also have | 606 | /* Since we change the pointer 'from', we also have |
622 | to change the perceived length of the string it | 607 | to change the perceived length of the string it |
623 | points at. /RL */ | 608 | points at. /RL */ |
624 | len -= e-from; | 609 | len -= e - from; |
625 | from=e; | 610 | from = e; |
626 | 611 | ||
627 | /* In case there were no braces or parenthesis around | 612 | /* In case there were no braces or parenthesis around |
628 | the variable reference, we have to put back the | 613 | the variable reference, we have to put back the |
629 | character that was replaced with a '\0'. /RL */ | 614 | character that was replaced with a '\0'. /RL */ |
630 | *rp = r; | 615 | *rp = r; |
631 | } | 616 | } else |
632 | else | 617 | buf->data[to++] = *(from++); |
633 | buf->data[to++]= *(from++); | 618 | } |
634 | } | ||
635 | buf->data[to]='\0'; | 619 | buf->data[to]='\0'; |
636 | if (*pto != NULL) free(*pto); | 620 | if (*pto != NULL) |
637 | *pto=buf->data; | 621 | free(*pto); |
622 | *pto = buf->data; | ||
638 | free(buf); | 623 | free(buf); |
639 | return(1); | 624 | return (1); |
640 | err: | ||
641 | if (buf != NULL) BUF_MEM_free(buf); | ||
642 | return(0); | ||
643 | } | ||
644 | 625 | ||
645 | static char *eat_ws(CONF *conf, char *p) | 626 | err: |
646 | { | 627 | if (buf != NULL) |
647 | while (IS_WS(conf,*p) && (!IS_EOF(conf,*p))) | 628 | BUF_MEM_free(buf); |
629 | return (0); | ||
630 | } | ||
631 | |||
632 | static char * | ||
633 | eat_ws(CONF *conf, char *p) | ||
634 | { | ||
635 | while (IS_WS(conf, *p) && (!IS_EOF(conf, *p))) | ||
648 | p++; | 636 | p++; |
649 | return(p); | 637 | return (p); |
650 | } | 638 | } |
651 | 639 | ||
652 | static char *eat_alpha_numeric(CONF *conf, char *p) | 640 | static char * |
653 | { | 641 | eat_alpha_numeric(CONF *conf, char *p) |
654 | for (;;) | 642 | { |
655 | { | 643 | for (;;) { |
656 | if (IS_ESC(conf,*p)) | 644 | if (IS_ESC(conf, *p)) { |
657 | { | 645 | p = scan_esc(conf, p); |
658 | p=scan_esc(conf,p); | ||
659 | continue; | 646 | continue; |
660 | } | ||
661 | if (!IS_ALPHA_NUMERIC_PUNCT(conf,*p)) | ||
662 | return(p); | ||
663 | p++; | ||
664 | } | 647 | } |
648 | if (!IS_ALPHA_NUMERIC_PUNCT(conf, *p)) | ||
649 | return (p); | ||
650 | p++; | ||
665 | } | 651 | } |
652 | } | ||
666 | 653 | ||
667 | static char *scan_quote(CONF *conf, char *p) | 654 | static char * |
668 | { | 655 | scan_quote(CONF *conf, char *p) |
669 | int q= *p; | 656 | { |
657 | int q = *p; | ||
670 | 658 | ||
671 | p++; | 659 | p++; |
672 | while (!(IS_EOF(conf,*p)) && (*p != q)) | 660 | while (!(IS_EOF(conf, *p)) && (*p != q)) { |
673 | { | 661 | if (IS_ESC(conf, *p)) { |
674 | if (IS_ESC(conf,*p)) | ||
675 | { | ||
676 | p++; | 662 | p++; |
677 | if (IS_EOF(conf,*p)) return(p); | 663 | if (IS_EOF(conf, *p)) |
678 | } | 664 | return (p); |
679 | p++; | ||
680 | } | 665 | } |
681 | if (*p == q) p++; | 666 | p++; |
682 | return(p); | ||
683 | } | 667 | } |
668 | if (*p == q) | ||
669 | p++; | ||
670 | return (p); | ||
671 | } | ||
684 | 672 | ||
685 | 673 | ||
686 | static char *scan_dquote(CONF *conf, char *p) | 674 | static char * |
687 | { | 675 | scan_dquote(CONF *conf, char *p) |
688 | int q= *p; | 676 | { |
677 | int q = *p; | ||
689 | 678 | ||
690 | p++; | 679 | p++; |
691 | while (!(IS_EOF(conf,*p))) | 680 | while (!(IS_EOF(conf, *p))) { |
692 | { | 681 | if (*p == q) { |
693 | if (*p == q) | 682 | if (*(p + 1) == q) { |
694 | { | ||
695 | if (*(p+1) == q) | ||
696 | { | ||
697 | p++; | 683 | p++; |
698 | } | 684 | } else { |
699 | else | ||
700 | { | ||
701 | break; | 685 | break; |
702 | } | ||
703 | } | 686 | } |
704 | p++; | ||
705 | } | 687 | } |
706 | if (*p == q) p++; | 688 | p++; |
707 | return(p); | ||
708 | } | 689 | } |
690 | if (*p == q) | ||
691 | p++; | ||
692 | return (p); | ||
693 | } | ||
709 | 694 | ||
710 | static void dump_value_doall_arg(CONF_VALUE *a, BIO *out) | 695 | static void |
711 | { | 696 | dump_value_doall_arg(CONF_VALUE *a, BIO *out) |
697 | { | ||
712 | if (a->name) | 698 | if (a->name) |
713 | BIO_printf(out, "[%s] %s=%s\n", a->section, a->name, a->value); | 699 | BIO_printf(out, "[%s] %s=%s\n", a->section, a->name, a->value); |
714 | else | 700 | else |
715 | BIO_printf(out, "[[%s]]\n", a->section); | 701 | BIO_printf(out, "[[%s]]\n", a->section); |
716 | } | 702 | } |
717 | 703 | ||
718 | static IMPLEMENT_LHASH_DOALL_ARG_FN(dump_value, CONF_VALUE, BIO) | 704 | static IMPLEMENT_LHASH_DOALL_ARG_FN(dump_value, CONF_VALUE, BIO) |
719 | 705 | ||
720 | static int def_dump(const CONF *conf, BIO *out) | 706 | static int |
721 | { | 707 | def_dump(const CONF *conf, BIO *out) |
708 | { | ||
722 | lh_CONF_VALUE_doall_arg(conf->data, LHASH_DOALL_ARG_FN(dump_value), | 709 | lh_CONF_VALUE_doall_arg(conf->data, LHASH_DOALL_ARG_FN(dump_value), |
723 | BIO, out); | 710 | BIO, out); |
724 | return 1; | 711 | return 1; |
725 | } | 712 | } |
726 | 713 | ||
727 | static int def_is_number(const CONF *conf, char c) | 714 | static int |
728 | { | 715 | def_is_number(const CONF *conf, char c) |
729 | return IS_NUMBER(conf,c); | 716 | { |
730 | } | 717 | return IS_NUMBER(conf, c); |
718 | } | ||
731 | 719 | ||
732 | static int def_to_int(const CONF *conf, char c) | 720 | static int |
733 | { | 721 | def_to_int(const CONF *conf, char c) |
722 | { | ||
734 | return c - '0'; | 723 | return c - '0'; |
735 | } | 724 | } |
736 | |||