doveadm-connection.c revision 550d2fe097e95f12e8fa60ef52753ea7fe53d4ea
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik/* Copyright (c) 2010-2014 Dovecot authors, see the included COPYING file */
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik#define DOVEADM_HANDSHAKE "VERSION\tdirector-doveadm\t1\t0\n"
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březinastatic struct doveadm_connection *doveadm_connections;
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březinastatic void doveadm_connection_deinit(struct doveadm_connection **_conn);
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březinastatic void doveadm_cmd_host_list(struct doveadm_connection *conn)
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina array_foreach(mail_hosts_get(conn->dir->mail_hosts), hostp) {
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina net_ip2addr(&(*hostp)->ip), (*hostp)->vhost_count,
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina o_stream_nsend(conn->output, str_data(str), str_len(str));
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březinastatic void doveadm_cmd_host_list_removed(struct doveadm_connection *conn)
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina struct mail_host *const *orig_hosts, *const *cur_hosts;
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina unsigned int i, j, orig_hosts_count, cur_hosts_count;
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina (void)mail_hosts_parse_and_add(orig_hosts_list,
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina orig_hosts = array_get(mail_hosts_get(orig_hosts_list),
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina cur_hosts = array_get(mail_hosts_get(conn->dir->mail_hosts),
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina /* the hosts are sorted by IP */
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina for (i = j = 0; i < orig_hosts_count && j < cur_hosts_count; ) {
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina ret = net_ip_cmp(&orig_hosts[i]->ip, &cur_hosts[j]->ip);
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina else if (ret > 0)
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina for (; i < orig_hosts_count; i++)
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina str_printfa(str, "%s\n", net_ip2addr(&orig_hosts[i]->ip));
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina o_stream_nsend(conn->output, str_data(str), str_len(str));
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březinastatic void doveadm_cmd_director_list(struct doveadm_connection *conn)
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březina director_connection_get_host(dir->left) == host;
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březina director_connection_get_host(dir->right) == host;
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březina last_failed = I_MAX(host->last_network_failure,
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březina (unsigned long)last_failed);
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březina o_stream_nsend(conn->output, str_data(str), str_len(str));
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březinadoveadm_cmd_director_add(struct doveadm_connection *conn, const char *line)
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březina const char *const *args;
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březina (args[1] != NULL && str_to_uint(args[1], &port) < 0)) {
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březina i_error("doveadm sent invalid DIRECTOR-ADD parameters");
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březina if (director_host_lookup(conn->dir, &ip, port) == NULL) {
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březina host = director_host_add(conn->dir, &ip, port);
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březina director_notify_ring_added(host, conn->dir->self_host);
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březinadoveadm_cmd_director_remove(struct doveadm_connection *conn, const char *line)
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březina const char *const *args;
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik unsigned int port = 0;
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina (args[1] != NULL && str_to_uint(args[1], &port) < 0)) {
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina i_error("doveadm sent invalid DIRECTOR-REMOVE parameters");
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina o_stream_nsend_str(conn->output, "NOTFOUND\n");
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik director_ring_remove(host, conn->dir->self_host);
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březinadoveadm_cmd_host_set(struct doveadm_connection *conn, const char *line)
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina const char *const *args;
0f04241fc90f134af0272eb0999e75fb6749b595Pavel Březina (args[1] != NULL && str_to_uint(args[1], &vhost_count) < 0)) {
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik i_error("doveadm sent invalid HOST-SET parameters: %s", line);
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březina if (vhost_count > MAX_VALID_VHOST_COUNT && vhost_count != UINT_MAX) {
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březina o_stream_nsend_str(conn->output, "vhost count too large\n");
4ddd5591c50e27dffa55f03fbce0dcc85cd50a8bPavel Březina host = mail_host_lookup(dir->mail_hosts, &ip);
return TRUE;
return FALSE;
return TRUE;
return TRUE;
return FALSE;
return TRUE;
unsigned int username_hash;
return TRUE;
return FALSE;
} T_END;
return TRUE;
unsigned int username_hash;
const char *const *args;
return FALSE;
return TRUE;
return TRUE;
return TRUE;
const char *const *args;
return FALSE;
return TRUE;
args++;
struct doveadm_connection *
return conn;
void doveadm_connections_deinit(void)