main.c revision 2e37d45867d081db150ab78dad303b9077aea24f
2e37d45867d081db150ab78dad303b9077aea24fTimo Sirainen/* Copyright (c) 2010-2011 Dovecot authors, see the included COPYING file */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "lib.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "ioloop.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "array.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "restrict-access.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "master-interface.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "master-service.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "master-service-settings.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "auth-connection.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "doveadm-connection.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "login-connection.h"
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen#include "notify-connection.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "director.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "director-host.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "director-connection.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "director-request.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "mail-host.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
ae46f6ba5bb9eee8900254d3042e89d490023be0Timo Sirainen#include <stdio.h>
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include <unistd.h>
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
3f3ad16ff74d694796d22501250a9a29997c0729Timo Sirainen#define AUTH_SOCKET_PATH "auth-login"
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen#define AUTH_USERDB_SOCKET_PATH "auth-userdb"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic struct director *director;
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainenstatic struct notify_connection *notify_conn;
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainenstatic char *auth_socket_path, *userdb_socket_path;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic int director_client_connected(int fd, const struct ip_addr *ip)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen{
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen if (director_host_lookup_ip(director, ip) == NULL) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen i_warning("Connection from %s: Server not listed in "
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen "director_servers, dropping", net_ip2addr(ip));
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return -1;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen director_connection_init_in(director, fd, ip);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return 0;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen}
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
db693bf6fcae96d834567f1782257517b7207655Timo Sirainenstatic void client_connected(struct master_service_connection *conn)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen{
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen struct auth_connection *auth;
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen const char *path, *name, *socket_path;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen struct ip_addr ip;
5801ce4da7d807ab85d02051ece5969e7175eebaTimo Sirainen unsigned int local_port, len;
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen bool userdb;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen if (conn->fifo) {
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen if (notify_conn != NULL) {
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen i_error("Received another proxy-notify connection");
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen return;
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen }
db693bf6fcae96d834567f1782257517b7207655Timo Sirainen master_service_client_connection_accept(conn);
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen notify_conn = notify_connection_init(director, conn->fd);
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen return;
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen }
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen
5801ce4da7d807ab85d02051ece5969e7175eebaTimo Sirainen if (net_getpeername(conn->fd, &ip, NULL) == 0 &&
5801ce4da7d807ab85d02051ece5969e7175eebaTimo Sirainen net_getsockname(conn->fd, NULL, &local_port) == 0 &&
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen (IPADDR_IS_V4(&ip) || IPADDR_IS_V6(&ip))) {
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen /* TCP/IP connection */
5801ce4da7d807ab85d02051ece5969e7175eebaTimo Sirainen if (local_port == director->set->director_doveadm_port) {
db693bf6fcae96d834567f1782257517b7207655Timo Sirainen master_service_client_connection_accept(conn);
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen (void)doveadm_connection_init(director, conn->fd);
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen } else {
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen if (director_client_connected(conn->fd, &ip) == 0)
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen master_service_client_connection_accept(conn);
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen if (net_getunixname(conn->listen_fd, &path) < 0)
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen i_fatal("getunixname(%d) failed: %m", conn->listen_fd);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen name = strrchr(path, '/');
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen if (name == NULL)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen name = path;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen else
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen name++;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen len = strlen(name);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen if (len > 6 && strcmp(name + len - 6, "-admin") == 0) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* doveadm connection */
db693bf6fcae96d834567f1782257517b7207655Timo Sirainen master_service_client_connection_accept(conn);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen (void)doveadm_connection_init(director, conn->fd);
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen return;
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen }
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen /* a) userdb connection, probably for lmtp proxy
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen b) login connection
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen Both of them are handled exactly the same, except for which
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen auth socket they connect to. */
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen userdb = len > 7 && strcmp(name + len - 7, "-userdb") == 0;
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen socket_path = userdb ? userdb_socket_path : auth_socket_path;
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen auth = auth_connection_init(socket_path);
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen if (auth_connection_connect(auth) == 0) {
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen master_service_client_connection_accept(conn);
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen login_connection_init(director, conn->fd, auth, userdb);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen } else {
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen auth_connection_deinit(&auth);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen}
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
fa87f0ef3636fa52ce42513533ee500c0bf29910Timo Sirainenstatic unsigned int
fa87f0ef3636fa52ce42513533ee500c0bf29910Timo Sirainenfind_inet_listener_port(struct ip_addr *ip_r,
fa87f0ef3636fa52ce42513533ee500c0bf29910Timo Sirainen const struct director_settings *set)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen{
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int i, socket_count, port;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen socket_count = master_service_get_socket_count(master_service);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen for (i = 0; i < socket_count; i++) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen int fd = MASTER_LISTEN_FD_FIRST + i;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
fa87f0ef3636fa52ce42513533ee500c0bf29910Timo Sirainen if (net_getsockname(fd, ip_r, &port) == 0 && port > 0 &&
fa87f0ef3636fa52ce42513533ee500c0bf29910Timo Sirainen port != set->director_doveadm_port)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return port;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return 0;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen}
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic void director_state_changed(struct director *dir)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen{
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen struct director_request *const *requestp;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen bool ret;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
242abe3ad2423776e9cf05e1304eb8fda4831b23Timo Sirainen if (!dir->ring_synced ||
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainen mail_host_get_by_hash(dir->mail_hosts, 0) == NULL)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* if there are any pending client requests, finish them now */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen array_foreach(&dir->pending_requests, requestp) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen ret = director_request_continue(*requestp);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen i_assert(ret);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen array_clear(&dir->pending_requests);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen if (dir->to_request != NULL)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen timeout_remove(&dir->to_request);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen}
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic void main_init(void)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen{
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen const struct director_settings *set;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen struct ip_addr listen_ip;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int listen_port;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen set = master_service_settings_get_others(master_service)[0];
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen auth_socket_path = i_strconcat(set->base_dir,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen "/"AUTH_SOCKET_PATH, NULL);
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen userdb_socket_path = i_strconcat(set->base_dir,
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen "/"AUTH_USERDB_SOCKET_PATH, NULL);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
fa87f0ef3636fa52ce42513533ee500c0bf29910Timo Sirainen listen_port = find_inet_listener_port(&listen_ip, set);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen if (listen_port == 0 && *set->director_servers != '\0') {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen i_fatal("No inet_listeners defined for director service "
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen "(for standalone keep director_servers empty)");
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen director = director_init(set, &listen_ip, listen_port,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen director_state_changed);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen director_host_add_from_string(director, set->director_servers);
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainen if (mail_hosts_parse_and_add(director->mail_hosts,
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainen set->director_mail_servers) < 0)
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainen i_fatal("Invalid value for director_mail_servers setting");
edd318d5866ac3fbc6e8df28fb24a4dfef93c884Timo Sirainen director->orig_config_hosts = mail_hosts_dup(director->mail_hosts);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen}
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic void main_deinit(void)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen{
8dd76854cc680053986142d5f5e823f637447929Timo Sirainen if (notify_conn != NULL)
8dd76854cc680053986142d5f5e823f637447929Timo Sirainen notify_connection_deinit(&notify_conn);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen director_deinit(&director);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen doveadm_connections_deinit();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen login_connections_deinit();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen auth_connections_deinit();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen i_free(auth_socket_path);
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen i_free(userdb_socket_path);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen}
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenint main(int argc, char *argv[])
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen{
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen const struct setting_parser_info *set_roots[] = {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen &director_setting_parser_info,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen NULL
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen };
412b772c337428b72149605c1410524c2353e5d4Timo Sirainen const enum master_service_flags service_flags =
412b772c337428b72149605c1410524c2353e5d4Timo Sirainen MASTER_SERVICE_FLAG_NO_IDLE_DIE |
412b772c337428b72149605c1410524c2353e5d4Timo Sirainen MASTER_SERVICE_FLAG_UPDATE_PROCTITLE;
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen unsigned int test_port = 0;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen const char *error;
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen bool debug = FALSE;
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen int c;
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen
412b772c337428b72149605c1410524c2353e5d4Timo Sirainen master_service = master_service_init("director", service_flags,
f9f77e06a148fd0816004e0e1b0f585307148a7dTimo Sirainen &argc, &argv, "Dt:");
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen while ((c = master_getopt(master_service)) > 0) {
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen switch (c) {
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen case 'D':
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen debug = TRUE;
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen break;
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen case 't':
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen if (str_to_uint(optarg, &test_port) < 0)
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen i_fatal("-t: Not a number: %s", optarg);
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen break;
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen default:
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen return FATAL_DEFAULT;
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen }
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen if (master_service_settings_read_simple(master_service, set_roots,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen &error) < 0)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen i_fatal("Error reading configuration: %s", error);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen master_service_init_log(master_service, "director: ");
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen restrict_access_by_env(NULL, FALSE);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen restrict_access_allow_coredumps(TRUE);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen master_service_init_finish(master_service);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen main_init();
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen director->test_port = test_port;
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen director->debug = debug;
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen director_connect(director);
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen if (director->test_port != 0) {
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen /* we're testing, possibly writing to same log file.
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen make it clear which director we are. */
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen master_service_init_log(master_service,
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen t_strdup_printf("director(%s): ",
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen net_ip2addr(&director->self_ip)));
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen }
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen master_service_run(master_service, client_connected);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen main_deinit();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen master_service_deinit(&master_service);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return 0;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen}