os/ossrv/ssl/libcrypto/src/crypto/conf/conf_def.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* crypto/conf/conf.c */
sl@0
     2
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
sl@0
     3
 * All rights reserved.
sl@0
     4
 *
sl@0
     5
 * This package is an SSL implementation written
sl@0
     6
 * by Eric Young (eay@cryptsoft.com).
sl@0
     7
 * The implementation was written so as to conform with Netscapes SSL.
sl@0
     8
 * 
sl@0
     9
 * This library is free for commercial and non-commercial use as long as
sl@0
    10
 * the following conditions are aheared to.  The following conditions
sl@0
    11
 * apply to all code found in this distribution, be it the RC4, RSA,
sl@0
    12
 * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
sl@0
    13
 * included with this distribution is covered by the same copyright terms
sl@0
    14
 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
sl@0
    15
 * 
sl@0
    16
 * Copyright remains Eric Young's, and as such any Copyright notices in
sl@0
    17
 * the code are not to be removed.
sl@0
    18
 * If this package is used in a product, Eric Young should be given attribution
sl@0
    19
 * as the author of the parts of the library used.
sl@0
    20
 * This can be in the form of a textual message at program startup or
sl@0
    21
 * in documentation (online or textual) provided with the package.
sl@0
    22
 * 
sl@0
    23
 * Redistribution and use in source and binary forms, with or without
sl@0
    24
 * modification, are permitted provided that the following conditions
sl@0
    25
 * are met:
sl@0
    26
 * 1. Redistributions of source code must retain the copyright
sl@0
    27
 *    notice, this list of conditions and the following disclaimer.
sl@0
    28
 * 2. Redistributions in binary form must reproduce the above copyright
sl@0
    29
 *    notice, this list of conditions and the following disclaimer in the
sl@0
    30
 *    documentation and/or other materials provided with the distribution.
sl@0
    31
 * 3. All advertising materials mentioning features or use of this software
sl@0
    32
 *    must display the following acknowledgement:
sl@0
    33
 *    "This product includes cryptographic software written by
sl@0
    34
 *     Eric Young (eay@cryptsoft.com)"
sl@0
    35
 *    The word 'cryptographic' can be left out if the rouines from the library
sl@0
    36
 *    being used are not cryptographic related :-).
sl@0
    37
 * 4. If you include any Windows specific code (or a derivative thereof) from 
sl@0
    38
 *    the apps directory (application code) you must include an acknowledgement:
sl@0
    39
 *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
sl@0
    40
 * 
sl@0
    41
 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
sl@0
    42
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
sl@0
    43
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
sl@0
    44
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
sl@0
    45
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
sl@0
    46
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
sl@0
    47
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
sl@0
    48
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
sl@0
    49
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
sl@0
    50
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
sl@0
    51
 * SUCH DAMAGE.
sl@0
    52
 * 
sl@0
    53
 * The licence and distribution terms for any publically available version or
sl@0
    54
 * derivative of this code cannot be changed.  i.e. this code cannot simply be
sl@0
    55
 * copied and put under another distribution licence
sl@0
    56
 * [including the GNU Public Licence.]
sl@0
    57
 */
sl@0
    58
 /*
sl@0
    59
 © Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
sl@0
    60
 */
sl@0
    61
sl@0
    62
/* Part of the code in here was originally in conf.c, which is now removed */
sl@0
    63
sl@0
    64
#include <stdio.h>
sl@0
    65
#include <string.h>
sl@0
    66
#include "cryptlib.h"
sl@0
    67
#include <openssl/stack.h>
sl@0
    68
#include <openssl/lhash.h>
sl@0
    69
#include <openssl/conf.h>
sl@0
    70
#include <openssl/conf_api.h>
sl@0
    71
#include "conf_def.h"
sl@0
    72
#include <openssl/buffer.h>
sl@0
    73
#include <openssl/err.h>
sl@0
    74
#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
sl@0
    75
#include "libcrypto_wsd_macros.h"
sl@0
    76
#include "libcrypto_wsd.h"
sl@0
    77
#endif
sl@0
    78
sl@0
    79
static char *eat_ws(CONF *conf, char *p);
sl@0
    80
static char *eat_alpha_numeric(CONF *conf, char *p);
sl@0
    81
static void clear_comments(CONF *conf, char *p);
sl@0
    82
static int str_copy(CONF *conf,char *section,char **to, char *from);
sl@0
    83
static char *scan_quote(CONF *conf, char *p);
sl@0
    84
static char *scan_dquote(CONF *conf, char *p);
sl@0
    85
