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.ssl90
-rw-r--r--src/lib/libcrypto/conf/README78
-rw-r--r--src/lib/libcrypto/conf/cnf_save.c7
-rw-r--r--src/lib/libcrypto/conf/conf.c730
-rw-r--r--src/lib/libcrypto/conf/conf.h111
-rw-r--r--src/lib/libcrypto/conf/conf_api.c49
-rw-r--r--src/lib/libcrypto/conf/conf_api.h12
-rw-r--r--src/lib/libcrypto/conf/conf_def.c62
-rw-r--r--src/lib/libcrypto/conf/conf_def.h143
-rw-r--r--src/lib/libcrypto/conf/conf_err.c18
-rw-r--r--src/lib/libcrypto/conf/conf_lib.c158
-rw-r--r--src/lib/libcrypto/conf/conf_mall.c76
-rw-r--r--src/lib/libcrypto/conf/conf_mod.c616
-rw-r--r--src/lib/libcrypto/conf/conf_sap.c107
-rw-r--r--src/lib/libcrypto/conf/keysets.pl62
15 files changed, 2083 insertions, 236 deletions
diff --git a/src/lib/libcrypto/conf/Makefile.ssl b/src/lib/libcrypto/conf/Makefile.ssl
index 9df4fca877..795eec1a01 100644
--- a/src/lib/libcrypto/conf/Makefile.ssl
+++ b/src/lib/libcrypto/conf/Makefile.ssl
@@ -5,13 +5,14 @@
5DIR= conf 5DIR= conf
6TOP= ../.. 6TOP= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX= 10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl 11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
14MAKEDEPEND= $(TOP)/util/domd $(TOP) 14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
15MAKEFILE= Makefile.ssl 16MAKEFILE= Makefile.ssl
16AR= ar r 17AR= ar r
17 18
@@ -22,9 +23,11 @@ TEST=
22APPS= 23APPS=
23 24
24LIB=$(TOP)/libcrypto.a 25LIB=$(TOP)/libcrypto.a
25LIBSRC= conf_err.c conf_lib.c conf_api.c conf_def.c 26LIBSRC= conf_err.c conf_lib.c conf_api.c conf_def.c conf_mod.c \
27 conf_mall.c conf_sap.c
26 28
27LIBOBJ= conf_err.o conf_lib.o conf_api.o conf_def.o 29LIBOBJ= conf_err.o conf_lib.o conf_api.o conf_def.o conf_mod.o \
30 conf_mall.o conf_sap.o
28 31
29SRC= $(LIBSRC) 32SRC= $(LIBSRC)
30 33
@@ -40,8 +43,7 @@ all: lib
40 43
41lib: $(LIBOBJ) 44lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ) 45 $(AR) $(LIB) $(LIBOBJ)
43 @echo You may get an error following this line. Please ignore. 46 $(RANLIB) $(LIB) || echo Never mind.
44 - $(RANLIB) $(LIB)
45 @touch lib 47 @touch lib
46 48
47files: 49files:
@@ -80,30 +82,80 @@ clean:
80 82
81# DO NOT DELETE THIS LINE -- make depend depends on it. 83# DO NOT DELETE THIS LINE -- make depend depends on it.
82 84
83conf_api.o: ../../include/openssl/bio.h ../../include/openssl/conf.h 85conf_api.o: ../../e_os.h ../../include/openssl/bio.h
84conf_api.o: ../../include/openssl/conf_api.h ../../include/openssl/crypto.h 86conf_api.o: ../../include/openssl/conf.h ../../include/openssl/conf_api.h
85conf_api.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 87conf_api.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
86conf_api.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h 88conf_api.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
87conf_api.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 89conf_api.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
88conf_api.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 90conf_api.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
91conf_api.o: conf_api.c
89conf_def.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 92conf_def.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
90conf_def.o: ../../include/openssl/conf.h ../../include/openssl/conf_api.h 93conf_def.o: ../../include/openssl/conf.h ../../include/openssl/conf_api.h
91conf_def.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 94conf_def.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
92conf_def.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 95conf_def.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
93conf_def.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h 96conf_def.o: ../../include/openssl/opensslconf.h
94conf_def.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 97conf_def.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
95conf_def.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 98conf_def.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
96conf_def.o: conf_def.h 99conf_def.o: conf_def.c conf_def.h
97conf_err.o: ../../include/openssl/bio.h ../../include/openssl/conf.h 100conf_err.o: ../../include/openssl/bio.h ../../include/openssl/conf.h
98conf_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 101conf_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
99conf_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 102conf_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
100conf_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h 103conf_err.o: ../../include/openssl/opensslconf.h
101conf_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 104conf_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
102conf_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 105conf_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
106conf_err.o: conf_err.c
103conf_lib.o: ../../include/openssl/bio.h ../../include/openssl/conf.h 107conf_lib.o: ../../include/openssl/bio.h ../../include/openssl/conf.h
104conf_lib.o: ../../include/openssl/conf_api.h ../../include/openssl/crypto.h 108conf_lib.o: ../../include/openssl/conf_api.h ../../include/openssl/crypto.h
105conf_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 109conf_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
106conf_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h 110conf_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
107conf_lib.o: ../../include/openssl/opensslconf.h
108conf_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 111conf_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
109conf_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 112conf_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
113conf_lib.o: conf_lib.c
114conf_mall.o: ../../e_os.h ../../include/openssl/asn1.h
115conf_mall.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
116conf_mall.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
117conf_mall.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
118conf_mall.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h
119conf_mall.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
120conf_mall.o: ../../include/openssl/err.h ../../include/openssl/evp.h
121conf_mall.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
122conf_mall.o: ../../include/openssl/objects.h
123conf_mall.o: ../../include/openssl/opensslconf.h
124conf_mall.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
125conf_mall.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
126conf_mall.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
127conf_mall.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
128conf_mall.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
129conf_mall.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
130conf_mall.o: ../cryptlib.h conf_mall.c
131conf_mod.o: ../../e_os.h ../../include/openssl/asn1.h
132conf_mod.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
133conf_mod.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
134conf_mod.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
135conf_mod.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h
136conf_mod.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
137conf_mod.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
138conf_mod.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
139conf_mod.o: ../../include/openssl/opensslconf.h
140conf_mod.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
141conf_mod.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
142conf_mod.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
143conf_mod.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
144conf_mod.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
145conf_mod.o: ../cryptlib.h conf_mod.c
146conf_sap.o: ../../e_os.h ../../include/openssl/asn1.h
147conf_sap.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
148conf_sap.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
149conf_sap.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
150conf_sap.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h
151conf_sap.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
152conf_sap.o: ../../include/openssl/err.h ../../include/openssl/evp.h
153conf_sap.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
154conf_sap.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
155conf_sap.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
156conf_sap.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
157conf_sap.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
158conf_sap.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
159conf_sap.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
160conf_sap.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
161conf_sap.o: ../cryptlib.h conf_sap.c
diff --git a/src/lib/libcrypto/conf/README b/src/lib/libcrypto/conf/README
new file mode 100644
index 0000000000..ca58d0240f
--- /dev/null
+++ b/src/lib/libcrypto/conf/README
@@ -0,0 +1,78 @@
1WARNING WARNING WARNING!!!
2
3This stuff is experimental, may change radically or be deleted altogether
4before OpenSSL 0.9.7 release. You have been warned!
5
6Configuration modules. These are a set of modules which can perform
7various configuration functions.
8
9Currently the routines should be called at most once when an application
10starts up: that is before it starts any threads.
11
12The routines read a configuration file set up like this:
13
14-----
15#default section
16openssl_init=init_section
17
18[init_section]
19
20module1=value1
21#Second instance of module1
22module1.1=valueX
23module2=value2
24module3=dso_literal
25module4=dso_section
26
27[dso_section]
28
29path=/some/path/to/some/dso.so
30other_stuff=other_value
31----
32
33When this file is loaded a configuration module with the specified
34string (module* in the above example) is looked up and its init
35function called as:
36
37int conf_init_func(CONF_IMODULE *md, CONF *cnf);
38
39The function can then take whatever action is appropriate, for example
40further lookups based on the value. Multiple instances of the same
41config module can be loaded.
42
43When the application closes down the modules are cleaned up by calling
44an optional finish function:
45
46void conf_finish_func(CONF_IMODULE *md);
47
48The finish functions are called in reverse order: that is the last module
49loaded is the first one cleaned up.
50
51If no module exists with a given name then an attempt is made to load
52a DSO with the supplied name. This might mean that "module3" attempts
53to load a DSO called libmodule3.so or module3.dll for example. An explicit
54DSO name can be given by including a separate section as in the module4 example
55above.
56
57The DSO is expected to at least contain an initialization function:
58
59int OPENSSL_init(CONF_IMODULE *md, CONF *cnf);
60
61and may also include a finish function:
62
63void OPENSSL_finish(CONF_IMODULE *md);
64
65Static modules can also be added using,
66
67int CONF_module_add(char *name, dso_mod_init_func *ifunc, dso_mod_finish_func *ffunc);
68
69where "name" is the name in the configuration file this function corresponds to.
70
71A set of builtin modules (currently only an ASN1 non functional test module) can be
72added by calling OPENSSL_load_builtin_modules().
73
74The function OPENSSL_config() is intended as a simple configuration function that
75any application can call to perform various default configuration tasks. It uses the
76file openssl.cnf in the usual locations.
77
78
diff --git a/src/lib/libcrypto/conf/cnf_save.c b/src/lib/libcrypto/conf/cnf_save.c
index e907cc2242..1439487526 100644
--- a/src/lib/libcrypto/conf/cnf_save.c
+++ b/src/lib/libcrypto/conf/cnf_save.c
@@ -59,7 +59,8 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <openssl/conf.h> 60#include <openssl/conf.h>
61 61
62void print_conf(CONF_VALUE *cv); 62static void print_conf(CONF_VALUE *cv);
63static IMPLEMENT_LHASH_DOALL_FN(print_conf, CONF_VALUE *);
63 64
64main() 65main()
65 { 66 {
@@ -73,11 +74,11 @@ main()
73 exit(1); 74 exit(1);
74 } 75 }
75 76
76 lh_doall(conf,print_conf); 77 lh_doall(conf,LHASH_DOALL_FN(print_conf));
77 } 78 }
78 79
79 80
80void print_conf(CONF_VALUE *cv) 81static void print_conf(CONF_VALUE *cv)
81 { 82 {
82 int i; 83 int i;
83 CONF_VALUE *v; 84 CONF_VALUE *v;
diff --git a/src/lib/libcrypto/conf/conf.c b/src/lib/libcrypto/conf/conf.c
new file mode 100644
index 0000000000..3031fa3b44
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf.c
@@ -0,0 +1,730 @@
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 cd40a0db21..3c03fb19c0 100644
--- a/src/lib/libcrypto/conf/conf.h
+++ b/src/lib/libcrypto/conf/conf.h
@@ -63,7 +63,7 @@
63#include <openssl/lhash.h> 63#include <openssl/lhash.h>
64#include <openssl/stack.h> 64#include <openssl/stack.h>
65#include <openssl/safestack.h> 65#include <openssl/safestack.h>
66#include <openssl/e_os.h> 66#include <openssl/e_os2.h>
67 67
68#ifdef __cplusplus 68#ifdef __cplusplus
69extern "C" { 69extern "C" {
@@ -77,6 +77,8 @@ typedef struct
77 } CONF_VALUE; 77 } CONF_VALUE;
78 78
79DECLARE_STACK_OF(CONF_VALUE) 79DECLARE_STACK_OF(CONF_VALUE)
80DECLARE_STACK_OF(CONF_MODULE)
81DECLARE_STACK_OF(CONF_IMODULE)
80 82
81struct conf_st; 83struct conf_st;
82typedef struct conf_st CONF; 84typedef struct conf_st CONF;
@@ -86,29 +88,47 @@ typedef struct conf_method_st CONF_METHOD;
86struct conf_method_st 88struct conf_method_st
87 { 89 {
88 const char *name; 90 const char *name;
89 CONF *(MS_FAR *create)(CONF_METHOD *meth); 91 CONF *(*create)(CONF_METHOD *meth);
90 int (MS_FAR *init)(CONF *conf); 92 int (*init)(CONF *conf);
91 int (MS_FAR *destroy)(CONF *conf); 93 int (*destroy)(CONF *conf);
92 int (MS_FAR *destroy_data)(CONF *conf); 94 int (*destroy_data)(CONF *conf);
93 int (MS_FAR *load)(CONF *conf, BIO *bp, long *eline); 95 int (*load_bio)(CONF *conf, BIO *bp, long *eline);
94 int (MS_FAR *dump)(CONF *conf, BIO *bp); 96 int (*dump)(const CONF *conf, BIO *bp);
95 int (MS_FAR *is_number)(CONF *conf, char c); 97 int (*is_number)(const CONF *conf, char c);
96 int (MS_FAR *to_int)(CONF *conf, char c); 98 int (*to_int)(const CONF *conf, char c);
99 int (*load)(CONF *conf, const char *name, long *eline);
97 }; 100 };
98 101
102/* Module definitions */
103
104typedef struct conf_imodule_st CONF_IMODULE;
105typedef struct conf_module_st CONF_MODULE;
106
107/* DSO module function typedefs */
108typedef int conf_init_func(CONF_IMODULE *md, const CONF *cnf);
109typedef void conf_finish_func(CONF_IMODULE *md);
110
111#define CONF_MFLAGS_IGNORE_ERRORS 0x1
112#define CONF_MFLAGS_IGNORE_RETURN_CODES 0x2
113#define CONF_MFLAGS_SILENT 0x4
114#define CONF_MFLAGS_NO_DSO 0x8
115#define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10
116
99int CONF_set_default_method(CONF_METHOD *meth); 117int CONF_set_default_method(CONF_METHOD *meth);
118void CONF_set_nconf(CONF *conf,LHASH *hash);
100LHASH *CONF_load(LHASH *conf,const char *file,long *eline); 119LHASH *CONF_load(LHASH *conf,const char *file,long *eline);
101#ifndef NO_FP_API 120#ifndef OPENSSL_NO_FP_API
102LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline); 121LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline);
103#endif 122#endif
104LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline); 123LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline);
105STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section); 124STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,const char *section);
106char *CONF_get_string(LHASH *conf,char *group,char *name); 125char *CONF_get_string(LHASH *conf,const char *group,const char *name);
107long CONF_get_number(LHASH *conf,char *group,char *name); 126long CONF_get_number(LHASH *conf,const char *group,const char *name);
108void CONF_free(LHASH *conf); 127void CONF_free(LHASH *conf);
109int CONF_dump_fp(LHASH *conf, FILE *out); 128int CONF_dump_fp(LHASH *conf, FILE *out);
110int CONF_dump_bio(LHASH *conf, BIO *out); 129int CONF_dump_bio(LHASH *conf, BIO *out);
111void ERR_load_CONF_strings(void ); 130
131void OPENSSL_config(const char *config_name);
112 132
113/* New conf code. The semantics are different from the functions above. 133/* 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 */ 134 If that wasn't the case, the above functions would have been replaced */
@@ -130,21 +150,57 @@ void NCONF_free(CONF *conf);
130void NCONF_free_data(CONF *conf); 150void NCONF_free_data(CONF *conf);
131 151
132int NCONF_load(CONF *conf,const char *file,long *eline); 152int NCONF_load(CONF *conf,const char *file,long *eline);
133#ifndef NO_FP_API 153#ifndef OPENSSL_NO_FP_API
134int NCONF_load_fp(CONF *conf, FILE *fp,long *eline); 154int NCONF_load_fp(CONF *conf, FILE *fp,long *eline);
135#endif 155#endif
136int NCONF_load_bio(CONF *conf, BIO *bp,long *eline); 156int NCONF_load_bio(CONF *conf, BIO *bp,long *eline);
137STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section); 157STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,const char *section);
138char *NCONF_get_string(CONF *conf,char *group,char *name); 158char *NCONF_get_string(const CONF *conf,const char *group,const char *name);
159int NCONF_get_number_e(const CONF *conf,const char *group,const char *name,
160 long *result);
161int NCONF_dump_fp(const CONF *conf, FILE *out);
162int NCONF_dump_bio(const CONF *conf, BIO *out);
163
164#if 0 /* The following function has no error checking,
165 and should therefore be avoided */
139long NCONF_get_number(CONF *conf,char *group,char *name); 166long NCONF_get_number(CONF *conf,char *group,char *name);
140int NCONF_dump_fp(CONF *conf, FILE *out); 167#else
141int NCONF_dump_bio(CONF *conf, BIO *out); 168#define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r)
142 169#endif
170
171/* Module functions */
172
173int CONF_modules_load(const CONF *cnf, const char *appname,
174 unsigned long flags);
175int CONF_modules_load_file(const char *filename, const char *appname,
176 unsigned long flags);
177void CONF_modules_unload(int all);
178void CONF_modules_finish(void);
179int CONF_module_add(const char *name, conf_init_func *ifunc,
180 conf_finish_func *ffunc);
181
182const char *CONF_imodule_get_name(const CONF_IMODULE *md);
183const char *CONF_imodule_get_value(const CONF_IMODULE *md);
184void *CONF_imodule_get_usr_data(const CONF_IMODULE *md);
185void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data);
186CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md);
187unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md);
188void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags);
189void *CONF_module_get_usr_data(CONF_MODULE *pmod);
190void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data);
191
192char *CONF_get1_default_config_file(void);
193
194int CONF_parse_list(const char *list, int sep, int nospc,
195 int (*list_cb)(const char *elem, int len, void *usr), void *arg);
196
197void OPENSSL_load_builtin_modules(void);
143 198
144/* BEGIN ERROR CODES */ 199/* BEGIN ERROR CODES */
145/* The following lines are auto generated by the script mkerr.pl. Any changes 200/* The following lines are auto generated by the script mkerr.pl. Any changes
146 * made after this point may be overwritten when the script is next run. 201 * made after this point may be overwritten when the script is next run.
147 */ 202 */
203void ERR_load_CONF_strings(void);
148 204
149/* Error codes for the CONF functions. */ 205/* Error codes for the CONF functions. */
150 206
@@ -153,27 +209,40 @@ int NCONF_dump_bio(CONF *conf, BIO *out);
153#define CONF_F_CONF_LOAD 100 209#define CONF_F_CONF_LOAD 100
154#define CONF_F_CONF_LOAD_BIO 102 210#define CONF_F_CONF_LOAD_BIO 102
155#define CONF_F_CONF_LOAD_FP 103 211#define CONF_F_CONF_LOAD_FP 103
212#define CONF_F_CONF_MODULES_LOAD 116
213#define CONF_F_MODULE_INIT 115
214#define CONF_F_MODULE_LOAD_DSO 117
215#define CONF_F_MODULE_RUN 118
156#define CONF_F_NCONF_DUMP_BIO 105 216#define CONF_F_NCONF_DUMP_BIO 105
157#define CONF_F_NCONF_DUMP_FP 106 217#define CONF_F_NCONF_DUMP_FP 106
158#define CONF_F_NCONF_GET_NUMBER 107 218#define CONF_F_NCONF_GET_NUMBER 107
219#define CONF_F_NCONF_GET_NUMBER_E 112
159#define CONF_F_NCONF_GET_SECTION 108 220#define CONF_F_NCONF_GET_SECTION 108
160#define CONF_F_NCONF_GET_STRING 109 221#define CONF_F_NCONF_GET_STRING 109
222#define CONF_F_NCONF_LOAD 113
161#define CONF_F_NCONF_LOAD_BIO 110 223#define CONF_F_NCONF_LOAD_BIO 110
224#define CONF_F_NCONF_LOAD_FP 114
162#define CONF_F_NCONF_NEW 111 225#define CONF_F_NCONF_NEW 111
163#define CONF_F_STR_COPY 101 226#define CONF_F_STR_COPY 101
164 227
165/* Reason codes. */ 228/* Reason codes. */
229#define CONF_R_ERROR_LOADING_DSO 110
166#define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100 230#define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100
167#define CONF_R_MISSING_EQUAL_SIGN 101 231#define CONF_R_MISSING_EQUAL_SIGN 101
232#define CONF_R_MISSING_FINISH_FUNCTION 111
233#define CONF_R_MISSING_INIT_FUNCTION 112
234#define CONF_R_MODULE_INITIALIZATION_ERROR 109
168#define CONF_R_NO_CLOSE_BRACE 102 235#define CONF_R_NO_CLOSE_BRACE 102
169#define CONF_R_NO_CONF 105 236#define CONF_R_NO_CONF 105
170#define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE 106 237#define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE 106
171#define CONF_R_NO_SECTION 107 238#define CONF_R_NO_SECTION 107
239#define CONF_R_NO_SUCH_FILE 114
240#define CONF_R_NO_VALUE 108
172#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103 241#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103
242#define CONF_R_UNKNOWN_MODULE_NAME 113
173#define CONF_R_VARIABLE_HAS_NO_VALUE 104 243#define CONF_R_VARIABLE_HAS_NO_VALUE 104
174 244
175#ifdef __cplusplus 245#ifdef __cplusplus
176} 246}
177#endif 247#endif
178#endif 248#endif
179
diff --git a/src/lib/libcrypto/conf/conf_api.c b/src/lib/libcrypto/conf/conf_api.c
index d05a778ff6..0032baa711 100644
--- a/src/lib/libcrypto/conf/conf_api.c
+++ b/src/lib/libcrypto/conf/conf_api.c
@@ -67,26 +67,34 @@
67#include <string.h> 67#include <string.h>
68#include <openssl/conf.h> 68#include <openssl/conf.h>
69#include <openssl/conf_api.h> 69#include <openssl/conf_api.h>
70#include "e_os.h"
70 71
71static void value_free_hash(CONF_VALUE *a, LHASH *conf); 72static void value_free_hash(CONF_VALUE *a, LHASH *conf);
72static void value_free_stack(CONF_VALUE *a,LHASH *conf); 73static void value_free_stack(CONF_VALUE *a,LHASH *conf);
73static unsigned long hash(CONF_VALUE *v); 74static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_hash, CONF_VALUE *, LHASH *)
74static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b); 75static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_stack, CONF_VALUE *, LHASH *)
76/* We don't use function pointer casting or wrapper functions - but cast each
77 * callback parameter inside the callback functions. */
78/* static unsigned long hash(CONF_VALUE *v); */
79static unsigned long hash(const void *v_void);
80/* static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b); */
81static int cmp_conf(const void *a_void,const void *b_void);
75 82
76/* Up until OpenSSL 0.9.5a, this was get_section */ 83/* Up until OpenSSL 0.9.5a, this was get_section */
77CONF_VALUE *_CONF_get_section(CONF *conf, char *section) 84CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section)
78 { 85 {
79 CONF_VALUE *v,vv; 86 CONF_VALUE *v,vv;
80 87
81 if ((conf == NULL) || (section == NULL)) return(NULL); 88 if ((conf == NULL) || (section == NULL)) return(NULL);
82 vv.name=NULL; 89 vv.name=NULL;
83 vv.section=section; 90 vv.section=(char *)section;
84 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv); 91 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
85 return(v); 92 return(v);
86 } 93 }
87 94
88/* Up until OpenSSL 0.9.5a, this was CONF_get_section */ 95/* Up until OpenSSL 0.9.5a, this was CONF_get_section */
89STACK_OF(CONF_VALUE) *_CONF_get_section_values(CONF *conf, char *section) 96STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf,
97 const char *section)
90 { 98 {
91 CONF_VALUE *v; 99 CONF_VALUE *v;
92 100
@@ -121,7 +129,7 @@ int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value)
121 return 1; 129 return 1;
122 } 130 }
123 131
124char *_CONF_get_string(CONF *conf, char *section, char *name) 132char *_CONF_get_string(const CONF *conf, const char *section, const char *name)
125 { 133 {
126 CONF_VALUE *v,vv; 134 CONF_VALUE *v,vv;
127 char *p; 135 char *p;
@@ -131,8 +139,8 @@ char *_CONF_get_string(CONF *conf, char *section, char *name)
131 { 139 {
132 if (section != NULL) 140 if (section != NULL)
133 { 141 {
134 vv.name=name; 142 vv.name=(char *)name;
135 vv.section=section; 143 vv.section=(char *)section;
136 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv); 144 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
137 if (v != NULL) return(v->value); 145 if (v != NULL) return(v->value);
138 if (strcmp(section,"ENV") == 0) 146 if (strcmp(section,"ENV") == 0)
@@ -142,7 +150,7 @@ char *_CONF_get_string(CONF *conf, char *section, char *name)
142 } 150 }
143 } 151 }
144 vv.section="default"; 152 vv.section="default";
145 vv.name=name; 153 vv.name=(char *)name;
146 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv); 154 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
147 if (v != NULL) 155 if (v != NULL)
148 return(v->value); 156 return(v->value);
@@ -153,6 +161,9 @@ char *_CONF_get_string(CONF *conf, char *section, char *name)
153 return(Getenv(name)); 161 return(Getenv(name));
154 } 162 }
155 163
164#if 0 /* There's no way to provide error checking with this function, so
165 force implementors of the higher levels to get a string and read
166 the number themselves. */
156long _CONF_get_number(CONF *conf, char *section, char *name) 167long _CONF_get_number(CONF *conf, char *section, char *name)
157 { 168 {
158 char *str; 169 char *str;
@@ -169,6 +180,7 @@ long _CONF_get_number(CONF *conf, char *section, char *name)
169 str++; 180 str++;
170 } 181 }
171 } 182 }
183#endif
172 184
173int _CONF_new_data(CONF *conf) 185int _CONF_new_data(CONF *conf)
174 { 186 {
@@ -177,7 +189,7 @@ int _CONF_new_data(CONF *conf)
177 return 0; 189 return 0;
178 } 190 }
179 if (conf->data == NULL) 191 if (conf->data == NULL)
180 if ((conf->data = lh_new(hash,cmp_conf)) == NULL) 192 if ((conf->data = lh_new(hash, cmp_conf)) == NULL)
181 { 193 {
182 return 0; 194 return 0;
183 } 195 }
@@ -190,12 +202,14 @@ void _CONF_free_data(CONF *conf)
190 202
191 conf->data->down_load=0; /* evil thing to make sure the 'OPENSSL_free()' 203 conf->data->down_load=0; /* evil thing to make sure the 'OPENSSL_free()'
192 * works as expected */ 204 * works as expected */
193 lh_doall_arg(conf->data,(void (*)())value_free_hash,conf->data); 205 lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_hash),
206 conf->data);
194 207
195 /* We now have only 'section' entries in the hash table. 208 /* We now have only 'section' entries in the hash table.
196 * Due to problems with */ 209 * Due to problems with */
197 210
198 lh_doall_arg(conf->data,(void (*)())value_free_stack,conf->data); 211 lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_stack),
212 conf->data);
199 lh_free(conf->data); 213 lh_free(conf->data);
200 } 214 }
201 215
@@ -228,14 +242,19 @@ static void value_free_stack(CONF_VALUE *a, LHASH *conf)
228 OPENSSL_free(a); 242 OPENSSL_free(a);
229 } 243 }
230 244
231static unsigned long hash(CONF_VALUE *v) 245/* static unsigned long hash(CONF_VALUE *v) */
246static unsigned long hash(const void *v_void)
232 { 247 {
248 CONF_VALUE *v = (CONF_VALUE *)v_void;
233 return((lh_strhash(v->section)<<2)^lh_strhash(v->name)); 249 return((lh_strhash(v->section)<<2)^lh_strhash(v->name));
234 } 250 }
235 251
236static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b) 252/* static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b) */
253static int cmp_conf(const void *a_void,const void *b_void)
237 { 254 {
238 int i; 255 int i;
256 CONF_VALUE *a = (CONF_VALUE *)a_void;
257 CONF_VALUE *b = (CONF_VALUE *)b_void;
239 258
240 if (a->section != b->section) 259 if (a->section != b->section)
241 { 260 {
@@ -255,7 +274,7 @@ static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b)
255 } 274 }
256 275
257/* Up until OpenSSL 0.9.5a, this was new_section */ 276/* Up until OpenSSL 0.9.5a, this was new_section */
258CONF_VALUE *_CONF_new_section(CONF *conf, char *section) 277CONF_VALUE *_CONF_new_section(CONF *conf, const char *section)
259 { 278 {
260 STACK *sk=NULL; 279 STACK *sk=NULL;
261 int ok=0,i; 280 int ok=0,i;
diff --git a/src/lib/libcrypto/conf/conf_api.h b/src/lib/libcrypto/conf/conf_api.h
index a5cc17b233..87a954aff6 100644
--- a/src/lib/libcrypto/conf/conf_api.h
+++ b/src/lib/libcrypto/conf/conf_api.h
@@ -67,15 +67,17 @@ extern "C" {
67#endif 67#endif
68 68
69/* Up until OpenSSL 0.9.5a, this was new_section */ 69/* Up until OpenSSL 0.9.5a, this was new_section */
70CONF_VALUE *_CONF_new_section(CONF *conf, char *section); 70CONF_VALUE *_CONF_new_section(CONF *conf, const char *section);
71/* Up until OpenSSL 0.9.5a, this was get_section */ 71/* Up until OpenSSL 0.9.5a, this was get_section */
72CONF_VALUE *_CONF_get_section(CONF *conf, char *section); 72CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section);
73/* Up until OpenSSL 0.9.5a, this was CONF_get_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); 74STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf,
75 const char *section);
75 76
76int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value); 77int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value);
77char *_CONF_get_string(CONF *conf, char *section, char *name); 78char *_CONF_get_string(const CONF *conf, const char *section,
78long _CONF_get_number(CONF *conf, char *section, char *name); 79 const char *name);
80long _CONF_get_number(const CONF *conf, const char *section, const char *name);
79 81
80int _CONF_new_data(CONF *conf); 82int _CONF_new_data(CONF *conf);
81void _CONF_free_data(CONF *conf); 83void _CONF_free_data(CONF *conf);
diff --git a/src/lib/libcrypto/conf/conf_def.c b/src/lib/libcrypto/conf/conf_def.c
index 773df32c68..31f2766246 100644
--- a/src/lib/libcrypto/conf/conf_def.c
+++ b/src/lib/libcrypto/conf/conf_def.c
@@ -81,10 +81,11 @@ static int def_init_default(CONF *conf);
81static int def_init_WIN32(CONF *conf); 81static int def_init_WIN32(CONF *conf);
82static int def_destroy(CONF *conf); 82static int def_destroy(CONF *conf);
83static int def_destroy_data(CONF *conf); 83static int def_destroy_data(CONF *conf);
84static int def_load(CONF *conf, BIO *bp, long *eline); 84static int def_load(CONF *conf, const char *name, long *eline);
85static int def_dump(CONF *conf, BIO *bp); 85static int def_load_bio(CONF *conf, BIO *bp, long *eline);
86static int def_is_number(CONF *conf, char c); 86static int def_dump(const CONF *conf, BIO *bp);
87static int def_to_int(CONF *conf, char c); 87static int def_is_number(const CONF *conf, char c);
88static int def_to_int(const CONF *conf, char c);
88 89
89const char *CONF_def_version="CONF_def" OPENSSL_VERSION_PTEXT; 90const char *CONF_def_version="CONF_def" OPENSSL_VERSION_PTEXT;
90 91
@@ -94,10 +95,11 @@ static CONF_METHOD default_method = {
94 def_init_default, 95 def_init_default,
95 def_destroy, 96 def_destroy,
96 def_destroy_data, 97 def_destroy_data,
97 def_load, 98 def_load_bio,
98 def_dump, 99 def_dump,
99 def_is_number, 100 def_is_number,
100 def_to_int 101 def_to_int,
102 def_load
101 }; 103 };
102 104
103static CONF_METHOD WIN32_method = { 105static CONF_METHOD WIN32_method = {
@@ -106,10 +108,11 @@ static CONF_METHOD WIN32_method = {
106 def_init_WIN32, 108 def_init_WIN32,
107 def_destroy, 109 def_destroy,
108 def_destroy_data, 110 def_destroy_data,
109 def_load, 111 def_load_bio,
110 def_dump, 112 def_dump,
111 def_is_number, 113 def_is_number,
112 def_to_int 114 def_to_int,
115 def_load
113 }; 116 };
114 117
115CONF_METHOD *NCONF_default() 118CONF_METHOD *NCONF_default()
@@ -177,7 +180,32 @@ static int def_destroy_data(CONF *conf)
177 return 1; 180 return 1;
178 } 181 }
179 182
180static int def_load(CONF *conf, BIO *in, long *line) 183static int def_load(CONF *conf, const char *name, long *line)
184 {
185 int ret;
186 BIO *in=NULL;
187
188#ifdef OPENSSL_SYS_VMS
189 in=BIO_new_file(name, "r");
190#else
191 in=BIO_new_file(name, "rb");
192#endif
193 if (in == NULL)
194 {
195 if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE)
196 CONFerr(CONF_F_CONF_LOAD,CONF_R_NO_SUCH_FILE);
197 else
198 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
199 return 0;
200 }
201
202 ret = def_load_bio(conf, in, line);
203 BIO_free(in);
204
205 return ret;
206 }
207
208static int def_load_bio(CONF *conf, BIO *in, long *line)
181 { 209 {
182#define BUFSIZE 512 210#define BUFSIZE 512
183 char btmp[16]; 211 char btmp[16];
@@ -418,7 +446,11 @@ err:
418 if (line != NULL) *line=eline; 446 if (line != NULL) *line=eline;
419 sprintf(btmp,"%ld",eline); 447 sprintf(btmp,"%ld",eline);
420 ERR_add_error_data(2,"line ",btmp); 448 ERR_add_error_data(2,"line ",btmp);
421 if ((h != conf->data) && (conf->data != NULL)) CONF_free(conf->data); 449 if ((h != conf->data) && (conf->data != NULL))
450 {
451 CONF_free(conf->data);
452 conf->data=NULL;
453 }
422 if (v != NULL) 454 if (v != NULL)
423 { 455 {
424 if (v->name != NULL) OPENSSL_free(v->name); 456 if (v->name != NULL) OPENSSL_free(v->name);
@@ -685,18 +717,20 @@ static void dump_value(CONF_VALUE *a, BIO *out)
685 BIO_printf(out, "[[%s]]\n", a->section); 717 BIO_printf(out, "[[%s]]\n", a->section);
686 } 718 }
687 719
688static int def_dump(CONF *conf, BIO *out) 720static IMPLEMENT_LHASH_DOALL_ARG_FN(dump_value, CONF_VALUE *, BIO *)
721
722static int def_dump(const CONF *conf, BIO *out)
689 { 723 {
690 lh_doall_arg(conf->data, (void (*)())dump_value, out); 724 lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(dump_value), out);
691 return 1; 725 return 1;
692 } 726 }
693 727
694static int def_is_number(CONF *conf, char c) 728static int def_is_number(const CONF *conf, char c)
695 { 729 {
696 return IS_NUMBER(conf,c); 730 return IS_NUMBER(conf,c);
697 } 731 }
698 732
699static int def_to_int(CONF *conf, char c) 733static int def_to_int(const CONF *conf, char c)
700 { 734 {
701 return c - '0'; 735 return c - '0';
702 } 736 }
diff --git a/src/lib/libcrypto/conf/conf_def.h b/src/lib/libcrypto/conf/conf_def.h
index 3244d9a331..92a7d8ad77 100644
--- a/src/lib/libcrypto/conf/conf_def.h
+++ b/src/lib/libcrypto/conf/conf_def.h
@@ -71,6 +71,7 @@
71#define CONF_COMMENT 128 71#define CONF_COMMENT 128
72#define CONF_FCOMMENT 2048 72#define CONF_FCOMMENT 2048
73#define CONF_EOF 8 73#define CONF_EOF 8
74#define CONF_HIGHBIT 4096
74#define CONF_ALPHA (CONF_UPPER|CONF_LOWER) 75#define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
75#define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER) 76#define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
76#define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \ 77#define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \
@@ -78,68 +79,102 @@
78 79
79#define KEYTYPES(c) ((unsigned short *)((c)->meth_data)) 80#define KEYTYPES(c) ((unsigned short *)((c)->meth_data))
80#ifndef CHARSET_EBCDIC 81#ifndef CHARSET_EBCDIC
81#define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_COMMENT) 82#define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_COMMENT)
82#define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_FCOMMENT) 83#define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_FCOMMENT)
83#define IS_EOF(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_EOF) 84#define IS_EOF(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_EOF)
84#define IS_ESC(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_ESC) 85#define IS_ESC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ESC)
85#define IS_NUMBER(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_NUMBER) 86#define IS_NUMBER(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_NUMBER)
86#define IS_WS(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_WS) 87#define IS_WS(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_WS)
87#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_ALPHA_NUMERIC) 88#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC)
88#define IS_ALPHA_NUMERIC_PUNCT(c,a) \ 89#define IS_ALPHA_NUMERIC_PUNCT(c,a) \
89 (KEYTYPES(c)[(a)&0x7f]&CONF_ALPHA_NUMERIC_PUNCT) 90 (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
90#define IS_QUOTE(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_QUOTE) 91#define IS_QUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_QUOTE)
91#define IS_DQUOTE(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_DQUOTE) 92#define IS_DQUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_DQUOTE)
93#define IS_HIGHBIT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_HIGHBIT)
92 94
93#else /*CHARSET_EBCDIC*/ 95#else /*CHARSET_EBCDIC*/
94 96
95#define IS_COMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_COMMENT) 97#define IS_COMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_COMMENT)
96#define IS_FCOMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_FCOMMENT) 98#define IS_FCOMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_FCOMMENT)
97#define IS_EOF(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_EOF) 99#define IS_EOF(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_EOF)
98#define IS_ESC(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ESC) 100#define IS_ESC(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ESC)
99#define IS_NUMBER(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_NUMBER) 101#define IS_NUMBER(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_NUMBER)
100#define IS_WS(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_WS) 102#define IS_WS(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_WS)
101#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC) 103#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ALPHA_NUMERIC)
102#define IS_ALPHA_NUMERIC_PUNCT(c,a) \ 104#define IS_ALPHA_NUMERIC_PUNCT(c,a) \
103 (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC_PUNCT) 105 (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
104#define IS_QUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_QUOTE) 106#define IS_QUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_QUOTE)
105#define IS_DQUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_DQUOTE) 107#define IS_DQUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_DQUOTE)
108#define IS_HIGHBIT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_HIGHBIT)
106#endif /*CHARSET_EBCDIC*/ 109#endif /*CHARSET_EBCDIC*/
107 110
108static unsigned short CONF_type_default[128]={ 111static unsigned short CONF_type_default[256]={
109 0x008,0x000,0x000,0x000,0x000,0x000,0x000,0x000, 112 0x0008,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
110 0x000,0x010,0x010,0x000,0x000,0x010,0x000,0x000, 113 0x0000,0x0010,0x0010,0x0000,0x0000,0x0010,0x0000,0x0000,
111 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000, 114 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
112 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000, 115 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
113 0x010,0x200,0x040,0x080,0x000,0x200,0x200,0x040, 116 0x0010,0x0200,0x0040,0x0080,0x0000,0x0200,0x0200,0x0040,
114 0x000,0x000,0x200,0x200,0x200,0x200,0x200,0x200, 117 0x0000,0x0000,0x0200,0x0200,0x0200,0x0200,0x0200,0x0200,
115 0x001,0x001,0x001,0x001,0x001,0x001,0x001,0x001, 118 0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
116 0x001,0x001,0x000,0x200,0x000,0x000,0x000,0x200, 119 0x0001,0x0001,0x0000,0x0200,0x0000,0x0000,0x0000,0x0200,
117 0x200,0x002,0x002,0x002,0x002,0x002,0x002,0x002, 120 0x0200,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
118 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002, 121 0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
119 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002, 122 0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
120 0x002,0x002,0x002,0x000,0x020,0x000,0x200,0x100, 123 0x0002,0x0002,0x0002,0x0000,0x0020,0x0000,0x0200,0x0100,
121 0x040,0x004,0x004,0x004,0x004,0x004,0x004,0x004, 124 0x0040,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
122 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004, 125 0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
123 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004, 126 0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
124 0x004,0x004,0x004,0x000,0x200,0x000,0x200,0x000, 127 0x0004,0x0004,0x0004,0x0000,0x0200,0x0000,0x0200,0x0000,
128 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
129 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
130 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
131 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
132 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
133 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
134 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
135 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
136 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
137 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
138 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
139 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
140 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
141 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
142 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
143 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
125 }; 144 };
126 145
127static unsigned short CONF_type_win32[128]={ 146static unsigned short CONF_type_win32[256]={
128 0x008,0x000,0x000,0x000,0x000,0x000,0x000,0x000, 147 0x0008,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
129 0x000,0x010,0x010,0x000,0x000,0x010,0x000,0x000, 148 0x0000,0x0010,0x0010,0x0000,0x0000,0x0010,0x0000,0x0000,
130 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000, 149 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
131 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000, 150 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
132 0x010,0x200,0x400,0x000,0x000,0x200,0x200,0x000, 151 0x0010,0x0200,0x0400,0x0000,0x0000,0x0200,0x0200,0x0000,
133 0x000,0x000,0x200,0x200,0x200,0x200,0x200,0x200, 152 0x0000,0x0000,0x0200,0x0200,0x0200,0x0200,0x0200,0x0200,
134 0x001,0x001,0x001,0x001,0x001,0x001,0x001,0x001, 153 0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
135 0x001,0x001,0x000,0xA00,0x000,0x000,0x000,0x200, 154 0x0001,0x0001,0x0000,0x0A00,0x0000,0x0000,0x0000,0x0200,
136 0x200,0x002,0x002,0x002,0x002,0x002,0x002,0x002, 155 0x0200,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
137 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002, 156 0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
138 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002, 157 0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
139 0x002,0x002,0x002,0x000,0x000,0x000,0x200,0x100, 158 0x0002,0x0002,0x0002,0x0000,0x0000,0x0000,0x0200,0x0100,
140 0x000,0x004,0x004,0x004,0x004,0x004,0x004,0x004, 159 0x0000,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
141 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004, 160 0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
142 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004, 161 0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
143 0x004,0x004,0x004,0x000,0x200,0x000,0x200,0x000, 162 0x0004,0x0004,0x0004,0x0000,0x0200,0x0000,0x0200,0x0000,
163 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
164 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
165 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
166 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
167 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
168 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
169 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
170 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
171 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
172 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
173 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
174 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
175 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
176 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
177 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
178 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
144 }; 179 };
145 180
diff --git a/src/lib/libcrypto/conf/conf_err.c b/src/lib/libcrypto/conf/conf_err.c
index 8c2bc6f1c4..ee07bfe9d9 100644
--- a/src/lib/libcrypto/conf/conf_err.c
+++ b/src/lib/libcrypto/conf/conf_err.c
@@ -63,19 +63,26 @@
63#include <openssl/conf.h> 63#include <openssl/conf.h>
64 64
65/* BEGIN ERROR CODES */ 65/* BEGIN ERROR CODES */
66#ifndef NO_ERR 66#ifndef OPENSSL_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_DUMP_FP,0), "CONF_dump_fp"},
70{ERR_PACK(0,CONF_F_CONF_LOAD,0), "CONF_load"}, 70{ERR_PACK(0,CONF_F_CONF_LOAD,0), "CONF_load"},
71{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"},
72{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_CONF_MODULES_LOAD,0), "CONF_modules_load"},
74{ERR_PACK(0,CONF_F_MODULE_INIT,0), "MODULE_INIT"},
75{ERR_PACK(0,CONF_F_MODULE_LOAD_DSO,0), "MODULE_LOAD_DSO"},
76{ERR_PACK(0,CONF_F_MODULE_RUN,0), "MODULE_RUN"},
73{ERR_PACK(0,CONF_F_NCONF_DUMP_BIO,0), "NCONF_dump_bio"}, 77{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"}, 78{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"}, 79{ERR_PACK(0,CONF_F_NCONF_GET_NUMBER,0), "NCONF_get_number"},
80{ERR_PACK(0,CONF_F_NCONF_GET_NUMBER_E,0), "NCONF_get_number_e"},
76{ERR_PACK(0,CONF_F_NCONF_GET_SECTION,0), "NCONF_get_section"}, 81{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"}, 82{ERR_PACK(0,CONF_F_NCONF_GET_STRING,0), "NCONF_get_string"},
83{ERR_PACK(0,CONF_F_NCONF_LOAD,0), "NCONF_load"},
78{ERR_PACK(0,CONF_F_NCONF_LOAD_BIO,0), "NCONF_load_bio"}, 84{ERR_PACK(0,CONF_F_NCONF_LOAD_BIO,0), "NCONF_load_bio"},
85{ERR_PACK(0,CONF_F_NCONF_LOAD_FP,0), "NCONF_load_fp"},
79{ERR_PACK(0,CONF_F_NCONF_NEW,0), "NCONF_new"}, 86{ERR_PACK(0,CONF_F_NCONF_NEW,0), "NCONF_new"},
80{ERR_PACK(0,CONF_F_STR_COPY,0), "STR_COPY"}, 87{ERR_PACK(0,CONF_F_STR_COPY,0), "STR_COPY"},
81{0,NULL} 88{0,NULL}
@@ -83,13 +90,20 @@ static ERR_STRING_DATA CONF_str_functs[]=
83 90
84static ERR_STRING_DATA CONF_str_reasons[]= 91static ERR_STRING_DATA CONF_str_reasons[]=
85 { 92 {
93{CONF_R_ERROR_LOADING_DSO ,"error loading dso"},
86{CONF_R_MISSING_CLOSE_SQUARE_BRACKET ,"missing close square bracket"}, 94{CONF_R_MISSING_CLOSE_SQUARE_BRACKET ,"missing close square bracket"},
87{CONF_R_MISSING_EQUAL_SIGN ,"missing equal sign"}, 95{CONF_R_MISSING_EQUAL_SIGN ,"missing equal sign"},
96{CONF_R_MISSING_FINISH_FUNCTION ,"missing finish function"},
97{CONF_R_MISSING_INIT_FUNCTION ,"missing init function"},
98{CONF_R_MODULE_INITIALIZATION_ERROR ,"module initialization error"},
88{CONF_R_NO_CLOSE_BRACE ,"no close brace"}, 99{CONF_R_NO_CLOSE_BRACE ,"no close brace"},
89{CONF_R_NO_CONF ,"no conf"}, 100{CONF_R_NO_CONF ,"no conf"},
90{CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE ,"no conf or environment variable"}, 101{CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE ,"no conf or environment variable"},
91{CONF_R_NO_SECTION ,"no section"}, 102{CONF_R_NO_SECTION ,"no section"},
103{CONF_R_NO_SUCH_FILE ,"no such file"},
104{CONF_R_NO_VALUE ,"no value"},
92{CONF_R_UNABLE_TO_CREATE_NEW_SECTION ,"unable to create new section"}, 105{CONF_R_UNABLE_TO_CREATE_NEW_SECTION ,"unable to create new section"},
106{CONF_R_UNKNOWN_MODULE_NAME ,"unknown module name"},
93{CONF_R_VARIABLE_HAS_NO_VALUE ,"variable has no value"}, 107{CONF_R_VARIABLE_HAS_NO_VALUE ,"variable has no value"},
94{0,NULL} 108{0,NULL}
95 }; 109 };
@@ -103,7 +117,7 @@ void ERR_load_CONF_strings(void)
103 if (init) 117 if (init)
104 { 118 {
105 init=0; 119 init=0;
106#ifndef NO_ERR 120#ifndef OPENSSL_NO_ERR
107 ERR_load_strings(ERR_LIB_CONF,CONF_str_functs); 121 ERR_load_strings(ERR_LIB_CONF,CONF_str_functs);
108 ERR_load_strings(ERR_LIB_CONF,CONF_str_reasons); 122 ERR_load_strings(ERR_LIB_CONF,CONF_str_reasons);
109#endif 123#endif
diff --git a/src/lib/libcrypto/conf/conf_lib.c b/src/lib/libcrypto/conf/conf_lib.c
index 11ec639732..7998f34c7b 100644
--- a/src/lib/libcrypto/conf/conf_lib.c
+++ b/src/lib/libcrypto/conf/conf_lib.c
@@ -67,6 +67,17 @@ const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT;
67 67
68static CONF_METHOD *default_CONF_method=NULL; 68static CONF_METHOD *default_CONF_method=NULL;
69 69
70/* Init a 'CONF' structure from an old LHASH */
71
72void CONF_set_nconf(CONF *conf, LHASH *hash)
73 {
74 if (default_CONF_method == NULL)
75 default_CONF_method = NCONF_default();
76
77 default_CONF_method->init(conf);
78 conf->data = hash;
79 }
80
70/* The following section contains the "CONF classic" functions, 81/* The following section contains the "CONF classic" functions,
71 rewritten in terms of the new CONF interface. */ 82 rewritten in terms of the new CONF interface. */
72 83
@@ -81,7 +92,7 @@ LHASH *CONF_load(LHASH *conf, const char *file, long *eline)
81 LHASH *ltmp; 92 LHASH *ltmp;
82 BIO *in=NULL; 93 BIO *in=NULL;
83 94
84#ifdef VMS 95#ifdef OPENSSL_SYS_VMS
85 in=BIO_new_file(file, "r"); 96 in=BIO_new_file(file, "r");
86#else 97#else
87 in=BIO_new_file(file, "rb"); 98 in=BIO_new_file(file, "rb");
@@ -98,7 +109,7 @@ LHASH *CONF_load(LHASH *conf, const char *file, long *eline)
98 return ltmp; 109 return ltmp;
99 } 110 }
100 111
101#ifndef NO_FP_API 112#ifndef OPENSSL_NO_FP_API
102LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline) 113LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline)
103 { 114 {
104 BIO *btmp; 115 BIO *btmp;
@@ -118,18 +129,15 @@ LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline)
118 CONF ctmp; 129 CONF ctmp;
119 int ret; 130 int ret;
120 131
121 if (default_CONF_method == NULL) 132 CONF_set_nconf(&ctmp, conf);
122 default_CONF_method = NCONF_default();
123 133
124 default_CONF_method->init(&ctmp);
125 ctmp.data = conf;
126 ret = NCONF_load_bio(&ctmp, bp, eline); 134 ret = NCONF_load_bio(&ctmp, bp, eline);
127 if (ret) 135 if (ret)
128 return ctmp.data; 136 return ctmp.data;
129 return NULL; 137 return NULL;
130 } 138 }
131 139
132STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section) 140STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,const char *section)
133 { 141 {
134 if (conf == NULL) 142 if (conf == NULL)
135 { 143 {
@@ -138,17 +146,12 @@ STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section)
138 else 146 else
139 { 147 {
140 CONF ctmp; 148 CONF ctmp;
141 149 CONF_set_nconf(&ctmp, conf);
142 if (default_CONF_method == NULL)
143 default_CONF_method = NCONF_default();
144
145 default_CONF_method->init(&ctmp);
146 ctmp.data = conf;
147 return NCONF_get_section(&ctmp, section); 150 return NCONF_get_section(&ctmp, section);
148 } 151 }
149 } 152 }
150 153
151char *CONF_get_string(LHASH *conf,char *group,char *name) 154char *CONF_get_string(LHASH *conf,const char *group,const char *name)
152 { 155 {
153 if (conf == NULL) 156 if (conf == NULL)
154 { 157 {
@@ -157,48 +160,43 @@ char *CONF_get_string(LHASH *conf,char *group,char *name)
157 else 160 else
158 { 161 {
159 CONF ctmp; 162 CONF ctmp;
160 163 CONF_set_nconf(&ctmp, conf);
161 if (default_CONF_method == NULL)
162 default_CONF_method = NCONF_default();
163
164 default_CONF_method->init(&ctmp);
165 ctmp.data = conf;
166 return NCONF_get_string(&ctmp, group, name); 164 return NCONF_get_string(&ctmp, group, name);
167 } 165 }
168 } 166 }
169 167
170long CONF_get_number(LHASH *conf,char *group,char *name) 168long CONF_get_number(LHASH *conf,const char *group,const char *name)
171 { 169 {
170 int status;
171 long result = 0;
172
172 if (conf == NULL) 173 if (conf == NULL)
173 { 174 {
174 return NCONF_get_number(NULL, group, name); 175 status = NCONF_get_number_e(NULL, group, name, &result);
175 } 176 }
176 else 177 else
177 { 178 {
178 CONF ctmp; 179 CONF ctmp;
180 CONF_set_nconf(&ctmp, conf);
181 status = NCONF_get_number_e(&ctmp, group, name, &result);
182 }
179 183
180 if (default_CONF_method == NULL) 184 if (status == 0)
181 default_CONF_method = NCONF_default(); 185 {
182 186 /* This function does not believe in errors... */
183 default_CONF_method->init(&ctmp); 187 ERR_get_error();
184 ctmp.data = conf;
185 return NCONF_get_number(&ctmp, group, name);
186 } 188 }
189 return result;
187 } 190 }
188 191
189void CONF_free(LHASH *conf) 192void CONF_free(LHASH *conf)
190 { 193 {
191 CONF ctmp; 194 CONF ctmp;
192 195 CONF_set_nconf(&ctmp, conf);
193 if (default_CONF_method == NULL)
194 default_CONF_method = NCONF_default();
195
196 default_CONF_method->init(&ctmp);
197 ctmp.data = conf;
198 NCONF_free_data(&ctmp); 196 NCONF_free_data(&ctmp);
199 } 197 }
200 198
201#ifndef NO_FP_API 199#ifndef OPENSSL_NO_FP_API
202int CONF_dump_fp(LHASH *conf, FILE *out) 200int CONF_dump_fp(LHASH *conf, FILE *out)
203 { 201 {
204 BIO *btmp; 202 BIO *btmp;
@@ -217,12 +215,7 @@ int CONF_dump_fp(LHASH *conf, FILE *out)
217int CONF_dump_bio(LHASH *conf, BIO *out) 215int CONF_dump_bio(LHASH *conf, BIO *out)
218 { 216 {
219 CONF ctmp; 217 CONF ctmp;
220 218 CONF_set_nconf(&ctmp, conf);
221 if (default_CONF_method == NULL)
222 default_CONF_method = NCONF_default();
223
224 default_CONF_method->init(&ctmp);
225 ctmp.data = conf;
226 return NCONF_dump_bio(&ctmp, out); 219 return NCONF_dump_bio(&ctmp, out);
227 } 220 }
228 221
@@ -265,34 +258,23 @@ void NCONF_free_data(CONF *conf)
265 258
266int NCONF_load(CONF *conf, const char *file, long *eline) 259int NCONF_load(CONF *conf, const char *file, long *eline)
267 { 260 {
268 int ret; 261 if (conf == NULL)
269 BIO *in=NULL;
270
271#ifdef VMS
272 in=BIO_new_file(file, "r");
273#else
274 in=BIO_new_file(file, "rb");
275#endif
276 if (in == NULL)
277 { 262 {
278 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB); 263 CONFerr(CONF_F_NCONF_LOAD,CONF_R_NO_CONF);
279 return 0; 264 return 0;
280 } 265 }
281 266
282 ret = NCONF_load_bio(conf, in, eline); 267 return conf->meth->load(conf, file, eline);
283 BIO_free(in);
284
285 return ret;
286 } 268 }
287 269
288#ifndef NO_FP_API 270#ifndef OPENSSL_NO_FP_API
289int NCONF_load_fp(CONF *conf, FILE *fp,long *eline) 271int NCONF_load_fp(CONF *conf, FILE *fp,long *eline)
290 { 272 {
291 BIO *btmp; 273 BIO *btmp;
292 int ret; 274 int ret;
293 if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) 275 if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE)))
294 { 276 {
295 CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB); 277 CONFerr(CONF_F_NCONF_LOAD_FP,ERR_R_BUF_LIB);
296 return 0; 278 return 0;
297 } 279 }
298 ret = NCONF_load_bio(conf, btmp, eline); 280 ret = NCONF_load_bio(conf, btmp, eline);
@@ -309,10 +291,10 @@ int NCONF_load_bio(CONF *conf, BIO *bp,long *eline)
309 return 0; 291 return 0;
310 } 292 }
311 293
312 return conf->meth->load(conf, bp, eline); 294 return conf->meth->load_bio(conf, bp, eline);
313 } 295 }
314 296
315STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section) 297STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,const char *section)
316 { 298 {
317 if (conf == NULL) 299 if (conf == NULL)
318 { 300 {
@@ -329,7 +311,7 @@ STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section)
329 return _CONF_get_section_values(conf, section); 311 return _CONF_get_section_values(conf, section);
330 } 312 }
331 313
332char *NCONF_get_string(CONF *conf,char *group,char *name) 314char *NCONF_get_string(const CONF *conf,const char *group,const char *name)
333 { 315 {
334 char *s = _CONF_get_string(conf, group, name); 316 char *s = _CONF_get_string(conf, group, name);
335 317
@@ -343,29 +325,39 @@ char *NCONF_get_string(CONF *conf,char *group,char *name)
343 CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE); 325 CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE);
344 return NULL; 326 return NULL;
345 } 327 }
328 CONFerr(CONF_F_NCONF_GET_STRING,
329 CONF_R_NO_VALUE);
330 ERR_add_error_data(4,"group=",group," name=",name);
346 return NULL; 331 return NULL;
347 } 332 }
348 333
349long NCONF_get_number(CONF *conf,char *group,char *name) 334int NCONF_get_number_e(const CONF *conf,const char *group,const char *name,
335 long *result)
350 { 336 {
351#if 0 /* As with _CONF_get_string(), we rely on the possibility of finding 337 char *str;
352 an environment variable with a suitable name. Unfortunately, there's 338
353 no way with the current API to see if we found one or not... 339 if (result == NULL)
354 The meaning of this is that if a number is not found anywhere, it
355 will always default to 0. */
356 if (conf == NULL)
357 { 340 {
358 CONFerr(CONF_F_NCONF_GET_NUMBER, 341 CONFerr(CONF_F_NCONF_GET_NUMBER_E,ERR_R_PASSED_NULL_PARAMETER);
359 CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE);
360 return 0; 342 return 0;
361 } 343 }
362#endif 344
363 345 str = NCONF_get_string(conf,group,name);
364 return _CONF_get_number(conf, group, name); 346
347 if (str == NULL)
348 return 0;
349
350 for (*result = 0;conf->meth->is_number(conf, *str);)
351 {
352 *result = (*result)*10 + conf->meth->to_int(conf, *str);
353 str++;
354 }
355
356 return 1;
365 } 357 }
366 358
367#ifndef NO_FP_API 359#ifndef OPENSSL_NO_FP_API
368int NCONF_dump_fp(CONF *conf, FILE *out) 360int NCONF_dump_fp(const CONF *conf, FILE *out)
369 { 361 {
370 BIO *btmp; 362 BIO *btmp;
371 int ret; 363 int ret;
@@ -379,7 +371,7 @@ int NCONF_dump_fp(CONF *conf, FILE *out)
379 } 371 }
380#endif 372#endif
381 373
382int NCONF_dump_bio(CONF *conf, BIO *out) 374int NCONF_dump_bio(const CONF *conf, BIO *out)
383 { 375 {
384 if (conf == NULL) 376 if (conf == NULL)
385 { 377 {
@@ -390,3 +382,19 @@ int NCONF_dump_bio(CONF *conf, BIO *out)
390 return conf->meth->dump(conf, out); 382 return conf->meth->dump(conf, out);
391 } 383 }
392 384
385/* This function should be avoided */
386#undef NCONF_get_number
387long NCONF_get_number(CONF *conf,char *group,char *name)
388 {
389 int status;
390 long ret=0;
391
392 status = NCONF_get_number_e(conf, group, name, &ret);
393 if (status == 0)
394 {
395 /* This function does not believe in errors... */
396 ERR_get_error();
397 }
398 return ret;
399 }
400
diff --git a/src/lib/libcrypto/conf/conf_mall.c b/src/lib/libcrypto/conf/conf_mall.c
new file mode 100644
index 0000000000..d702af689b
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_mall.c
@@ -0,0 +1,76 @@
1/* conf_mall.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 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 "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/dso.h>
64#include <openssl/x509.h>
65#include <openssl/asn1.h>
66#include <openssl/engine.h>
67
68/* Load all OpenSSL builtin modules */
69
70void OPENSSL_load_builtin_modules(void)
71 {
72 /* Add builtin modules here */
73 ASN1_add_oid_module();
74 ENGINE_add_conf_module();
75 }
76
diff --git a/src/lib/libcrypto/conf/conf_mod.c b/src/lib/libcrypto/conf/conf_mod.c
new file mode 100644
index 0000000000..f92babc2e2
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_mod.c
@@ -0,0 +1,616 @@
1/* conf_mod.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 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 <ctype.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include <openssl/conf.h>
64#include <openssl/dso.h>
65#include <openssl/x509.h>
66
67
68#define DSO_mod_init_name "OPENSSL_init"
69#define DSO_mod_finish_name "OPENSSL_finish"
70
71
72/* This structure contains a data about supported modules.
73 * entries in this table correspond to either dynamic or
74 * static modules.
75 */
76
77struct conf_module_st
78 {
79 /* DSO of this module or NULL if static */
80 DSO *dso;
81 /* Name of the module */
82 char *name;
83 /* Init function */
84 conf_init_func *init;
85 /* Finish function */
86 conf_finish_func *finish;
87 /* Number of successfully initialized modules */
88 int links;
89 void *usr_data;
90 };
91
92
93/* This structure contains information about modules that have been
94 * successfully initialized. There may be more than one entry for a
95 * given module.
96 */
97
98struct conf_imodule_st
99 {
100 CONF_MODULE *pmod;
101 char *name;
102 char *value;
103 unsigned long flags;
104 void *usr_data;
105 };
106
107static STACK_OF(CONF_MODULE) *supported_modules = NULL;
108static STACK_OF(CONF_IMODULE) *initialized_modules = NULL;
109
110static void module_free(CONF_MODULE *md);
111static void module_finish(CONF_IMODULE *imod);
112static int module_run(const CONF *cnf, char *name, char *value,
113 unsigned long flags);
114static CONF_MODULE *module_add(DSO *dso, const char *name,
115 conf_init_func *ifunc, conf_finish_func *ffunc);
116static CONF_MODULE *module_find(char *name);
117static int module_init(CONF_MODULE *pmod, char *name, char *value,
118 const CONF *cnf);
119static CONF_MODULE *module_load_dso(const CONF *cnf, char *name, char *value,
120 unsigned long flags);
121
122/* Main function: load modules from a CONF structure */
123
124int CONF_modules_load(const CONF *cnf, const char *appname,
125 unsigned long flags)
126 {
127 STACK_OF(CONF_VALUE) *values;
128 CONF_VALUE *vl;
129 char *vsection;
130
131 int ret, i;
132
133 if (!cnf)
134 return 1;
135
136 if (appname == NULL)
137 appname = "openssl_conf";
138
139 vsection = NCONF_get_string(cnf, NULL, appname);
140
141 if (!vsection)
142 {
143 ERR_clear_error();
144 return 1;
145 }
146
147 values = NCONF_get_section(cnf, vsection);
148
149 if (!values)
150 return 0;
151
152 for (i = 0; i < sk_CONF_VALUE_num(values); i++)
153 {
154 vl = sk_CONF_VALUE_value(values, i);
155 ret = module_run(cnf, vl->name, vl->value, flags);
156 if (ret <= 0)
157 if(!(flags & CONF_MFLAGS_IGNORE_ERRORS))
158 return ret;
159 }
160
161 return 1;
162
163 }
164
165int CONF_modules_load_file(const char *filename, const char *appname,
166 unsigned long flags)
167 {
168 char *file = NULL;
169 CONF *conf = NULL;
170 int ret = 0;
171 conf = NCONF_new(NULL);
172 if (!conf)
173 goto err;
174
175 if (filename == NULL)
176 {
177 file = CONF_get1_default_config_file();
178 if (!file)
179 goto err;
180 }
181 else
182 file = (char *)filename;
183
184 if (NCONF_load(conf, file, NULL) <= 0)
185 {
186 if ((flags & CONF_MFLAGS_IGNORE_MISSING_FILE) &&
187 (ERR_GET_REASON(ERR_peek_last_error()) == CONF_R_NO_SUCH_FILE))
188 {
189 ERR_clear_error();
190 ret = 1;
191 }
192 goto err;
193 }
194
195 ret = CONF_modules_load(conf, appname, flags);
196
197 err:
198 if (filename == NULL)
199 OPENSSL_free(file);
200 NCONF_free(conf);
201
202 return ret;
203 }
204
205static int module_run(const CONF *cnf, char *name, char *value,
206 unsigned long flags)
207 {
208 CONF_MODULE *md;
209 int ret;
210
211 md = module_find(name);
212
213 /* Module not found: try to load DSO */
214 if (!md && !(flags & CONF_MFLAGS_NO_DSO))
215 md = module_load_dso(cnf, name, value, flags);
216
217 if (!md)
218 {
219 if (!(flags & CONF_MFLAGS_SILENT))
220 {
221 CONFerr(CONF_F_MODULE_RUN, CONF_R_UNKNOWN_MODULE_NAME);
222 ERR_add_error_data(2, "module=", name);
223 }
224 return -1;
225 }
226
227 ret = module_init(md, name, value, cnf);
228
229 if (ret <= 0)
230 {
231 if (!(flags & CONF_MFLAGS_SILENT))
232 {
233 char rcode[10];
234 CONFerr(CONF_F_CONF_MODULES_LOAD, CONF_R_MODULE_INITIALIZATION_ERROR);
235 sprintf(rcode, "%-8d", ret);
236 ERR_add_error_data(6, "module=", name, ", value=", value, ", retcode=", rcode);
237 }
238 }
239
240 return ret;
241 }
242
243/* Load a module from a DSO */
244static CONF_MODULE *module_load_dso(const CONF *cnf, char *name, char *value,
245 unsigned long flags)
246 {
247 DSO *dso = NULL;
248 conf_init_func *ifunc;
249 conf_finish_func *ffunc;
250 char *path = NULL;
251 int errcode = 0;
252 CONF_MODULE *md;
253 /* Look for alternative path in module section */
254 path = NCONF_get_string(cnf, value, "path");
255 if (!path)
256 {
257 ERR_get_error();
258 path = name;
259 }
260 dso = DSO_load(NULL, path, NULL, 0);
261 if (!dso)
262 {
263 errcode = CONF_R_ERROR_LOADING_DSO;
264 goto err;
265 }
266 ifunc = (conf_init_func *)DSO_bind_func(dso, DSO_mod_init_name);
267 if (!ifunc)
268 {
269 errcode = CONF_R_MISSING_INIT_FUNCTION;
270 goto err;
271 }
272 ffunc = (conf_finish_func *)DSO_bind_func(dso, DSO_mod_finish_name);
273 /* All OK, add module */
274 md = module_add(dso, name, ifunc, ffunc);
275
276 if (!md)
277 goto err;
278
279 return md;
280
281 err:
282 if (dso)
283 DSO_free(dso);
284 CONFerr(CONF_F_MODULE_LOAD_DSO, errcode);
285 ERR_add_error_data(4, "module=", name, ", path=", path);
286 return NULL;
287 }
288
289/* add module to list */
290static CONF_MODULE *module_add(DSO *dso, const char *name,
291 conf_init_func *ifunc, conf_finish_func *ffunc)
292 {
293 CONF_MODULE *tmod = NULL;
294 if (supported_modules == NULL)
295 supported_modules = sk_CONF_MODULE_new_null();
296 if (supported_modules == NULL)
297 return NULL;
298 tmod = OPENSSL_malloc(sizeof(CONF_MODULE));
299 if (tmod == NULL)
300 return NULL;
301
302 tmod->dso = dso;
303 tmod->name = BUF_strdup(name);
304 tmod->init = ifunc;
305 tmod->finish = ffunc;
306 tmod->links = 0;
307
308 if (!sk_CONF_MODULE_push(supported_modules, tmod))
309 {
310 OPENSSL_free(tmod);
311 return NULL;
312 }
313
314 return tmod;
315 }
316
317/* Find a module from the list. We allow module names of the
318 * form modname.XXXX to just search for modname to allow the
319 * same module to be initialized more than once.
320 */
321
322static CONF_MODULE *module_find(char *name)
323 {
324 CONF_MODULE *tmod;
325 int i, nchar;
326 char *p;
327 p = strrchr(name, '.');
328
329 if (p)
330 nchar = p - name;
331 else
332 nchar = strlen(name);
333
334 for (i = 0; i < sk_CONF_MODULE_num(supported_modules); i++)
335 {
336 tmod = sk_CONF_MODULE_value(supported_modules, i);
337 if (!strncmp(tmod->name, name, nchar))
338 return tmod;
339 }
340
341 return NULL;
342
343 }
344
345/* initialize a module */
346static int module_init(CONF_MODULE *pmod, char *name, char *value,
347 const CONF *cnf)
348 {
349 int ret = 1;
350 int init_called = 0;
351 CONF_IMODULE *imod = NULL;
352
353 /* Otherwise add initialized module to list */
354 imod = OPENSSL_malloc(sizeof(CONF_IMODULE));
355 if (!imod)
356 goto err;
357
358 imod->pmod = pmod;
359 imod->name = BUF_strdup(name);
360 imod->value = BUF_strdup(value);
361 imod->usr_data = NULL;
362
363 if (!imod->name || !imod->value)
364 goto memerr;
365
366 /* Try to initialize module */
367 if(pmod->init)
368 {
369 ret = pmod->init(imod, cnf);
370 init_called = 1;
371 /* Error occurred, exit */
372 if (ret <= 0)
373 goto err;
374 }
375
376 if (initialized_modules == NULL)
377 {
378 initialized_modules = sk_CONF_IMODULE_new_null();
379 if (!initialized_modules)
380 {
381 CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE);
382 goto err;
383 }
384 }
385
386 if (!sk_CONF_IMODULE_push(initialized_modules, imod))
387 {
388 CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE);
389 goto err;
390 }
391
392 pmod->links++;
393
394 return ret;
395
396 err:
397
398 /* We've started the module so we'd better finish it */
399 if (pmod->finish && init_called)
400 pmod->finish(imod);
401
402 memerr:
403 if (imod)
404 {
405 if (imod->name)
406 OPENSSL_free(imod->name);
407 if (imod->value)
408 OPENSSL_free(imod->value);
409 OPENSSL_free(imod);
410 }
411
412 return -1;
413
414 }
415
416/* Unload any dynamic modules that have a link count of zero:
417 * i.e. have no active initialized modules. If 'all' is set
418 * then all modules are unloaded including static ones.
419 */
420
421void CONF_modules_unload(int all)
422 {
423 int i;
424 CONF_MODULE *md;
425 CONF_modules_finish();
426 /* unload modules in reverse order */
427 for (i = sk_CONF_MODULE_num(supported_modules) - 1; i >= 0; i--)
428 {
429 md = sk_CONF_MODULE_value(supported_modules, i);
430 /* If static or in use and 'all' not set ignore it */
431 if (((md->links > 0) || !md->dso) && !all)
432 continue;
433 /* Since we're working in reverse this is OK */
434 sk_CONF_MODULE_delete(supported_modules, i);
435 module_free(md);
436 }
437 if (sk_CONF_MODULE_num(supported_modules) == 0)
438 {
439 sk_CONF_MODULE_free(supported_modules);
440 supported_modules = NULL;
441 }
442 }
443
444/* unload a single module */
445static void module_free(CONF_MODULE *md)
446 {
447 if (md->dso)
448 DSO_free(md->dso);
449 OPENSSL_free(md->name);
450 OPENSSL_free(md);
451 }
452
453/* finish and free up all modules instances */
454
455void CONF_modules_finish(void)
456 {
457 CONF_IMODULE *imod;
458 while (sk_CONF_IMODULE_num(initialized_modules) > 0)
459 {
460 imod = sk_CONF_IMODULE_pop(initialized_modules);
461 module_finish(imod);
462 }
463 sk_CONF_IMODULE_free(initialized_modules);
464 initialized_modules = NULL;
465 }
466
467/* finish a module instance */
468
469static void module_finish(CONF_IMODULE *imod)
470 {
471 if (imod->pmod->finish)
472 imod->pmod->finish(imod);
473 imod->pmod->links--;
474 OPENSSL_free(imod->name);
475 OPENSSL_free(imod->value);
476 OPENSSL_free(imod);
477 }
478
479/* Add a static module to OpenSSL */
480
481int CONF_module_add(const char *name, conf_init_func *ifunc,
482 conf_finish_func *ffunc)
483 {
484 if (module_add(NULL, name, ifunc, ffunc))
485 return 1;
486 else
487 return 0;
488 }
489
490void CONF_modules_free(void)
491 {
492 CONF_modules_finish();
493 CONF_modules_unload(1);
494 }
495
496/* Utility functions */
497
498const char *CONF_imodule_get_name(const CONF_IMODULE *md)
499 {
500 return md->name;
501 }
502
503const char *CONF_imodule_get_value(const CONF_IMODULE *md)
504 {
505 return md->value;
506 }
507
508void *CONF_imodule_get_usr_data(const CONF_IMODULE *md)
509 {
510 return md->usr_data;
511 }
512
513void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data)
514 {
515 md->usr_data = usr_data;
516 }
517
518CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md)
519 {
520 return md->pmod;
521 }
522
523unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md)
524 {
525 return md->flags;
526 }
527
528void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags)
529 {
530 md->flags = flags;
531 }
532
533void *CONF_module_get_usr_data(CONF_MODULE *pmod)
534 {
535 return pmod->usr_data;
536 }
537
538void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data)
539 {
540 pmod->usr_data = usr_data;
541 }
542
543/* Return default config file name */
544
545char *CONF_get1_default_config_file(void)
546 {
547 char *file;
548 int len;
549
550 file = getenv("OPENSSL_CONF");
551 if (file)
552 return BUF_strdup(file);
553
554 len = strlen(X509_get_default_cert_area());
555#ifndef OPENSSL_SYS_VMS
556 len++;
557#endif
558 len += strlen(OPENSSL_CONF);
559
560 file = OPENSSL_malloc(len + 1);
561
562 if (!file)
563 return NULL;
564 strcpy(file,X509_get_default_cert_area());
565#ifndef OPENSSL_SYS_VMS
566 strcat(file,"/");
567#endif
568 strcat(file,OPENSSL_CONF);
569
570 return file;
571 }
572
573/* This function takes a list separated by 'sep' and calls the
574 * callback function giving the start and length of each member
575 * optionally stripping leading and trailing whitespace. This can
576 * be used to parse comma separated lists for example.
577 */
578
579int CONF_parse_list(const char *list, int sep, int nospc,
580 int (*list_cb)(const char *elem, int len, void *usr), void *arg)
581 {
582 int ret;
583 const char *lstart, *tmpend, *p;
584 lstart = list;
585
586 for(;;)
587 {
588 if (nospc)
589 {
590 while(*lstart && isspace((unsigned char)*lstart))
591 lstart++;
592 }
593 p = strchr(lstart, sep);
594 if (p == lstart || !*lstart)
595 ret = list_cb(NULL, 0, arg);
596 else
597 {
598 if (p)
599 tmpend = p - 1;
600 else
601 tmpend = lstart + strlen(lstart) - 1;
602 if (nospc)
603 {
604 while(isspace((unsigned char)*tmpend))
605 tmpend--;
606 }
607 ret = list_cb(lstart, tmpend - lstart + 1, arg);
608 }
609 if (ret <= 0)
610 return ret;
611 if (p == NULL)
612 return 1;
613 lstart = p + 1;
614 }
615 }
616
diff --git a/src/lib/libcrypto/conf/conf_sap.c b/src/lib/libcrypto/conf/conf_sap.c
new file mode 100644
index 0000000000..97fb174303
--- /dev/null
+++ b/src/lib/libcrypto/conf/conf_sap.c
@@ -0,0 +1,107 @@
1/* conf_sap.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 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 "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/dso.h>
64#include <openssl/x509.h>
65#include <openssl/asn1.h>
66#include <openssl/engine.h>
67
68/* This is the automatic configuration loader: it is called automatically by
69 * OpenSSL when any of a number of standard initialisation functions are called,
70 * unless this is overridden by calling OPENSSL_no_config()
71 */
72
73static int openssl_configured = 0;
74
75void OPENSSL_config(const char *config_name)
76 {
77 if (openssl_configured)
78 return;
79
80 OPENSSL_load_builtin_modules();
81 /* Need to load ENGINEs */
82 ENGINE_load_builtin_engines();
83 /* Add others here? */
84
85
86 ERR_clear_error();
87 if (CONF_modules_load_file(NULL, NULL,
88 CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0)
89 {
90 BIO *bio_err;
91 ERR_load_crypto_strings();
92 if ((bio_err=BIO_new_fp(stderr, BIO_NOCLOSE)) != NULL)
93 {
94 BIO_printf(bio_err,"Auto configuration failed\n");
95 ERR_print_errors(bio_err);
96 BIO_free(bio_err);
97 }
98 exit(1);
99 }
100
101 return;
102 }
103
104void OPENSSL_no_config()
105 {
106 openssl_configured = 1;
107 }
diff --git a/src/lib/libcrypto/conf/keysets.pl b/src/lib/libcrypto/conf/keysets.pl
index 56669e76ac..50ed67fa52 100644
--- a/src/lib/libcrypto/conf/keysets.pl
+++ b/src/lib/libcrypto/conf/keysets.pl
@@ -12,8 +12,9 @@ $DQUOTE=0x400;
12$COMMENT=0x80; 12$COMMENT=0x80;
13$FCOMMENT=0x800; 13$FCOMMENT=0x800;
14$EOF=0x08; 14$EOF=0x08;
15$HIGHBIT=0x1000;
15 16
16foreach (0 .. 127) 17foreach (0 .. 255)
17 { 18 {
18 $v=0; 19 $v=0;
19 $c=sprintf("%c",$_); 20 $c=sprintf("%c",$_);
@@ -27,11 +28,12 @@ foreach (0 .. 127)
27 $v|=$QUOTE if ($c =~ /['`"]/); # for emacs: "`'}/) 28 $v|=$QUOTE if ($c =~ /['`"]/); # for emacs: "`'}/)
28 $v|=$COMMENT if ($c =~ /\#/); 29 $v|=$COMMENT if ($c =~ /\#/);
29 $v|=$EOF if ($c =~ /\0/); 30 $v|=$EOF if ($c =~ /\0/);
31 $v|=$HIGHBIT if ($c =~/[\x80-\xff]/);
30 32
31 push(@V_def,$v); 33 push(@V_def,$v);
32 } 34 }
33 35
34foreach (0 .. 127) 36foreach (0 .. 255)
35 { 37 {
36 $v=0; 38 $v=0;
37 $c=sprintf("%c",$_); 39 $c=sprintf("%c",$_);
@@ -44,6 +46,7 @@ foreach (0 .. 127)
44 $v|=$DQUOTE if ($c =~ /["]/); # for emacs: "}/) 46 $v|=$DQUOTE if ($c =~ /["]/); # for emacs: "}/)
45 $v|=$FCOMMENT if ($c =~ /;/); 47 $v|=$FCOMMENT if ($c =~ /;/);
46 $v|=$EOF if ($c =~ /\0/); 48 $v|=$EOF if ($c =~ /\0/);
49 $v|=$HIGHBIT if ($c =~/[\x80-\xff]/);
47 50
48 push(@V_w32,$v); 51 push(@V_w32,$v);
49 } 52 }
@@ -122,6 +125,7 @@ print <<"EOF";
122#define CONF_COMMENT $COMMENT 125#define CONF_COMMENT $COMMENT
123#define CONF_FCOMMENT $FCOMMENT 126#define CONF_FCOMMENT $FCOMMENT
124#define CONF_EOF $EOF 127#define CONF_EOF $EOF
128#define CONF_HIGHBIT $HIGHBIT
125#define CONF_ALPHA (CONF_UPPER|CONF_LOWER) 129#define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
126#define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER) 130#define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
127#define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \\ 131#define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \\
@@ -129,51 +133,53 @@ print <<"EOF";
129 133
130#define KEYTYPES(c) ((unsigned short *)((c)->meth_data)) 134#define KEYTYPES(c) ((unsigned short *)((c)->meth_data))
131#ifndef CHARSET_EBCDIC 135#ifndef CHARSET_EBCDIC
132#define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_COMMENT) 136#define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_COMMENT)
133#define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_FCOMMENT) 137#define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_FCOMMENT)
134#define IS_EOF(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_EOF) 138#define IS_EOF(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_EOF)
135#define IS_ESC(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_ESC) 139#define IS_ESC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ESC)
136#define IS_NUMBER(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_NUMBER) 140#define IS_NUMBER(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_NUMBER)
137#define IS_WS(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_WS) 141#define IS_WS(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_WS)
138#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_ALPHA_NUMERIC) 142#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC)
139#define IS_ALPHA_NUMERIC_PUNCT(c,a) \\ 143#define IS_ALPHA_NUMERIC_PUNCT(c,a) \\
140 (KEYTYPES(c)[(a)&0x7f]&CONF_ALPHA_NUMERIC_PUNCT) 144 (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
141#define IS_QUOTE(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_QUOTE) 145#define IS_QUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_QUOTE)
142#define IS_DQUOTE(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_DQUOTE) 146#define IS_DQUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_DQUOTE)
147#define IS_HIGHBIT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_HIGHBIT)
143 148
144#else /*CHARSET_EBCDIC*/ 149#else /*CHARSET_EBCDIC*/
145 150
146#define IS_COMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_COMMENT) 151#define IS_COMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_COMMENT)
147#define IS_FCOMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_FCOMMENT) 152#define IS_FCOMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_FCOMMENT)
148#define IS_EOF(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_EOF) 153#define IS_EOF(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_EOF)
149#define IS_ESC(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ESC) 154#define IS_ESC(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ESC)
150#define IS_NUMBER(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_NUMBER) 155#define IS_NUMBER(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_NUMBER)
151#define IS_WS(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_WS) 156#define IS_WS(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_WS)
152#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC) 157#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ALPHA_NUMERIC)
153#define IS_ALPHA_NUMERIC_PUNCT(c,a) \\ 158#define IS_ALPHA_NUMERIC_PUNCT(c,a) \\
154 (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC_PUNCT) 159 (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
155#define IS_QUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_QUOTE) 160#define IS_QUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_QUOTE)
156#define IS_DQUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_DQUOTE) 161#define IS_DQUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_DQUOTE)
162#define IS_HIGHBIT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_HIGHBIT)
157#endif /*CHARSET_EBCDIC*/ 163#endif /*CHARSET_EBCDIC*/
158 164
159EOF 165EOF
160 166
161print "static unsigned short CONF_type_default[128]={"; 167print "static unsigned short CONF_type_default[256]={";
162 168
163for ($i=0; $i<128; $i++) 169for ($i=0; $i<256; $i++)
164 { 170 {
165 print "\n\t" if ($i % 8) == 0; 171 print "\n\t" if ($i % 8) == 0;
166 printf "0x%03X,",$V_def[$i]; 172 printf "0x%04X,",$V_def[$i];
167 } 173 }
168 174
169print "\n\t};\n\n"; 175print "\n\t};\n\n";
170 176
171print "static unsigned short CONF_type_win32[128]={"; 177print "static unsigned short CONF_type_win32[256]={";
172 178
173for ($i=0; $i<128; $i++) 179for ($i=0; $i<256; $i++)
174 { 180 {
175 print "\n\t" if ($i % 8) == 0; 181 print "\n\t" if ($i % 8) == 0;
176 printf "0x%03X,",$V_w32[$i]; 182 printf "0x%04X,",$V_w32[$i];
177 } 183 }
178 184
179print "\n\t};\n\n"; 185print "\n\t};\n\n";