The attached patch tries to play it safe. To the fastmail.fm crew, are you
sure all those prot_fill calls are really needed? SHUT_RD should dump any
unread data from the socket anyway...

I have also tracked down some closes() that the original fastmail.fm patch
does not fix to properly shutdown the stream, and reduced the penalty on
linux for tcp-wrapper blocked connections to the bare minimum using
SHUT_RDWR.

Patches rediffed against stock 2.1.4 tarball.

-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
diff -ru cyrus-imapd-2.1.4.orig/imap/backend.c cyrus-imapd-2.1.4/imap/backend.c
--- cyrus-imapd-2.1.4.orig/imap/backend.c       Wed Apr  3 20:11:18 2002
+++ cyrus-imapd-2.1.4/imap/backend.c    Sun May 19 13:10:56 2002
@@ -411,6 +411,7 @@
        }
     }
 
+    shutdown(s->sock, SHUT_RD);
     close(s->sock);
     prot_free(s->in);
     prot_free(s->out);
diff -ru cyrus-imapd-2.1.4.orig/imap/fud.c cyrus-imapd-2.1.4/imap/fud.c
--- cyrus-imapd-2.1.4.orig/imap/fud.c   Fri Feb 22 14:25:26 2002
+++ cyrus-imapd-2.1.4/imap/fud.c        Sun May 19 13:10:56 2002
@@ -146,6 +146,14 @@
     mboxlist_close();
     mboxlist_done();
     closelog();
+
+    /* be nice to remote */
+    shutdown(0, SHUT_RD);
+    shutdown(1, SHUT_RD);
+    shutdown(2, SHUT_RD);
+    close(0);
+    close(1);
+    close(2);
     exit(code);
 }
 
diff -ru cyrus-imapd-2.1.4.orig/imap/imapd.c cyrus-imapd-2.1.4/imap/imapd.c
--- cyrus-imapd-2.1.4.orig/imap/imapd.c Thu Apr 25 15:15:14 2002
+++ cyrus-imapd-2.1.4/imap/imapd.c      Sun May 19 13:10:56 2002
@@ -428,6 +428,9 @@
     if (imapd_in) prot_free(imapd_in);
     if (imapd_out) prot_free(imapd_out);
     imapd_in = imapd_out = NULL;
+    shutdown(0, SHUT_RD);
+    shutdown(1, SHUT_RD);
+    shutdown(2, SHUT_RD);
     close(0);
     close(1);
     close(2);
@@ -730,6 +733,14 @@
        /* one less active connection */
        snmp_increment(ACTIVE_CONNECTIONS, -1);
     }
+
+    /* shutdown socket nicely */
+    shutdown(0, SHUT_RD);
+    shutdown(1, SHUT_RD);
+    shutdown(2, SHUT_RD);
+    close(0);
+    close(1);
+    close(2);
 
     exit(code);
 }
Only in cyrus-imapd-2.1.4/imap: imapd.c.orig
diff -ru cyrus-imapd-2.1.4.orig/imap/lmtpd.c cyrus-imapd-2.1.4/imap/lmtpd.c
--- cyrus-imapd-2.1.4.orig/imap/lmtpd.c Mon Apr 15 11:42:17 2002
+++ cyrus-imapd-2.1.4/imap/lmtpd.c      Sun May 19 13:10:56 2002
@@ -342,6 +342,9 @@
        deliver_logfd = -1;
     }
 
+    shutdown(0, SHUT_RD);
+    shutdown(1, SHUT_RD);
+    shutdown(2, SHUT_RD);
     close(0);
     close(1);
     close(2);
@@ -1380,6 +1383,14 @@
        /* one less active connection */
        snmp_increment(ACTIVE_CONNECTIONS, -1);
     }
+
+    /* shutdown socket nicely */
+    shutdown(0, SHUT_RD);
+    shutdown(1, SHUT_RD);
+    shutdown(2, SHUT_RD);
+    close(0);
+    close(1);
+    close(2);
 
     exit(code);
 }
Only in cyrus-imapd-2.1.4/imap: lmtpd.c.orig
diff -ru cyrus-imapd-2.1.4.orig/imap/lmtpproxyd.c cyrus-imapd-2.1.4/imap/lmtpproxyd.c
--- cyrus-imapd-2.1.4.orig/imap/lmtpproxyd.c    Tue Apr 30 13:49:28 2002
+++ cyrus-imapd-2.1.4/imap/lmtpproxyd.c Sun May 19 13:10:56 2002
@@ -326,6 +326,9 @@
         deliver_logfd = -1;
     }
 
+    shutdown(0, SHUT_RD);
+    shutdown(1, SHUT_RD);
+    shutdown(2, SHUT_RD);
     close(0);
     close(1);
     close(2);
