aboutsummaryrefslogtreecommitdiff
path: root/crypto/conf
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>1999-06-20 17:36:11 +0000
committerDr. Stephen Henson <steve@openssl.org>1999-06-20 17:36:11 +0000
commit8623f693d9a5c74f76311aebd29767e89467ecea (patch)
tree03798bbe6a24a55e425f874096d8b6b9486d109a /crypto/conf
parent11af1a2758baefab1157755c508d7b7490155bab (diff)
downloadopenssl-8623f693d9a5c74f76311aebd29767e89467ecea.zip
openssl-8623f693d9a5c74f76311aebd29767e89467ecea.tar.gz
openssl-8623f693d9a5c74f76311aebd29767e89467ecea.tar.bz2
New functions CONF_load_bio() and CONF_load_fp() to load a configuration
file from a bio or fp. Added some more constification to the BN library.
Diffstat (limited to 'crypto/conf')
-rw-r--r--crypto/conf/Makefile.ssl6
-rw-r--r--crypto/conf/conf.c94
-rw-r--r--crypto/conf/conf.h9
-rw-r--r--crypto/conf/conf_err.c2
4 files changed, 75 insertions, 36 deletions
diff --git a/crypto/conf/Makefile.ssl b/crypto/conf/Makefile.ssl
index c686b34..ab2e148 100644
--- a/crypto/conf/Makefile.ssl
+++ b/crypto/conf/Makefile.ssl
@@ -85,5 +85,7 @@ conf.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
conf.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
conf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
conf.o: ../../include/openssl/stack.h ../cryptlib.h conf_lcl.h
-conf_err.o: ../../include/openssl/conf.h ../../include/openssl/err.h
-conf_err.o: ../../include/openssl/lhash.h ../../include/openssl/stack.h
+conf_err.o: ../../include/openssl/bio.h ../../include/openssl/conf.h
+conf_err.o: ../../include/openssl/crypto.h ../../include/openssl/err.h
+conf_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslv.h
+conf_err.o: ../../include/openssl/stack.h
diff --git a/crypto/conf/conf.c b/crypto/conf/conf.c
index a55ecbb..3a055fa 100644
--- a/crypto/conf/conf.c
+++ b/crypto/conf/conf.c
@@ -82,10 +82,48 @@ static CONF_VALUE *get_section(LHASH *conf,char *section);
const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT;
-LHASH *CONF_load(LHASH *h, char *file, long *line)
+
+LHASH *CONF_load(LHASH *h, const char *file, long *line)
{
- LHASH *ret=NULL;
+ LHASH *ltmp;
FILE *in=NULL;
+
+#ifdef VMS
+ in=fopen(file,"r");
+#else
+ in=fopen(file,"rb");
+#endif
+ if (in == NULL)
+ {
+ SYSerr(SYS_F_FOPEN,get_last_sys_error());
+ ERR_set_error_data(BUF_strdup(file),
+ ERR_TXT_MALLOCED|ERR_TXT_STRING);
+ CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
+ return NULL;
+ }
+
+ ltmp = CONF_load_fp(h, in, line);
+ fclose(in);
+
+ return ltmp;
+}
+
+LHASH *CONF_load_fp(LHASH *h, FILE *in, long *line)
+{
+ BIO *btmp;
+ LHASH *ltmp;
+ if(!(btmp = BIO_new_fp(in, BIO_NOCLOSE))) {
+ CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
+ return NULL;
+ }
+ ltmp = CONF_load_bio(h, btmp, line);
+ BIO_free(btmp);
+ return ltmp;
+}
+
+LHASH *CONF_load_bio(LHASH *h, BIO *in, long *line)
+ {
+ LHASH *ret=NULL;
#define BUFSIZE 512
char btmp[16];
int bufnum=0,i,ii;
@@ -101,28 +139,14 @@ LHASH *CONF_load(LHASH *h, char *file, long *line)
if ((buff=BUF_MEM_new()) == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,ERR_R_BUF_LIB);
- goto err;
- }
-
-#ifdef VMS
- in=fopen(file,"r");
-#else
- in=fopen(file,"rb");
-#endif
- if (in == NULL)
- {
- SYSerr(SYS_F_FOPEN,get_last_sys_error());
- ERR_set_error_data(BUF_strdup(file),
- ERR_TXT_MALLOCED|ERR_TXT_STRING);
- CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
+ CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
goto err;
}
section=(char *)Malloc(10);
if (section == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);
+ CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
goto err;
}
strcpy(section,"default");
@@ -131,7 +155,7 @@ LHASH *CONF_load(LHASH *h, char *file, long *line)
{
if ((ret=lh_new(hash,cmp)) == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);
+ CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
goto err;
}
}
@@ -141,7 +165,8 @@ LHASH *CONF_load(LHASH *h, char *file, long *line)
sv=new_section(ret,section);
if (sv == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
goto err;
}
section_sk=(STACK *)sv->value;
@@ -152,12 +177,12 @@ LHASH *CONF_load(LHASH *h, char *file, long *line)
again=0;
if (!BUF_MEM_grow(buff,bufnum+BUFSIZE))
{
- CONFerr(CONF_F_CONF_LOAD,ERR_R_BUF_LIB);
+ CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
goto err;
}
p= &(buff->data[bufnum]);
*p='\0';
- fgets(p,BUFSIZE-1,in);
+ BIO_gets(in, p, BUFSIZE-1);
p[BUFSIZE-1]='\0';
ii=i=strlen(p);
if (i == 0) break;
@@ -222,7 +247,8 @@ again:
ss=p;
goto again;
}
- CONFerr(CONF_F_CONF_LOAD,CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
goto err;
}
*end='\0';
@@ -231,7 +257,8 @@ again:
sv=new_section(ret,section);
if (sv == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
goto err;
}
section_sk=(STACK *)sv->value;
@@ -253,7 +280,8 @@ again:
p=eat_ws(end);
if (*p != '=')
{
- CONFerr(CONF_F_CONF_LOAD,CONF_R_MISSING_EQUAL_SIGN);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ CONF_R_MISSING_EQUAL_SIGN);
goto err;
}
*end='\0';
@@ -269,7 +297,8 @@ again:
if ((v=(CONF_VALUE *)Malloc(sizeof(CONF_VALUE))) == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ ERR_R_MALLOC_FAILURE);
goto err;
}
if (psection == NULL) psection=section;
@@ -277,7 +306,8 @@ again:
v->value=NULL;
if (v->name == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ ERR_R_MALLOC_FAILURE);
goto err;
}
strcpy(v->name,pname);
@@ -290,7 +320,8 @@ again:
tv=new_section(ret,psection);
if (tv == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
goto err;
}
ts=(STACK *)tv->value;
@@ -303,7 +334,8 @@ again:
v->section=tv->section;
if (!sk_push(ts,(char *)v))
{
- CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ ERR_R_MALLOC_FAILURE);
goto err;
}
vv=(CONF_VALUE *)lh_insert(ret,(char *)v);
@@ -319,7 +351,6 @@ again:
}
if (buff != NULL) BUF_MEM_free(buff);
if (section != NULL) Free(section);
- if (in != NULL) fclose(in);
return(ret);
err:
if (buff != NULL) BUF_MEM_free(buff);
@@ -327,7 +358,6 @@ err:
if (line != NULL) *line=eline;
sprintf(btmp,"%ld",eline);
ERR_add_error_data(2,"line ",btmp);
- if (in != NULL) fclose(in);
if ((h != ret) && (ret != NULL)) CONF_free(ret);
if (v != NULL)
{
@@ -337,7 +367,7 @@ err:
}
return(NULL);
}
-
+
char *CONF_get_string(LHASH *conf, char *section, char *name)
{
CONF_VALUE *v,vv;
diff --git a/crypto/conf/conf.h b/crypto/conf/conf.h
index 2401518..feb65f2 100644
--- a/crypto/conf/conf.h
+++ b/crypto/conf/conf.h
@@ -63,8 +63,9 @@
extern "C" {
#endif
-#include <openssl/stack.h>
+#include <openssl/bio.h>
#include <openssl/lhash.h>
+#include <openssl/stack.h>
typedef struct
{
@@ -74,7 +75,9 @@ typedef struct
} CONF_VALUE;
-LHASH *CONF_load(LHASH *conf,char *file,long *eline);
+LHASH *CONF_load(LHASH *conf,const char *file,long *eline);
+LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline);
+LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline);
STACK *CONF_get_section(LHASH *conf,char *section);
char *CONF_get_string(LHASH *conf,char *group,char *name);
long CONF_get_number(LHASH *conf,char *group,char *name);
@@ -90,6 +93,8 @@ void ERR_load_CONF_strings(void );
/* Function codes. */
#define CONF_F_CONF_LOAD 100
+#define CONF_F_CONF_LOAD_BIO 102
+#define CONF_F_CONF_LOAD_FP 103
#define CONF_F_STR_COPY 101
/* Reason codes. */
diff --git a/crypto/conf/conf_err.c b/crypto/conf/conf_err.c
index 340e429..eb4b3cf 100644
--- a/crypto/conf/conf_err.c
+++ b/crypto/conf/conf_err.c
@@ -66,6 +66,8 @@
static ERR_STRING_DATA CONF_str_functs[]=
{
{ERR_PACK(0,CONF_F_CONF_LOAD,0), "CONF_load"},
+{ERR_PACK(0,CONF_F_CONF_LOAD_BIO,0), "CONF_load_bio"},
+{ERR_PACK(0,CONF_F_CONF_LOAD_FP,0), "CONF_load_fp"},
{ERR_PACK(0,CONF_F_STR_COPY,0), "STR_COPY"},
{0,NULL}
};