main.c revision f059a046515f4b2b15a6c2a10a6f12f6166e39a5
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainenconst struct login_settings *global_login_settings;
c000c8eca8f24b2a0c76393ec4bbf76a505a4983Timo Sirainenstatic void client_connected(const struct master_service_connection *conn)
4307c886579381dbb1897ea1388ae6978c96f560Timo Sirainen if (net_getsockname(conn->fd, &local_ip, &local_port) < 0) {
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen pool = pool_alloconly_create("login client", 3*1024);
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen set = login_settings_read(master_service, pool, &local_ip,
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen client = client_create(conn->fd, FALSE, pool, set, other_sets,
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen fd_ssl = ssl_proxy_new(conn->fd, &conn->remote_ip, set, &proxy);
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen client = client_create(fd_ssl, TRUE, pool, set, other_sets,
8ed8c821ba8aab0b4ed0375f87d48737ef0e0d8eTimo Sirainenstatic void auth_connect_notify(struct auth_client *client ATTR_UNUSED,
8ed8c821ba8aab0b4ed0375f87d48737ef0e0d8eTimo Sirainenstatic int anvil_connect(void)
8ed8c821ba8aab0b4ed0375f87d48737ef0e0d8eTimo Sirainen#define ANVIL_HANDSHAKE "VERSION\tanvil\t1\t0\n"
e93184a9055c2530366dfe617e07199603c399ddMartti Rannanjärvi while ((fd = net_connect_unix("anvil")) == -1) {
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainen i_fatal("net_connect_unix(anvil) failed: %m");
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen if (write(fd, ANVIL_HANDSHAKE, strlen(ANVIL_HANDSHAKE)) < 0)
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainenstatic void main_preinit(void)
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen unsigned int max_fds;
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen /* Initialize SSL proxy so it can read certificate and private
c000c8eca8f24b2a0c76393ec4bbf76a505a4983Timo Sirainen /* set the number of fds we want to use. it may get increased or
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen decreased. leave a couple of extra fds for auth sockets and such.
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen worst case each connection can use:
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen - 1 for client
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen - 1 for login proxy
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen - 2 for client-side ssl proxy
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen - 2 for server-side ssl proxy (with login proxy)
3d4c24127f4f83259c0f81851184abc34793dbe0Timo Sirainen master_service_get_socket_count(master_service) +
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen master_service_get_client_limit(master_service)*6;
3d4c24127f4f83259c0f81851184abc34793dbe0Timo Sirainen io_loop_set_max_fd_count(current_ioloop, max_fds);
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen i_assert(strcmp(global_login_settings->ssl, "no") == 0 ||
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen if (global_login_settings->mail_max_userip_connections > 0)
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainenstatic void main_init(void)
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen /* make sure we can't fork() */
424236b2b88a5a7bbde5cf6a6b32189ca3437629Timo Sirainen if (restrict_access_get_current_chroot() == NULL) {
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen master_service_set_avail_overflow_callback(master_service,
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen auth_client = auth_client_init("auth", (unsigned int)getpid(), FALSE);
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen auth_client_set_connect_notify(auth_client, auth_connect_notify, NULL);
f1901fd21906911f7be075c965ac882f6a87b4c3Timo Sirainen master_auth = master_auth_init(master_service, login_protocol);
f1901fd21906911f7be075c965ac882f6a87b4c3Timo Sirainenstatic void main_deinit(void)
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen master_service = master_service_init(login_process_name, service_flags,
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen master_service_init_log(master_service, t_strconcat(
e5afebd2df1d4990f7bec2a839260ff2e6d78168Timo Sirainen getopt_str = t_strconcat("DS", master_service_getopt_string(), NULL);
ccc895c0358108d2304239063e940b7d75f364abTimo Sirainen while ((c = getopt(argc, argv, getopt_str)) > 0) {
ccc895c0358108d2304239063e940b7d75f364abTimo Sirainen if (!master_service_parse_option(master_service,
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen set_pool = pool_alloconly_create("global login settings", 4096);
3343a61404603b21c246783a7963b77833095f31Timo Sirainen login_settings_read(master_service, set_pool, NULL, NULL,
f1901fd21906911f7be075c965ac882f6a87b4c3Timo Sirainen /* main_preinit() needs to know the client limit, which is set by
f1901fd21906911f7be075c965ac882f6a87b4c3Timo Sirainen this. so call it first. */
main_init();
main_deinit();