]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_smtp.c
* serv_smtp.c: instead of doubling delivery retry times unbounded, set a
[citadel.git] / citadel / serv_smtp.c
index 41ea537572beba944f119c673ce52c5d547f2cb6..7cd291824dcf4fd63dd988b5d2bb7aa47cfa6e6f 100644 (file)
 #include <pwd.h>
 #include <errno.h>
 #include <sys/types.h>
-#include <sys/time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
 #include <sys/wait.h>
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
-#include <time.h>
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
@@ -91,8 +101,7 @@ void smtp_greeting(void) {
        CtdlAllocUserData(SYM_SMTP_RECP, SIZ);
        sprintf(SMTP_RECP, "%s", "");
 
-       cprintf("220 Welcome to the Citadel/UX ESMTP server at %s\r\n",
-               config.c_fqdn);
+       cprintf("220 %s ESMTP Citadel/UX server ready.\r\n", config.c_fqdn);
 }
 
 
@@ -107,7 +116,7 @@ void smtp_hello(char *argbuf, int is_esmtp) {
                cprintf("250 Greetings and joyous salutations.\r\n");
        }
        else {
-               cprintf("250-Greetings and joyous salutations.\r\n");
+               cprintf("250-Extended greetings and joyous salutations.\r\n");
                cprintf("250-HELP\r\n");
                cprintf("250-SIZE %ld\r\n", config.c_maxmsglen);
                cprintf("250 AUTH=LOGIN\r\n");
@@ -119,7 +128,7 @@ void smtp_hello(char *argbuf, int is_esmtp) {
  * Implement HELP command.
  */
 void smtp_help(void) {
-       cprintf("214-Here's the frequency, Kenneth:\r\n");
+       cprintf("214-Commands accepted:\r\n");
        cprintf("214-    DATA\r\n");
        cprintf("214-    EHLO\r\n");
        cprintf("214-    EXPN\r\n");
@@ -131,7 +140,7 @@ void smtp_help(void) {
        cprintf("214-    RCPT\r\n");
        cprintf("214-    RSET\r\n");
        cprintf("214-    VRFY\r\n");
-       cprintf("214 I could tell you more, but then I'd have to kill you.\r\n");
+       cprintf("214     \r\n");
 }
 
 
@@ -440,7 +449,7 @@ void smtp_rcpt(char *argbuf) {
 
                case rfc822_address_nonlocal:
                        if (SMTP->message_originated_locally == 0) {
-                               cprintf("551 Relaying denied\r\n");
+                               cprintf("551 Third-party relaying denied.\r\n");
                        }
                        else {
                                cprintf("250 Remote recipient %s ok\r\n", recp);
@@ -672,7 +681,7 @@ void smtp_data(void) {
        CtdlFreeMessage(msg);
 
        if (!retval) {
-               cprintf("250 Message accepted for delivery.\r\n");
+               cprintf("250 ok terrific\r\n");
        }
        else {
                cprintf("550 Internal delivery errors: %d\r\n", retval);
@@ -688,80 +697,78 @@ void smtp_data(void) {
  * Main command loop for SMTP sessions.
  */
 void smtp_command_loop(void) {
-       char *icmdbuf;
+       char cmdbuf[SIZ];
 
        time(&CC->lastcmd);
-       if (client_gets(&icmdbuf) < 1) {
+       memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
+       if (client_gets(cmdbuf) < 1) {
                lprintf(3, "SMTP socket is broken.  Ending session.\n");
                CC->kill_me = 1;
                return;
        }
-       /* Rather than fix the dynamic buffer a zillion places in here... */
-       if (strlen(icmdbuf) >= SIZ)
-         *(icmdbuf+SIZ)= '\0'; /* no SMTP command should be this big */
-       lprintf(5, "citserver[%3d]: %s\n", CC->cs_pid, icmdbuf);
-       while (strlen(icmdbuf) < 5) strcat(icmdbuf, " ");
+       lprintf(5, "citserver[%3d]: %s\n", CC->cs_pid, cmdbuf);
+       while (strlen(cmdbuf) < 5) strcat(cmdbuf, " ");
 
        if (SMTP->command_state == smtp_user) {
-               smtp_get_user(icmdbuf);
+               smtp_get_user(cmdbuf);
        }
 
        else if (SMTP->command_state == smtp_password) {
-               smtp_get_pass(icmdbuf);
+               smtp_get_pass(cmdbuf);
        }
 
-       else if (!strncasecmp(icmdbuf, "AUTH", 4)) {
-               smtp_auth(&icmdbuf[5]);
+       else if (!strncasecmp(cmdbuf, "AUTH", 4)) {
+               smtp_auth(&cmdbuf[5]);
        }
 
-       else if (!strncasecmp(icmdbuf, "DATA", 4)) {
+       else if (!strncasecmp(cmdbuf, "DATA", 4)) {
                smtp_data();
        }
 
-       else if (!strncasecmp(icmdbuf, "EHLO", 4)) {
-               smtp_hello(&icmdbuf[5], 1);
+       else if (!strncasecmp(cmdbuf, "EHLO", 4)) {
+               smtp_hello(&cmdbuf[5], 1);
        }
 
-       else if (!strncasecmp(icmdbuf, "EXPN", 4)) {
-               smtp_expn(&icmdbuf[5]);
+       else if (!strncasecmp(cmdbuf, "EXPN", 4)) {
+               smtp_expn(&cmdbuf[5]);
        }
 
-       else if (!strncasecmp(icmdbuf, "HELO", 4)) {
-               smtp_hello(&icmdbuf[5], 0);
+       else if (!strncasecmp(cmdbuf, "HELO", 4)) {
+               smtp_hello(&cmdbuf[5], 0);
        }
 
-       else if (!strncasecmp(icmdbuf, "HELP", 4)) {
+       else if (!strncasecmp(cmdbuf, "HELP", 4)) {
                smtp_help();
        }
 
-       else if (!strncasecmp(icmdbuf, "MAIL", 4)) {
-               smtp_mail(&icmdbuf[5]);
+       else if (!strncasecmp(cmdbuf, "MAIL", 4)) {
+               smtp_mail(&cmdbuf[5]);
        }
 
-       else if (!strncasecmp(icmdbuf, "NOOP", 4)) {
+       else if (!strncasecmp(cmdbuf, "NOOP", 4)) {
                cprintf("250 This command successfully did nothing.\r\n");
        }
 
-       else if (!strncasecmp(icmdbuf, "QUIT", 4)) {
+       else if (!strncasecmp(cmdbuf, "QUIT", 4)) {
                cprintf("221 Goodbye...\r\n");
                CC->kill_me = 1;
                return;
                }
 
-       else if (!strncasecmp(icmdbuf, "RCPT", 4)) {
-               smtp_rcpt(&icmdbuf[5]);
+       else if (!strncasecmp(cmdbuf, "RCPT", 4)) {
+               smtp_rcpt(&cmdbuf[5]);
        }
 
-       else if (!strncasecmp(icmdbuf, "RSET", 4)) {
+       else if (!strncasecmp(cmdbuf, "RSET", 4)) {
                smtp_rset();
        }
 
-       else if (!strncasecmp(icmdbuf, "VRFY", 4)) {
-               smtp_vrfy(&icmdbuf[5]);
+       else if (!strncasecmp(cmdbuf, "VRFY", 4)) {
+               smtp_vrfy(&cmdbuf[5]);
        }
 
        else {
-               cprintf("502 I'm sorry Dave, I'm afraid I can't do that.\r\n");
+               cprintf("502 I'm afraid I can't do that.\r\n");
        }
 
 }
@@ -1307,6 +1314,9 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
                if (!strcasecmp(key, "retry")) {
                        /* double the retry interval after each attempt */
                        retry = extract_long(buf, 1) * 2L;
+                       if (retry > SMTP_RETRY_MAX) {
+                               retry = SMTP_RETRY_MAX;
+                       }
                        remove_token(instr, i, '\n');
                }
                if (!strcasecmp(key, "attempted")) {