bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinastatic const struct smtp_server_callbacks lmtp_callbacks;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinastatic const char *client_remote_id(struct client *client)
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina str_append(title, client_state_get_name(client));
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina str_printfa(title, "%u connections", clients_count);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinastatic void client_raw_user_create(struct client *client)
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sets = master_service_settings_get_others(master_service);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina raw_storage_create_from_set(client->user_set_info, sets[0]);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinastatic void client_read_settings(struct client *client, bool ssl)
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina const struct setting_parser_context *set_parser;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (mail_storage_service_read_settings(storage_service, &input,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina lmtp_settings_dup(set_parser, client->pool, &lmtp_set, &lda_set);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina mail_storage_service_get_var_expand_table(storage_service, &input);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (settings_var_expand(&lmtp_setting_parser_info, lmtp_set,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina i_fatal("Failed to expand settings: %s", error);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina client->service_set = master_service_settings_get(master_service);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinastruct client *client_create(int fd_in, int fd_out,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina pool = pool_alloconly_create("lmtp client", 2048);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina client->state_pool = pool_alloconly_create("client state", 4096);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina client->my_domain = client->unexpanded_lda_set->hostname;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (!conn->ssl && master_service_ssl_is_enabled(master_service))
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina lmtp_set.capabilities |= SMTP_CAPABILITY_STARTTLS;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina lmtp_set.hostname = client->unexpanded_lda_set->hostname;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina lmtp_set.max_client_idle_time_msecs = CLIENT_IDLE_TIMEOUT_MSECS;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina conn->ssl, &lmtp_set, &lmtp_callbacks, client);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina i_info("Connect from %s", client_remote_id(client));
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina o_stream_unref(&client->state.mail_data_output);
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březinavoid client_destroy(struct client *client, const char *enh_code,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina master_service_client_connection_destroyed(master_service);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinaconst char *client_state_get_name(struct client *client)
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina state = smtp_server_connection_get_state(client->conn);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinavoid client_disconnect(struct client *client, const char *enh_code,
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina struct smtp_server_connection *conn = client->conn;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina i_info("Disconnect from %s: %s (state = %s)", client_remote_id(client),
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina client->last_state = smtp_server_connection_get_state(conn);
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina (enh_code == NULL ? "4.0.0" : enh_code), reason);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina struct smtp_server_transaction *trans ATTR_UNUSED)
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina struct client *client = (struct client *)context;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinaclient_connection_state_changed(void *context ATTR_UNUSED,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinaclient_connection_proxy_data_updated(void *context,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina struct client *client = (struct client *)context;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinastatic void client_connection_disconnect(void *context, const char *reason)
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina struct client *client = (struct client *)context;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina struct smtp_server_connection *conn = client->conn;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina client->last_state = smtp_server_connection_get_state(conn);
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březinastatic void client_connection_destroy(void *context)
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina struct client *client = (struct client *)context;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinastatic bool client_connection_is_trusted(void *context)
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina struct client *client = (struct client *)context;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (client->lmtp_set->login_trusted_networks == NULL)
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina net = t_strsplit_spaces(client->lmtp_set->login_trusted_networks, ", ");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (net_parse_range(*net, &net_ip, &bits) < 0) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (net_is_in_network(&client->remote_ip, &net_ip, bits))
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina client_destroy(clients, "4.3.2", "Shutting down");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinastatic const struct smtp_server_callbacks lmtp_callbacks = {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina .conn_trans_free = client_connection_trans_free,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina .conn_state_changed = client_connection_state_changed,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina .conn_proxy_data_updated = client_connection_proxy_data_updated,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina .conn_disconnect = client_connection_disconnect,