#define scan_esc(conf,p)	(((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2)))
sl@0
    86
sl@0
    87
static CONF *def_create(CONF_METHOD *meth);
sl@0
    88
static int def_init_default(CONF *conf);
sl@0
    89
static int def_init_WIN32(CONF *conf);
sl@0
    90
static int def_destroy(CONF *conf);
sl@0
    91
static int def_destroy_data(CONF *conf);
sl@0
    92
static int def_load(CONF *conf, const char *name, long *eline);
sl@0
    93
static int def_load_bio(CONF *conf, BIO *bp, long *eline);
sl@0
    94
static int def_dump(const CONF *conf, BIO *bp);
sl@0
    95
static int def_is_number(const CONF *conf, char c);
sl@0
    96
static int def_to_int(const CONF *conf, char c);
sl@0
    97
sl@0
    98
const char CONF_def_version[]="CONF_def" OPENSSL_VERSION_PTEXT;
sl@0
    99
sl@0
   100
#ifndef EMULATOR
sl@0
   101
static CONF_METHOD default_method = {
sl@0
   102
	"OpenSSL default",
sl@0
   103
	def_create,
sl@0
   104
	def_init_default,
sl@0
   105
	def_destroy,
sl@0
   106
	def_destroy_data,
sl@0
   107
	def_load_bio,
sl@0
   108
	def_dump,
sl@0
   109
	def_is_number,
sl@0
   110
	def_to_int,
sl@0
   111
	def_load
sl@0
   112
	};
sl@0
   113
sl@0
   114
static CONF_METHOD WIN32_method = {
sl@0
   115
	"WIN32",
sl@0
   116
	def_create,
sl@0
   117
	def_init_WIN32,
sl@0
   118
	def_destroy,
sl@0
   119
	def_destroy_data,
sl@0
   120
	def_load_bio,
sl@0
   121
	def_dump,
sl@0
   122
	def_is_number,
sl@0
   123
	def_to_int,
sl@0
   124
	def_load
sl@0
   125
	};
sl@0
   126
#else
sl@0
   127
GET_STATIC_VAR_FROM_TLS(default_method,conf_def,CONF_METHOD)
sl@0
   128
#define default_method (*GET_WSD_VAR_NAME(default_method,conf_def, s)())
sl@0
   129
const CONF_METHOD temp_s_default_method = {
sl@0
   130
	"OpenSSL default",
sl@0
   131
	def_create,
sl@0
   132
	def_init_default,
sl@0
   133
	def_destroy,
sl@0
   134
	def_destroy_data,
sl@0
   135
	def_load_bio,
sl@0
   136
	def_dump,
sl@0
   137
	def_is_number,
sl@0
   138
	def_to_int,
sl@0
   139
	def_load
sl@0
   140
	};
sl@0
   141
sl@0
   142
GET_STATIC_VAR_FROM_TLS(WIN32_method,conf_def,CONF_METHOD)
sl@0
   143
#define WIN32_method (*GET_WSD_VAR_NAME(WIN32_method,conf_def, s)())
sl@0
   144
const CONF_METHOD temp_s_WIN32_method = {
sl@0
   145
	"WIN32",
sl@0
   146
	def_create,
sl@0
   147
	def_init_WIN32,
sl@0
   148
	def_destroy,
sl@0
   149
	def_destroy_data,
sl@0
   150
	def_load_bio,
sl@0
   151
	def_dump,
sl@0
   152
	def_is_number,
sl@0
   153
	def_to_int,
sl@0
   154
	def_load
sl@0
   155
	};
sl@0
   156
sl@0
   157
sl@0
   158
#endif	
sl@0
   159
sl@0
   160
EXPORT_C CONF_METHOD *NCONF_default()
sl@0
   161
	{
sl@0
   162
	return &default_method;
sl@0
   163
	}
sl@0
   164
CONF_METHOD *NCONF_WIN32()
sl@0
   165
	{
sl@0
   166
	return &WIN32_method;
sl@0
   167
	}
sl@0
   168
sl@0
   169
static CONF *def_create(CONF_METHOD *meth)
sl@0
   170
	{
sl@0
   171
	CONF *ret;
sl@0
   172
sl@0
   173
	ret = (CONF *)OPENSSL_malloc(sizeof(CONF) + sizeof(unsigned short *));
sl@0
   174
	if (ret)
sl@0
   175
		if (meth->init(ret) == 0)
sl@0
   176
			{
sl@0
   177
			OPENSSL_free(ret);
sl@0
   178
			ret = NULL;
sl@0
   179
			}
sl@0
   180
	return ret;
sl@0
   181
	}
