initial hooks for ISO networking
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Sat, 20 Mar 1993 08:24:40 +0000 (00:24 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Sat, 20 Mar 1993 08:24:40 +0000 (00:24 -0800)
SCCS-vsn: usr.sbin/sendmail/src/headers.c 6.24
SCCS-vsn: usr.sbin/sendmail/src/sendmail.h 6.32
SCCS-vsn: usr.sbin/sendmail/src/daemon.c 6.20
SCCS-vsn: usr.sbin/sendmail/src/Makefile 6.2
SCCS-vsn: usr.sbin/sendmail/src/srvrsmtp.c 6.28
SCCS-vsn: usr.sbin/sendmail/src/deliver.c 6.53
SCCS-vsn: usr.sbin/sendmail/src/udb.c 6.14

usr/src/usr.sbin/sendmail/src/Makefile
usr/src/usr.sbin/sendmail/src/daemon.c
usr/src/usr.sbin/sendmail/src/deliver.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/udb.c

index 4344910..6ba11ec 100644 (file)
@@ -1,4 +1,4 @@
-#      @(#)Makefile    6.1 (Berkeley) %G%
+#      @(#)Makefile    6.2 (Berkeley) %G%
 
 PROG=  sendmail
 
 
 PROG=  sendmail
 
@@ -12,7 +12,7 @@ PROG= sendmail
 # spiral snail, but it will work.
 DBMDEF=        -DNEWDB -DNDBM
 
 # spiral snail, but it will work.
 DBMDEF=        -DNEWDB -DNDBM
 
-CFLAGS+=-I${.CURDIR} ${DBMDEF}
+CFLAGS+=-I${.CURDIR} ${DBMDEF} -DNETISO
 
 SRCS=  alias.c arpadate.c clock.c collect.c conf.c convtime.c daemon.c \
        deliver.c domain.c envelope.c err.c headers.c macro.c main.c map.c \
 
 SRCS=  alias.c arpadate.c clock.c collect.c conf.c convtime.c daemon.c \
        deliver.c domain.c envelope.c err.c headers.c macro.c main.c map.c \
index e002a31..f082619 100644 (file)
@@ -13,9 +13,9 @@
 
 #ifndef lint
 #ifdef DAEMON
 
 #ifndef lint
 #ifdef DAEMON
-static char sccsid[] = "@(#)daemon.c   6.19 (Berkeley) %G% (with daemon mode)";
+static char sccsid[] = "@(#)daemon.c   6.20 (Berkeley) %G% (with daemon mode)";
 #else
 #else
-static char sccsid[] = "@(#)daemon.c   6.19 (Berkeley) %G% (without daemon mode)";
+static char sccsid[] = "@(#)daemon.c   6.20 (Berkeley) %G% (without daemon mode)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -25,6 +25,10 @@ static char sccsid[] = "@(#)daemon.c 6.19 (Berkeley) %G% (without daemon mode)";
 # include <sys/wait.h>
 # include <sys/time.h>
 
 # include <sys/wait.h>
 # include <sys/time.h>
 
+#ifdef NETISO
+# include <netiso/iso.h>
+#endif
+
 /*
 **  DAEMON.C -- routines to use when running as a daemon.
 **
 /*
 **  DAEMON.C -- routines to use when running as a daemon.
 **
@@ -55,6 +59,8 @@ static char sccsid[] = "@(#)daemon.c  6.19 (Berkeley) %G% (without daemon mode)";
 **             Convert the entry in hbuf into a canonical form.
 */
 
 **             Convert the entry in hbuf into a canonical form.
 */
 
+extern char    *anynet_ntoa();
+
 static FILE    *MailPort;      /* port that mail comes in on */
 \f/*
 **  GETREQUESTS -- open mail IPC port and get requests.
 static FILE    *MailPort;      /* port that mail comes in on */
 \f/*
 **  GETREQUESTS -- open mail IPC port and get requests.
@@ -175,7 +181,7 @@ getrequests()
 **             none.
 */
 
 **             none.
 */
 
-struct sockaddr_in     CurHostAddr;            /* address of current host */
+SOCKADDR       CurHostAddr;            /* address of current host */
 
 int
 makeconnection(host, port, mci, usesecureport)
 
 int
 makeconnection(host, port, mci, usesecureport)
@@ -186,9 +192,9 @@ makeconnection(host, port, mci, usesecureport)
 {
        register int i, s;
        register struct hostent *hp = (struct hostent *)NULL;
 {
        register int i, s;
        register struct hostent *hp = (struct hostent *)NULL;
-       struct sockaddr_in addr;
+       SOCKADDR addr;
        int sav_errno;
        int sav_errno;
-       extern char *inet_ntoa();
+       int addrlen;
 #ifdef NAMED_BIND
        extern int h_errno;
 #endif
 #ifdef NAMED_BIND
        extern int h_errno;
 #endif
@@ -226,7 +232,9 @@ makeconnection(host, port, mci, usesecureport)
                        usrerr("553 Invalid numeric domain spec \"%s\"", host);
                        return (EX_NOHOST);
                }
                        usrerr("553 Invalid numeric domain spec \"%s\"", host);
                        return (EX_NOHOST);
                }
-               addr.sin_addr.s_addr = hid;
+               addr.sa_family = AF_INET;
+               addr.sa_len = sizeof hid;
+               addr.sa_u.sa_inet.sin_addr.s_addr = hid;
        }
        else
        {
        }
        else
        {
@@ -244,7 +252,16 @@ gothostent:
 #endif
                        return (EX_NOHOST);
                }
 #endif
                        return (EX_NOHOST);
                }
