doveadm-director.c revision 7536dca18968a279b69c685eedda205bee228fd4
/* Copyright (c) 2009-2012 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "md5.h"
#include "hash.h"
#include "str.h"
#include "network.h"
#include "istream.h"
#include "write-full.h"
#include "master-service.h"
#include "auth-master.h"
#include "doveadm.h"
#include "doveadm-print.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
struct director_context {
const char *socket_path;
const char *users_path;
bool explicit_socket_path;
};
struct user_list {
const char *name;
};
extern struct doveadm_cmd doveadm_cmd_director[];
static void
{
}
{
#define DIRECTOR_HANDSHAKE "VERSION\tdirector-doveadm\t1\t0\n"
const char *line;
int fd;
alarm(5);
alarm(0);
else {
i_fatal("read(%s) timed out (is director configured?)",
ctx->socket_path);
}
}
"%s not a compatible director-doveadm socket",
ctx->socket_path);
}
}
{
}
static struct director_context *
{
struct director_context *ctx;
int c;
"/director-admin", NULL);
switch (c) {
case 'a':
break;
case 'f':
break;
default:
}
}
return ctx;
}
static void
{
unsigned int expires;
i_error("Lookup failed");
return;
}
i_error("Invalid reply from director");
return;
}
if (args[0][0] != '\0') {
printf("Current: %s (expires %s)\n",
} else {
printf("Current: not assigned\n");
}
}
{
struct director_context *ctx;
return;
}
doveadm_print_header_simple("mail server ip");
if (*line == '\0')
break;
T_BEGIN {
doveadm_print(args[0]);
}
} T_END;
}
i_error("Director disconnected unexpectedly");
}
}
static unsigned int director_username_hash(const char *username)
{
unsigned char md5[MD5_RESULTLEN];
unsigned int i, hash = 0;
for (i = 0; i < sizeof(hash); i++)
return hash;
}
static void
{
unsigned int user_hash;
}
static void ATTR_NULL(1)
struct hash_table *users)
{
struct auth_master_user_list_ctx *ctx;
struct auth_master_connection *conn;
const char *username;
if (auth_socket_path == NULL) {
"/auth-userdb", NULL);
}
if (auth_master_user_list_deinit(&ctx) < 0) {
i_error("user listing failed");
}
}
static void
{
const char *username;
int fd;
if (fd == -1)
}
unsigned int *ips_count_r)
{
int ret;
*ips_count_r = 1;
} else {
if (ret != 0) {
}
}
}
{
unsigned int i;
for (i = 0; i < ips_count; i++) {
return TRUE;
}
return FALSE;
}
{
struct director_context *ctx;
struct hash_table *users;
ips_count = 0;
else
else
doveadm_print_header_simple("mail server ip");
doveadm_print_header_simple("expire time");
if (ips_count != 1)
else {
}
if (*line == '\0')
break;
T_BEGIN {
} else if (ips_count == 0 ||
doveadm_print("<unknown>");
}
}
}
} T_END;
}
i_error("Director disconnected unexpectedly");
}
pool_unref(&pool);
}
{
struct director_context *ctx;
}
for (i = 0; i < ips_count; i++) {
t_strdup_printf("HOST-SET\t%s\n",
net_ip2addr(&ips[i])) :
t_strdup_printf("HOST-SET\t%s\t%u\n",
}
for (i = 0; i < ips_count; i++) {
} else if (doveadm_verbose) {
}
}
}
{
struct director_context *ctx;
unsigned int i, ips_count;
for (i = 0; i < ips_count; i++) {
}
for (i = 0; i < ips_count; i++) {
net_ip2addr(&ips[i]));
if (doveadm_exit_code == 0)
} else if (doveadm_verbose) {
}
}
}
{
struct director_context *ctx;
i_error("failed");
if (doveadm_verbose)
i_error("User is already being moved, "
"wait a while for it to be finished");
} else {
}
}
{
const char *line;
i_error("failed");
} else if (doveadm_verbose)
printf("flushed\n");
}
{
struct director_context *ctx;
unsigned int i, ips_count;
int ret;
return;
}
ips_count = 1;
} else {
if (ret != 0) {
}
}
for (i = 0; i < ips_count; i++) {
}
for (i = 0; i < ips_count; i++) {
net_ip2addr(&ips[i]));
if (doveadm_exit_code == 0)
} else if (doveadm_verbose) {
}
}
}
{
if (ctx->explicit_socket_path)
putchar('\n');
}
{
struct director_context *ctx;
if (*line == '\0')
break;
T_BEGIN {
}
} T_END;
}
if (*line == '\0')
break;
}
i_error("Director disconnected unexpectedly");
}
}
{
const char *line;
i_error("Director disconnected unexpectedly");
i_error("Not found");
}
}
{
struct director_context *ctx;
unsigned int port = 0;
if (port != 0)
}
{
struct director_context *ctx;
unsigned int port = 0;
if (port != 0)
}
{
struct director_context *ctx;
unsigned long l;
doveadm_print_header_simple("director ip");
doveadm_print_header_simple("port");
doveadm_print_header_simple("type");
doveadm_print_header_simple("last failed");
if (*line == '\0')
break;
T_BEGIN {
doveadm_print(args[0]);
if (l == 0)
doveadm_print("never");
else
}
} T_END;
}
i_error("Director disconnected unexpectedly");
}
}
struct doveadm_cmd doveadm_cmd_director[] = {
{ cmd_director_status, "director status",
"[-a <director socket path>] [<user>]" },
{ cmd_director_map, "director map",
"[-a <director socket path>] [-f <users file>] [<host>]" },
{ cmd_director_add, "director add",
"[-a <director socket path>] <host> [<vhost count>]" },
{ cmd_director_remove, "director remove",
"[-a <director socket path>] <host>" },
{ cmd_director_move, "director move",
"[-a <director socket path>] <user> <host>" },
{ cmd_director_flush, "director flush",
"[-a <director socket path>] <host>|all" },
{ cmd_director_dump, "director dump",
"[-a <director socket path>]" },
{ cmd_director_ring_add, "director ring add",
"[-a <director socket path>] <ip> [<port>]" },
{ cmd_director_ring_remove, "director ring remove",
"[-a <director socket path>] <ip> [<port>]" },
{ cmd_director_ring_status, "director ring status",
"[-a <director socket path>]" }
};
{
unsigned int i;
for (i = 0; i < N_ELEMENTS(doveadm_cmd_director); i++) {
help(&doveadm_cmd_director[i]);
}
i_unreached();
}
void doveadm_register_director_commands(void)
{
unsigned int i;
for (i = 0; i < N_ELEMENTS(doveadm_cmd_director); i++)
}