sl@0
   182
	
sl@0
   183
static int def_init_default(CONF *conf)
sl@0
   184
	{
sl@0
   185
	if (conf == NULL)
sl@0
   186
		return 0;
sl@0
   187
sl@0
   188
	conf->meth = &default_method;
sl@0
   189
	conf->meth_data = (void *)CONF_type_default;
sl@0
   190
	conf->data = NULL;
sl@0
   191
sl@0
   192
	return 1;
sl@0
   193
	}
sl@0
   194
sl@0
   195
static int def_init_WIN32(CONF *conf)
sl@0
   196
	{
sl@0
   197
	if (conf == NULL)
sl@0
   198
		return 0;
sl@0
   199
sl@0
   200
	conf->meth = &WIN32_method;
sl@0
   201
	conf->meth_data = (void *)CONF_type_win32;
sl@0
   202
	conf->data = NULL;
sl@0
   203
sl@0
   204
	return 1;
sl@0
   205
	}
sl@0
   206
sl@0
   207
static int def_destroy(CONF *conf)
sl@0
   208
	{
sl@0
   209
	if (def_destroy_data(conf))
sl@0
   210
		{
sl@0
   211
		OPENSSL_free(conf);
sl@0
   212
		return 1;
sl@0
   213
		}
sl@0
   214
	return 0;
sl@0
   215
	}
sl@0
   216
sl@0
   217
static int def_destroy_data(CONF *conf)
sl@0
   218
	{
sl@0
   219
	if (conf == NULL)
sl@0
   220
		return 0;
sl@0
   221
	_CONF_free_data(conf);
sl@0
   222
	return 1;
sl@0
   223
	}
sl@0
   224
sl@0
   225
static int def_load(CONF *conf, const char *name, long *line)
sl@0
   226
	{
sl@0
   227
	int ret;
sl@0
   228
	BIO *in=NULL;
sl@0
   229
sl@0
   230
#ifdef OPENSSL_SYS_VMS
sl@0
   231
	in=BIO_new_file(name, "r");
sl@0
   232
#else
sl@0
   233
	in=BIO_new_file(name, "rb");
sl@0
   234
#endif
sl@0
   235
	if (in == NULL)
sl@0
   236
		{
sl@0
   237
		if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE)
sl@0
   238
			CONFerr(CONF_F_DEF_LOAD,CONF_R_NO_SUCH_FILE);
sl@0
   239
		else
sl@0
   240
			CONFerr(CONF_F_DEF_LOAD,ERR_R_SYS_LIB);
sl@0
   241
		return 0;
sl@0
   242
		}
sl@0
   243
sl@0
   244
	ret = def_load_bio(conf, in, line);
sl@0
   245
	BIO_free(in);
sl@0
   246
sl@0
   247
	return ret;
sl@0
   248
	}
sl@0
   249
sl@0
   250
static int def_load_bio(CONF *conf, BIO *in, long *line)
sl@0
   251
	{
sl@0
   252
/* The macro BUFSIZE conflicts with a system macro in VxWorks */
sl@0
   253
#define CONFBUFSIZE	512
sl@0
   254
	int bufnum=0,i,ii;
sl@0
   255
	BUF_MEM *buff=NULL;
sl@0
   256
	char *s,*p,*end;
sl@0
   257
	int again,n;
sl@0
   258
	long eline=0;
sl@0
   259
	char btmp[DECIMAL_SIZE(eline)+1];
sl@0
   260
	CONF_VALUE *v=NULL,*tv;
sl@0
   261
	CONF_VALUE *sv=NULL;
sl@0
   262
	char *section=NULL,*buf;
sl@0
   263
	STACK_OF(CONF_VALUE) *section_sk=NULL,*ts;
sl@0
   264
	char *start,*psection,*pname;
sl@0
   265
	void *h = (void *)(conf->data);
sl@0
   266
sl@0
   267
	if ((buff=BUF_MEM_new()) == NULL)
sl@0
   268
		{
sl@0
   269
		CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_BUF_LIB);
sl@0
   270
		goto err;
sl@0
   271
		}
sl@0
   272
sl@0
   273
	section=(char *)OPENSSL_malloc(10);
sl@0
   274
	if (section == NULL)
sl@0
   275
		{
sl@0
   276
		CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
sl@0
   277
		goto err;
sl@0
   278
		}
sl@0
   279
	BUF_strlcpy(section,"default",10);
sl@0
   280
sl@0
   281
	if (_CONF_new_data(conf) == 0)
sl@0
   282
		{
sl@0
   283
		CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
sl@0
   284
		goto err;
sl@0
   285
		}
sl@0
   286
sl@0
   287
	sv=_CONF_new_section(conf,section);
sl@0
   288
	if (sv == NULL)
sl@0
   289
		{
sl@0
   290
		CONFerr(CONF_F_DEF_LOAD_BIO,
sl@0
   291
					CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
sl@0
   292
		goto err;
sl@0
   293
		}
sl@0
   294
	section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
sl@0
   295
sl@0
   296
	bufnum=0;
sl@0
   297
	again=0;
sl@0
   298
	for (;;)
sl@0
   299
		{
sl@0
   300
		if (!BUF_MEM_grow(buff,bufnum+CONFBUFSIZE))
sl@0
   301
			{
sl@0
   302
			CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_BUF_LIB);
sl@0
   303
			goto err;
sl@0
   304
			}
sl@0
   305
		p= &(buff->data[bufnum]);
sl@0
   306
		*p='\0';
sl@0
   307
		BIO_gets(in, p, CONFBUFSIZE-1);
sl@0
   308
		p[CONFBUFSIZE-1]='\0';
sl@0
   309
		ii=i=strlen(p);
sl@0
   310
		if (i == 0 && !again) break;
sl@0
   311
		again=0;
sl@0
   312
		while (i > 0)
sl@0
   313
			{
sl@0
   314
			if ((p[i-1] != '\r') && (p[i-1] != '\n'))
sl@0
   315
				break;
sl@0
   316
			else
sl@0
   317
				i--;
sl@0
   318
			}
sl@0
   319
		/* we removed some trailing stuff so there is a new
sl@0
   320
		 * line on the end. */
sl@0
   321
		if (ii && i == ii)
sl@0
   322
			again=1; /* long line */
sl@0
   323
		else
sl@0
   324
			{
sl@0
   325
			p[i]='\0';
sl@0
   326
			eline++; /* another input line */
sl@0
   327
			}
sl@0
   328
sl@0
   329
		/* we now have a line with trailing \r\n removed */
sl@0
   330
sl@0
   331
		/* i is the number of bytes */
sl@0
   332
		bufnum+=i;
sl@0
   333
sl@0
   334
		v=NULL;
sl@0
   335
		/* check for line continuation */
sl@0
   336
		if (bufnum >= 1)
sl@0
   337
			{
sl@0
   338
			/* If we have bytes and the last char '\\' and
sl@0
   339
			 * second last char is not '\\' */
sl@0
   340
			p= &(buff->data[bufnum-1]);
sl@0
   341
			if (IS_ESC(conf,p[0]) &&
sl@0
   342
				((bufnum <= 1) || !IS_ESC(conf,p[-1])))
sl@0
   343
				{
sl@0
   344
				bufnum--;
sl@0
   345
				again=1;
sl@0
   346
				}
sl@0
   347
			}
sl@0
   348
		if (again) continue;
sl@0
   349
		bufnum=0;
sl@0
   350
		buf=buff->data;
sl@0
   351
sl@0
   352
		clear_comments(conf, buf);
sl@0
   353
		n=strlen(buf);
sl@0
   354
		s=eat_ws(conf, buf);
sl@0
   355
		if (IS_EOF(conf,*s)) continue; /* blank line */
sl@0
   356
		if (*s == '[')
sl@0
   357
			{
sl@0
   358
			char *ss;
sl@0
   359
sl@0
   360
			s++;
sl@0
   361
			start=eat_ws(conf, s);
sl@0
   362
			ss=start;
sl@0
   363
again:
sl@0
   364
			end=eat_alpha_numeric(conf, ss);
sl@0
   365
			p=eat_ws(conf, end);
sl@0
   366
			if (*p != ']')
sl@0
   367
				{
sl@0
   368
				if (*p != '\0')
sl@0
   369
					{
sl@0
   370
					ss=p;
sl@0
   371
					goto again;
sl@0
   372
					}
sl@0
   373
				CONFerr(CONF_F_DEF_LOAD_BIO,
sl@0
   374
					CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
sl@0
   375
				goto err;
sl@0
   376
				}
sl@0
   377
			*end='\0';
sl@0
   378
			if (!str_copy(conf,NULL,&section,start)) goto err;
sl@0
   379
			if ((sv=_CONF_get_section(conf,section)) == NULL)
sl@0
   380
				sv=_CONF_new_section(conf,section);
sl@0
   381
			if (sv == NULL)
sl@0
   382
				{
sl@0
   383
				CONFerr(CONF_F_DEF_LOAD_BIO,
sl@0
   384
					CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
sl@0
   385
				goto err;
sl@0
   386
				}
sl@0
   387
			section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
sl@0
   388
			continue;
sl@0
   389
			}
sl@0
   390
		else
sl@0
   391
			{
sl@0
   392
			pname=s;
sl@0
   393
			psection=NULL;
sl@0
   394
			end=eat_alpha_numeric(conf, s);
sl@0
   395
			if ((end[0] == ':') && (end[1] == ':'))
sl@0
   396
				{
sl@0
   397
				*end='\0';
sl@0
   398
				end+=2;
sl@0
   399
				psection=pname;
sl@0
   400
				pname=end;
sl@0
   401
				end=eat_alpha_numeric(conf, end);
sl@0
   402
				}
sl@0
   403
			p=eat_ws(conf, end);
sl@0
   404
			if (*p != '=')
sl@0
   405
				{
sl@0
   406
				CONFerr(CONF_F_DEF_LOAD_BIO,
sl@0
   407
						CONF_R_MISSING_EQUAL_SIGN);
sl@0
   408
				goto err;
sl@0
   409
				}
sl@0
   410
			*end='\0';
sl@0
   411
			p++;
sl@0
   412
			start=eat_ws(conf, p);
sl@0
   413
			while (!IS_EOF(conf,*p))
sl@0
   414
				p++;
sl@0
   415
			p--;
sl@0
   416
			while ((p != start) && (IS_WS(conf,*p)))
sl@0
   417
				p--;
sl@0
   418
			p++;
sl@0
   419
			*p='\0';
sl@0
   420
sl@0
   421
			if (!(v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))))
sl@0
   422
				{
sl@0
   423
				CONFerr(CONF_F_DEF_LOAD_BIO,
sl@0
   424
							ERR_R_MALLOC_FAILURE);
sl@0
   425
				goto err;
sl@0
   426
				}
sl@0
   427
			if (psection == NULL) psection=section;
sl@0
   428
			v->name=(char *)OPENSSL_malloc(strlen(pname)+1);
sl@0
   429
			v->value=NULL;
sl@0
   430
			if (v->name == NULL)
sl@0
   431
				{
sl@0
   432
				CONFerr(CONF_F_DEF_LOAD_BIO,
sl@0
   433
							ERR_R_MALLOC_FAILURE);
sl@0
   434
				goto err;
sl@0
   435
				}
sl@0
   436
			BUF_strlcpy(v->name,pname,strlen(pname)+1);
sl@0
   437
			if (!str_copy(conf,psection,&(v->value),start)) goto err;
sl@0
   438
sl@0
   439
			if (strcmp(psection,section) != 0)
sl@0
   440
				{
sl@0
   441
				if ((tv=_CONF_get_section(conf,psection))
sl@0
   442
					== NULL)
sl@0
   443
					tv=_CONF_new_section(conf,psection);
sl@0
   444
				if (tv == NULL)
sl@0
   445
					{
sl@0
   446
					CONFerr(CONF_F_DEF_LOAD_BIO,
sl@0
   447
					   CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
sl@0
   448
					goto err;
sl@0
   449
					}
sl@0
   450
				ts=(STACK_OF(CONF_VALUE) *)tv->value;
sl@0
   451
				}
sl@0
   452
			else
sl@0
   453
				{
sl@0
   454
				tv=sv;
sl@0
   455
				ts=section_sk;
sl@0
   456
				}
sl@0
   457
#if 1
sl@0
   458
			if (_CONF_add_string(conf, tv, v) == 0)
sl@0
   459
				{
sl@0
   460
				CONFerr(CONF_F_DEF_LOAD_BIO,
sl@0
   461
							ERR_R_MALLOC_FAILURE);
sl@0
   462
				goto err;
sl@0
   463
				}
sl@0
   464
#else
sl@0
   465
			v->section=tv->section;	
sl@0
   466
			if (!sk_CONF_VALUE_push(ts,v))
sl@0
   467
				{
sl@0
   468
				CONFerr(CONF_F_DEF_LOAD_BIO,
sl@0
   469
							ERR_R_MALLOC_FAILURE);
sl@0
   470
				goto err;
sl@0
   471
				}
sl@0
   472
			vv=(CONF_VALUE *)lh_insert(conf->data,v);
sl@0
   473
			if (vv != NULL)
sl@0
   474
				{
sl@0
   475
				sk_CONF_VALUE_delete_ptr(ts,vv);
sl@0
   476
				OPENSSL_free(vv->name);
sl@0
   477
				OPENSSL_free(vv->value);
sl@0
   478
				OPENSSL_free(vv);
sl@0
   479
				}
sl@0
   480
#endif
sl@0
   481
			v=NULL;
sl@0
   482
			}
sl@0
   483
		}
sl@0
   484
	if (buff != NULL) BUF_MEM_free(buff);
sl@0
   485
	if (section != NULL) OPENSSL_free(section);
sl@0
   486
	return(1);
sl@0
   487
err:
sl@0
   488
	if (buff != NULL) BUF_MEM_free(buff);
sl@0
   489
	if (section != NULL) OPENSSL_free(section);
sl@0
   490
	if (line != NULL) *line=eline;
sl@0
   491
	BIO_snprintf(btmp,sizeof btmp,"%ld",eline);
sl@0
   492
	ERR_add_error_data(2,"line ",btmp);
sl@0
   493
	if ((h != conf->data) && (conf->data != NULL))
sl@0
   494
		{
sl@0
   495
		CONF_free(conf->data);
sl@0
   496
		conf->data=NULL;
sl@0
   497
		}
sl@0
   498
	if (v != NULL)
sl@0
   499
		{
sl@0
   500
		if (v->name != NULL) OPENSSL_free(v->name);
sl@0
   501
		if (v->value != NULL) OPENSSL_free(v->value);
sl@0
   502
		if (v != NULL) OPENSSL_free(v);
sl@0
   503
		}
sl@0
   504
	return(0);
sl@0
   505
	}
