]> granicus.if.org Git - apache/commitdiff
allow empty user ids to be supplied without responding a 500.
authorAndré Malo <nd@apache.org>
Sun, 5 Jan 2003 06:36:29 +0000 (06:36 +0000)
committerAndré Malo <nd@apache.org>
Sun, 5 Jan 2003 06:36:29 +0000 (06:36 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@98165 13f79535-47bb-0310-9956-ffa450edef68

modules/aaa/mod_authn_dbm.c

index cf704a376abc8386f9311ff82c33213376e249ea..164e032f24b01ab899508c76d6b8c32f519f25e4 100644 (file)
@@ -119,12 +119,12 @@ static const command_rec authn_dbm_cmds[] =
 
 module AP_MODULE_DECLARE_DATA authn_dbm_module;
 
-static apr_status_t fetch_dbm(const char *dbmtype, const char *dbmfile,
-                              const char *user, apr_datum_t *val,
-                              apr_pool_t *pool)
+static apr_status_t fetch_dbm_value(const char *dbmtype, const char *dbmfile,
+                                    const char *user, char **value,
+                                    apr_pool_t *pool)
 {
     apr_dbm_t *f;
-    apr_datum_t key;
+    apr_datum_t key, val;
     apr_status_t rv;
 
     rv = apr_dbm_open_ex(&f, dbmtype, dbmfile, APR_DBM_READONLY, 
@@ -141,7 +141,11 @@ static apr_status_t fetch_dbm(const char *dbmtype, const char *dbmfile,
     key.dsize = strlen(key.dptr) + 1;
 #endif
 
-    rv = apr_dbm_fetch(f, key, val);
+    *value = NULL;
+
+    if (apr_dbm_fetch(f, key, &val) == APR_SUCCESS && val.dptr) {
+        *value = apr_pstrmemdup(pool, val.dptr, val.dsize);
+    }
 
     apr_dbm_close(f);
     
@@ -153,12 +157,12 @@ static authn_status check_dbm_pw(request_rec *r, const char *user,
 {
     authn_dbm_config_rec *conf = ap_get_module_config(r->per_dir_config,
                                                       &authn_dbm_module);
-    apr_datum_t dbm_pw;
     apr_status_t rv;
-    char *dbm_password = NULL;
+    char *dbm_password;
     char *colon_pw;
 
-    rv = fetch_dbm(conf->dbmtype, conf->pwfile, user, &dbm_pw, r->pool);
+    rv = fetch_dbm_value(conf->dbmtype, conf->pwfile, user, &dbm_password,
+                         r->pool);
 
     if (rv != APR_SUCCESS) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
@@ -167,10 +171,6 @@ static authn_status check_dbm_pw(request_rec *r, const char *user,
         return AUTH_GENERAL_ERROR;
     }
 
-    if (dbm_pw.dptr) {
-        dbm_password = apr_pstrmemdup(r->pool, dbm_pw.dptr, dbm_pw.dsize);
-    }
-
     if (!dbm_password) {
         return AUTH_USER_NOT_FOUND;
     }
@@ -194,14 +194,13 @@ static authn_status get_dbm_realm_hash(request_rec *r, const char *user,
 {
     authn_dbm_config_rec *conf = ap_get_module_config(r->per_dir_config,
                                                       &authn_dbm_module);
-    apr_datum_t dbm_hd;
     apr_status_t rv;
-    char *dbm_hash = NULL;
+    char *dbm_hash;
     char *colon_hash;
 
-    rv = fetch_dbm(conf->dbmtype, conf->pwfile,
-                   apr_pstrcat(r->pool, user, ":", realm, NULL),
-                   &dbm_hd, r->pool);
+    rv = fetch_dbm_value(conf->dbmtype, conf->pwfile,
+                         apr_pstrcat(r->pool, user, ":", realm, NULL),
+                         &dbm_hash, r->pool);
 
     if (rv != APR_SUCCESS) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
@@ -210,10 +209,6 @@ static authn_status get_dbm_realm_hash(request_rec *r, const char *user,
         return AUTH_GENERAL_ERROR;
     }
 
-    if (dbm_hd.dptr) {
-        dbm_hash = apr_pstrmemdup(r->pool, dbm_hd.dptr, dbm_hd.dsize);
-    }
-
     if (!dbm_hash) {
         return AUTH_USER_NOT_FOUND;
     }