Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion changes-entries/65172.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
and AuthDBDUserRealmQuery columns, exported as AUTHENTICATE_<NAME>
environment variables, on a login answered from the cache
(AuthBasicProvider/AuthDigestProvider "socache dbd"). Previously only
the first, uncached login for a user had them. PR 65172.
the first, uncached login for a user had them. A column which is
NULL now sets its variable to an empty value. PR 65172.
[Arturo Bernal]
14 changes: 8 additions & 6 deletions modules/aaa/mod_authn_dbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static authn_status authn_dbd_password(request_rec *r, const char *user,
if (dbd_password == NULL) {
/* add the rest of the columns to the environment */
int i = 1;
const char *name;
const char *name, *value;
for (name = apr_dbd_get_name(dbd->driver, res, i);
name != NULL;
name = apr_dbd_get_name(dbd->driver, res, i)) {
Expand All @@ -181,8 +181,9 @@ static authn_status authn_dbd_password(request_rec *r, const char *user,
if (env == NULL) {
env = apr_table_make(r->pool, 2);
}
apr_table_set(env, str,
apr_dbd_get_entry(dbd->driver, row, i));
/* a NULL column is set as an empty value */
value = apr_dbd_get_entry(dbd->driver, row, i);
apr_table_set(env, str, value ? value : "");
i++;
}

Expand Down Expand Up @@ -262,7 +263,7 @@ static authn_status authn_dbd_realm(request_rec *r, const char *user,
if (dbd_hash == NULL) {
/* add the rest of the columns to the environment */
int i = 1;
const char *name;
const char *name, *value;
for (name = apr_dbd_get_name(dbd->driver, res, i);
name != NULL;
name = apr_dbd_get_name(dbd->driver, res, i)) {
Expand All @@ -283,8 +284,9 @@ static authn_status authn_dbd_realm(request_rec *r, const char *user,
if (env == NULL) {
env = apr_table_make(r->pool, 2);
}
apr_table_set(env, str,
apr_dbd_get_entry(dbd->driver, row, i));
/* a NULL column is set as an empty value */
value = apr_dbd_get_entry(dbd->driver, row, i);
apr_table_set(env, str, value ? value : "");
i++;
}

Expand Down
5 changes: 4 additions & 1 deletion test/modules/aaa/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class AAATestEnv(HttpdTestEnv):
# A role too long to be cached with the password hash.
DBD_LONG_USER = "dbdlonguser"
DBD_LONG_ROLE = "r" * 300
# A user whose role column is SQL NULL.
DBD_NULL_USER = "dbdnulluser"

def __init__(self, pytestconfig=None):
super().__init__(pytestconfig=pytestconfig)
Expand All @@ -68,7 +70,8 @@ def _write_dbd_file(self):
digest = hashlib.sha1(self.DBD_PASSWORD.encode()).digest()
pw_hash = "{SHA}" + base64.b64encode(digest).decode()
for user, role in [(self.DBD_USER, self.DBD_ROLE),
(self.DBD_LONG_USER, self.DBD_LONG_ROLE)]:
(self.DBD_LONG_USER, self.DBD_LONG_ROLE),
(self.DBD_NULL_USER, None)]:
con.execute("INSERT INTO users (user, password, role) "
"VALUES (?, ?, ?)", (user, pw_hash, role))
con.commit()
Expand Down
1 change: 1 addition & 0 deletions test/modules/aaa/htdocs/dbd/cgi/whoami.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
print("Content-Type: text/plain\n")
print(f"user={os.environ.get('REMOTE_USER', '')}")
print(f"role={os.environ.get('AUTHENTICATE_ROLE', '')}")
print(f"role_set={'AUTHENTICATE_ROLE' in os.environ}")
11 changes: 11 additions & 0 deletions test/modules/aaa/test_018_authn_dbd_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,14 @@ def test_authn_dbd_018_long_role_not_cached(self, env):
assert f"user={user}" in body
assert f"role={AAATestEnv.DBD_LONG_ROLE}" in body, \
f"AUTHENTICATE_ROLE missing: {body!r}"

def test_authn_dbd_018_null_role_cached(self, env):
# A NULL role column sets AUTHENTICATE_ROLE to an empty value, on
# the first login and on the cache hit that follows it, rather than
# crashing the child.
user = AAATestEnv.DBD_NULL_USER
for _ in range(2):
body = self.whoami(env, user=user)
assert f"user={user}" in body
assert "role=\nrole_set=True\n" in body, \
f"AUTHENTICATE_ROLE not set and empty: {body!r}"
Loading