sl@0
   506
sl@0
   507
static void clear_comments(CONF *conf, char *p)
sl@0
   508
	{
sl@0
   509
	char *to;
sl@0
   510
sl@0
   511
	to=p;
sl@0
   512
	for (;;)
sl@0
   513
		{
sl@0
   514
		if (IS_FCOMMENT(conf,*p))
sl@0
   515
			{
sl@0
   516
			*p='\0';
sl@0
   517
			return;
sl@0
   518
			}
sl@0
   519
		if (!IS_WS(conf,*p))
sl@0
   520
			{
sl@0
   521
			break;
sl@0
   522
			}
sl@0
   523
		p++;
sl@0
   524
		}
sl@0
   525
sl@0
   526
	for (;;)
sl@0
   527
		{
sl@0
   528
		if (IS_COMMENT(conf,*p))
sl@0
   529
			{
sl@0
   530
			*p='\0';
sl@0
   531
			return;
sl@0
   532
			}
sl@0
   533
		if (IS_DQUOTE(conf,*p))
sl@0
   534
			{
sl@0
   535
			p=scan_dquote(conf, p);
sl@0
   536
			continue;
sl@0
   537
			}
sl@0
   538
		if (IS_QUOTE(conf,*p))
sl@0
   539
			{
sl@0
   540
			p=scan_quote(conf, p);
sl@0
   541
			continue;
sl@0
   542
			}
sl@0
   543
		if (IS_ESC(conf,*p))
sl@0
   544
			{
sl@0
   545
			p=scan_esc(conf,p);
sl@0
   546
			continue;
sl@0
   547
			}
sl@0
   548
		if (IS_EOF(conf,*p))
sl@0
   549
			return;
sl@0
   550
		else
sl@0
   551
			p++;
sl@0
   552
		}
sl@0
   553
	}