-               bcopy(hp->h_addr, (char *) &addr.sin_addr, hp->h_length);
+               addr.sa_family = hp->h_addrtype;
+               addr.sa_len = hp->h_length;
+               if (addr.sa_family == AF_INET)
+                       bcopy(hp->h_addr,
+                               &addr.sa_u.sa_inet.sin_addr,
+                               hp->h_length);
+               else
+                       bcopy(hp->h_addr,
+                               addr.sa_u.sa_data,
+                               hp->h_length);
                i = 1;
        }
 
                i = 1;
        }
 
@@ -253,7 +270,7 @@ gothostent:
        */
 
        if (port != 0)
        */
 
        if (port != 0)
-               addr.sin_port = htons(port);
+               port = htons(port);
        else
        {
                register struct servent *sp = getservbyname("smtp", "tcp");
        else
        {
                register struct servent *sp = getservbyname("smtp", "tcp");
@@ -263,7 +280,27 @@ gothostent:
                        syserr("554 makeconnection: server \"smtp\" unknown");
                        return (EX_OSERR);
                }
                        syserr("554 makeconnection: server \"smtp\" unknown");
                        return (EX_OSERR);
                }
-               addr.sin_port = sp->s_port;
+               port = sp->s_port;
+       }
+
+       switch (addr.sa_family)
+       {
+         case AF_INET:
+               addr.sa_u.sa_inet.sin_port = port;
+               addrlen = sizeof (struct sockaddr_in);
+               break;
+
+#ifdef NETISO
+         case AF_ISO:
+               /* assume two byte transport selector */
+               bcopy((char *) &port, TSEL((struct sockaddr_iso *) &addr), 2);
+               addrlen = sizeof (struct sockaddr_iso);
+               break;
+#endif
+
+         default:
+               syserr("Can't connect to address family %d", addr.sa_family);
+               return (EX_NOHOST);
        }
 
        /*
        }
 
        /*
@@ -273,8 +310,8 @@ gothostent:
        for (;;)
        {
                if (tTd(16, 1))
        for (;;)
        {
                if (tTd(16, 1))
-                       printf("makeconnection (%s [%s])\n", host,
-                           inet_ntoa(addr.sin_addr));
+                       printf("makeconnection (%s [%s])\n",
+                               host, anynet_ntoa(&addr));
 
                /* save for logging */
                CurHostAddr = addr;
 
                /* save for logging */
                CurHostAddr = addr;
@@ -309,8 +346,7 @@ gothostent:
                if (CurEnv->e_xfp != NULL)
                        (void) fflush(CurEnv->e_xfp);           /* for debugging */
                errno = 0;                                      /* for debugging */
                if (CurEnv->e_xfp != NULL)
                        (void) fflush(CurEnv->e_xfp);           /* for debugging */
                errno = 0;                                      /* for debugging */
