Fix from main trunk, 2000-10-13 10:30 levitte:
authorRichard Levitte <levitte@openssl.org>
Fri, 27 Oct 2000 20:18:00 +0000 (20:18 +0000)
committerRichard Levitte <levitte@openssl.org>
Fri, 27 Oct 2000 20:18:00 +0000 (20:18 +0000)
Make the new conf implementatoin bug-compatible with the old one.
Actually, it's a feature that it goes looking at environment
variables.  It's just a pity that it's at the cost of the error
checking...  I'll see if I can come up with a better interface for
this.

Fix from main trunk, 2000-10-16 15:08  ben:

Always return a value.

crypto/conf/conf.h
crypto/conf/conf_err.c
crypto/conf/conf_lib.c

index 2f70634455b95f1b6bf1bcadf83dc800e6860f16..cd40a0db215acbd8d9b9562123d4dafa382addce 100644 (file)
@@ -167,6 +167,8 @@ int NCONF_dump_bio(CONF *conf, BIO *out);
 #define CONF_R_MISSING_EQUAL_SIGN                       101
 #define CONF_R_NO_CLOSE_BRACE                           102
 #define CONF_R_NO_CONF                                  105
+#define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE          106
+#define CONF_R_NO_SECTION                               107
 #define CONF_R_UNABLE_TO_CREATE_NEW_SECTION             103
 #define CONF_R_VARIABLE_HAS_NO_VALUE                    104
 
index 06d3163573c20abd797d8d20000546e0fa04a9b5..8c2bc6f1c4cbbb1cbdd9da7d758df5d27c9ad381 100644 (file)
@@ -87,6 +87,8 @@ static ERR_STRING_DATA CONF_str_reasons[]=
 {CONF_R_MISSING_EQUAL_SIGN               ,"missing equal sign"},
 {CONF_R_NO_CLOSE_BRACE                   ,"no close brace"},
 {CONF_R_NO_CONF                          ,"no conf"},
+{CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE  ,"no conf or environment variable"},
+{CONF_R_NO_SECTION                       ,"no section"},
 {CONF_R_UNABLE_TO_CREATE_NEW_SECTION     ,"unable to create new section"},
 {CONF_R_VARIABLE_HAS_NO_VALUE            ,"variable has no value"},
 {0,NULL}
index 4c8ca9e9ae4f3df23f798b3aaede9b947f16e433..51bd0db655fa1cbf1c99bb162bd9709f4c01caa8 100644 (file)
@@ -299,27 +299,46 @@ STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section)
                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);
+
+        /* Since we may get a value from an environment variable even
+           if conf is NULL, let's check the value first */
+        if (s) return s;
+
        if (conf == NULL)
                {
-               CONFerr(CONF_F_NCONF_GET_STRING,CONF_R_NO_CONF);
+               CONFerr(CONF_F_NCONF_GET_STRING,
+                        CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE);
                return NULL;
                }
-
-       return _CONF_get_string(conf, group, name);
+       return NULL;
        }
 
 long NCONF_get_number(CONF *conf,char *group,char *name)
        {
+#if 0 /* As with _CONF_get_string(), we rely on the possibility of finding
+         an environment variable with a suitable name.  Unfortunately, there's
+         no way with the current API to see if we found one or not...
+         The meaning of this is that if a number is not found anywhere, it
+         will always default to 0. */
        if (conf == NULL)
                {
-               CONFerr(CONF_F_NCONF_GET_NUMBER,CONF_R_NO_CONF);
+               CONFerr(CONF_F_NCONF_GET_NUMBER,
+                        CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE);
                return 0;
                }
+#endif
        
        return _CONF_get_number(conf, group, name);
        }