summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/conf
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/conf')
-rw-r--r--src/lib/libcrypto/conf/Makefile.ssl44
-rw-r--r--src/lib/libcrypto/conf/conf.c730
-rw-r--r--src/lib/libcrypto/conf/conf.h69
-rw-r--r--src/lib/libcrypto/conf/conf_api.c289
-rw-r--r--src/lib/libcrypto/conf/conf_api.h87
-rw-r--r--src/lib/libcrypto/conf/conf_def.c703
-rw-r--r--src/lib/libcrypto/conf/conf_def.h145
-rw-r--r--src/lib/libcrypto/conf/conf_err.c9
-rw-r--r--src/lib/libcrypto/conf/conf_lcl.h116
-rw-r--r--src/lib/libcrypto/conf/conf_lib.c352
-rw-r--r--src/lib/libcrypto/conf/keysets.pl152
-rw-r--r--src/lib/libcrypto/conf/test.c8
12 files changed, 1822 insertions, 882 deletions
diff --git a/src/lib/libcrypto/conf/Makefile.ssl b/src/lib/libcrypto/conf/Makefile.ssl
index 9dbb2b276a..efbb578981 100644
--- a/src/lib/libcrypto/conf/Makefile.ssl
+++ b/src/lib/libcrypto/conf/Makefile.ssl
@@ -22,14 +22,14 @@ TEST=
22APPS= 22APPS=
23 23
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= conf.c conf_err.c 25LIBSRC= conf_err.c conf_lib.c conf_api.c conf_def.c
26 26
27LIBOBJ= conf.o conf_err.o 27LIBOBJ= conf_err.o conf_lib.o conf_api.o conf_def.o
28 28
29SRC= $(LIBSRC) 29SRC= $(LIBSRC)
30 30
31EXHEADER= conf.h 31EXHEADER= conf.h conf_api.h
32HEADER= conf_lcl.h $(EXHEADER) 32HEADER= conf_def.h $(EXHEADER)
33 33
34ALL= $(GENERAL) $(SRC) $(HEADER) 34ALL= $(GENERAL) $(SRC) $(HEADER)
35 35
@@ -79,14 +79,30 @@ clean:
79 79
80# DO NOT DELETE THIS LINE -- make depend depends on it. 80# DO NOT DELETE THIS LINE -- make depend depends on it.
81 81
82conf.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 82conf_api.o: ../../include/openssl/bio.h ../../include/openssl/conf.h
83conf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h 83conf_api.o: ../../include/openssl/conf_api.h ../../include/openssl/crypto.h
84conf.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 84conf_api.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
85conf.o: ../../include/openssl/err.h ../../include/openssl/lhash.h 85conf_api.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
86conf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 86conf_api.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
87conf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 87conf_api.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
88conf.o: ../cryptlib.h conf_lcl.h 88conf_def.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
89conf_def.o: ../../include/openssl/conf.h ../../include/openssl/conf_api.h
90conf_def.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
91conf_def.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
92conf_def.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
93conf_def.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
94conf_def.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
95conf_def.o: conf_def.h
89conf_err.o: ../../include/openssl/bio.h ../../include/openssl/conf.h 96conf_err.o: ../../include/openssl/bio.h ../../include/openssl/conf.h
90conf_err.o: ../../include/openssl/crypto.h ../../include/openssl/err.h 97conf_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
91conf_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslv.h 98conf_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
92conf_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 99conf_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
100conf_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
101conf_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
102conf_lib.o: ../../include/openssl/bio.h ../../include/openssl/conf.h
103conf_lib.o: ../../include/openssl/conf_api.h ../../include/openssl/crypto.h
104conf_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
105conf_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
106conf_lib.o: ../../include/openssl/opensslconf.h
107conf_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
108conf_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
diff --git a/src/lib/libcrypto/conf/conf.c b/src/lib/libcrypto/conf/conf.c
index 3031fa3b44..e69de29bb2 100644
--- a/src/lib/libcrypto/conf/conf.c
+++ b/src/lib/libcrypto/conf/conf.c
@@ -1,730 +0,0 @@
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#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/stack.h>
63#include <openssl/lhash.h>
64#include <openssl/conf.h>
65#include <openssl/buffer.h>
66#include <openssl/err.h>
67
68#include "conf_lcl.h"
69
70static void value_free_hash(CONF_VALUE *a, LHASH *conf);
71static void value_free_stack(CONF_VALUE *a,LHASH *conf);
72static unsigned long hash(CONF_VALUE *v);
73static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b);
74static char *eat_ws(char *p);
75static char *eat_alpha_numeric(char *p);
76static void clear_comments(char *p);
77static int str_copy(LHASH *conf,char *section,char **to, char *from);
78static char *scan_quote(char *p);
79static CONF_VALUE *new_section(LHASH *conf,char *section);
80static CONF_VALUE *get_section(LHASH *conf,char *section);
81#define scan_esc(p) ((((p)[1] == '\0')?(p++):(p+=2)),p)
82
83const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT;
84
85
86LHASH *CONF_load(LHASH *h, const char *file, long *line)
87 {
88 LHASH *ltmp;
89 BIO *in=NULL;
90
91#ifdef VMS
92 in=BIO_new_file(file, "r");
93#else
94 in=BIO_new_file(file, "rb");
95#endif
96 if (in == NULL)
97 {
98 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
99 return NULL;
100 }
101
102 ltmp = CONF_load_bio(h, in, line);
103 BIO_free(in);
104
105 return ltmp;
106}
107#ifndef NO_FP_API
108LHASH *CONF_load_fp(LHASH *h, FILE *in, long *line)
109{
110 BIO *btmp;
111 LHASH *ltmp;
112 if(!(btmp = BIO_new_fp(in, BIO_NOCLOSE))) {
113 CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
114 return NULL;
115 }
116 ltmp = CONF_load_bio(h, btmp, line);
117 BIO_free(btmp);
118 return ltmp;
119}
120#endif
121
122LHASH *CONF_load_bio(LHASH *h, BIO *in, long *line)
123 {
124 LHASH *ret=NULL;
125#define BUFSIZE 512
126 char btmp[16];
127 int bufnum=0,i,ii;
128 BUF_MEM *buff=NULL;
129 char *s,*p,*end;
130 int again,n;
131 long eline=0;
132 CONF_VALUE *v=NULL,*vv,*tv;
133 CONF_VALUE *sv=NULL;
134 char *section=NULL,*buf;
135 STACK_OF(CONF_VALUE) *section_sk=NULL,*ts;
136 char *start,*psection,*pname;
137
138 if ((buff=BUF_MEM_new()) == NULL)
139 {
140 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
141 goto err;
142 }
143
144 section=(char *)Malloc(10);
145 if (section == NULL)
146 {
147 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
148 goto err;
149 }
150 strcpy(section,"default");
151
152 if (h == NULL)
153 {
154 if ((ret=lh_new(hash,cmp_conf)) == NULL)
155 {
156 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
157 goto err;
158 }
159 }
160 else
161 ret=h;
162
163 sv=new_section(ret,section);
164 if (sv == NULL)
165 {
166 CONFerr(CONF_F_CONF_LOAD_BIO,
167 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
168 goto err;
169 }
170 section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
171
172 bufnum=0;
173 for (;;)
174 {
175 again=0;
176 if (!BUF_MEM_grow(buff,bufnum+BUFSIZE))
177 {
178 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
179 goto err;
180 }
181 p= &(buff->data[bufnum]);
182 *p='\0';
183 BIO_gets(in, p, BUFSIZE-1);
184 p[BUFSIZE-1]='\0';
185 ii=i=strlen(p);
186 if (i == 0) break;
187 while (i > 0)
188 {
189 if ((p[i-1] != '\r') && (p[i-1] != '\n'))
190 break;
191 else
192 i--;
193 }
194 /* we removed some trailing stuff so there is a new
195 * line on the end. */
196 if (i == ii)
197 again=1; /* long line */
198 else
199 {
200 p[i]='\0';
201 eline++; /* another input line */
202 }
203
204 /* we now have a line with trailing \r\n removed */
205
206 /* i is the number of bytes */
207 bufnum+=i;
208
209 v=NULL;
210 /* check for line continuation */
211 if (bufnum >= 1)
212 {
213 /* If we have bytes and the last char '\\' and
214 * second last char is not '\\' */
215 p= &(buff->data[bufnum-1]);
216 if ( IS_ESC(p[0]) &&
217 ((bufnum <= 1) || !IS_ESC(p[-1])))
218 {
219 bufnum--;
220 again=1;
221 }
222 }
223 if (again) continue;
224 bufnum=0;
225 buf=buff->data;
226
227 clear_comments(buf);
228 n=strlen(buf);
229 s=eat_ws(buf);
230 if (IS_EOF(*s)) continue; /* blank line */
231 if (*s == '[')
232 {
233 char *ss;
234
235 s++;
236 start=eat_ws(s);
237 ss=start;
238again:
239 end=eat_alpha_numeric(ss);
240 p=eat_ws(end);
241 if (*p != ']')
242 {
243 if (*p != '\0')
244 {
245 ss=p;
246 goto again;
247 }
248 CONFerr(CONF_F_CONF_LOAD_BIO,
249 CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
250 goto err;
251 }
252 *end='\0';
253 if (!str_copy(ret,NULL,&section,start)) goto err;
254 if ((sv=get_section(ret,section)) == NULL)
255 sv=new_section(ret,section);
256 if (sv == NULL)
257 {
258 CONFerr(CONF_F_CONF_LOAD_BIO,
259 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
260 goto err;
261 }
262 section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
263 continue;
264 }
265 else
266 {
267 pname=s;
268 psection=NULL;
269 end=eat_alpha_numeric(s);
270 if ((end[0] == ':') && (end[1] == ':'))
271 {
272 *end='\0';
273 end+=2;
274 psection=pname;
275 pname=end;
276 end=eat_alpha_numeric(end);
277 }
278 p=eat_ws(end);
279 if (*p != '=')
280 {
281 CONFerr(CONF_F_CONF_LOAD_BIO,
282 CONF_R_MISSING_EQUAL_SIGN);
283 goto err;
284 }
285 *end='\0';
286 p++;
287 start=eat_ws(p);
288 while (!IS_EOF(*p))
289 p++;
290 p--;
291 while ((p != start) && (IS_WS(*p)))
292 p--;
293 p++;
294 *p='\0';
295
296 if (!(v=(CONF_VALUE *)Malloc(sizeof(CONF_VALUE))))
297 {
298 CONFerr(CONF_F_CONF_LOAD_BIO,
299 ERR_R_MALLOC_FAILURE);
300 goto err;
301 }
302 if (psection == NULL) psection=section;
303 v->name=(char *)Malloc(strlen(pname)+1);
304 v->value=NULL;
305 if (v->name == NULL)
306 {
307 CONFerr(CONF_F_CONF_LOAD_BIO,
308 ERR_R_MALLOC_FAILURE);
309 goto err;
310 }
311 strcpy(v->name,pname);
312 if (!str_copy(ret,psection,&(v->value),start)) goto err;
313
314 if (strcmp(psection,section) != 0)
315 {
316 if ((tv=get_section(ret,psection))
317 == NULL)
318 tv=new_section(ret,psection);
319 if (tv == NULL)
320 {
321 CONFerr(CONF_F_CONF_LOAD_BIO,
322 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
323 goto err;
324 }
325 ts=(STACK_OF(CONF_VALUE) *)tv->value;
326 }
327 else
328 {
329 tv=sv;
330 ts=section_sk;
331 }
332 v->section=tv->section;
333 if (!sk_CONF_VALUE_push(ts,v))
334 {
335 CONFerr(CONF_F_CONF_LOAD_BIO,
336 ERR_R_MALLOC_FAILURE);
337 goto err;
338 }
339 vv=(CONF_VALUE *)lh_insert(ret,v);
340 if (vv != NULL)
341 {
342 sk_CONF_VALUE_delete_ptr(ts,vv);
343 Free(vv->name);
344 Free(vv->value);
345 Free(vv);
346 }
347 v=NULL;
348 }
349 }
350 if (buff != NULL) BUF_MEM_free(buff);
351 if (section != NULL) Free(section);
352 return(ret);
353err:
354 if (buff != NULL) BUF_MEM_free(buff);
355 if (section != NULL) Free(section);
356 if (line != NULL) *line=eline;
357 sprintf(btmp,"%ld",eline);
358 ERR_add_error_data(2,"line ",btmp);
359 if ((h != ret) && (ret != NULL)) CONF_free(ret);
360 if (v != NULL)
361 {
362 if (v->name != NULL) Free(v->name);
363 if (v->value != NULL) Free(v->value);
364 if (v != NULL) Free(v);
365 }
366 return(NULL);
367 }
368
369char *CONF_get_string(LHASH *conf, char *section, char *name)
370 {
371 CONF_VALUE *v,vv;
372 char *p;
373
374 if (name == NULL) return(NULL);
375 if (conf != NULL)
376 {
377 if (section != NULL)
378 {
379 vv.name=name;
380 vv.section=section;
381 v=(CONF_VALUE *)lh_retrieve(conf,&vv);
382 if (v != NULL) return(v->value);
383 if (strcmp(section,"ENV") == 0)
384 {
385 p=Getenv(name);
386 if (p != NULL) return(p);
387 }
388 }
389 vv.section="default";
390 vv.name=name;
391 v=(CONF_VALUE *)lh_retrieve(conf,&vv);
392 if (v != NULL)
393 return(v->value);
394 else
395 return(NULL);
396 }
397 else
398 return(Getenv(name));
399 }
400
401static CONF_VALUE *get_section(LHASH *conf, char *section)
402 {
403 CONF_VALUE *v,vv;
404
405 if ((conf == NULL) || (section == NULL)) return(NULL);
406 vv.name=NULL;
407 vv.section=section;
408 v=(CONF_VALUE *)lh_retrieve(conf,&vv);
409 return(v);
410 }
411
412STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf, char *section)
413 {
414 CONF_VALUE *v;
415
416 v=get_section(conf,section);
417 if (v != NULL)
418 return((STACK_OF(CONF_VALUE) *)v->value);
419 else
420 return(NULL);
421 }
422
423long CONF_get_number(LHASH *conf, char *section, char *name)
424 {
425 char *str;
426 long ret=0;
427
428 str=CONF_get_string(conf,section,name);
429 if (str == NULL) return(0);
430 for (;;)
431 {
432 if (IS_NUMER(*str))
433 ret=ret*10+(*str -'0');
434 else
435 return(ret);
436 str++;
437 }
438 }
439
440void CONF_free(LHASH *conf)
441 {
442 if (conf == NULL) return;
443
444 conf->down_load=0; /* evil thing to make sure the 'Free()'
445 * works as expected */
446 lh_doall_arg(conf,(void (*)())value_free_hash,conf);
447
448 /* We now have only 'section' entries in the hash table.
449 * Due to problems with */
450
451 lh_doall_arg(conf,(void (*)())value_free_stack,conf);
452 lh_free(conf);
453 }
454
455static void value_free_hash(CONF_VALUE *a, LHASH *conf)
456 {
457 if (a->name != NULL)
458 {
459 a=(CONF_VALUE *)lh_delete(conf,a);
460 }
461 }
462
463static void value_free_stack(CONF_VALUE *a, LHASH *conf)
464 {
465 CONF_VALUE *vv;
466 STACK *sk;
467 int i;
468
469 if (a->name != NULL) return;
470
471 sk=(STACK *)a->value;
472 for (i=sk_num(sk)-1; i>=0; i--)
473 {
474 vv=(CONF_VALUE *)sk_value(sk,i);
475 Free(vv->value);
476 Free(vv->name);
477 Free(vv);
478 }
479 if (sk != NULL) sk_free(sk);
480 Free(a->section);
481 Free(a);
482 }
483
484static void clear_comments(char *p)
485 {
486 char *to;
487
488 to=p;
489 for (;;)
490 {
491 if (IS_COMMENT(*p))
492 {
493 *p='\0';
494 return;
495 }
496 if (IS_QUOTE(*p))
497 {
498 p=scan_quote(p);
499 continue;
500 }
501 if (IS_ESC(*p))
502 {
503 p=scan_esc(p);
504 continue;
505 }
506 if (IS_EOF(*p))
507 return;
508 else
509 p++;
510 }
511 }
512
513static int str_copy(LHASH *conf, char *section, char **pto, char *from)
514 {
515 int q,r,rr=0,to=0,len=0;
516 char *s,*e,*rp,*p,*rrp,*np,*cp,v;
517 BUF_MEM *buf;
518
519 if ((buf=BUF_MEM_new()) == NULL) return(0);
520
521 len=strlen(from)+1;
522 if (!BUF_MEM_grow(buf,len)) goto err;
523
524 for (;;)
525 {
526 if (IS_QUOTE(*from))
527 {
528 q= *from;
529 from++;
530 while ((*from != '\0') && (*from != q))
531 {
532 if (*from == '\\')
533 {
534 from++;
535 if (*from == '\0') break;
536 }
537 buf->data[to++]= *(from++);
538 }
539 }
540 else if (*from == '\\')
541 {
542 from++;
543 v= *(from++);
544 if (v == '\0') break;
545 else if (v == 'r') v='\r';
546 else if (v == 'n') v='\n';
547 else if (v == 'b') v='\b';
548 else if (v == 't') v='\t';
549 buf->data[to++]= v;
550 }
551 else if (*from == '\0')
552 break;
553 else if (*from == '$')
554 {
555 /* try to expand it */
556 rrp=NULL;
557 s= &(from[1]);
558 if (*s == '{')
559 q='}';
560 else if (*s == '(')
561 q=')';
562 else q=0;
563
564 if (q) s++;
565 cp=section;
566 e=np=s;
567 while (IS_ALPHA_NUMERIC(*e))
568 e++;
569 if ((e[0] == ':') && (e[1] == ':'))
570 {
571 cp=np;
572 rrp=e;
573 rr= *e;
574 *rrp='\0';
575 e+=2;
576 np=e;
577 while (IS_ALPHA_NUMERIC(*e))
578 e++;
579 }
580 r= *e;
581 *e='\0';
582 rp=e;
583 if (q)
584 {
585 if (r != q)
586 {
587 CONFerr(CONF_F_STR_COPY,CONF_R_NO_CLOSE_BRACE);
588 goto err;
589 }
590 e++;
591 }
592 /* So at this point we have
593 * ns which is the start of the name string which is
594 * '\0' terminated.
595 * cs which is the start of the section string which is
596 * '\0' terminated.
597 * e is the 'next point after'.
598 * r and s are the chars replaced by the '\0'
599 * rp and sp is where 'r' and 's' came from.
600 */
601 p=CONF_get_string(conf,cp,np);
602 if (rrp != NULL) *rrp=rr;
603 *rp=r;
604 if (p == NULL)
605 {
606 CONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE);
607 goto err;
608 }
609 BUF_MEM_grow(buf,(strlen(p)+len-(e-from)));
610 while (*p)
611 buf->data[to++]= *(p++);
612 from=e;
613 }
614 else
615 buf->data[to++]= *(from++);
616 }
617 buf->data[to]='\0';
618 if (*pto != NULL) Free(*pto);
619 *pto=buf->data;
620 Free(buf);
621 return(1);
622err:
623 if (buf != NULL) BUF_MEM_free(buf);
624 return(0);
625 }
626
627static char *eat_ws(char *p)
628 {
629 while (IS_WS(*p) && (!IS_EOF(*p)))
630 p++;
631 return(p);
632 }
633
634static char *eat_alpha_numeric(char *p)
635 {
636 for (;;)
637 {
638 if (IS_ESC(*p))
639 {
640 p=scan_esc(p);
641 continue;
642 }
643 if (!IS_ALPHA_NUMERIC_PUNCT(*p))
644 return(p);
645 p++;
646 }
647 }
648
649static unsigned long hash(CONF_VALUE *v)
650 {
651 return((lh_strhash(v->section)<<2)^lh_strhash(v->name));
652 }
653
654static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b)
655 {
656 int i;
657
658 if (a->section != b->section)
659 {
660 i=strcmp(a->section,b->section);
661 if (i) return(i);
662 }
663
664 if ((a->name != NULL) && (b->name != NULL))
665 {
666 i=strcmp(a->name,b->name);
667 return(i);
668 }
669 else if (a->name == b->name)
670 return(0);
671 else
672 return((a->name == NULL)?-1:1);
673 }
674
675static char *scan_quote(char *p)
676 {
677 int q= *p;
678
679 p++;
680 while (!(IS_EOF(*p)) && (*p != q))
681 {
682 if (IS_ESC(*p))
683 {
684 p++;
685 if (IS_EOF(*p)) return(p);
686 }
687 p++;
688 }
689 if (*p == q) p++;
690 return(p);
691 }
692
693static CONF_VALUE *new_section(LHASH *conf, char *section)
694 {
695 STACK *sk=NULL;
696 int ok=0,i;
697 CONF_VALUE *v=NULL,*vv;
698
699 if ((sk=sk_new_null()) == NULL)
700 goto err;
701 if ((v=(CONF_VALUE *)Malloc(sizeof(CONF_VALUE))) == NULL)
702 goto err;
703 i=strlen(section)+1;
704 if ((v->section=(char *)Malloc(i)) == NULL)
705 goto err;
706
707 memcpy(v->section,section,i);
708 v->name=NULL;
709 v->value=(char *)sk;
710
711 vv=(CONF_VALUE *)lh_insert(conf,v);
712 if (vv != NULL)
713 {
714#if !defined(NO_STDIO) && !defined(WIN16)
715 fprintf(stderr,"internal fault\n");
716#endif
717 abort();
718 }
719 ok=1;
720err:
721 if (!ok)
722 {
723 if (sk != NULL) sk_free(sk);
724 if (v != NULL) Free(v);
725 v=NULL;
726 }
727 return(v);
728 }
729
730IMPLEMENT_STACK_OF(CONF_VALUE)
diff --git a/src/lib/libcrypto/conf/conf.h b/src/lib/libcrypto/conf/conf.h
index 21831a92a3..2f70634455 100644
--- a/src/lib/libcrypto/conf/conf.h
+++ b/src/lib/libcrypto/conf/conf.h
@@ -59,14 +59,15 @@
59#ifndef HEADER_CONF_H 59#ifndef HEADER_CONF_H
60#define HEADER_CONF_H 60#define HEADER_CONF_H
61 61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include <openssl/bio.h> 62#include <openssl/bio.h>
67#include <openssl/lhash.h> 63#include <openssl/lhash.h>
68#include <openssl/stack.h> 64#include <openssl/stack.h>
69#include <openssl/safestack.h> 65#include <openssl/safestack.h>
66#include <openssl/e_os.h>
67
68#ifdef __cplusplus
69extern "C" {
70#endif
70 71
71typedef struct 72typedef struct
72 { 73 {
@@ -77,6 +78,25 @@ typedef struct
77 78
78DECLARE_STACK_OF(CONF_VALUE) 79DECLARE_STACK_OF(CONF_VALUE)
79 80
81struct conf_st;
82typedef struct conf_st CONF;
83struct conf_method_st;
84typedef struct conf_method_st CONF_METHOD;
85
86struct conf_method_st
87 {
88 const char *name;
89 CONF *(MS_FAR *create)(CONF_METHOD *meth);
90 int (MS_FAR *init)(CONF *conf);
91 int (MS_FAR *destroy)(CONF *conf);
92 int (MS_FAR *destroy_data)(CONF *conf);
93 int (MS_FAR *load)(CONF *conf, BIO *bp, long *eline);
94 int (MS_FAR *dump)(CONF *conf, BIO *bp);
95 int (MS_FAR *is_number)(CONF *conf, char c);
96 int (MS_FAR *to_int)(CONF *conf, char c);
97 };
98
99int CONF_set_default_method(CONF_METHOD *meth);
80LHASH *CONF_load(LHASH *conf,const char *file,long *eline); 100LHASH *CONF_load(LHASH *conf,const char *file,long *eline);
81#ifndef NO_FP_API 101#ifndef NO_FP_API
82LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline); 102LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline);
@@ -86,8 +106,40 @@ STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section);
86char *CONF_get_string(LHASH *conf,char *group,char *name); 106char *CONF_get_string(LHASH *conf,char *group,char *name);
87long CONF_get_number(LHASH *conf,char *group,char *name); 107long CONF_get_number(LHASH *conf,char *group,char *name);
88void CONF_free(LHASH *conf); 108void CONF_free(LHASH *conf);
109int CONF_dump_fp(LHASH *conf, FILE *out);
110int CONF_dump_bio(LHASH *conf, BIO *out);
89void ERR_load_CONF_strings(void ); 111void ERR_load_CONF_strings(void );
90 112
113/* New conf code. The semantics are different from the functions above.
114 If that wasn't the case, the above functions would have been replaced */
115
116struct conf_st
117 {
118 CONF_METHOD *meth;
119 void *meth_data;
120 LHASH *data;
121 };
122
123CONF *NCONF_new(CONF_METHOD *meth);
124CONF_METHOD *NCONF_default();
125CONF_METHOD *NCONF_WIN32();
126#if 0 /* Just to give you an idea of what I have in mind */
127CONF_METHOD *NCONF_XML();
128#endif
129void NCONF_free(CONF *conf);
130void NCONF_free_data(CONF *conf);
131
132int NCONF_load(CONF *conf,const char *file,long *eline);
133#ifndef NO_FP_API
134int NCONF_load_fp(CONF *conf, FILE *fp,long *eline);
135#endif
136int NCONF_load_bio(CONF *conf, BIO *bp,long *eline);
137STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section);
138char *NCONF_get_string(CONF *conf,char *group,char *name);
139long NCONF_get_number(CONF *conf,char *group,char *name);
140int NCONF_dump_fp(CONF *conf, FILE *out);
141int NCONF_dump_bio(CONF *conf, BIO *out);
142
91 143
92/* BEGIN ERROR CODES */ 144/* BEGIN ERROR CODES */
93/* The following lines are auto generated by the script mkerr.pl. Any changes 145/* The following lines are auto generated by the script mkerr.pl. Any changes
@@ -97,15 +149,24 @@ void ERR_load_CONF_strings(void );
97/* Error codes for the CONF functions. */ 149/* Error codes for the CONF functions. */
98 150
99/* Function codes. */ 151/* Function codes. */
152#define CONF_F_CONF_DUMP_FP 104
100#define CONF_F_CONF_LOAD 100 153#define CONF_F_CONF_LOAD 100
101#define CONF_F_CONF_LOAD_BIO 102 154#define CONF_F_CONF_LOAD_BIO 102
102#define CONF_F_CONF_LOAD_FP 103 155#define CONF_F_CONF_LOAD_FP 103
156#define CONF_F_NCONF_DUMP_BIO 105
157#define CONF_F_NCONF_DUMP_FP 106
158#define CONF_F_NCONF_GET_NUMBER 107
159#define CONF_F_NCONF_GET_SECTION 108
160#define CONF_F_NCONF_GET_STRING 109
161#define CONF_F_NCONF_LOAD_BIO 110
162#define CONF_F_NCONF_NEW 111
103#define CONF_F_STR_COPY 101 163#define CONF_F_STR_COPY 101
104 164
105/* Reason codes. */ 165/* Reason codes. */
106#define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100 166#define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100
107#define CONF_R_MISSING_EQUAL_SIGN 101 167#define CONF_R_MISSING_EQUAL_SIGN 101
108#define CONF_R_NO_CLOSE_BRACE 102 168#define CONF_R_NO_CLOSE_BRACE 102
169#define CONF_R_NO_CONF 105
109#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103 170#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103
110#define CONF_R_VARIABLE_HAS_NO_VALUE 104 171#define CONF_R_VARIABLE_HAS_NO_VALUE 104
111 172
diff --git a/src/lib/libcrypto/conf/conf_api.c b/src/lib/libcrypto/conf/conf_api.c
new file mode 100644
index 0000000000..d05a778ff6
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_api.c
@@ -0,0 +1,289 @@
1/* conf_api.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#ifndef CONF_DEBUG
62# undef NDEBUG /* avoid conflicting definitions */
63# define NDEBUG
64#endif
65
66#include <assert.h>
67#include <string.h>
68#include <openssl/conf.h>
69#include <openssl/conf_api.h>
70
71static void value_free_hash(CONF_VALUE *a, LHASH *conf);
72static void value_free_stack(CONF_VALUE *a,LHASH *conf);
73static unsigned long hash(CONF_VALUE *v);
74static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b);
75
76/* Up until OpenSSL 0.9.5a, this was get_section */
77CONF_VALUE *_CONF_get_section(CONF *conf, char *section)
78 {
79 CONF_VALUE *v,vv;
80
81 if ((conf == NULL) || (section == NULL)) return(NULL);
82 vv.name=NULL;
83 vv.section=section;
84 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
85 return(v);
86 }
87
88/* Up until OpenSSL 0.9.5a, this was CONF_get_section */
89STACK_OF(CONF_VALUE) *_CONF_get_section_values(CONF *conf, char *section)
90 {
91 CONF_VALUE *v;
92
93 v=_CONF_get_section(conf,section);
94 if (v != NULL)
95 return((STACK_OF(CONF_VALUE) *)v->value);
96 else
97 return(NULL);
98 }
99
100int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value)
101 {
102 CONF_VALUE *v = NULL;
103 STACK_OF(CONF_VALUE) *ts;
104
105 ts = (STACK_OF(CONF_VALUE) *)section->value;
106
107 value->section=section->section;
108 if (!sk_CONF_VALUE_push(ts,value))
109 {
110 return 0;
111 }
112
113 v = (CONF_VALUE *)lh_insert(conf->data, value);
114 if (v != NULL)
115 {
116 sk_CONF_VALUE_delete_ptr(ts,v);
117 OPENSSL_free(v->name);
118 OPENSSL_free(v->value);
119 OPENSSL_free(v);
120 }
121 return 1;
122 }
123
124char *_CONF_get_string(CONF *conf, char *section, char *name)
125 {
126 CONF_VALUE *v,vv;
127 char *p;
128
129 if (name == NULL) return(NULL);
130 if (conf != NULL)
131 {
132 if (section != NULL)
133 {
134 vv.name=name;
135 vv.section=section;
136 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
137 if (v != NULL) return(v->value);
138 if (strcmp(section,"ENV") == 0)
139 {
140 p=Getenv(name);
141 if (p != NULL) return(p);
142 }
143 }
144 vv.section="default";
145 vv.name=name;
146 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
147 if (v != NULL)
148 return(v->value);
149 else
150 return(NULL);
151 }
152 else
153 return(Getenv(name));
154 }
155
156long _CONF_get_number(CONF *conf, char *section, char *name)
157 {
158 char *str;
159 long ret=0;
160
161 str=_CONF_get_string(conf,section,name);
162 if (str == NULL) return(0);
163 for (;;)
164 {
165 if (conf->meth->is_number(conf, *str))
166 ret=ret*10+conf->meth->to_int(conf, *str);
167 else
168 return(ret);
169 str++;
170 }
171 }
172
173int _CONF_new_data(CONF *conf)
174 {
175 if (conf == NULL)
176 {
177 return 0;
178 }
179 if (conf->data == NULL)
180 if ((conf->data = lh_new(hash,cmp_conf)) == NULL)
181 {
182 return 0;
183 }
184 return 1;
185 }
186
187void _CONF_free_data(CONF *conf)
188 {
189 if (conf == NULL || conf->data == NULL) return;
190
191 conf->data->down_load=0; /* evil thing to make sure the 'OPENSSL_free()'
192 * works as expected */
193 lh_doall_arg(conf->data,(void (*)())value_free_hash,conf->data);
194
195 /* We now have only 'section' entries in the hash table.
196 * Due to problems with */
197
198 lh_doall_arg(conf->data,(void (*)())value_free_stack,conf->data);
199 lh_free(conf->data);
200 }
201
202static void value_free_hash(CONF_VALUE *a, LHASH *conf)
203 {
204 if (a->name != NULL)
205 {
206 a=(CONF_VALUE *)lh_delete(conf,a);
207 }
208 }
209
210static void value_free_stack(CONF_VALUE *a, LHASH *conf)
211 {
212 CONF_VALUE *vv;
213 STACK *sk;
214 int i;
215
216 if (a->name != NULL) return;
217
218 sk=(STACK *)a->value;
219 for (i=sk_num(sk)-1; i>=0; i--)
220 {
221 vv=(CONF_VALUE *)sk_value(sk,i);
222 OPENSSL_free(vv->value);
223 OPENSSL_free(vv->name);
224 OPENSSL_free(vv);
225 }
226 if (sk != NULL) sk_free(sk);
227 OPENSSL_free(a->section);
228 OPENSSL_free(a);
229 }
230
231static unsigned long hash(CONF_VALUE *v)
232 {
233 return((lh_strhash(v->section)<<2)^lh_strhash(v->name));
234 }
235
236static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b)
237 {
238 int i;
239
240 if (a->section != b->section)
241 {
242 i=strcmp(a->section,b->section);
243 if (i) return(i);
244 }
245
246 if ((a->name != NULL) && (b->name != NULL))
247 {
248 i=strcmp(a->name,b->name);
249 return(i);
250 }
251 else if (a->name == b->name)
252 return(0);
253 else
254 return((a->name == NULL)?-1:1);
255 }
256
257/* Up until OpenSSL 0.9.5a, this was new_section */
258CONF_VALUE *_CONF_new_section(CONF *conf, char *section)
259 {
260 STACK *sk=NULL;
261 int ok=0,i;
262 CONF_VALUE *v=NULL,*vv;
263
264 if ((sk=sk_new_null()) == NULL)
265 goto err;
266 if ((v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))) == NULL)
267 goto err;
268 i=strlen(section)+1;
269 if ((v->section=(char *)OPENSSL_malloc(i)) == NULL)
270 goto err;
271
272 memcpy(v->section,section,i);
273 v->name=NULL;
274 v->value=(char *)sk;
275
276 vv=(CONF_VALUE *)lh_insert(conf->data,v);
277 assert(vv == NULL);
278 ok=1;
279err:
280 if (!ok)
281 {
282 if (sk != NULL) sk_free(sk);
283 if (v != NULL) OPENSSL_free(v);
284 v=NULL;
285 }
286 return(v);
287 }
288
289IMPLEMENT_STACK_OF(CONF_VALUE)
diff --git a/src/lib/libcrypto/conf/conf_api.h b/src/lib/libcrypto/conf/conf_api.h
new file mode 100644
index 0000000000..a5cc17b233
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_api.h
@@ -0,0 +1,87 @@
1/* conf_api.h */
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#ifndef HEADER_CONF_API_H
60#define HEADER_CONF_API_H
61
62#include <openssl/lhash.h>
63#include <openssl/conf.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* Up until OpenSSL 0.9.5a, this was new_section */
70CONF_VALUE *_CONF_new_section(CONF *conf, char *section);
71/* Up until OpenSSL 0.9.5a, this was get_section */
72CONF_VALUE *_CONF_get_section(CONF *conf, char *section);
73/* Up until OpenSSL 0.9.5a, this was CONF_get_section */
74STACK_OF(CONF_VALUE) *_CONF_get_section_values(CONF *conf, char *section);
75
76int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value);
77char *_CONF_get_string(CONF *conf, char *section, char *name);
78long _CONF_get_number(CONF *conf, char *section, char *name);
79
80int _CONF_new_data(CONF *conf);
81void _CONF_free_data(CONF *conf);
82
83#ifdef __cplusplus
84}
85#endif
86#endif
87
diff --git a/src/lib/libcrypto/conf/conf_def.c b/src/lib/libcrypto/conf/conf_def.c
new file mode 100644
index 0000000000..773df32c68
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_def.c
@@ -0,0 +1,703 @@
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 <openssl/stack.h>
64#include <openssl/lhash.h>
65#include <openssl/conf.h>
66#include <openssl/conf_api.h>
67#include "conf_def.h"
68#include <openssl/buffer.h>
69#include <openssl/err.h>
70
71static char *eat_ws(CONF *conf, char *p);
72static char *eat_alpha_numeric(CONF *conf, char *p);
73static void clear_comments(CONF *conf, char *p);
74static int str_copy(CONF *conf,char *section,char **to, char *from);
75static char *scan_quote(CONF *conf, char *p);
76static char *scan_dquote(CONF *conf, char *p);
77#define scan_esc(conf,p) (((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2)))
78
79static CONF *def_create(CONF_METHOD *meth);
80static int def_init_default(CONF *conf);
81static int def_init_WIN32(CONF *conf);
82static int def_destroy(CONF *conf);
83static int def_destroy_data(CONF *conf);
84static int def_load(CONF *conf, BIO *bp, long *eline);
85static int def_dump(CONF *conf, BIO *bp);
86static int def_is_number(CONF *conf, char c);
87static int def_to_int(CONF *conf, char c);
88
89const char *CONF_def_version="CONF_def" OPENSSL_VERSION_PTEXT;
90
91static CONF_METHOD default_method = {
92 "OpenSSL default",
93 def_create,
94 def_init_default,
95 def_destroy,
96 def_destroy_data,
97 def_load,
98 def_dump,
99 def_is_number,
100 def_to_int
101 };
102
103static CONF_METHOD WIN32_method = {
104 "WIN32",
105 def_create,
106 def_init_WIN32,
107 def_destroy,
108 def_destroy_data,
109 def_load,
110 def_dump,
111 def_is_number,
112 def_to_int
113 };
114
115CONF_METHOD *NCONF_default()
116 {
117 return &default_method;
118 }
119CONF_METHOD *NCONF_WIN32()
120 {
121 return &WIN32_method;
122 }
123
124static CONF *def_create(CONF_METHOD *meth)
125 {
126 CONF *ret;
127
128 ret = (CONF *)OPENSSL_malloc(sizeof(CONF) + sizeof(unsigned short *));
129 if (ret)
130 if (meth->init(ret) == 0)
131 {
132 OPENSSL_free(ret);
133 ret = NULL;
134 }
135 return ret;
136 }
137
138static int def_init_default(CONF *conf)
139 {
140 if (conf == NULL)
141 return 0;
142
143 conf->meth = &default_method;
144 conf->meth_data = (void *)CONF_type_default;
145 conf->data = NULL;
146
147 return 1;
148 }
149
150static int def_init_WIN32(CONF *conf)
151 {
152 if (conf == NULL)
153 return 0;
154
155 conf->meth = &WIN32_method;
156 conf->meth_data = (void *)CONF_type_win32;
157 conf->data = NULL;
158
159 return 1;
160 }
161
162static int def_destroy(CONF *conf)
163 {
164 if (def_destroy_data(conf))
165 {
166 OPENSSL_free(conf);
167 return 1;
168 }
169 return 0;
170 }
171
172static int def_destroy_data(CONF *conf)
173 {
174 if (conf == NULL)
175 return 0;
176 _CONF_free_data(conf);
177 return 1;
178 }
179
180static int def_load(CONF *conf, BIO *in, long *line)
181 {
182#define BUFSIZE 512
183 char btmp[16];
184 int bufnum=0,i,ii;
185 BUF_MEM *buff=NULL;
186 char *s,*p,*end;
187 int again,n;
188 long eline=0;
189 CONF_VALUE *v=NULL,*tv;
190 CONF_VALUE *sv=NULL;
191 char *section=NULL,*buf;
192 STACK_OF(CONF_VALUE) *section_sk=NULL,*ts;
193 char *start,*psection,*pname;
194 void *h = (void *)(conf->data);
195
196 if ((buff=BUF_MEM_new()) == NULL)
197 {
198 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
199 goto err;
200 }
201
202 section=(char *)OPENSSL_malloc(10);
203 if (section == NULL)
204 {
205 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
206 goto err;
207 }
208 strcpy(section,"default");
209
210 if (_CONF_new_data(conf) == 0)
211 {
212 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
213 goto err;
214 }
215
216 sv=_CONF_new_section(conf,section);
217 if (sv == NULL)
218 {
219 CONFerr(CONF_F_CONF_LOAD_BIO,
220 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
221 goto err;
222 }
223 section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
224
225 bufnum=0;
226 for (;;)
227 {
228 again=0;
229 if (!BUF_MEM_grow(buff,bufnum+BUFSIZE))
230 {
231 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
232 goto err;
233 }
234 p= &(buff->data[bufnum]);
235 *p='\0';
236 BIO_gets(in, p, BUFSIZE-1);
237 p[BUFSIZE-1]='\0';
238 ii=i=strlen(p);
239 if (i == 0) break;
240 while (i > 0)
241 {
242 if ((p[i-1] != '\r') && (p[i-1] != '\n'))
243 break;
244 else
245 i--;
246 }
247 /* we removed some trailing stuff so there is a new
248 * line on the end. */
249 if (i == ii)
250 again=1; /* long line */
251 else
252 {
253 p[i]='\0';
254 eline++; /* another input line */
255 }
256
257 /* we now have a line with trailing \r\n removed */
258
259 /* i is the number of bytes */
260 bufnum+=i;
261
262 v=NULL;
263 /* check for line continuation */
264 if (bufnum >= 1)
265 {
266 /* If we have bytes and the last char '\\' and
267 * second last char is not '\\' */
268 p= &(buff->data[bufnum-1]);
269 if (IS_ESC(conf,p[0]) &&
270 ((bufnum <= 1) || !IS_ESC(conf,p[-1])))
271 {
272 bufnum--;
273 again=1;
274 }
275 }
276 if (again) continue;
277 bufnum=0;
278 buf=buff->data;
279
280 clear_comments(conf, buf);
281 n=strlen(buf);
282 s=eat_ws(conf, buf);
283 if (IS_EOF(conf,*s)) continue; /* blank line */
284 if (*s == '[')
285 {
286 char *ss;
287
288 s++;
289 start=eat_ws(conf, s);
290 ss=start;
291again:
292 end=eat_alpha_numeric(conf, ss);
293 p=eat_ws(conf, end);
294 if (*p != ']')
295 {
296 if (*p != '\0')
297 {
298 ss=p;
299 goto again;
300 }
301 CONFerr(CONF_F_CONF_LOAD_BIO,
302 CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
303 goto err;
304 }
305 *end='\0';
306 if (!str_copy(conf,NULL,&section,start)) goto err;
307 if ((sv=_CONF_get_section(conf,section)) == NULL)
308 sv=_CONF_new_section(conf,section);
309 if (sv == NULL)
310 {
311 CONFerr(CONF_F_CONF_LOAD_BIO,
312 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
313 goto err;
314 }
315 section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
316 continue;
317 }
318 else
319 {
320 pname=s;
321 psection=NULL;
322 end=eat_alpha_numeric(conf, s);
323 if ((end[0] == ':') && (end[1] == ':'))
324 {
325 *end='\0';
326 end+=2;
327 psection=pname;
328 pname=end;
329 end=eat_alpha_numeric(conf, end);
330 }
331 p=eat_ws(conf, end);
332 if (*p != '=')
333 {
334 CONFerr(CONF_F_CONF_LOAD_BIO,
335 CONF_R_MISSING_EQUAL_SIGN);
336 goto err;
337 }
338 *end='\0';
339 p++;
340 start=eat_ws(conf, p);
341 while (!IS_EOF(conf,*p))
342 p++;
343 p--;
344 while ((p != start) && (IS_WS(conf,*p)))
345 p--;
346 p++;
347 *p='\0';
348
349 if (!(v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))))
350 {
351 CONFerr(CONF_F_CONF_LOAD_BIO,
352 ERR_R_MALLOC_FAILURE);
353 goto err;
354 }
355 if (psection == NULL) psection=section;
356 v->name=(char *)OPENSSL_malloc(strlen(pname)+1);
357 v->value=NULL;
358 if (v->name == NULL)
359 {
360 CONFerr(CONF_F_CONF_LOAD_BIO,
361 ERR_R_MALLOC_FAILURE);
362 goto err;
363 }
364 strcpy(v->name,pname);
365 if (!str_copy(conf,psection,&(v->value),start)) goto err;
366
367 if (strcmp(psection,section) != 0)
368 {
369 if ((tv=_CONF_get_section(conf,psection))
370 == NULL)
371 tv=_CONF_new_section(conf,psection);
372 if (tv == NULL)
373 {
374 CONFerr(CONF_F_CONF_LOAD_BIO,
375 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
376 goto err;
377 }
378 ts=(STACK_OF(CONF_VALUE) *)tv->value;
379 }
380 else
381 {
382 tv=sv;
383 ts=section_sk;
384 }
385#if 1
386 if (_CONF_add_string(conf, tv, v) == 0)
387 {
388 CONFerr(CONF_F_CONF_LOAD_BIO,
389 ERR_R_MALLOC_FAILURE);
390 goto err;
391 }
392#else
393 v->section=tv->section;
394 if (!sk_CONF_VALUE_push(ts,v))
395 {
396 CONFerr(CONF_F_CONF_LOAD_BIO,
397 ERR_R_MALLOC_FAILURE);
398 goto err;
399 }
400 vv=(CONF_VALUE *)lh_insert(conf->data,v);
401 if (vv != NULL)
402 {
403 sk_CONF_VALUE_delete_ptr(ts,vv);
404 OPENSSL_free(vv->name);
405 OPENSSL_free(vv->value);
406 OPENSSL_free(vv);
407 }
408#endif
409 v=NULL;
410 }
411 }
412 if (buff != NULL) BUF_MEM_free(buff);
413 if (section != NULL) OPENSSL_free(section);
414 return(1);
415err:
416 if (buff != NULL) BUF_MEM_free(buff);
417 if (section != NULL) OPENSSL_free(section);
418 if (line != NULL) *line=eline;
419 sprintf(btmp,"%ld",eline);
420 ERR_add_error_data(2,"line ",btmp);
421 if ((h != conf->data) && (conf->data != NULL)) CONF_free(conf->data);
422 if (v != NULL)
423 {
424 if (v->name != NULL) OPENSSL_free(v->name);
425 if (v->value != NULL) OPENSSL_free(v->value);
426 if (v != NULL) OPENSSL_free(v);
427 }
428 return(0);
429 }
430
431static void clear_comments(CONF *conf, char *p)
432 {
433 char *to;
434
435 to=p;
436 for (;;)
437 {
438 if (IS_FCOMMENT(conf,*p))
439 {
440 *p='\0';
441 return;
442 }
443 if (!IS_WS(conf,*p))
444 {
445 break;
446 }
447 p++;
448 }
449
450 for (;;)
451 {
452 if (IS_COMMENT(conf,*p))
453 {
454 *p='\0';
455 return;
456 }
457 if (IS_DQUOTE(conf,*p))
458 {
459 p=scan_dquote(conf, p);
460 continue;
461 }
462 if (IS_QUOTE(conf,*p))
463 {
464 p=scan_quote(conf, p);
465 continue;
466 }
467 if (IS_ESC(conf,*p))
468 {
469 p=scan_esc(conf,p);
470 continue;
471 }
472 if (IS_EOF(conf,*p))
473 return;
474 else
475 p++;
476 }
477 }
478
479static int str_copy(CONF *conf, char *section, char **pto, char *from)
480 {
481 int q,r,rr=0,to=0,len=0;
482 char *s,*e,*rp,*p,*rrp,*np,*cp,v;
483 BUF_MEM *buf;
484
485 if ((buf=BUF_MEM_new()) == NULL) return(0);
486
487 len=strlen(from)+1;
488 if (!BUF_MEM_grow(buf,len)) goto err;
489
490 for (;;)
491 {
492 if (IS_QUOTE(conf,*from))
493 {
494 q= *from;
495 from++;
496 while (!IS_EOF(conf,*from) && (*from != q))
497 {
498 if (IS_ESC(conf,*from))
499 {
500 from++;
501 if (IS_EOF(conf,*from)) break;
502 }
503 buf->data[to++]= *(from++);
504 }
505 if (*from == q) from++;
506 }
507 else if (IS_DQUOTE(conf,*from))
508 {
509 q= *from;
510 from++;
511 while (!IS_EOF(conf,*from))
512 {
513 if (*from == q)
514 {
515 if (*(from+1) == q)
516 {
517 from++;
518 }
519 else
520 {
521 break;
522 }
523 }
524 buf->data[to++]= *(from++);
525 }
526 if (*from == q) from++;
527 }
528 else if (IS_ESC(conf,*from))
529 {
530 from++;
531 v= *(from++);
532 if (IS_EOF(conf,v)) break;
533 else if (v == 'r') v='\r';
534 else if (v == 'n') v='\n';
535 else if (v == 'b') v='\b';
536 else if (v == 't') v='\t';
537 buf->data[to++]= v;
538 }
539 else if (IS_EOF(conf,*from))
540 break;
541 else if (*from == '$')
542 {
543 /* try to expand it */
544 rrp=NULL;
545 s= &(from[1]);
546 if (*s == '{')
547 q='}';
548 else if (*s == '(')
549 q=')';
550 else q=0;
551
552 if (q) s++;
553 cp=section;
554 e=np=s;
555 while (IS_ALPHA_NUMERIC(conf,*e))
556 e++;
557 if ((e[0] == ':') && (e[1] == ':'))
558 {
559 cp=np;
560 rrp=e;
561 rr= *e;
562 *rrp='\0';
563 e+=2;
564 np=e;
565 while (IS_ALPHA_NUMERIC(conf,*e))
566 e++;
567 }
568 r= *e;
569 *e='\0';
570 rp=e;
571 if (q)
572 {
573 if (r != q)
574 {
575 CONFerr(CONF_F_STR_COPY,CONF_R_NO_CLOSE_BRACE);
576 goto err;
577 }
578 e++;
579 }
580 /* So at this point we have
581 * ns which is the start of the name string which is
582 * '\0' terminated.
583 * cs which is the start of the section string which is
584 * '\0' terminated.
585 * e is the 'next point after'.
586 * r and s are the chars replaced by the '\0'
587 * rp and sp is where 'r' and 's' came from.
588 */
589 p=_CONF_get_string(conf,cp,np);
590 if (rrp != NULL) *rrp=rr;
591 *rp=r;
592 if (p == NULL)
593 {
594 CONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE);
595 goto err;
596 }
597 BUF_MEM_grow(buf,(strlen(p)+len-(e-from)));
598 while (*p)
599 buf->data[to++]= *(p++);
600 from=e;
601 }
602 else
603 buf->data[to++]= *(from++);
604 }
605 buf->data[to]='\0';
606 if (*pto != NULL) OPENSSL_free(*pto);
607 *pto=buf->data;
608 OPENSSL_free(buf);
609 return(1);
610err:
611 if (buf != NULL) BUF_MEM_free(buf);
612 return(0);
613 }
614
615static char *eat_ws(CONF *conf, char *p)
616 {
617 while (IS_WS(conf,*p) && (!IS_EOF(conf,*p)))
618 p++;
619 return(p);
620 }
621
622static char *eat_alpha_numeric(CONF *conf, char *p)
623 {
624 for (;;)
625 {
626 if (IS_ESC(conf,*p))
627 {
628 p=scan_esc(conf,p);
629 continue;
630 }
631 if (!IS_ALPHA_NUMERIC_PUNCT(conf,*p))
632 return(p);
633 p++;
634 }
635 }
636
637static char *scan_quote(CONF *conf, char *p)
638 {
639 int q= *p;
640
641 p++;
642 while (!(IS_EOF(conf,*p)) && (*p != q))
643 {
644 if (IS_ESC(conf,*p))
645 {
646 p++;
647 if (IS_EOF(conf,*p)) return(p);
648 }
649 p++;
650 }
651 if (*p == q) p++;
652 return(p);
653 }
654
655
656static char *scan_dquote(CONF *conf, char *p)
657 {
658 int q= *p;
659
660 p++;
661 while (!(IS_EOF(conf,*p)))
662 {
663 if (*p == q)
664 {
665 if (*(p+1) == q)
666 {
667 p++;
668 }
669 else
670 {
671 break;
672 }
673 }
674 p++;
675 }
676 if (*p == q) p++;
677 return(p);
678 }
679
680static void dump_value(CONF_VALUE *a, BIO *out)
681 {
682 if (a->name)
683 BIO_printf(out, "[%s] %s=%s\n", a->section, a->name, a->value);
684 else
685 BIO_printf(out, "[[%s]]\n", a->section);
686 }
687
688static int def_dump(CONF *conf, BIO *out)
689 {
690 lh_doall_arg(conf->data, (void (*)())dump_value, out);
691 return 1;
692 }
693
694static int def_is_number(CONF *conf, char c)
695 {
696 return IS_NUMBER(conf,c);
697 }
698
699static int def_to_int(CONF *conf, char c)
700 {
701 return c - '0';
702 }
703
diff --git a/src/lib/libcrypto/conf/conf_def.h b/src/lib/libcrypto/conf/conf_def.h
new file mode 100644
index 0000000000..3244d9a331
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_def.h
@@ -0,0 +1,145 @@
1/* crypto/conf/conf_def.h */
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/* THIS FILE WAS AUTOMAGICALLY GENERATED!
60 Please modify and use keysets.pl to regenerate it. */
61
62#define CONF_NUMBER 1
63#define CONF_UPPER 2
64#define CONF_LOWER 4
65#define CONF_UNDER 256
66#define CONF_PUNCTUATION 512
67#define CONF_WS 16
68#define CONF_ESC 32
69#define CONF_QUOTE 64
70#define CONF_DQUOTE 1024
71#define CONF_COMMENT 128
72#define CONF_FCOMMENT 2048
73#define CONF_EOF 8
74#define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
75#define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
76#define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \
77 CONF_PUNCTUATION)
78
79#define KEYTYPES(c) ((unsigned short *)((c)->meth_data))
80#ifndef CHARSET_EBCDIC
81#define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_COMMENT)
82#define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_FCOMMENT)
83#define IS_EOF(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_EOF)
84#define IS_ESC(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_ESC)
85#define IS_NUMBER(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_NUMBER)
86#define IS_WS(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_WS)
87#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_ALPHA_NUMERIC)
88#define IS_ALPHA_NUMERIC_PUNCT(c,a) \
89 (KEYTYPES(c)[(a)&0x7f]&CONF_ALPHA_NUMERIC_PUNCT)
90#define IS_QUOTE(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_QUOTE)
91#define IS_DQUOTE(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_DQUOTE)
92
93#else /*CHARSET_EBCDIC*/
94
95#define IS_COMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_COMMENT)
96#define IS_FCOMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_FCOMMENT)
97#define IS_EOF(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_EOF)
98#define IS_ESC(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ESC)
99#define IS_NUMBER(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_NUMBER)
100#define IS_WS(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_WS)
101#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC)
102#define IS_ALPHA_NUMERIC_PUNCT(c,a) \
103 (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC_PUNCT)
104#define IS_QUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_QUOTE)
105#define IS_DQUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_DQUOTE)
106#endif /*CHARSET_EBCDIC*/
107
108static unsigned short CONF_type_default[128]={
109 0x008,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
110 0x000,0x010,0x010,0x000,0x000,0x010,0x000,0x000,
111 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
112 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
113 0x010,0x200,0x040,0x080,0x000,0x200,0x200,0x040,
114 0x000,0x000,0x200,0x200,0x200,0x200,0x200,0x200,
115 0x001,0x001,0x001,0x001,0x001,0x001,0x001,0x001,
116 0x001,0x001,0x000,0x200,0x000,0x000,0x000,0x200,
117 0x200,0x002,0x002,0x002,0x002,0x002,0x002,0x002,
118 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002,
119 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002,
120 0x002,0x002,0x002,0x000,0x020,0x000,0x200,0x100,
121 0x040,0x004,0x004,0x004,0x004,0x004,0x004,0x004,
122 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004,
123 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004,
124 0x004,0x004,0x004,0x000,0x200,0x000,0x200,0x000,
125 };
126
127static unsigned short CONF_type_win32[128]={
128 0x008,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
129 0x000,0x010,0x010,0x000,0x000,0x010,0x000,0x000,
130 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
131 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
132 0x010,0x200,0x400,0x000,0x000,0x200,0x200,0x000,
133 0x000,0x000,0x200,0x200,0x200,0x200,0x200,0x200,
134 0x001,0x001,0x001,0x001,0x001,0x001,0x001,0x001,
135 0x001,0x001,0x000,0xA00,0x000,0x000,0x000,0x200,
136 0x200,0x002,0x002,0x002,0x002,0x002,0x002,0x002,
137 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002,
138 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002,
139 0x002,0x002,0x002,0x000,0x000,0x000,0x200,0x100,
140 0x000,0x004,0x004,0x004,0x004,0x004,0x004,0x004,
141 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004,
142 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004,
143 0x004,0x004,0x004,0x000,0x200,0x000,0x200,0x000,
144 };
145
diff --git a/src/lib/libcrypto/conf/conf_err.c b/src/lib/libcrypto/conf/conf_err.c
index 5c1ca59090..06d3163573 100644
--- a/src/lib/libcrypto/conf/conf_err.c
+++ b/src/lib/libcrypto/conf/conf_err.c
@@ -66,9 +66,17 @@
66#ifndef NO_ERR 66#ifndef NO_ERR
67static ERR_STRING_DATA CONF_str_functs[]= 67static ERR_STRING_DATA CONF_str_functs[]=
68 { 68 {
69{ERR_PACK(0,CONF_F_CONF_DUMP_FP,0), "CONF_dump_fp"},
69{ERR_PACK(0,CONF_F_CONF_LOAD,0), "CONF_load"}, 70{ERR_PACK(0,CONF_F_CONF_LOAD,0), "CONF_load"},
70{ERR_PACK(0,CONF_F_CONF_LOAD_BIO,0), "CONF_load_bio"}, 71{ERR_PACK(0,CONF_F_CONF_LOAD_BIO,0), "CONF_load_bio"},
71{ERR_PACK(0,CONF_F_CONF_LOAD_FP,0), "CONF_load_fp"}, 72{ERR_PACK(0,CONF_F_CONF_LOAD_FP,0), "CONF_load_fp"},
73{ERR_PACK(0,CONF_F_NCONF_DUMP_BIO,0), "NCONF_dump_bio"},
74{ERR_PACK(0,CONF_F_NCONF_DUMP_FP,0), "NCONF_dump_fp"},
75{ERR_PACK(0,CONF_F_NCONF_GET_NUMBER,0), "NCONF_get_number"},
76{ERR_PACK(0,CONF_F_NCONF_GET_SECTION,0), "NCONF_get_section"},
77{ERR_PACK(0,CONF_F_NCONF_GET_STRING,0), "NCONF_get_string"},
78{ERR_PACK(0,CONF_F_NCONF_LOAD_BIO,0), "NCONF_load_bio"},
79{ERR_PACK(0,CONF_F_NCONF_NEW,0), "NCONF_new"},
72{ERR_PACK(0,CONF_F_STR_COPY,0), "STR_COPY"}, 80{ERR_PACK(0,CONF_F_STR_COPY,0), "STR_COPY"},
73{0,NULL} 81{0,NULL}
74 }; 82 };
@@ -78,6 +86,7 @@ static ERR_STRING_DATA CONF_str_reasons[]=
78{CONF_R_MISSING_CLOSE_SQUARE_BRACKET ,"missing close square bracket"}, 86{CONF_R_MISSING_CLOSE_SQUARE_BRACKET ,"missing close square bracket"},
79{CONF_R_MISSING_EQUAL_SIGN ,"missing equal sign"}, 87{CONF_R_MISSING_EQUAL_SIGN ,"missing equal sign"},
80{CONF_R_NO_CLOSE_BRACE ,"no close brace"}, 88{CONF_R_NO_CLOSE_BRACE ,"no close brace"},
89{CONF_R_NO_CONF ,"no conf"},
81{CONF_R_UNABLE_TO_CREATE_NEW_SECTION ,"unable to create new section"}, 90{CONF_R_UNABLE_TO_CREATE_NEW_SECTION ,"unable to create new section"},
82{CONF_R_VARIABLE_HAS_NO_VALUE ,"variable has no value"}, 91{CONF_R_VARIABLE_HAS_NO_VALUE ,"variable has no value"},
83{0,NULL} 92{0,NULL}
diff --git a/src/lib/libcrypto/conf/conf_lcl.h b/src/lib/libcrypto/conf/conf_lcl.h
index f9a015df57..e69de29bb2 100644
--- a/src/lib/libcrypto/conf/conf_lcl.h
+++ b/src/lib/libcrypto/conf/conf_lcl.h
@@ -1,116 +0,0 @@
1/* crypto/conf/conf_lcl.h */
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#define CONF_NUMBER 1
60#define CONF_UPPER 2
61#define CONF_LOWER 4
62#define CONF_UNDER 256
63#define CONF_PUNCTUATION 512
64#define CONF_WS 16
65#define CONF_ESC 32
66#define CONF_QUOTE 64
67#define CONF_COMMENT 128
68#define CONF_EOF 8
69#define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
70#define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
71#define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \
72 CONF_PUNCTUATION)
73
74#ifndef CHARSET_EBCDIC
75#define IS_COMMENT(a) (CONF_COMMENT&(CONF_type[(a)&0x7f]))
76#define IS_EOF(a) ((a) == '\0')
77#define IS_ESC(a) ((a) == '\\')
78#define IS_NUMER(a) (CONF_type[(a)&0x7f]&CONF_NUMBER)
79#define IS_WS(a) (CONF_type[(a)&0x7f]&CONF_WS)
80#define IS_ALPHA_NUMERIC(a) (CONF_type[(a)&0x7f]&CONF_ALPHA_NUMERIC)
81#define IS_ALPHA_NUMERIC_PUNCT(a) \
82 (CONF_type[(a)&0x7f]&CONF_ALPHA_NUMERIC_PUNCT)
83#define IS_QUOTE(a) (CONF_type[(a)&0x7f]&CONF_QUOTE)
84
85#else /*CHARSET_EBCDIC*/
86
87#define IS_COMMENT(a) (CONF_COMMENT&(CONF_type[os_toascii[a]&0x7f]))
88#define IS_EOF(a) (os_toascii[a] == '\0')
89#define IS_ESC(a) (os_toascii[a] == '\\')
90#define IS_NUMER(a) (CONF_type[os_toascii[a]&0x7f]&CONF_NUMBER)
91#define IS_WS(a) (CONF_type[os_toascii[a]&0x7f]&CONF_WS)
92#define IS_ALPHA_NUMERIC(a) (CONF_type[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC)
93#define IS_ALPHA_NUMERIC_PUNCT(a) \
94 (CONF_type[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC_PUNCT)
95#define IS_QUOTE(a) (CONF_type[os_toascii[a]&0x7f]&CONF_QUOTE)
96#endif /*CHARSET_EBCDIC*/
97
98static unsigned short CONF_type[128]={
99 0x008,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
100 0x000,0x010,0x010,0x000,0x000,0x010,0x000,0x000,
101 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
102 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
103 0x010,0x200,0x040,0x080,0x000,0x200,0x200,0x040,
104 0x000,0x000,0x200,0x200,0x200,0x200,0x200,0x200,
105 0x001,0x001,0x001,0x001,0x001,0x001,0x001,0x001,
106 0x001,0x001,0x000,0x200,0x000,0x000,0x000,0x200,
107 0x200,0x002,0x002,0x002,0x002,0x002,0x002,0x002,
108 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002,
109 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002,
110 0x002,0x002,0x002,0x000,0x020,0x000,0x200,0x100,
111 0x040,0x004,0x004,0x004,0x004,0x004,0x004,0x004,
112 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004,
113 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004,
114 0x004,0x004,0x004,0x000,0x200,0x000,0x200,0x000,
115 };
116
diff --git a/src/lib/libcrypto/conf/conf_lib.c b/src/lib/libcrypto/conf/conf_lib.c
new file mode 100644
index 0000000000..4c8ca9e9ae
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_lib.c
@@ -0,0 +1,352 @@
1/* conf_lib.c */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include <openssl/err.h>
62#include <openssl/conf.h>
63#include <openssl/conf_api.h>
64#include <openssl/lhash.h>
65
66const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT;
67
68static CONF_METHOD *default_CONF_method=NULL;
69
70/* The following section contains the "CONF classic" functions,
71 rewritten in terms of the new CONF interface. */
72
73int CONF_set_default_method(CONF_METHOD *meth)
74 {
75 default_CONF_method = meth;
76 return 1;
77 }
78
79LHASH *CONF_load(LHASH *conf, const char *file, long *eline)
80 {
81 LHASH *ltmp;
82 BIO *in=NULL;
83
84#ifdef VMS
85 in=BIO_new_file(file, "r");
86#else
87 in=BIO_new_file(file, "rb");
88#endif
89 if (in == NULL)
90 {
91 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
92 return NULL;
93 }
94
95 ltmp = CONF_load_bio(conf, in, eline);
96 BIO_free(in);
97
98 return ltmp;
99 }
100
101#ifndef NO_FP_API
102LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline)
103 {
104 BIO *btmp;
105 LHASH *ltmp;
106 if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) {
107 CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
108 return NULL;
109 }
110 ltmp = CONF_load_bio(conf, btmp, eline);
111 BIO_free(btmp);
112 return ltmp;
113 }
114#endif
115
116LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline)
117 {
118 CONF ctmp;
119 int ret;
120
121 if (default_CONF_method == NULL)
122 default_CONF_method = NCONF_default();
123
124 default_CONF_method->init(&ctmp);
125 ctmp.data = conf;
126 ret = NCONF_load_bio(&ctmp, bp, eline);
127 if (ret)
128 return ctmp.data;
129 return NULL;
130 }
131
132STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section)
133 {
134 CONF ctmp;
135
136 if (default_CONF_method == NULL)
137 default_CONF_method = NCONF_default();
138
139 default_CONF_method->init(&ctmp);
140 ctmp.data = conf;
141 return NCONF_get_section(&ctmp, section);
142 }
143
144char *CONF_get_string(LHASH *conf,char *group,char *name)
145 {
146 CONF ctmp;
147
148 if (default_CONF_method == NULL)
149 default_CONF_method = NCONF_default();
150
151 default_CONF_method->init(&ctmp);
152 ctmp.data = conf;
153 return NCONF_get_string(&ctmp, group, name);
154 }
155
156long CONF_get_number(LHASH *conf,char *group,char *name)
157 {
158 CONF ctmp;
159
160 if (default_CONF_method == NULL)
161 default_CONF_method = NCONF_default();
162
163 default_CONF_method->init(&ctmp);
164 ctmp.data = conf;
165 return NCONF_get_number(&ctmp, group, name);
166 }
167
168void CONF_free(LHASH *conf)
169 {
170 CONF ctmp;
171
172 if (default_CONF_method == NULL)
173 default_CONF_method = NCONF_default();
174
175 default_CONF_method->init(&ctmp);
176 ctmp.data = conf;
177 NCONF_free_data(&ctmp);
178 }
179
180#ifndef NO_FP_API
181int CONF_dump_fp(LHASH *conf, FILE *out)
182 {
183 BIO *btmp;
184 int ret;
185
186 if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
187 CONFerr(CONF_F_CONF_DUMP_FP,ERR_R_BUF_LIB);
188 return 0;
189 }
190 ret = CONF_dump_bio(conf, btmp);
191 BIO_free(btmp);
192 return ret;
193 }
194#endif
195
196int CONF_dump_bio(LHASH *conf, BIO *out)
197 {
198 CONF ctmp;
199
200 if (default_CONF_method == NULL)
201 default_CONF_method = NCONF_default();
202
203 default_CONF_method->init(&ctmp);
204 ctmp.data = conf;
205 return NCONF_dump_bio(&ctmp, out);
206 }
207
208/* The following section contains the "New CONF" functions. They are
209 completely centralised around a new CONF structure that may contain
210 basically anything, but at least a method pointer and a table of data.
211 These functions are also written in terms of the bridge functions used
212 by the "CONF classic" functions, for consistency. */
213
214CONF *NCONF_new(CONF_METHOD *meth)
215 {
216 CONF *ret;
217
218 if (meth == NULL)
219 meth = NCONF_default();
220
221 ret = meth->create(meth);
222 if (ret == NULL)
223 {
224 CONFerr(CONF_F_NCONF_NEW,ERR_R_MALLOC_FAILURE);
225 return(NULL);
226 }
227
228 return ret;
229 }
230
231void NCONF_free(CONF *conf)
232 {
233 if (conf == NULL)
234 return;
235 conf->meth->destroy(conf);
236 }
237
238void NCONF_free_data(CONF *conf)
239 {
240 if (conf == NULL)
241 return;
242 conf->meth->destroy_data(conf);
243 }
244
245int NCONF_load(CONF *conf, const char *file, long *eline)
246 {
247 int ret;
248 BIO *in=NULL;
249
250#ifdef VMS
251 in=BIO_new_file(file, "r");
252#else
253 in=BIO_new_file(file, "rb");
254#endif
255 if (in == NULL)
256 {
257 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
258 return 0;
259 }
260
261 ret = NCONF_load_bio(conf, in, eline);
262 BIO_free(in);
263
264 return ret;
265 }
266
267#ifndef NO_FP_API
268int NCONF_load_fp(CONF *conf, FILE *fp,long *eline)
269 {
270 BIO *btmp;
271 int ret;
272 if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE)))
273 {
274 CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
275 return 0;
276 }
277 ret = NCONF_load_bio(conf, btmp, eline);
278 BIO_free(btmp);
279 return ret;
280 }
281#endif
282
283int NCONF_load_bio(CONF *conf, BIO *bp,long *eline)
284 {
285 if (conf == NULL)
286 {
287 CONFerr(CONF_F_NCONF_LOAD_BIO,CONF_R_NO_CONF);
288 return 0;
289 }
290
291 return conf->meth->load(conf, bp, eline);
292 }
293
294STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section)
295 {
296 if (conf == NULL)
297 {
298 CONFerr(CONF_F_NCONF_GET_SECTION,CONF_R_NO_CONF);
299 return NULL;
300 }
301
302 return _CONF_get_section_values(conf, section);
303 }
304
305char *NCONF_get_string(CONF *conf,char *group,char *name)
306 {
307 if (conf == NULL)
308 {
309 CONFerr(CONF_F_NCONF_GET_STRING,CONF_R_NO_CONF);
310 return NULL;
311 }
312
313 return _CONF_get_string(conf, group, name);
314 }
315
316long NCONF_get_number(CONF *conf,char *group,char *name)
317 {
318 if (conf == NULL)
319 {
320 CONFerr(CONF_F_NCONF_GET_NUMBER,CONF_R_NO_CONF);
321 return 0;
322 }
323
324 return _CONF_get_number(conf, group, name);
325 }
326
327#ifndef NO_FP_API
328int NCONF_dump_fp(CONF *conf, FILE *out)
329 {
330 BIO *btmp;
331 int ret;
332 if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
333 CONFerr(CONF_F_NCONF_DUMP_FP,ERR_R_BUF_LIB);
334 return 0;
335 }
336 ret = NCONF_dump_bio(conf, btmp);
337 BIO_free(btmp);
338 return ret;
339 }
340#endif
341
342int NCONF_dump_bio(CONF *conf, BIO *out)
343 {
344 if (conf == NULL)
345 {
346 CONFerr(CONF_F_NCONF_DUMP_BIO,CONF_R_NO_CONF);
347 return 0;
348 }
349
350 return conf->meth->dump(conf, out);
351 }
352
diff --git a/src/lib/libcrypto/conf/keysets.pl b/src/lib/libcrypto/conf/keysets.pl
index 1aed0c80c4..56669e76ac 100644
--- a/src/lib/libcrypto/conf/keysets.pl
+++ b/src/lib/libcrypto/conf/keysets.pl
@@ -3,12 +3,15 @@
3$NUMBER=0x01; 3$NUMBER=0x01;
4$UPPER=0x02; 4$UPPER=0x02;
5$LOWER=0x04; 5$LOWER=0x04;
6$EOF=0x08; 6$UNDER=0x100;
7$PUNCTUATION=0x200;
7$WS=0x10; 8$WS=0x10;
8$ESC=0x20; 9$ESC=0x20;
9$QUOTE=0x40; 10$QUOTE=0x40;
11$DQUOTE=0x400;
10$COMMENT=0x80; 12$COMMENT=0x80;
11$UNDER=0x100; 13$FCOMMENT=0x800;
14$EOF=0x08;
12 15
13foreach (0 .. 127) 16foreach (0 .. 127)
14 { 17 {
@@ -18,44 +21,159 @@ foreach (0 .. 127)
18 $v|=$UPPER if ($c =~ /[A-Z]/); 21 $v|=$UPPER if ($c =~ /[A-Z]/);
19 $v|=$LOWER if ($c =~ /[a-z]/); 22 $v|=$LOWER if ($c =~ /[a-z]/);
20 $v|=$UNDER if ($c =~ /_/); 23 $v|=$UNDER if ($c =~ /_/);
21 $v|=$WS if ($c =~ / \t\r\n/); 24 $v|=$PUNCTUATION if ($c =~ /[!\.%&\*\+,\/;\?\@\^\~\|-]/);
25 $v|=$WS if ($c =~ /[ \t\r\n]/);
22 $v|=$ESC if ($c =~ /\\/); 26 $v|=$ESC if ($c =~ /\\/);
23 $v|=$QUOTE if ($c =~ /['`"]/); 27 $v|=$QUOTE if ($c =~ /['`"]/); # for emacs: "`'}/)
24 $v|=$COMMENT if ($c =~ /\#/); 28 $v|=$COMMENT if ($c =~ /\#/);
25 $v|=$EOF if ($c =~ /\0/); 29 $v|=$EOF if ($c =~ /\0/);
26 30
27 push(@V,$v); 31 push(@V_def,$v);
32 }
33
34foreach (0 .. 127)
35 {
36 $v=0;
37 $c=sprintf("%c",$_);
38 $v|=$NUMBER if ($c =~ /[0-9]/);
39 $v|=$UPPER if ($c =~ /[A-Z]/);
40 $v|=$LOWER if ($c =~ /[a-z]/);
41 $v|=$UNDER if ($c =~ /_/);
42 $v|=$PUNCTUATION if ($c =~ /[!\.%&\*\+,\/;\?\@\^\~\|-]/);
43 $v|=$WS if ($c =~ /[ \t\r\n]/);
44 $v|=$DQUOTE if ($c =~ /["]/); # for emacs: "}/)
45 $v|=$FCOMMENT if ($c =~ /;/);
46 $v|=$EOF if ($c =~ /\0/);
47
48 push(@V_w32,$v);
28 } 49 }
29 50
30print <<"EOF"; 51print <<"EOF";
52/* crypto/conf/conf_def.h */
53/* Copyright (C) 1995-1998 Eric Young (eay\@cryptsoft.com)
54 * All rights reserved.
55 *
56 * This package is an SSL implementation written
57 * by Eric Young (eay\@cryptsoft.com).
58 * The implementation was written so as to conform with Netscapes SSL.
59 *
60 * This library is free for commercial and non-commercial use as long as
61 * the following conditions are aheared to. The following conditions
62 * apply to all code found in this distribution, be it the RC4, RSA,
63 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
64 * included with this distribution is covered by the same copyright terms
65 * except that the holder is Tim Hudson (tjh\@cryptsoft.com).
66 *
67 * Copyright remains Eric Young's, and as such any Copyright notices in
68 * the code are not to be removed.
69 * If this package is used in a product, Eric Young should be given attribution
70 * as the author of the parts of the library used.
71 * This can be in the form of a textual message at program startup or
72 * in documentation (online or textual) provided with the package.
73 *
74 * Redistribution and use in source and binary forms, with or without
75 * modification, are permitted provided that the following conditions
76 * are met:
77 * 1. Redistributions of source code must retain the copyright
78 * notice, this list of conditions and the following disclaimer.
79 * 2. Redistributions in binary form must reproduce the above copyright
80 * notice, this list of conditions and the following disclaimer in the
81 * documentation and/or other materials provided with the distribution.
82 * 3. All advertising materials mentioning features or use of this software
83 * must display the following acknowledgement:
84 * "This product includes cryptographic software written by
85 * Eric Young (eay\@cryptsoft.com)"
86 * The word 'cryptographic' can be left out if the rouines from the library
87 * being used are not cryptographic related :-).
88 * 4. If you include any Windows specific code (or a derivative thereof) from
89 * the apps directory (application code) you must include an acknowledgement:
90 * "This product includes software written by Tim Hudson (tjh\@cryptsoft.com)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
93 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
95 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
96 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
97 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
98 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
99 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
100 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
101 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
102 * SUCH DAMAGE.
103 *
104 * The licence and distribution terms for any publically available version or
105 * derivative of this code cannot be changed. i.e. this code cannot simply be
106 * copied and put under another distribution licence
107 * [including the GNU Public Licence.]
108 */
109
110/* THIS FILE WAS AUTOMAGICALLY GENERATED!
111 Please modify and use keysets.pl to regenerate it. */
112
31#define CONF_NUMBER $NUMBER 113#define CONF_NUMBER $NUMBER
32#define CONF_UPPER $UPPER 114#define CONF_UPPER $UPPER
33#define CONF_LOWER $LOWER 115#define CONF_LOWER $LOWER
34#define CONF_EOF $EOF 116#define CONF_UNDER $UNDER
117#define CONF_PUNCTUATION $PUNCTUATION
35#define CONF_WS $WS 118#define CONF_WS $WS
36#define CONF_ESC $ESC 119#define CONF_ESC $ESC
37#define CONF_QUOTE $QUOTE 120#define CONF_QUOTE $QUOTE
121#define CONF_DQUOTE $DQUOTE
38#define CONF_COMMENT $COMMENT 122#define CONF_COMMENT $COMMENT
123#define CONF_FCOMMENT $FCOMMENT
124#define CONF_EOF $EOF
39#define CONF_ALPHA (CONF_UPPER|CONF_LOWER) 125#define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
40#define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER) 126#define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
41#define CONF_UNDER $UNDER 127#define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \\
128 CONF_PUNCTUATION)
129
130#define KEYTYPES(c) ((unsigned short *)((c)->meth_data))
131#ifndef CHARSET_EBCDIC
132#define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_COMMENT)
133#define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_FCOMMENT)
134#define IS_EOF(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_EOF)
135#define IS_ESC(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_ESC)
136#define IS_NUMBER(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_NUMBER)
137#define IS_WS(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_WS)
138#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_ALPHA_NUMERIC)
139#define IS_ALPHA_NUMERIC_PUNCT(c,a) \\
140 (KEYTYPES(c)[(a)&0x7f]&CONF_ALPHA_NUMERIC_PUNCT)
141#define IS_QUOTE(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_QUOTE)
142#define IS_DQUOTE(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_DQUOTE)
143
144#else /*CHARSET_EBCDIC*/
42 145
43#define IS_COMMENT(a) (CONF_COMMENT&(CONF_type[(a)&0x7f])) 146#define IS_COMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_COMMENT)
44#define IS_EOF(a) ((a) == '\\0') 147#define IS_FCOMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_FCOMMENT)
45#define IS_ESC(a) ((a) == '\\\\') 148#define IS_EOF(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_EOF)
46#define IS_NUMER(a) (CONF_type[(a)&0x7f]&CONF_NUMBER) 149#define IS_ESC(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ESC)
47#define IS_WS(a) (CONF_type[(a)&0x7f]&CONF_WS) 150#define IS_NUMBER(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_NUMBER)
48#define IS_ALPHA_NUMERIC(a) (CONF_type[(a)&0x7f]&CONF_ALPHA_NUMERIC) 151#define IS_WS(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_WS)
49#define IS_QUOTE(a) (CONF_type[(a)&0x7f]&CONF_QUOTE) 152#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC)
153#define IS_ALPHA_NUMERIC_PUNCT(c,a) \\
154 (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC_PUNCT)
155#define IS_QUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_QUOTE)
156#define IS_DQUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_DQUOTE)
157#endif /*CHARSET_EBCDIC*/
50 158
51EOF 159EOF
52 160
53print "static unsigned short CONF_type[128]={"; 161print "static unsigned short CONF_type_default[128]={";
162
163for ($i=0; $i<128; $i++)
164 {
165 print "\n\t" if ($i % 8) == 0;
166 printf "0x%03X,",$V_def[$i];
167 }
168
169print "\n\t};\n\n";
170
171print "static unsigned short CONF_type_win32[128]={";
54 172
55for ($i=0; $i<128; $i++) 173for ($i=0; $i<128; $i++)
56 { 174 {
57 print "\n\t" if ($i % 8) == 0; 175 print "\n\t" if ($i % 8) == 0;
58 printf "0x%03X,",$V[$i]; 176 printf "0x%03X,",$V_w32[$i];
59 } 177 }
60 178
61print "\n\t};\n"; 179print "\n\t};\n\n";
diff --git a/src/lib/libcrypto/conf/test.c b/src/lib/libcrypto/conf/test.c
index 9390a48baf..7fab85053e 100644
--- a/src/lib/libcrypto/conf/test.c
+++ b/src/lib/libcrypto/conf/test.c
@@ -67,7 +67,10 @@ main()
67 long eline; 67 long eline;
68 char *s,*s2; 68 char *s,*s2;
69 69
70 conf=CONF_load(NULL,"openssl.conf",&eline); 70#ifdef USE_WIN32
71 CONF_set_default_method(CONF_WIN32);
72#endif
73 conf=CONF_load(NULL,"ssleay.cnf",&eline);
71 if (conf == NULL) 74 if (conf == NULL)
72 { 75 {
73 ERR_load_crypto_strings(); 76 ERR_load_crypto_strings();
@@ -88,5 +91,8 @@ main()
88 s=CONF_get_string(conf,"s_client","cipher1"); 91 s=CONF_get_string(conf,"s_client","cipher1");
89 printf("s_client:cipher1=%s\n",(s == NULL)?"NULL":s); 92 printf("s_client:cipher1=%s\n",(s == NULL)?"NULL":s);
90 93
94 printf("---------------------------- DUMP ------------------------\n");
95 CONF_dump_fp(conf, stdout);
96
91 exit(0); 97 exit(0);
92 } 98 }