[tpop3d-discuss]mailbox->apply_changes() at connection_shutdown().

Jacek Dębowczyk j.debowczyk at diface.com
Fri, 30 Sep 2005 18:48:55 +0200


--envbJBWh7q8WU6mo
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

Hi,

probably I found bug in use of mailbox->apply_changes(). This is called only
when when client sends QUIT command. Therefore in situation when client
sends number of DELE and simly closes connection, these commands won't be
applied (in my opinion they should).
I'm attaching patches, which repairs this bug. Additionaly I'm using
cucipop-style logging in my system, which is placed in these patches.

Best regards,
Jacek Dębowczyk

--envbJBWh7q8WU6mo
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: attachment; filename="connection.c.patch"

--- connection.c.orig	Fri Nov 14 20:15:20 2003
+++ connection.c	Fri Sep 30 18:30:55 2005
@@ -146,6 +146,7 @@
     c->state = authorisation;
 
     c->idlesince = time(NULL);
+    c->start_time = c->idlesince;
     c->frozenuntil = 0;
 
     if (!connection_sendresponse(c, 1, c->timestamp)) {
@@ -206,7 +207,14 @@
     if (connection_isfrozen(c) || buffer_available(c->wrb) > 0) {
         c->do_shutdown = 1;
         return IOABS_WOULDBLOCK;
-    } else return c->io->shutdown(c);
+    } else {
+        if (c->m) {
+            mailbox curmbox;
+            curmbox = c->m; /* this connection's mailbox */
+            (curmbox)->apply_changes(curmbox);                
+        }
+        return c->io->shutdown(c);
+    }
 }
 
 /* connection_send_now CONNECTION DATA COUNT

--envbJBWh7q8WU6mo
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: attachment; filename="connection.h.patch"

--- connection.h.orig	Sun Jul 31 18:36:40 2005
+++ connection.h	Sun Jul 31 18:36:40 2005
@@ -66,6 +66,7 @@
     mailbox m;
 
     listener l;             /* need listener for STLS           */
+    time_t start_time;
 } *connection;
 
 /* struct ioabs:

--envbJBWh7q8WU6mo
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: attachment; filename="ioabs_tcp.c.patch"

--- ioabs_tcp.c.orig	Fri Sep 30 18:06:29 2005
+++ ioabs_tcp.c	Fri Sep 30 18:07:19 2005
@@ -101,11 +101,11 @@
         if (n == 0) {
             /* Connection has been closed. */
             log_print(LOG_INFO, _("ioabs_tcp_post_select: client %s: connection closed by peer"), c->idstr);
-            ioabs_tcp_shutdown(c);
+            c->do_shutdown = 1;
             return 0;
         } else if (n == -1 && errno != EAGAIN) {
             log_print(LOG_ERR, _("ioabs_tcp_post_select: client %s: read: %m; closing connection"), c->idstr);
-            ioabs_tcp_shutdown(c);
+            c->do_shutdown = 1;
             return 0;
         }
     }

--envbJBWh7q8WU6mo
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: attachment; filename="netloop.c.patch"

--- netloop.c.orig	Sun Jul 31 18:36:40 2005
+++ netloop.c	Sun Jul 31 18:36:40 2005
@@ -462,8 +462,12 @@
         if (c->cstate == closed) {
             /* We should now log the closure of the connection and ending
              * of any authenticated session. */
-            if (c->a)
+            if (c->a) {
                 log_print(LOG_INFO, _("connections_post_select: client %s: finished session for `%s' with %s"), c->idstr, c->a->user, c->a->auth);
+                if (c->m)
+                    log_print(LOG_NOTICE, _("%s[%d] %s%s %d, %d (%d), %d (%d)"), c->a->user, c->a->uid, c->remote_ip, (c->secured ? ":SSL" : ""),
+                              time(NULL) - c->start_time, c->m->numdeleted, c->m->sizedeleted, c->m->num, c->m->totalsize);
+            }
             log_print(LOG_INFO, _("connections_post_select: client %s: disconnected; %d/%d bytes read/written"), c->idstr, c->nrd, c->nwr);
 
 /*            remove_connection(c);*/

--envbJBWh7q8WU6mo
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: attachment; filename="pop3.c.patch"

--- pop3.c.orig	Fri Sep 30 17:51:05 2005
+++ pop3.c	Fri Sep 30 17:52:19 2005
@@ -614,9 +614,6 @@
                 break;
 
             case QUIT:
-                /* Now perform UPDATE */
-                if ((curmbox)->apply_changes(curmbox)) connection_sendresponse(c, 1, _("Done"));
-                else connection_sendresponse(c, 0, _("Something went wrong."));
                 return close_connection;
 
             case NOOP:

--envbJBWh7q8WU6mo--