]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dict: Add dict_op_settings
authorSiavash Tavakoli <siavash.tavakoli@open-xchange.com>
Mon, 3 May 2021 12:42:56 +0000 (13:42 +0100)
committerSiavash Tavakoli <siavash.tavakoli@open-xchange.com>
Thu, 1 Jul 2021 19:06:16 +0000 (20:06 +0100)
Used for dict operations. Currently username & home_dir are used. Also, change
dict_lookup() to accept a parameter of this type but don't actually use it.

14 files changed:
src/auth/db-dict.c
src/dict/dict-commands.c
src/doveadm/doveadm-dict.c
src/lib-dict-backend/test-dict-sql.c
src/lib-dict-extra/test-dict-fs.c
src/lib-dict/dict-client.c
src/lib-dict/dict-lua.c
src/lib-dict/dict.c
src/lib-dict/dict.h
src/lib-dict/test-dict-client.c
src/lib-fs/fs-dict.c
src/lib-oauth2/oauth2-jwt.c
src/lib-storage/index/index-attribute.c
src/plugins/quota/quota-dict.c

index e86f0c444d4f52f3c451bafc7a9f14587f37485a..09c357d9a46a96f7bfe0545b29668faa1e326b60 100644 (file)
@@ -415,7 +415,7 @@ static int db_dict_iter_lookup_key_values(struct db_dict_value_iter *iter)
 
                str_truncate(path, strlen(DICT_PATH_SHARED));
                str_append(path, key->key->key);
