implement SMTP mode -- doesn't support source routing or the
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Tue, 20 Oct 1981 14:27:46 +0000 (06:27 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Tue, 20 Oct 1981 14:27:46 +0000 (06:27 -0800)
HELP command, and doesn't give the correct code on VRFY or forwarding.
Maybe someday....

SCCS-vsn: usr.sbin/sendmail/src/deliver.c 3.48
SCCS-vsn: usr.sbin/sendmail/src/collect.c 3.24
SCCS-vsn: usr.sbin/sendmail/src/err.c 3.11
SCCS-vsn: usr.sbin/sendmail/src/sendmail.h 3.48
SCCS-vsn: usr.sbin/sendmail/src/version.c 3.51
SCCS-vsn: usr.sbin/sendmail/src/main.c 3.43
SCCS-vsn: usr.sbin/sendmail/src/recipient.c 3.26

usr/src/usr.sbin/sendmail/src/collect.c
usr/src/usr.sbin/sendmail/src/deliver.c
usr/src/usr.sbin/sendmail/src/err.c
usr/src/usr.sbin/sendmail/src/main.c
usr/src/usr.sbin/sendmail/src/recipient.c
usr/src/usr.sbin/sendmail/src/sendmail.h
usr/src/usr.sbin/sendmail/src/version.c

index bdf99d0..32f6405 100644 (file)
@@ -1,7 +1,7 @@
 # include <errno.h>
 # include "sendmail.h"
 
 # include <errno.h>
 # include "sendmail.h"
 
-static char    SccsId[] = "@(#)collect.c       3.23    %G%";
+static char    SccsId[] = "@(#)collect.c       3.24    %G%";
 
 /*
 **  COLLECT -- read & parse message header & make temp file.
 
 /*
 **  COLLECT -- read & parse message header & make temp file.
@@ -138,14 +138,19 @@ maketemp(from)
        for (; !feof(stdin); !feof(stdin) && fgets(buf, sizeof buf, stdin) != NULL)
        {
                register int i;
        for (; !feof(stdin); !feof(stdin) && fgets(buf, sizeof buf, stdin) != NULL)
        {
                register int i;
+               register char *bp = buf;
 
                /* 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;
 
+               /* check for transparent dot */
+               if (Smtp && *bp == '.')
+                       bp++;
+
 # ifndef NOTUNIX
                /* Hide UNIX-like From lines */
 # ifndef NOTUNIX
                /* Hide UNIX-like From lines */
-               if (strncmp(buf, "From ", 5) == 0)
+               if (strncmp(bp, "From ", 5) == 0)
                {
                        fputs(">", tf);
                        MsgSize++;
                {
                        fputs(">", tf);
                        MsgSize++;
@@ -157,10 +162,10 @@ maketemp(from)
                **  file, and insert a newline if missing.
                */
 
                **  file, and insert a newline if missing.
                */
 
-               i = strlen(buf);
+               i = strlen(bp);
                MsgSize += i;
                MsgSize += i;
-               fputs(buf, tf);
-               if (buf[i - 1] != '\n')
+               fputs(bp, tf);
+               if (bp[i - 1] != '\n')
                        fputs("\n", tf);
                if (ferror(tf))
                {
                        fputs("\n", tf);
                if (ferror(tf))
                {
index 9563b67..d8ed37a 100644 (file)
@@ -7,7 +7,7 @@
 # include <syslog.h>
 # endif LOG
 
 # include <syslog.h>
 # endif LOG
 
-static char SccsId[] = "@(#)deliver.c  3.47    %G%";
+static char SccsId[] = "@(#)deliver.c  3.48    %G%";
 
 /*
 **  DELIVER -- Deliver a message to a list of addresses.
 
 /*
 **  DELIVER -- Deliver a message to a list of addresses.
@@ -852,3 +852,44 @@ mailfile(filename, ctladdr)
                return ((stat >> 8) & 0377);
        }
 }
                return ((stat >> 8) & 0377);
        }
 }
+\f/*
+**  SENDALL -- actually send all the messages.
+**
+**     Parameters:
+**             verifyonly -- if set, only give verification messages.
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             Scans the send lists and sends everything it finds.
+*/
+
+sendall(verifyonly)
+       bool verifyonly;
+{
+       register int i;
+       typedef int (*fnptr)();
+
+       for (i = 0; Mailer[i] != NULL; i++)
+       {
+               ADDRESS *q;
+
+               for (q = Mailer[i]->m_sendq; q != NULL; q = q->q_next)
+               {
+                       if (verifyonly)
+                       {
+                               To = q->q_paddr;
+                               if (!bitset(QDONTSEND|QBADADDR, q->q_flags))
+                               {
+                                       if (q->q_mailer == MN_LOCAL || q->q_mailer == MN_PROG)
+                                               message(Arpa_Info, "deliverable");
+                                       else
+                                               message(Arpa_Info, "queueable");
+                               }
+                       }
+                       else
+                               (void) deliver(q, (fnptr) NULL);
+               }
+       }
+}
index 9e36b37..a406b84 100644 (file)
@@ -3,7 +3,7 @@
 # include <syslog.h>
 # endif LOG
 
 # include <syslog.h>
 # endif LOG
 
-static char    SccsId[] = "@(#)err.c   3.10    %G%";
+static char    SccsId[] = "@(#)err.c   3.11    %G%";
 
 extern bool    HasXscrpt;
 
 
 extern bool    HasXscrpt;
 
@@ -60,10 +60,10 @@ syserr(fmt, a, b, c, d, e)
        }
 
        if (ArpaMode != ARPA_NONE && !HasXscrpt)
        }
 
        if (ArpaMode != ARPA_NONE && !HasXscrpt)
-               printf("%s\r\n", errbuf);
+               fprintf(OutChannel, "%s\r\n", errbuf);
        else
        else
-               printf("sendmail: %s\n", &errbuf[4]);
-       (void) fflush(stdout);
+               fprintf(OutChannel, "sendmail: %s\n", &errbuf[4]);
+       (void) fflush(OutChannel);
        Errors++;
 
        /* determine exit status if not already set */
        Errors++;
 
        /* determine exit status if not already set */
@@ -138,13 +138,13 @@ message(num, msg, a, b, c, d, e)
 
        /* print arpa format header if needed */
        if (ArpaMode != ARPA_NONE && !HasXscrpt)
 
        /* print arpa format header if needed */
        if (ArpaMode != ARPA_NONE && !HasXscrpt)
-               printf("%.3s ", num);
+               fprintf(OutChannel, "%.3s ", num);
 
        if (To != NULL && To[0] != '\0')
 
        if (To != NULL && To[0] != '\0')
-               printf("%s... ", To);
-       printf(msg, a, b, c, d, e);
+               fprintf(OutChannel, "%s... ", To);
+       fprintf(OutChannel, msg, a, b, c, d, e);
        if (ArpaMode != ARPA_NONE && !HasXscrpt)
        if (ArpaMode != ARPA_NONE && !HasXscrpt)
-               printf("\r");
-       printf("\n");
-       (void) fflush(stdout);
+               fprintf(OutChannel, "\r");
+       fprintf(OutChannel, "\n");
+       (void) fflush(OutChannel);
 }
 }
index f30ba99..88964d1 100644 (file)
@@ -8,7 +8,7 @@
 # include <syslog.h>
 # endif LOG
 
 # include <syslog.h>
 # endif LOG
 
-static char    SccsId[] = "@(#)main.c  3.42    %G%";
+static char    SccsId[] = "@(#)main.c  3.43    %G%";
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
@@ -106,6 +106,7 @@ static char SccsId[] = "@(#)main.c  3.42    %G%";
 char   InFileName[] = "/tmp/mailtXXXXXX";
 char   Transcript[] = "/tmp/mailxXXXXXX";
 int    NextMailer = 0;         /* "free" index into Mailer struct */
 char   InFileName[] = "/tmp/mailtXXXXXX";
 char   Transcript[] = "/tmp/mailxXXXXXX";
 int    NextMailer = 0;         /* "free" index into Mailer struct */
+static char    *FullName;      /* sender's full name */
 
 
 
 
 
 
@@ -118,14 +119,12 @@ main(argc, argv)
 {
        register char *p;
        char *realname;
 {
        register char *p;
        char *realname;
-       char *fullname = NULL;
        extern char *getlogin();
        char *locname;
        extern int finis();
        extern char Version[];
        char *from;
        typedef int (*fnptr)();
        extern char *getlogin();
        char *locname;
        extern int finis();
        extern char Version[];
        char *from;
        typedef int (*fnptr)();
-       struct passwd *pw;
        extern char *arpadate();
        extern char *AliasFile;         /* location of alias file */
        extern char *ConfFile;          /* location of configuration file */
        extern char *arpadate();
        extern char *AliasFile;         /* location of alias file */
        extern char *ConfFile;          /* location of configuration file */
@@ -140,11 +139,12 @@ main(argc, argv)
        char ybuf[10];                  /* holds tty id */
        bool aliasinit = FALSE;
        extern char *ttyname();
        char ybuf[10];                  /* holds tty id */
        bool aliasinit = FALSE;
        extern char *ttyname();
-       char cfbuf[60];                 /* holds .cf filename */
        extern bool safefile();
        bool canrename;
 
        argv[argc] = NULL;
        extern bool safefile();
        bool canrename;
 
        argv[argc] = NULL;
+       InChannel = stdin;
+       OutChannel = stdout;
        if (signal(SIGINT, SIG_IGN) != SIG_IGN)
                (void) signal(SIGINT, finis);
        if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
        if (signal(SIGINT, SIG_IGN) != SIG_IGN)
                (void) signal(SIGINT, finis);
        if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
@@ -253,7 +253,7 @@ main(argc, argv)
                                        break;
                                }
                        }
                                        break;
                                }
                        }
