]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
global: Try to initialize var_expand_tab[] directly.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 20 Oct 2016 09:39:27 +0000 (12:39 +0300)
committerGitLab <gitlab@git.dovecot.net>
Thu, 20 Oct 2016 15:53:36 +0000 (18:53 +0300)
This avoids accidents with the array numbering being wrong.

13 files changed:
src/imap-hibernate/imap-client.c
src/imap/imap-client.c
src/lib-lda/mail-deliver.c
src/lib-lda/mail-send.c
src/lib-mail/mail-user-hash.c
src/lib-storage/index/shared/shared-storage.c
src/lib-storage/mail-storage-service.c
src/lib-storage/mail-user.c
src/login-common/client-common.c
src/login-common/login-settings.c
src/plugins/acl/acl-shared-storage.c
src/pop3/pop3-client.c
src/pop3/pop3-commands.c

index 90cb18d3ade1ca76c54c30485bb1ebc78c0f2ac0..c511698c2e36013dab15c97579b01f8bffed1adc 100644 (file)
@@ -436,55 +436,47 @@ static void imap_client_add_idle_keepalive_timeout(struct imap_client *client)
 static const struct var_expand_table *
 imap_client_get_var_expand_table(struct imap_client *client)
 {
-       static struct var_expand_table static_tab[] = {
-               { 'u', NULL, "user" },
-               { 'n', NULL, "username" },
-               { 'd', NULL, "domain" },
-               { 's', NULL, "service" },
-               { 'h', NULL, "home" },
-               { 'l', NULL, "lip" },
-               { 'r', NULL, "rip" },
-               { 'p', NULL, "pid" },
-               { 'i', NULL, "uid" },
-               { '\0', NULL, "gid" },
-               { '\0', NULL, "session" },
-               { '\0', NULL, "auth_user" },
-               { '\0', NULL, "auth_username" },
-               { '\0', NULL, "auth_domain" },
-               /* NOTE: keep this synced with lib-storage's
-                  mail_user_var_expand_table() */
-               { '\0', NULL, NULL }
-       };
-       struct var_expand_table *tab;
-       const char *auth_user;
-
-       tab = t_malloc_no0(sizeof(static_tab));
-       memcpy(tab, static_tab, sizeof(static_tab));
-
-       tab[0].value = client->state.username;
-       tab[1].value = t_strcut(client->state.username, '@');
-       tab[2].value = i_strchr_to_next(client->state.username, '@');
-       tab[3].value = "imap-hibernate";
-       tab[4].value = NULL; /* we shouldn't need this */
-       tab[5].value = client->state.local_ip.family == 0 ? NULL :
+       const char *username = t_strcut(client->state.username, '@');
+       const char *domain = i_strchr_to_next(client->state.username, '@');
+       const char *local_ip = client->state.local_ip.family == 0 ? NULL :
                net_ip2addr(&client->state.local_ip);
-       tab[6].value = client->state.remote_ip.family == 0 ? NULL :
+       const char *remote_ip = client->state.remote_ip.family == 0 ? NULL :
                net_ip2addr(&client->state.remote_ip);
-       tab[7].value = my_pid;
-       tab[8].value = dec2str(client->state.uid);
-       tab[9].value = dec2str(client->state.gid);
-       tab[10].value = client->state.session_id;
 
+       const char *auth_user, *auth_username, *auth_domain;
        imap_client_parse_userdb_fields(client, &auth_user);
        if (auth_user == NULL) {
-               tab[11].value = tab[0].value;
-               tab[12].value = tab[1].value;
-               tab[13].value = tab[2].value;
+               auth_user = client->state.username;
+               auth_username = username;
+               auth_domain = domain;
        } else {
-               tab[11].value = auth_user;
-               tab[12].value = t_strcut(auth_user, '@');
-               tab[13].value = i_strchr_to_next(auth_user, '@');
-       }
+               auth_username = t_strcut(auth_user, '@');
+               auth_domain = i_strchr_to_next(auth_user, '@');
+       }
+
+       const struct var_expand_table stack_tab[] = {
+               { 'u', client->state.username, "user" },
+               { 'n', username, "username" },
+               { 'd', domain, "domain" },
+               { 's', "imap-hibernate", "service" },
+               { 'h', NULL /* we shouldn't need this */, "home" },
+               { 'l', local_ip, "lip" },
+               { 'r', remote_ip, "rip" },
+               { 'p', my_pid, "pid" },
+               { 'i', dec2str(client->state.uid), "uid" },
+               { '\0', dec2str(client->state.gid), "gid" },
+               { '\0', client->state.session_id, "session" },
+               { '\0', auth_user, "auth_user" },
+               { '\0', auth_username, "auth_username" },
+               { '\0', auth_domain, "auth_domain" },
+               /* NOTE: keep this synced with lib-storage's
+                  mail_user_var_expand_table() */
+               { '\0', NULL, NULL }
+       };
+       struct var_expand_table *tab;
+
+       tab = t_malloc_no0(sizeof(stack_tab));
+       memcpy(tab, stack_tab, sizeof(stack_tab));
        return tab;
 }
 
