add option to print IP source routing info
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Mon, 22 May 1995 23:30:01 +0000 (15:30 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Mon, 22 May 1995 23:30:01 +0000 (15:30 -0800)
SCCS-vsn: usr.sbin/sendmail/src/READ_ME 8.87
SCCS-vsn: usr.sbin/sendmail/src/conf.h 8.163
SCCS-vsn: usr.sbin/sendmail/src/daemon.c 8.91

usr/src/usr.sbin/sendmail/src/READ_ME
usr/src/usr.sbin/sendmail/src/conf.h
usr/src/usr.sbin/sendmail/src/daemon.c

index 939b414..240c556 100644 (file)
@@ -4,7 +4,7 @@
 #
 # %sccs.include.redist.sh%
 #
 #
 # %sccs.include.redist.sh%
 #
-#      @(#)READ_ME     8.86 (Berkeley) %G%
+#      @(#)READ_ME     8.87 (Berkeley) %G%
 #
 
 This directory contains the source files for sendmail.
 #
 
 This directory contains the source files for sendmail.
@@ -414,6 +414,12 @@ IDENTPROTO Define this as 1 to get IDENT (RFC 1413) protocol support.
                is actually still compiled in, but it defaults off; you
                can turn it on by setting the IDENT timeout to 30s in the
                configuration file.
                is actually still compiled in, but it defaults off; you
                can turn it on by setting the IDENT timeout to 30s in the
                configuration file.
+IP_SRCROUTE    Define this to 1 to get IP source routing information
+               displayed in the Received: header.  This is assumed on
+               most systems, but some (e.g., Ultrix) apparently have a
+               broken version of getsockopt that doesn't properly
+               support the IP_OPTIONS call.  You probably want this if
+               your OS can cope with it.
 LOG            Set this to get syslog(3) support.  Defined by default
                in conf.h.  You want this if at all possible.
 NETINET                Set this to get TCP/IP support.  Defined by default
 LOG            Set this to get syslog(3) support.  Defined by default
                in conf.h.  You want this if at all possible.
 NETINET                Set this to get TCP/IP support.  Defined by default
@@ -1006,4 +1012,4 @@ version.c The version number and information about this
 
 Eric Allman
 
 
 Eric Allman
 
-(Version 8.86, last update %G% 08:30:29)
+(Version 8.87, last update %G% 08:29:55)
index 5603597..317af33 100644 (file)
@@ -5,7 +5,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)conf.h      8.162 (Berkeley) %G%
+ *     @(#)conf.h      8.163 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -183,6 +183,9 @@ extern int  syslog(int, char *, ...);
 # define HASINITGROUPS 1       /* has initgroups(3) call */
 # define HASUNAME      1       /* use System V uname(2) system call */
 # define HASGETUSERSHELL 0     /* does not have getusershell(3) call */
 # define HASINITGROUPS 1       /* has initgroups(3) call */
 # define HASUNAME      1       /* use System V uname(2) system call */
 # define HASGETUSERSHELL 0     /* does not have getusershell(3) call */
+# ifndef IP_SRCROUTE
+#  define IP_SRCROUTE  0       /* Something is broken with getsockopt() */
+# endif
 # define FORK          fork    /* no vfork primitive available */
 # define GIDSET_T      gid_t
 # define SFS_TYPE      SFS_STATFS      /* use <sys/statfs.h> statfs() impl */
 # define FORK          fork    /* no vfork primitive available */
 # define GIDSET_T      gid_t
 # define SFS_TYPE      SFS_STATFS      /* use <sys/statfs.h> statfs() impl */
@@ -700,6 +703,9 @@ typedef short               pid_t;
 # ifndef IDENTPROTO
 #  define IDENTPROTO   0       /* TCP/IP implementation is broken */
 # endif
 # ifndef IDENTPROTO
 #  define IDENTPROTO   0       /* TCP/IP implementation is broken */
 # endif
+# ifndef IP_SRCROUTE
+#  define IP_SRCROUTE  0       /* Something is broken with getsockopt() */
+# endif
 #endif
 
 
 #endif
 
 
@@ -1391,6 +1397,10 @@ extern int       errno;
 # define IDENTPROTO    1       /* use IDENT proto (RFC 1413) */
 #endif
 
 # define IDENTPROTO    1       /* use IDENT proto (RFC 1413) */
 #endif
 
+#ifndef IP_SRCROUTE
+# define IP_SRCROUTE   1       /* Detect IP source routing */
+#endif
+
 #ifndef HASGETUSERSHELL
 # define HASGETUSERSHELL 1     /* libc has getusershell(3) call */
 #endif
 #ifndef HASGETUSERSHELL
 # define HASGETUSERSHELL 1     /* libc has getusershell(3) call */
 #endif
index 7eb14b2..d448ca0 100644 (file)
@@ -12,9 +12,9 @@
 
 #ifndef lint
 #ifdef DAEMON
 
 #ifndef lint
 #ifdef DAEMON
-static char sccsid[] = "@(#)daemon.c   8.90 (Berkeley) %G% (with daemon mode)";
+static char sccsid[] = "@(#)daemon.c   8.91 (Berkeley) %G% (with daemon mode)";
 #else
 #else
-static char sccsid[] = "@(#)daemon.c   8.90 (Berkeley) %G% (without daemon mode)";
+static char sccsid[] = "@(#)daemon.c   8.91 (Berkeley) %G% (without daemon mode)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -26,6 +26,12 @@ static char sccsid[] = "@(#)daemon.c 8.90 (Berkeley) %G% (without daemon mode)";
 # include <resolv.h>
 #endif
 
 # include <resolv.h>
 #endif
 
+#if IP_SRCROUTE
+# include <netinet/in_systm.h>
+# include <netinet/ip.h>
+# include <netinet/ip_var.h>
+#endif
+
 /*
 **  DAEMON.C -- routines to use when running as a daemon.
 **
 /*
 **  DAEMON.C -- routines to use when running as a daemon.
 **
@@ -722,7 +728,7 @@ getauthinfo(fd)
        i = strlen(hbuf);
        hbuf[i++] = '@';
        strcpy(&hbuf[i], RealHostName == NULL ? "localhost" : RealHostName);
        i = strlen(hbuf);
        hbuf[i++] = '@';
        strcpy(&hbuf[i], RealHostName == NULL ? "localhost" : RealHostName);
-       goto finish;
+       goto postident;
 
 closeident:
        (void) close(s);
 
 closeident:
        (void) close(s);
@@ -737,12 +743,91 @@ noident:
        }
        (void) strcpy(hbuf, RealHostName);
 
        }
        (void) strcpy(hbuf, RealHostName);
 
-finish:
+postident:
+#if IP_SRCROUTE
+       /*
+       **  Extract IP source routing information.
+       **
+       **      Format of output for a connection from site a through b
+       **      through c to d:
+       **              loose:      @site-c@site-b:site-a
+       **              strict:    !@site-c@site-b:site-a
+       **
+       **      o - pointer within ipopt_list structure.
+       **      q - pointer within ls/ss rr route data
+       **      p - pointer to hbuf
+       */
+
+       if (RealHostAddr.sa.sa_family == AF_INET)
+       {
+               int ipoptlen, j;
+               char *q;
+               u_char *o;
+               struct in_addr addr;
+               struct ipoption ipopt;
+
+               ipoptlen = sizeof ipopt;
+               if (getsockopt(fd, IPPROTO_IP, IP_OPTIONS,
+                              (char *) &ipopt, &ipoptlen) < 0)
+                       goto noipsr;
+               if (ipoptlen == 0)
+                       goto noipsr;
+               o = (u_char *) &ipopt.ipopt_list;
+               while (o != NULL && o < (u_char *) (&ipopt + ipoptlen))
+               {
+                       switch (*o)
+                       {
+                         case IPOPT_EOL: 
+                               o = NULL;
+                               break;
+
+                         case IPOPT_NOP:
+                               o++;
+                               break;
+
+                         case IPOPT_SSRR:
+                         case IPOPT_LSRR:
+                               p = &hbuf[strlen(hbuf)];
+                               sprintf(p, " [%s@%s",
+                                   *o == IPOPT_SSRR ? "!" : "",
+                                   inet_ntoa(ipopt.ipopt_dst));
+                               p += strlen(p);
+
+                               /* o[1] is option length */
+                               j = *++o / sizeof(struct in_addr) - 1;
+
+                               /* q skips length and router pointer to data */
+                               q = o + 2;
+                               for ( ; j >= 0; j--)
+                               {
+                                       memcpy(&addr, q, sizeof(addr));
+                                       p += sprintf(p, "%c%s",
+                                                    j ? '@' : ':',
+                                                    inet_ntoa(addr));
+                                       q+=sizeof(struct in_addr); 
+                               }
+                               o += *o;
+                               break;
+
+                         default:
+                               /* Skip over option */
+                               o += o[1];
+                               break;
+                       }
+               }
+               strcat(hbuf,"]");
+               goto postipsr;
+       }
+#endif
+
+noipsr:
        if (RealHostName != NULL && RealHostName[0] != '[')
        {
                p = &hbuf[strlen(hbuf)];
                (void) sprintf(p, " [%s]", anynet_ntoa(&RealHostAddr));
        }
        if (RealHostName != NULL && RealHostName[0] != '[')
        {
                p = &hbuf[strlen(hbuf)];
                (void) sprintf(p, " [%s]", anynet_ntoa(&RealHostAddr));
        }
+
+postipsr:
        if (tTd(9, 1))
                printf("getauthinfo: %s\n", hbuf);
        return hbuf;
        if (tTd(9, 1))
                printf("getauthinfo: %s\n", hbuf);
        return hbuf;