-               addr.sin_family = AF_INET;
-               if (connect(s, (struct sockaddr *) &addr, sizeof addr) >= 0)
+               if (connect(s, (struct sockaddr *) &addr, addrlen) >= 0)
                        break;
 
                /* couldn't connect.... figure out why */
                        break;
 
                /* couldn't connect.... figure out why */
@@ -318,9 +354,18 @@ gothostent:
                (void) close(s);
                if (hp && hp->h_addr_list[i])
                {
                (void) close(s);
                if (hp && hp->h_addr_list[i])
                {
+                       extern char *errstring();
+
                        if (tTd(16, 1))
                        if (tTd(16, 1))
-                               printf("Connect failed; trying new address....\n");
-                       bcopy(hp->h_addr_list[i++], (char *) &addr.sin_addr,
+                               printf("Connect failed (%s); trying new address....\n",
+                                       errstring(sav_errno));
+                       if (addr.sa_family == AF_INET)
+                               bcopy(hp->h_addr_list[i++],
+                                     &addr.sa_u.sa_inet.sin_addr,
+                                     hp->h_length);
+                       else
+                               bcopy(hp->h_addr_list[i++],
+                                       addr.sa_u.sa_data,
                                        hp->h_length);
                        continue;
                }
                                        hp->h_length);
                        continue;
                }
@@ -329,13 +374,6 @@ gothostent:
        failure:
                if (transienterror(sav_errno))
                        return EX_TEMPFAIL;
        failure:
                if (transienterror(sav_errno))
                        return EX_TEMPFAIL;