index 1ba81bfe75e75c71b83fc2d7b9306a28a0f1d320..c6000b3518fb687fabf236f830f72c6885b62ba2 100644 (file)
@@ -237,36 +237,21 @@ void client_command_cancel(struct client_command_context **_cmd)
 
 const char *client_stats(struct client *client)
 {
-       static struct var_expand_table static_tab[] = {
-               { 'i', NULL, "input" },
-               { 'o', NULL, "output" },
-               { '\0', NULL, "session" },
-               { '\0', NULL, "fetch_hdr_count" },
-               { '\0', NULL, "fetch_hdr_bytes" },
-               { '\0', NULL, "fetch_body_count" },
-               { '\0', NULL, "fetch_body_bytes" },
-               { '\0', NULL, "deleted" },
-               { '\0', NULL, "expunged" },
-               { '\0', NULL, "trashed" },
+       const struct var_expand_table tab[] = {
+               { 'i', dec2str(i_stream_get_absolute_offset(client->input)), "input" },
+               { 'o', dec2str(client->output->offset), "output" },
+               { '\0', client->session_id, "session" },
+               { '\0', dec2str(client->fetch_hdr_count), "fetch_hdr_count" },
+               { '\0', dec2str(client->fetch_hdr_bytes), "fetch_hdr_bytes" },
+               { '\0', dec2str(client->fetch_body_count), "fetch_body_count" },
+               { '\0', dec2str(client->fetch_body_bytes), "fetch_body_bytes" },
+               { '\0', dec2str(client->deleted_count), "deleted" },
+               { '\0', dec2str(client->expunged_count), "expunged" },
+               { '\0', dec2str(client->trashed_count), "trashed" },
                { '\0', NULL, NULL }
        };
-       struct var_expand_table *tab;
        string_t *str;
 
-       tab = t_malloc_no0(sizeof(static_tab));
-       memcpy(tab, static_tab, sizeof(static_tab));
-
-       tab[0].value = dec2str(i_stream_get_absolute_offset(client->input));
-       tab[1].value = dec2str(client->output->offset);
-       tab[2].value = client->session_id;
-       tab[3].value = dec2str(client->fetch_hdr_count);
-       tab[4].value = dec2str(client->fetch_hdr_bytes);
-       tab[5].value = dec2str(client->fetch_body_count);
-       tab[6].value = dec2str(client->fetch_body_bytes);
-       tab[7].value = dec2str(client->deleted_count);
-       tab[8].value = dec2str(client->expunged_count);
-       tab[9].value = dec2str(client->trashed_count);
-
        str = t_str_new(128);
        var_expand(str, client->set->imap_logout_format, tab);
        return str_c(str);
index 99fdd35103e61d2b074955b4cffdabf7562217f1..4f753de7dfe3f7667adc4d64855786d4863fd540 100644 (file)
@@ -43,13 +43,13 @@ static void
 mail_deliver_log_var_expand_table_update_times(struct mail_deliver_context *ctx,
                                               struct var_expand_table *tab)
 {
-#define VAR_EXPAND_SESSION_TIME_IDX 7
+#define VAR_EXPAND_DELIVERY_TIME_IDX 7
        int delivery_time_msecs;
 
        io_loop_time_refresh();
        delivery_time_msecs = timeval_diff_msecs(&ioloop_timeval,
                                                 &ctx->delivery_time_started);
-       tab[VAR_EXPAND_SESSION_TIME_IDX].value = dec2str(delivery_time_msecs);
+       tab[VAR_EXPAND_DELIVERY_TIME_IDX].value = dec2str(delivery_time_msecs);
 }
 
 static const struct var_expand_table *
@@ -57,50 +57,54 @@ mail_deliver_get_log_var_expand_table_full(struct mail_deliver_context *ctx,
                                           struct mail *mail,
                                           const char *message)
 {
-       static struct var_expand_table static_tab[] = {
-               { '$', NULL, NULL },
-               { 'm', NULL, "msgid" },
-               { 's', NULL, "subject" },
-               { 'f', NULL, "from" },
-               { 'e', NULL, "from_envelope" },
-               { 'p', NULL, "size" },
-               { 'w', NULL, "vsize" },
-               { '\0', NULL, "delivery_time" },
-               { '\0', NULL, "session_time" },
-               { '\0', NULL, "to_envelope" },
-               { '\0', NULL, "storage_id" },
-               { '\0', NULL, NULL }
-       };
-       struct var_expand_table *tab;
-       const char *str;
+       const char *message_id, *subject = NULL, *from_envelope = NULL;
+       const char *from, *psize = NULL, *vsize = NULL, *storage_id = NULL;
+       const char *session_time = NULL, *to_envelope = NULL;
        uoff_t size;
 
-       tab = t_malloc_no0(sizeof(static_tab));
-       memcpy(tab, static_tab, sizeof(static_tab));
-
-       tab[0].value = message;
-       (void)mail_get_first_header(mail, "Message-ID", &tab[1].value);
-       tab[1].value = tab[1].value == NULL ? "unspecified" :
-               str_sanitize(tab[1].value, 200);
+       if (mail_get_first_header(mail, "Message-ID", &message_id) <= 0)
+               message_id = "unspecified";
+       else
+               message_id = str_sanitize(message_id, 200);
 
-       (void)mail_get_first_header_utf8(mail, "Subject", &tab[2].value);
-       tab[2].value = str_sanitize(tab[2].value, 80);
-       tab[3].value = str_sanitize(mail_deliver_get_address(mail, "From"), 80);
+       if (mail_get_first_header_utf8(mail, "Subject", &subject) > 0)
+               subject = str_sanitize(subject, 80);
+       from = str_sanitize(mail_deliver_get_address(mail, "From"), 80);
 
-       if (mail_get_special(mail, MAIL_FETCH_FROM_ENVELOPE, &str) < 0)
-               str = "";
-       tab[4].value = str_sanitize(str, 80);
+       if (mail_get_special(mail, MAIL_FETCH_FROM_ENVELOPE, &from_envelope) > 0)
+               from_envelope = str_sanitize(from_envelope, 80);
 
        if (mail_get_physical_size(mail, &size) == 0)
-               tab[5].value = dec2str(size);
+               psize = dec2str(size);
        if (mail_get_virtual_size(mail, &size) == 0)
-               tab[6].value = dec2str(size);
+               vsize = dec2str(size);
        if (ctx != NULL) {
-               mail_deliver_log_var_expand_table_update_times(ctx, tab);
-               tab[8].value = dec2str(ctx->session_time_msecs);
-               tab[9].value = ctx->dest_addr;
+               session_time = dec2str(ctx->session_time_msecs);
+               to_envelope = ctx->dest_addr;
        }
-       (void)mail_get_special(mail, MAIL_FETCH_STORAGE_ID, &tab[10].value);
+       (void)mail_get_special(mail, MAIL_FETCH_STORAGE_ID, &storage_id);
+
+       const struct var_expand_table stack_tab[] = {
+               { '$', message, NULL },
+               { 'm', message_id, "msgid" },
+               { 's', subject, "subject" },
+               { 'f', from, "from" },
+               { 'e', from_envelope, "from_envelope" },
+               { 'p', psize, "size" },
+               { 'w', vsize, "vsize" },
+               /* must be VAR_EXPAND_DELIVERY_TIME_IDX */
+               { '\0', NULL, "delivery_time" },
+               { '\0', session_time, "session_time" },
+               { '\0', to_envelope, "to_envelope" },
+               { '\0', storage_id, "storage_id" },
+               { '\0', NULL, NULL }
+       };
+       struct var_expand_table *tab;
+
+       tab = t_malloc_no0(sizeof(stack_tab));
+       memcpy(tab, stack_tab, sizeof(stack_tab));
+       if (ctx != NULL)
+               mail_deliver_log_var_expand_table_update_times(ctx, tab);
        return tab;
 }
 
@@ -159,7 +163,7 @@ void mail_deliver_log(struct mail_deliver_context *ctx, const char *fmt, ...)
        mail_deliver_log_var_expand_table_update_times(ctx, ctx->var_expand_table);
        var_expand(str, ctx->set->deliver_log_format, ctx->var_expand_table);
        ctx->var_expand_table[0].value = "";
-       ctx->var_expand_table[VAR_EXPAND_SESSION_TIME_IDX].value = "";
+       ctx->var_expand_table[VAR_EXPAND_DELIVERY_TIME_IDX].value = "";
 
        i_info("%s", str_c(str));
        va_end(args);
index bf2d404caada9f9717fce53241c8db569c4feaed..4082146fb104d44fc5c44b556df00eb27576a0c3 100644 (file)
@@ -24,26 +24,21 @@ static const struct var_expand_table *
 get_var_expand_table(struct mail *mail, const char *reason,
                     const char *recipient)
 {
-       static struct var_expand_table static_tab[] = {
-               { 'n', NULL, "crlf" },
-               { 'r', NULL, "reason" },
-               { 's', NULL, "subject" },
-               { 't', NULL, "to" },
-               { '\0', NULL, NULL }
-       };
-       struct var_expand_table *tab;
        const char *subject;
-
-       tab = t_malloc_no0(sizeof(static_tab));
-       memcpy(tab, static_tab, sizeof(static_tab));
-
-       tab[0].value = "\r\n";
-       tab[1].value = reason;
        if (mail_get_first_header(mail, "Subject", &subject) <= 0)
                subject = "";
-       tab[2].value = str_sanitize(subject, 80);
-       tab[3].value = recipient;
 
+       const struct var_expand_table stack_tab[] = {
+               { 'n', "\r\n", "crlf" },
+               { 'r', reason, "reason" },
+               { 's', subject, "subject" },
+               { 't', recipient, "to" },
+               { '\0', NULL, NULL }
+       };
+       struct var_expand_table *tab;
+
+       tab = t_malloc_no0(sizeof(stack_tab));
+       memcpy(tab, stack_tab, sizeof(stack_tab));
        return tab;
 }
 
index 34b160e2d85a58090f20636ac304f29044dd4fe3..1c7bc850756d3841a3b3a830555ee3ff55fe17c8 100644 (file)
@@ -8,13 +8,6 @@
 
 unsigned int mail_user_hash(const char *username, const char *format)
 {
-       static struct var_expand_table static_tab[] = {
-               { 'u', NULL, "user" },
-               { 'n', NULL, "username" },
-               { 'd', NULL, "domain" },
-               { '\0', NULL, NULL }
-       };
-       struct var_expand_table *tab;
        unsigned char md5[MD5_RESULTLEN];
        unsigned int i, hash = 0;
 
@@ -28,14 +21,14 @@ unsigned int mail_user_hash(const char *username, const char *format)
                                       strlen(username), md5);
                } T_END;
        } else T_BEGIN {
+               const struct var_expand_table tab[] = {
+                       { 'u', username, "user" },
+                       { 'n', t_strcut(username, '@'), "username" },
+                       { 'd', i_strchr_to_next(username, '@'), "domain" },
+                       { '\0', NULL, NULL }
+               };
                string_t *str = t_str_new(128);
 
-               tab = t_malloc_no0(sizeof(static_tab));
-               memcpy(tab, static_tab, sizeof(static_tab));
-               tab[0].value = username;
-               tab[1].value = t_strcut(username, '@');
-               tab[2].value = i_strchr_to_next(username, '@');
-
                var_expand(str, format, tab);
                md5_get_digest(str_data(str), str_len(str), md5);
        } T_END;
