bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */
c2d398246d2a5bb42beb083370695484142295f6Phil Carmodystatic struct config_connection *config_connections = NULL;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenstatic const char *const *
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenconfig_connection_next_line(struct config_connection *conn)
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainenconfig_request_output(const char *key, const char *value,
d84c270231a617298088f597474a73f4a14921aeTimo Sirainen enum config_key_type type ATTR_UNUSED, void *context)
1b33e848e84e6f74aa0e3339c32fa96bc15102a2Timo Sirainen const char *p;
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen o_stream_nsend(output, SETTING_STREAM_LF_CHAR, 1);
ec1a4f4306496380e9d96ee08a3718a669d0875aTimo Sirainenstatic int config_connection_request(struct config_connection *conn,
ec1a4f4306496380e9d96ee08a3718a669d0875aTimo Sirainen const char *const *args)
3b3a70990ab21c97140fcc2d1e3eb84c17d90388Timo Sirainen const char *path, *error, *module, *const *wanted_modules;
c3c0a727bdc9b883af7ae098785643464d13e332Timo Sirainen /* [<args>] */
1358e2c58ce29231485a5cfa454756d429ad3d2cTimo Sirainen if (net_addr2ip(*args + 4, &filter.local_net) == 0) {
1358e2c58ce29231485a5cfa454756d429ad3d2cTimo Sirainen if (net_addr2ip(*args + 4, &filter.remote_net) == 0) {
3b3a70990ab21c97140fcc2d1e3eb84c17d90388Timo Sirainen wanted_modules = array_count(&modules) == 1 ? NULL :
ec1a4f4306496380e9d96ee08a3718a669d0875aTimo Sirainen /* master reads configuration only when reloading settings */
ec1a4f4306496380e9d96ee08a3718a669d0875aTimo Sirainen path = master_service_get_config_path(master_service);
633a3da9d3e9a5befd3405f6651043a6bdd327cbTimo Sirainen if (config_parse_file(path, TRUE, NULL, &error) <= 0) {
3b3a70990ab21c97140fcc2d1e3eb84c17d90388Timo Sirainen ctx = config_export_init(wanted_modules, CONFIG_DUMP_SCOPE_SET, 0,
194755bdfb97c07ca8b9df071099f68947b971e3Timo Sirainen const char *const *s;
194755bdfb97c07ca8b9df071099f68947b971e3Timo Sirainen for (s = output.specific_services; *s != NULL; s++) {
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen o_stream_nsend_str(conn->output, "service-uses-local\t");
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen o_stream_nsend_str(conn->output, "service-uses-remote\t");
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen o_stream_nsend_str(conn->output, "used-local\t");
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen o_stream_nsend_str(conn->output, "used-remote\t");
27a44fcfd8d19bffe0f267f20a2b5d3fe7600fddTimo Sirainenstatic void config_connection_input(struct config_connection *conn)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen i_error("BUG: Config client connection sent too much data");
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen i_error("Config client not compatible with this server "
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen "(mixed old and new binaries?)");
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen while ((args = config_connection_next_line(conn)) != NULL) {
ec1a4f4306496380e9d96ee08a3718a669d0875aTimo Sirainen if (config_connection_request(conn, args + 1) < 0)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenstruct config_connection *config_connection_create(int fd)
e93184a9055c2530366dfe617e07199603c399ddMartti Rannanjärvi conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE);
e93184a9055c2530366dfe617e07199603c399ddMartti Rannanjärvi conn->output = o_stream_create_fd(fd, (size_t)-1);
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen o_stream_set_no_error_handling(conn->output, TRUE);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen conn->io = io_add(fd, IO_READ, config_connection_input, conn);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenvoid config_connection_destroy(struct config_connection *conn)
24ff367825286b52be4edb92df2fff0dd54cdf10Timo Sirainen master_service_client_connection_destroyed(master_service);