Coverage Report

Created: 2022-11-30 06:20

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