Skip to content

Commit

Permalink
auth: Fix handling passdbs with identical driver/args but different m…
Browse files Browse the repository at this point in the history
…echanisms/username_filter

The passdb was wrongly deduplicated in this situation, causing wrong
mechanisms or username_filter setting to be used. This would be a rather
unlikely configuration though.

Fixed by moving mechanisms and username_filter from struct passdb_module
to struct auth_passdb, which is where they should have been in the first
place.
  • Loading branch information
sirainen authored and cmouse committed Jul 6, 2022
1 parent 837465a commit 7bad6a2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/auth/auth-request.c
Expand Up @@ -534,8 +534,8 @@ auth_request_want_skip_passdb(struct auth_request *request,
struct auth_passdb *passdb)
{
/* if mechanism is not supported, skip */
const char *const *mechs = passdb->passdb->mechanisms;
const char *const *username_filter = passdb->passdb->username_filter;
const char *const *mechs = passdb->mechanisms;
const char *const *username_filter = passdb->username_filter;
const char *username;

username = request->fields.user;
Expand All @@ -548,7 +548,7 @@ auth_request_want_skip_passdb(struct auth_request *request,
return TRUE;
}

if (passdb->passdb->username_filter != NULL &&
if (passdb->username_filter != NULL &&
!auth_request_username_accepted(username_filter, username)) {
auth_request_log_debug(request,
request->mech != NULL ? AUTH_SUBSYS_MECH
Expand Down
18 changes: 18 additions & 0 deletions src/auth/auth.c
Expand Up @@ -99,6 +99,24 @@ auth_passdb_preinit(struct auth *auth, const struct auth_passdb_settings *set,
auth_passdb->override_fields_tmpl =
passdb_template_build(auth->pool, set->override_fields);

if (*set->mechanisms == '\0') {
auth_passdb->mechanisms = NULL;
} else if (strcasecmp(set->mechanisms, "none") == 0) {
auth_passdb->mechanisms = (const char *const[]){ NULL };
} else {
auth_passdb->mechanisms =
(const char *const *)p_strsplit_spaces(auth->pool,
set->mechanisms, " ,");
}

if (*set->username_filter == '\0') {
auth_passdb->username_filter = NULL;
} else {
auth_passdb->username_filter =
(const char *const *)p_strsplit_spaces(auth->pool,
set->username_filter, " ,");
}

/* for backwards compatibility: */
if (set->pass)
auth_passdb->result_success = AUTH_DB_RULE_CONTINUE;
Expand Down
5 changes: 5 additions & 0 deletions src/auth/auth.h
Expand Up @@ -41,6 +41,11 @@ struct auth_passdb {
struct passdb_template *default_fields_tmpl;
struct passdb_template *override_fields_tmpl;

/* Supported authentication mechanisms, NULL is all, {NULL} is none */
const char *const *mechanisms;
/* Username filter, NULL is no filter */
const char *const *username_filter;

enum auth_passdb_skip skip;
enum auth_db_rule result_success;
enum auth_db_rule result_failure;
Expand Down
15 changes: 2 additions & 13 deletions src/auth/passdb.c
Expand Up @@ -224,19 +224,8 @@ passdb_preinit(pool_t pool, const struct auth_passdb_settings *set)
passdb->id = ++auth_passdb_id;
passdb->iface = *iface;
passdb->args = p_strdup(pool, set->args);
if (*set->mechanisms == '\0') {
passdb->mechanisms = NULL;
} else if (strcasecmp(set->mechanisms, "none") == 0) {
passdb->mechanisms = (const char *const[]){NULL};
} else {
passdb->mechanisms = (const char* const*)p_strsplit_spaces(pool, set->mechanisms, " ,");
}

if (*set->username_filter == '\0') {
passdb->username_filter = NULL;
} else {
passdb->username_filter = (const char* const*)p_strsplit_spaces(pool, set->username_filter, " ,");
}
/* NOTE: if anything else than driver & args are added here,
passdb_find() also needs to be updated. */
array_push_back(&passdb_modules, &passdb);
return passdb;
}
Expand Down
4 changes: 0 additions & 4 deletions src/auth/passdb.h
Expand Up @@ -63,10 +63,6 @@ struct passdb_module {
/* Default password scheme for this module.
If default_cache_key is set, must not be NULL. */
const char *default_pass_scheme;
/* Supported authentication mechanisms, NULL is all, [NULL] is none*/
const char *const *mechanisms;
/* Username filter, NULL is no filter */
const char *const *username_filter;

/* If blocking is set to TRUE, use child processes to access
this passdb. */
Expand Down

0 comments on commit 7bad6a2

Please sign in to comment.