#include <stdio.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <openssl/conf.h>
#include <openssl/conf_api.h>
#include <openssl/lhash.h>
const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT;
static CONF_METHOD *default_CONF_method=NULL;
int CONF_set_default_method(CONF_METHOD *meth)
{
default_CONF_method = meth;
return 1;
}
LHASH *CONF_load(LHASH *conf, const char *file, long *eline)
{
LHASH *ltmp;
BIO *in=NULL;
#ifdef VMS
in=BIO_new_file(file, "r");
#else
in=BIO_new_file(file, "rb");
#endif
if (in == NULL)
{
CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
return NULL;
}
ltmp = CONF_load_bio(conf, in, eline);
BIO_free(in);
return ltmp;
}
#ifndef NO_FP_API
LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline)
{
BIO *btmp;
LHASH *ltmp;
if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) {
CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
return NULL;
}
ltmp = CONF_load_bio(conf, btmp, eline);
BIO_free(btmp);
return ltmp;
}
#endif
LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline)
{
CONF ctmp;
int ret;
if (default_CONF_method == NULL)
default_CONF_method = NCONF_default();
default_CONF_method->init(&ctmp);
ctmp.data = conf;
ret = NCONF_load_bio(&ctmp, bp, eline);
if (ret)
return ctmp.data;
return NULL;
}
STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section)
{
if (conf == NULL)
{
return NULL;
}
else
{
CONF ctmp;
if (default_CONF_method == NULL)
default_CONF_method = NCONF_default();
default_CONF_method->init(&ctmp);
ctmp.data = conf;
return NCONF_get_section(&ctmp, section);
}
}
char *CONF_get_string(LHASH *conf,char *group,char *name)
{
if (conf == NULL)
{
return NCONF_get_string(NULL, group, name);
}
else
{
CONF ctmp;
if (default_CONF_method == NULL)
default_CONF_method = NCONF_default();
default_CONF_method->init(&ctmp);
ctmp.data = conf;
return NCONF_get_string(&ctmp, group, name);
}
}
long CONF_get_number(LHASH *conf,char *group,char *name)
{
if (conf == NULL)
{
return NCONF_get_number(NULL, group, name);
}
else
{
CONF ctmp;
if (default_CONF_method == NULL)
default_CONF_method = NCONF_default();
default_CONF_method->init(&ctmp);
ctmp.data = conf;
return NCONF_get_number(&ctmp, group, name);
}
}
void CONF_free(LHASH *conf)
{
CONF ctmp;
if (default_CONF_method == NULL)
default_CONF_method = NCONF_default();
default_CONF_method->init(&ctmp);
ctmp.data = conf;
NCONF_free_data(&ctmp);
}
#ifndef NO_FP_API
int CONF_dump_fp(LHASH *conf, FILE *out)
{
BIO *btmp;
int ret;
if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
CONFerr(CONF_F_CONF_DUMP_FP,ERR_R_BUF_LIB);
return 0;
}
ret = CONF_dump_bio(conf, btmp);
BIO_free(btmp);
return ret;
}
#endif
int CONF_dump_bio(LHASH *conf, BIO *out)
{
CONF ctmp;
if (default_CONF_method == NULL)
default_CONF_method = NCONF_default();
default_CONF_method->init(&ctmp);
ctmp.data = conf;
return NCONF_dump_bio(&ctmp, out);
}
CONF *NCONF_new(CONF_METHOD *meth)
{
CONF *ret;
if (meth == NULL)
meth = NCONF_default();
ret = meth->create(meth);
if (ret == NULL)
{
CONFerr(CONF_F_NCONF_NEW,ERR_R_MALLOC_FAILURE);
return(NULL);
}
return ret;
}
void NCONF_free(CONF *conf)
{
if (conf == NULL)
return;
conf->meth->destroy(conf);
}
void NCONF_free_data(CONF *conf)
{
if (conf == NULL)
return;
conf->meth->destroy_data(conf);
}
int NCONF_load(CONF *conf, const char *file, long *eline)
{
int ret;
BIO *in=NULL;
#ifdef VMS
in=BIO_new_file(file, "r");
#else
in=BIO_new_file(file, "rb");
#endif
if (in == NULL)
{
CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
return 0;
}
ret = NCONF_load_bio(conf, in, eline);
BIO_free(in);
return ret;
}
#ifndef NO_FP_API
int NCONF_load_fp(CONF *conf, FILE *fp,long *eline)
{
BIO *btmp;
int ret;
if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE)))
{
CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
return 0;
}
ret = NCONF_load_bio(conf, btmp, eline);
BIO_free(btmp);
return ret;
}
#endif
int NCONF_load_bio(CONF *conf, BIO *bp,long *eline)
{
if (conf == NULL)
{
CONFerr(CONF_F_NCONF_LOAD_BIO,CONF_R_NO_CONF);
return 0;
}
return conf->meth->load(conf, bp, eline);
}
STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section)
{
if (conf == NULL)
{
CONFerr(CONF_F_NCONF_GET_SECTION,CONF_R_NO_CONF);
return NULL;
}
if (section == NULL)
{
CONFerr(CONF_F_NCONF_GET_SECTION,CONF_R_NO_SECTION);
return NULL;
}
return _CONF_get_section_values(conf, section);
}
char *NCONF_get_string(CONF *conf,char *group,char *name)
{
char *s = _CONF_get_string(conf, group, name);
if (s) return s;
if (conf == NULL)
{
CONFerr(CONF_F_NCONF_GET_STRING,
CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE);
return NULL;
}
return NULL;
}
long NCONF_get_number(CONF *conf,char *group,char *name)
{
#if 0
if (conf == NULL)
{
CONFerr(CONF_F_NCONF_GET_NUMBER,
CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE);
return 0;
}
#endif
return _CONF_get_number(conf, group, name);
}
#ifndef NO_FP_API
int NCONF_dump_fp(CONF *conf, FILE *out)
{
BIO *btmp;
int ret;
if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
CONFerr(CONF_F_NCONF_DUMP_FP,ERR_R_BUF_LIB);
return 0;
}
ret = NCONF_dump_bio(conf, btmp);
BIO_free(btmp);
return ret;
}
#endif
int NCONF_dump_bio(CONF *conf, BIO *out)
{
if (conf == NULL)
{
CONFerr(CONF_F_NCONF_DUMP_BIO,CONF_R_NO_CONF);
return 0;
}
return conf->meth->dump(conf, out);
}