-                       fullname = p;
+                       FullName = p;
                        break;
 
                  case 'h':     /* hop count */
                        break;
 
                  case 'h':     /* hop count */
@@ -381,7 +381,11 @@ main(argc, argv)
 
                  case 'D':     /* run as a daemon */
                        Daemon = TRUE;
 
                  case 'D':     /* run as a daemon */
                        Daemon = TRUE;
-                       MailBack = TRUE;
+                       /* explicit fall-through */
+
+                 case 'p':     /* run SMTP protocol */
+                       Smtp = TRUE;
+                       ArpaMode = ARPA_SMTP;
                        break;
 
                  default:
                        break;
 
                  default:
@@ -432,64 +436,16 @@ main(argc, argv)
 
        if (Daemon)
                getrequests();
 
        if (Daemon)
                getrequests();
-
+       
        /*
        /*
-       locname = getname();
-       if (locname == NULL || locname[0] == '\0')
-       {
-               errno = 0;
-               p = getlogin();
-               errno = 0;
-       }
-       if (Daemon || p == NULL)
-       {
-               extern struct passwd *getpwuid();
-               int uid;
-
-               uid = getruid();
-               pw = getpwuid(uid);
-               if (pw == NULL)
-                       syserr("Who are you? (uid=%d)", uid);
-               else
-                       p = pw->pw_name;
-       }
-       else
-       {
-               extern struct passwd *getpwnam();
-
-               pw = getpwnam(p);
-               if (pw == NULL)
-                       syserr("Who are you? (name=%s)", p);
-       }
-       if (p == NULL || p[0] == '\0' || pw == NULL)
-               finis();
-
-       realname = p;
+       if (Smtp)
+               smtp();
 
        /*
 
        /*
-       **  Process passwd file entry.
+       **  Set the sender
        */
 
        */
 
