Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 1 | /* crypto/conf/conf.c */ |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 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 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 59 | /* Part of the code in here was originally in conf.c, which is now removed */ |
| 60 | |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 61 | #include <stdio.h> |
Andy Polyakov | 9887c71 | 2000-06-06 15:21:12 +0000 | [diff] [blame] | 62 | #include <string.h> |
Andy Polyakov | 25a66ee | 2005-05-17 00:01:48 +0000 | [diff] [blame] | 63 | #include "cryptlib.h" |
Bodo Möller | ec57782 | 1999-04-23 22:13:45 +0000 | [diff] [blame] | 64 | #include <openssl/stack.h> |
| 65 | #include <openssl/lhash.h> |
| 66 | #include <openssl/conf.h> |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 67 | #include <openssl/conf_api.h> |
| 68 | #include "conf_def.h" |
Bodo Möller | ec57782 | 1999-04-23 22:13:45 +0000 | [diff] [blame] | 69 | #include <openssl/buffer.h> |
| 70 | #include <openssl/err.h> |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 71 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 72 | static char *eat_ws(CONF *conf, char *p); |
| 73 | static char *eat_alpha_numeric(CONF *conf, char *p); |
| 74 | static void clear_comments(CONF *conf, char *p); |
| 75 | static int str_copy(CONF *conf,char *section,char **to, char *from); |
| 76 | static char *scan_quote(CONF *conf, char *p); |
| 77 | static char *scan_dquote(CONF *conf, char *p); |
Andy Polyakov | 9887c71 | 2000-06-06 15:21:12 +0000 | [diff] [blame] | 78 | #define scan_esc(conf,p) (((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2))) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 79 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 80 | static CONF *def_create(CONF_METHOD *meth); |
| 81 | static int def_init_default(CONF *conf); |
| 82 | static int def_init_WIN32(CONF *conf); |
| 83 | static int def_destroy(CONF *conf); |
| 84 | static int def_destroy_data(CONF *conf); |
Richard Levitte | befb3e7 | 2000-10-19 08:26:32 +0000 | [diff] [blame] | 85 | static int def_load(CONF *conf, const char *name, long *eline); |
| 86 | static int def_load_bio(CONF *conf, BIO *bp, long *eline); |
Ben Laurie | 9dd5ae6 | 2002-01-18 16:51:05 +0000 | [diff] [blame] | 87 | static int def_dump(const CONF *conf, BIO *bp); |
| 88 | static int def_is_number(const CONF *conf, char c); |
| 89 | static int def_to_int(const CONF *conf, char c); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 90 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 91 | const char *CONF_def_version="CONF_def" OPENSSL_VERSION_PTEXT; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 92 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 93 | static CONF_METHOD default_method = { |
| 94 | "OpenSSL default", |
| 95 | def_create, |
| 96 | def_init_default, |
| 97 | def_destroy, |
| 98 | def_destroy_data, |
Richard Levitte | befb3e7 | 2000-10-19 08:26:32 +0000 | [diff] [blame] | 99 | def_load_bio, |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 100 | def_dump, |
| 101 | def_is_number, |
Richard Levitte | c8cda40 | 2000-10-19 08:29:27 +0000 | [diff] [blame] | 102 | def_to_int, |
| 103 | def_load |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 104 | }; |
Dr. Stephen Henson | 8623f69 | 1999-06-20 17:36:11 +0000 | [diff] [blame] | 105 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 106 | static CONF_METHOD WIN32_method = { |
| 107 | "WIN32", |
| 108 | def_create, |
| 109 | def_init_WIN32, |
| 110 | def_destroy, |
| 111 | def_destroy_data, |
Richard Levitte | befb3e7 | 2000-10-19 08:26:32 +0000 | [diff] [blame] | 112 | def_load_bio, |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 113 | def_dump, |
| 114 | def_is_number, |
Richard Levitte | c8cda40 | 2000-10-19 08:29:27 +0000 | [diff] [blame] | 115 | def_to_int, |
| 116 | def_load |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | CONF_METHOD *NCONF_default() |
Dr. Stephen Henson | 8623f69 | 1999-06-20 17:36:11 +0000 | [diff] [blame] | 120 | { |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 121 | return &default_method; |
Dr. Stephen Henson | 8623f69 | 1999-06-20 17:36:11 +0000 | [diff] [blame] | 122 | } |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 123 | CONF_METHOD *NCONF_WIN32() |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 124 | { |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 125 | return &WIN32_method; |
| 126 | } |
| 127 | |
| 128 | static CONF *def_create(CONF_METHOD *meth) |
| 129 | { |
| 130 | CONF *ret; |
| 131 | |
Richard Levitte | 26a3a48 | 2000-06-01 22:19:21 +0000 | [diff] [blame] | 132 | ret = (CONF *)OPENSSL_malloc(sizeof(CONF) + sizeof(unsigned short *)); |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 133 | if (ret) |
| 134 | if (meth->init(ret) == 0) |
| 135 | { |
Richard Levitte | 26a3a48 | 2000-06-01 22:19:21 +0000 | [diff] [blame] | 136 | OPENSSL_free(ret); |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 137 | ret = NULL; |
| 138 | } |
| 139 | return ret; |
| 140 | } |
| 141 | |
| 142 | static int def_init_default(CONF *conf) |
| 143 | { |
| 144 | if (conf == NULL) |
| 145 | return 0; |
| 146 | |
| 147 | conf->meth = &default_method; |
| 148 | conf->meth_data = (void *)CONF_type_default; |
| 149 | conf->data = NULL; |
| 150 | |
| 151 | return 1; |
| 152 | } |
| 153 | |
| 154 | static int def_init_WIN32(CONF *conf) |
| 155 | { |
| 156 | if (conf == NULL) |
| 157 | return 0; |
| 158 | |
| 159 | conf->meth = &WIN32_method; |
| 160 | conf->meth_data = (void *)CONF_type_win32; |
| 161 | conf->data = NULL; |
| 162 | |
| 163 | return 1; |
| 164 | } |
| 165 | |
| 166 | static int def_destroy(CONF *conf) |
| 167 | { |
| 168 | if (def_destroy_data(conf)) |
| 169 | { |
Richard Levitte | 26a3a48 | 2000-06-01 22:19:21 +0000 | [diff] [blame] | 170 | OPENSSL_free(conf); |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 171 | return 1; |
| 172 | } |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | static int def_destroy_data(CONF *conf) |
| 177 | { |
| 178 | if (conf == NULL) |
| 179 | return 0; |
| 180 | _CONF_free_data(conf); |
| 181 | return 1; |
| 182 | } |
| 183 | |
Richard Levitte | befb3e7 | 2000-10-19 08:26:32 +0000 | [diff] [blame] | 184 | static int def_load(CONF *conf, const char *name, long *line) |
| 185 | { |
| 186 | int ret; |
| 187 | BIO *in=NULL; |
| 188 | |
Richard Levitte | bc36ee6 | 2001-02-20 08:13:47 +0000 | [diff] [blame] | 189 | #ifdef OPENSSL_SYS_VMS |
Richard Levitte | befb3e7 | 2000-10-19 08:26:32 +0000 | [diff] [blame] | 190 | in=BIO_new_file(name, "r"); |
| 191 | #else |
| 192 | in=BIO_new_file(name, "rb"); |
| 193 | #endif |
| 194 | if (in == NULL) |
| 195 | { |
Bodo Möller | a14e2d9 | 2002-01-24 16:16:43 +0000 | [diff] [blame] | 196 | if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE) |
Bodo Möller | aa4ce73 | 2005-04-26 18:53:22 +0000 | [diff] [blame] | 197 | CONFerr(CONF_F_DEF_LOAD,CONF_R_NO_SUCH_FILE); |
Ben Laurie | 0fc5cf0 | 2002-01-22 22:29:58 +0000 | [diff] [blame] | 198 | else |
Bodo Möller | aa4ce73 | 2005-04-26 18:53:22 +0000 | [diff] [blame] | 199 | CONFerr(CONF_F_DEF_LOAD,ERR_R_SYS_LIB); |
Richard Levitte | befb3e7 | 2000-10-19 08:26:32 +0000 | [diff] [blame] | 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | ret = def_load_bio(conf, in, line); |
| 204 | BIO_free(in); |
| 205 | |
| 206 | return ret; |
| 207 | } |
| 208 | |
| 209 | static int def_load_bio(CONF *conf, BIO *in, long *line) |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 210 | { |
Richard Levitte | 6a89a25 | 2002-10-09 13:40:48 +0000 | [diff] [blame] | 211 | /* The macro BUFSIZE conflicts with a system macro in VxWorks */ |
| 212 | #define CONFBUFSIZE 512 |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 213 | int bufnum=0,i,ii; |
| 214 | BUF_MEM *buff=NULL; |
| 215 | char *s,*p,*end; |
Ralf S. Engelschall | dfeab06 | 1998-12-21 11:00:56 +0000 | [diff] [blame] | 216 | int again,n; |
| 217 | long eline=0; |
Lutz Jänicke | c046fff | 2002-07-30 13:04:04 +0000 | [diff] [blame] | 218 | char btmp[DECIMAL_SIZE(eline)+1]; |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 219 | CONF_VALUE *v=NULL,*tv; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 220 | CONF_VALUE *sv=NULL; |
| 221 | char *section=NULL,*buf; |
Dr. Stephen Henson | ba404b5 | 1999-06-20 22:18:16 +0000 | [diff] [blame] | 222 | STACK_OF(CONF_VALUE) *section_sk=NULL,*ts; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 223 | char *start,*psection,*pname; |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 224 | void *h = (void *)(conf->data); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 225 | |
| 226 | if ((buff=BUF_MEM_new()) == NULL) |
| 227 | { |
Bodo Möller | aa4ce73 | 2005-04-26 18:53:22 +0000 | [diff] [blame] | 228 | CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_BUF_LIB); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 229 | goto err; |
| 230 | } |
| 231 | |
Richard Levitte | 26a3a48 | 2000-06-01 22:19:21 +0000 | [diff] [blame] | 232 | section=(char *)OPENSSL_malloc(10); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 233 | if (section == NULL) |
| 234 | { |
Bodo Möller | aa4ce73 | 2005-04-26 18:53:22 +0000 | [diff] [blame] | 235 | CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_MALLOC_FAILURE); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 236 | goto err; |
| 237 | } |
Richard Levitte | d420ac2 | 2003-12-27 14:40:17 +0000 | [diff] [blame] | 238 | BUF_strlcpy(section,"default",10); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 239 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 240 | if (_CONF_new_data(conf) == 0) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 241 | { |
Bodo Möller | aa4ce73 | 2005-04-26 18:53:22 +0000 | [diff] [blame] | 242 | CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_MALLOC_FAILURE); |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 243 | goto err; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 244 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 245 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 246 | sv=_CONF_new_section(conf,section); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 247 | if (sv == NULL) |
| 248 | { |
Bodo Möller | aa4ce73 | 2005-04-26 18:53:22 +0000 | [diff] [blame] | 249 | CONFerr(CONF_F_DEF_LOAD_BIO, |
Dr. Stephen Henson | 8623f69 | 1999-06-20 17:36:11 +0000 | [diff] [blame] | 250 | CONF_R_UNABLE_TO_CREATE_NEW_SECTION); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 251 | goto err; |
| 252 | } |
Dr. Stephen Henson | ba404b5 | 1999-06-20 22:18:16 +0000 | [diff] [blame] | 253 | section_sk=(STACK_OF(CONF_VALUE) *)sv->value; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 254 | |
| 255 | bufnum=0; |
Richard Levitte | 8341179 | 2002-11-14 06:51:18 +0000 | [diff] [blame] | 256 | again=0; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 257 | for (;;) |
| 258 | { |
Richard Levitte | 6a89a25 | 2002-10-09 13:40:48 +0000 | [diff] [blame] | 259 | if (!BUF_MEM_grow(buff,bufnum+CONFBUFSIZE)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 260 | { |
Bodo Möller | aa4ce73 | 2005-04-26 18:53:22 +0000 | [diff] [blame] | 261 | CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_BUF_LIB); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 262 | goto err; |
| 263 | } |
| 264 | p= &(buff->data[bufnum]); |
| 265 | *p='\0'; |
Richard Levitte | 6a89a25 | 2002-10-09 13:40:48 +0000 | [diff] [blame] | 266 | BIO_gets(in, p, CONFBUFSIZE-1); |
| 267 | p[CONFBUFSIZE-1]='\0'; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 268 | ii=i=strlen(p); |
Richard Levitte | 8341179 | 2002-11-14 06:51:18 +0000 | [diff] [blame] | 269 | if (i == 0 && !again) break; |
| 270 | again=0; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 271 | while (i > 0) |
| 272 | { |
| 273 | if ((p[i-1] != '\r') && (p[i-1] != '\n')) |
| 274 | break; |
| 275 | else |
| 276 | i--; |
| 277 | } |
| 278 | /* we removed some trailing stuff so there is a new |
| 279 | * line on the end. */ |
Richard Levitte | 8341179 | 2002-11-14 06:51:18 +0000 | [diff] [blame] | 280 | if (ii && i == ii) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 281 | again=1; /* long line */ |
| 282 | else |
| 283 | { |
| 284 | p[i]='\0'; |
| 285 | eline++; /* another input line */ |
| 286 | } |
| 287 | |
| 288 | /* we now have a line with trailing \r\n removed */ |
| 289 | |
| 290 | /* i is the number of bytes */ |
| 291 | bufnum+=i; |
| 292 | |
| 293 | v=NULL; |
| 294 | /* check for line continuation */ |
| 295 | if (bufnum >= 1) |
| 296 | { |
| 297 | /* If we have bytes and the last char '\\' and |
| 298 | * second last char is not '\\' */ |
| 299 | p= &(buff->data[bufnum-1]); |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 300 | if (IS_ESC(conf,p[0]) && |
| 301 | ((bufnum <= 1) || !IS_ESC(conf,p[-1]))) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 302 | { |
| 303 | bufnum--; |
| 304 | again=1; |
| 305 | } |
| 306 | } |
| 307 | if (again) continue; |
| 308 | bufnum=0; |
| 309 | buf=buff->data; |
| 310 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 311 | clear_comments(conf, buf); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 312 | n=strlen(buf); |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 313 | s=eat_ws(conf, buf); |
| 314 | if (IS_EOF(conf,*s)) continue; /* blank line */ |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 315 | if (*s == '[') |
| 316 | { |
Ralf S. Engelschall | dfeab06 | 1998-12-21 11:00:56 +0000 | [diff] [blame] | 317 | char *ss; |
| 318 | |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 319 | s++; |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 320 | start=eat_ws(conf, s); |
Ralf S. Engelschall | dfeab06 | 1998-12-21 11:00:56 +0000 | [diff] [blame] | 321 | ss=start; |
| 322 | again: |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 323 | end=eat_alpha_numeric(conf, ss); |
| 324 | p=eat_ws(conf, end); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 325 | if (*p != ']') |
| 326 | { |
Ralf S. Engelschall | dfeab06 | 1998-12-21 11:00:56 +0000 | [diff] [blame] | 327 | if (*p != '\0') |
| 328 | { |
| 329 | ss=p; |
| 330 | goto again; |
| 331 | } |
Bodo Möller | aa4ce73 | 2005-04-26 18:53:22 +0000 | [diff] [blame] | 332 | CONFerr(CONF_F_DEF_LOAD_BIO, |
Dr. Stephen Henson | 8623f69 | 1999-06-20 17:36:11 +0000 | [diff] [blame] | 333 | CONF_R_MISSING_CLOSE_SQUARE_BRACKET); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 334 | goto err; |
| 335 | } |
| 336 | *end='\0'; |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 337 | if (!str_copy(conf,NULL,§ion,start)) goto err; |
| 338 | if ((sv=_CONF_get_section(conf,section)) == NULL) |
| 339 | sv=_CONF_new_section(conf,section); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 340 | if (sv == NULL) |
| 341 | { |
Bodo Möller | aa4ce73 | 2005-04-26 18:53:22 +0000 | [diff] [blame] | 342 | CONFerr(CONF_F_DEF_LOAD_BIO, |
Dr. Stephen Henson | 8623f69 | 1999-06-20 17:36:11 +0000 | [diff] [blame] | 343 | CONF_R_UNABLE_TO_CREATE_NEW_SECTION); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 344 | goto err; |
| 345 | } |
Dr. Stephen Henson | ba404b5 | 1999-06-20 22:18:16 +0000 | [diff] [blame] | 346 | section_sk=(STACK_OF(CONF_VALUE) *)sv->value; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 347 | continue; |
| 348 | } |
| 349 | else |
| 350 | { |
| 351 | pname=s; |
| 352 | psection=NULL; |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 353 | end=eat_alpha_numeric(conf, s); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 354 | if ((end[0] == ':') && (end[1] == ':')) |
| 355 | { |
| 356 | *end='\0'; |
| 357 | end+=2; |
| 358 | psection=pname; |
| 359 | pname=end; |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 360 | end=eat_alpha_numeric(conf, end); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 361 | } |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 362 | p=eat_ws(conf, end); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 363 | if (*p != '=') |
| 364 | { |
Bodo Möller | aa4ce73 | 2005-04-26 18:53:22 +0000 | [diff] [blame] | 365 | CONFerr(CONF_F_DEF_LOAD_BIO, |
Dr. Stephen Henson | 8623f69 | 1999-06-20 17:36:11 +0000 | [diff] [blame] | 366 | CONF_R_MISSING_EQUAL_SIGN); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 367 | goto err; |
| 368 | } |
| 369 | *end='\0'; |
| 370 | p++; |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 371 | start=eat_ws(conf, p); |
| 372 | while (!IS_EOF(conf,*p)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 373 | p++; |
| 374 | p--; |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 375 | while ((p != start) && (IS_WS(conf,*p))) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 376 | p--; |
| 377 | p++; |
| 378 | *p='\0'; |
| 379 | |
Richard Levitte | 26a3a48 | 2000-06-01 22:19:21 +0000 | [diff] [blame] | 380 | if (!(v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE)))) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 381 | { |
Bodo Möller | aa4ce73 | 2005-04-26 18:53:22 +0000 | [diff] [blame] | 382 | CONFerr(CONF_F_DEF_LOAD_BIO, |
Dr. Stephen Henson | 8623f69 | 1999-06-20 17:36:11 +0000 | [diff] [blame] | 383 | ERR_R_MALLOC_FAILURE); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 384 | goto err; |
| 385 | } |
| 386 | if (psection == NULL) psection=section; |
Richard Levitte | 26a3a48 | 2000-06-01 22:19:21 +0000 | [diff] [blame] | 387 | v->name=(char *)OPENSSL_malloc(strlen(pname)+1); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 388 | v->value=NULL; |
| 389 | if (v->name == NULL) |
| 390 | { |
Bodo Möller | aa4ce73 | 2005-04-26 18:53:22 +0000 | [diff] [blame] | 391 | CONFerr(CONF_F_DEF_LOAD_BIO, |
Dr. Stephen Henson | 8623f69 | 1999-06-20 17:36:11 +0000 | [diff] [blame] | 392 | ERR_R_MALLOC_FAILURE); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 393 | goto err; |
| 394 | } |
Richard Levitte | d420ac2 | 2003-12-27 14:40:17 +0000 | [diff] [blame] | 395 | BUF_strlcpy(v->name,pname,strlen(pname)+1); |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 396 | if (!str_copy(conf,psection,&(v->value),start)) goto err; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 397 | |
| 398 | if (strcmp(psection,section) != 0) |
| 399 | { |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 400 | if ((tv=_CONF_get_section(conf,psection)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 401 | == NULL) |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 402 | tv=_CONF_new_section(conf,psection); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 403 | if (tv == NULL) |
| 404 | { |
Bodo Möller | aa4ce73 | 2005-04-26 18:53:22 +0000 | [diff] [blame] | 405 | CONFerr(CONF_F_DEF_LOAD_BIO, |
Dr. Stephen Henson | ba404b5 | 1999-06-20 22:18:16 +0000 | [diff] [blame] | 406 | CONF_R_UNABLE_TO_CREATE_NEW_SECTION); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 407 | goto err; |
| 408 | } |
Dr. Stephen Henson | ba404b5 | 1999-06-20 22:18:16 +0000 | [diff] [blame] | 409 | ts=(STACK_OF(CONF_VALUE) *)tv->value; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 410 | } |
| 411 | else |
| 412 | { |
| 413 | tv=sv; |
| 414 | ts=section_sk; |
| 415 | } |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 416 | #if 1 |
| 417 | if (_CONF_add_string(conf, tv, v) == 0) |
| 418 | { |
Bodo Möller | aa4ce73 | 2005-04-26 18:53:22 +0000 | [diff] [blame] | 419 | CONFerr(CONF_F_DEF_LOAD_BIO, |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 420 | ERR_R_MALLOC_FAILURE); |
| 421 | goto err; |
| 422 | } |
| 423 | #else |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 424 | v->section=tv->section; |
Dr. Stephen Henson | ba404b5 | 1999-06-20 22:18:16 +0000 | [diff] [blame] | 425 | if (!sk_CONF_VALUE_push(ts,v)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 426 | { |
Bodo Möller | aa4ce73 | 2005-04-26 18:53:22 +0000 | [diff] [blame] | 427 | CONFerr(CONF_F_DEF_LOAD_BIO, |
Dr. Stephen Henson | 8623f69 | 1999-06-20 17:36:11 +0000 | [diff] [blame] | 428 | ERR_R_MALLOC_FAILURE); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 429 | goto err; |
| 430 | } |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 431 | vv=(CONF_VALUE *)lh_insert(conf->data,v); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 432 | if (vv != NULL) |
| 433 | { |
Dr. Stephen Henson | ba404b5 | 1999-06-20 22:18:16 +0000 | [diff] [blame] | 434 | sk_CONF_VALUE_delete_ptr(ts,vv); |
Richard Levitte | 26a3a48 | 2000-06-01 22:19:21 +0000 | [diff] [blame] | 435 | OPENSSL_free(vv->name); |
| 436 | OPENSSL_free(vv->value); |
| 437 | OPENSSL_free(vv); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 438 | } |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 439 | #endif |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 440 | v=NULL; |
| 441 | } |
| 442 | } |
| 443 | if (buff != NULL) BUF_MEM_free(buff); |
Richard Levitte | 26a3a48 | 2000-06-01 22:19:21 +0000 | [diff] [blame] | 444 | if (section != NULL) OPENSSL_free(section); |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 445 | return(1); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 446 | err: |
| 447 | if (buff != NULL) BUF_MEM_free(buff); |
Richard Levitte | 26a3a48 | 2000-06-01 22:19:21 +0000 | [diff] [blame] | 448 | if (section != NULL) OPENSSL_free(section); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 449 | if (line != NULL) *line=eline; |
Richard Levitte | d420ac2 | 2003-12-27 14:40:17 +0000 | [diff] [blame] | 450 | BIO_snprintf(btmp,sizeof btmp,"%ld",eline); |
Ralf S. Engelschall | dfeab06 | 1998-12-21 11:00:56 +0000 | [diff] [blame] | 451 | ERR_add_error_data(2,"line ",btmp); |
Ben Laurie | bdae099 | 2002-01-18 11:32:30 +0000 | [diff] [blame] | 452 | if ((h != conf->data) && (conf->data != NULL)) |
| 453 | { |
| 454 | CONF_free(conf->data); |
| 455 | conf->data=NULL; |
| 456 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 457 | if (v != NULL) |
| 458 | { |
Richard Levitte | 26a3a48 | 2000-06-01 22:19:21 +0000 | [diff] [blame] | 459 | if (v->name != NULL) OPENSSL_free(v->name); |
| 460 | if (v->value != NULL) OPENSSL_free(v->value); |
| 461 | if (v != NULL) OPENSSL_free(v); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 462 | } |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 463 | return(0); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 464 | } |
Dr. Stephen Henson | 8623f69 | 1999-06-20 17:36:11 +0000 | [diff] [blame] | 465 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 466 | static void clear_comments(CONF *conf, char *p) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 467 | { |
| 468 | char *to; |
| 469 | |
| 470 | to=p; |
| 471 | for (;;) |
| 472 | { |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 473 | if (IS_FCOMMENT(conf,*p)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 474 | { |
| 475 | *p='\0'; |
| 476 | return; |
| 477 | } |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 478 | if (!IS_WS(conf,*p)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 479 | { |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 480 | break; |
| 481 | } |
| 482 | p++; |
| 483 | } |
| 484 | |
| 485 | for (;;) |
| 486 | { |
| 487 | if (IS_COMMENT(conf,*p)) |
| 488 | { |
| 489 | *p='\0'; |
| 490 | return; |
| 491 | } |
| 492 | if (IS_DQUOTE(conf,*p)) |
| 493 | { |
| 494 | p=scan_dquote(conf, p); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 495 | continue; |
| 496 | } |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 497 | if (IS_QUOTE(conf,*p)) |
| 498 | { |
| 499 | p=scan_quote(conf, p); |
| 500 | continue; |
| 501 | } |
| 502 | if (IS_ESC(conf,*p)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 503 | { |
Andy Polyakov | 9887c71 | 2000-06-06 15:21:12 +0000 | [diff] [blame] | 504 | p=scan_esc(conf,p); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 505 | continue; |
| 506 | } |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 507 | if (IS_EOF(conf,*p)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 508 | return; |
| 509 | else |
| 510 | p++; |
| 511 | } |
| 512 | } |
| 513 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 514 | static int str_copy(CONF *conf, char *section, char **pto, char *from) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 515 | { |
| 516 | int q,r,rr=0,to=0,len=0; |
| 517 | char *s,*e,*rp,*p,*rrp,*np,*cp,v; |
| 518 | BUF_MEM *buf; |
| 519 | |
| 520 | if ((buf=BUF_MEM_new()) == NULL) return(0); |
| 521 | |
| 522 | len=strlen(from)+1; |
| 523 | if (!BUF_MEM_grow(buf,len)) goto err; |
| 524 | |
| 525 | for (;;) |
| 526 | { |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 527 | if (IS_QUOTE(conf,*from)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 528 | { |
| 529 | q= *from; |
| 530 | from++; |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 531 | while (!IS_EOF(conf,*from) && (*from != q)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 532 | { |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 533 | if (IS_ESC(conf,*from)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 534 | { |
| 535 | from++; |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 536 | if (IS_EOF(conf,*from)) break; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 537 | } |
| 538 | buf->data[to++]= *(from++); |
| 539 | } |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 540 | if (*from == q) from++; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 541 | } |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 542 | else if (IS_DQUOTE(conf,*from)) |
| 543 | { |
| 544 | q= *from; |
| 545 | from++; |
| 546 | while (!IS_EOF(conf,*from)) |
| 547 | { |
| 548 | if (*from == q) |
| 549 | { |
| 550 | if (*(from+1) == q) |
| 551 | { |
| 552 | from++; |
| 553 | } |
| 554 | else |
| 555 | { |
| 556 | break; |
| 557 | } |
| 558 | } |
| 559 | buf->data[to++]= *(from++); |
| 560 | } |
| 561 | if (*from == q) from++; |
| 562 | } |
| 563 | else if (IS_ESC(conf,*from)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 564 | { |
| 565 | from++; |
| 566 | v= *(from++); |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 567 | if (IS_EOF(conf,v)) break; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 568 | else if (v == 'r') v='\r'; |
| 569 | else if (v == 'n') v='\n'; |
| 570 | else if (v == 'b') v='\b'; |
| 571 | else if (v == 't') v='\t'; |
| 572 | buf->data[to++]= v; |
| 573 | } |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 574 | else if (IS_EOF(conf,*from)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 575 | break; |
| 576 | else if (*from == '$') |
| 577 | { |
| 578 | /* try to expand it */ |
| 579 | rrp=NULL; |
| 580 | s= &(from[1]); |
| 581 | if (*s == '{') |
| 582 | q='}'; |
| 583 | else if (*s == '(') |
| 584 | q=')'; |
| 585 | else q=0; |
| 586 | |
| 587 | if (q) s++; |
| 588 | cp=section; |
| 589 | e=np=s; |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 590 | while (IS_ALPHA_NUMERIC(conf,*e)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 591 | e++; |
| 592 | if ((e[0] == ':') && (e[1] == ':')) |
| 593 | { |
| 594 | cp=np; |
| 595 | rrp=e; |
| 596 | rr= *e; |
| 597 | *rrp='\0'; |
| 598 | e+=2; |
| 599 | np=e; |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 600 | while (IS_ALPHA_NUMERIC(conf,*e)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 601 | e++; |
| 602 | } |
| 603 | r= *e; |
| 604 | *e='\0'; |
| 605 | rp=e; |
| 606 | if (q) |
| 607 | { |
| 608 | if (r != q) |
| 609 | { |
| 610 | CONFerr(CONF_F_STR_COPY,CONF_R_NO_CLOSE_BRACE); |
| 611 | goto err; |
| 612 | } |
| 613 | e++; |
| 614 | } |
| 615 | /* So at this point we have |
| 616 | * ns which is the start of the name string which is |
| 617 | * '\0' terminated. |
| 618 | * cs which is the start of the section string which is |
| 619 | * '\0' terminated. |
| 620 | * e is the 'next point after'. |
| 621 | * r and s are the chars replaced by the '\0' |
| 622 | * rp and sp is where 'r' and 's' came from. |
| 623 | */ |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 624 | p=_CONF_get_string(conf,cp,np); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 625 | if (rrp != NULL) *rrp=rr; |
| 626 | *rp=r; |
| 627 | if (p == NULL) |
| 628 | { |
| 629 | CONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE); |
| 630 | goto err; |
| 631 | } |
Geoff Thorpe | ec2179c | 2003-11-21 21:42:35 +0000 | [diff] [blame] | 632 | BUF_MEM_grow_clean(buf,(strlen(p)+buf->length-(e-from))); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 633 | while (*p) |
| 634 | buf->data[to++]= *(p++); |
Richard Levitte | 430d7af | 2004-05-06 09:33:22 +0000 | [diff] [blame] | 635 | |
| 636 | /* Since we change the pointer 'from', we also have |
| 637 | to change the perceived length of the string it |
| 638 | points at. /RL */ |
| 639 | len -= e-from; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 640 | from=e; |
| 641 | } |
| 642 | else |
| 643 | buf->data[to++]= *(from++); |
| 644 | } |
| 645 | buf->data[to]='\0'; |
Richard Levitte | 26a3a48 | 2000-06-01 22:19:21 +0000 | [diff] [blame] | 646 | if (*pto != NULL) OPENSSL_free(*pto); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 647 | *pto=buf->data; |
Richard Levitte | 26a3a48 | 2000-06-01 22:19:21 +0000 | [diff] [blame] | 648 | OPENSSL_free(buf); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 649 | return(1); |
| 650 | err: |
| 651 | if (buf != NULL) BUF_MEM_free(buf); |
| 652 | return(0); |
| 653 | } |
| 654 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 655 | static char *eat_ws(CONF *conf, char *p) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 656 | { |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 657 | while (IS_WS(conf,*p) && (!IS_EOF(conf,*p))) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 658 | p++; |
| 659 | return(p); |
| 660 | } |
| 661 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 662 | static char *eat_alpha_numeric(CONF *conf, char *p) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 663 | { |
| 664 | for (;;) |
| 665 | { |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 666 | if (IS_ESC(conf,*p)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 667 | { |
Andy Polyakov | 9887c71 | 2000-06-06 15:21:12 +0000 | [diff] [blame] | 668 | p=scan_esc(conf,p); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 669 | continue; |
| 670 | } |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 671 | if (!IS_ALPHA_NUMERIC_PUNCT(conf,*p)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 672 | return(p); |
| 673 | p++; |
| 674 | } |
| 675 | } |
| 676 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 677 | static char *scan_quote(CONF *conf, char *p) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 678 | { |
| 679 | int q= *p; |
| 680 | |
| 681 | p++; |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 682 | while (!(IS_EOF(conf,*p)) && (*p != q)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 683 | { |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 684 | if (IS_ESC(conf,*p)) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 685 | { |
| 686 | p++; |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 687 | if (IS_EOF(conf,*p)) return(p); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 688 | } |
| 689 | p++; |
| 690 | } |
| 691 | if (*p == q) p++; |
| 692 | return(p); |
| 693 | } |
| 694 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 695 | |
| 696 | static char *scan_dquote(CONF *conf, char *p) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 697 | { |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 698 | int q= *p; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 699 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 700 | p++; |
| 701 | while (!(IS_EOF(conf,*p))) |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 702 | { |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 703 | if (*p == q) |
| 704 | { |
| 705 | if (*(p+1) == q) |
| 706 | { |
| 707 | p++; |
| 708 | } |
| 709 | else |
| 710 | { |
| 711 | break; |
| 712 | } |
| 713 | } |
| 714 | p++; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 715 | } |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 716 | if (*p == q) p++; |
| 717 | return(p); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 718 | } |
Dr. Stephen Henson | ba404b5 | 1999-06-20 22:18:16 +0000 | [diff] [blame] | 719 | |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 720 | static void dump_value(CONF_VALUE *a, BIO *out) |
| 721 | { |
| 722 | if (a->name) |
| 723 | BIO_printf(out, "[%s] %s=%s\n", a->section, a->name, a->value); |
| 724 | else |
| 725 | BIO_printf(out, "[[%s]]\n", a->section); |
| 726 | } |
| 727 | |
Geoff Thorpe | 3c91484 | 2001-01-09 00:24:38 +0000 | [diff] [blame] | 728 | static IMPLEMENT_LHASH_DOALL_ARG_FN(dump_value, CONF_VALUE *, BIO *) |
| 729 | |
Ben Laurie | 9dd5ae6 | 2002-01-18 16:51:05 +0000 | [diff] [blame] | 730 | static int def_dump(const CONF *conf, BIO *out) |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 731 | { |
Geoff Thorpe | 3c91484 | 2001-01-09 00:24:38 +0000 | [diff] [blame] | 732 | lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(dump_value), out); |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 733 | return 1; |
| 734 | } |
| 735 | |
Ben Laurie | 9dd5ae6 | 2002-01-18 16:51:05 +0000 | [diff] [blame] | 736 | static int def_is_number(const CONF *conf, char c) |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 737 | { |
| 738 | return IS_NUMBER(conf,c); |
| 739 | } |
| 740 | |
Ben Laurie | 9dd5ae6 | 2002-01-18 16:51:05 +0000 | [diff] [blame] | 741 | static int def_to_int(const CONF *conf, char c) |
Richard Levitte | d86b691 | 2000-04-09 12:04:35 +0000 | [diff] [blame] | 742 | { |
| 743 | return c - '0'; |
| 744 | } |
| 745 | |