expunge debugging/nonstandard/trojan horse commands from smtp,
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Fri, 18 Nov 1988 02:32:18 +0000 (18:32 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Fri, 18 Nov 1988 02:32:18 +0000 (18:32 -0800)
logging attempts to use them; log name/address of host from which mail received
("mail from" may not include it or may lie); don't allow debug to affect
permissions locally; change some of the non-system syserrs to syslog at lower
priority; still need to unifdef remaining debug code

SCCS-vsn: usr.sbin/sendmail/src/collect.c 5.5
SCCS-vsn: usr.sbin/sendmail/src/daemon.c 5.28
SCCS-vsn: usr.sbin/sendmail/src/envelope.c 5.16
SCCS-vsn: usr.sbin/sendmail/src/headers.c 5.11
SCCS-vsn: usr.sbin/sendmail/src/sendmail.h 5.14
SCCS-vsn: usr.sbin/sendmail/src/srvrsmtp.c 5.24
SCCS-vsn: usr.sbin/sendmail/src/util.c 5.12

usr/src/usr.sbin/sendmail/src/collect.c
usr/src/usr.sbin/sendmail/src/daemon.c
usr/src/usr.sbin/sendmail/src/envelope.c
usr/src/usr.sbin/sendmail/src/headers.c
usr/src/usr.sbin/sendmail/src/sendmail.h
usr/src/usr.sbin/sendmail/src/srvrsmtp.c
usr/src/usr.sbin/sendmail/src/util.c

index c0bb52a..40a149f 100644 (file)
@@ -17,7 +17,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)collect.c  5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)collect.c  5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 # include <errno.h>
 #endif /* not lint */
 
 # include <errno.h>
@@ -187,7 +187,11 @@ maketemp(from)
        /* An EOF when running SMTP is an error */
        if ((feof(InChannel) || ferror(InChannel)) && OpMode == MD_SMTP)
        {
        /* An EOF when running SMTP is an error */
        if ((feof(InChannel) || ferror(InChannel)) && OpMode == MD_SMTP)
        {
-               syserr("collect: unexpected close, from=%s", CurEnv->e_from.q_paddr);
+               if (RealHostName)
+                       syslog(LOG_NOTICE,
+                           "collect: unexpected close on connection from %s: %m\n",
+                           CurEnv->e_from.q_paddr, RealHostName);
+               usrerr("collect: unexpected close, from=%s", CurEnv->e_from.q_paddr);
 
                /* don't return an error indication */
                CurEnv->e_to = NULL;
 
                /* don't return an error indication */
                CurEnv->e_to = NULL;
index a8db531..9bae582 100644 (file)
@@ -22,9 +22,9 @@
 
 #ifndef lint
 #ifdef DAEMON
 
 #ifndef lint
 #ifdef DAEMON
-static char sccsid[] = "@(#)daemon.c   5.27 (Berkeley) %G% (with daemon mode)";
+static char sccsid[] = "@(#)daemon.c   5.28 (Berkeley) %G% (with daemon mode)";
 #else
 #else
-static char sccsid[] = "@(#)daemon.c   5.27 (Berkeley) %G% (without daemon mode)";
+static char sccsid[] = "@(#)daemon.c   5.28 (Berkeley) %G% (without daemon mode)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
index 487980b..a9764a5 100644 (file)
@@ -17,7 +17,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)envelope.c 5.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)envelope.c 5.16 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <pwd.h>
 #endif /* not lint */
 
 #include <pwd.h>