-               ret = dict_lookup(iter->conn->dict, iter->pool,
+               ret = dict_lookup(iter->conn->dict, NULL, iter->pool,
                                  str_c(path), &key->value, &error);
                if (ret > 0) {
                        e_debug(authdb_event(iter->auth_request),
index 85d2eec70bcaeeede151908db65c7aedc919c4d6..bdb7c40be307c2ff972a03f9243fb5e248600b03 100644 (file)
@@ -224,7 +224,7 @@ static int cmd_lookup(struct dict_connection_cmd *cmd, const char *line)
        /* <key> */
        dict_connection_cmd_async(cmd);
        event_add_str(cmd->event, "key", line);
-       dict_lookup_async(cmd->conn->dict, line, cmd_lookup_callback, cmd);
+       dict_lookup_async(cmd->conn->dict, NULL, line, cmd_lookup_callback, cmd);
        return 1;
 }
 
index dcede048483ac21d39ba73b8cf2abcf2cd79203e..134e762acd97efdd0190900f1ce8ccd804a8fb2e 100644 (file)
@@ -108,7 +108,7 @@ static void cmd_dict_get(struct doveadm_cmd_context *cctx)
        i_zero(&ctx);
        ctx.pool = pool_alloconly_create("doveadm dict lookup", 512);
        ctx.ret = -2;
-       dict_lookup_async(dict, key, dict_lookup_callback, &ctx);
+       dict_lookup_async(dict, NULL, key, dict_lookup_callback, &ctx);
        while (ctx.ret == -2)
                dict_wait(dict);
        if (ctx.ret < 0) {
index 1d16728e36d5a7454a7f1b9632ed66ae400dbd68..ffaa9c6a8e016f86b054069c823ed968b103e0c5 100644 (file)
@@ -64,7 +64,7 @@ static void test_lookup_one(void)
 
        test_set_expected(dict, &res);
 
-       test_assert(dict_lookup(dict, pool, "shared/dictmap/hello/world", &value, &error) == 1);
+       test_assert(dict_lookup(dict, NULL, pool, "shared/dictmap/hello/world", &value, &error) == 1);
        test_assert_strcmp(value, "one");
         if (error != NULL)
                 i_error("dict_lookup failed: %s", error);
index b95a59f79430f6a639962ba196754ec0492c89fe..aa7f67491ec9ece520ec7909494044799ae33340 100644 (file)
@@ -13,7 +13,7 @@ static void test_dict_set_get(struct dict *dict, const char *key,
        dict_set(t, key, value);
        if (dict_transaction_commit(&t, &error) < 0)
                i_fatal("dict_transaction_commit(%s) failed: %s", key, error);
-       if (dict_lookup(dict, pool_datastack_create(), key, &got_value,
+       if (dict_lookup(dict, NULL, pool_datastack_create(), key, &got_value,
                        &error) < 0)
                i_fatal("dict_lookup(%s) failed: %s", key, error);
        test_assert_strcmp(got_value, value);
index 3539e6b920a680bdf73cf9855065232a09efc007..d16ddb4a9aa1d0603975995d032f3705aa819147 100644 (file)
@@ -1006,7 +1006,7 @@ static int client_dict_lookup(struct dict *_dict, pool_t pool, const char *key,
        i_zero(&lookup);
        lookup.ret = -2;
 
-       dict_lookup_async(_dict, key, client_dict_lookup_callback, &lookup);
+       dict_lookup_async(_dict, NULL, key, client_dict_lookup_callback, &lookup);
        if (lookup.ret == -2)
                client_dict_wait(_dict);
 
index 1955722396f763ca6b9b75f777eed7e746ddeb5d..bfd2b5bbbe9c15ee69c92867e7484e5b8e5ed0da 100644 (file)
@@ -77,7 +77,7 @@ static int lua_dict_lookup(lua_State *L)
        dict = xlua_dict_getptr(L, 1, NULL);
        key = luaL_checkstring(L, 2);
 
-       dict_lookup_async(dict, key, lua_dict_lookup_callback, L);
+       dict_lookup_async(dict, NULL, key, lua_dict_lookup_callback, L);
 
        return lua_dict_async_continue(L,
                lua_yieldk(L, 0, 0, lua_dict_async_continue), 0);
index 48f709dd61d92258a4a38384c20fd6cb7e1e8073..250dacb48e4a15eeecc82191ac2ea07b214c3ddb 100644 (file)
@@ -294,7 +294,8 @@ static void dict_commit_callback(const struct dict_commit_result *result,
        }
 }
 
-int dict_lookup(struct dict *dict, pool_t pool, const char *key,
+int dict_lookup(struct dict *dict, const struct dict_op_settings *set ATTR_UNUSED,
+               pool_t pool, const char *key,
                const char **value_r, const char **error_r)
 {
        struct event *event = event_create(dict->event);
@@ -310,15 +311,16 @@ int dict_lookup(struct dict *dict, pool_t pool, const char *key,
 }
 
 #undef dict_lookup_async
-void dict_lookup_async(struct dict *dict, const char *key,
-                      dict_lookup_callback_t *callback, void *context)
+void dict_lookup_async(struct dict *dict, const struct dict_op_settings *set ATTR_UNUSED,
+                      const char *key, dict_lookup_callback_t *callback,
+                      void *context)
 {
        if (dict->v.lookup_async == NULL) {
                struct dict_lookup_result result;
 
                i_zero(&result);
                /* event is going to be sent by dict_lookup */
-               result.ret = dict_lookup(dict, pool_datastack_create(),
+               result.ret = dict_lookup(dict, NULL, pool_datastack_create(),
                                         key, &result.value, &result.error);
                const char *const values[] = { result.value, NULL };
                result.values = values;
index 194bcb4758003a111fe831053f40ce265f50608b..9b48376c57c2b2b538ff3ed6deb95b2140553138 100644 (file)
@@ -40,6 +40,12 @@ struct dict_settings {
        struct event *event_parent;
 };
 
+struct dict_op_settings {
+       const char *username;
+       /* home directory for the user, if known */
+       const char *home_dir;
+};
+
 struct dict_lookup_result {
        int ret;
 
@@ -97,12 +103,13 @@ bool dict_switch_ioloop(struct dict *dict) ATTR_NOWARN_UNUSED_RESULT;
 
 /* Lookup value for key. Set it to NULL if it's not found.
    Returns 1 if found, 0 if not found and -1 if lookup failed. */
-int dict_lookup(struct dict *dict, pool_t pool,
+int dict_lookup(struct dict *dict, const struct dict_op_settings *set, pool_t pool,
                const char *key, const char **value_r, const char **error_r);
-void dict_lookup_async(struct dict *dict, const char *key,
-                      dict_lookup_callback_t *callback, void *context);
-#define dict_lookup_async(dict, key, callback, context) \
-       dict_lookup_async(dict, key, (dict_lookup_callback_t *)(callback), \
+void dict_lookup_async(struct dict *dict, const struct dict_op_settings *set,
+                      const char *key, dict_lookup_callback_t *callback,
+                      void *context);
+#define dict_lookup_async(dict, set, key, callback, context) \
+       dict_lookup_async(dict, set, key, (dict_lookup_callback_t *)(callback), \
                1 ? (context) : \
                CALLBACK_TYPECHECK(callback, \
                        void (*)(const struct dict_lookup_result *, typeof(context))))
index 80607ed1d7bab792e29b443241fd6372572750c7..74e58c066d7f5e2887428142ce5075d097f40e64 100644 (file)
@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
                switch (i_rand_limit(4)) {
                case 0:
                        pending++;
-                       dict_lookup_async(dict, key, lookup_callback, NULL);
+                       dict_lookup_async(dict, NULL, key, lookup_callback, NULL);
                        break;
                case 1: {
                        struct dict_transaction_context *trans;
index 6a0a8bd026ed7d16a75ed4252d528cbe18c9dbbb..172236ffbefbafc6d64280e29cc558d017369d90 100644 (file)
@@ -157,7 +157,7 @@ static int fs_dict_lookup(struct dict_fs_file *file)
        if (file->value != NULL)
                return 0;
 
-       ret = dict_lookup(fs->dict, file->pool, file->key, &file->value, &error);
+       ret = dict_lookup(fs->dict, NULL, file->pool, file->key, &file->value, &error);
        if (ret > 0)
                return 0;
        else if (ret < 0) {
index 6dd09be4d39d101c1ca2428a4683917f72e8ae18..6e850c693717db86993944268fab7fe8c4613ac6 100644 (file)
@@ -98,7 +98,7 @@ oauth2_lookup_hmac_key(const struct oauth2_settings *set, const char *azp,
        /* do a synchronous dict lookup */
        lookup_key = t_strconcat(DICT_PATH_SHARED, azp, "/", alg, "/", key_id,
                                 NULL);
-       if ((ret = dict_lookup(set->key_dict, pool_datastack_create(),
+       if ((ret = dict_lookup(set->key_dict, NULL, pool_datastack_create(),
                               lookup_key, &base64_key, error_r)) < 0) {
                return -1;
        } else if (ret == 0) {
@@ -178,7 +178,7 @@ oauth2_lookup_pubkey(const struct oauth2_settings *set, const char *azp,
        /* do a synchronous dict lookup */
        lookup_key = t_strconcat(DICT_PATH_SHARED, azp, "/", alg, "/", key_id,
                                 NULL);
-       if ((ret = dict_lookup(set->key_dict, pool_datastack_create(),
+       if ((ret = dict_lookup(set->key_dict, NULL, pool_datastack_create(),
                               lookup_key, &key_str, error_r)) < 0) {
                return -1;
        } else if (ret == 0) {
index 8aef8c89c71226855014f9320ee05dc0ea2bb98f..e7d20888d6c556e6469146dd3cea05ce837136d1 100644 (file)
@@ -257,7 +257,7 @@ int index_storage_attribute_get(struct mailbox *box,
        if (index_storage_get_dict(box, type_flags, &dict, &mailbox_prefix) < 0)
                return -1;
 
-       ret = dict_lookup(dict, pool_datastack_create(),
+       ret = dict_lookup(dict, NULL, pool_datastack_create(),
                          key_get_prefixed(type_flags, mailbox_prefix, key),
                          &value_r->value, &error);
        if (ret < 0) {
index 10f608f09fa2f7f189b2645b719f24b5c5af0806..e4a9729ae8d5158f18891001510494ca2125d87c 100644 (file)
@@ -160,7 +160,7 @@ dict_quota_get_resource(struct quota_root *_root,
        const char *key, *value, *error;
        key = want_bytes ? DICT_QUOTA_CURRENT_BYTES_PATH :
                DICT_QUOTA_CURRENT_COUNT_PATH;
-       ret = dict_lookup(root->dict, unsafe_data_stack_pool,
+       ret = dict_lookup(root->dict, NULL, unsafe_data_stack_pool,
                          key, &value, &error);
        if (ret < 0) {
                *error_r = t_strdup_printf(