-       /* run user's .mailcf file */
-       define('z', pw->pw_dir);
-       (void) expand("$z/.mailcf", cfbuf, &cfbuf[sizeof cfbuf - 1]);
-       if (safefile(cfbuf, getruid(), S_IREAD))
-               readcf(cfbuf, FALSE);
-
-       /* extract full name from passwd file */
-       if ((fullname == NULL || fullname[0] == '\0') &&
-           pw != NULL && pw->pw_gecos != NULL)
-       {
-               char nbuf[MAXNAME];
-
-               buildfname(pw->pw_gecos, realname, nbuf);
-               if (ArpaMode == ARPA_NONE && from == NULL && nbuf[0] != '\0')
-                       fullname = newstr(nbuf);
-       }
-       if (fullname != NULL && fullname[0] != '\0')
-               define('x', fullname);
-
-       setfrom(from, realname);
+       setsender(from);
 
        if (!Daemon && argc <= 0 && !GrabTo)
                usrerr("Usage: /etc/sendmail [flags] addr...");
 
        if (!Daemon && argc <= 0 && !GrabTo)
                usrerr("Usage: /etc/sendmail [flags] addr...");
@@ -513,10 +469,7 @@ main(argc, argv)
 
        if (GrabTo)
                DontSend = TRUE;
 
        if (GrabTo)
                DontSend = TRUE;
-       if (Daemon)
-               getrecipients();
-       else
-               sendtoargv(argv);
+       sendtoargv(argv);
 
        /* if we have had errors sofar, drop out now */
        if (Errors > 0 && ExitStat == EX_OK)
 
        /* if we have had errors sofar, drop out now */
        if (Errors > 0 && ExitStat == EX_OK)
