]> granicus.if.org Git - icinga2/commitdiff
ApiListener#NewClientHandlerInternal(): shut down TLS stream
authorAlexander A. Klimov <alexander.klimov@icinga.com>
Tue, 19 Feb 2019 17:06:14 +0000 (18:06 +0100)
committerAlexander A. Klimov <alexander.klimov@icinga.com>
Mon, 1 Apr 2019 11:30:42 +0000 (13:30 +0200)
lib/remote/apilistener.cpp

index 235e6c573e6f4842b20ad00fa71d26f2a36a47ed..56fda20e512a00b032d28ec2a2d06299fc247824 100644 (file)
@@ -7,6 +7,7 @@
 #include "remote/jsonrpc.hpp"
 #include "remote/apifunction.hpp"
 #include "base/convert.hpp"
+#include "base/defer.hpp"
 #include "base/io-engine.hpp"
 #include "base/netstring.hpp"
 #include "base/json.hpp"
@@ -570,6 +571,14 @@ void ApiListener::NewClientHandlerInternal(boost::asio::yield_context yc, const
                return;
        }
 
+       bool willBeShutDown = false;
+
+       Defer shutDownIfNeeded ([&sslConn, &willBeShutDown, &yc]() {
+               if (!willBeShutDown) {
+                       sslConn.async_shutdown(yc);
+               }
+       });
+
        std::shared_ptr<X509> cert (SSL_get_peer_certificate(sslConn.native_handle()), X509_free);
        String identity;
        Endpoint::Ptr endpoint;
@@ -684,6 +693,8 @@ void ApiListener::NewClientHandlerInternal(boost::asio::yield_context yc, const
 
                if (aclient) {
                        aclient->Start();
+
+                       willBeShutDown = true;
                }
        } else {
                Log(LogNotice, "ApiListener", "New HTTP client");
@@ -691,6 +702,8 @@ void ApiListener::NewClientHandlerInternal(boost::asio::yield_context yc, const
                HttpServerConnection::Ptr aclient = new HttpServerConnection(identity, verify_ok, client);
                AddHttpClient(aclient);
                aclient->Start();
+
+               willBeShutDown = true;
        }
 }