add route pruning
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Tue, 23 Feb 1993 08:59:53 +0000 (00:59 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Tue, 23 Feb 1993 08:59:53 +0000 (00:59 -0800)
SCCS-vsn: usr.sbin/sendmail/src/sendmail.h 6.18
SCCS-vsn: usr.sbin/sendmail/src/savemail.c 6.10

usr/src/usr.sbin/sendmail/src/savemail.c
usr/src/usr.sbin/sendmail/src/sendmail.h

index 322116c..9bb5dcb 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)savemail.c 6.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)savemail.c 6.10 (Berkeley) %G%";
 #endif /* not lint */
 
 # include <sys/types.h>
 #endif /* not lint */
 
 # include <sys/types.h>
@@ -397,6 +397,9 @@ returntosender(msg, returnq, sendbody, e)
        openxscript(ee);
        for (q = returnq; q != NULL; q = q->q_next)
        {
        openxscript(ee);
        for (q = returnq; q != NULL; q = q->q_next)
        {
+               if (!DontPruneRoutes && pruneroute(q->q_paddr))
+                       parseaddr(q->q_paddr, q, 0, '\0', e);
+
                if (q->q_alias == NULL)
                        addheader("to", q->q_paddr, ee);
        }
                if (q->q_alias == NULL)
                        addheader("to", q->q_paddr, ee);
        }
@@ -559,3 +562,62 @@ errbody(fp, m, e)
        if (errno != 0)
                syserr("errbody: I/O error");
 }
        if (errno != 0)
                syserr("errbody: I/O error");
 }
+\f/*
+**  PRUNEROUTE -- prune an RFC-822 source route
+** 
+**     Trims down a source route to the last internet-registered hop.
+**     This is encouraged by RFC 1123 section 5.3.3.
+** 
+**     Parameters:
+**             addr -- the address
+** 
+**     Returns:
+**             TRUE -- address was modified
+**             FALSE -- address could not be pruned
+** 
+**     Side Effects:
+**             modifies addr in-place
+*/
+
+pruneroute(addr)
+       char *addr;
+{
+#ifdef NAMED_BIND
+       char *start, *at, *comma;
+       char c;
+       int rcode;
+       char hostbuf[BUFSIZ];
+       char *mxhosts[MAXMXHOSTS + 1];
+
+       /* check to see if this is really a route-addr */
+       if (*addr != '<' || addr[1] != '@' || addr[strlen(addr) - 1] != '>')
+               return FALSE;
+       start = strchr(addr, ':');
+       at = strrchr(addr, '@');
+       if (start == NULL || at == NULL || at < start)
+               return FALSE;
+
+       /* slice off the angle brackets */
+       strcpy(hostbuf, at + 1);
+       hostbuf[strlen(hostbuf) - 1] = '\0';
+
+       while (start)
+       {
+               if (getmxrr(hostbuf, mxhosts, "", &rcode) > 0)
+               {
+                       strcpy(addr + 1, start + 1);
+                       return TRUE;
+               }
+               c = *start;
+               *start = '\0';
+               comma = strrchr(addr, ',');
+               if (comma && comma[1] == '@')
+                       strcpy(hostbuf, comma + 2);
+               else
+                       comma = 0;
+               *start = c;
+               start = comma;
+       }
+#endif
+       return FALSE;
+}
index f9807c8..33de9e9 100644 (file)
@@ -5,7 +5,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)sendmail.h  6.17 (Berkeley) %G%
+ *     @(#)sendmail.h  6.18 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -15,7 +15,7 @@
 # ifdef _DEFINE
 # define EXTERN
 # ifndef lint
 # ifdef _DEFINE
 # define EXTERN
 # ifndef lint
-static char SmailSccsId[] =    "@(#)sendmail.h 6.17            %G%";
+static char SmailSccsId[] =    "@(#)sendmail.h 6.18            %G%";
 # endif lint
 # else /*  _DEFINE */
 # define EXTERN extern
 # endif lint
 # else /*  _DEFINE */
 # define EXTERN extern
@@ -666,6 +666,7 @@ EXTERN int  MaxHopCount;    /* number of hops until we give an error */
 EXTERN int     ConfigLevel;    /* config file level -- what does .cf expect? */
 EXTERN char    *TimeZoneSpec;  /* override time zone specification */
 EXTERN bool    MatchGecos;     /* look for user names in gecos field */
 EXTERN int     ConfigLevel;    /* config file level -- what does .cf expect? */
 EXTERN char    *TimeZoneSpec;  /* override time zone specification */
 EXTERN bool    MatchGecos;     /* look for user names in gecos field */
+EXTERN bool    DontPruneRoutes;        /* don't prune source routes */
 EXTERN int     MaxMciCache;    /* maximum entries in MCI cache */
 EXTERN time_t  MciCacheTimeout;        /* maximum idle time on connections */
 EXTERN char    *ForwardPath;   /* path to search for .forward files */
 EXTERN int     MaxMciCache;    /* maximum entries in MCI cache */
 EXTERN time_t  MciCacheTimeout;        /* maximum idle time on connections */
 EXTERN char    *ForwardPath;   /* path to search for .forward files */