diff options
| author | cvs2svn <admin@example.com> | 2002-05-15 02:29:24 +0000 |
|---|---|---|
| committer | cvs2svn <admin@example.com> | 2002-05-15 02:29:24 +0000 |
| commit | 027351f729b9e837200dae6e1520cda6577ab930 (patch) | |
| tree | e25a717057aa4529e433fc3b1fac8d4df8db3a5c /src/lib/libcrypto/conf | |
| parent | aeeae06a79815dc190061534d47236cec09f9e32 (diff) | |
| download | openbsd-027351f729b9e837200dae6e1520cda6577ab930.tar.gz openbsd-027351f729b9e837200dae6e1520cda6577ab930.tar.bz2 openbsd-027351f729b9e837200dae6e1520cda6577ab930.zip | |
This commit was manufactured by cvs2git to create branch 'unlabeled-1.1.1'.
Diffstat (limited to 'src/lib/libcrypto/conf')
| -rw-r--r-- | src/lib/libcrypto/conf/README | 78 | ||||
| -rw-r--r-- | src/lib/libcrypto/conf/conf_api.c | 289 | ||||
| -rw-r--r-- | src/lib/libcrypto/conf/conf_api.h | 87 | ||||
| -rw-r--r-- | src/lib/libcrypto/conf/conf_def.c | 703 | ||||
| -rw-r--r-- | src/lib/libcrypto/conf/conf_def.h | 145 | ||||
| -rw-r--r-- | src/lib/libcrypto/conf/conf_lib.c | 352 | ||||
| -rw-r--r-- | src/lib/libcrypto/conf/conf_mall.c | 76 | ||||
| -rw-r--r-- | src/lib/libcrypto/conf/conf_mod.c | 616 | ||||
| -rw-r--r-- | src/lib/libcrypto/conf/conf_sap.c | 107 |
9 files changed, 2453 insertions, 0 deletions
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 @@ | |||
| 1 | WARNING WARNING WARNING!!! | ||
| 2 | |||
| 3 | This stuff is experimental, may change radically or be deleted altogether | ||
| 4 | before OpenSSL 0.9.7 release. You have been warned! | ||
| 5 | |||
| 6 | Configuration modules. These are a set of modules which can perform | ||
| 7 | various configuration functions. | ||
| 8 | |||
| 9 | Currently the routines should be called at most once when an application | ||
| 10 | starts up: that is before it starts any threads. | ||
| 11 | |||
| 12 | The routines read a configuration file set up like this: | ||
| 13 | |||
| 14 | ----- | ||
| 15 | #default section | ||
| 16 | openssl_init=init_section | ||
| 17 | |||
| 18 | [init_section] | ||
| 19 | |||
| 20 | module1=value1 | ||
| 21 | #Second instance of module1 | ||
| 22 | module1.1=valueX | ||
| 23 | module2=value2 | ||
| 24 | module3=dso_literal | ||
| 25 | module4=dso_section | ||
| 26 | |||
| 27 | [dso_section] | ||
| 28 | |||
| 29 | path=/some/path/to/some/dso.so | ||
| 30 | other_stuff=other_value | ||
| 31 | ---- | ||
| 32 | |||
| 33 | When this file is loaded a configuration module with the specified | ||
| 34 | string (module* in the above example) is looked up and its init | ||
| 35 | function called as: | ||
| 36 | |||
| 37 | int conf_init_func(CONF_IMODULE *md, CONF *cnf); | ||
| 38 | |||
| 39 | The function can then take whatever action is appropriate, for example | ||
| 40 | further lookups based on the value. Multiple instances of the same | ||
| 41 | config module can be loaded. | ||
| 42 | |||
| 43 | When the application closes down the modules are cleaned up by calling | ||
| 44 | an optional finish function: | ||
| 45 | |||
| 46 | void conf_finish_func(CONF_IMODULE *md); | ||
| 47 | |||
| 48 | The finish functions are called in reverse order: that is the last module | ||
| 49 | loaded is the first one cleaned up. | ||
| 50 | |||
| 51 | If no module exists with a given name then an attempt is made to load | ||
| 52 | a DSO with the supplied name. This might mean that "module3" attempts | ||
| 53 | to load a DSO called libmodule3.so or module3.dll for example. An explicit | ||
| 54 | DSO name can be given by including a separate section as in the module4 example | ||
| 55 | above. | ||
| 56 | |||
| 57 | The DSO is expected to at least contain an initialization function: | ||
| 58 | |||
| 59 | int OPENSSL_init(CONF_IMODULE *md, CONF *cnf); | ||
| 60 | |||
| 61 | and may also include a finish function: | ||
| 62 | |||
| 63 | void OPENSSL_finish(CONF_IMODULE *md); | ||
| 64 | |||
| 65 | Static modules can also be added using, | ||
| 66 | |||
| 67 | int CONF_module_add(char *name, dso_mod_init_func *ifunc, dso_mod_finish_func *ffunc); | ||
| 68 | |||
| 69 | where "name" is the name in the configuration file this function corresponds to. | ||
| 70 | |||
| 71 | A set of builtin modules (currently only an ASN1 non functional test module) can be | ||
| 72 | added by calling OPENSSL_load_builtin_modules(). | ||
| 73 | |||
| 74 | The function OPENSSL_config() is intended as a simple configuration function that | ||
| 75 | any application can call to perform various default configuration tasks. It uses the | ||
| 76 | file openssl.cnf in the usual locations. | ||
| 77 | |||
| 78 | |||
diff --git a/src/lib/libcrypto/conf/conf_api.c b/src/lib/libcrypto/conf/conf_api.c new file mode 100644 index 0000000000..d05a778ff6 --- /dev/null +++ b/src/lib/libcrypto/conf/conf_api.c | |||
| @@ -0,0 +1,289 @@ | |||
| 1 | /* conf_api.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* Part of the code in here was originally in conf.c, which is now removed */ | ||
| 60 | |||
| 61 | #ifndef CONF_DEBUG | ||
| 62 | # undef NDEBUG /* avoid conflicting definitions */ | ||
| 63 | # define NDEBUG | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #include <assert.h> | ||
| 67 | #include <string.h> | ||
| 68 | #include <openssl/conf.h> | ||
| 69 | #include <openssl/conf_api.h> | ||
| 70 | |||
| 71 | static void value_free_hash(CONF_VALUE *a, LHASH *conf); | ||
| 72 | static void value_free_stack(CONF_VALUE *a,LHASH *conf); | ||
| 73 | static unsigned long hash(CONF_VALUE *v); | ||
| 74 | static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b); | ||
| 75 | |||
| 76 | /* Up until OpenSSL 0.9.5a, this was get_section */ | ||
| 77 | CONF_VALUE *_CONF_get_section(CONF *conf, char *section) | ||
| 78 | { | ||
| 79 | CONF_VALUE *v,vv; | ||
| 80 | |||
| 81 | if ((conf == NULL) || (section == NULL)) return(NULL); | ||
| 82 | vv.name=NULL; | ||
| 83 | vv.section=section; | ||
| 84 | v=(CONF_VALUE *)lh_retrieve(conf->data,&vv); | ||
| 85 | return(v); | ||
| 86 | } | ||
| 87 | |||
| 88 | /* Up until OpenSSL 0.9.5a, this was CONF_get_section */ | ||
| 89 | STACK_OF(CONF_VALUE) *_CONF_get_section_values(CONF *conf, char *section) | ||
| 90 | { | ||
| 91 | CONF_VALUE *v; | ||
| 92 | |||
| 93 | v=_CONF_get_section(conf,section); | ||
| 94 | if (v != NULL) | ||
| 95 | return((STACK_OF(CONF_VALUE) *)v->value); | ||
| 96 | else | ||
| 97 | return(NULL); | ||
| 98 | } | ||
| 99 | |||
| 100 | int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value) | ||
| 101 | { | ||
| 102 | CONF_VALUE *v = NULL; | ||
| 103 | STACK_OF(CONF_VALUE) *ts; | ||
| 104 | |||
| 105 | ts = (STACK_OF(CONF_VALUE) *)section->value; | ||
| 106 | |||
| 107 | value->section=section->section; | ||
| 108 | if (!sk_CONF_VALUE_push(ts,value)) | ||
| 109 | { | ||
| 110 | return 0; | ||
| 111 | } | ||
| 112 | |||
| 113 | v = (CONF_VALUE *)lh_insert(conf->data, value); | ||
| 114 | if (v != NULL) | ||
| 115 | { | ||
| 116 | sk_CONF_VALUE_delete_ptr(ts,v); | ||
| 117 | OPENSSL_free(v->name); | ||
| 118 | OPENSSL_free(v->value); | ||
| 119 | OPENSSL_free(v); | ||
| 120 | } | ||
| 121 | return 1; | ||
| 122 | } | ||
| 123 | |||
| 124 | char *_CONF_get_string(CONF *conf, char *section, char *name) | ||
| 125 | { | ||
| 126 | CONF_VALUE *v,vv; | ||
| 127 | char *p; | ||
| 128 | |||
| 129 | if (name == NULL) return(NULL); | ||
| 130 | if (conf != NULL) | ||
| 131 | { | ||
| 132 | if (section != NULL) | ||
| 133 | { | ||
| 134 | vv.name=name; | ||
| 135 | vv.section=section; | ||
| 136 | v=(CONF_VALUE *)lh_retrieve(conf->data,&vv); | ||
| 137 | if (v != NULL) return(v->value); | ||
| 138 | if (strcmp(section,"ENV") == 0) | ||
| 139 | { | ||
| 140 | p=Getenv(name); | ||
| 141 | if (p != NULL) return(p); | ||
| 142 | } | ||
| 143 | } | ||
| 144 | vv.section="default"; | ||
| 145 | vv.name=name; | ||
| 146 | v=(CONF_VALUE *)lh_retrieve(conf->data,&vv); | ||
| 147 | if (v != NULL) | ||
| 148 | return(v->value); | ||
| 149 | else | ||
| 150 | return(NULL); | ||
| 151 | } | ||
| 152 | else | ||
| 153 | return(Getenv(name)); | ||
| 154 | } | ||
| 155 | |||
| 156 | long _CONF_get_number(CONF *conf, char *section, char *name) | ||
| 157 | { | ||
| 158 | char *str; | ||
| 159 | long ret=0; | ||
| 160 | |||
| 161 | str=_CONF_get_string(conf,section,name); | ||
| 162 | if (str == NULL) return(0); | ||
| 163 | for (;;) | ||
| 164 | { | ||
| 165 | if (conf->meth->is_number(conf, *str)) | ||
| 166 | ret=ret*10+conf->meth->to_int(conf, *str); | ||
| 167 | else | ||
| 168 | return(ret); | ||
| 169 | str++; | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | int _CONF_new_data(CONF *conf) | ||
| 174 | { | ||
| 175 | if (conf == NULL) | ||
| 176 | { | ||
| 177 | return 0; | ||
| 178 | } | ||
| 179 | if (conf->data == NULL) | ||
| 180 | if ((conf->data = lh_new(hash,cmp_conf)) == NULL) | ||
| 181 | { | ||
| 182 | return 0; | ||
| 183 | } | ||
| 184 | return 1; | ||
| 185 | } | ||
| 186 | |||
| 187 | void _CONF_free_data(CONF *conf) | ||
| 188 | { | ||
| 189 | if (conf == NULL || conf->data == NULL) return; | ||
| 190 | |||
| 191 | conf->data->down_load=0; /* evil thing to make sure the 'OPENSSL_free()' | ||
| 192 | * works as expected */ | ||
| 193 | lh_doall_arg(conf->data,(void (*)())value_free_hash,conf->data); | ||
| 194 | |||
| 195 | /* We now have only 'section' entries in the hash table. | ||
| 196 | * Due to problems with */ | ||
| 197 | |||
| 198 | lh_doall_arg(conf->data,(void (*)())value_free_stack,conf->data); | ||
| 199 | lh_free(conf->data); | ||
| 200 | } | ||
| 201 | |||
| 202 | static void value_free_hash(CONF_VALUE *a, LHASH *conf) | ||
| 203 | { | ||
| 204 | if (a->name != NULL) | ||
| 205 | { | ||
| 206 | a=(CONF_VALUE *)lh_delete(conf,a); | ||
| 207 | } | ||
| 208 | } | ||
| 209 | |||
| 210 | static void value_free_stack(CONF_VALUE *a, LHASH *conf) | ||
| 211 | { | ||
| 212 | CONF_VALUE *vv; | ||
| 213 | STACK *sk; | ||
| 214 | int i; | ||
| 215 | |||
| 216 | if (a->name != NULL) return; | ||
| 217 | |||
| 218 | sk=(STACK *)a->value; | ||
| 219 | for (i=sk_num(sk)-1; i>=0; i--) | ||
| 220 | { | ||
| 221 | vv=(CONF_VALUE *)sk_value(sk,i); | ||
| 222 | OPENSSL_free(vv->value); | ||
| 223 | OPENSSL_free(vv->name); | ||
| 224 | OPENSSL_free(vv); | ||
| 225 | } | ||
| 226 | if (sk != NULL) sk_free(sk); | ||
| 227 | OPENSSL_free(a->section); | ||
| 228 | OPENSSL_free(a); | ||
| 229 | } | ||
| 230 | |||
| 231 | static unsigned long hash(CONF_VALUE *v) | ||
| 232 | { | ||
| 233 | return((lh_strhash(v->section)<<2)^lh_strhash(v->name)); | ||
| 234 | } | ||
| 235 | |||
| 236 | static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b) | ||
| 237 | { | ||
| 238 | int i; | ||
| 239 | |||
| 240 | if (a->section != b->section) | ||
| 241 | { | ||
| 242 | i=strcmp(a->section,b->section); | ||
| 243 | if (i) return(i); | ||
| 244 | } | ||
| 245 | |||
| 246 | if ((a->name != NULL) && (b->name != NULL)) | ||
| 247 | { | ||
| 248 | i=strcmp(a->name,b->name); | ||
| 249 | return(i); | ||
| 250 | } | ||
| 251 | else if (a->name == b->name) | ||
| 252 | return(0); | ||
| 253 | else | ||
| 254 | return((a->name == NULL)?-1:1); | ||
| 255 | } | ||
| 256 | |||
| 257 | /* Up until OpenSSL 0.9.5a, this was new_section */ | ||
| 258 | CONF_VALUE *_CONF_new_section(CONF *conf, char *section) | ||
| 259 | { | ||
| 260 | STACK *sk=NULL; | ||
| 261 | int ok=0,i; | ||
| 262 | CONF_VALUE *v=NULL,*vv; | ||
| 263 | |||
| 264 | if ((sk=sk_new_null()) == NULL) | ||
| 265 | goto err; | ||
| 266 | if ((v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))) == NULL) | ||
| 267 | goto err; | ||
| 268 | i=strlen(section)+1; | ||
| 269 | if ((v->section=(char *)OPENSSL_malloc(i)) == NULL) | ||
| 270 | goto err; | ||
| 271 | |||
| 272 | memcpy(v->section,section,i); | ||
| 273 | v->name=NULL; | ||
| 274 | v->value=(char *)sk; | ||
| 275 | |||
| 276 | vv=(CONF_VALUE *)lh_insert(conf->data,v); | ||
| 277 | assert(vv == NULL); | ||
| 278 | ok=1; | ||
| 279 | err: | ||
| 280 | if (!ok) | ||
| 281 | { | ||
| 282 | if (sk != NULL) sk_free(sk); | ||
| 283 | if (v != NULL) OPENSSL_free(v); | ||
| 284 | v=NULL; | ||
| 285 | } | ||
| 286 | return(v); | ||
| 287 | } | ||
| 288 | |||
| 289 | IMPLEMENT_STACK_OF(CONF_VALUE) | ||
diff --git a/src/lib/libcrypto/conf/conf_api.h b/src/lib/libcrypto/conf/conf_api.h new file mode 100644 index 0000000000..a5cc17b233 --- /dev/null +++ b/src/lib/libcrypto/conf/conf_api.h | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | /* conf_api.h */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef HEADER_CONF_API_H | ||
| 60 | #define HEADER_CONF_API_H | ||
| 61 | |||
| 62 | #include <openssl/lhash.h> | ||
| 63 | #include <openssl/conf.h> | ||
| 64 | |||
| 65 | #ifdef __cplusplus | ||
| 66 | extern "C" { | ||
| 67 | #endif | ||
| 68 | |||
| 69 | /* Up until OpenSSL 0.9.5a, this was new_section */ | ||
| 70 | CONF_VALUE *_CONF_new_section(CONF *conf, char *section); | ||
| 71 | /* Up until OpenSSL 0.9.5a, this was get_section */ | ||
| 72 | CONF_VALUE *_CONF_get_section(CONF *conf, char *section); | ||
| 73 | /* Up until OpenSSL 0.9.5a, this was CONF_get_section */ | ||
| 74 | STACK_OF(CONF_VALUE) *_CONF_get_section_values(CONF *conf, char *section); | ||
| 75 | |||
| 76 | int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value); | ||
| 77 | char *_CONF_get_string(CONF *conf, char *section, char *name); | ||
| 78 | long _CONF_get_number(CONF *conf, char *section, char *name); | ||
| 79 | |||
| 80 | int _CONF_new_data(CONF *conf); | ||
| 81 | void _CONF_free_data(CONF *conf); | ||
| 82 | |||
| 83 | #ifdef __cplusplus | ||
| 84 | } | ||
| 85 | #endif | ||
| 86 | #endif | ||
| 87 | |||
diff --git a/src/lib/libcrypto/conf/conf_def.c b/src/lib/libcrypto/conf/conf_def.c new file mode 100644 index 0000000000..773df32c68 --- /dev/null +++ b/src/lib/libcrypto/conf/conf_def.c | |||
| @@ -0,0 +1,703 @@ | |||
| 1 | /* crypto/conf/conf.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* Part of the code in here was originally in conf.c, which is now removed */ | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include <string.h> | ||
| 63 | #include <openssl/stack.h> | ||
| 64 | #include <openssl/lhash.h> | ||
| 65 | #include <openssl/conf.h> | ||
| 66 | #include <openssl/conf_api.h> | ||
| 67 | #include "conf_def.h" | ||
| 68 | #include <openssl/buffer.h> | ||
| 69 | #include <openssl/err.h> | ||
| 70 | |||
| 71 | static char *eat_ws(CONF *conf, char *p); | ||
| 72 | static char *eat_alpha_numeric(CONF *conf, char *p); | ||
| 73 | static void clear_comments(CONF *conf, char *p); | ||
| 74 | static int str_copy(CONF *conf,char *section,char **to, char *from); | ||
| 75 | static char *scan_quote(CONF *conf, char *p); | ||
| 76 | static char *scan_dquote(CONF *conf, char *p); | ||
| 77 | #define scan_esc(conf,p) (((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2))) | ||
| 78 | |||
| 79 | static CONF *def_create(CONF_METHOD *meth); | ||
| 80 | static int def_init_default(CONF *conf); | ||
| 81 | static int def_init_WIN32(CONF *conf); | ||
| 82 | static int def_destroy(CONF *conf); | ||
| 83 | static int def_destroy_data(CONF *conf); | ||
| 84 | static int def_load(CONF *conf, BIO *bp, long *eline); | ||
| 85 | static int def_dump(CONF *conf, BIO *bp); | ||
| 86 | static int def_is_number(CONF *conf, char c); | ||
| 87 | static int def_to_int(CONF *conf, char c); | ||
| 88 | |||
| 89 | const char *CONF_def_version="CONF_def" OPENSSL_VERSION_PTEXT; | ||
| 90 | |||
| 91 | static CONF_METHOD default_method = { | ||
| 92 | "OpenSSL default", | ||
| 93 | def_create, | ||
| 94 | def_init_default, | ||
| 95 | def_destroy, | ||
| 96 | def_destroy_data, | ||
| 97 | def_load, | ||
| 98 | def_dump, | ||
| 99 | def_is_number, | ||
| 100 | def_to_int | ||
| 101 | }; | ||
| 102 | |||
| 103 | static CONF_METHOD WIN32_method = { | ||
| 104 | "WIN32", | ||
| 105 | def_create, | ||
| 106 | def_init_WIN32, | ||
| 107 | def_destroy, | ||
| 108 | def_destroy_data, | ||
| 109 | def_load, | ||
| 110 | def_dump, | ||
| 111 | def_is_number, | ||
| 112 | def_to_int | ||
| 113 | }; | ||
| 114 | |||
| 115 | CONF_METHOD *NCONF_default() | ||
| 116 | { | ||
| 117 | return &default_method; | ||
| 118 | } | ||
| 119 | CONF_METHOD *NCONF_WIN32() | ||
| 120 | { | ||
| 121 | return &WIN32_method; | ||
| 122 | } | ||
| 123 | |||
| 124 | static CONF *def_create(CONF_METHOD *meth) | ||
| 125 | { | ||
| 126 | CONF *ret; | ||
| 127 | |||
| 128 | ret = (CONF *)OPENSSL_malloc(sizeof(CONF) + sizeof(unsigned short *)); | ||
| 129 | if (ret) | ||
| 130 | if (meth->init(ret) == 0) | ||
| 131 | { | ||
| 132 | OPENSSL_free(ret); | ||
| 133 | ret = NULL; | ||
| 134 | } | ||
| 135 | return ret; | ||
| 136 | } | ||
| 137 | |||
| 138 | static int def_init_default(CONF *conf) | ||
| 139 | { | ||
| 140 | if (conf == NULL) | ||
| 141 | return 0; | ||
| 142 | |||
| 143 | conf->meth = &default_method; | ||
| 144 | conf->meth_data = (void *)CONF_type_default; | ||
| 145 | conf->data = NULL; | ||
| 146 | |||
| 147 | return 1; | ||
| 148 | } | ||
| 149 | |||
| 150 | static int def_init_WIN32(CONF *conf) | ||
| 151 | { | ||
| 152 | if (conf == NULL) | ||
| 153 | return 0; | ||
| 154 | |||
| 155 | conf->meth = &WIN32_method; | ||
| 156 | conf->meth_data = (void *)CONF_type_win32; | ||
| 157 | conf->data = NULL; | ||
| 158 | |||
| 159 | return 1; | ||
| 160 | } | ||
| 161 | |||
| 162 | static int def_destroy(CONF *conf) | ||
| 163 | { | ||
| 164 | if (def_destroy_data(conf)) | ||
| 165 | { | ||
| 166 | OPENSSL_free(conf); | ||
| 167 | return 1; | ||
| 168 | } | ||
| 169 | return 0; | ||
| 170 | } | ||
| 171 | |||
| 172 | static int def_destroy_data(CONF *conf) | ||
| 173 | { | ||
| 174 | if (conf == NULL) | ||
| 175 | return 0; | ||
| 176 | _CONF_free_data(conf); | ||
| 177 | return 1; | ||
| 178 | } | ||
| 179 | |||
| 180 | static int def_load(CONF *conf, BIO *in, long *line) | ||
| 181 | { | ||
| 182 | #define BUFSIZE 512 | ||
| 183 | char btmp[16]; | ||
| 184 | int bufnum=0,i,ii; | ||
| 185 | BUF_MEM *buff=NULL; | ||
| 186 | char *s,*p,*end; | ||
| 187 | int again,n; | ||
| 188 | long eline=0; | ||
| 189 | CONF_VALUE *v=NULL,*tv; | ||
| 190 | CONF_VALUE *sv=NULL; | ||
| 191 | char *section=NULL,*buf; | ||
| 192 | STACK_OF(CONF_VALUE) *section_sk=NULL,*ts; | ||
| 193 | char *start,*psection,*pname; | ||
| 194 | void *h = (void *)(conf->data); | ||
| 195 | |||
| 196 | if ((buff=BUF_MEM_new()) == NULL) | ||
| 197 | { | ||
| 198 | CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB); | ||
| 199 | goto err; | ||
| 200 | } | ||
| 201 | |||
| 202 | section=(char *)OPENSSL_malloc(10); | ||
| 203 | if (section == NULL) | ||
| 204 | { | ||
| 205 | CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE); | ||
| 206 | goto err; | ||
| 207 | } | ||
| 208 | strcpy(section,"default"); | ||
| 209 | |||
| 210 | if (_CONF_new_data(conf) == 0) | ||
| 211 | { | ||
| 212 | CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE); | ||
| 213 | goto err; | ||
| 214 | } | ||
| 215 | |||
| 216 | sv=_CONF_new_section(conf,section); | ||
| 217 | if (sv == NULL) | ||
| 218 | { | ||
| 219 | CONFerr(CONF_F_CONF_LOAD_BIO, | ||
| 220 | CONF_R_UNABLE_TO_CREATE_NEW_SECTION); | ||
| 221 | goto err; | ||
| 222 | } | ||
| 223 | section_sk=(STACK_OF(CONF_VALUE) *)sv->value; | ||
| 224 | |||
| 225 | bufnum=0; | ||
| 226 | for (;;) | ||
| 227 | { | ||
| 228 | again=0; | ||
| 229 | if (!BUF_MEM_grow(buff,bufnum+BUFSIZE)) | ||
| 230 | { | ||
| 231 | CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB); | ||
| 232 | goto err; | ||
| 233 | } | ||
| 234 | p= &(buff->data[bufnum]); | ||
| 235 | *p='\0'; | ||
| 236 | BIO_gets(in, p, BUFSIZE-1); | ||
| 237 | p[BUFSIZE-1]='\0'; | ||
| 238 | ii=i=strlen(p); | ||
| 239 | if (i == 0) break; | ||
| 240 | while (i > 0) | ||
| 241 | { | ||
| 242 | if ((p[i-1] != '\r') && (p[i-1] != '\n')) | ||
| 243 | break; | ||
| 244 | else | ||
| 245 | i--; | ||
| 246 | } | ||
| 247 | /* we removed some trailing stuff so there is a new | ||
| 248 | * line on the end. */ | ||
| 249 | if (i == ii) | ||
| 250 | again=1; /* long line */ | ||
| 251 | else | ||
| 252 | { | ||
| 253 | p[i]='\0'; | ||
| 254 | eline++; /* another input line */ | ||
| 255 | } | ||
| 256 | |||
| 257 | /* we now have a line with trailing \r\n removed */ | ||
| 258 | |||
| 259 | /* i is the number of bytes */ | ||
| 260 | bufnum+=i; | ||
| 261 | |||
| 262 | v=NULL; | ||
| 263 | /* check for line continuation */ | ||
| 264 | if (bufnum >= 1) | ||
| 265 | { | ||
| 266 | /* If we have bytes and the last char '\\' and | ||
| 267 | * second last char is not '\\' */ | ||
| 268 | p= &(buff->data[bufnum-1]); | ||
| 269 | if (IS_ESC(conf,p[0]) && | ||
| 270 | ((bufnum <= 1) || !IS_ESC(conf,p[-1]))) | ||
| 271 | { | ||
| 272 | bufnum--; | ||
| 273 | again=1; | ||
| 274 | } | ||
| 275 | } | ||
| 276 | if (again) continue; | ||
| 277 | bufnum=0; | ||
| 278 | buf=buff->data; | ||
| 279 | |||
| 280 | clear_comments(conf, buf); | ||
| 281 | n=strlen(buf); | ||
| 282 | s=eat_ws(conf, buf); | ||
| 283 | if (IS_EOF(conf,*s)) continue; /* blank line */ | ||
| 284 | if (*s == '[') | ||
| 285 | { | ||
| 286 | char *ss; | ||
| 287 | |||
| 288 | s++; | ||
| 289 | start=eat_ws(conf, s); | ||
| 290 | ss=start; | ||
| 291 | again: | ||
| 292 | end=eat_alpha_numeric(conf, ss); | ||
| 293 | p=eat_ws(conf, end); | ||
| 294 | if (*p != ']') | ||
| 295 | { | ||
| 296 | if (*p != '\0') | ||
| 297 | { | ||
| 298 | ss=p; | ||
| 299 | goto again; | ||
| 300 | } | ||
| 301 | CONFerr(CONF_F_CONF_LOAD_BIO, | ||
| 302 | CONF_R_MISSING_CLOSE_SQUARE_BRACKET); | ||
| 303 | goto err; | ||
| 304 | } | ||
| 305 | *end='\0'; | ||
| 306 | if (!str_copy(conf,NULL,§ion,start)) goto err; | ||
| 307 | if ((sv=_CONF_get_section(conf,section)) == NULL) | ||
| 308 | sv=_CONF_new_section(conf,section); | ||
| 309 | if (sv == NULL) | ||
| 310 | { | ||
| 311 | CONFerr(CONF_F_CONF_LOAD_BIO, | ||
| 312 | CONF_R_UNABLE_TO_CREATE_NEW_SECTION); | ||
| 313 | goto err; | ||
| 314 | } | ||
| 315 | section_sk=(STACK_OF(CONF_VALUE) *)sv->value; | ||
| 316 | continue; | ||
| 317 | } | ||
| 318 | else | ||
| 319 | { | ||
| 320 | pname=s; | ||
| 321 | psection=NULL; | ||
| 322 | end=eat_alpha_numeric(conf, s); | ||
| 323 | if ((end[0] == ':') && (end[1] == ':')) | ||
| 324 | { | ||
| 325 | *end='\0'; | ||
| 326 | end+=2; | ||
| 327 | psection=pname; | ||
| 328 | pname=end; | ||
| 329 | end=eat_alpha_numeric(conf, end); | ||
| 330 | } | ||
| 331 | p=eat_ws(conf, end); | ||
| 332 | if (*p != '=') | ||
| 333 | { | ||
| 334 | CONFerr(CONF_F_CONF_LOAD_BIO, | ||
| 335 | CONF_R_MISSING_EQUAL_SIGN); | ||
| 336 | goto err; | ||
| 337 | } | ||
| 338 | *end='\0'; | ||
| 339 | p++; | ||
| 340 | start=eat_ws(conf, p); | ||
| 341 | while (!IS_EOF(conf,*p)) | ||
| 342 | p++; | ||
| 343 | p--; | ||
| 344 | while ((p != start) && (IS_WS(conf,*p))) | ||
| 345 | p--; | ||
| 346 | p++; | ||
| 347 | *p='\0'; | ||
| 348 | |||
| 349 | if (!(v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE)))) | ||
| 350 | { | ||
| 351 | CONFerr(CONF_F_CONF_LOAD_BIO, | ||
| 352 | ERR_R_MALLOC_FAILURE); | ||
| 353 | goto err; | ||
| 354 | } | ||
| 355 | if (psection == NULL) psection=section; | ||
| 356 | v->name=(char *)OPENSSL_malloc(strlen(pname)+1); | ||
| 357 | v->value=NULL; | ||
| 358 | if (v->name == NULL) | ||
| 359 | { | ||
| 360 | CONFerr(CONF_F_CONF_LOAD_BIO, | ||
| 361 | ERR_R_MALLOC_FAILURE); | ||
| 362 | goto err; | ||
| 363 | } | ||
| 364 | strcpy(v->name,pname); | ||
| 365 | if (!str_copy(conf,psection,&(v->value),start)) goto err; | ||
| 366 | |||
| 367 | if (strcmp(psection,section) != 0) | ||
| 368 | { | ||
| 369 | if ((tv=_CONF_get_section(conf,psection)) | ||
| 370 | == NULL) | ||
| 371 | tv=_CONF_new_section(conf,psection); | ||
| 372 | if (tv == NULL) | ||
| 373 | { | ||
| 374 | CONFerr(CONF_F_CONF_LOAD_BIO, | ||
| 375 | CONF_R_UNABLE_TO_CREATE_NEW_SECTION); | ||
| 376 | goto err; | ||
| 377 | } | ||
| 378 | ts=(STACK_OF(CONF_VALUE) *)tv->value; | ||
| 379 | } | ||
| 380 | else | ||
| 381 | { | ||
| 382 | tv=sv; | ||
| 383 | ts=section_sk; | ||
| 384 | } | ||
| 385 | #if 1 | ||
| 386 | if (_CONF_add_string(conf, tv, v) == 0) | ||
| 387 | { | ||
| 388 | CONFerr(CONF_F_CONF_LOAD_BIO, | ||
| 389 | ERR_R_MALLOC_FAILURE); | ||
| 390 | goto err; | ||
| 391 | } | ||
| 392 | #else | ||
| 393 | v->section=tv->section; | ||
| 394 | if (!sk_CONF_VALUE_push(ts,v)) | ||
| 395 | { | ||
| 396 | CONFerr(CONF_F_CONF_LOAD_BIO, | ||
| 397 | ERR_R_MALLOC_FAILURE); | ||
| 398 | goto err; | ||
| 399 | } | ||
| 400 | vv=(CONF_VALUE *)lh_insert(conf->data,v); | ||
| 401 | if (vv != NULL) | ||
| 402 | { | ||
| 403 | sk_CONF_VALUE_delete_ptr(ts,vv); | ||
| 404 | OPENSSL_free(vv->name); | ||
| 405 | OPENSSL_free(vv->value); | ||
| 406 | OPENSSL_free(vv); | ||
| 407 | } | ||
| 408 | #endif | ||
| 409 | v=NULL; | ||
| 410 | } | ||
| 411 | } | ||
| 412 | if (buff != NULL) BUF_MEM_free(buff); | ||
| 413 | if (section != NULL) OPENSSL_free(section); | ||
| 414 | return(1); | ||
| 415 | err: | ||
| 416 | if (buff != NULL) BUF_MEM_free(buff); | ||
| 417 | if (section != NULL) OPENSSL_free(section); | ||
| 418 | if (line != NULL) *line=eline; | ||
| 419 | sprintf(btmp,"%ld",eline); | ||
| 420 | ERR_add_error_data(2,"line ",btmp); | ||
| 421 | if ((h != conf->data) && (conf->data != NULL)) CONF_free(conf->data); | ||
| 422 | if (v != NULL) | ||
| 423 | { | ||
| 424 | if (v->name != NULL) OPENSSL_free(v->name); | ||
| 425 | if (v->value != NULL) OPENSSL_free(v->value); | ||
| 426 | if (v != NULL) OPENSSL_free(v); | ||
| 427 | } | ||
| 428 | return(0); | ||
| 429 | } | ||
| 430 | |||
| 431 | static void clear_comments(CONF *conf, char *p) | ||
| 432 | { | ||
| 433 | char *to; | ||
| 434 | |||
| 435 | to=p; | ||
| 436 | for (;;) | ||
| 437 | { | ||
| 438 | if (IS_FCOMMENT(conf,*p)) | ||
| 439 | { | ||
| 440 | *p='\0'; | ||
| 441 | return; | ||
| 442 | } | ||
| 443 | if (!IS_WS(conf,*p)) | ||
| 444 | { | ||
| 445 | break; | ||
| 446 | } | ||
| 447 | p++; | ||
| 448 | } | ||
| 449 | |||
| 450 | for (;;) | ||
| 451 | { | ||
| 452 | if (IS_COMMENT(conf,*p)) | ||
| 453 | { | ||
| 454 | *p='\0'; | ||
| 455 | return; | ||
| 456 | } | ||
| 457 | if (IS_DQUOTE(conf,*p)) | ||
| 458 | { | ||
| 459 | p=scan_dquote(conf, p); | ||
| 460 | continue; | ||
| 461 | } | ||
| 462 | if (IS_QUOTE(conf,*p)) | ||
| 463 | { | ||
| 464 | p=scan_quote(conf, p); | ||
| 465 | continue; | ||
| 466 | } | ||
| 467 | if (IS_ESC(conf,*p)) | ||
| 468 | { | ||
| 469 | p=scan_esc(conf,p); | ||
| 470 | continue; | ||
| 471 | } | ||
| 472 | if (IS_EOF(conf,*p)) | ||
| 473 | return; | ||
| 474 | else | ||
| 475 | p++; | ||
| 476 | } | ||
| 477 | } | ||
| 478 | |||
| 479 | static int str_copy(CONF *conf, char *section, char **pto, char *from) | ||
| 480 | { | ||
| 481 | int q,r,rr=0,to=0,len=0; | ||
| 482 | char *s,*e,*rp,*p,*rrp,*np,*cp,v; | ||
| 483 | BUF_MEM *buf; | ||
| 484 | |||
| 485 | if ((buf=BUF_MEM_new()) == NULL) return(0); | ||
| 486 | |||
| 487 | len=strlen(from)+1; | ||
| 488 | if (!BUF_MEM_grow(buf,len)) goto err; | ||
| 489 | |||
| 490 | for (;;) | ||
| 491 | { | ||
| 492 | if (IS_QUOTE(conf,*from)) | ||
| 493 | { | ||
| 494 | q= *from; | ||
| 495 | from++; | ||
| 496 | while (!IS_EOF(conf,*from) && (*from != q)) | ||
| 497 | { | ||
| 498 | if (IS_ESC(conf,*from)) | ||
| 499 | { | ||
| 500 | from++; | ||
| 501 | if (IS_EOF(conf,*from)) break; | ||
| 502 | } | ||
| 503 | buf->data[to++]= *(from++); | ||
| 504 | } | ||
| 505 | if (*from == q) from++; | ||
| 506 | } | ||
| 507 | else if (IS_DQUOTE(conf,*from)) | ||
| 508 | { | ||
| 509 | q= *from; | ||
| 510 | from++; | ||
| 511 | while (!IS_EOF(conf,*from)) | ||
| 512 | { | ||
| 513 | if (*from == q) | ||
| 514 | { | ||
| 515 | if (*(from+1) == q) | ||
| 516 | { | ||
| 517 | from++; | ||
| 518 | } | ||
| 519 | else | ||
| 520 | { | ||
| 521 | break; | ||
| 522 | } | ||
| 523 | } | ||
| 524 | buf->data[to++]= *(from++); | ||
| 525 | } | ||
| 526 | if (*from == q) from++; | ||
| 527 | } | ||
| 528 | else if (IS_ESC(conf,*from)) | ||
| 529 | { | ||
| 530 | from++; | ||
| 531 | v= *(from++); | ||
| 532 | if (IS_EOF(conf,v)) break; | ||
| 533 | else if (v == 'r') v='\r'; | ||
| 534 | else if (v == 'n') v='\n'; | ||
| 535 | else if (v == 'b') v='\b'; | ||
| 536 | else if (v == 't') v='\t'; | ||
| 537 | buf->data[to++]= v; | ||
| 538 | } | ||
| 539 | else if (IS_EOF(conf,*from)) | ||
| 540 | break; | ||
| 541 | else if (*from == '$') | ||
| 542 | { | ||
| 543 | /* try to expand it */ | ||
| 544 | rrp=NULL; | ||
| 545 | s= &(from[1]); | ||
| 546 | if (*s == '{') | ||
| 547 | q='}'; | ||
| 548 | else if (*s == '(') | ||
| 549 | q=')'; | ||
| 550 | else q=0; | ||
| 551 | |||
| 552 | if (q) s++; | ||
| 553 | cp=section; | ||
| 554 | e=np=s; | ||
| 555 | while (IS_ALPHA_NUMERIC(conf,*e)) | ||
| 556 | e++; | ||
| 557 | if ((e[0] == ':') && (e[1] == ':')) | ||
| 558 | { | ||
| 559 | cp=np; | ||
| 560 | rrp=e; | ||
| 561 | rr= *e; | ||
| 562 | *rrp='\0'; | ||
| 563 | e+=2; | ||
| 564 | np=e; | ||
| 565 | while (IS_ALPHA_NUMERIC(conf,*e)) | ||
| 566 | e++; | ||
| 567 | } | ||
| 568 | r= *e; | ||
| 569 | *e='\0'; | ||
| 570 | rp=e; | ||
| 571 | if (q) | ||
| 572 | { | ||
| 573 | if (r != q) | ||
| 574 | { | ||
| 575 | CONFerr(CONF_F_STR_COPY,CONF_R_NO_CLOSE_BRACE); | ||
| 576 | goto err; | ||
| 577 | } | ||
| 578 | e++; | ||
| 579 | } | ||
| 580 | /* So at this point we have | ||
| 581 | * ns which is the start of the name string which is | ||
| 582 | * '\0' terminated. | ||
| 583 | * cs which is the start of the section string which is | ||
| 584 | * '\0' terminated. | ||
| 585 | * e is the 'next point after'. | ||
| 586 | * r and s are the chars replaced by the '\0' | ||
| 587 | * rp and sp is where 'r' and 's' came from. | ||
| 588 | */ | ||
| 589 | p=_CONF_get_string(conf,cp,np); | ||
| 590 | if (rrp != NULL) *rrp=rr; | ||
| 591 | *rp=r; | ||
| 592 | if (p == NULL) | ||
| 593 | { | ||
| 594 | CONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE); | ||
| 595 | goto err; | ||
| 596 | } | ||
| 597 | BUF_MEM_grow(buf,(strlen(p)+len-(e-from))); | ||
| 598 | while (*p) | ||
| 599 | buf->data[to++]= *(p++); | ||
| 600 | from=e; | ||
| 601 | } | ||
| 602 | else | ||
| 603 | buf->data[to++]= *(from++); | ||
| 604 | } | ||
| 605 | buf->data[to]='\0'; | ||
| 606 | if (*pto != NULL) OPENSSL_free(*pto); | ||
| 607 | *pto=buf->data; | ||
| 608 | OPENSSL_free(buf); | ||
| 609 | return(1); | ||
| 610 | err: | ||
| 611 | if (buf != NULL) BUF_MEM_free(buf); | ||
| 612 | return(0); | ||
| 613 | } | ||
| 614 | |||
| 615 | static char *eat_ws(CONF *conf, char *p) | ||
| 616 | { | ||
| 617 | while (IS_WS(conf,*p) && (!IS_EOF(conf,*p))) | ||
| 618 | p++; | ||
| 619 | return(p); | ||
| 620 | } | ||
| 621 | |||
| 622 | static char *eat_alpha_numeric(CONF *conf, char *p) | ||
| 623 | { | ||
| 624 | for (;;) | ||
| 625 | { | ||
| 626 | if (IS_ESC(conf,*p)) | ||
| 627 | { | ||
| 628 | p=scan_esc(conf,p); | ||
| 629 | continue; | ||
| 630 | } | ||
| 631 | if (!IS_ALPHA_NUMERIC_PUNCT(conf,*p)) | ||
| 632 | return(p); | ||
| 633 | p++; | ||
| 634 | } | ||
| 635 | } | ||
| 636 | |||
| 637 | static char *scan_quote(CONF *conf, char *p) | ||
| 638 | { | ||
| 639 | int q= *p; | ||
| 640 | |||
| 641 | p++; | ||
| 642 | while (!(IS_EOF(conf,*p)) && (*p != q)) | ||
| 643 | { | ||
| 644 | if (IS_ESC(conf,*p)) | ||
| 645 | { | ||
| 646 | p++; | ||
| 647 | if (IS_EOF(conf,*p)) return(p); | ||
| 648 | } | ||
| 649 | p++; | ||
| 650 | } | ||
| 651 | if (*p == q) p++; | ||
| 652 | return(p); | ||
| 653 | } | ||
| 654 | |||
| 655 | |||
| 656 | static char *scan_dquote(CONF *conf, char *p) | ||
| 657 | { | ||
| 658 | int q= *p; | ||
| 659 | |||
| 660 | p++; | ||
| 661 | while (!(IS_EOF(conf,*p))) | ||
| 662 | { | ||
| 663 | if (*p == q) | ||
| 664 | { | ||
| 665 | if (*(p+1) == q) | ||
| 666 | { | ||
| 667 | p++; | ||
| 668 | } | ||
| 669 | else | ||
| 670 | { | ||
| 671 | break; | ||
| 672 | } | ||
| 673 | } | ||
| 674 | p++; | ||
| 675 | } | ||
| 676 | if (*p == q) p++; | ||
| 677 | return(p); | ||
| 678 | } | ||
| 679 | |||
| 680 | static void dump_value(CONF_VALUE *a, BIO *out) | ||
| 681 | { | ||
| 682 | if (a->name) | ||
| 683 | BIO_printf(out, "[%s] %s=%s\n", a->section, a->name, a->value); | ||
| 684 | else | ||
| 685 | BIO_printf(out, "[[%s]]\n", a->section); | ||
| 686 | } | ||
| 687 | |||
| 688 | static int def_dump(CONF *conf, BIO *out) | ||
| 689 | { | ||
| 690 | lh_doall_arg(conf->data, (void (*)())dump_value, out); | ||
| 691 | return 1; | ||
| 692 | } | ||
| 693 | |||
| 694 | static int def_is_number(CONF *conf, char c) | ||
| 695 | { | ||
| 696 | return IS_NUMBER(conf,c); | ||
| 697 | } | ||
| 698 | |||
| 699 | static int def_to_int(CONF *conf, char c) | ||
| 700 | { | ||
| 701 | return c - '0'; | ||
| 702 | } | ||
| 703 | |||
diff --git a/src/lib/libcrypto/conf/conf_def.h b/src/lib/libcrypto/conf/conf_def.h new file mode 100644 index 0000000000..3244d9a331 --- /dev/null +++ b/src/lib/libcrypto/conf/conf_def.h | |||
| @@ -0,0 +1,145 @@ | |||
| 1 | /* crypto/conf/conf_def.h */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* THIS FILE WAS AUTOMAGICALLY GENERATED! | ||
| 60 | Please modify and use keysets.pl to regenerate it. */ | ||
| 61 | |||
| 62 | #define CONF_NUMBER 1 | ||
| 63 | #define CONF_UPPER 2 | ||
| 64 | #define CONF_LOWER 4 | ||
| 65 | #define CONF_UNDER 256 | ||
| 66 | #define CONF_PUNCTUATION 512 | ||
| 67 | #define CONF_WS 16 | ||
| 68 | #define CONF_ESC 32 | ||
| 69 | #define CONF_QUOTE 64 | ||
| 70 | #define CONF_DQUOTE 1024 | ||
| 71 | #define CONF_COMMENT 128 | ||
| 72 | #define CONF_FCOMMENT 2048 | ||
| 73 | #define CONF_EOF 8 | ||
| 74 | #define CONF_ALPHA (CONF_UPPER|CONF_LOWER) | ||
| 75 | #define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER) | ||
| 76 | #define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \ | ||
| 77 | CONF_PUNCTUATION) | ||
| 78 | |||
| 79 | #define KEYTYPES(c) ((unsigned short *)((c)->meth_data)) | ||
| 80 | #ifndef CHARSET_EBCDIC | ||
| 81 | #define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_COMMENT) | ||
| 82 | #define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_FCOMMENT) | ||
| 83 | #define IS_EOF(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_EOF) | ||
| 84 | #define IS_ESC(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_ESC) | ||
| 85 | #define IS_NUMBER(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_NUMBER) | ||
| 86 | #define IS_WS(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_WS) | ||
| 87 | #define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_ALPHA_NUMERIC) | ||
| 88 | #define IS_ALPHA_NUMERIC_PUNCT(c,a) \ | ||
| 89 | (KEYTYPES(c)[(a)&0x7f]&CONF_ALPHA_NUMERIC_PUNCT) | ||
| 90 | #define IS_QUOTE(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_QUOTE) | ||
| 91 | #define IS_DQUOTE(c,a) (KEYTYPES(c)[(a)&0x7f]&CONF_DQUOTE) | ||
| 92 | |||
| 93 | #else /*CHARSET_EBCDIC*/ | ||
| 94 | |||
| 95 | #define IS_COMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_COMMENT) | ||
| 96 | #define IS_FCOMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_FCOMMENT) | ||
| 97 | #define IS_EOF(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_EOF) | ||
| 98 | #define IS_ESC(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ESC) | ||
| 99 | #define IS_NUMBER(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_NUMBER) | ||
| 100 | #define IS_WS(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_WS) | ||
| 101 | #define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC) | ||
| 102 | #define IS_ALPHA_NUMERIC_PUNCT(c,a) \ | ||
| 103 | (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC_PUNCT) | ||
| 104 | #define IS_QUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_QUOTE) | ||
| 105 | #define IS_DQUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0x7f]&CONF_DQUOTE) | ||
| 106 | #endif /*CHARSET_EBCDIC*/ | ||
| 107 | |||
| 108 | static unsigned short CONF_type_default[128]={ | ||
| 109 | 0x008,0x000,0x000,0x000,0x000,0x000,0x000,0x000, | ||
| 110 | 0x000,0x010,0x010,0x000,0x000,0x010,0x000,0x000, | ||
| 111 | 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000, | ||
| 112 | 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000, | ||
| 113 | 0x010,0x200,0x040,0x080,0x000,0x200,0x200,0x040, | ||
| 114 | 0x000,0x000,0x200,0x200,0x200,0x200,0x200,0x200, | ||
| 115 | 0x001,0x001,0x001,0x001,0x001,0x001,0x001,0x001, | ||
| 116 | 0x001,0x001,0x000,0x200,0x000,0x000,0x000,0x200, | ||
| 117 | 0x200,0x002,0x002,0x002,0x002,0x002,0x002,0x002, | ||
| 118 | 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002, | ||
| 119 | 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002, | ||
| 120 | 0x002,0x002,0x002,0x000,0x020,0x000,0x200,0x100, | ||
| 121 | 0x040,0x004,0x004,0x004,0x004,0x004,0x004,0x004, | ||
| 122 | 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004, | ||
| 123 | 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004, | ||
| 124 | 0x004,0x004,0x004,0x000,0x200,0x000,0x200,0x000, | ||
| 125 | }; | ||
| 126 | |||
| 127 | static unsigned short CONF_type_win32[128]={ | ||
| 128 | 0x008,0x000,0x000,0x000,0x000,0x000,0x000,0x000, | ||
| 129 | 0x000,0x010,0x010,0x000,0x000,0x010,0x000,0x000, | ||
| 130 | 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000, | ||
| 131 | 0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000, | ||
| 132 | 0x010,0x200,0x400,0x000,0x000,0x200,0x200,0x000, | ||
| 133 | 0x000,0x000,0x200,0x200,0x200,0x200,0x200,0x200, | ||
| 134 | 0x001,0x001,0x001,0x001,0x001,0x001,0x001,0x001, | ||
| 135 | 0x001,0x001,0x000,0xA00,0x000,0x000,0x000,0x200, | ||
| 136 | 0x200,0x002,0x002,0x002,0x002,0x002,0x002,0x002, | ||
| 137 | 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002, | ||
| 138 | 0x002,0x002,0x002,0x002,0x002,0x002,0x002,0x002, | ||
| 139 | 0x002,0x002,0x002,0x000,0x000,0x000,0x200,0x100, | ||
| 140 | 0x000,0x004,0x004,0x004,0x004,0x004,0x004,0x004, | ||
| 141 | 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004, | ||
| 142 | 0x004,0x004,0x004,0x004,0x004,0x004,0x004,0x004, | ||
| 143 | 0x004,0x004,0x004,0x000,0x200,0x000,0x200,0x000, | ||
| 144 | }; | ||
| 145 | |||
diff --git a/src/lib/libcrypto/conf/conf_lib.c b/src/lib/libcrypto/conf/conf_lib.c new file mode 100644 index 0000000000..4c8ca9e9ae --- /dev/null +++ b/src/lib/libcrypto/conf/conf_lib.c | |||
| @@ -0,0 +1,352 @@ | |||
| 1 | /* conf_lib.c */ | ||
| 2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <openssl/crypto.h> | ||
| 61 | #include <openssl/err.h> | ||
| 62 | #include <openssl/conf.h> | ||
| 63 | #include <openssl/conf_api.h> | ||
| 64 | #include <openssl/lhash.h> | ||
| 65 | |||
| 66 | const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT; | ||
| 67 | |||
| 68 | static CONF_METHOD *default_CONF_method=NULL; | ||
| 69 | |||
| 70 | /* The following section contains the "CONF classic" functions, | ||
| 71 | rewritten in terms of the new CONF interface. */ | ||
| 72 | |||
| 73 | int CONF_set_default_method(CONF_METHOD *meth) | ||
| 74 | { | ||
| 75 | default_CONF_method = meth; | ||
| 76 | return 1; | ||
| 77 | } | ||
| 78 | |||
| 79 | LHASH *CONF_load(LHASH *conf, const char *file, long *eline) | ||
| 80 | { | ||
| 81 | LHASH *ltmp; | ||
| 82 | BIO *in=NULL; | ||
| 83 | |||
| 84 | #ifdef VMS | ||
| 85 | in=BIO_new_file(file, "r"); | ||
| 86 | #else | ||
| 87 | in=BIO_new_file(file, "rb"); | ||
| 88 | #endif | ||
| 89 | if (in == NULL) | ||
| 90 | { | ||
| 91 | CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB); | ||
| 92 | return NULL; | ||
| 93 | } | ||
| 94 | |||
| 95 | ltmp = CONF_load_bio(conf, in, eline); | ||
| 96 | BIO_free(in); | ||
| 97 | |||
| 98 | return ltmp; | ||
| 99 | } | ||
| 100 | |||
| 101 | #ifndef NO_FP_API | ||
| 102 | LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline) | ||
| 103 | { | ||
| 104 | BIO *btmp; | ||
| 105 | LHASH *ltmp; | ||
| 106 | if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) { | ||
| 107 | CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB); | ||
| 108 | return NULL; | ||
| 109 | } | ||
| 110 | ltmp = CONF_load_bio(conf, btmp, eline); | ||
| 111 | BIO_free(btmp); | ||
| 112 | return ltmp; | ||
| 113 | } | ||
| 114 | #endif | ||
| 115 | |||
| 116 | LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline) | ||
| 117 | { | ||
| 118 | CONF ctmp; | ||
| 119 | int ret; | ||
| 120 | |||
| 121 | if (default_CONF_method == NULL) | ||
| 122 | default_CONF_method = NCONF_default(); | ||
| 123 | |||
| 124 | default_CONF_method->init(&ctmp); | ||
| 125 | ctmp.data = conf; | ||
| 126 | ret = NCONF_load_bio(&ctmp, bp, eline); | ||
| 127 | if (ret) | ||
| 128 | return ctmp.data; | ||
| 129 | return NULL; | ||
| 130 | } | ||
| 131 | |||
| 132 | STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section) | ||
| 133 | { | ||
| 134 | CONF ctmp; | ||
| 135 | |||
| 136 | if (default_CONF_method == NULL) | ||
| 137 | default_CONF_method = NCONF_default(); | ||
| 138 | |||
| 139 | default_CONF_method->init(&ctmp); | ||
| 140 | ctmp.data = conf; | ||
| 141 | return NCONF_get_section(&ctmp, section); | ||
| 142 | } | ||
| 143 | |||
| 144 | char *CONF_get_string(LHASH *conf,char *group,char *name) | ||
| 145 | { | ||
| 146 | CONF ctmp; | ||
| 147 | |||
| 148 | if (default_CONF_method == NULL) | ||
| 149 | default_CONF_method = NCONF_default(); | ||
| 150 | |||
| 151 | default_CONF_method->init(&ctmp); | ||
| 152 | ctmp.data = conf; | ||
| 153 | return NCONF_get_string(&ctmp, group, name); | ||
| 154 | } | ||
| 155 | |||
| 156 | long CONF_get_number(LHASH *conf,char *group,char *name) | ||
| 157 | { | ||
| 158 | CONF ctmp; | ||
| 159 | |||
| 160 | if (default_CONF_method == NULL) | ||
| 161 | default_CONF_method = NCONF_default(); | ||
| 162 | |||
| 163 | default_CONF_method->init(&ctmp); | ||
| 164 | ctmp.data = conf; | ||
| 165 | return NCONF_get_number(&ctmp, group, name); | ||
| 166 | } | ||
| 167 | |||
| 168 | void CONF_free(LHASH *conf) | ||
| 169 | { | ||
| 170 | CONF ctmp; | ||
| 171 | |||
| 172 | if (default_CONF_method == NULL) | ||
| 173 | default_CONF_method = NCONF_default(); | ||
| 174 | |||
| 175 | default_CONF_method->init(&ctmp); | ||
| 176 | ctmp.data = conf; | ||
| 177 | NCONF_free_data(&ctmp); | ||
| 178 | } | ||
| 179 | |||
| 180 | #ifndef NO_FP_API | ||
| 181 | int CONF_dump_fp(LHASH *conf, FILE *out) | ||
| 182 | { | ||
| 183 | BIO *btmp; | ||
| 184 | int ret; | ||
| 185 | |||
| 186 | if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) { | ||
| 187 | CONFerr(CONF_F_CONF_DUMP_FP,ERR_R_BUF_LIB); | ||
| 188 | return 0; | ||
| 189 | } | ||
| 190 | ret = CONF_dump_bio(conf, btmp); | ||
| 191 | BIO_free(btmp); | ||
| 192 | return ret; | ||
| 193 | } | ||
| 194 | #endif | ||
| 195 | |||
| 196 | int CONF_dump_bio(LHASH *conf, BIO *out) | ||
| 197 | { | ||
| 198 | CONF ctmp; | ||
| 199 | |||
| 200 | if (default_CONF_method == NULL) | ||
| 201 | default_CONF_method = NCONF_default(); | ||
| 202 | |||
| 203 | default_CONF_method->init(&ctmp); | ||
| 204 | ctmp.data = conf; | ||
| 205 | return NCONF_dump_bio(&ctmp, out); | ||
| 206 | } | ||
| 207 | |||
| 208 | /* The following section contains the "New CONF" functions. They are | ||
| 209 | completely centralised around a new CONF structure that may contain | ||
| 210 | basically anything, but at least a method pointer and a table of data. | ||
| 211 | These functions are also written in terms of the bridge functions used | ||
| 212 | by the "CONF classic" functions, for consistency. */ | ||
| 213 | |||
| 214 | CONF *NCONF_new(CONF_METHOD *meth) | ||
| 215 | { | ||
| 216 | CONF *ret; | ||
| 217 | |||
| 218 | if (meth == NULL) | ||
| 219 | meth = NCONF_default(); | ||
| 220 | |||
| 221 | ret = meth->create(meth); | ||
| 222 | if (ret == NULL) | ||
| 223 | { | ||
| 224 | CONFerr(CONF_F_NCONF_NEW,ERR_R_MALLOC_FAILURE); | ||
| 225 | return(NULL); | ||
| 226 | } | ||
| 227 | |||
| 228 | return ret; | ||
| 229 | } | ||
| 230 | |||
| 231 | void NCONF_free(CONF *conf) | ||
| 232 | { | ||
| 233 | if (conf == NULL) | ||
| 234 | return; | ||
| 235 | conf->meth->destroy(conf); | ||
| 236 | } | ||
| 237 | |||
| 238 | void NCONF_free_data(CONF *conf) | ||
| 239 | { | ||
| 240 | if (conf == NULL) | ||
| 241 | return; | ||
| 242 | conf->meth->destroy_data(conf); | ||
| 243 | } | ||
| 244 | |||
| 245 | int NCONF_load(CONF *conf, const char *file, long *eline) | ||
| 246 | { | ||
| 247 | int ret; | ||
| 248 | BIO *in=NULL; | ||
| 249 | |||
| 250 | #ifdef VMS | ||
| 251 | in=BIO_new_file(file, "r"); | ||
| 252 | #else | ||
| 253 | in=BIO_new_file(file, "rb"); | ||
| 254 | #endif | ||
| 255 | if (in == NULL) | ||
| 256 | { | ||
| 257 | CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB); | ||
| 258 | return 0; | ||
| 259 | } | ||
| 260 | |||
| 261 | ret = NCONF_load_bio(conf, in, eline); | ||
| 262 | BIO_free(in); | ||
| 263 | |||
| 264 | return ret; | ||
| 265 | } | ||
| 266 | |||
| 267 | #ifndef NO_FP_API | ||
| 268 | int NCONF_load_fp(CONF *conf, FILE *fp,long *eline) | ||
| 269 | { | ||
| 270 | BIO *btmp; | ||
| 271 | int ret; | ||
| 272 | if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) | ||
| 273 | { | ||
| 274 | CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB); | ||
| 275 | return 0; | ||
| 276 | } | ||
| 277 | ret = NCONF_load_bio(conf, btmp, eline); | ||
| 278 | BIO_free(btmp); | ||
| 279 | return ret; | ||
| 280 | } | ||
| 281 | #endif | ||
| 282 | |||
| 283 | int NCONF_load_bio(CONF *conf, BIO *bp,long *eline) | ||
| 284 | { | ||
| 285 | if (conf == NULL) | ||
| 286 | { | ||
| 287 | CONFerr(CONF_F_NCONF_LOAD_BIO,CONF_R_NO_CONF); | ||
| 288 | return 0; | ||
| 289 | } | ||
| 290 | |||
| 291 | return conf->meth->load(conf, bp, eline); | ||
| 292 | } | ||
| 293 | |||
| 294 | STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section) | ||
| 295 | { | ||
| 296 | if (conf == NULL) | ||
| 297 | { | ||
| 298 | CONFerr(CONF_F_NCONF_GET_SECTION,CONF_R_NO_CONF); | ||
| 299 | return NULL; | ||
| 300 | } | ||
| 301 | |||
| 302 | return _CONF_get_section_values(conf, section); | ||
| 303 | } | ||
| 304 | |||
| 305 | char *NCONF_get_string(CONF *conf,char *group,char *name) | ||
| 306 | { | ||
| 307 | if (conf == NULL) | ||
| 308 | { | ||
| 309 | CONFerr(CONF_F_NCONF_GET_STRING,CONF_R_NO_CONF); | ||
| 310 | return NULL; | ||
| 311 | } | ||
| 312 | |||
| 313 | return _CONF_get_string(conf, group, name); | ||
| 314 | } | ||
| 315 | |||
| 316 | long NCONF_get_number(CONF *conf,char *group,char *name) | ||
| 317 | { | ||
| 318 | if (conf == NULL) | ||
| 319 | { | ||
| 320 | CONFerr(CONF_F_NCONF_GET_NUMBER,CONF_R_NO_CONF); | ||
| 321 | return 0; | ||
| 322 | } | ||
| 323 | |||
| 324 | return _CONF_get_number(conf, group, name); | ||
| 325 | } | ||
| 326 | |||
| 327 | #ifndef NO_FP_API | ||
| 328 | int NCONF_dump_fp(CONF *conf, FILE *out) | ||
| 329 | { | ||
| 330 | BIO *btmp; | ||
| 331 | int ret; | ||
| 332 | if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) { | ||
| 333 | CONFerr(CONF_F_NCONF_DUMP_FP,ERR_R_BUF_LIB); | ||
| 334 | return 0; | ||
| 335 | } | ||
| 336 | ret = NCONF_dump_bio(conf, btmp); | ||
| 337 | BIO_free(btmp); | ||
| 338 | return ret; | ||
| 339 | } | ||
| 340 | #endif | ||
| 341 | |||
| 342 | int NCONF_dump_bio(CONF *conf, BIO *out) | ||
| 343 | { | ||
| 344 | if (conf == NULL) | ||
| 345 | { | ||
| 346 | CONFerr(CONF_F_NCONF_DUMP_BIO,CONF_R_NO_CONF); | ||
| 347 | return 0; | ||
| 348 | } | ||
| 349 | |||
| 350 | return conf->meth->dump(conf, out); | ||
| 351 | } | ||
| 352 | |||
diff --git a/src/lib/libcrypto/conf/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 | |||
| 70 | void 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 | |||
| 77 | struct 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 | |||
| 98 | struct conf_imodule_st | ||
| 99 | { | ||
| 100 | CONF_MODULE *pmod; | ||
| 101 | char *name; | ||
| 102 | char *value; | ||
| 103 | unsigned long flags; | ||
| 104 | void *usr_data; | ||
| 105 | }; | ||
| 106 | |||
| 107 | static STACK_OF(CONF_MODULE) *supported_modules = NULL; | ||
| 108 | static STACK_OF(CONF_IMODULE) *initialized_modules = NULL; | ||
| 109 | |||
| 110 | static void module_free(CONF_MODULE *md); | ||
| 111 | static void module_finish(CONF_IMODULE *imod); | ||
| 112 | static int module_run(const CONF *cnf, char *name, char *value, | ||
| 113 | unsigned long flags); | ||
| 114 | static CONF_MODULE *module_add(DSO *dso, const char *name, | ||
| 115 | conf_init_func *ifunc, conf_finish_func *ffunc); | ||
| 116 | static CONF_MODULE *module_find(char *name); | ||
| 117 | static int module_init(CONF_MODULE *pmod, char *name, char *value, | ||
| 118 | const CONF *cnf); | ||
| 119 | static 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 | |||
| 124 | int 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 | |||
| 165 | int 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 | |||
| 205 | static 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 */ | ||
| 244 | static 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 */ | ||
| 290 | static 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 | |||
| 322 | static 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 */ | ||
| 346 | static 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 | |||
| 421 | void 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 */ | ||
| 445 | static 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 | |||
| 455 | void 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 | |||
| 469 | static 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 | |||
| 481 | int 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 | |||
| 490 | void CONF_modules_free(void) | ||
| 491 | { | ||
| 492 | CONF_modules_finish(); | ||
| 493 | CONF_modules_unload(1); | ||
| 494 | } | ||
| 495 | |||
| 496 | /* Utility functions */ | ||
| 497 | |||
| 498 | const char *CONF_imodule_get_name(const CONF_IMODULE *md) | ||
| 499 | { | ||
| 500 | return md->name; | ||
| 501 | } | ||
| 502 | |||
| 503 | const char *CONF_imodule_get_value(const CONF_IMODULE *md) | ||
| 504 | { | ||
| 505 | return md->value; | ||
| 506 | } | ||
| 507 | |||
| 508 | void *CONF_imodule_get_usr_data(const CONF_IMODULE *md) | ||
| 509 | { | ||
| 510 | return md->usr_data; | ||
| 511 | } | ||
| 512 | |||
| 513 | void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data) | ||
| 514 | { | ||
| 515 | md->usr_data = usr_data; | ||
| 516 | } | ||
| 517 | |||
| 518 | CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md) | ||
| 519 | { | ||
| 520 | return md->pmod; | ||
| 521 | } | ||
| 522 | |||
| 523 | unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md) | ||
| 524 | { | ||
| 525 | return md->flags; | ||
| 526 | } | ||
| 527 | |||
| 528 | void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags) | ||
| 529 | { | ||
| 530 | md->flags = flags; | ||
| 531 | } | ||
| 532 | |||
| 533 | void *CONF_module_get_usr_data(CONF_MODULE *pmod) | ||
| 534 | { | ||
| 535 | return pmod->usr_data; | ||
| 536 | } | ||
| 537 | |||
| 538 | void 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 | |||
| 545 | char *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 | |||
| 579 | int 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 | |||
| 73 | static int openssl_configured = 0; | ||
| 74 | |||
| 75 | void 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 | |||
| 104 | void OPENSSL_no_config() | ||
| 105 | { | ||
| 106 | openssl_configured = 1; | ||
| 107 | } | ||
