Revise and cleanup; use strict,warnings
[openssl.git] / crypto / conf / conf_def.c
1 /*
2  * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 /* Part of the code in here was originally in conf.c, which is now removed */
11
12 #include <stdio.h>
13 #include <string.h>
14 #include "internal/cryptlib.h"
15 #include "internal/o_dir.h"
16 #include <openssl/lhash.h>
17 #include <openssl/conf.h>
18 #include <openssl/conf_api.h>
19 #include "conf_def.h"
20 #include <openssl/buffer.h>
21 #include <openssl/err.h>
22 #ifndef OPENSSL_NO_POSIX_IO
23 # include <sys/stat.h>
24 # ifdef _WIN32
25 #  define stat    _stat
26 #  define strcasecmp _stricmp
27 # endif
28 #endif
29
30 /*
31  * The maximum length we can grow a value to after variable expansion. 64k
32  * should be more than enough for all reasonable uses.
33  */
34 #define MAX_CONF_VALUE_LENGTH       65536
35
36 static char *eat_ws(CONF *conf, char *p);
37 static void trim_ws(CONF *conf, char *start);
38 static char *eat_alpha_numeric(CONF *conf, char *p);
39 static void clear_comments(CONF *conf, char *p);
40 static int str_copy(CONF *conf, char *section, char **to, char *from);
41 static char *scan_quote(CONF *conf, char *p);
42 static char *scan_dquote(CONF *conf, char *p);
43 #define scan_esc(conf,p)        (((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2)))
44 #ifndef OPENSSL_NO_POSIX_IO
45 static BIO *process_include(char *include, OPENSSL_DIR_CTX **dirctx,
46                             char **dirpath);
47 static BIO *get_next_file(const char *path, OPENSSL_DIR_CTX **dirctx);
48 #endif
49
50 static CONF *def_create(CONF_METHOD *meth);
51 static int def_init_default(CONF *conf);
52 static int def_init_WIN32(CONF *conf);
53 static int def_destroy(CONF *conf);
54 static int def_destroy_data(CONF *conf);
55 static int def_load(CONF *conf, const char *name, long *eline);
56 static int def_load_bio(CONF *conf, BIO *bp, long *eline);
57 static int def_dump(const CONF *conf, BIO *bp);
58 static int def_is_number(const CONF *conf, char c);
59 static int def_to_int(const CONF *conf, char c);
60
61 static CONF_METHOD default_method = {
62     "OpenSSL default",
63     def_create,
64     def_init_default,
65     def_destroy,
66     def_destroy_data,
67     def_load_bio,
68     def_dump,
69     def_is_number,
70     def_to_int,
71     def_load
72 };
73
74 static CONF_METHOD WIN32_method = {
75     "WIN32",
76     def_create,
77     def_init_WIN32,
78     def_destroy,
79     def_destroy_data,
80     def_load_bio,
81     def_dump,
82     def_is_number,
83     def_to_int,
84     def_load
85 };
86
87 CONF_METHOD *NCONF_default()
88 {
89     return &default_method;
90 }
91
92 CONF_METHOD *NCONF_WIN32()
93 {
94     return &WIN32_method;
95 }
96
97 static CONF *def_create(CONF_METHOD *meth)
98 {
99     CONF *ret;
100
101     ret = OPENSSL_malloc(sizeof(*ret));
102     if (ret != NULL)
103         if (meth->init(ret) == 0) {
104             OPENSSL_free(ret);
105             ret = NULL;
106         }
107     return ret;
108 }
109
110 static int def_init_default(CONF *conf)
111 {
112     if (conf == NULL)
113         return 0;
114
115     conf->meth = &default_method;
116     conf->meth_data = (void *)CONF_type_default;
117     conf->data = NULL;
118
119     return 1;
120 }
121
122 static int def_init_WIN32(CONF *conf)
123 {
124     if (conf == NULL)
125         return 0;
126
127     conf->meth = &WIN32_method;
128     conf->meth_data = (void *)CONF_type_win32;
129     conf->data = NULL;
130
131     return 1;
132 }
133
134 static int def_destroy(CONF *conf)
135 {
136     if (def_destroy_data(conf)) {
137         OPENSSL_free(conf);
138         return 1;
139     }
140     return 0;
141 }
142
143 static int def_destroy_data(CONF *conf)
144 {
145     if (conf == NULL)
146         return 0;
147     _CONF_free_data(conf);
148     return 1;
149 }
150
151 static int def_load(CONF *conf, const char *name, long *line)
152 {
153     int ret;
154     BIO *in = NULL;
155
156 #ifdef OPENSSL_SYS_VMS
157     in = BIO_new_file(name, "r");
158 #else
159     in = BIO_new_file(name, "rb");
160 #endif
161     if (in == NULL) {
162         if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE)
163             CONFerr(CONF_F_DEF_LOAD, CONF_R_NO_SUCH_FILE);
164         else
165             CONFerr(CONF_F_DEF_LOAD, ERR_R_SYS_LIB);
166         return 0;
167     }
168
169     ret = def_load_bio(conf, in, line);
170     BIO_free(in);
171
172     return ret;
173 }
174
175 static int def_load_bio(CONF *conf, BIO *in, long *line)
176 {
177 /* The macro BUFSIZE conflicts with a system macro in VxWorks */
178 #define CONFBUFSIZE     512
179     int bufnum = 0, i, ii;
180     BUF_MEM *buff = NULL;
181     char *s, *p, *end;
182     int again;
183     long eline = 0;
184     char btmp[DECIMAL_SIZE(eline) + 1];
185     CONF_VALUE *v = NULL, *tv;
186     CONF_VALUE *sv = NULL;
187     char *section = NULL, *buf;
188     char *start, *psection, *pname;
189     void *h = (void *)(conf->data);
190     STACK_OF(BIO) *biosk = NULL;
191 #ifndef OPENSSL_NO_POSIX_IO
192     char *dirpath = NULL;
193     OPENSSL_DIR_CTX *dirctx = NULL;
194 #endif
195
196     if ((buff = BUF_MEM_new()) == NULL) {
197         CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_BUF_LIB);
198         goto err;
199     }
200
201     section = OPENSSL_strdup("default");
202     if (section == NULL) {
203         CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE);
204         goto err;
205     }
206
207     if (_CONF_new_data(conf) == 0) {
208         CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE);
209         goto err;
210     }
211
212     sv = _CONF_new_section(conf, section);
213     if (sv == NULL) {
214         CONFerr(CONF_F_DEF_LOAD_BIO, CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
215         goto err;
216     }
217
218     bufnum = 0;
219     again = 0;
220     for (;;) {
221         if (!BUF_MEM_grow(buff, bufnum + CONFBUFSIZE)) {
222             CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_BUF_LIB);
223             goto err;
224         }
225         p = &(buff->data[bufnum]);
226         *p = '\0';
227  read_retry:
228         BIO_gets(in, p, CONFBUFSIZE - 1);
229         p[CONFBUFSIZE - 1] = '\0';
230         ii = i = strlen(p);
231         if (i == 0 && !again) {
232             /* the currently processed BIO is at EOF */
233             BIO *parent;
234
235 #ifndef OPENSSL_NO_POSIX_IO
236             /* continue processing with the next file from directory */
237             if (dirctx != NULL) {
238                 BIO *next;
239
240                 if ((next = get_next_file(dirpath, &dirctx)) != NULL) {
241                     BIO_vfree(in);
242                     in = next;
243                     goto read_retry;
244                 } else {
245                     OPENSSL_free(dirpath);
246                     dirpath = NULL;
247                 }
248             }
249 #endif
250             /* no more files in directory, continue with processing parent */
251             if ((parent = sk_BIO_pop(biosk)) == NULL) {
252                 /* everything processed get out of the loop */
253                 break;
254             } else {
255                 BIO_vfree(in);
256                 in = parent;
257                 goto read_retry;
258             }
259         }
260         again = 0;
261         while (i > 0) {
262             if ((p[i - 1] != '\r') && (p[i - 1] != '\n'))
263                 break;
264             else
265                 i--;
266         }
267         /*
268          * we removed some trailing stuff so there is a new line on the end.
269          */
270         if (ii && i == ii)
271             again = 1;          /* long line */
272         else {
273             p[i] = '\0';
274             eline++;            /* another input line */
275         }
276
277         /* we now have a line with trailing \r\n removed */
278
279         /* i is the number of bytes */
280         bufnum += i;
281
282         v = NULL;
283         /* check for line continuation */
284         if (bufnum >= 1) {
285             /*
286              * If we have bytes and the last char '\\' and second last char
287              * is not '\\'
288              */
289             p = &(buff->data[bufnum - 1]);
290             if (IS_ESC(conf, p[0]) && ((bufnum <= 1) || !IS_ESC(conf, p[-1]))) {
291                 bufnum--;
292                 again = 1;
293             }
294         }
295         if (again)
296             continue;
297         bufnum = 0;
298         buf = buff->data;
299
300         clear_comments(conf, buf);
301         s = eat_ws(conf, buf);
302         if (IS_EOF(conf, *s))
303             continue;           /* blank line */
304         if (*s == '[') {
305             char *ss;
306
307             s++;
308             start = eat_ws(conf, s);
309             ss = start;
310  again:
311             end = eat_alpha_numeric(conf, ss);
312             p = eat_ws(conf, end);
313             if (*p != ']') {
314                 if (*p != '\0' && ss != p) {
315                     ss = p;
316                     goto again;
317                 }
318                 CONFerr(CONF_F_DEF_LOAD_BIO,
319                         CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
320                 goto err;
321             }
322             *end = '\0';
323             if (!str_copy(conf, NULL, &section, start))
324                 goto err;
325             if ((sv = _CONF_get_section(conf, section)) == NULL)
326                 sv = _CONF_new_section(conf, section);
327             if (sv == NULL) {
328                 CONFerr(CONF_F_DEF_LOAD_BIO,
329                         CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
330                 goto err;
331             }
332             continue;
333         } else {
334             pname = s;
335             end = eat_alpha_numeric(conf, s);
336             if ((end[0] == ':') && (end[1] == ':')) {
337                 *end = '\0';
338                 end += 2;
339                 psection = pname;
340                 pname = end;
341                 end = eat_alpha_numeric(conf, end);
342             } else {
343                 psection = section;
344             }
345             p = eat_ws(conf, end);
346             if (strncmp(pname, ".include", 8) == 0 && p != pname + 8) {
347                 char *include = NULL;
348                 BIO *next;
349
350                 trim_ws(conf, p);
351                 if (!str_copy(conf, psection, &include, p))
352                     goto err;
353                 /* get the BIO of the included file */
354 #ifndef OPENSSL_NO_POSIX_IO
355                 next = process_include(include, &dirctx, &dirpath);
356                 if (include != dirpath) {
357                     /* dirpath will contain include in case of a directory */
358                     OPENSSL_free(include);
359                 }
360 #else
361                 next = BIO_new_file(include, "r");
362                 OPENSSL_free(include);
363 #endif
364                 if (next != NULL) {
365                     /* push the currently processing BIO onto stack */
366                     if (biosk == NULL) {
367                         if ((biosk = sk_BIO_new_null()) == NULL) {
368                             CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE);
369                             goto err;
370                         }
371                     }
372                     if (!sk_BIO_push(biosk, in)) {
373                         CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE);
374                         goto err;
375                     }
376                     /* continue with reading from the included BIO */
377                     in = next;
378                 }
379                 continue;
380             } else if (*p != '=') {
381                 CONFerr(CONF_F_DEF_LOAD_BIO, CONF_R_MISSING_EQUAL_SIGN);
382                 goto err;
383             }
384             *end = '\0';
385             p++;
386             start = eat_ws(conf, p);
387             trim_ws(conf, start);
388
389             if ((v = OPENSSL_malloc(sizeof(*v))) == NULL) {
390                 CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE);
391                 goto err;
392             }
393             v->name = OPENSSL_strdup(pname);
394             v->value = NULL;
395             if (v->name == NULL) {
396                 CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE);
397                 goto err;
398             }
399             if (!str_copy(conf, psection, &(v->value), start))
400                 goto err;
401
402             if (strcmp(psection, section) != 0) {
403                 if ((tv = _CONF_get_section(conf, psection))
404                     == NULL)
405                     tv = _CONF_new_section(conf, psection);
406                 if (tv == NULL) {
407                     CONFerr(CONF_F_DEF_LOAD_BIO,
408                             CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
409                     goto err;
410                 }
411             } else
412                 tv = sv;
413             if (_CONF_add_string(conf, tv, v) == 0) {
414                 CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE);
415                 goto err;
416             }
417             v = NULL;
418         }
419     }
420     BUF_MEM_free(buff);
421     OPENSSL_free(section);
422     sk_BIO_pop_free(biosk, BIO_vfree);
423     return 1;
424  err:
425     BUF_MEM_free(buff);
426     OPENSSL_free(section);
427     sk_BIO_pop_free(biosk, BIO_vfree);
428 #ifndef OPENSSL_NO_POSIX_IO
429     OPENSSL_free(dirpath);
430     if (dirctx != NULL)
431         OPENSSL_DIR_end(&dirctx);
432 #endif
433     if (line != NULL)
434         *line = eline;
435     BIO_snprintf(btmp, sizeof(btmp), "%ld", eline);
436     ERR_add_error_data(2, "line ", btmp);
437     if (h != conf->data) {
438         CONF_free(conf->data);
439         conf->data = NULL;
440     }
441     if (v != NULL) {
442         OPENSSL_free(v->name);
443         OPENSSL_free(v->value);
444         OPENSSL_free(v);
445     }
446     return 0;
447 }
448
449 static void clear_comments(CONF *conf, char *p)
450 {
451     for (;;) {
452         if (IS_FCOMMENT(conf, *p)) {
453             *p = '\0';
454             return;
455         }
456         if (!IS_WS(conf, *p)) {
457             break;
458         }
459         p++;
460     }
461
462     for (;;) {
463         if (IS_COMMENT(conf, *p)) {
464             *p = '\0';
465             return;
466         }
467         if (IS_DQUOTE(conf, *p)) {
468             p = scan_dquote(conf, p);
469             continue;
470         }
471         if (IS_QUOTE(conf, *p)) {
472             p = scan_quote(conf, p);
473             continue;
474         }
475         if (IS_ESC(conf, *p)) {
476             p = scan_esc(conf, p);
477             continue;
478         }
479         if (IS_EOF(conf, *p))
480             return;
481         else
482             p++;
483     }
484 }
485
486 static int str_copy(CONF *conf, char *section, char **pto, char *from)
487 {
488     int q, r, rr = 0, to = 0, len = 0;
489     char *s, *e, *rp, *p, *rrp, *np, *cp, v;
490     BUF_MEM *buf;
491
492     if ((buf = BUF_MEM_new()) == NULL)
493         return 0;
494
495     len = strlen(from) + 1;
496     if (!BUF_MEM_grow(buf, len))
497         goto err;
498
499     for (;;) {
500         if (IS_QUOTE(conf, *from)) {
501             q = *from;
502             from++;
503             while (!IS_EOF(conf, *from) && (*from != q)) {
504                 if (IS_ESC(conf, *from)) {
505                     from++;
506                     if (IS_EOF(conf, *from))
507                         break;
508                 }
509                 buf->data[to++] = *(from++);
510             }
511             if (*from == q)
512                 from++;
513         } else if (IS_DQUOTE(conf, *from)) {
514             q = *from;
515             from++;
516             while (!IS_EOF(conf, *from)) {
517                 if (*from == q) {
518                     if (*(from + 1) == q) {
519                         from++;
520                     } else {
521                         break;
522                     }
523                 }
524                 buf->data[to++] = *(from++);
525             }
526             if (*from == q)
527                 from++;
528         } else if (IS_ESC(conf, *from)) {
529             from++;
530             v = *(from++);
531             if (IS_EOF(conf, v))
532                 break;
533             else if (v == 'r')
534                 v = '\r';
535             else if (v == 'n')
536                 v = '\n';
537             else if (v == 'b')
538                 v = '\b';
539             else if (v == 't')
540                 v = '\t';
541             buf->data[to++] = v;
542         } else if (IS_EOF(conf, *from))
543             break;
544         else if (*from == '$') {
545             size_t newsize;
546
547             /* try to expand it */
548             rrp = NULL;
549             s = &(from[1]);
550             if (*s == '{')
551                 q = '}';
552             else if (*s == '(')
553                 q = ')';
554             else
555                 q = 0;
556
557             if (q)
558                 s++;
559             cp = section;
560             e = np = s;
561             while (IS_ALNUM(conf, *e))
562                 e++;
563             if ((e[0] == ':') && (e[1] == ':')) {
564                 cp = np;
565                 rrp = e;
566                 rr = *e;
567                 *rrp = '\0';
568                 e += 2;
569                 np = e;
570                 while (IS_ALNUM(conf, *e))
571                     e++;
572             }
573             r = *e;
574             *e = '\0';
575             rp = e;
576             if (q) {
577                 if (r != q) {
578                     CONFerr(CONF_F_STR_COPY, CONF_R_NO_CLOSE_BRACE);
579                     goto err;
580                 }
581                 e++;
582             }
583             /*-
584              * So at this point we have
585              * np which is the start of the name string which is
586              *   '\0' terminated.
587              * cp which is the start of the section string which is
588              *   '\0' terminated.
589              * e is the 'next point after'.
590              * r and rr are the chars replaced by the '\0'
591              * rp and rrp is where 'r' and 'rr' came from.
592              */
593             p = _CONF_get_string(conf, cp, np);
594             if (rrp != NULL)
595                 *rrp = rr;
596             *rp = r;
597             if (p == NULL) {
598                 CONFerr(CONF_F_STR_COPY, CONF_R_VARIABLE_HAS_NO_VALUE);
599                 goto err;
600             }
601             newsize = strlen(p) + buf->length - (e - from);
602             if (newsize > MAX_CONF_VALUE_LENGTH) {
603                 CONFerr(CONF_F_STR_COPY, CONF_R_VARIABLE_EXPANSION_TOO_LONG);
604                 goto err;
605             }
606             if (!BUF_MEM_grow_clean(buf, newsize)) {
607                 CONFerr(CONF_F_STR_COPY, ERR_R_MALLOC_FAILURE);
608                 goto err;
609             }
610             while (*p)
611                 buf->data[to++] = *(p++);
612
613             /*
614              * Since we change the pointer 'from', we also have to change the
615              * perceived length of the string it points at.  /RL
616              */
617             len -= e - from;
618             from = e;
619
620             /*
621              * In case there were no braces or parenthesis around the
622              * variable reference, we have to put back the character that was
623              * replaced with a '\0'.  /RL
624              */
625             *rp = r;
626         } else
627             buf->data[to++] = *(from++);
628     }
629     buf->data[to] = '\0';
630     OPENSSL_free(*pto);
631     *pto = buf->data;
632     OPENSSL_free(buf);
633     return 1;
634  err:
635     BUF_MEM_free(buf);
636     return 0;
637 }
638
639 #ifndef OPENSSL_NO_POSIX_IO
640 /*
641  * Check whether included path is a directory.
642  * Returns next BIO to process and in case of a directory
643  * also an opened directory context and the include path.
644  */
645 static BIO *process_include(char *include, OPENSSL_DIR_CTX **dirctx,
646                             char **dirpath)
647 {
648     struct stat st = { 0 };
649     BIO *next;
650
651     if (stat(include, &st) < 0) {
652         SYSerr(SYS_F_STAT, errno);
653         ERR_add_error_data(1, include);
654         /* missing include file is not fatal error */
655         return NULL;
656     }
657
658     if ((st.st_mode & S_IFDIR) == S_IFDIR) {
659         if (*dirctx != NULL) {
660             CONFerr(CONF_F_PROCESS_INCLUDE,
661                     CONF_R_RECURSIVE_DIRECTORY_INCLUDE);
662             ERR_add_error_data(1, include);
663             return NULL;
664         }
665         /* a directory, load its contents */
666         if ((next = get_next_file(include, dirctx)) != NULL)
667             *dirpath = include;
668         return next;
669     }
670
671     next = BIO_new_file(include, "r");
672     return next;
673 }
674
675 /*
676  * Get next file from the directory path.
677  * Returns BIO of the next file to read and updates dirctx.
678  */
679 static BIO *get_next_file(const char *path, OPENSSL_DIR_CTX **dirctx)
680 {
681     const char *filename;
682
683     while ((filename = OPENSSL_DIR_read(dirctx, path)) != NULL) {
684         size_t namelen;
685
686         namelen = strlen(filename);
687
688
689         if ((namelen > 5 && strcasecmp(filename + namelen - 5, ".conf") == 0)
690             || (namelen > 4 && strcasecmp(filename + namelen - 4, ".cnf") == 0)) {
691             size_t newlen;
692             char *newpath;
693             BIO *bio;
694
695             newlen = strlen(path) + namelen + 2;
696             newpath = OPENSSL_zalloc(newlen);
697             if (newpath == NULL) {
698                 CONFerr(CONF_F_GET_NEXT_FILE, ERR_R_MALLOC_FAILURE);
699                 break;
700             }
701 #ifdef OPENSSL_SYS_VMS
702             /*
703              * If the given path isn't clear VMS syntax,
704              * we treat it as on Unix.
705              */
706             {
707                 size_t pathlen = strlen(path);
708
709                 if (path[pathlen - 1] == ']' || path[pathlen - 1] == '>'
710                     || path[pathlen - 1] == ':') {
711                     /* Clear VMS directory syntax, just copy as is */
712                     OPENSSL_strlcpy(newpath, path, newlen);
713                 }
714             }
715 #endif
716             if (newpath[0] == '\0') {
717                 OPENSSL_strlcpy(newpath, path, newlen);
718                 OPENSSL_strlcat(newpath, "/", newlen);
719             }
720             OPENSSL_strlcat(newpath, filename, newlen);
721
722             bio = BIO_new_file(newpath, "r");
723             OPENSSL_free(newpath);
724             /* Errors when opening files are non-fatal. */
725             if (bio != NULL)
726                 return bio;
727         }
728     }
729     OPENSSL_DIR_end(dirctx);
730     *dirctx = NULL;
731     return NULL;
732 }
733 #endif
734
735 static char *eat_ws(CONF *conf, char *p)
736 {
737     while (IS_WS(conf, *p) && (!IS_EOF(conf, *p)))
738         p++;
739     return p;
740 }
741
742 static void trim_ws(CONF *conf, char *start)
743 {
744     char *p = start;
745
746     while (!IS_EOF(conf, *p))
747         p++;
748     p--;
749     while ((p >= start) && IS_WS(conf, *p))
750         p--;
751     p++;
752     *p = '\0';
753 }
754
755 static char *eat_alpha_numeric(CONF *conf, char *p)
756 {
757     for (;;) {
758         if (IS_ESC(conf, *p)) {
759             p = scan_esc(conf, p);
760             continue;
761         }
762         if (!IS_ALNUM_PUNCT(conf, *p))
763             return p;
764         p++;
765     }
766 }
767
768 static char *scan_quote(CONF *conf, char *p)
769 {
770     int q = *p;
771
772     p++;
773     while (!(IS_EOF(conf, *p)) && (*p != q)) {
774         if (IS_ESC(conf, *p)) {
775             p++;
776             if (IS_EOF(conf, *p))
777                 return p;
778         }
779         p++;
780     }
781     if (*p == q)
782         p++;
783     return p;
784 }
785
786 static char *scan_dquote(CONF *conf, char *p)
787 {
788     int q = *p;
789
790     p++;
791     while (!(IS_EOF(conf, *p))) {
792         if (*p == q) {
793             if (*(p + 1) == q) {
794                 p++;
795             } else {
796                 break;
797             }
798         }
799         p++;
800     }
801     if (*p == q)
802         p++;
803     return p;
804 }
805
806 static void dump_value_doall_arg(const CONF_VALUE *a, BIO *out)
807 {
808     if (a->name)
809         BIO_printf(out, "[%s] %s=%s\n", a->section, a->name, a->value);
810     else
811         BIO_printf(out, "[[%s]]\n", a->section);
812 }
813
814 IMPLEMENT_LHASH_DOALL_ARG_CONST(CONF_VALUE, BIO);
815
816 static int def_dump(const CONF *conf, BIO *out)
817 {
818     lh_CONF_VALUE_doall_BIO(conf->data, dump_value_doall_arg, out);
819     return 1;
820 }
821
822 static int def_is_number(const CONF *conf, char c)
823 {
824     return IS_NUMBER(conf, c);
825 }
826
827 static int def_to_int(const CONF *conf, char c)
828 {
829     return c - '0';
830 }