clean up the SMTP stuff some more
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Wed, 21 Oct 1981 03:36:54 +0000 (19:36 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Wed, 21 Oct 1981 03:36:54 +0000 (19:36 -0800)
SCCS-vsn: usr.sbin/sendmail/src/collect.c 3.25
SCCS-vsn: usr.sbin/sendmail/src/util.c 3.11
SCCS-vsn: usr.sbin/sendmail/src/version.c 3.52
SCCS-vsn: usr.sbin/sendmail/src/main.c 3.44
SCCS-vsn: usr.sbin/sendmail/src/macro.c 3.6
SCCS-vsn: usr.sbin/sendmail/src/srvrsmtp.c 3.3

usr/src/usr.sbin/sendmail/src/collect.c
usr/src/usr.sbin/sendmail/src/macro.c
usr/src/usr.sbin/sendmail/src/main.c
usr/src/usr.sbin/sendmail/src/srvrsmtp.c
usr/src/usr.sbin/sendmail/src/util.c
usr/src/usr.sbin/sendmail/src/version.c

index 32f6405..cf75cc6 100644 (file)
@@ -1,7 +1,7 @@
 # include <errno.h>
 # include "sendmail.h"
 
 # include <errno.h>
 # include "sendmail.h"
 
-static char    SccsId[] = "@(#)collect.c       3.24    %G%";
+static char    SccsId[] = "@(#)collect.c       3.25    %G%";
 
 /*
 **  COLLECT -- read & parse message header & make temp file.
 
 /*
 **  COLLECT -- read & parse message header & make temp file.
@@ -76,11 +76,13 @@ maketemp(from)
 
        if (fgets(buf, sizeof buf, stdin) == NULL)
                return;
 
        if (fgets(buf, sizeof buf, stdin) == NULL)
                return;
+       fixcrlf(buf, FALSE);
 # ifndef NOTUNIX
        if (!SaveFrom && strncmp(buf, "From ", 5) == 0)
        {
                eatfrom(buf);
                (void) fgets(buf, sizeof buf, stdin);
 # ifndef NOTUNIX
        if (!SaveFrom && strncmp(buf, "From ", 5) == 0)
        {
                eatfrom(buf);
                (void) fgets(buf, sizeof buf, stdin);
+               fixcrlf(buf, FALSE);
        }
 # endif NOTUNIX
 
        }
 # endif NOTUNIX
 
@@ -97,6 +99,8 @@ maketemp(from)
                register char c;
                extern bool isheader();
 
                register char c;
                extern bool isheader();
 
+               fixcrlf(buf, FALSE);
+
                /* see if the header is over */
                if (!isheader(buf))
                        break;
                /* see if the header is over */
                if (!isheader(buf))
                        break;
@@ -108,6 +112,7 @@ maketemp(from)
                        *p++ = c;
                        if (fgets(p, sizeof buf - (p - buf), stdin) == NULL)
                                break;
                        *p++ = c;
                        if (fgets(p, sizeof buf - (p - buf), stdin) == NULL)
                                break;
+                       fixcrlf(p, FALSE);
                }
                if (!feof(stdin))
                        (void) ungetc(c, stdin);
                }
                if (!feof(stdin))
                        (void) ungetc(c, stdin);
@@ -129,7 +134,10 @@ maketemp(from)
 
        /* throw away a blank line */
        if (buf[0] == '\n')
 
        /* throw away a blank line */
        if (buf[0] == '\n')
+       {
                (void) fgets(buf, sizeof buf, stdin);
                (void) fgets(buf, sizeof buf, stdin);
+               fixcrlf(buf, FALSE);
+       }
 
        /*
        **  Collect the body of the message.
 
        /*
        **  Collect the body of the message.
@@ -140,6 +148,8 @@ maketemp(from)
                register int i;
                register char *bp = buf;
 
                register int i;
                register char *bp = buf;
 
+               fixcrlf(buf, FALSE);
+
                /* check for end-of-message */
                if (!IgnrDot && buf[0] == '.' && (buf[1] == '\n' || buf[1] == '\0'))
                        break;
                /* check for end-of-message */
                if (!IgnrDot && buf[0] == '.' && (buf[1] == '\n' || buf[1] == '\0'))
                        break;
@@ -173,7 +183,7 @@ maketemp(from)
                        {
                                (void) freopen(InFileName, "w", tf);
                                fputs("\nMAIL DELETED BECAUSE OF LACK OF DISK SPACE\n\n", tf);
                        {
                                (void) freopen(InFileName, "w", tf);
                                fputs("\nMAIL DELETED BECAUSE OF LACK OF DISK SPACE\n\n", tf);
-                               syserr("collect: Out of disk space for temp file");
+                               usrerr("452 Out of disk space for temp file");
                        }
                        else
                                syserr("collect: Cannot write %s", InFileName);
                        }
                        else
                                syserr("collect: Cannot write %s", InFileName);
