main.c revision 0a53eb0283d7ec28c6105f61e118b96fce8ecb95
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozekstatic int director_client_connected(int fd, const struct ip_addr *ip)
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina if (director_host_lookup_ip(director, ip) == NULL) {
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina i_warning("Connection from %s: Server not listed in "
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina "director_servers, dropping", net_ip2addr(ip));
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina director_connection_init_in(director, fd, ip);
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březinastatic void client_connected(struct master_service_connection *conn)
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce i_error("Received another proxy-notify connection");
07b92f78d1751d8a2a538a440e1fdb24c59021e0Pavel Březina notify_conn = notify_connection_init(director, conn->fd);
1f800ebb0f190854b8296146174f3d696a426333Simo Sorce if (net_getpeername(conn->fd, &ip, &port) == 0 &&
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce /* TCP/IP connection - this is another director */
1f800ebb0f190854b8296146174f3d696a426333Simo Sorce if (director_client_connected(conn->fd, &ip) == 0)
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek if (net_getunixname(conn->listen_fd, &path) < 0)
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek i_fatal("getunixname(%d) failed: %m", conn->listen_fd);
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek if (len > 6 && strcmp(name + len - 6, "-admin") == 0) {
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek /* doveadm connection */
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek (void)doveadm_connection_init(director, conn->fd);
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek /* login connection */
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek login_connection_init(director, conn->fd, auth);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorcestatic unsigned int find_inet_listener_port(struct ip_addr *ip_r)
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce socket_count = master_service_get_socket_count(master_service);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce for (i = 0; i < socket_count; i++) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (net_getsockname(fd, ip_r, &port) == 0 && port > 0)
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorcestatic void director_state_changed(struct director *dir)
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina mail_host_get_by_hash(dir->mail_hosts, 0) == NULL)
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina /* if there are any pending client requests, finish them now */
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina array_foreach(&dir->pending_requests, requestp) {
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březinastatic void main_init(void)
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina set = master_service_settings_get_others(master_service)[0];
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina listen_port = find_inet_listener_port(&listen_ip);
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina if (listen_port == 0 && *set->director_servers != '\0') {
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina i_fatal("No inet_listeners defined for director service "
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina "(for standalone keep director_servers empty)");
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březina director = director_init(set, &listen_ip, listen_port,
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina director_host_add_from_string(director, set->director_servers);
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina if (mail_hosts_parse_and_add(director->mail_hosts,
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina i_fatal("Invalid value for director_mail_servers setting");
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina director->orig_config_hosts = mail_hosts_dup(director->mail_hosts);
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březinastatic void main_deinit(void)
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina const struct setting_parser_info *set_roots[] = {
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina unsigned int test_port = 0;
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina master_service = master_service_init("director",
0b81cc5d41ec6a1c58e610f402fd93a1fbda4affPavel Březina while ((c = master_getopt(master_service)) > 0) {
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce if (master_service_settings_read_simple(master_service, set_roots,
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce i_fatal("Error reading configuration: %s", error);
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny master_service_init_log(master_service, "director: ");
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny /* we're testing, possibly writing to same log file.
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny make it clear which director we are. */