sl@0
   554
sl@0
   555
static int str_copy(CONF *conf, char *section, char **pto, char *from)
sl@0
   556
	{
sl@0
   557
	int q,r,rr=0,to=0,len=0;
sl@0
   558
	char *s,*e,*rp,*p,*rrp,*np,*cp,v;
sl@0
   559
	BUF_MEM *buf;
sl@0
   560
sl@0
   561
	if ((buf=BUF_MEM_new()) == NULL) return(0);
sl@0
   562
sl@0
   563
	len=strlen(from)+1;
sl@0
   564
	if (!BUF_MEM_grow(buf,len)) goto err;
sl@0
   565
sl@0
   566
	for (;;)
sl@0
   567
		{
sl@0
   568
		if (IS_QUOTE(conf,*from))
sl@0
   569
			{
sl@0
   570
			q= *from;
sl@0
   571
			from++;
sl@0
   572
			while (!IS_EOF(conf,*from) && (*from != q))
sl@0
   573
				{
sl@0
   574
				if (IS_ESC(conf,*from))
sl@0
   575
					{
sl@0
   576
					from++;
sl@0
   577
					if (IS_EOF(conf,*from)) break;
sl@0
   578
					}
sl@0
   579
				buf->data[to++]= *(from++);
sl@0
   580
				}
sl@0
   581
			if (*from == q) from++;
sl@0
   582
			}
sl@0
   583
		else if (IS_DQUOTE(conf,*from))
sl@0
   584
			{
sl@0
   585
			q= *from;
sl@0
   586
			from++;
sl@0
   587
			while (!IS_EOF(conf,*from))
sl@0
   588
				{
sl@0
   589
				if (*from == q)
sl@0
   590
					{
sl@0
   591
					if (*(from+1) == q)
sl@0
   592
						{
sl@0
   593
						from++;
sl@0
   594
						}
sl@0
   595
					else
sl@0
   596
						{
sl@0
   597
						break;
sl@0
   598
						}
sl@0
   599
					}
sl@0
   600
				buf->data[to++]= *(from++);
sl@0
   601
				}
sl@0
   602
			if (*from == q) from++;
sl@0
   603
			}
sl@0
   604
		else if (IS_ESC(conf,*from))
sl@0
   605
			{
sl@0
   606
			from++;
sl@0
   607
			v= *(from++);
sl@0
   608
			if (IS_EOF(conf,v)) break;
sl@0
   609
			else if (v == 'r') v='\r';
sl@0
   610
			else if (v == 'n') v='\n';
sl@0
   611
			else if (v == 'b') v='\b';
sl@0
   612
			else if (v == 't') v='\t';
sl@0
   613
			buf->data[to++]= v;
sl@0
   614
			}
sl@0
   615
		else if (IS_EOF(conf,*from))
sl@0
   616
			break;
sl@0
   617
		else if (*from == '$')
sl@0
   618
			{
sl@0
   619
			/* try to expand it */
sl@0
   620
			rrp=NULL;
sl@0
   621
			s= &(from[1]);
sl@0
   622
			if (*s == '{')
sl@0
   623
				q='}';
sl@0
   624
			else if (*s == '(')
sl@0
   625
				q=')';
sl@0
   626
			else q=0;
sl@0
   627
sl@0
   628
			if (q) s++;
sl@0
   629
			cp=section;
sl@0
   630
			e=np=s;
sl@0
   631
			while (IS_ALPHA_NUMERIC(conf,*e))
sl@0
   632
				e++;
sl@0
   633
			if ((e[0] == ':') && (e[1] == ':'))
sl@0
   634
				{
sl@0
   635
				cp=np;
sl@0
   636
				rrp=e;
sl@0
   637
				rr= *e;
sl@0
   638
				*rrp='\0';
sl@0
   639
				e+=2;
sl@0
   640
				np=e;
sl@0
   641
				while (IS_ALPHA_NUMERIC(conf,*e))
sl@0
   642
					e++;
sl@0
   643
				}
sl@0
   644
			r= *e;
sl@0
   645
			*e='\0';
sl@0
   646
			rp=e;
sl@0
   647
			if (q)
sl@0
   648
				{
sl@0
   649
				if (r != q)
sl@0
   650
					{
sl@0
   651
					CONFerr(CONF_F_STR_COPY,CONF_R_NO_CLOSE_BRACE);
sl@0
   652
					goto err;
sl@0
   653
					}
sl@0
   654
				e++;
sl@0
   655
				}
sl@0
   656
			/* So at this point we have
sl@0
   657
			 * np which is the start of the name string which is
sl@0
   658
			 *   '\0' terminated. 
sl@0
   659
			 * cp which is the start of the section string which is
sl@0
   660
			 *   '\0' terminated.
sl@0
   661
			 * e is the 'next point after'.
sl@0
   662
			 * r and rr are the chars replaced by the '\0'
sl@0
   663
			 * rp and rrp is where 'r' and 'rr' came from.
sl@0
   664
			 */
sl@0
   665
			p=_CONF_get_string(conf,cp,np);
sl@0
   666
			if (rrp != NULL) *rrp=rr;
sl@0
   667
			*rp=r;
sl@0
   668
			if (p == NULL)
sl@0
   669
				{
sl@0
   670
				CONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE);
sl@0
   671
				goto err;
sl@0
   672
				}
sl@0
   673
			BUF_MEM_grow_clean(buf,(strlen(p)+buf->length-(e-from)));
sl@0
   674
			while (*p)
sl@0
   675
				buf->data[to++]= *(p++);
sl@0
   676
sl@0
   677
			/* Since we change the pointer 'from', we also have
sl@0
   678
			   to change the perceived length of the string it
sl@0
   679
			   points at.  /RL */
sl@0
   680
			len -= e-from;
sl@0
   681
			from=e;
sl@0
   682
sl@0
   683
			/* In case there were no braces or parenthesis around
sl@0
   684
			   the variable reference, we have to put back the
sl@0
   685
			   character that was replaced with a '\0'.  /RL */
sl@0
   686
			*rp = r;
sl@0
   687
			}
sl@0
   688
		else
sl@0
   689
			buf->data[to++]= *(from++);
sl@0
   690
		}