index 5f82465..21224e3 100644 (file)
@@ -1,7 +1,7 @@
 # include "useful.h"
 # include "conf.h"
 
 # include "useful.h"
 # include "conf.h"
 
-static char SccsId[] = "@(#)macro.c    3.5     %G%";
+static char SccsId[] = "@(#)macro.c    3.6     %G%";
 
 char   *Macro[128];
 extern int     Debug;
 
 char   *Macro[128];
 extern int     Debug;
@@ -125,6 +125,7 @@ expand(s, buf, buflim)
 **             $f   raw from address
 **             $g   translated from address
 **             $h   to host
 **             $f   raw from address
 **             $g   translated from address
 **             $h   to host
+**             $i   official SMTP hostname, used in messages+
 **             $l   UNIX-style from line+
 **             $n   name of sendmail ("MAILER-DAEMON" on local
 **                  net typically)+
 **             $l   UNIX-style from line+
 **             $n   name of sendmail ("MAILER-DAEMON" on local
 **                  net typically)+
index 88964d1..9a3002a 100644 (file)
@@ -8,7 +8,7 @@
 # include <syslog.h>
 # endif LOG
 
 # include <syslog.h>
 # endif LOG
 
-static char    SccsId[] = "@(#)main.c  3.43    %G%";
+static char    SccsId[] = "@(#)main.c  3.44    %G%";
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
@@ -137,6 +137,7 @@ main(argc, argv)
        char cbuf[5];                   /* holds hop count */
        char dbuf[30];                  /* holds ctime(tbuf) */
        char ybuf[10];                  /* holds tty id */
        char cbuf[5];                   /* holds hop count */
        char dbuf[30];                  /* holds ctime(tbuf) */
        char ybuf[10];                  /* holds tty id */
+       char ibuf[30];                  /* holds HostName */
        bool aliasinit = FALSE;
        extern char *ttyname();
        extern bool safefile();
        bool aliasinit = FALSE;
        extern char *ttyname();
        extern bool safefile();
@@ -401,6 +402,8 @@ main(argc, argv)
        */
 
        readcf(ConfFile, safecf);
        */
 
        readcf(ConfFile, safecf);
+       (void) expand("$i", ibuf, &ibuf[sizeof ibuf - 1]);
+       HostName = ibuf;
 
        /*
        **  Initialize aliases.
 
        /*
        **  Initialize aliases.
index b0efbbd..258c4ae 100644 (file)
@@ -1,6 +1,6 @@
 # include "sendmail.h"
 
 # include "sendmail.h"
 
-static char    SccsId[] =      "@(#)srvrsmtp.c 3.2     %G%";
+static char    SccsId[] =      "@(#)srvrsmtp.c 3.3     %G%";
 
 /*
 **  SMTP -- run the SMTP protocol.
 
 /*
 **  SMTP -- run the SMTP protocol.
@@ -59,28 +59,23 @@ smtp()
        bool hasmail;                   /* mail command received */
        bool hasmrcp;                   /* has a recipient */
        bool hasdata;                   /* has mail data */
        bool hasmail;                   /* mail command received */
        bool hasmrcp;                   /* has a recipient */
        bool hasdata;                   /* has mail data */
