]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth ldap: Previous change broke %$ variable.
authorTimo Sirainen <tss@iki.fi>
Mon, 24 Sep 2012 14:03:42 +0000 (17:03 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 24 Sep 2012 14:03:42 +0000 (17:03 +0300)
src/auth/auth-request.c
src/auth/db-ldap.c

index d7a2c1e60dbaeae8fadfa95b0f1eaf3f346f4554..4181f2ef820039a0b065ce8489538889e498f387 100644 (file)
@@ -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 *
index 85875c2a6b22c0eaa34c3cbf4bd8811a16dc4360..0c53c53f5453e31552003bb287aa6c1b1042dfa9 100644 (file)
@@ -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;
 }