bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2017-2018 Dovecot authors, see the included COPYING file */
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch (const struct smtp_server_settings *server_set);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtypedef void (*test_client_init_t)(unsigned int index);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic struct smtp_server_callbacks server_callbacks;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic struct connection_list *client_conn_list;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic void (*test_client_connected)(struct client_connection *conn);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic void (*test_client_input)(struct client_connection *conn);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch * Forward declarations
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_defaults(struct smtp_server_settings *smtp_set);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_run(const struct smtp_server_settings *smtp_set);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic void test_client_run(unsigned int index);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch const struct smtp_server_settings *server_set,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch * Slow server
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_slow_server_input(struct client_connection *conn ATTR_UNUSED)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch /* do nothing */
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_slow_server_connected(struct client_connection *conn)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "EHLO frop\r\n");
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic void test_client_slow_server(unsigned int index)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch test_client_connected = test_slow_server_connected;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_slow_server_destroyed(struct smtp_server_cmd_ctx *cmd)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct _slow_server *ctx = (struct _slow_server *)cmd->context;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_slow_server_delayed(struct _slow_server *ctx)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch reply = smtp_server_reply_create_ehlo(cmd->cmd);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_slow_server_cmd_helo(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct smtp_server_cmd_helo *data ATTR_UNUSED)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch cmd->hook_destroy = test_server_slow_server_destroyed;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch(const struct smtp_server_settings *server_set)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch server_callbacks.conn_cmd_helo = test_server_slow_server_cmd_helo;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch smtp_server_set.max_client_idle_time_msecs = 1000;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch * Slow client
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_slow_client_input(struct client_connection *conn ATTR_UNUSED)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch /* nothing */
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_slow_client_connected(struct client_connection *conn)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "EHLO frop\r\n");
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic void test_client_slow_client(unsigned int index)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch test_client_connected = test_slow_client_connected;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_slow_client_disconnect_timeout(struct _slow_client *ctx)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_slow_client_disconnect(void *conn_ctx, const char *reason)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct server_connection *conn = (struct server_connection *)conn_ctx;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct _slow_client *ctx = (struct _slow_client *)conn->context;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_slow_client_cmd_destroyed(struct smtp_server_cmd_ctx *cmd)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct _slow_client *ctx = (struct _slow_client *)cmd->context;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_slow_client_delayed(struct _slow_client *ctx)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch reply = smtp_server_reply_create_ehlo(cmd->cmd);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch test_server_slow_client_disconnect_timeout, ctx);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_slow_client_cmd_helo(void *conn_ctx,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct smtp_server_cmd_helo *data ATTR_UNUSED)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch cmd->hook_destroy = test_server_slow_client_cmd_destroyed;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch(const struct smtp_server_settings *server_set)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch server_callbacks.conn_disconnect = test_server_slow_client_disconnect;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch server_callbacks.conn_cmd_helo = test_server_slow_client_cmd_helo;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch smtp_server_set.max_client_idle_time_msecs = 1000;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch * Hanging command payload
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_hanging_command_payload_connected(struct client_connection *conn)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "EHLO frop\r\n"
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "MAIL FROM:<hangman@example.com>\r\n"
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "RCPT TO:<jerry@example.com>\r\n"
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "To be continued... or not");
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic void test_client_hanging_command_payload(unsigned int index)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch test_client_connected = test_hanging_command_payload_connected;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_hanging_command_payload_trans_free(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch (struct _hanging_command_payload *)trans->context;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_hanging_command_payload_rcpt(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_hanging_command_payload_data_begin(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch ctx = i_new(struct _hanging_command_payload, 1);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_hanging_command_payload_data_continue(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch (struct _hanging_command_payload *)trans->context;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch while ((ret=i_stream_read_data(ctx->payload_input,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic void test_server_hanging_command_payload
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch(const struct smtp_server_settings *server_set)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch test_server_hanging_command_payload_trans_free;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch test_server_hanging_command_payload_data_begin;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch test_server_hanging_command_payload_data_continue;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch smtp_server_set.max_client_idle_time_msecs = 1000;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch * Bad command
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_bad_command_connected(struct client_connection *conn)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "EHLO\tfrop\r\n");
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic void test_client_bad_command(unsigned int index)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch test_client_connected = test_bad_command_connected;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_bad_command_disconnect(void *context ATTR_UNUSED, const char *reason)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_bad_command_helo(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct smtp_server_cmd_helo *data ATTR_UNUSED)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_bad_command_rcpt(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct smtp_server_cmd_rcpt *data ATTR_UNUSED)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_bad_command_data_begin(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct smtp_server_transaction *trans ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch(const struct smtp_server_settings *server_set)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch smtp_server_set.max_client_idle_time_msecs = 1000;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch * Long command
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_long_command_connected(struct client_connection *conn)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "EHLO some.very.very.very.very.very.long.domain\r\n");
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic void test_client_long_command(unsigned int index)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch test_client_connected = test_long_command_connected;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_long_command_disconnect(void *context ATTR_UNUSED, const char *reason)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_long_command_helo(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct smtp_server_cmd_helo *data ATTR_UNUSED)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_long_command_rcpt(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct smtp_server_cmd_rcpt *data ATTR_UNUSED)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_long_command_data_begin(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct smtp_server_transaction *trans ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch(const struct smtp_server_settings *server_set)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch smtp_server_set.max_client_idle_time_msecs = 1000;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch smtp_server_set.command_limits.max_parameters_size = 32;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_big_data_connected(struct client_connection *conn)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "EHLO frop\r\n"
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "MAIL FROM:<sender@example.com>\r\n"
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "RCPT TO:<recipient@example.com>\r\n"
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "0123456789ABCDEF0123456789ABCDEF\r\n"
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "0123456789ABCDEF0123456789ABCDEF\r\n"
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "0123456789ABCDEF0123456789ABCDEF\r\n"
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "0123456789ABCDEF0123456789ABCDEF\r\n"
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "0123456789ABCDEF0123456789ABCDEF\r\n"
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "0123456789ABCDEF0123456789ABCDEF\r\n"
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "0123456789ABCDEF0123456789ABCDEF\r\n"
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic void test_client_big_data(unsigned int index)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch test_client_connected = test_big_data_connected;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_big_data_trans_free(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_big_data_rcpt(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_big_data_data_begin(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_big_data_data_continue(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch while (ctx->payload_input->v_offset < max_size &&
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch if (ctx->payload_input->v_offset + size > max_size) {
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch size = max_size - ctx->payload_input->v_offset;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch if (ctx->payload_input->v_offset >= max_size) {
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "Message too big for system");
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch(const struct smtp_server_settings *server_set)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch smtp_server_set.max_client_idle_time_msecs = 1000;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch smtp_server_set.command_limits.max_data_size = 64;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_bad_ehlo_connected(struct client_connection *conn)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch "EHLO \r\n");
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic void test_client_bad_ehlo(unsigned int index)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch test_client_connected = test_bad_ehlo_connected;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_bad_ehlo_disconnect(void *context ATTR_UNUSED, const char *reason)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_bad_ehlo_helo(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct smtp_server_cmd_helo *data ATTR_UNUSED)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_bad_ehlo_rcpt(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct smtp_server_cmd_rcpt *data ATTR_UNUSED)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_bad_ehlo_data_begin(void *conn_ctx ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct smtp_server_transaction *trans ATTR_UNUSED,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch(const struct smtp_server_settings *server_set)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch smtp_server_set.max_client_idle_time_msecs = 1000;
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch * Too many recipients
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Boschtest_too_many_recipients_connected(struct client_connection *conn)
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "EHLO frop\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "MAIL FROM:<sender@example.com>\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "RCPT TO:<recipient1@example.com>\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "RCPT TO:<recipient2@example.com>\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "RCPT TO:<recipient3@example.com>\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "RCPT TO:<recipient4@example.com>\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "RCPT TO:<recipient5@example.com>\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "RCPT TO:<recipient6@example.com>\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "RCPT TO:<recipient7@example.com>\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "RCPT TO:<recipient8@example.com>\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "RCPT TO:<recipient9@example.com>\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "RCPT TO:<recipient10@example.com>\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "RCPT TO:<recipient11@example.com>\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "0123456789ABCDEF0123456789ABCDEF\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "0123456789ABCDEF0123456789ABCDEF\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "0123456789ABCDEF0123456789ABCDEF\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "0123456789ABCDEF0123456789ABCDEF\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "0123456789ABCDEF0123456789ABCDEF\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "0123456789ABCDEF0123456789ABCDEF\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch "0123456789ABCDEF0123456789ABCDEF\r\n"
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Boschstatic void test_client_too_many_recipients(unsigned int index)
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch test_client_connected = test_too_many_recipients_connected;
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Boschtest_server_too_many_recipients_trans_free(void *conn_ctx ATTR_UNUSED,
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch struct smtp_server_transaction *trans ATTR_UNUSED)
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Boschtest_server_too_many_recipients_rcpt(void *conn_ctx ATTR_UNUSED,
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Boschtest_server_too_many_recipients_data_begin(void *conn_ctx ATTR_UNUSED,
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch test_assert(array_count(&trans->rcpt_to) == 10);
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch(const struct smtp_server_settings *server_set)
4dd460cf19f1df3b51090427fea87e9c4b73c6d4Stephan Bosch smtp_server_set.max_client_idle_time_msecs = 1000;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic void (*const test_functions[])(void) = {
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch * Test client
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch/* client connection */
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschclient_connection_input(struct connection *_conn)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct client_connection *conn = (struct client_connection *)_conn;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschclient_connection_connected(struct connection *_conn, bool success)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch struct client_connection *conn = (struct client_connection *)_conn;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschclient_connection_init(const struct ip_addr *ip, in_port_t port)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch pool = pool_alloconly_create("client connection", 256);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch conn = p_new(pool, struct client_connection, 1);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschserver_connection_deinit(struct client_connection **_conn)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschclient_connection_destroy(struct connection *_conn)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic struct connection_settings client_connection_set = {
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic const struct connection_vfuncs client_connection_vfuncs = {
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch .client_connected = client_connection_connected,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic void test_client_run(unsigned int index)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch i_debug("client connecting to %u", bind_port);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch (&client_connection_set, &client_connection_vfuncs);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch /* close server socket */
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch * Test server
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_defaults(struct smtp_server_settings *smtp_set)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch /* server settings */
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch smtp_set->max_client_idle_time_msecs = 5*1000;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch/* client connection */
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschstatic void server_connection_destroy(void *context)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschserver_connection_accept(void *context ATTR_UNUSED)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch /* accept new client */
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch server_callbacks.conn_destroy = server_connection_destroy;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch conn = smtp_server_connection_create(smtp_server, fd, fd,
40a926a1aeae93b3d4944b56eacb013d3059b549Stephan Bosch NULL, 0, FALSE, NULL, &server_callbacks, sconn);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Boschtest_server_run(const struct smtp_server_settings *smtp_set)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch /* open server socket */
677b75f90d81eafe742896d6570a2f63ce501d05Josef 'Jeff' Sipek IO_READ, server_connection_accept, NULL);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch /* close server socket */
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch int fd = net_listen(&bind_ip, &bind_port, 128);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch unsigned int i;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch for (i = 0; i < client_pids_count; i++) {
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch const struct smtp_server_settings *server_set,
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch unsigned int i;
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch client_pids = i_new(pid_t, client_tests_count);
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch for (i = 0; i < client_tests_count; i++)
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch for (i = 0; i < client_tests_count; i++) {
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch if (client_pids[i] == 0) {
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch /* child: client */
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch usleep(100000); /* wait a little for server setup */
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch /* wait for it to be killed; this way, valgrind
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch will not object to this process going away
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch inelegantly. */
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch /* parent: server */
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch /* make sure we don't leave any pesky children alive */
b85d7b8561dba4072a61f6df26443896072efae9Stephan Bosch /* listen on localhost */