-               else if (sav_errno == EPERM)
-               {
-                       /* why is this happening? */
-                       syserr("makeconnection: funny failure, addr=%lx, port=%x",
-                               addr.sin_addr.s_addr, addr.sin_port);
-                       return (EX_TEMPFAIL);
-               }
                else
                {
                        extern char *errstring();
                else
                {
                        extern char *errstring();
@@ -423,21 +461,20 @@ getrealhostname(fd)
        int fd;
 {
        register struct hostent *hp;
        int fd;
 {
        register struct hostent *hp;
-       struct sockaddr_in sin;
-       int sinlen;
+       struct sockaddr sa;
+       int salen;
        char hbuf[MAXNAME];
        extern struct hostent *gethostbyaddr();
        char hbuf[MAXNAME];
        extern struct hostent *gethostbyaddr();
-       extern char *inet_ntoa();
 
 
-       if (getsockname(fd, (struct sockaddr *) &sin, &sinlen) < 0 ||
-           sinlen <= 0)
+       salen = sizeof sa;
+       if (getsockname(fd, &sa, &salen) < 0 || salen <= 0)
                return NULL;
                return NULL;
-       hp = gethostbyaddr((char *) &sin.sin_addr, sizeof sin.sin_addr,
-                          sin.sin_family);
+       hp = gethostbyaddr(sa.sa_data, sa.sa_len,
+                          sa.sa_family);
        if (hp != NULL)
                (void) strcpy(hbuf, hp->h_name);
        else
        if (hp != NULL)
                (void) strcpy(hbuf, hp->h_name);
        else
-               (void) sprintf(hbuf, "[%s]", inet_ntoa(sin.sin_addr));
+               (void) sprintf(hbuf, "[%s]", anynet_ntoa(&sa));
        return hbuf;
 }
 \f/*
        return hbuf;
 }
 \f/*
@@ -519,6 +556,44 @@ maphostname(map, hbuf, hbsize, avp)
        (void) strcpy(hbuf, hp->h_name);
        return hbuf;
 }
        (void) strcpy(hbuf, hp->h_name);
        return hbuf;
 }
+\f/*
+**  ANYNET_NTOA -- convert a network address to printable form.
+**
+**     Parameters:
+**             sap -- a pointer to a sockaddr structure.
+**
+**     Returns:
+**             A printable version of that sockaddr.
+*/
+
+char *
+anynet_ntoa(sap)
+       register SOCKADDR *sap;
+{
+       register char *bp;
+       register char *ap;
+       int l;
+       static char buf[80];
+
+       if (sap->sa_family == AF_INET)
+       {
+               extern char *inet_ntoa();
+
+               return inet_ntoa(((struct sockaddr_in *) sap)->sin_addr);
+       }
+
+       /* unknown family -- just dump bytes */
+       (void) sprintf(buf, "Family %d: ", sap->sa_family);
+       bp = &buf[strlen(buf)];
+       ap = sap->sa_u.sa_data;
+       for (l = sap->sa_len; --l >= 0; )
+       {
+               (void) sprintf(bp, "%02x:", *ap++ & 0377);
+               bp += 3;
+       }
+       *--bp = '\0';
+       return buf;
+}
 
 # else /* DAEMON */
 /* code for systems without sophisticated networking */
 
 # else /* DAEMON */
 /* code for systems without sophisticated networking */
index 0aae512..0b17295 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)deliver.c  6.52 (Berkeley) %G%";
+static char sccsid[] = "@(#)deliver.c  6.53 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "sendmail.h"
 #endif /* not lint */
 
 #include "sendmail.h"
@@ -1189,8 +1189,8 @@ logdelivery(m, mci, stat, e)
        if (mci != NULL && mci->mci_host != NULL)
        {
 # ifdef DAEMON
        if (mci != NULL && mci->mci_host != NULL)
        {
 # ifdef DAEMON
-               extern struct sockaddr_in CurHostAddr;
-               extern char *inet_ntoa();
+               extern SOCKADDR CurHostAddr;
+               extern char *anynet_ntoa();
 # endif
 
                (void) strcat(buf, ", relay=");
 # endif
 
                (void) strcat(buf, ", relay=");
@@ -1198,7 +1198,7 @@ logdelivery(m, mci, stat, e)
 
 # ifdef DAEMON
                (void) strcat(buf, " (");
 
 # ifdef DAEMON
                (void) strcat(buf, " (");
-               (void) strcat(buf, inet_ntoa(CurHostAddr.sin_addr));
+               (void) strcat(buf, anynet_ntoa(&CurHostAddr));
                (void) strcat(buf, ")");
 # endif
        }
                (void) strcat(buf, ")");
 # endif
        }
index b1e72ce..0e5d843 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)headers.c  6.23 (Berkeley) %G%";
+static char sccsid[] = "@(#)headers.c  6.24 (Berkeley) %G%";
 #endif /* not lint */
 
 # include <errno.h>
 #endif /* not lint */
 
 # include <errno.h>
@@ -399,11 +399,11 @@ eatheader(e)
                        name = RealHostName;
                else
                {
                        name = RealHostName;
                else
                {
-                       extern char *inet_ntoa();
+                       extern char *anynet_ntoa();
 
                        name = hbuf;
                        (void)sprintf(hbuf, "%.80s (%s)", 
 
                        name = hbuf;
                        (void)sprintf(hbuf, "%.80s (%s)", 
-                           RealHostName, inet_ntoa(RealHostAddr.sin_addr));
+                           RealHostName, anynet_ntoa(&RealHostAddr));
                }
 
                /* some versions of syslog only take 5 printf args */
                }
 
                /* some versions of syslog only take 5 printf args */
index e1d56c4..66b54c5 100644 (file)
@@ -5,7 +5,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)sendmail.h  6.31 (Berkeley) %G%
+ *     @(#)sendmail.h  6.32 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -15,7 +15,7 @@
 # ifdef _DEFINE
 # define EXTERN
 # ifndef lint
 # ifdef _DEFINE
 # define EXTERN
 # ifndef lint
-static char SmailSccsId[] =    "@(#)sendmail.h 6.31            %G%";
+static char SmailSccsId[] =    "@(#)sendmail.h 6.32            %G%";
 # endif lint
 # else /*  _DEFINE */
 # define EXTERN extern
 # endif lint
 # else /*  _DEFINE */
 # define EXTERN extern
@@ -595,6 +595,29 @@ struct prival
        char    *pv_name;       /* name of privacy flag */
        int     pv_flag;        /* numeric level */
 };
        char    *pv_name;       /* name of privacy flag */
        int     pv_flag;        /* numeric level */
 };
+
+/*
+**  Regular UNIX sockaddrs are too small to handle ISO addresses, so
+**  we are forced to declare a supertype here.
+*/
+
+struct bigsockaddr
+{
+       u_char  sa_len;                 /* address length */
+       u_char  sa_family;              /* address family */
+       union
+       {
+               char    sa_data[256];   /* make sure there's plenty of space */
+               struct
+               {
+                       u_short         sin_port;       /* INET port */
+                       struct in_addr  sin_addr;       /* INET address */
+               } sa_inet;
+       } sa_u;
+};
+
+#define SOCKADDR       struct bigsockaddr
+
 \f/*
 **  Global variables.
 */
 \f/*
 **  Global variables.
 */
