doveadm-mail-server.c revision 06c303e21a11e11209f40a2658f2864819d59f70
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2010-2013 Dovecot authors, see the included COPYING file */
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainen (internal_failure || master_service_is_killed(master_service))
c000c8eca8f24b2a0c76393ec4bbf76a505a4983Timo Sirainenstatic HASH_TABLE(char *, struct doveadm_server *) servers;
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainenstatic struct doveadm_mail_cmd_context *cmd_ctx;
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainenstatic void doveadm_mail_server_handle(struct server_connection *conn,
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainendoveadm_server_get(struct doveadm_mail_cmd_context *ctx, const char *name)
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen server_pool = pool_alloconly_create("doveadm servers", 1024*16);
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen hash_table_create(&servers, server_pool, 0, str_hash, strcmp);
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen server = p_new(server_pool, struct doveadm_server, 1);
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen server->name = dup_name = p_strdup(server_pool, name);
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen p_array_init(&server->connections, server_pool,
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainendoveadm_server_find_unused_conn(struct doveadm_server *server)
8ed8c821ba8aab0b4ed0375f87d48737ef0e0d8eTimo Sirainenstatic bool doveadm_server_have_used_connections(struct doveadm_server *server)
e93184a9055c2530366dfe617e07199603c399ddMartti Rannanjärvistatic void doveadm_cmd_callback(int exit_code, const char *error,
8ed8c821ba8aab0b4ed0375f87d48737ef0e0d8eTimo Sirainen struct doveadm_mail_server_cmd *servercmd = context;
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen server_connection_get_server(servercmd->conn);
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen const char *username = t_strdup(servercmd->username);
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen server->name, cmd_ctx->cmd->name, username, error);
c000c8eca8f24b2a0c76393ec4bbf76a505a4983Timo Sirainen i_error("%s: No such user: %s", server->name, username);
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen if (cmd_ctx->exit_code == 0 || exit_code == EX_TEMPFAIL)
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen char *const *usernamep = array_idx(&server->queue, 0);
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen conn = doveadm_server_find_unused_conn(server);
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainenstatic void doveadm_mail_server_handle(struct server_connection *conn,
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainen unsigned int i;
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainen /* <flags> <username> <command> [<args>] */
f1901fd21906911f7be075c965ac882f6a87b4c3Timo Sirainen str_append_tabescaped(cmd, cmd_ctx->cmd->name);
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen for (i = 0; cmd_ctx->full_args[i] != NULL; i++) {
f1901fd21906911f7be075c965ac882f6a87b4c3Timo Sirainen str_append_tabescaped(cmd, cmd_ctx->full_args[i]);
7501b9f694460101b41d1d708ebc3ec2b0400b1cTimo Sirainen servercmd = i_new(struct doveadm_mail_server_cmd, 1);
1b5366b2234892f8930a29351da06b193e385150Timo Sirainenstatic void doveadm_server_flush_one(struct doveadm_server *server)
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen unsigned int count = array_count(&server->queue);
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen } while (array_count(&server->queue) == count &&
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen doveadm_server_have_used_connections(server) &&
1b5366b2234892f8930a29351da06b193e385150Timo Sirainendoveadm_mail_server_user_get_host(struct doveadm_mail_cmd_context *ctx,
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen const struct mail_storage_service_input *input,
e5afebd2df1d4990f7bec2a839260ff2e6d78168Timo Sirainen const char *auth_socket_path, *proxy_host, *const *fields;
ccc895c0358108d2304239063e940b7d75f364abTimo Sirainen unsigned int i;
ccc895c0358108d2304239063e940b7d75f364abTimo Sirainen /* make sure we have an auth connection */
f1901fd21906911f7be075c965ac882f6a87b4c3Timo Sirainen mail_storage_service_init_settings(ctx->storage_service, input);
690bafa70767e3f6e98bbfd62ad4a26be2387ea9Timo Sirainen info.service = master_service_get_name(master_service);
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen pool = pool_alloconly_create("auth lookup", 1024);
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen auth_conn = mail_storage_service_get_auth_conn(ctx->storage_service);
3343a61404603b21c246783a7963b77833095f31Timo Sirainen auth_socket_path = auth_master_get_socket_path(auth_conn);
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen ret = auth_master_pass_lookup(auth_conn, input->username, &info,
f1901fd21906911f7be075c965ac882f6a87b4c3Timo Sirainen *error_r = t_strdup_printf("%s: %s (to see if user is proxied, "
} else if (ret == 0) {
if (!proxying)
ret = 0;
*error_r);
return ret;
const char **error_r)
const char *host;
char *username_dup;
int ret;
if (ret < 0)
if (ret == 0 &&
char *key;
return ret;
static void doveadm_servers_destroy_all_connections(void)
char *key;
void doveadm_mail_server_flush(void)
if (DOVEADM_MAIL_SERVER_FAILED())