sl@0
   691
	buf->data[to]='\0';
sl@0
   692
	if (*pto != NULL) OPENSSL_free(*pto);
sl@0
   693
	*pto=buf->data;
sl@0
   694
	OPENSSL_free(buf);
sl@0
   695
	return(1);
sl@0
   696
err:
sl@0
   697
	if (buf != NULL) BUF_MEM_free(buf);
sl@0
   698
	return(0);
sl@0
   699
	}
sl@0
   700
sl@0
   701
static char *eat_ws(CONF *conf, char *p)
sl@0
   702
	{
sl@0
   703
	while (IS_WS(conf,*p) && (!IS_EOF(conf,*p)))
sl@0
   704
		p++;
sl@0
   705
	return(p);
sl@0
   706
	}
sl@0
   707
sl@0
   708
static char *eat_alpha_numeric(CONF *conf, char *p)
sl@0
   709
	{
sl@0
   710
	for (;;)
sl@0
   711
		{
sl@0
   712
		if (IS_ESC(conf,*p))
sl@0
   713
			{
sl@0
   714
			p=scan_esc(conf,p);
sl@0
   715
			continue;
sl@0
   716
			}
sl@0
   717
		if (!IS_ALPHA_NUMERIC_PUNCT(conf,*p))
sl@0
   718
			return(p);
sl@0
   719
		p++;
sl@0
   720
		}
sl@0
   721
	}
