]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: smtp-server-connection: Add smtp_server_connection_abort().
authorStephan Bosch <stephan.bosch@open-xchange.com>
Fri, 9 Aug 2019 21:10:59 +0000 (23:10 +0200)
committerStephan Bosch <stephan.bosch@open-xchange.com>
Tue, 13 Aug 2019 22:46:26 +0000 (00:46 +0200)
Provides a clean method to abort the connection before it is even started.

src/lib-smtp/smtp-server-connection.c
src/lib-smtp/smtp-server.h

index 476f94ad7fb5f90b0659e3fc86be8452768dcd56..8c4f2e36b1cc02d93782e311ac4497389786075e 100644 (file)
@@ -1232,6 +1232,31 @@ void smtp_server_connection_start(struct smtp_server_connection *conn)
        smtp_server_connection_resume(conn);
 }
 
+void smtp_server_connection_abort(struct smtp_server_connection **_conn,
+                                 unsigned int status, const char *enh_code,
+                                 const char *reason)
+{
+       struct smtp_server_connection *conn = *_conn;
+       const char **reason_lines;
+
+       if (conn == NULL)
+               return;
+       *_conn = NULL;
+
+       i_assert(!conn->started);
+       conn->started = TRUE;
+
+       if (conn->authenticated) {
+               reason_lines = t_strsplit_spaces(reason, "\r\n");
+               smtp_server_connection_reply_lines(
+                       conn, status, enh_code, reason_lines);
+               smtp_server_connection_terminate(
+                       &conn, "4.3.2", "Shutting down due to fatal error");
+       } else {
+               smtp_server_connection_terminate(&conn, enh_code, reason);
+       }
+}
+
 void smtp_server_connection_halt(struct smtp_server_connection *conn)
 {
        conn->halted = TRUE;
index b176a40f602b02f750b36f10a024919c9ebcb3c7..633282761e72533752a004ee756ec4415fbf182f 100644 (file)
@@ -420,6 +420,10 @@ void smtp_server_connection_start(struct smtp_server_connection *conn);
    handling command input is held off until smtp_server_connection_resume() is
    called. */
 void smtp_server_connection_start_pending(struct smtp_server_connection *conn);
+/* Abort the connection prematurely (before it is started). */
+void smtp_server_connection_abort(struct smtp_server_connection **_conn,
+                                 unsigned int status, const char *enh_code,
+                                 const char *reason);
 
 /* Halt connection command input and idle timeout entirely. */
 void smtp_server_connection_halt(struct smtp_server_connection *conn);