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