[1259] in Kerberos-V5-bugs

home help back first fref pref prev next nref lref last post

krb5b4pl3: popper: deal properly with abnormal termination of client

daemon@ATHENA.MIT.EDU (Jonathan I. Kamens)
Thu Mar 23 16:19:56 1995

From: "Jonathan I. Kamens" <jik@cam.ov.com>
Date: Thu, 23 Mar 1995 16:23:10 -0500
To: krb5-bugs@MIT.EDU

There are two fixes in the patch below, to help popper deal properly
when a client disconnects in mid-session:

1) Ignore SIGPIPE, so the server won't get a signal and die without
cleaning up.

2) When a connection is terminated abnormally, execute pop RSET and
QUIT commands, so that all messages are copied back into the user's
maildrop.

Please forward these patches back to the original authors of the
popper code, if appropriate.

--- popper.c	1995/03/23 21:20:21	1.1
+++ popper.c	1995/03/23 21:21:26
@@ -11,6 +11,7 @@
 
 #include <stdio.h>
 #include <sys/types.h>
+#include <signal.h>
 #include "popper.h"
 
 extern  state_table *   pop_get_command();
@@ -26,6 +27,8 @@
     state_table     *   s;
     char                message[MAXLINELEN];
 
+    signal(SIGPIPE, SIG_IGN);
+
     /*  Start things rolling */
     pop_init(&p,argc,argv);
 
@@ -54,6 +57,25 @@
 
         /*  Obtain a line from the client */
         if (fgets(message,MAXLINELEN,p.input) == NULL) {
+	    /*
+	     * Abnormal termination of connection should result in a
+	     * reset of the mailbox (so that messages are not lost)
+	     * and a quit (so that messages are copied back into the
+	     * maildrop).
+	     */
+	    /*
+	     * Use strcpy to put the two commands into the message
+	     * buffer to avoid problems with read-only strings (since
+	     * pop_get_command modifies the string passed into it).
+	     */
+	    strcpy(message, "RSET\r\n");
+	    if ((s = pop_get_command(&p, message)) && s->function) {
+		(*s->function)(&p);
+	    }
+	    strcpy(message, "QUIT\r\n");
+	    if ((s = pop_get_command(&p, message)) && s->function) {
+		(*s->function)(&p);
+	    }
             p.CurrentState = error;
             pop_msg(&p,POP_FAILURE,"POP server at %s signing off.",p.myhost);
         }

home help back first fref pref prev next nref lref last post