bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Disconnect client when it sends too many bad commands */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstatic const struct smtp_server_callbacks smtp_callbacks;
9249c80276766fdc4d31fc3eebc22fba7d53d77cStephan Boschstatic int submission_login_start_tls(void *conn_ctx,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct istream **input, struct ostream **output)
0afd9a9acab584e770ffcd6a0e1e02e2d18d360aJosef 'Jeff' Sipek struct submission_client *subm_client = conn_ctx;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch "TLS initialization failed.");
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch "Disconnected: TLS initialization failed.");
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstatic struct client *submission_client_alloc(pool_t pool)
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch subm_client = p_new(pool, struct submission_client, 1);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstatic void submission_client_create(struct client *client,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch static const char *const xclient_extensions[] =
c4588e66e80482994cf0fbc45251cb8e9db6404dJosef 'Jeff' Sipek container_of(client, struct submission_client, common);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_set.capabilities = SMTP_CAPABILITY_SIZE |
e1f52248b04b91cf1b5c8f55719391f03198242bStephan Bosch SMTP_CAPABILITY_ENHANCEDSTATUSCODES | SMTP_CAPABILITY_AUTH |
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_set.capabilities |= SMTP_CAPABILITY_STARTTLS;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_set.hostname = subm_client->set->hostname;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_set.login_greeting = client->set->login_greeting;
df957821a4b2e2d8708aa35cfe30860ee71af686Stephan Bosch (strcmp(client->ssl_set->ssl, "required") == 0);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_set.xclient_extensions = xclient_extensions;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch subm_client->conn = smtp_server_connection_create_from_streams(
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch &client->real_remote_ip, client->real_remote_port,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstatic void submission_client_destroy(struct client *client)
c4588e66e80482994cf0fbc45251cb8e9db6404dJosef 'Jeff' Sipek container_of(client, struct submission_client, common);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_server_connection_close(&subm_client->conn, NULL);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstatic void submission_client_notify_auth_ready(struct client *client)
c4588e66e80482994cf0fbc45251cb8e9db6404dJosef 'Jeff' Sipek container_of(client, struct submission_client, common);
40a926a1aeae93b3d4944b56eacb013d3059b549Stephan Bosch smtp_server_connection_start(subm_client->conn);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschsubmission_client_notify_disconnect(struct client *_client,
c4588e66e80482994cf0fbc45251cb8e9db6404dJosef 'Jeff' Sipek container_of(_client, struct submission_client, common);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_server_connection_terminate(&conn, "4.4.2", text);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_server_connection_terminate(&conn, "4.3.2", text);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_server_connection_terminate(&conn, "4.0.0", text);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch unsigned int i;
0afd9a9acab584e770ffcd6a0e1e02e2d18d360aJosef 'Jeff' Sipek struct submission_client *client = context;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch client->common.remote_port = data->source_port;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch for (i = 0; i < data->extra_fields_count; i++) {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const char *name = data->extra_fields[i].name;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const char *value = data->extra_fields[i].value;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch str_truncate(client->common.forward_fields, 0);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch "Invalid FORWARD parameter");
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch } else if (strcasecmp(name, "SESSION") == 0) {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstatic void client_connection_disconnect(void *context, const char *reason)
0afd9a9acab584e770ffcd6a0e1e02e2d18d360aJosef 'Jeff' Sipek struct submission_client *client = context;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstatic void client_connection_destroy(void *context)
0afd9a9acab584e770ffcd6a0e1e02e2d18d360aJosef 'Jeff' Sipek struct submission_client *client = context;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstatic bool client_connection_is_trusted(void *context)
0afd9a9acab584e770ffcd6a0e1e02e2d18d360aJosef 'Jeff' Sipek struct submission_client *client = context;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* do nothing. submission connections typically die pretty quick anyway.
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch login_set_roots = submission_login_setting_roots;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* override the default login_die() */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch master_service_set_die_callback(master_service, submission_login_die);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* initialize SMTP server */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_server_set.protocol = SMTP_PROTOCOL_SMTP;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_server_set.max_bad_commands = CLIENT_MAX_BAD_COMMANDS;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_server = smtp_server_init(&smtp_server_set);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstatic const struct smtp_server_callbacks smtp_callbacks = {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch .conn_cmd_xclient = client_connection_cmd_xclient,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch .conn_disconnect = client_connection_disconnect,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch .conn_is_trusted = client_connection_is_trusted
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstatic struct client_vfuncs submission_client_vfuncs = {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstatic const struct login_binary submission_login_binary = {