+       int baseerrs;
 
 
-       /*%%%*/ HostName = "XYZZY";
        hasmail = hasmrcp = hasdata = FALSE;
        message("220", "%s Sendmail at your service", HostName);
        for (;;)
        {
                To = NULL;
        hasmail = hasmrcp = hasdata = FALSE;
        message("220", "%s Sendmail at your service", HostName);
        for (;;)
        {
                To = NULL;
-               Errors = 0;
+               baseerrs = Errors;
                if (fgets(inp, sizeof inp, InChannel) == NULL)
                {
                        /* end of file, just die */
                if (fgets(inp, sizeof inp, InChannel) == NULL)
                {
                        /* end of file, just die */
-                       message("421", "Lost input channel");
+                       message("421", "%s Lost input channel", HostName);
                        finis();
                }
 
                /* clean up end of line */
                        finis();
                }
 
                /* clean up end of line */
-               p = index(inp, '\n');
-               if (p != NULL)
-                       *p = '\0';
-               p = index(inp, '\r');
-               if (p != NULL)
-                       *p = '\0';
+               fixcrlf(inp, TRUE);
 
                /* break off command */
                for (p = inp; isspace(*p); p++)
 
                /* break off command */
                for (p = inp; isspace(*p); p++)
@@ -102,6 +97,11 @@ smtp()
                switch (c->cmdcode)
                {
                  case CMDMAIL:         /* mail -- designate sender */
                switch (c->cmdcode)
                {
                  case CMDMAIL:         /* mail -- designate sender */
+                       if (hasmail)
+                       {
+                               message("503", "Sender already specified");
+                               break;
+                       }
                        p = skipword(p, "from");
                        if (p == NULL)
                                break;
                        p = skipword(p, "from");
                        if (p == NULL)
                                break;
@@ -112,7 +112,7 @@ smtp()
                                break;
                        }
                        setsender(p);
                                break;
                        }
                        setsender(p);
-                       if (Errors == 0)
+                       if (Errors == baseerrs)
                        {
                                message("250", "Sender ok");
                                hasmail = TRUE;
                        {
                                message("250", "Sender ok");
                                hasmail = TRUE;
@@ -130,7 +130,7 @@ smtp()
                                break;
                        }
                        sendto(p, 1, NULL);
                                break;
                        }
                        sendto(p, 1, NULL);
-                       if (Errors == 0)
+                       if (Errors == baseerrs)
                        {
                                message("250", "Recipient ok");
                                hasmrcp = TRUE;
                        {
                                message("250", "Recipient ok");
                                hasmrcp = TRUE;
@@ -140,7 +140,7 @@ smtp()
                  case CMDDATA:         /* data -- text of mail */
                        message("354", "Enter mail, end with dot");
                        collect();
                  case CMDDATA:         /* data -- text of mail */
                        message("354", "Enter mail, end with dot");
                        collect();
-                       if (Errors == 0)
+                       if (Errors == baseerrs)
                        {
                                message("250", "Message stored");
                                hasdata = TRUE;
                        {
                                message("250", "Message stored");
                                hasdata = TRUE;
@@ -157,7 +157,7 @@ smtp()
                        else
                        {
                                sendall(FALSE);
                        else
                        {
                                sendall(FALSE);
-                               if (Errors == 0)
+                               if (Errors == baseerrs)
                                        message("250", "Sent");
                        }
                        break;
                                        message("250", "Sent");
                        }
                        break;
@@ -168,7 +168,7 @@ smtp()
 
                  case CMDVRFY:         /* vrfy -- verify address */
                        sendto(p, 1, NULL);
 
                  case CMDVRFY:         /* vrfy -- verify address */
                        sendto(p, 1, NULL);
-                       if (Errors == 0)
+                       if (Errors == baseerrs)
                                message("250", "user ok");
                        break;
 
                                message("250", "user ok");
                        break;
 
index 34b361d..16c2fe8 100644 (file)
@@ -6,7 +6,7 @@
 # include <ctype.h>
 # include "conf.h"
 
 # include <ctype.h>
 # include "conf.h"
 
-static char    SccsId[] = "@(#)util.c  3.10    %G%";
+static char    SccsId[] = "@(#)util.c  3.11    %G%";
 
 /*
 **  STRIPQUOTES -- Strip quotes & quote bits from a string.
 
 /*
 **  STRIPQUOTES -- Strip quotes & quote bits from a string.
@@ -413,6 +413,40 @@ safefile(fn, uid, mode)
        return (FALSE);
 }
 \f/*
        return (FALSE);
 }
 \f/*
+**  FIXCRLF -- fix <CR><LF> in line.
+**
+**     Looks for the <CR><LF> combination and turns it into the
+**     UNIX canonical <NL> character.  It only takes one line,
+**     i.e., it is assumed that the first <NL> found is the end
+**     of the line.
+**
+**     Parameters:
+**             line -- the line to fix.
+**             stripnl -- if true, strip the newline also.
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             line is changed in place.
+*/
+
+fixcrlf(line, stripnl)
+       char *line;
+       bool stripnl;
+{
+       register char *p;
+
+       p = index(line, '\n');
+       if (p == NULL)
+               return;
+       if (*p == '\r')
+               p--;
+       if (!stripnl)
+               *p++ = '\n';
+       *p = '\0';
+}
+\f/*
 **  SYSLOG -- fake entry to fool lint
 */
 
 **  SYSLOG -- fake entry to fool lint
 */
 
index 1eb39ac..fcdfdc7 100644 (file)
@@ -1,3 +1,3 @@
-static char    SccsId[] = "@(#)SendMail version 3.51 of %G%";
+static char    SccsId[] = "@(#)SendMail version 3.52 of %G%";
 
 
-char   Version[] = "3.51 [%G%]";
+char   Version[] = "3.52 [%G%]";