@@ -558,27 +511,7 @@ main(argc, argv)
        **      If verifying, just ack.
        */
 
        **      If verifying, just ack.
        */
 
-       for (i = 0; Mailer[i] != NULL; i++)
-       {
-               ADDRESS *q;
-
-               for (q = Mailer[i]->m_sendq; q != NULL; q = q->q_next)
-               {
-                       if (verifyonly)
-                       {
-                               To = q->q_paddr;
-                               if (!bitset(QDONTSEND|QBADADDR, q->q_flags))
-                               {
-                                       if (q->q_mailer == MN_LOCAL || q->q_mailer == MN_PROG)
-                                               message(Arpa_Info, "deliverable");
-                                       else
-                                               message(Arpa_Info, "queueable");
-                               }
-                       }
-                       else
-                               (void) deliver(q, (fnptr) NULL);
-               }
-       }
+       sendall(verifyonly);
 
        /*
        ** All done.
 
        /*
        ** All done.
@@ -748,3 +681,87 @@ openxscrpt()
        (void) chmod(Transcript, 0600);
        setbuf(stdout, (char *) NULL);
 }
        (void) chmod(Transcript, 0600);
        setbuf(stdout, (char *) NULL);
 }
+\f/*
+**  SETSENDER -- set sendmail's idea of the sender.
+**
+**     Parameters:
+**             from -- the person we would like to believe this
+**                     is from.
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             Sets the idea of the sender.
+*/
+
+setsender(from)
+       char *from;
+{
+       register char *p;
+       extern char *getlogin();
+       register struct passwd *pw;
+       char *realname;
+       char cfbuf[40];
+
+       /*
+       **  Figure out the real user executing us.
+       **      Getlogin can return errno != 0 on non-errors.
+       */
+
+       if (!Daemon)
+       {
+               errno = 0;
+               p = getlogin();
+               errno = 0;
+       }
+       if (Daemon || p == NULL)
+       {
+               extern struct passwd *getpwuid();
+               int uid;
+
+               uid = getruid();
+               pw = getpwuid(uid);
+               if (pw == NULL)
+                       syserr("Who are you? (uid=%d)", uid);
+               else
+                       p = pw->pw_name;
+       }
+       else
+       {
+               extern struct passwd *getpwnam();
+
+               pw = getpwnam(p);
+               if (pw == NULL)
+                       syserr("Who are you? (name=%s)", p);
+       }
+       if (p == NULL || p[0] == '\0' || pw == NULL)
+               finis();
+
+       realname = p;
+
+       /*
+       **  Process passwd file entry.
+       */
+
+       /* run user's .mailcf file */
+       define('z', pw->pw_dir);
+       (void) expand("$z/.mailcf", cfbuf, &cfbuf[sizeof cfbuf - 1]);
+       if (safefile(cfbuf, getruid(), S_IREAD))
+               readcf(cfbuf, FALSE);
+
+       /* extract full name from passwd file */
+       if ((FullName == NULL || FullName[0] == '\0') &&
+           pw != NULL && pw->pw_gecos != NULL)
+       {
+               char nbuf[MAXNAME];
+
+               buildfname(pw->pw_gecos, realname, nbuf);
+               if (ArpaMode == ARPA_NONE && from == NULL && nbuf[0] != '\0')
+                       FullName = newstr(nbuf);
+       }
+       if (FullName != NULL && FullName[0] != '\0')
+               define('x', FullName);
+
+       setfrom(from, realname);
+}
index 916a8cd..729146a 100644 (file)
@@ -3,7 +3,7 @@
 # include <sys/stat.h>
 # include "sendmail.h"
 
 # include <sys/stat.h>
 # include "sendmail.h"
 
-static char SccsId[] = "@(#)recipient.c        3.25    %G%";
+static char SccsId[] = "@(#)recipient.c        3.26    %G%";
 
 /*
 **  SENDTO -- Designate a send list.
 
 /*
 **  SENDTO -- Designate a send list.
index 0c2b0ed..5703e66 100644 (file)
@@ -6,7 +6,7 @@
 
 # ifdef _DEFINE
 # define EXTERN
 
 # ifdef _DEFINE
 # define EXTERN
-static char SmailSccsId[] =    "@(#)sendmail.h 3.47    %G%";
+static char SmailSccsId[] =    "@(#)sendmail.h 3.48    %G%";
 # else  _DEFINE
 # define EXTERN extern
 # endif _DEFINE
 # else  _DEFINE
 # define EXTERN extern
 # endif _DEFINE
@@ -35,6 +35,7 @@ static char SmailSccsId[] =   "@(#)sendmail.h 3.47    %G%";
 # define ARPA_OLD      1       /* in old arpanet mode */
 # define ARPA_MAIL     2       /* in regular arpanet mail */
 # define ARPA_FILE     3       /* reading over data connection */
 # define ARPA_OLD      1       /* in old arpanet mode */
 # define ARPA_MAIL     2       /* in regular arpanet mail */
 # define ARPA_FILE     3       /* reading over data connection */