@@ -456,10 +456,7 @@ setsender(from)
        {
                extern bool trusteduser();
 
        {
                extern bool trusteduser();
 
-               if (!trusteduser(realname) &&
-# ifdef DEBUG
-                   (!tTd(1, 9) || getuid() != geteuid()) &&
-# endif DEBUG
+               if (!trusteduser(realname) && getuid() != geteuid() &&
                    index(from, '!') == NULL && getuid() != 0)
                {
                        /* network sends -r regardless (why why why?) */
                    index(from, '!') == NULL && getuid() != 0)
                {
                        /* network sends -r regardless (why why why?) */
@@ -476,8 +473,14 @@ setsender(from)
                {
 # ifdef LOG
                        if (LogLevel >= 1)
                {
 # ifdef LOG
                        if (LogLevel >= 1)
-                               syslog(LOG_ERR, "Unparseable user %s wants to be %s",
-                                               realname, from);
+                           if (realname == from && RealHostName != NULL)
+                               syslog(LOG_NOTICE,
+                                   "from=%s unparseable, received from %s",
+                                   from, RealHostName);
+                           else
+                               syslog(LOG_NOTICE,
+                                   "Unparseable username %s wants from=%s",
+                                   realname, from);
 # endif LOG
                }
                from = newstr(realname);
 # endif LOG
                }
                from = newstr(realname);
@@ -548,7 +551,8 @@ setsender(from)
        pvp = prescan(from, '\0', pvpbuf);
        if (pvp == NULL)
        {
        pvp = prescan(from, '\0', pvpbuf);
        if (pvp == NULL)
        {
-               syserr("cannot prescan from (%s)", from);
+               syslog(LOG_INFO, "cannot prescan from (%s)", from);
+               usrerr("cannot prescan from (%s)", from);
                finis();
        }
        rewrite(pvp, 3);
                finis();
        }
        rewrite(pvp, 3);
index bb6158b..30f6d17 100644 (file)
@@ -17,7 +17,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)headers.c  5.10 (Berkeley) %G%";
+static char sccsid[] = "@(#)headers.c  5.11 (Berkeley) %G%";
 #endif /* not lint */
 
 # include <errno.h>
 #endif /* not lint */
 
 # include <errno.h>
@@ -407,9 +407,19 @@ eatheader(e)
 # ifdef LOG
        if (!QueueRun && LogLevel > 1)
        {
 # ifdef LOG
        if (!QueueRun && LogLevel > 1)
        {
-               syslog(LOG_INFO, "%s: from=%s, size=%ld, class=%d\n",
-                      CurEnv->e_id, CurEnv->e_from.q_paddr, CurEnv->e_msgsize,
-                      CurEnv->e_class);
+               char hbuf[100], *name = hbuf;
+
+               if (RealHostName == NULL)
+                       name = "local";
+               else if (RealHostName[0] == '[')
+                       name = RealHostName;
+               else
+                       (void)sprintf(hbuf, "%.90s (%s)", 
+                           RealHostName, inet_ntoa(RealHostAddr.sin_addr));
+               syslog(LOG_INFO,
+                   "%s: from=%s, size=%ld, class=%d, received from %s\n",
+                   CurEnv->e_id, CurEnv->e_from.q_paddr, CurEnv->e_msgsize,
+                   CurEnv->e_class, name);
        }
 # endif LOG
 }
        }
 # endif LOG
 }
index 57eb3c2..bb2ac52 100644 (file)
@@ -15,7 +15,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)sendmail.h  5.13 (Berkeley) %G%
+ *     @(#)sendmail.h  5.14 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -25,7 +25,7 @@
 # ifdef _DEFINE
 # define EXTERN
 # ifndef lint
 # ifdef _DEFINE
 # define EXTERN
 # ifndef lint
-static char SmailSccsId[] =    "@(#)sendmail.h 5.13            %G%";
+static char SmailSccsId[] =    "@(#)sendmail.h 5.14            %G%";
 # endif lint
 # else  _DEFINE
 # define EXTERN extern
 # endif lint
 # else  _DEFINE
 # define EXTERN extern
@@ -540,6 +540,7 @@ EXTERN char *FileName;      /* name to print on error messages */
 EXTERN char    *SmtpPhase;     /* current phase in SMTP processing */
 EXTERN char    *MyHostName;    /* name of this host for SMTP messages */
 EXTERN char    *RealHostName;  /* name of host we are talking to */
 EXTERN char    *SmtpPhase;     /* current phase in SMTP processing */
 EXTERN char    *MyHostName;    /* name of this host for SMTP messages */
 EXTERN char    *RealHostName;  /* name of host we are talking to */
+EXTERN struct  sockaddr_in RealHostAddr;/* address of host we are talking to */
 EXTERN char    *CurHostName;   /* current host we are dealing with */
 EXTERN jmp_buf TopFrame;       /* branch-to-top-of-loop-on-error frame */
 EXTERN bool    QuickAbort;     /*  .... but only if we want a quick abort */
 EXTERN char    *CurHostName;   /* current host we are dealing with */
 EXTERN jmp_buf TopFrame;       /* branch-to-top-of-loop-on-error frame */
 EXTERN bool    QuickAbort;     /*  .... but only if we want a quick abort */
index c5f9f87..85cf0eb 100644 (file)
@@ -20,9 +20,9 @@
 
 #ifndef lint
 #ifdef SMTP
 
 #ifndef lint
 #ifdef SMTP
-static char sccsid[] = "@(#)srvrsmtp.c 5.23 (Berkeley) %G% (with SMTP)";
+static char sccsid[] = "@(#)srvrsmtp.c 5.24 (Berkeley) %G% (with SMTP)";
 #else
 #else
-static char sccsid[] = "@(#)srvrsmtp.c 5.23 (Berkeley) %G% (without SMTP)";
+static char sccsid[] = "@(#)srvrsmtp.c 5.24 (Berkeley) %G% (without SMTP)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -63,12 +63,13 @@ struct cmd
 # define CMDNOOP       7       /* noop -- do nothing */
 # define CMDQUIT       8       /* quit -- close connection and die */
 # define CMDHELO       9       /* helo -- be polite */
 # define CMDNOOP       7       /* noop -- do nothing */
 # define CMDQUIT       8       /* quit -- close connection and die */
 # define CMDHELO       9       /* helo -- be polite */
-# define CMDDBGQSHOW   10      /* showq -- show send queue (DEBUG) */
-# define CMDDBGDEBUG   11      /* debug -- set debug mode */
-# define CMDVERB       12      /* verb -- go into verbose mode */
-# define CMDDBGKILL    13      /* kill -- kill sendmail */
-# define CMDDBGWIZ     14      /* wiz -- become a wizard */
-# define CMDONEX       15      /* onex -- sending one transaction only */
+# define CMDONEX       10      /* onex -- sending one transaction only */
+# define CMDVERB       11      /* verb -- go into verbose mode */
+/* debugging-only commands, only enabled if SMTPDEBUG is defined */
+# define CMDDBGQSHOW   12      /* showq -- show send queue */
+# define CMDDBGDEBUG   13      /* debug -- set debug mode */
+# define CMDDBGKILL    14      /* kill -- kill sendmail */
+# define CMDDBGWIZ     15      /* wiz -- become a wizard */
 
 static struct cmd      CmdTab[] =
 {
 
 static struct cmd      CmdTab[] =
 {
@@ -86,23 +87,21 @@ static struct cmd   CmdTab[] =
        "verb",         CMDVERB,
        "onex",         CMDONEX,
        "hops",         CMDHOPS,
        "verb",         CMDVERB,
        "onex",         CMDONEX,
        "hops",         CMDHOPS,
-# ifdef DEBUG
+       /*
+        * remaining commands are here only
+        * to trap and log attempts to use them
+        */
        "showq",        CMDDBGQSHOW,
        "showq",        CMDDBGQSHOW,
-# endif DEBUG
-# ifdef notdef
        "debug",        CMDDBGDEBUG,
        "debug",        CMDDBGDEBUG,
-# endif notdef
-# ifdef WIZ
        "kill",         CMDDBGKILL,
        "kill",         CMDDBGKILL,
-# endif WIZ
        "wiz",          CMDDBGWIZ,
        NULL,           CMDERROR,
 };
 
 # ifdef WIZ
 bool   IsWiz = FALSE;                  /* set if we are a wizard */
        "wiz",          CMDDBGWIZ,
        NULL,           CMDERROR,
 };
 
 # ifdef WIZ
 bool   IsWiz = FALSE;                  /* set if we are a wizard */
-# endif WIZ
 char   *WizWord;                       /* the wizard word to compare against */
 char   *WizWord;                       /* the wizard word to compare against */
+# endif WIZ
 bool   InChild = FALSE;                /* true if running in a subprocess */
 bool   OneXact = FALSE;                /* one xaction only this run */
 
 bool   InChild = FALSE;                /* true if running in a subprocess */
 bool   OneXact = FALSE;                /* one xaction only this run */
 
@@ -160,7 +159,7 @@ smtp()
                if (p == NULL)
                {
                        /* end of file, just die */
                if (p == NULL)
                {
                        /* end of file, just die */
-                       message("421", "%s Lost input channel to %s",
+                       message("421", "%s Lost input channel from %s",
                                MyHostName, CurHostName);
                        finis();
                }
                                MyHostName, CurHostName);
                        finis();
                }
@@ -199,9 +198,11 @@ smtp()
                        setproctitle("%s: %s", CurHostName, inp);
                        if (!strcasecmp(p, MyHostName))
                        {
                        setproctitle("%s: %s", CurHostName, inp);
                        if (!strcasecmp(p, MyHostName))
                        {
-                               /* connected to an echo server */
-                               message("553", "%s I refuse to talk to myself",
-                                       MyHostName);
+                               /*
+                                * didn't know about alias,
+                                * or connected to an echo server
+                                */
+                               message("553", "Local configuration error, hostname not recognized as local");
                                break;
                        }
                        if (RealHostName != NULL && strcasecmp(p, RealHostName))
                                break;
                        }
                        if (RealHostName != NULL && strcasecmp(p, RealHostName))
@@ -231,6 +232,7 @@ smtp()
                        }
                        if (InChild)
                        {
                        }
                        if (InChild)
                        {
+                               errno = 0;
                                syserr("Nested MAIL command");
                                exit(0);
                        }
                                syserr("Nested MAIL command");
                                exit(0);
                        }
