bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen#include "lib.h"
73b8333f9a979efefe1db70f22c63edec5ad4466Timo Sirainen#include "module-dir.h"
4ff8be55becadd47c67c57ff1ec4f61b100fcab9Timo Sirainen#include "restrict-access.h"
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen#include "master-service.h"
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#include "config-connection.h"
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#include "config-parser.h"
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen#include "config-request.h"
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
db693bf6fcae96d834567f1782257517b7207655Timo Sirainenstatic void client_connected(struct master_service_connection *conn)
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen{
db693bf6fcae96d834567f1782257517b7207655Timo Sirainen master_service_client_connection_accept(conn);
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen (void)config_connection_create(conn->fd);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen}
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenint main(int argc, char *argv[])
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen{
ec1a4f4306496380e9d96ee08a3718a669d0875aTimo Sirainen const char *path, *error;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen master_service = master_service_init("config", 0, &argc, &argv, "");
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen if (master_getopt(master_service) > 0)
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen return FATAL_DEFAULT;
e0740628f6ca05f4bc79a9d8a90b650f4d38d4d0Timo Sirainen master_service_init_log(master_service, "config: ");
4ff8be55becadd47c67c57ff1ec4f61b100fcab9Timo Sirainen
816d20be0cf95fc4eb1a8aa716639e73b8ba525eMartti Rannanjärvi restrict_access_by_env(RESTRICT_ACCESS_FLAG_ALLOW_ROOT, NULL);
4ff8be55becadd47c67c57ff1ec4f61b100fcab9Timo Sirainen restrict_access_allow_coredumps(TRUE);
4ff8be55becadd47c67c57ff1ec4f61b100fcab9Timo Sirainen
fc4b301e2dd86c096b9c41ad1b011b752fffd570Timo Sirainen config_parse_load_modules();
ec1a4f4306496380e9d96ee08a3718a669d0875aTimo Sirainen
ec1a4f4306496380e9d96ee08a3718a669d0875aTimo Sirainen path = master_service_get_config_path(master_service);
633a3da9d3e9a5befd3405f6651043a6bdd327cbTimo Sirainen if (config_parse_file(path, TRUE, NULL, &error) <= 0)
ec1a4f4306496380e9d96ee08a3718a669d0875aTimo Sirainen i_fatal("%s", error);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
1af33d3c483b1759c4b184937b5f9829afb6b238Timo Sirainen /* notify about our success only after successfully parsing the
1af33d3c483b1759c4b184937b5f9829afb6b238Timo Sirainen config file, so if the parsing fails, master won't immediately
1af33d3c483b1759c4b184937b5f9829afb6b238Timo Sirainen just recreate this process (and fail again and so on). */
1af33d3c483b1759c4b184937b5f9829afb6b238Timo Sirainen master_service_init_finish(master_service);
1af33d3c483b1759c4b184937b5f9829afb6b238Timo Sirainen
4d4d6d4745682790c20d759ba93dbea46b812c5dTimo Sirainen master_service_run(master_service, client_connected);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen config_connections_destroy_all();
6ed1e82824590b514201d9db84ba96bdfc832dd5Timo Sirainen
6ed1e82824590b514201d9db84ba96bdfc832dd5Timo Sirainen config_filter_deinit(&config_filter);
73b8333f9a979efefe1db70f22c63edec5ad4466Timo Sirainen module_dir_unload(&modules);
6347bb65e93c27f1bf4330786447c9ab0cab4dbfTimo Sirainen config_parser_deinit();
4d4d6d4745682790c20d759ba93dbea46b812c5dTimo Sirainen master_service_deinit(&master_service);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen return 0;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen}