main.c revision 4e65040b019c061d242c8bc19bf76009679b8a15
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
fc40a9a002458e372ff4b9f6f4e15239520c0bcdTimo Sirainenstatic struct auth_worker_client *worker_client;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic ARRAY_DEFINE(listen_fd_types, enum auth_socket_type);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic void main_preinit(struct auth_settings *set)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* Open /dev/urandom before chrooting */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* Load built-in SQL drivers (if any) */
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen /* Initialize databases so their configuration files can be readable
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi only by root. Also load all modules here. */
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen modules = module_dir_load(AUTH_MODULE_DIR, NULL, TRUE,
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen master_service_get_version_string(master_service));
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* Password lookups etc. may require roots, allow it. */
df3963075d67f76ade66b6a74764f4eae31d9c87Josef 'Jeff' Sipekstatic void main_init(void)
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen /* If auth caches aren't used, just ignore these signals */
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen /* workers have only a single connection from the master
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen auth process */
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen master_service_set_client_limit(master_service, 1);
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainenstatic void main_deinit(void)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic void worker_connected(const struct master_service_connection *conn)
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen i_error("Auth workers can handle only a single client");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen worker_client = auth_worker_client_create(auth, conn->fd);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic void client_connected(const struct master_service_connection *conn)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen type = array_idx_modifiable(&listen_fd_types, conn->listen_fd);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* figure out if this is a server or network socket by
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen checking the socket path name. */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (net_getunixname(conn->listen_fd, &name) < 0)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen i_fatal("getsockname(%d) failed: %m", conn->listen_fd);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen (void)auth_master_connection_create(auth, conn->fd, FALSE);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen (void)auth_master_connection_create(auth, conn->fd, TRUE);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen (void)auth_client_connection_create(auth, conn->fd);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen master_service = master_service_init("auth", 0, &argc, &argv, "w");
6564208826b0f46a00f010d1b5711d85944c3c88Timo Sirainen master_service_init_log(master_service, "auth: ");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen while ((c = master_getopt(master_service)) > 0) {
return FATAL_DEFAULT;
main_init();
main_deinit();