Commit 0d961fe9 0d961fe97ba3cf531a92967be2959e2e95a456aa by Alain Magloire

* pop3d/extra.c (pop3_readline) : Since the length of the string

is known, we can use memcpy() and friends for string manipulations.
memXXX() functions are builtin in GNU C (gcc) and are much faster
then the strXXX() counterparts. Small change in the loop to take
advantage of this.

* pop3d/quit.c : The rfc1939 insist that after a QUIT, we must
release any resources and close the connection:
"Whether the removal was successful or not, the server
then releases any exclusive-access lock on the maildrop
and closes the TCP connection."  This was not done if error
occured while expunging, no we will close the connection and
notify the client of the error(ERR_FILE).
1 parent 9a3839df
......@@ -169,6 +169,7 @@ pop3_readline (int fd)
struct timeval tv;
char buf[512], *ret = NULL;
int nread;
int total = 0;
int available;
FD_ZERO (&rfds);
......@@ -190,19 +191,13 @@ pop3_readline (int fd)
pop3_abquit (ERR_DEAD_SOCK);
buf[nread] = '\0';
ret = realloc (ret, (total + nread + 1) * sizeof (char));
if (ret == NULL)
{
ret = malloc ((nread + 1) * sizeof (char));
strcpy (ret, buf);
}
else
{
ret = realloc (ret, (strlen (ret) + nread + 1) * sizeof (char));
strcat (ret, buf);
}
pop3_abquit (ERR_NO_MEM);
memcpy (ret + total, buf, nread + 1);
total += nread;
}
while (strchr (buf, '\n') == NULL);
while (memchr (buf, '\n', nread) == NULL);
return ret;
}
......
......@@ -117,6 +117,7 @@ main (int argc, char **argv)
{
list_t bookie;
registrar_get_list (&bookie);
/* list_append (bookie, mbox_record); */
list_append (bookie, path_record);
}
......@@ -300,6 +301,8 @@ pop3_mainloop (int infile, int outfile)
fprintf (ofile, "-ERR [IN-USE] " MBOX_LOCK "\r\n");
else if (status == ERR_TOO_LONG)
fprintf (ofile, "-ERR " TOO_LONG "\r\n");
else if (status == ERR_FILE)
fprintf (ofile, "-ERR " FILE_EXP "\r\n");
else
fprintf (ofile, "-ERR unknown error\r\n");
......
......@@ -56,6 +56,9 @@
/* The command argument was > 40 characters */
#define TOO_LONG "Argument too long"
/* An error occured when expunging. */
#define FILE_EXP "Some deleted messages not removed"
/* APOP password file, without .db or .passwd, which are added based on file
type automatically */
#define APOP_PASSFILE "/etc/apop"
......
......@@ -18,17 +18,24 @@
#include "pop3d.h"
/* Enters the UPDATE phase and deletes marked messages */
/* Note:
Whether the removal was successful or not, the server
then releases any exclusive-access lock on the maildrop
and closes the TCP connection. */
int
pop3_quit (const char *arg)
{
int err = OK;
if (strlen (arg) != 0)
return ERR_BAD_ARGS;
if (state == TRANSACTION)
{
if (mailbox_expunge (mbox) != 0 || mailbox_close (mbox) != 0 )
return ERR_FILE;
if (mailbox_expunge (mbox) != 0)
err = ERR_FILE;
if (mailbox_close (mbox) != 0)
err = ERR_FILE;
mailbox_destroy (&mbox);
syslog (LOG_INFO, "Session ended for user: %s", username);
}
......@@ -39,6 +46,7 @@ pop3_quit (const char *arg)
free (username);
free (md5shared);
if (err == OK)
fprintf (ofile, "+OK\r\n");
return OK;
return err;
}
......