]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth-db-dict: Allow key name expansion
authorAki Tuomi <aki.tuomi@dovecot.fi>
Wed, 13 Jul 2016 06:51:08 +0000 (09:51 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 15 Aug 2016 13:24:07 +0000 (16:24 +0300)
This allows expansion of dictionary keys based on userdb
variables on dict lookup mapping. Example:
key userdb {
  key = %{userdb:nspace:default}/userdb
  format = json
}

src/auth/db-dict.c

index 6720de150d86c29c275b64b0cb46c3de3d1f3158..138ac0dc33d6c30a5cfd9062aac10ba7b99d6a31 100644 (file)
@@ -457,7 +457,14 @@ int db_dict_value_iter_init(struct dict_connection *conn,
        p_array_init(&iter->keys, pool, array_count(&conn->set.keys));
        array_foreach(&conn->set.keys, key) {
                iterkey = array_append_space(&iter->keys);
-               iterkey->key = key;
+               struct db_dict_key *new_key = p_new(iter->pool, struct db_dict_key, 1);
+               memcpy(new_key, key, sizeof(struct db_dict_key));
+               string_t *expanded_key = str_new(iter->pool, strlen(key->key));
+               auth_request_var_expand_with_table(expanded_key, key->key, auth_request,
+                                                  iter->var_expand_table,
+                                                  NULL);
+               new_key->key = str_c(expanded_key);
+               iterkey->key = new_key;
        }
        T_BEGIN {
                db_dict_iter_find_used_keys(iter);