From: Timo Sirainen Date: Mon, 3 Aug 2020 13:18:00 +0000 (+0300) Subject: auth: auth_request_get_var_expand_table_full() - Add username parameter X-Git-Tag: 2.3.13~332 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aa2199918036fcef239298d306da84b943b88e4d;p=thirdparty%2Fdovecot%2Fcore.git auth: auth_request_get_var_expand_table_full() - Add username parameter --- diff --git a/src/auth/auth-policy.c b/src/auth/auth-policy.c index 397fa18c50..bd4300ad85 100644 --- a/src/auth/auth-policy.c +++ b/src/auth/auth-policy.c @@ -468,8 +468,8 @@ const struct var_expand_table *policy_get_var_expand_table(struct auth_request * struct var_expand_table *table; unsigned int count = 2; - table = auth_request_get_var_expand_table_full(auth_request, auth_policy_escape_function, - &count); + table = auth_request_get_var_expand_table_full(auth_request, + auth_request->fields.user, auth_policy_escape_function, &count); table[0].key = '\0'; table[0].long_key = "hashed_password"; table[0].value = hashed_password; diff --git a/src/auth/auth-request-var-expand.c b/src/auth/auth-request-var-expand.c index 65eac76733..04d774e54e 100644 --- a/src/auth/auth-request-var-expand.c +++ b/src/auth/auth-request-var-expand.c @@ -82,6 +82,7 @@ auth_request_str_escape(const char *string, struct var_expand_table * auth_request_get_var_expand_table_full(const struct auth_request *auth_request, + const char *username, auth_request_escape_func_t *escape_func, unsigned int *count) { @@ -89,7 +90,7 @@ auth_request_get_var_expand_table_full(const struct auth_request *auth_request, const unsigned int auth_count = N_ELEMENTS(auth_request_var_expand_static_tab); struct var_expand_table *tab, *ret_tab; - const char *orig_user, *auth_user, *username; + const char *orig_user, *auth_user; if (escape_func == NULL) escape_func = escape_none; @@ -104,7 +105,8 @@ auth_request_get_var_expand_table_full(const struct auth_request *auth_request, memcpy(tab, auth_request_var_expand_static_tab, auth_count * sizeof(*tab)); - username = fields->user != NULL ? fields->user : ""; + if (username == NULL) + username = ""; tab[0].value = escape_func(username, auth_request); tab[1].value = escape_func(t_strcut(username, '@'), auth_request); @@ -209,8 +211,8 @@ auth_request_get_var_expand_table(const struct auth_request *auth_request, { unsigned int count = 0; - return auth_request_get_var_expand_table_full(auth_request, escape_func, - &count); + return auth_request_get_var_expand_table_full(auth_request, + auth_request->fields.user, escape_func, &count); } static const char *field_get_default(const char *data) diff --git a/src/auth/auth-request-var-expand.h b/src/auth/auth-request-var-expand.h index ddad1d4d35..57e18a8add 100644 --- a/src/auth/auth-request-var-expand.h +++ b/src/auth/auth-request-var-expand.h @@ -20,8 +20,9 @@ auth_request_get_var_expand_table(const struct auth_request *auth_request, ATTR_NULL(2); struct var_expand_table * auth_request_get_var_expand_table_full(const struct auth_request *auth_request, + const char *username, auth_request_escape_func_t *escape_func, - unsigned int *count) ATTR_NULL(2); + unsigned int *count) ATTR_NULL(3); int auth_request_var_expand(string_t *dest, const char *str, const struct auth_request *auth_request, diff --git a/src/auth/db-ldap.c b/src/auth/db-ldap.c index 0a377ca014..60a3af4897 100644 --- a/src/auth/db-ldap.c +++ b/src/auth/db-ldap.c @@ -1473,8 +1473,8 @@ db_ldap_value_get_var_expand_table(struct auth_request *auth_request, struct var_expand_table *table; unsigned int count = 1; - table = auth_request_get_var_expand_table_full(auth_request, NULL, - &count); + table = auth_request_get_var_expand_table_full(auth_request, + auth_request->fields.user, NULL, &count); table[0].key = '$'; table[0].value = ldap_value; return table; diff --git a/src/auth/db-oauth2.c b/src/auth/db-oauth2.c index f681eb73cd..2e2f73aa58 100644 --- a/src/auth/db-oauth2.c +++ b/src/auth/db-oauth2.c @@ -409,8 +409,8 @@ db_oauth2_value_get_var_expand_table(struct auth_request *auth_request, struct var_expand_table *table; unsigned int count = 1; - table = auth_request_get_var_expand_table_full(auth_request, NULL, - &count); + table = auth_request_get_var_expand_table_full(auth_request, + auth_request->fields.user, NULL, &count); table[0].key = '$'; table[0].value = oauth2_value; return table;