@@ -402,7 +404,7 @@ smtp()
                        message("200", "Only one transaction");
                        break;
 
                        message("200", "Only one transaction");
                        break;
 
-# ifdef DEBUG
+# ifdef SMTPDEBUG
                  case CMDDBGQSHOW:     /* show queues */
                        printf("Send Queue=");
                        printaddr(CurEnv->e_sendqueue, TRUE);
                  case CMDDBGQSHOW:     /* show queues */
                        printf("Send Queue=");
                        printaddr(CurEnv->e_sendqueue, TRUE);
@@ -413,7 +415,6 @@ smtp()
                        tTflag(p);
                        message("200", "Debug set");
                        break;
                        tTflag(p);
                        message("200", "Debug set");
                        break;
-# endif DEBUG
 
 # ifdef WIZ
                  case CMDDBGKILL:      /* kill the parent */
 
 # ifdef WIZ
                  case CMDDBGKILL:      /* kill the parent */
@@ -447,12 +448,26 @@ smtp()
                        message("500", "You wascal wabbit!  Wandering wizards won't win!");
                        break;
 # endif WIZ
                        message("500", "You wascal wabbit!  Wandering wizards won't win!");
                        break;
 # endif WIZ
+# else /* not SMTPDEBUG */
+
+                 case CMDDBGQSHOW:     /* show queues */
+                 case CMDDBGDEBUG:     /* set debug mode */
+                 case CMDDBGKILL:      /* kill the parent */
+                 case CMDDBGWIZ:       /* become a wizard */
+                       if (RealHostName)
+                               syslog(LOG_NOTICE,
+                                   "\"%s\" command from %s (%s)\n",
+                                   c->cmdname, RealHostName,
+                                   inet_ntoa(RealHostAddr.sin_addr));
+                       /* FALL THROUGH */
+# endif /* SMTPDEBUG */
 
                  case CMDERROR:        /* unknown command */
                        message("500", "Command unrecognized");
                        break;
 
                  default:
 
                  case CMDERROR:        /* unknown command */
                        message("500", "Command unrecognized");
                        break;
 
                  default:
