Make it possible for methods to load from something other than a BIO,
authorRichard Levitte <levitte@openssl.org>
Thu, 19 Oct 2000 08:26:32 +0000 (08:26 +0000)
committerRichard Levitte <levitte@openssl.org>
Thu, 19 Oct 2000 08:26:32 +0000 (08:26 +0000)
by providing a function pointer that is given a name instead of a BIO.
For example, this could be used to load configuration data from an
LDAP server.

crypto/conf/conf.h
crypto/conf/conf_def.c
crypto/conf/conf_lib.c

index 3fded162a2351d26a8a6ea7e25f5d027d40297f1..9f039391c995acda7b66aa7ee31e7580b5d7d8b9 100644 (file)
@@ -90,7 +90,8 @@ struct conf_method_st
        int (MS_FAR *init)(CONF *conf);
        int (MS_FAR *destroy)(CONF *conf);
        int (MS_FAR *destroy_data)(CONF *conf);
-       int (MS_FAR *load)(CONF *conf, BIO *bp, long *eline);
+       int (MS_FAR *load)(CONF *conf, const char *name, long *eline);
+       int (MS_FAR *load_bio)(CONF *conf, BIO *bp, long *eline);
        int (MS_FAR *dump)(CONF *conf, BIO *bp);
        int (MS_FAR *is_number)(CONF *conf, char c);
        int (MS_FAR *to_int)(CONF *conf, char c);
@@ -166,7 +167,9 @@ long NCONF_get_number(CONF *conf,char *group,char *name);
 #define CONF_F_NCONF_GET_NUMBER_E                       112
 #define CONF_F_NCONF_GET_SECTION                        108
 #define CONF_F_NCONF_GET_STRING                                 109
+#define CONF_F_NCONF_LOAD                               113
 #define CONF_F_NCONF_LOAD_BIO                           110
+#define CONF_F_NCONF_LOAD_FP                            114
 #define CONF_F_NCONF_NEW                                111
 #define CONF_F_STR_COPY                                         101
 
index 773df32c681bb07426e3f2e1baca0dc82eb4244d..7cf14316d5c2c926bbf5bb87ff66867ca10a5bcc 100644 (file)
@@ -81,7 +81,8 @@ static int def_init_default(CONF *conf);
 static int def_init_WIN32(CONF *conf);
 static int def_destroy(CONF *conf);
 static int def_destroy_data(CONF *conf);
-static int def_load(CONF *conf, BIO *bp, long *eline);
+static int def_load(CONF *conf, const char *name, long *eline);
+static int def_load_bio(CONF *conf, BIO *bp, long *eline);
 static int def_dump(CONF *conf, BIO *bp);
 static int def_is_number(CONF *conf, char c);
 static int def_to_int(CONF *conf, char c);
@@ -95,6 +96,7 @@ static CONF_METHOD default_method = {
        def_destroy,
        def_destroy_data,
        def_load,
+       def_load_bio,
        def_dump,
        def_is_number,
        def_to_int
@@ -107,6 +109,7 @@ static CONF_METHOD WIN32_method = {
        def_destroy,
        def_destroy_data,
        def_load,
+       def_load_bio,
        def_dump,
        def_is_number,
        def_to_int
@@ -177,7 +180,29 @@ static int def_destroy_data(CONF *conf)
        return 1;
        }
 
-static int def_load(CONF *conf, BIO *in, long *line)
+static int def_load(CONF *conf, const char *name, long *line)
+       {
+       int ret;
+       BIO *in=NULL;
+
+#ifdef VMS
+       in=BIO_new_file(name, "r");
+#else
+       in=BIO_new_file(name, "rb");
+#endif
+       if (in == NULL)
+               {
+               CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
+               return 0;
+               }
+
+       ret = def_load_bio(conf, in, line);
+       BIO_free(in);
+
+       return ret;
+       }
+
+static int def_load_bio(CONF *conf, BIO *in, long *line)
        {
 #define BUFSIZE        512
        char btmp[16];
index a1d31cf9537207a734f53bc2dddc078635b9cbc7..2005c87350b7a65dcdbedbcf5c493faeda83fa81 100644 (file)
@@ -252,24 +252,13 @@ void NCONF_free_data(CONF *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)
+       if (conf == NULL)
                {
-               CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
+               CONFerr(CONF_F_NCONF_LOAD,CONF_R_NO_CONF);
                return 0;
                }
 
-       ret = NCONF_load_bio(conf, in, eline);
-       BIO_free(in);
-
-       return ret;
+       return conf->meth->load(conf, file, eline);
        }
 
 #ifndef NO_FP_API
@@ -279,7 +268,7 @@ int NCONF_load_fp(CONF *conf, FILE *fp,long *eline)
        int ret;
        if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE)))
                {
-               CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
+               CONFerr(CONF_F_NCONF_LOAD_FP,ERR_R_BUF_LIB);
                return 0;
                }
        ret = NCONF_load_bio(conf, btmp, eline);
@@ -296,7 +285,7 @@ int NCONF_load_bio(CONF *conf, BIO *bp,long *eline)
                return 0;
                }
 
-       return conf->meth->load(conf, bp, eline);
+       return conf->meth->load_bio(conf, bp, eline);
        }
 
 STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section)