]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap-hibernate: Support userdb in var_expand
authorAki Tuomi <aki.tuomi@dovecot.fi>
Thu, 23 Feb 2017 09:47:20 +0000 (11:47 +0200)
committerGitLab <gitlab@git.dovecot.net>
Tue, 28 Feb 2017 07:25:17 +0000 (09:25 +0200)
src/imap-hibernate/imap-client.c

index e6c7072d8c28102e46c9e2ff63d68ffb896f8112..43b369a8afd23cafa0f5805757409404a5bbe3ff 100644 (file)
@@ -482,6 +482,27 @@ imap_client_get_var_expand_table(struct imap_client *client)
        return tab;
 }
 
+static int
+imap_client_var_expand_func_userdb(const char *data, void *context,
+                                  const char **value_r, const char **error_r ATTR_UNUSED)
+{
+       const char *const *fields = (const char *const *)context;
+       const char *field_name = t_strdup_printf("%s=",t_strcut(data, ':'));
+       const char *default_value = i_strchr_to_next(data, ':');
+       const char *value = NULL;
+
+       for(;*fields != NULL; fields++) {
+               if (strncmp(*fields, field_name, strlen(field_name)) == 0) {
+                       value = *fields+strlen(field_name);
+                       break;
+               }
+       }
+
+       *value_r = value != NULL ? value : default_value;
+
+       return 1;
+}
+
 static void imap_client_io_activate_user(struct imap_client *client)
 {
        i_set_failure_prefix("%s", client->log_prefix);
@@ -503,6 +524,10 @@ static const char *imap_client_get_anvil_userip_ident(struct imap_client_state *
 struct imap_client *
 imap_client_create(int fd, const struct imap_client_state *state)
 {
+       const struct var_expand_func_table funcs[] = {
+               { "userdb", imap_client_var_expand_func_userdb },
+               { NULL, NULL }
+       };
        struct imap_client *client;
        pool_t pool = pool_alloconly_create("imap client", 256);
        void *statebuf;
@@ -531,11 +556,12 @@ imap_client_create(int fd, const struct imap_client_state *state)
        }
        T_BEGIN {
                string_t *str;
-
+               const char *const *fields =
+                       t_strsplit_tabescaped(client->state.userdb_fields);
                str = t_str_new(256);
-               if (var_expand(str, state->mail_log_prefix,
-                              imap_client_get_var_expand_table(client),
-                              &error) <= 0) {
+               if (var_expand_with_funcs(str, state->mail_log_prefix,
+                                         imap_client_get_var_expand_table(client),
+                                         funcs, (void*)fields, &error) <= 0) {
                        i_error("Failed to expand mail_log_prefix=%s: %s",
                                state->mail_log_prefix, error);
                }