~james-page/ubuntu/raring/dovecot/autopkgtest

« back to all changes in this revision

Viewing changes to src/imap/imap-client.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 11:11:54 UTC
  • mfrom: (1.15.2) (4.1.27 sid)
  • Revision ID: package-import@ubuntu.com-20120611111154-678cwbdj6ktgsv1h
Tags: 1:2.1.7-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/{control,rules}: enable PIE hardening.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + d/control: Added Pre-Depends: dpkg (>= 1.15.6) to dovecot-dbg to support
    xz compression in Ubuntu.
  + d/control: Demote dovecot-common Recommends: to Suggests: to prevent
    install of extra packages on upgrade.
  + d/patches/dovecot-drac.patch: Updated with version for dovecot >= 2.0.0.
  + d/control: Drop B-D on systemd.
* Dropped changes:
  + d/patches/fix-racey-restart.patch: part of 2.1.x, no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2002-2011 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2002-2012 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "imap-common.h"
4
4
#include "ioloop.h"
32
32
        client_destroy(client, "Disconnected for inactivity");
33
33
}
34
34
 
35
 
struct client *client_create(int fd_in, int fd_out, struct mail_user *user,
 
35
struct client *client_create(int fd_in, int fd_out, const char *session_id,
 
36
                             struct mail_user *user,
36
37
                             struct mail_storage_service_user *service_user,
37
38
                             const struct imap_settings *set)
38
39
{
44
45
        net_set_nonblock(fd_in, TRUE);
45
46
        net_set_nonblock(fd_out, TRUE);
46
47
 
47
 
        pool = pool_alloconly_create("imap client", 1024);
 
48
        pool = pool_alloconly_create("imap client", 2048);
48
49
        client = p_new(pool, struct client, 1);
49
50
        client->pool = pool;
50
51
        client->set = set;
51
52
        client->service_user = service_user;
 
53
        client->session_id = p_strdup(pool, session_id);
52
54
        client->fd_in = fd_in;
53
55
        client->fd_out = fd_out;
54
56
        client->input = i_stream_create_fd(fd_in,
82
84
                str_append_c(client->capability_string, ' ');
83
85
                str_append(client->capability_string, set->imap_capability + 1);
84
86
        }
 
87
        if (user->fuzzy_search) {
 
88
                /* Enable FUZZY capability only when it actually has
 
89
                   a chance of working */
 
90
                str_append(client->capability_string, " SEARCH=FUZZY");
 
91
        }
85
92
 
86
93
        ident = mail_user_get_anvil_userip_ident(client->user);
87
94
        if (ident != NULL) {
123
130
                i_unreached();
124
131
        }
125
132
 
126
 
        cmd_ret = !cmd->cancel || cmd->func == NULL ? TRUE : cmd->func(cmd);
 
133
        cmd_ret = !cmd->cancel || cmd->func == NULL ? TRUE :
 
134
                command_exec(cmd);
127
135
        if (!cmd_ret && cmd->state != CLIENT_COMMAND_STATE_DONE) {
128
136
                if (cmd->client->output->closed)
129
137
                        i_panic("command didn't cancel itself: %s", cmd->name);
137
145
        static struct var_expand_table static_tab[] = {
138
146
                { 'i', NULL, "input" },
139
147
                { 'o', NULL, "output" },
 
148
                { '\0', NULL, "session" },
140
149
                { '\0', NULL, NULL }
141
150
        };
142
151
        struct var_expand_table *tab;
147
156
 
148
157
        tab[0].value = dec2str(i_stream_get_absolute_offset(client->input));
149
158
        tab[1].value = dec2str(client->output->offset);
 
159
        tab[2].value = client->session_id;
150
160
 
151
161
        str = t_str_new(128);
152
162
        var_expand(str, client->set->imap_logout_format, tab);
209
219
        mail_user_unref(&client->user);
210
220
 
211
221
        if (client->free_parser != NULL)
212
 
                imap_parser_destroy(&client->free_parser);
 
222
                imap_parser_unref(&client->free_parser);
213
223
        if (client->io != NULL)
214
224
                io_remove(&client->io);
215
225
        if (client->to_idle_output != NULL)
547
557
                client->mailbox_change_lock = NULL;
548
558
 
549
559
        if (client->free_parser != NULL)
550
 
                imap_parser_destroy(&cmd->parser);
 
560
                imap_parser_unref(&cmd->parser);
551
561
        else {
552
562
                imap_parser_reset(cmd->parser);
553
563
                client->free_parser = cmd->parser;
669
679
 
670
680
        if (cmd->func != NULL) {
671
681
                /* command is being executed - continue it */
672
 
                if (cmd->func(cmd) || cmd->state == CLIENT_COMMAND_STATE_DONE) {
 
682
                if (command_exec(cmd) ||
 
683
                    cmd->state == CLIENT_COMMAND_STATE_DONE) {
673
684
                        /* command execution was finished */
674
685
                        client_command_free(&cmd);
675
686
                        client_add_missing_io(client);
837
848
        bool finished;
838
849
 
839
850
        /* continue processing command */
840
 
        finished = cmd->func(cmd) || cmd->state == CLIENT_COMMAND_STATE_DONE;
 
851
        finished = command_exec(cmd) || cmd->state == CLIENT_COMMAND_STATE_DONE;
841
852
 
842
853
        if (!finished)
843
854
                (void)client_handle_unfinished_cmd(cmd);
923
934
        return TRUE;
924
935
}
925
936
 
926
 
void client_enable(struct client *client, enum mailbox_feature features)
 
937
int client_enable(struct client *client, enum mailbox_feature features)
927
938
{
928
939
        struct mailbox_status status;
 
940
        int ret;
929
941
 
930
942
        if ((client->enabled_features & features) == features)
931
 
                return;
 
943
                return 0;
932
944
 
933
945
        client->enabled_features |= features;
934
946
        if (client->mailbox == NULL)
935
 
                return;
 
947
                return 0;
936
948
 
937
 
        mailbox_enable(client->mailbox, features);
938
 
        if ((features & MAILBOX_FEATURE_CONDSTORE) != 0) {
 
949
        ret = mailbox_enable(client->mailbox, features);
 
950
        if ((features & MAILBOX_FEATURE_CONDSTORE) != 0 && ret == 0) {
939
951
                /* CONDSTORE being enabled while mailbox is selected.
940
952
                   Notify client of the latest HIGHESTMODSEQ. */
941
 
                mailbox_get_status(client->mailbox,
942
 
                                   STATUS_HIGHESTMODSEQ, &status);
943
 
                client_send_line(client, t_strdup_printf(
944
 
                        "* OK [HIGHESTMODSEQ %llu] Highest",
945
 
                        (unsigned long long)status.highest_modseq));
946
 
        }
 
953
                ret = mailbox_get_status(client->mailbox,
 
954
                                         STATUS_HIGHESTMODSEQ, &status);
 
955
                if (ret == 0) {
 
956
                        client_send_line(client, t_strdup_printf(
 
957
                                "* OK [HIGHESTMODSEQ %llu] Highest",
 
958
                                (unsigned long long)status.highest_modseq));
 
959
                }
 
960
        }
 
961
        if (ret < 0) {
 
962
                client_send_untagged_storage_error(client,
 
963
                        mailbox_get_storage(client->mailbox));
 
964
        }
 
965
        return ret;
947
966
}
948
967
 
949
968
struct imap_search_update *