add -R flag to log incoming raw recipients for analysis
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Sat, 21 Dec 1991 12:01:24 +0000 (04:01 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Sat, 21 Dec 1991 12:01:24 +0000 (04:01 -0800)
SCCS-vsn: usr.sbin/sendmail/src/recipient.c 5.25
SCCS-vsn: usr.sbin/sendmail/src/main.c 5.40
SCCS-vsn: usr.sbin/sendmail/src/version.c 5.86

usr/src/usr.sbin/sendmail/src/main.c
usr/src/usr.sbin/sendmail/src/recipient.c
usr/src/usr.sbin/sendmail/src/version.c

index 1f9b4b8..604cbc7 100644 (file)
@@ -13,7 +13,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.39 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.40 (Berkeley) %G%";
 #endif /* not lint */
 
 #define        _DEFINE
 #endif /* not lint */
 
 #define        _DEFINE
@@ -55,6 +55,7 @@ char  edata, end;
 **             Eric Allman, UCB/INGRES (until 10/81)
 **                          Britton-Lee, Inc., purveyors of fine
 **                             database computers (from 11/81)
 **             Eric Allman, UCB/INGRES (until 10/81)
 **                          Britton-Lee, Inc., purveyors of fine
 **                             database computers (from 11/81)
+**                          Now back at UCB at the Mammoth project.
 **             The support of the INGRES Project and Britton-Lee is
 **                     gratefully acknowledged.  Britton-Lee in
 **                     particular had absolutely nothing to gain from
 **             The support of the INGRES Project and Britton-Lee is
 **                     gratefully acknowledged.  Britton-Lee in
 **                     particular had absolutely nothing to gain from
@@ -81,6 +82,19 @@ char         **Argv = NULL;          /* pointer to argument vector */
 char           *LastArgv = NULL;       /* end of argv */
 # endif SETPROCTITLE
 
 char           *LastArgv = NULL;       /* end of argv */
 # endif SETPROCTITLE
 
+/*
+**  The file in which to log raw recipient information.
+**     This is logged before aliasing, forwarding, and so forth so we
+**     can see how our addresses are being used.  For example, this
+**     would give us the names of aliases (instead of what they alias
+**     to), the pre-MX hostnames, and so forth.
+**
+**     This is specified on the command line, not in the config file,
+**     and is therefore really only useful for logging SMTP RCPTs.
+*/
+
+char           *RcptLogFile = NULL;    /* file name */
+
 #ifdef DAEMON
 #ifndef SMTP
 ERROR %%%%   Cannot have daemon mode without SMTP   %%%% ERROR
 #ifdef DAEMON
 #ifndef SMTP
 ERROR %%%%   Cannot have daemon mode without SMTP   %%%% ERROR
@@ -436,7 +450,19 @@ main(argc, argv, envp)
                  case 'I':     /* initialize alias DBM file */
                        OpMode = MD_INITALIAS;
                        break;
                  case 'I':     /* initialize alias DBM file */
                        OpMode = MD_INITALIAS;
                        break;
-# endif DBM
+# endif /* DBM */
+
+                 case 'R':     /* log raw recipient info */
+                       p += 2;
+                       if (*p == '\0' && ((p = *++av) == NULL || *p == '-'))
+                       {
+                               usrerr("Bad -R flag");
+                               ExitStat = EX_USAGE;
+                               av--;
+                               break;
+                       }
+                       RcptLogFile = newstr(p);
+                       break;
                }
        }
 
                }
        }
 
index ade87b1..09a7507 100644 (file)
@@ -7,11 +7,12 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)recipient.c        5.24 (Berkeley) %G%";
+static char sccsid[] = "@(#)recipient.c        5.25 (Berkeley) %G%";
 #endif /* not lint */
 
 # include <sys/types.h>
 # include <sys/stat.h>
 #endif /* not lint */
 
 # include <sys/types.h>
 # include <sys/stat.h>
+# include <sys/file.h>
 # include <pwd.h>
 # include "sendmail.h"
 
 # include <pwd.h>
 # include "sendmail.h"
 
@@ -203,6 +204,7 @@ addrref(a, r)
 */
 
 extern ADDRESS *getctladdr();
 */
 
 extern ADDRESS *getctladdr();
+extern char    *RcptLogFile;
 
 ADDRESS *
 ADDRESS *
 
 ADDRESS *
 ADDRESS *
@@ -299,6 +301,37 @@ recipient(a, sendq)
        a->q_next = NULL;
        CurEnv->e_nrcpts++;
 
        a->q_next = NULL;
        CurEnv->e_nrcpts++;
 
+       if (a->q_alias == NULL && RcptLogFile != NULL &&
+           !bitset(QDONTSEND, a->q_flags))
+       {
+               static int RcptLogFd = -1;
+
+               /*
+               **  Log the incoming recipient name before aliasing,
+               **  expanding, forwarding, rewriting, and all that jazz.
+               **  We'll use this to track down out-of-date aliases,
+               **  host names, and so forth.
+               */
+
+               if (RcptLogFd < 0)
+               {
+                       /* try to open the log file */
+                       RcptLogFd = open(RcptLogFile, O_WRONLY|O_APPEND|O_CREAT, 0666);
+               }
+               if (RcptLogFd >= 0)
+               {
+                       int l = strlen(a->q_paddr);
+
+                       a->q_paddr[l] = '\n';
+                       if (write(RcptLogFd, a->q_paddr, l + 1) < 0)
+                       {
+                               (void) close(RcptLogFd);
+                               RcptLogFd = -1;
+                       }
+                       a->q_paddr[l] = '\0';
+               }
+       }
+
        /*
        **  Alias the name and handle :include: specs.
        */
        /*
        **  Alias the name and handle :include: specs.
        */
index 492c8e8..b8ac320 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)version.c  5.85 (Berkeley) %G%";
+static char sccsid[] = "@(#)version.c  5.86 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
-char   Version[] = "5.85";
+char   Version[] = "5.86";