From: Timo Sirainen Date: Mon, 24 Sep 2012 14:03:42 +0000 (+0300) Subject: auth ldap: Previous change broke %$ variable. X-Git-Tag: 2.2.alpha1~138^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be83284aff645d005e22817ab144fc598486619a;p=thirdparty%2Fdovecot%2Fcore.git auth ldap: Previous change broke %$ variable. --- diff --git a/src/auth/auth-request.c b/src/auth/auth-request.c index d7a2c1e60d..4181f2ef82 100644 --- a/src/auth/auth-request.c +++ b/src/auth/auth-request.c @@ -1799,15 +1799,22 @@ auth_request_get_var_expand_table_full(const struct auth_request *auth_request, auth_request_escape_func_t *escape_func, unsigned int *count) { - struct var_expand_table *tab; + const unsigned int auth_count = + N_ELEMENTS(auth_request_var_expand_static_tab); + struct var_expand_table *tab, *ret_tab; if (escape_func == NULL) escape_func = escape_none; - *count += N_ELEMENTS(auth_request_var_expand_static_tab); - tab = t_malloc(*count * sizeof(struct var_expand_table)); + /* keep the extra fields at the beginning. the last static_tab field + contains the ending NULL-fields. */ + tab = ret_tab = t_malloc((*count + auth_count) * sizeof(*tab)); + memset(tab, 0, *count * sizeof(*tab)); + tab += *count; + *count += auth_count; + memcpy(tab, auth_request_var_expand_static_tab, - sizeof(auth_request_var_expand_static_tab)); + auth_count * sizeof(*tab)); tab[0].value = escape_func(auth_request->user, auth_request); tab[1].value = escape_func(t_strcut(auth_request->user, '@'), @@ -1854,7 +1861,7 @@ auth_request_get_var_expand_table_full(const struct auth_request *auth_request, } tab[18].value = auth_request->session_id == NULL ? NULL : escape_func(auth_request->session_id, auth_request); - return tab; + return ret_tab; } const struct var_expand_table * diff --git a/src/auth/db-ldap.c b/src/auth/db-ldap.c index 85875c2a6b..0c53c53f54 100644 --- a/src/auth/db-ldap.c +++ b/src/auth/db-ldap.c @@ -1076,8 +1076,8 @@ db_ldap_value_get_var_expand_table(struct auth_request *auth_request, table = auth_request_get_var_expand_table_full(auth_request, NULL, &count); - table[count-1].key = '$'; - table[count-1].value = ldap_value; + table[0].key = '$'; + table[0].value = ldap_value; return table; }