@@ -645,7 +668,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 SOCKADDR 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 6cccbed..7153797 100644 (file)
@@ -10,9 +10,9 @@
 
 #ifndef lint
 #ifdef SMTP
 
 #ifndef lint
 #ifdef SMTP
-static char sccsid[] = "@(#)srvrsmtp.c 6.27 (Berkeley) %G% (with SMTP)";
+static char sccsid[] = "@(#)srvrsmtp.c 6.28 (Berkeley) %G% (with SMTP)";
 #else
 #else
-static char sccsid[] = "@(#)srvrsmtp.c 6.27 (Berkeley) %G% (without SMTP)";
+static char sccsid[] = "@(#)srvrsmtp.c 6.28 (Berkeley) %G% (without SMTP)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -214,7 +214,7 @@ smtp(e)
                        }
                        (void) strcpy(hostbuf, p);
                        (void) strcat(hostbuf, " (");
                        }
                        (void) strcpy(hostbuf, p);
                        (void) strcat(hostbuf, " (");
-                       (void) strcat(hostbuf, inet_ntoa(RealHostAddr.sin_addr));
+                       (void) strcat(hostbuf, anynet_ntoa(&RealHostAddr));
                        if (strcasecmp(p, RealHostName) != 0)
                        {
                                (void) strcat(hostbuf, "; ");
                        if (strcasecmp(p, RealHostName) != 0)
                        {
                                (void) strcat(hostbuf, "; ");
@@ -538,7 +538,7 @@ smtp(e)
                                syslog(LOG_NOTICE,
                                    "\"%s\" command from %s (%s)",
                                    c->cmdname, RealHostName,
                                syslog(LOG_NOTICE,
                                    "\"%s\" command from %s (%s)",
                                    c->cmdname, RealHostName,
-                                   inet_ntoa(RealHostAddr.sin_addr));
+                                   anynet_ntoa(&RealHostAddr));
 # endif
                        /* FALL THROUGH */
 # endif /* SMTPDEBUG */
 # endif
                        /* FALL THROUGH */
 # endif /* SMTPDEBUG */
index 029e567..45153e2 100644 (file)
@@ -8,9 +8,9 @@
 
 #ifndef lint
 #ifdef USERDB
 
 #ifndef lint
 #ifdef USERDB
-static char sccsid [] = "@(#)udb.c     6.13 (Berkeley) %G% (with USERDB)";
+static char sccsid [] = "@(#)udb.c     6.14 (Berkeley) %G% (with USERDB)";
 #else
 #else
-static char sccsid [] = "@(#)udb.c     6.13 (Berkeley) %G% (without USERDB)";
+static char sccsid [] = "@(#)udb.c     6.14 (Berkeley) %G% (without USERDB)";
 #endif
 #endif
 
 #endif
 #endif
 
@@ -530,6 +530,7 @@ _udbx_init()
                                        continue;
                                up->udb_type = UDB_REMOTE;
                                up->udb_addr.sin_family = h->h_addrtype;
                                        continue;
                                up->udb_type = UDB_REMOTE;
                                up->udb_addr.sin_family = h->h_addrtype;
+                               up->udb_addr.sin_len = h->h_length;
                                bcopy(h->h_addr_list[0],
                                      (char *) &up->udb_addr.sin_addr,
                                      h->h_length);
                                bcopy(h->h_addr_list[0],
                                      (char *) &up->udb_addr.sin_addr,
                                      h->h_length);
@@ -580,7 +581,7 @@ _udbx_init()
                        {
                          case UDB_REMOTE:
                                printf("REMOTE: addr %s, timeo %d\n",
                        {
                          case UDB_REMOTE:
                                printf("REMOTE: addr %s, timeo %d\n",
-                                       inet_ntoa(up->udb_addr.sin_addr),
+                                       anynet_ntoa(&up->udb_addr),
                                        up->udb_timeout);
                                break;
 
                                        up->udb_timeout);
                                break;