Only in cyrus-imapd-2.1.4/imap: lmtpproxyd.c.orig
diff -ru cyrus-imapd-2.1.4.orig/imap/pop3d.c cyrus-imapd-2.1.4/imap/pop3d.c
--- cyrus-imapd-2.1.4.orig/imap/pop3d.c Wed Apr 10 15:02:42 2002
+++ cyrus-imapd-2.1.4/imap/pop3d.c      Sun May 19 13:10:56 2002
@@ -252,6 +252,9 @@
     if (popd_in) prot_free(popd_in);
     if (popd_out) prot_free(popd_out);
     popd_in = popd_out = NULL;
+    shutdown(0, SHUT_RD);
+    shutdown(1, SHUT_RD);
+    shutdown(2, SHUT_RD);
     close(0);
     close(1);
     close(2);
@@ -484,6 +487,12 @@
     tls_shutdown_serverengine();
 #endif
     if (popd_out) prot_flush(popd_out);
+    shutdown(0, SHUT_RD);
+    shutdown(1, SHUT_RD);
+    shutdown(2, SHUT_RD);
+    close(0);
+    close(1);
+    close(2);
     exit(code);
 }
 
Only in cyrus-imapd-2.1.4/imap: pop3d.c.orig
diff -ru cyrus-imapd-2.1.4.orig/imap/pop3proxyd.c cyrus-imapd-2.1.4/imap/pop3proxyd.c
--- cyrus-imapd-2.1.4.orig/imap/pop3proxyd.c    Tue Apr 23 15:41:33 2002
+++ cyrus-imapd-2.1.4/imap/pop3proxyd.c Sun May 19 13:10:56 2002
@@ -339,6 +339,12 @@
     tls_shutdown_serverengine();
 #endif
     if (popd_out) prot_flush(popd_out);
+    shutdown(0, SHUT_RD);
+    shutdown(1, SHUT_RD);
+    shutdown(2, SHUT_RD);
+    close(0);
+    close(1);
+    close(2);
     exit(code);
 }
 
@@ -1289,11 +1295,16 @@
     /* ok, we're done. close backend connection */
     prot_free(backend_in);
     prot_free(backend_out);
+    shutdown(backend_sock, SHUT_RD);
     close(backend_sock);
 
     /* close the connection to the client */
+    shutdown(0, SHUT_RD);
+    shutdown(1, SHUT_RD);
+    shutdown(2, SHUT_RD);
     close(0);
     close(1);
+    close(2);
     prot_free(popd_in);
     prot_free(popd_out);
 
Only in cyrus-imapd-2.1.4/imap: pop3proxyd.c.orig
diff -ru cyrus-imapd-2.1.4.orig/imap/proxyd.c cyrus-imapd-2.1.4/imap/proxyd.c
--- cyrus-imapd-2.1.4.orig/imap/proxyd.c        Sun Apr 28 15:12:50 2002
+++ cyrus-imapd-2.1.4/imap/proxyd.c     Sun May 19 13:10:56 2002
@@ -971,6 +971,9 @@
     if(proxyd_in) prot_free(proxyd_in);
     if(proxyd_out) prot_free(proxyd_out);
     proxyd_in = proxyd_out = NULL;
+    shutdown(0, SHUT_RD);
+    shutdown(1, SHUT_RD);
+    shutdown(2, SHUT_RD);
     close(0);
     close(1);
     close(2);
Only in cyrus-imapd-2.1.4/imap: proxyd.c.orig
diff -ru cyrus-imapd-2.1.4.orig/master/service.c cyrus-imapd-2.1.4/master/service.c
--- cyrus-imapd-2.1.4.orig/master/service.c     Fri Mar  8 16:26:17 2002
+++ cyrus-imapd-2.1.4/master/service.c  Sun May 19 13:10:56 2002
@@ -413,6 +413,7 @@
 
            if (!libwrap_ask(&request, fd)) {
                /* connection denied! */
+               shutdown(fd, SHUT_RDWR);
                close(fd);
                continue;
            }
Only in cyrus-imapd-2.1.4/master: service.c.orig
diff -ru cyrus-imapd-2.1.4.orig/timsieved/timsieved.c 
cyrus-imapd-2.1.4/timsieved/timsieved.c
--- cyrus-imapd-2.1.4.orig/timsieved/timsieved.c        Fri Apr  5 18:55:42 2002
+++ cyrus-imapd-2.1.4/timsieved/timsieved.c     Sun May 19 13:10:56 2002
@@ -120,6 +120,13 @@
        prot_free(sieved_out);
     }
     if (sieved_in) prot_free(sieved_in);
+
+    shutdown(0, SHUT_RD);
+    shutdown(1, SHUT_RD);
+    shutdown(2, SHUT_RD);
+    close(0);
+    close(1);
+    close(2);
     
     /* done */
     exit(code);

Reply via email to