sl@0
   722
sl@0
   723
static char *scan_quote(CONF *conf, char *p)
sl@0
   724
	{
sl@0
   725
	int q= *p;
sl@0
   726
sl@0
   727
	p++;
sl@0
   728
	while (!(IS_EOF(conf,*p)) && (*p != q))
sl@0
   729
		{
sl@0
   730
		if (IS_ESC(conf,*p))
sl@0
   731
			{
sl@0
   732
			p++;
sl@0
   733
			if (IS_EOF(conf,*p)) return(p);
sl@0
   734
			}
sl@0
   735
		p++;
sl@0
   736
		}
sl@0
   737
	if (*p == q) p++;
sl@0
   738
	return(p);
sl@0
   739
	}
sl@0
   740
sl@0
   741
sl@0
   742
static char *scan_dquote(CONF *conf, char *p)
sl@0
   743
	{
sl@0
   744
	int q= *p;
sl@0
   745
sl@0
   746
	p++;
sl@0
   747
	while (!(IS_EOF(conf,*p)))
sl@0
   748
		{
sl@0
   749
		if (*p == q)
sl@0
   750
			{
sl@0
   751
			if (*(p+1) == q)
sl@0
   752
				{
sl@0
   753
				p++;
sl@0
   754
				}
sl@0
   755
			else
sl@0
   756
				{
sl@0
   757
				break;
sl@0
   758
				}
sl@0
   759
			}
sl@0
   760
		p++;
sl@0
   761
		}
sl@0
   762
	if (*p == q) p++;
sl@0
   763
	return(p);
sl@0
   764
	}
sl@0
   765
sl@0
   766
static void dump_value(CONF_VALUE *a, BIO *out)
sl@0
   767
	{
sl@0
   768
	if (a->name)
sl@0
   769
		BIO_printf(out, "[%s] %s=%s\n", a->section, a->name, a->value);
sl@0
   770
	else
sl@0
   771
		BIO_printf(out, "[[%s]]\n", a->section);
sl@0
   772
	}
sl@0
   773
sl@0
   774
static IMPLEMENT_LHASH_DOALL_ARG_FN(dump_value, CONF_VALUE *, BIO *)
sl@0
   775
sl@0
   776
static int def_dump(const CONF *conf, BIO *out)
sl@0
   777
	{
sl@0
   778
	lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(dump_value), out);
sl@0
   779
	return 1;
sl@0
   780
	}
sl@0
   781
sl@0
   782
static int def_is_number(const CONF *conf, char c)
sl@0
   783
	{
sl@0
   784
	return IS_NUMBER(conf,c);
sl@0
   785
	}
sl@0
   786
sl@0
   787
static int def_to_int(const CONF *conf, char c)
sl@0
   788
	{
sl@0
   789
	return c - '0';
sl@0
   790
	}
sl@0
   791