]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-ssl-iostream: Split code to openssl_iostream_shutdown()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 6 Jul 2018 08:24:41 +0000 (11:24 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 9 Jul 2018 07:39:36 +0000 (10:39 +0300)
src/lib-ssl-iostream/iostream-openssl.c
src/lib-ssl-iostream/iostream-openssl.h

index 2af3c001d26fdccf02c8b94294e27612e38a7a21..037fd0bae2fc303440e757f2ee5dad215be36b0a 100644 (file)
@@ -343,8 +343,14 @@ static void openssl_iostream_unref(struct ssl_iostream *ssl_io)
        openssl_iostream_free(ssl_io);
 }
 
-static void openssl_iostream_destroy(struct ssl_iostream *ssl_io)
+void openssl_iostream_shutdown(struct ssl_iostream *ssl_io)
 {
+       if (ssl_io->destroyed)
+               return;
+
+       i_assert(ssl_io->ssl_input != NULL);
+       i_assert(ssl_io->ssl_output != NULL);
+
        ssl_io->destroyed = TRUE;
        if (ssl_io->handshaked && SSL_shutdown(ssl_io->ssl) != 1) {
                /* if bidirectional shutdown fails we need to clear
@@ -357,7 +363,11 @@ static void openssl_iostream_destroy(struct ssl_iostream *ssl_io)
           but we may still keep this ssl-iostream referenced until later. */
        i_stream_close(ssl_io->plain_input);
        o_stream_close(ssl_io->plain_output);
+}
 
+static void openssl_iostream_destroy(struct ssl_iostream *ssl_io)
+{
+       openssl_iostream_shutdown(ssl_io);
        ssl_iostream_unref(&ssl_io);
 }
 
index ca34fae62387ef0543ab369d6c5769a91c0a6623..edd4a86af24328f072dc707b490a6b04ddf72bf7 100644 (file)
@@ -116,6 +116,9 @@ int openssl_iostream_handle_error(struct ssl_iostream *ssl_io, int ret,
                                  enum openssl_iostream_sync_type type,
                                  const char *func_name);
 
+/* Perform clean shutdown for the connection. */
+void openssl_iostream_shutdown(struct ssl_iostream *ssl_io);
+
 void openssl_iostream_set_error(struct ssl_iostream *ssl_io, const char *str);
 const char *openssl_iostream_error(void);
 const char *openssl_iostream_key_load_error(void);