/src/libressl/crypto/conf/conf_def.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* $OpenBSD: conf_def.c,v 1.33 2020/02/17 12:51:48 inoguchi Exp $ */ |
2 | | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | | * All rights reserved. |
4 | | * |
5 | | * This package is an SSL implementation written |
6 | | * by Eric Young (eay@cryptsoft.com). |
7 | | * The implementation was written so as to conform with Netscapes SSL. |
8 | | * |
9 | | * This library is free for commercial and non-commercial use as long as |
10 | | * the following conditions are aheared to. The following conditions |
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 |
13 | | * included with this distribution is covered by the same copyright terms |
14 | | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | | * |
16 | | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | | * the code are not to be removed. |
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. |
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. |
22 | | * |
23 | | * Redistribution and use in source and binary forms, with or without |
24 | | * modification, are permitted provided that the following conditions |
25 | | * are met: |
26 | | * 1. Redistributions of source code must retain the copyright |
27 | | * notice, this list of conditions and the following disclaimer. |
28 | | * 2. Redistributions in binary form must reproduce the above copyright |
29 | | * notice, this list of conditions and the following disclaimer in the |
30 | | * documentation and/or other materials provided with the distribution. |
31 | | * 3. All advertising materials mentioning features or use of this software |
32 | | * must display the following acknowledgement: |
33 | | * "This product includes cryptographic software written by |
34 | | * Eric Young (eay@cryptsoft.com)" |
35 | | * The word 'cryptographic' can be left out if the rouines from the library |
36 | | * being used are not cryptographic related :-). |
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: |
39 | | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | | * |
41 | | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
44 | | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
45 | | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
46 | | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
47 | | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
48 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
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 |
51 | | * SUCH DAMAGE. |
52 | | * |
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 |
55 | | * copied and put under another distribution licence |
56 | | * [including the GNU Public Licence.] |
57 | | */ |
58 | | |
59 | | /* Part of the code in here was originally in conf.c, which is now removed */ |
60 | | |
61 | | #include <stdio.h> |
62 | | #include <string.h> |
63 | | |
64 | | #include <openssl/buffer.h> |
65 | | #include <openssl/conf.h> |
66 | | #include <openssl/conf_api.h> |
67 | | #include <openssl/err.h> |
68 | | #include <openssl/lhash.h> |
69 | | #include <openssl/stack.h> |
70 | | |
71 | | #include "conf_def.h" |
72 | | |
73 | 0 | #define MAX_CONF_VALUE_LENGTH 65536 |
74 | | |
75 | | static char *eat_ws(CONF *conf, char *p); |
76 | | static char *eat_alpha_numeric(CONF *conf, char *p); |
77 | | static void clear_comments(CONF *conf, char *p); |
78 | | static int str_copy(CONF *conf, char *section, char **to, char *from); |
79 | | static char *scan_quote(CONF *conf, char *p); |
80 | | static char *scan_dquote(CONF *conf, char *p); |
81 | 0 | #define scan_esc(conf,p) (((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2))) |
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 | 0 | { |
123 | 0 | return &default_method; |
124 | 0 | } |
125 | | |
126 | | CONF_METHOD * |
127 | | NCONF_WIN32(void) |
128 | 0 | { |
129 | 0 | return &WIN32_method; |
130 | 0 | } |
131 | | |
132 | | static CONF * |
133 | | def_create(CONF_METHOD *meth) |
134 | 0 | { |
135 | 0 | CONF *ret; |
136 | |
|
137 | 0 | ret = malloc(sizeof(CONF) + sizeof(unsigned short *)); |
138 | 0 | if (ret) |
139 | 0 | if (meth->init(ret) == 0) { |
140 | 0 | free(ret); |
141 | 0 | ret = NULL; |
142 | 0 | } |
143 | 0 | return ret; |
144 | 0 | } |
145 | | |
146 | | static int |
147 | | def_init_default(CONF *conf) |
148 | 0 | { |
149 | 0 | if (conf == NULL) |
150 | 0 | return 0; |
151 | | |
152 | 0 | conf->meth = &default_method; |
153 | 0 | conf->meth_data = CONF_type_default; |
154 | 0 | conf->data = NULL; |
155 | |
|
156 | 0 | return 1; |
157 | 0 | } |
158 | | |
159 | | static int |
160 | | def_init_WIN32(CONF *conf) |
161 | 0 | { |
162 | 0 | if (conf == NULL) |
163 | 0 | return 0; |
164 | | |
165 | 0 | conf->meth = &WIN32_method; |
166 | 0 | conf->meth_data = (void *)CONF_type_win32; |
167 | 0 | conf->data = NULL; |
168 | |
|
169 | 0 | return 1; |
170 | 0 | } |
171 | | |
172 | | static int |
173 | | def_destroy(CONF *conf) |
174 | 0 | { |
175 | 0 | if (def_destroy_data(conf)) { |
176 | 0 | free(conf); |
177 | 0 | return 1; |
178 | 0 | } |
179 | 0 | return 0; |
180 | 0 | } |
181 | | |
182 | | static int |
183 | | def_destroy_data(CONF *conf) |
184 | 0 | { |
185 | 0 | if (conf == NULL) |
186 | 0 | return 0; |
187 | 0 | _CONF_free_data(conf); |
188 | 0 | return 1; |
189 | 0 | } |
190 | | |
191 | | static int |
192 | | def_load(CONF *conf, const char *name, long *line) |
193 | 0 | { |
194 | 0 | int ret; |
195 | 0 | BIO *in = NULL; |
196 | |
|
197 | 0 | in = BIO_new_file(name, "rb"); |
198 | 0 | if (in == NULL) { |
199 | 0 | if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE) |
200 | 0 | CONFerror(CONF_R_NO_SUCH_FILE); |
201 | 0 | else |
202 | 0 | CONFerror(ERR_R_SYS_LIB); |
203 | 0 | return 0; |
204 | 0 | } |
205 | | |
206 | 0 | ret = def_load_bio(conf, in, line); |
207 | 0 | BIO_free(in); |
208 | |
|
209 | 0 | return ret; |
210 | 0 | } |
211 | | |
212 | | static int |
213 | | def_load_bio(CONF *conf, BIO *in, long *line) |
214 | 0 | { |
215 | | /* The macro BUFSIZE conflicts with a system macro in VxWorks */ |
216 | 0 | #define CONFBUFSIZE 512 |
217 | 0 | int bufnum = 0, i, ii; |
218 | 0 | BUF_MEM *buff = NULL; |
219 | 0 | char *s, *p, *end; |
220 | 0 | int again; |
221 | 0 | long eline = 0; |
222 | 0 | CONF_VALUE *v = NULL, *tv; |
223 | 0 | CONF_VALUE *sv = NULL; |
224 | 0 | char *section = NULL, *buf; |
225 | 0 | char *start, *psection, *pname; |
226 | 0 | void *h = (void *)(conf->data); |
227 | |
|
228 | 0 | if ((buff = BUF_MEM_new()) == NULL) { |
229 | 0 | CONFerror(ERR_R_BUF_LIB); |
230 | 0 | goto err; |
231 | 0 | } |
232 | | |
233 | 0 | section = strdup("default"); |
234 | 0 | if (section == NULL) { |
235 | 0 | CONFerror(ERR_R_MALLOC_FAILURE); |
236 | 0 | goto err; |
237 | 0 | } |
238 | | |
239 | 0 | if (_CONF_new_data(conf) == 0) { |
240 | 0 | CONFerror(ERR_R_MALLOC_FAILURE); |
241 | 0 | goto err; |
242 | 0 | } |
243 | | |
244 | 0 | sv = _CONF_new_section(conf, section); |
245 | 0 | if (sv == NULL) { |
246 | 0 | CONFerror(CONF_R_UNABLE_TO_CREATE_NEW_SECTION); |
247 | 0 | goto err; |
248 | 0 | } |
249 | | |
250 | 0 | bufnum = 0; |
251 | 0 | again = 0; |
252 | 0 | for (;;) { |
253 | 0 | if (!BUF_MEM_grow(buff, bufnum + CONFBUFSIZE)) { |
254 | 0 | CONFerror(ERR_R_BUF_LIB); |
255 | 0 | goto err; |
256 | 0 | } |
257 | 0 | p = &(buff->data[bufnum]); |
258 | 0 | *p = '\0'; |
259 | 0 | BIO_gets(in, p, CONFBUFSIZE - 1); |
260 | 0 | p[CONFBUFSIZE - 1] = '\0'; |
261 | 0 | ii = i = strlen(p); |
262 | 0 | if (i == 0 && !again) |
263 | 0 | break; |
264 | 0 | again = 0; |
265 | 0 | while (i > 0) { |
266 | 0 | if ((p[i - 1] != '\r') && (p[i - 1] != '\n')) |
267 | 0 | break; |
268 | 0 | else |
269 | 0 | i--; |
270 | 0 | } |
271 | | /* we removed some trailing stuff so there is a new |
272 | | * line on the end. */ |
273 | 0 | if (ii && i == ii) |
274 | 0 | again = 1; /* long line */ |
275 | 0 | else { |
276 | 0 | p[i] = '\0'; |
277 | 0 | eline++; /* another input line */ |
278 | 0 | } |
279 | | |
280 | | /* we now have a line with trailing \r\n removed */ |
281 | | |
282 | | /* i is the number of bytes */ |
283 | 0 | bufnum += i; |
284 | |
|
285 | 0 | v = NULL; |
286 | | /* check for line continuation */ |
287 | 0 | if (bufnum >= 1) { |
288 | | /* If we have bytes and the last char '\\' and |
289 | | * second last char is not '\\' */ |
290 | 0 | p = &(buff->data[bufnum - 1]); |
291 | 0 | if (IS_ESC(conf, p[0]) && |
292 | 0 | ((bufnum <= 1) || !IS_ESC(conf, p[-1]))) { |
293 | 0 | bufnum--; |
294 | 0 | again = 1; |
295 | 0 | } |
296 | 0 | } |
297 | 0 | if (again) |
298 | 0 | continue; |
299 | 0 | bufnum = 0; |
300 | 0 | buf = buff->data; |
301 | |
|
302 | 0 | clear_comments(conf, buf); |
303 | 0 | s = eat_ws(conf, buf); |
304 | 0 | if (IS_EOF(conf, *s)) |
305 | 0 | continue; /* blank line */ |
306 | 0 | if (*s == '[') { |
307 | 0 | char *ss; |
308 | |
|
309 | 0 | s++; |
310 | 0 | start = eat_ws(conf, s); |
311 | 0 | ss = start; |
312 | 0 | again: |
313 | 0 | end = eat_alpha_numeric(conf, ss); |
314 | 0 | p = eat_ws(conf, end); |
315 | 0 | if (*p != ']') { |
316 | 0 | if (*p != '\0' && ss != p) { |
317 | 0 | ss = p; |
318 | 0 | goto again; |
319 | 0 | } |
320 | 0 | CONFerror(CONF_R_MISSING_CLOSE_SQUARE_BRACKET); |
321 | 0 | goto err; |
322 | 0 | } |
323 | 0 | *end = '\0'; |
324 | 0 | if (!str_copy(conf, NULL, §ion, start)) |
325 | 0 | goto err; |
326 | 0 | if ((sv = _CONF_get_section(conf, section)) == NULL) |
327 | 0 | sv = _CONF_new_section(conf, section); |
328 | 0 | if (sv == NULL) { |
329 | 0 | CONFerror(CONF_R_UNABLE_TO_CREATE_NEW_SECTION); |
330 | 0 | goto err; |
331 | 0 | } |
332 | 0 | continue; |
333 | 0 | } else { |
334 | 0 | pname = s; |
335 | 0 | psection = NULL; |
336 | 0 | end = eat_alpha_numeric(conf, s); |
337 | 0 | if ((end[0] == ':') && (end[1] == ':')) { |
338 | 0 | *end = '\0'; |
339 | 0 | end += 2; |
340 | 0 | psection = pname; |
341 | 0 | pname = end; |
342 | 0 | end = eat_alpha_numeric(conf, end); |
343 | 0 | } |
344 | 0 | p = eat_ws(conf, end); |
345 | 0 | if (*p != '=') { |
346 | 0 | CONFerror(CONF_R_MISSING_EQUAL_SIGN); |
347 | 0 | goto err; |
348 | 0 | } |
349 | 0 | *end = '\0'; |
350 | 0 | p++; |
351 | 0 | start = eat_ws(conf, p); |
352 | 0 | while (!IS_EOF(conf, *p)) |
353 | 0 | p++; |
354 | 0 | p--; |
355 | 0 | while ((p != start) && (IS_WS(conf, *p))) |
356 | 0 | p--; |
357 | 0 | p++; |
358 | 0 | *p = '\0'; |
359 | |
|
360 | 0 | if (!(v = malloc(sizeof(CONF_VALUE)))) { |
361 | 0 | CONFerror(ERR_R_MALLOC_FAILURE); |
362 | 0 | goto err; |
363 | 0 | } |
364 | 0 | if (psection == NULL) |
365 | 0 | psection = section; |
366 | 0 | v->name = strdup(pname); |
367 | 0 | v->value = NULL; |
368 | 0 | if (v->name == NULL) { |
369 | 0 | CONFerror(ERR_R_MALLOC_FAILURE); |
370 | 0 | goto err; |
371 | 0 | } |
372 | 0 | if (!str_copy(conf, psection, &(v->value), start)) |
373 | 0 | goto err; |
374 | | |
375 | 0 | if (strcmp(psection, section) != 0) { |
376 | 0 | if ((tv = _CONF_get_section(conf, psection)) |
377 | 0 | == NULL) |
378 | 0 | tv = _CONF_new_section(conf, psection); |
379 | 0 | if (tv == NULL) { |
380 | 0 | CONFerror(CONF_R_UNABLE_TO_CREATE_NEW_SECTION); |
381 | 0 | goto err; |
382 | 0 | } |
383 | 0 | } else |
384 | 0 | tv = sv; |
385 | | |
386 | 0 | if (_CONF_add_string(conf, tv, v) == 0) { |
387 | 0 | CONFerror(ERR_R_MALLOC_FAILURE); |
388 | 0 | goto err; |
389 | 0 | } |
390 | 0 | v = NULL; |
391 | 0 | } |
392 | 0 | } |
393 | 0 | if (buff != NULL) |
394 | 0 | BUF_MEM_free(buff); |
395 | 0 | free(section); |
396 | 0 | return (1); |
397 | | |
398 | 0 | err: |
399 | 0 | if (buff != NULL) |
400 | 0 | BUF_MEM_free(buff); |
401 | 0 | free(section); |
402 | 0 | if (line != NULL) |
403 | 0 | *line = eline; |
404 | 0 | ERR_asprintf_error_data("line %ld", eline); |
405 | 0 | if ((h != conf->data) && (conf->data != NULL)) { |
406 | 0 | CONF_free(conf->data); |
407 | 0 | conf->data = NULL; |
408 | 0 | } |
409 | 0 | if (v != NULL) { |
410 | 0 | free(v->name); |
411 | 0 | free(v->value); |
412 | 0 | free(v); |
413 | 0 | } |
414 | 0 | return (0); |
415 | 0 | } |
416 | | |
417 | | static void |
418 | | clear_comments(CONF *conf, char *p) |
419 | 0 | { |
420 | 0 | for (;;) { |
421 | 0 | if (IS_FCOMMENT(conf, *p)) { |
422 | 0 | *p = '\0'; |
423 | 0 | return; |
424 | 0 | } |
425 | 0 | if (!IS_WS(conf, *p)) { |
426 | 0 | break; |
427 | 0 | } |
428 | 0 | p++; |
429 | 0 | } |
430 | | |
431 | 0 | for (;;) { |
432 | 0 | if (IS_COMMENT(conf, *p)) { |
433 | 0 | *p = '\0'; |
434 | 0 | return; |
435 | 0 | } |
436 | 0 | if (IS_DQUOTE(conf, *p)) { |
437 | 0 | p = scan_dquote(conf, p); |
438 | 0 | continue; |
439 | 0 | } |
440 | 0 | if (IS_QUOTE(conf, *p)) { |
441 | 0 | p = scan_quote(conf, p); |
442 | 0 | continue; |
443 | 0 | } |
444 | 0 | if (IS_ESC(conf, *p)) { |
445 | 0 | p = scan_esc(conf, p); |
446 | 0 | continue; |
447 | 0 | } |
448 | 0 | if (IS_EOF(conf, *p)) |
449 | 0 | return; |
450 | 0 | else |
451 | 0 | p++; |
452 | 0 | } |
453 | 0 | } |
454 | | |
455 | | static int |
456 | | str_copy(CONF *conf, char *section, char **pto, char *from) |
457 | 0 | { |
458 | 0 | int q, r,rr = 0, to = 0, len = 0; |
459 | 0 | char *s, *e, *rp, *p, *rrp, *np, *cp, v; |
460 | 0 | size_t newsize; |
461 | 0 | BUF_MEM *buf; |
462 | |
|
463 | 0 | if ((buf = BUF_MEM_new()) == NULL) |
464 | 0 | return (0); |
465 | | |
466 | 0 | len = strlen(from) + 1; |
467 | 0 | if (!BUF_MEM_grow(buf, len)) |
468 | 0 | goto err; |
469 | | |
470 | 0 | for (;;) { |
471 | 0 | if (IS_QUOTE(conf, *from)) { |
472 | 0 | q = *from; |
473 | 0 | from++; |
474 | 0 | while (!IS_EOF(conf, *from) && (*from != q)) { |
475 | 0 | if (IS_ESC(conf, *from)) { |
476 | 0 | from++; |
477 | 0 | if (IS_EOF(conf, *from)) |
478 | 0 | break; |
479 | 0 | } |
480 | 0 | buf->data[to++] = *(from++); |
481 | 0 | } |
482 | 0 | if (*from == q) |
483 | 0 | from++; |
484 | 0 | } else if (IS_DQUOTE(conf, *from)) { |
485 | 0 | q = *from; |
486 | 0 | from++; |
487 | 0 | while (!IS_EOF(conf, *from)) { |
488 | 0 | if (*from == q) { |
489 | 0 | if (*(from + 1) == q) { |
490 | 0 | from++; |
491 | 0 | } else { |
492 | 0 | break; |
493 | 0 | } |
494 | 0 | } |
495 | 0 | buf->data[to++] = *(from++); |
496 | 0 | } |
497 | 0 | if (*from == q) |
498 | 0 | from++; |
499 | 0 | } else if (IS_ESC(conf, *from)) { |
500 | 0 | from++; |
501 | 0 | v = *(from++); |
502 | 0 | if (IS_EOF(conf, v)) |
503 | 0 | break; |
504 | 0 | else if (v == 'r') |
505 | 0 | v = '\r'; |
506 | 0 | else if (v == 'n') |
507 | 0 | v = '\n'; |
508 | 0 | else if (v == 'b') |
509 | 0 | v = '\b'; |
510 | 0 | else if (v == 't') |
511 | 0 | v = '\t'; |
512 | 0 | buf->data[to++] = v; |
513 | 0 | } else if (IS_EOF(conf, *from)) |
514 | 0 | break; |
515 | 0 | else if (*from == '$') { |
516 | | /* try to expand it */ |
517 | 0 | rrp = NULL; |
518 | 0 | s = &(from[1]); |
519 | 0 | if (*s == '{') |
520 | 0 | q = '}'; |
521 | 0 | else if (*s == '(') |
522 | 0 | q = ')'; |
523 | 0 | else |
524 | 0 | q = 0; |
525 | |
|
526 | 0 | if (q) |
527 | 0 | s++; |
528 | 0 | cp = section; |
529 | 0 | e = np = s; |
530 | 0 | while (IS_ALPHA_NUMERIC(conf, *e)) |
531 | 0 | e++; |
532 | 0 | if ((e[0] == ':') && (e[1] == ':')) { |
533 | 0 | cp = np; |
534 | 0 | rrp = e; |
535 | 0 | rr = *e; |
536 | 0 | *rrp = '\0'; |
537 | 0 | e += 2; |
538 | 0 | np = e; |
539 | 0 | while (IS_ALPHA_NUMERIC(conf, *e)) |
540 | 0 | e++; |
541 | 0 | } |
542 | 0 | r = *e; |
543 | 0 | *e = '\0'; |
544 | 0 | rp = e; |
545 | 0 | if (q) { |
546 | 0 | if (r != q) { |
547 | 0 | CONFerror(CONF_R_NO_CLOSE_BRACE); |
548 | 0 | goto err; |
549 | 0 | } |
550 | 0 | e++; |
551 | 0 | } |
552 | | /* So at this point we have |
553 | | * np which is the start of the name string which is |
554 | | * '\0' terminated. |
555 | | * cp which is the start of the section string which is |
556 | | * '\0' terminated. |
557 | | * e is the 'next point after'. |
558 | | * r and rr are the chars replaced by the '\0' |
559 | | * rp and rrp is where 'r' and 'rr' came from. |
560 | | */ |
561 | 0 | p = _CONF_get_string(conf, cp, np); |
562 | 0 | if (rrp != NULL) |
563 | 0 | *rrp = rr; |
564 | 0 | *rp = r; |
565 | 0 | if (p == NULL) { |
566 | 0 | CONFerror(CONF_R_VARIABLE_HAS_NO_VALUE); |
567 | 0 | goto err; |
568 | 0 | } |
569 | 0 | newsize = strlen(p) + buf->length - (e - from); |
570 | 0 | if (newsize > MAX_CONF_VALUE_LENGTH) { |
571 | 0 | CONFerror(CONF_R_VARIABLE_EXPANSION_TOO_LONG); |
572 | 0 | goto err; |
573 | 0 | } |
574 | 0 | if (!BUF_MEM_grow_clean(buf, newsize)) { |
575 | 0 | CONFerror(CONF_R_MODULE_INITIALIZATION_ERROR); |
576 | 0 | goto err; |
577 | 0 | } |
578 | 0 | while (*p) |
579 | 0 | buf->data[to++] = *(p++); |
580 | | |
581 | | /* Since we change the pointer 'from', we also have |
582 | | to change the perceived length of the string it |
583 | | points at. /RL */ |
584 | 0 | len -= e - from; |
585 | 0 | from = e; |
586 | | |
587 | | /* In case there were no braces or parenthesis around |
588 | | the variable reference, we have to put back the |
589 | | character that was replaced with a '\0'. /RL */ |
590 | 0 | *rp = r; |
591 | 0 | } else |
592 | 0 | buf->data[to++] = *(from++); |
593 | 0 | } |
594 | 0 | buf->data[to]='\0'; |
595 | 0 | free(*pto); |
596 | 0 | *pto = buf->data; |
597 | 0 | free(buf); |
598 | 0 | return (1); |
599 | | |
600 | 0 | err: |
601 | 0 | if (buf != NULL) |
602 | 0 | BUF_MEM_free(buf); |
603 | 0 | return (0); |
604 | 0 | } |
605 | | |
606 | | static char * |
607 | | eat_ws(CONF *conf, char *p) |
608 | 0 | { |
609 | 0 | while (IS_WS(conf, *p) && (!IS_EOF(conf, *p))) |
610 | 0 | p++; |
611 | 0 | return (p); |
612 | 0 | } |
613 | | |
614 | | static char * |
615 | | eat_alpha_numeric(CONF *conf, char *p) |
616 | 0 | { |
617 | 0 | for (;;) { |
618 | 0 | if (IS_ESC(conf, *p)) { |
619 | 0 | p = scan_esc(conf, p); |
620 | 0 | continue; |
621 | 0 | } |
622 | 0 | if (!IS_ALPHA_NUMERIC_PUNCT(conf, *p)) |
623 | 0 | return (p); |
624 | 0 | p++; |
625 | 0 | } |
626 | 0 | } |
627 | | |
628 | | static char * |
629 | | scan_quote(CONF *conf, char *p) |
630 | 0 | { |
631 | 0 | int q = *p; |
632 | |
|
633 | 0 | p++; |
634 | 0 | while (!(IS_EOF(conf, *p)) && (*p != q)) { |
635 | 0 | if (IS_ESC(conf, *p)) { |
636 | 0 | p++; |
637 | 0 | if (IS_EOF(conf, *p)) |
638 | 0 | return (p); |
639 | 0 | } |
640 | 0 | p++; |
641 | 0 | } |
642 | 0 | if (*p == q) |
643 | 0 | p++; |
644 | 0 | return (p); |
645 | 0 | } |
646 | | |
647 | | |
648 | | static char * |
649 | | scan_dquote(CONF *conf, char *p) |
650 | 0 | { |
651 | 0 | int q = *p; |
652 | |
|
653 | 0 | p++; |
654 | 0 | while (!(IS_EOF(conf, *p))) { |
655 | 0 | if (*p == q) { |
656 | 0 | if (*(p + 1) == q) { |
657 | 0 | p++; |
658 | 0 | } else { |
659 | 0 | break; |
660 | 0 | } |
661 | 0 | } |
662 | 0 | p++; |
663 | 0 | } |
664 | 0 | if (*p == q) |
665 | 0 | p++; |
666 | 0 | return (p); |
667 | 0 | } |
668 | | |
669 | | static void |
670 | | dump_value_doall_arg(CONF_VALUE *a, BIO *out) |
671 | 0 | { |
672 | 0 | if (a->name) |
673 | 0 | BIO_printf(out, "[%s] %s=%s\n", a->section, a->name, a->value); |
674 | 0 | else |
675 | 0 | BIO_printf(out, "[[%s]]\n", a->section); |
676 | 0 | } |
677 | | |
678 | | static IMPLEMENT_LHASH_DOALL_ARG_FN(dump_value, CONF_VALUE, BIO) |
679 | | |
680 | | static int |
681 | | def_dump(const CONF *conf, BIO *out) |
682 | 0 | { |
683 | 0 | lh_CONF_VALUE_doall_arg(conf->data, LHASH_DOALL_ARG_FN(dump_value), |
684 | 0 | BIO, out); |
685 | 0 | return 1; |
686 | 0 | } |
687 | | |
688 | | static int |
689 | | def_is_number(const CONF *conf, char c) |
690 | 0 | { |
691 | 0 | return IS_NUMBER(conf, c); |
692 | 0 | } |
693 | | |
694 | | static int |
695 | | def_to_int(const CONF *conf, char c) |
696 | 0 | { |
697 | 0 | return c - '0'; |
698 | 0 | } |