Andreas Thienemann afedbd
Andreas Thienemann afedbd
This patch should fix the spurious connection drops that fail jobs
Andreas Thienemann afedbd
as reported in bug #888.
Andreas Thienemann afedbd
Apply it to version 2.0.3 (possibly earlier versions of 2.0) with:
Andreas Thienemann afedbd
Andreas Thienemann afedbd
  cd <bacula-source>
Andreas Thienemann afedbd
  patch -p0 <2.0.3-tls-disconnect.patch
Andreas Thienemann afedbd
  make
Andreas Thienemann afedbd
  ...
Andreas Thienemann afedbd
  make install
Andreas Thienemann afedbd
Andreas Thienemann afedbd
Index: src/lib/tls.c
Andreas Thienemann afedbd
===================================================================
Andreas Thienemann afedbd
--- src/lib/tls.c	(revision 4668)
Andreas Thienemann afedbd
+++ src/lib/tls.c	(working copy)
Andreas Thienemann afedbd
@@ -540,14 +540,6 @@
Andreas Thienemann afedbd
     * The first time to initiate the shutdown handshake, and the second to
Andreas Thienemann afedbd
     * receive the peer's reply.
Andreas Thienemann afedbd
     *
Andreas Thienemann afedbd
-    * However, it is valid to close the SSL connection after the initial
Andreas Thienemann afedbd
-    * shutdown notification is sent to the peer, without waiting for the
Andreas Thienemann afedbd
-    * peer's reply, as long as you do not plan to re-use that particular
Andreas Thienemann afedbd
-    * SSL connection object.
Andreas Thienemann afedbd
-    *
Andreas Thienemann afedbd
-    * Because we do not re-use SSL connection objects, I do not bother
Andreas Thienemann afedbd
-    * calling SSL_shutdown a second time.
Andreas Thienemann afedbd
-    *
Andreas Thienemann afedbd
     * In addition, if the underlying socket is blocking, SSL_shutdown()
Andreas Thienemann afedbd
     * will not return until the current stage of the shutdown process has
Andreas Thienemann afedbd
     * completed or an error has occured. By setting the socket blocking
Andreas Thienemann afedbd
@@ -560,6 +552,10 @@
Andreas Thienemann afedbd
    flags = bnet_set_blocking(bsock);
Andreas Thienemann afedbd
 
Andreas Thienemann afedbd
    err = SSL_shutdown(bsock->tls->openssl);
Andreas Thienemann afedbd
+   if (err == 0) {
Andreas Thienemann afedbd
+      /* Finish up the closing */
Andreas Thienemann afedbd
+      err = SSL_shutdown(bsock->tls->openssl);
Andreas Thienemann afedbd
+   }
Andreas Thienemann afedbd
 
Andreas Thienemann afedbd
    switch (SSL_get_error(bsock->tls->openssl, err)) {
Andreas Thienemann afedbd
       case SSL_ERROR_NONE:
Andreas Thienemann afedbd
@@ -574,8 +570,6 @@
Andreas Thienemann afedbd
          break;
Andreas Thienemann afedbd
    }
Andreas Thienemann afedbd
 
Andreas Thienemann afedbd
-   /* Restore saved flags */
Andreas Thienemann afedbd
-   bnet_restore_blocking(bsock, flags);
Andreas Thienemann afedbd
 }
Andreas Thienemann afedbd
 
Andreas Thienemann afedbd
 /* Does all the manual labor for tls_bsock_readn() and tls_bsock_writen() */