index b3abaf342bf6adede3d462efa4afdf2e34b43d9a..06965538ad004a0340c23b25cdf9c0c844e8d0ef 100644 (file)
@@ -139,14 +139,6 @@ int shared_storage_get_namespace(struct mail_namespace **_ns,
        struct mailbox_list *list = (*_ns)->list;
        struct shared_storage *storage = (struct shared_storage *)_storage;
        struct mail_user *user = _storage->user;
-       static struct var_expand_table static_tab[] = {
-               { 'u', NULL, "user" },
-               { 'n', NULL, "username" },
-               { 'd', NULL, "domain" },
-               { 'h', NULL, "home" },
-               { '\0', NULL, NULL }
-       };
-       struct var_expand_table *tab;
        struct mail_namespace *new_ns, *ns = *_ns;
        struct mail_namespace_settings *ns_set, *unexpanded_ns_set;
        struct mail_user *owner;
@@ -234,11 +226,13 @@ int shared_storage_get_namespace(struct mail_namespace **_ns,
 
        /* expand the namespace prefix and see if it already exists.
           this should normally happen only when the mailbox is being opened */
-       tab = t_malloc_no0(sizeof(static_tab));
-       memcpy(tab, static_tab, sizeof(static_tab));
-       tab[0].value = userdomain;
-       tab[1].value = username;
-       tab[2].value = domain;
+       struct var_expand_table tab[] = {
+               { 'u', userdomain, "user" },
+               { 'n', username, "username" },
+               { 'd', domain, "domain" },
+               { 'h', NULL, "home" },
+               { '\0', NULL, NULL }
+       };
 
        prefix = t_str_new(128);
        str_append(prefix, ns->prefix);
index cb7998e9dbff3dd3e27a1f88cf62e8c237c1468c..83dffe9fa00678639bec8eb0cdde53783279afec 100644 (file)
@@ -394,48 +394,44 @@ get_var_expand_table(struct master_service *service,
                     const struct mail_storage_service_input *input,
                     const struct mail_storage_service_privileges *priv)
 {
-       static struct var_expand_table static_tab[] = {
-               { 'u', NULL, "user" },
-               { 'n', NULL, "username" },
-               { 'd', NULL, "domain" },
-               { 's', NULL, "service" },
-               { 'l', NULL, "lip" },
-               { 'r', NULL, "rip" },
-               { 'p', NULL, "pid" },
-               { 'i', NULL, "uid" },
-               { '\0', NULL, "gid" },
-               { '\0', NULL, "session" },
-               { '\0', NULL, "auth_user" },
-               { '\0', NULL, "auth_username" },
-               { '\0', NULL, "auth_domain" },
-               { '\0', NULL, NULL }
-       };
-       struct var_expand_table *tab;
-
-       tab = t_malloc_no0(sizeof(static_tab));
-       memcpy(tab, static_tab, sizeof(static_tab));
-
-       tab[0].value = input->username;
-       tab[1].value = t_strcut(input->username, '@');
-       tab[2].value = i_strchr_to_next(input->username, '@');
-       tab[3].value = service->name;
-       tab[4].value = net_ip2addr(&input->local_ip);
-       tab[5].value = net_ip2addr(&input->remote_ip);
-       tab[6].value = my_pid;
-       tab[7].value = priv == NULL ? NULL :
+       const char *username = t_strcut(input->username, '@');
+       const char *domain = i_strchr_to_next(input->username, '@');
+       const char *uid = priv == NULL ? NULL :
                dec2str(priv->uid == (uid_t)-1 ? geteuid() : priv->uid);
-       tab[8].value = priv == NULL ? NULL :
+       const char *gid = priv == NULL ? NULL :
                dec2str(priv->gid == (gid_t)-1 ? getegid() : priv->gid);
-       tab[9].value = input->session_id;
+
+       const char *auth_user, *auth_username, *auth_domain;
        if (user == NULL || user->auth_user == NULL) {
-               tab[10].value = tab[0].value;
-               tab[11].value = tab[1].value;
-               tab[12].value = tab[2].value;
+               auth_user = input->username;
+               auth_username = username;
+               auth_domain = domain;
        } else {
-               tab[10].value = user->auth_user;
-               tab[11].value = t_strcut(user->auth_user, '@');
-               tab[12].value = i_strchr_to_next(user->auth_user, '@');
-       }
+               auth_user = user->auth_user;
+               auth_username = t_strcut(user->auth_user, '@');
+               auth_domain = i_strchr_to_next(user->auth_user, '@');
+       }
+
+       const struct var_expand_table stack_tab[] = {
+               { 'u', input->username, "user" },
+               { 'n', username, "username" },
+               { 'd', domain, "domain" },
+               { 's', service->name, "service" },
+               { 'l', net_ip2addr(&input->local_ip), "lip" },
+               { 'r', net_ip2addr(&input->remote_ip), "rip" },
+               { 'p', my_pid, "pid" },
+               { 'i', uid, "uid" },
+               { '\0', gid, "gid" },
+               { '\0', input->session_id, "session" },
+               { '\0', auth_user, "auth_user" },
+               { '\0', auth_username, "auth_username" },
+               { '\0', auth_domain, "auth_domain" },
+               { '\0', NULL, NULL }
+       };
+       struct var_expand_table *tab;
+
+       tab = t_malloc_no0(sizeof(stack_tab));
+       memcpy(tab, stack_tab, sizeof(stack_tab));
        return tab;
 }
 
index 9631469f617dab5792222e5fc1f5faa6f9f23f75..771078b17cdbe057a8377f19aeaf73d9864eea9b 100644 (file)
@@ -209,58 +209,55 @@ void mail_user_set_vars(struct mail_user *user, const char *service,
 const struct var_expand_table *
 mail_user_var_expand_table(struct mail_user *user)
 {
-       static struct var_expand_table static_tab[] = {
-               { 'u', NULL, "user" },
-               { 'n', NULL, "username" },
-               { 'd', NULL, "domain" },
-               { 's', NULL, "service" },
-               { 'h', NULL, "home" },
-               { 'l', NULL, "lip" },
-               { 'r', NULL, "rip" },
-               { 'p', NULL, "pid" },
-               { 'i', NULL, "uid" },
-               { '\0', NULL, "gid" },
-               { '\0', NULL, "session" },
-               { '\0', NULL, "auth_user" },
-               { '\0', NULL, "auth_username" },
-               { '\0', NULL, "auth_domain" },
-               /* NOTE: keep this synced with imap-hibernate's
-                  imap_client_var_expand_table() */
-               { '\0', NULL, NULL }
-       };
-       struct var_expand_table *tab;
-
        /* use a cached table, unless home directory has been set afterwards */
        if (user->var_expand_table != NULL &&
            user->var_expand_table[4].value == user->_home)
                return user->var_expand_table;
 
-       tab = p_malloc(user->pool, sizeof(static_tab));
-       memcpy(tab, static_tab, sizeof(static_tab));
-
-       tab[0].value = user->username;
-       tab[1].value = p_strdup(user->pool, t_strcut(user->username, '@'));
-       tab[2].value = i_strchr_to_next(user->username, '@');
-       tab[3].value = user->service;
-       tab[4].value = user->_home; /* don't look it up unless we need it */
-       tab[5].value = user->local_ip == NULL ? NULL :
+       const char *username =
+               p_strdup(user->pool, t_strcut(user->username, '@'));
+       const char *domain = i_strchr_to_next(user->username, '@');
+       const char *local_ip = user->local_ip == NULL ? NULL :
                p_strdup(user->pool, net_ip2addr(user->local_ip));
-       tab[6].value = user->remote_ip == NULL ? NULL :
+       const char *remote_ip = user->remote_ip == NULL ? NULL :
                p_strdup(user->pool, net_ip2addr(user->remote_ip));
-       tab[7].value = my_pid;
-       tab[8].value = p_strdup(user->pool, dec2str(user->uid));
-       tab[9].value = p_strdup(user->pool, dec2str(user->gid));
-       tab[10].value = user->session_id;
+
+       const char *auth_user, *auth_username, *auth_domain;
        if (user->auth_user == NULL) {
-               tab[11].value = tab[0].value;
-               tab[12].value = tab[1].value;
-               tab[13].value = tab[2].value;
+               auth_user = user->username;
+               auth_username = username;
+               auth_domain = domain;
        } else {
-               tab[11].value = user->auth_user;
-               tab[12].value = p_strdup(user->pool, t_strcut(user->auth_user, '@'));
-               tab[13].value = i_strchr_to_next(user->auth_user, '@');
+               auth_user = user->auth_user;
+               auth_username =
+                       p_strdup(user->pool, t_strcut(user->auth_user, '@'));
+               auth_domain = i_strchr_to_next(user->auth_user, '@');
        }
 
+       const struct var_expand_table stack_tab[] = {
+               { 'u', user->username, "user" },
+               { 'n', username, "username" },
+               { 'd', domain, "domain" },
+               { 's', user->service, "service" },
+               { 'h', user->_home /* don't look it up unless we need it */, "home" },
+               { 'l', local_ip, "lip" },
+               { 'r', remote_ip, "rip" },
+               { 'p', my_pid, "pid" },
+               { 'i', p_strdup(user->pool, dec2str(user->uid)), "uid" },
+               { '\0', p_strdup(user->pool, dec2str(user->gid)), "gid" },
+               { '\0', user->session_id, "session" },
+               { '\0', auth_user, "auth_user" },
+               { '\0', auth_username, "auth_username" },
+               { '\0', auth_domain, "auth_domain" },
+               /* NOTE: keep this synced with imap-hibernate's
+                  imap_client_var_expand_table() */
+               { '\0', NULL, NULL }
+       };
+       struct var_expand_table *tab;
+
+       tab = p_malloc(user->pool, sizeof(stack_tab));
+       memcpy(tab, stack_tab, sizeof(stack_tab));
+
        user->var_expand_table = tab;
        return user->var_expand_table;
 }
index 354d170fa20ff1b1368d660d2f0d00eef527f59e..ae383b263e25a68486a2a490ae510bc5db240728 100644 (file)
@@ -623,26 +623,17 @@ client_var_expand_func_passdb(const char *data, void *context)
 static const char *
 client_get_log_str(struct client *client, const char *msg)
 {
-       static const struct var_expand_table static_tab[3] = {
-               { 's', NULL, NULL },
-               { '$', NULL, NULL },
-               { '\0', NULL, NULL }
-       };
        static const struct var_expand_func_table func_table[] = {
                { "passdb", client_var_expand_func_passdb },
                { NULL, NULL }
        };
        const struct var_expand_table *var_expand_table;
-       struct var_expand_table *tab;
        char *const *e;
        string_t *str, *str2;
        unsigned int pos;
 
        var_expand_table = get_var_expand_table(client);
 
-       tab = t_malloc_no0(sizeof(static_tab));
-       memcpy(tab, static_tab, sizeof(static_tab));
-
        str = t_str_new(256);
        str2 = t_str_new(128);
        for (e = client->set->log_format_elements_split; *e != NULL; e++) {
@@ -668,10 +659,13 @@ client_get_log_str(struct client *client, const char *msg)
        if (str_len(str) > 0)
                str_truncate(str, str_len(str)-2);
 
-       tab[0].value = t_strdup(str_c(str));
-       tab[1].value = msg;
-       str_truncate(str, 0);
+       const struct var_expand_table tab[3] = {
+               { 's', t_strdup(str_c(str)), NULL },
+               { '$', msg, NULL },
+               { '\0', NULL, NULL }
+       };
 
+       str_truncate(str, 0);
        var_expand(str, client->set->login_log_format, tab);
        return str_c(str);
 }
index ace5daeb75a0746f43ad1c9509a2b21928b34dea..089da722008f430dfbda8f70c0487fb1dfdaa281 100644 (file)
@@ -115,24 +115,18 @@ static bool login_settings_check(void *_set, pool_t pool,
 static const struct var_expand_table *
 login_set_var_expand_table(const struct master_service_settings_input *input)
 {
-       static struct var_expand_table static_tab[] = {
-               { 'l', NULL, "lip" },
-               { 'r', NULL, "rip" },
-               { 'p', NULL, "pid" },
-               { 's', NULL, "service" },
-               { '\0', NULL, "local_name" },
+       const struct var_expand_table stack_tab[] = {
+               { 'l', net_ip2addr(&input->local_ip), "lip" },
+               { 'r', net_ip2addr(&input->remote_ip), "rip" },
+               { 'p', my_pid, "pid" },
+               { 's', input->service, "service" },
+               { '\0', input->local_name, "local_name" },
                { '\0', NULL, NULL }
        };
        struct var_expand_table *tab;
 
-       tab = t_malloc_no0(sizeof(static_tab));
-       memcpy(tab, static_tab, sizeof(static_tab));
-
-       tab[0].value = net_ip2addr(&input->local_ip);
-       tab[1].value = net_ip2addr(&input->remote_ip);
-       tab[2].value = my_pid;
-       tab[3].value = input->service;
-       tab[4].value = input->local_name;
+       tab = t_malloc_no0(sizeof(stack_tab));
+       memcpy(tab, stack_tab, sizeof(stack_tab));
        return tab;
 }
 
index e36af1602e0e8aca78c9610241947c723313844a..5790c204d12c34377282d735f644e2bafdbd6616 100644 (file)
@@ -34,18 +34,11 @@ static void
 acl_shared_namespace_add(struct mail_namespace *ns,
                         struct mail_storage *storage, const char *userdomain)
 {
-       static struct var_expand_table static_tab[] = {
-               { 'u', NULL, "user" },
-               { 'n', NULL, "username" },
-               { 'd', NULL, "domain" },
-               { '\0', NULL, NULL }
-       };
        struct shared_storage *sstorage = (struct shared_storage *)storage;
        struct mail_namespace *new_ns = ns;
-       struct var_expand_table *tab;
        struct mailbox_list_iterate_context *iter;
        const struct mailbox_info *info;
-       const char *p, *mailbox;
+       const char *mailbox;
        string_t *str;
 
        if (strcmp(ns->user->username, userdomain) == 0) {
@@ -53,13 +46,12 @@ acl_shared_namespace_add(struct mail_namespace *ns,
                return;
        }
 
-       p = strchr(userdomain, '@');
-
-       tab = t_malloc_no0(sizeof(static_tab));
-       memcpy(tab, static_tab, sizeof(static_tab));
-       tab[0].value = userdomain;
-       tab[1].value = p == NULL ? userdomain : t_strdup_until(userdomain, p);
-       tab[2].value = p == NULL ? "" : p + 1;
+       const struct var_expand_table tab[] = {
+               { 'u', userdomain, "user" },
+               { 'n', t_strcut(userdomain, '@'), "username" },
+               { 'd', i_strchr_to_next(userdomain, '@'), "domain" },
+               { '\0', NULL, NULL }
+       };
 
        str = t_str_new(128);
        var_expand(str, sstorage->ns_prefix_pattern, tab);
index 4ca4e9923f9e976b874bcd962e1f9ebaddea5e0d..d8737fd25538f0ac84639417d62e8eb2ac4af5e9 100644 (file)
@@ -530,46 +530,30 @@ static const char *client_build_uidl_change_string(struct client *client)
 
 static const char *client_stats(struct client *client)
 {
-       static struct var_expand_table static_tab[] = {
-               { 'p', NULL, "top_bytes" },
-               { 't', NULL, "top_count" },
-               { 'b', NULL, "retr_bytes" },
-               { 'r', NULL, "retr_count" },
-               { 'd', NULL, "deleted_count" },
-               { 'm', NULL, "message_count" },
-               { 's', NULL, "message_bytes" },
-               { 'i', NULL, "input" },
-               { 'o', NULL, "output" },
-               { 'u', NULL, "uidl_change" },
-               { '\0', NULL, "session" },
-               { 'd', NULL, "deleted_bytes" },
+       const char *uidl_change = "";
+       if (var_has_key(client->set->pop3_logout_format,
+                       'o', "uidl_change"))
+               uidl_change = client_build_uidl_change_string(client);
+
+       const struct var_expand_table tab[] = {
+               { 'p', dec2str(client->top_bytes), "top_bytes" },
+               { 't', dec2str(client->top_count), "top_count" },
+               { 'b', dec2str(client->retr_bytes), "retr_bytes" },
+               { 'r', dec2str(client->retr_count), "retr_count" },
+               { 'd', !client->delete_success ? "0" :
+                      dec2str(client->deleted_count), "deleted_count" },
+               { 'm', dec2str(client->messages_count), "message_count" },
+               { 's', dec2str(client->total_size), "message_bytes" },
+               { 'i', dec2str(client->input->v_offset), "input" },
+               { 'o', dec2str(client->output->offset), "output" },
+               { 'u', uidl_change, "uidl_change" },
+               { '\0', client->session_id, "session" },
+               { 'd', !client->delete_success ? "0" :
+                      dec2str(client->deleted_size), "deleted_bytes" },
                { '\0', NULL, NULL }
        };
-       struct var_expand_table *tab;
        string_t *str;
 
-       tab = t_malloc_no0(sizeof(static_tab));
-       memcpy(tab, static_tab, sizeof(static_tab));
-
-       tab[0].value = dec2str(client->top_bytes);
-       tab[1].value = dec2str(client->top_count);
-       tab[2].value = dec2str(client->retr_bytes);
-       tab[3].value = dec2str(client->retr_count);
-       tab[4].value = client->delete_success ?
-               dec2str(client->deleted_count) : "0";
-       tab[5].value = dec2str(client->messages_count);
-       tab[6].value = dec2str(client->total_size);
-       tab[7].value = dec2str(client->input->v_offset);
-       tab[8].value = dec2str(client->output->offset);
-       if (var_has_key(client->set->pop3_logout_format,
-                       tab[9].key, tab[9].long_key))
-               tab[9].value = client_build_uidl_change_string(client);
-       else
-               tab[9].value = "";
-       tab[10].value = client->session_id;
-       tab[11].value = client->delete_success ?
-               dec2str(client->deleted_size) : "0";
-
        str = t_str_new(128);
        var_expand(str, client->set->pop3_logout_format, tab);
        return str_c(str);
index 7b48ca0493349b83fc4653e97d3e7bc4022dbdac..65fb01eb3cfa9e3ecaa0c2de2f4fd9a647f8b2b1 100644 (file)
@@ -570,17 +570,9 @@ static int
 pop3_get_uid(struct client *client, struct mail *mail, string_t *str,
             bool *permanent_uidl_r)
 {
-       static struct var_expand_table static_tab[] = {
-               { 'v', NULL, "uidvalidity" },
-               { 'u', NULL, "uid" },
-               { 'm', NULL, "md5" },
-               { 'f', NULL, "filename" },
-               { 'g', NULL, "guid" },
-               { '\0', NULL, NULL }
-       };
-       struct var_expand_table *tab;
-       char uid_str[MAX_INT_STRLEN];
+       char uid_str[MAX_INT_STRLEN] = { 0 };
        const char *uidl;
+       const char *hdr_md5 = NULL, *filename = NULL, *guid = NULL;
 
        if (mail_get_special(mail, MAIL_FETCH_UIDL_BACKEND, &uidl) == 0 &&
            *uidl != '\0') {
@@ -598,22 +590,17 @@ pop3_get_uid(struct client *client, struct mail *mail, string_t *str,
                return 0;
        }
 
-       tab = t_malloc_no0(sizeof(static_tab));
-       memcpy(tab, static_tab, sizeof(static_tab));
-       tab[0].value = t_strdup_printf("%u", client->uid_validity);
-
        if ((client->uidl_keymask & UIDL_UID) != 0) {
                if (i_snprintf(uid_str, sizeof(uid_str), "%u", mail->uid) < 0)
                        i_unreached();
-               tab[1].value = uid_str;
        }
        if ((client->uidl_keymask & UIDL_MD5) != 0) {
                if (mail_get_special(mail, MAIL_FETCH_HEADER_MD5,
-                                    &tab[2].value) < 0) {
+                                    &hdr_md5) < 0) {
                        i_error("UIDL: Header MD5 lookup failed: %s",
                                mailbox_get_last_error(mail->box, NULL));
                        return -1;
-               } else if (*tab[2].value == '\0') {
+               } else if (hdr_md5[0] == '\0') {
                        i_error("UIDL: Header MD5 not found "
                                "(pop3_uidl_format=%%m not supported by storage?)");
                        return -1;
@@ -621,11 +608,11 @@ pop3_get_uid(struct client *client, struct mail *mail, string_t *str,
        }
        if ((client->uidl_keymask & UIDL_FILE_NAME) != 0) {
                if (mail_get_special(mail, MAIL_FETCH_STORAGE_ID,
-                                    &tab[3].value) < 0) {
+                                    &filename) < 0) {
                        i_error("UIDL: File name lookup failed: %s",
                                mailbox_get_last_error(mail->box, NULL));
                        return -1;
-               } else if (*tab[3].value == '\0') {
+               } else if (filename[0] == '\0') {
                        i_error("UIDL: File name not found "
                                "(pop3_uidl_format=%%f not supported by storage?)");
                        return -1;
@@ -633,16 +620,25 @@ pop3_get_uid(struct client *client, struct mail *mail, string_t *str,
        }
        if ((client->uidl_keymask & UIDL_GUID) != 0) {
                if (mail_get_special(mail, MAIL_FETCH_GUID,
-                                    &tab[4].value) < 0) {
+                                    &guid) < 0) {
                        i_error("UIDL: Message GUID lookup failed: %s",
                                mailbox_get_last_error(mail->box, NULL));
                        return -1;
-               } else if (*tab[4].value == '\0') {
+               } else if (guid[0] == '\0') {
                        i_error("UIDL: Message GUID not found "
                                "(pop3_uidl_format=%%g not supported by storage?)");
                        return -1;
                }
        }
+
+       const struct var_expand_table tab[] = {
+               { 'v', dec2str(client->uid_validity), "uidvalidity" },
+               { 'u', uid_str, "uid" },
+               { 'm', hdr_md5, "md5" },
+               { 'f', filename, "filename" },
+               { 'g', guid, "guid" },
+               { '\0', NULL, NULL }
+       };
        var_expand(str, client->mail_set->pop3_uidl_format, tab);
        return 0;
 }