+# define ARPA_SMTP     4       /* running SMTP protocol */
 
 extern char    Arpa_Info[];    /* the message number for Arpanet info */
 
 
 extern char    Arpa_Info[];    /* the message number for Arpanet info */
 
@@ -279,6 +280,12 @@ EXTERN bool        GrabTo;         /* if set, get recipients from msg */
 EXTERN bool    DontSend;       /* mark recipients as QDONTSEND */
 EXTERN bool    NoReturn;       /* don't return letter to sender */
 EXTERN bool    Daemon;         /* running as a daemon */
 EXTERN bool    DontSend;       /* mark recipients as QDONTSEND */
 EXTERN bool    NoReturn;       /* don't return letter to sender */
 EXTERN bool    Daemon;         /* running as a daemon */
+EXTERN bool    Smtp;           /* using SMTP over connection */
+EXTERN bool    SuprErrs;       /* set if we are suppressing errors */
+EXTERN bool    HasXscrpt;      /* set if we have a transcript */
+EXTERN FILE    *InChannel;     /* input connection */
+EXTERN FILE    *OutChannel;    /* output connection */
+EXTERN FILE    *TempFile;      /* mail temp file */
 EXTERN int     RealUid;        /* when Daemon, real uid of caller */
 EXTERN int     RealGid;        /* when Daemon, real gid of caller */
 EXTERN int     OldUmask;       /* umask when sendmail starts up */
 EXTERN int     RealUid;        /* when Daemon, real uid of caller */
 EXTERN int     RealGid;        /* when Daemon, real gid of caller */
 EXTERN int     OldUmask;       /* umask when sendmail starts up */
@@ -286,18 +293,16 @@ EXTERN int        Debug;          /* debugging level */
 EXTERN int     Errors;         /* set if errors */
 EXTERN int     ExitStat;       /* exit status code */
 EXTERN int     ArpaMode;       /* ARPANET handling mode */
 EXTERN int     Errors;         /* set if errors */
 EXTERN int     ExitStat;       /* exit status code */
 EXTERN int     ArpaMode;       /* ARPANET handling mode */
-EXTERN long    MsgSize;        /* size of the message in bytes */
+EXTERN int     HopCount;       /* hop count */
+EXTERN int     AliasLevel;     /* depth of aliasing */
+EXTERN char    *OrigFrom;      /* the From: line read from the message */
+EXTERN char    *To;            /* the target person */
+EXTERN char    *HostName;      /* name of this host for SMTP messages */
 extern char    InFileName[];   /* input file name */
 extern char    Transcript[];   /* the transcript file name */
 extern char    InFileName[];   /* input file name */
 extern char    Transcript[];   /* the transcript file name */
-EXTERN FILE    *TempFile;      /* mail temp file */
 EXTERN ADDRESS From;           /* the person it is from */
 EXTERN ADDRESS From;           /* the person it is from */
-EXTERN char    *To;            /* the target person */
-EXTERN int     HopCount;       /* hop count */
+EXTERN long    MsgSize;        /* size of the message in bytes */
 EXTERN long    CurTime;        /* time of this message */
 EXTERN long    CurTime;        /* time of this message */
-EXTERN int     AliasLevel;     /* depth of aliasing */
-EXTERN char    *OrigFrom;      /* the From: line read from the message */
-EXTERN bool    SuprErrs;       /* set if we are suppressing errors */
-EXTERN bool    HasXscrpt;      /* set if we have a transcript */
 
 
 # include      <sysexits.h>
 
 
 # include      <sysexits.h>
index 472832f..1eb39ac 100644 (file)
@@ -1,3 +1,3 @@
-static char    SccsId[] = "@(#)SendMail version 3.50 of %G%";
+static char    SccsId[] = "@(#)SendMail version 3.51 of %G%";
 
 
-char   Version[] = "3.50 [%G%]";
+char   Version[] = "3.51 [%G%]";