+                       errno = 0;
                        syserr("smtp: unknown code %d", c->cmdcode);
                        break;
                }
                        syserr("smtp: unknown code %d", c->cmdcode);
                        break;
                }
index ee7a466..7c5f334 100644 (file)
@@ -15,7 +15,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)util.c     5.11 (Berkeley) %G%";
+static char sccsid[] = "@(#)util.c     5.12 (Berkeley) %G%";
 #endif /* not lint */
 
 # include <stdio.h>
 #endif /* not lint */
 
 # include <stdio.h>
@@ -570,10 +570,6 @@ xunlink(f)
 
 static jmp_buf CtxReadTimeout;
 
 
 static jmp_buf CtxReadTimeout;
 
-#ifndef ETIMEDOUT
-#define ETIMEDOUT      EINTR
-#endif
-
 char *
 sfgets(buf, siz, fp)
        char *buf;
 char *
 sfgets(buf, siz, fp)
        char *buf;
@@ -589,8 +585,11 @@ sfgets(buf, siz, fp)
        {
                if (setjmp(CtxReadTimeout) != 0)
                {
        {
                if (setjmp(CtxReadTimeout) != 0)
                {
-                       errno = ETIMEDOUT;
-                       syserr("net timeout");
+                       syslog(LOG_NOTICE,
+                           "timeout waiting for input from %s\n",
+                           RealHostName);
+                       errno = 0;
+                       usrerr("timeout waiting for input");
                        buf[0] = '\0';
                        return (NULL);
                }
                        buf[0] = '\0';
                        return (NULL);
                }