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

« back to all changes in this revision

Viewing changes to src/director/doveadm-connection.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) 2010-2011 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2010-2012 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "ioloop.h"
99
99
        string_t *str = t_str_new(1024);
100
100
        const char *type;
101
101
        bool left, right;
 
102
        time_t last_failed;
102
103
 
103
104
        array_foreach(&dir->dir_hosts, hostp) {
104
105
                const struct director_host *host = *hostp;
108
109
                right = dir->right != NULL &&
109
110
                         director_connection_get_host(dir->right) == host;
110
111
 
111
 
                if (dir->self_host == host)
 
112
                if (host->removed)
 
113
                        type = "removed";
 
114
                else if (dir->self_host == host)
112
115
                        type = "self";
113
116
                else if (left)
114
117
                        type = right ? "l+r" : "left";
116
119
                        type = "right";
117
120
                else
118
121
                        type = "";
 
122
 
 
123
                last_failed = I_MAX(host->last_network_failure,
 
124
                                    host->last_protocol_failure);
119
125
                str_printfa(str, "%s\t%u\t%s\t%lu\n",
120
126
                            net_ip2addr(&host->ip), host->port, type,
121
 
                            (unsigned long)host->last_failed);
 
127
                            (unsigned long)last_failed);
122
128
        }
123
129
        str_append_c(str, '\n');
124
130
        o_stream_send(conn->output, str_data(str), str_len(str));
125
131
}
126
132
 
127
133
static bool
 
134
doveadm_cmd_director_add(struct doveadm_connection *conn, const char *line)
 
135
{
 
136
        const char *const *args;
 
137
        struct director_host *host;
 
138
        struct ip_addr ip;
 
139
        unsigned int port = conn->dir->self_port;
 
140
 
 
141
        args = t_strsplit_tab(line);
 
142
        if (args[0] == NULL ||
 
143
            net_addr2ip(line, &ip) < 0 ||
 
144
            (args[1] != NULL && str_to_uint(args[1], &port) < 0)) {
 
145
                i_error("doveadm sent invalid DIRECTOR-ADD parameters");
 
146
                return FALSE;
 
147
        }
 
148
 
 
149
        if (director_host_lookup(conn->dir, &ip, port) == NULL) {
 
150
                host = director_host_add(conn->dir, &ip, port);
 
151
                director_notify_ring_added(host, conn->dir->self_host);
 
152
        }
 
153
        o_stream_send(conn->output, "OK\n", 3);
 
154
        return TRUE;
 
155
}
 
156
 
 
157
static bool
 
158
doveadm_cmd_director_remove(struct doveadm_connection *conn, const char *line)
 
159
{
 
160
        const char *const *args;
 
161
        struct director_host *host;
 
162
        struct ip_addr ip;
 
163
        unsigned int port = 0;
 
164
 
 
165
        args = t_strsplit_tab(line);
 
166
        if (args[0] == NULL ||
 
167
            net_addr2ip(line, &ip) < 0 ||
 
168
            (args[1] != NULL && str_to_uint(args[1], &port) < 0)) {
 
169
                i_error("doveadm sent invalid DIRECTOR-REMOVE parameters");
 
170
                return FALSE;
 
171
        }
 
172
 
 
173
        host = port != 0 ?
 
174
                director_host_lookup(conn->dir, &ip, port) :
 
175
                director_host_lookup_ip(conn->dir, &ip);
 
176
        if (host == NULL)
 
177
                o_stream_send_str(conn->output, "NOTFOUND\n");
 
178
        else {
 
179
                director_ring_remove(host, conn->dir->self_host);
 
180
                o_stream_send(conn->output, "OK\n", 3);
 
181
        }
 
182
        return TRUE;
 
183
}
 
184
 
 
185
static bool
128
186
doveadm_cmd_host_set(struct doveadm_connection *conn, const char *line)
129
187
{
130
188
        struct director *dir = conn->dir;
133
191
        struct ip_addr ip;
134
192
        unsigned int vhost_count = -1U;
135
193
 
136
 
        args = t_strsplit(line, "\t");
 
194
        args = t_strsplit_tab(line);
137
195
        if (args[0] == NULL ||
138
196
            net_addr2ip(args[0], &ip) < 0 ||
139
197
            (args[1] != NULL && str_to_uint(args[1], &vhost_count) < 0)) {
223
281
        string_t *str = t_str_new(256);
224
282
 
225
283
        if (str_to_uint(line, &username_hash) < 0)
226
 
                username_hash = user_directory_get_username_hash(line);
 
284
                username_hash = user_directory_get_username_hash(conn->dir->users, line);
227
285
 
228
286
        /* get user's current host */
229
287
        user = user_directory_lookup(conn->dir->users, username_hash);
296
354
        struct mail_host *host;
297
355
        struct ip_addr ip;
298
356
 
299
 
        args = t_strsplit(line, "\t");
 
357
        args = t_strsplit_tab(line);
300
358
        if (args[0] == NULL || args[1] == NULL ||
301
359
            net_addr2ip(args[1], &ip) < 0) {
302
360
                i_error("doveadm sent invalid USER-MOVE parameters: %s", line);
309
367
        }
310
368
 
311
369
        if (str_to_uint(args[0], &username_hash) < 0)
312
 
                username_hash = user_directory_get_username_hash(line);
 
370
                username_hash = user_directory_get_username_hash(conn->dir->users, line);
313
371
        user = user_directory_lookup(conn->dir->users, username_hash);
314
372
        if (user != NULL && user->kill_state != USER_KILL_STATE_NONE) {
315
373
                o_stream_send_str(conn->output, "TRYAGAIN\n");
360
418
                        doveadm_cmd_host_list_removed(conn);
361
419
                else if (strcmp(cmd, "DIRECTOR-LIST") == 0)
362
420
                        doveadm_cmd_director_list(conn);
 
421
                else if (strcmp(cmd, "DIRECTOR-ADD") == 0)
 
422
                        doveadm_cmd_director_add(conn, args);
 
423
                else if (strcmp(cmd, "DIRECTOR-REMOVE") == 0)
 
424
                        doveadm_cmd_director_remove(conn, args);
363
425
                else if (strcmp(cmd, "HOST-SET") == 0)
364
426
                        ret = doveadm_cmd_host_set(conn, args);
365
427
                else if (strcmp(cmd, "HOST-REMOVE") == 0)