put mailer definitions into configuration file
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Mon, 10 Aug 1981 10:08:47 +0000 (02:08 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Mon, 10 Aug 1981 10:08:47 +0000 (02:08 -0800)
SCCS-vsn: usr.sbin/sendmail/src/conf.c 3.16
SCCS-vsn: usr.sbin/sendmail/src/sendmail.h 3.22
SCCS-vsn: usr.sbin/sendmail/src/version.c 3.4
SCCS-vsn: usr.sbin/sendmail/src/main.c 3.16
SCCS-vsn: usr.sbin/sendmail/src/readcf.c 3.7

usr/src/usr.sbin/sendmail/src/conf.c
usr/src/usr.sbin/sendmail/src/main.c
usr/src/usr.sbin/sendmail/src/readcf.c
usr/src/usr.sbin/sendmail/src/sendmail.h
usr/src/usr.sbin/sendmail/src/version.c

index 4064865..72862ec 100644 (file)
@@ -8,12 +8,6 @@
 **     Defines the configuration of this installation.
 **
 **     Compilation Flags:
 **     Defines the configuration of this installation.
 **
 **     Compilation Flags:
-**             NETV6MAIL -- set if you want to use "v6mail" that
-**                     comes with the Berkeley network.  Normally
-**                     /bin/mail will work fine, but around Berkeley
-**                     we use v6mail because it is a "fixed target".
-**                     Also, only v6mail has the "/dev/mail" stuff
-**                     in it (for biff(1)).
 **             V6 -- running on a version 6 system.  This determines
 **                     whether to define certain routines between
 **                     the two systems.  If you are running a funny
 **             V6 -- running on a version 6 system.  This determines
 **                     whether to define certain routines between
 **                     the two systems.  If you are running a funny
 **                     should be checked carefully.
 **
 **     Configuration Variables:
 **                     should be checked carefully.
 **
 **     Configuration Variables:
-**             Mailer -- a table of mailers known to the system.
-**                     This should be fairly static.  The fields are:
-**                     - the pathname of the mailer.
-**                     - a list of flags describing the properties
-**                       of this mailer:
-**                        M_FOPT -- if set, the mailer has a picky "-f"
-**                             option.  In this mode, the mailer will
-**                             only accept the "-f" option if the
-**                             sender is actually "root", "network",
-**                             and possibly (but not necessarily) if
-**                             the -f argument matches the real sender.
-**                             The effect is that if the "-f" option
-**                             is given to sendmail then it will be
-**                             passed through (as arguments 1 & 2) to
-**                             the mailer.
-**                        M_ROPT -- identical to M_FOPT, except uses
-**                             -r instead.
-**                        M_QUIET -- if set, don't print a message if
-**                             the mailer returns bad status.
-**                        M_RESTR -- if set, this mailer is restricted
-**                             to use by "daemon"; otherwise, we do a
-**                             setuid(getuid()) before calling the
-**                             mailer.
-**                        M_NHDR -- if set, the mailer doesn't want us
-**                             to insert a UNIX "From" line before
-**                             outputing.
-**                        M_NOHOST -- if set, this mailer doesn't care
-**                             about the host part (e.g., the local
-**                             mailer).
-**                        M_STRIPQ -- if set, strip quote (`"')
-**                             characters out of parameters as you
-**                             transliterate them into the argument
-**                             vector.  For example, the local mailer
-**                             is called directly, so these should be
-**                             stripped, but the program-mailer (i.e.,
-**                             csh) should leave them in.
-**                        M_NEEDDATE -- this mailer requires a Date:
-**                             field in the message.
-**                        M_NEEDFROM -- this mailer requires a From:
-**                             field in the message.
-**                        M_MSGID -- this mailer requires a Message-Id
-**                             field in the message.
-**                        M_ARPAFMT == M_NEEDDATE|M_NEEDFROM|M_MSGID.
-**                     - an exit status to use as the code for the
-**                       error message print if the mailer returns
-**                       something we don't understand.
-**                     - A list of names that are to be considered
-**                       "local" (and hence are stripped off) for
-**                       this mailer.
-**                     - An argument vector to be passed to the
-**                       mailer; this is macro substituted.
-**                     >>>>>>>>>> Entry zero must be for the local
-**                     >> NOTE >> mailer and entry one must be for
-**                     >>>>>>>>>> the shell.
 **             HdrInfo -- a table describing well-known header fields.
 **                     Each entry has the field name and some flags,
 **                     which can be:
 **             HdrInfo -- a table describing well-known header fields.
 **                     Each entry has the field name and some flags,
 **                     which can be:
 **                     - H_DELETE -- delete this field.
 **                     There is also a field pointing to a pointer
 **                     that should be set to point to this header.
 **                     - H_DELETE -- delete this field.
 **                     There is also a field pointing to a pointer
 **                     that should be set to point to this header.
+**
+**     Notes:
+**             I have tried to put almost all the reasonable
+**             configuration information into the configuration
+**             file read at runtime.  My intent is that anything
+**             here is a function of the version of UNIX you
+**             are running, or is really static -- for example
+**             the headers are a superset of widely used
+**             protocols.  If you find yourself playing with
+**             this file too much, you may be making a mistake!
 */
 
 
 
 
 */
 
 
 
 
-static char SccsId[] = "@(#)conf.c     3.15    %G%";
+static char SccsId[] = "@(#)conf.c     3.16    %G%";
 
 
 # include <whoami.h>           /* definitions of machine id's at berkeley */
 
 
 
 # include <whoami.h>           /* definitions of machine id's at berkeley */
 
-# ifdef BERKELEY
-# define NETV6MAIL             /* use /usr/net/bin/v6mail for local delivery */
-# endif BERKELEY
-
-
-
-/* local mail -- must be #0 */
-static char    *LocalArgv[] =
-{
-       "...local%mail",
-       "-d",
-       "$u",
-       NULL
-};
-
-static struct mailer   LocalMailer =
-{
-# ifdef NETV6MAIL
-       "local",        "/usr/net/bin/v6mail",
-# else
-       "local",        "/bin/mail",
-# endif
-       M_ROPT|M_NOHOST|M_STRIPQ|M_ARPAFMT|M_MUSER|M_NHDR,
-       EX_NOUSER,      "$f",           LocalArgv,      NULL,
-};
-
-/* pipes through programs -- must be #1 -- also used for files */
-static char    *ProgArgv[] =
-{
-       "...prog%mail",
-       "-fc",
-       "$u",
-       NULL
-};
-
-static struct mailer   ProgMailer =
-{
-       "prog",         "/bin/csh",
-       M_NOHOST|M_ARPAFMT,
-       EX_UNAVAILABLE, "$f",           ProgArgv,       NULL,
-};
-
-/* user-private mailers -- must be #2 */
-static char    *PrivArgv[] =
-{
-       "...priv%mail",
-       "$u",
-       NULL
-};
-
-static struct mailer   PrivMailer =
-{
-       "priv",         NULL,
-       M_ROPT|M_NOHOST|M_STRIPQ|M_ARPAFMT,
-       EX_UNAVAILABLE, "$f",           PrivArgv,       NULL,
-};
-
-/* local berkeley mail */
-static char    *BerkArgv[] =
-{
-       "...berk%mail",
-       "-m",
-       "$h",
-       "-h",
-       "$c",
-       "-t",
-       "$u",
-       NULL
-};
-
-static struct mailer   BerkMailer =
-{
-       "berk",         "/usr/net/bin/sendberkmail",
-       M_FOPT|M_NEEDDATE|M_FULLNAME|M_STRIPQ,
-       EX_UNAVAILABLE, "$B:$f",        BerkArgv,       NULL,
-};
-
-/* arpanet mail */
-static char    *ArpaArgv[] =
-{
-       "...arpa%mail",
-       "$f",
-       "$h",
-       "$u",
-       NULL
-};
-
-static struct mailer   ArpaMailer =
-{
-       "arpa",         "/usr/lib/mailers/arpa",
-       M_STRIPQ|M_ARPAFMT|M_USR_UPPER,
-       0,              "$f@$A",        ArpaArgv,       NULL,
-};
-
-/* uucp mail (cheat & use Bell's v7 mail) */
-static char    *UucpArgv[] =
-{
-       "...uucp%mail",
-       "-",
-       "$h!rmail",
-       "($u)",
-       NULL
-};
-
-static struct mailer   UucpMailer =
-{
-       "uucp",         "/usr/bin/uux",
-       M_ROPT|M_STRIPQ|M_NEEDDATE|M_FULLNAME|M_MUSER,
-       EX_NOUSER,      "$U!$f",        UucpArgv,       NULL,
-};
-
-struct mailer  *Mailer[] =
-{
-       &LocalMailer,           /* 0 -- must be 0 */
-       &ProgMailer,            /* 1 -- must be 1 */
-       &PrivMailer,            /* 2 -- must be 2 */
-       &BerkMailer,            /* 3 */
-       &ArpaMailer,            /* 4 */
-       &UucpMailer,            /* 5 */
-       NULL
-};
-
-/* offsets for arbitrary mailers */
-# define M_BERK                2       /* berknet */
-# define M_ARPA                3       /* arpanet */
-# define M_UUCP                4       /* UUCPnet */
-
-
-
-
 
 /*
 **  Header info table
 
 /*
 **  Header info table
index 36da904..5f3027e 100644 (file)
@@ -7,7 +7,7 @@
 # include <syslog.h>
 # endif LOG
 
 # include <syslog.h>
 # endif LOG
 
-static char    SccsId[] = "@(#)main.c  3.15    %G%";
+static char    SccsId[] = "@(#)main.c  3.16    %G%";
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
@@ -134,6 +134,8 @@ HDR *Header;        /* header list */
 char   *Macro[128];    /* macros */
 long   CurTime;        /* current time */
 char   FromLine[80];   /* holds From line (UNIX style header) */
 char   *Macro[128];    /* macros */
 long   CurTime;        /* current time */
 char   FromLine[80];   /* holds From line (UNIX style header) */
+int    NextMailer = 0; /* "free" index into Mailer struct */
+struct mailer  *Mailer[MAXMAILERS+1];  /* definition of mailers */
 
 
 
 
 
 
@@ -186,7 +188,7 @@ main(argc, argv)
 # endif
        errno = 0;
        from = NULL;
 # endif
        errno = 0;
        from = NULL;
-       cfname = "/usr/lib/sendmail.cf";
+       cfname = CONFFILE;
 
        /*
        ** Crack argv.
 
        /*
        ** Crack argv.
@@ -359,6 +361,22 @@ main(argc, argv)
        }
 # endif V6
 
        }
 # endif V6
 
+# ifdef DEBUG
+       if (Debug > 15)
+       {
+               printrules();
+               for (i = 0; i < MAXMAILERS; i++)
+               {
+                       register struct mailer *m = Mailer[i];
+
+                       if (m == NULL)
+                               continue;
+                       printf("mailer %d: %s %s %o %s\n", i, m->m_name,
+                              m->m_mailer, m->m_flags, m->m_from);
+               }
+       }
+# endif DEBUG
+
        /*
        locname = getname();
        if (locname == NULL || locname[0] == '\0')
        /*
        locname = getname();
        if (locname == NULL || locname[0] == '\0')
index ae80be4..041dcb5 100644 (file)
@@ -2,7 +2,7 @@
 # include "sendmail.h"
 # include <ctype.h>
 
 # include "sendmail.h"
 # include <ctype.h>
 
-static char SccsId[] = "@(#)readcf.c   3.6     %G%";
+static char SccsId[] = "@(#)readcf.c   3.7     %G%";
 
 /*
 **  READCF -- read control file.
 
 /*
 **  READCF -- read control file.
@@ -133,16 +133,108 @@ readcf(cfname)
                        }
                        break;
 
                        }
                        break;
 
+                 case 'M':             /* define mailer */
+                       makemailer(&buf[1]);
+                       break;
+
                  default:
                  badline:
                        syserr("unknown control line \"%s\"", buf);
                }
        }
                  default:
                  badline:
                        syserr("unknown control line \"%s\"", buf);
                }
        }
+}
+\f/*
+**  MAKEMAILER -- define a new mailer.
+**
+**     Parameters:
+**             line -- description of mailer.  This is in tokens
+**                     separated by white space.  The fields are:
+**                     * the name of the mailer, as refered to
+**                       in the rewriting rules.
+**                     * the pathname of the program to fork to
+**                       execute it.
+**                     * the options needed by this program.
+**                     * the macro string needed to translate
+**                       a local "from" name to one that can be
+**                       returned to this machine.
+**                     * the argument vector (a series of parameters).
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             enters the mailer into the mailer table.
+*/
+
+# define SETWORD \
+               { \
+                       while (*p != '\0' && isspace(*p)) \
+                               p++; \
+                       q = p; \
+                       while (*p != '\0' && !isspace(*p)) \
+                               p++; \
+                       if (*p != '\0') \
+                               *p++ = '\0'; \
+               }
+
+makemailer(line)
+       char *line;
+{
+       register char *p;
+       register char *q;
+       char *mname;
+       char *mpath;
+       int mopts;
+       char *mfrom;
+       register struct mailer *m;
+       char *margv[MAXPV + 1];
+       register int i;
+       extern int NextMailer;
+
+       if (NextMailer >= MAXMAILERS)
+       {
+               syserr("Too many mailers defined");
+               return;
+       }
+
+       /* collect initial information */
+       p = line;
+       SETWORD;
+       mname = q;
+       SETWORD;
+       mpath = q;
+       SETWORD;
+       mopts = crackopts(q);
+       SETWORD;
+       mfrom = q;
+
+       if (*p == '\0')
+       {
+               syserr("invalid M line in configuration file");
+               return;
+       }
+
+       /* allocate a mailer */
+       m = (struct mailer *) xalloc(sizeof *m);
+       m->m_name = newstr(mname);
+       m->m_mailer = newstr(mpath);
+       m->m_flags = mopts;
+       m->m_from = newstr(mfrom);
+       m->m_badstat = EX_UNAVAILABLE;
+       m->m_sendq = NULL;
+       Mailer[NextMailer++] = m;
 
 
-# ifdef DEBUG
-       if (Debug > 6)
-               printrules();
-# endif DEBUG
+       /* collect the argument vector */
+       for (i = 0; i < MAXPV - 1 && *p != '\0'; i++)
+       {
+               SETWORD;
+               margv[i] = newstr(q);
+       }
+       margv[i++] = NULL;
+
+       /* save the argv */
+       m->m_argv = (char **) xalloc(sizeof margv[0] * i);
+       bmove((char *) margv, (char *) m->m_argv, sizeof margv[0] * i);
 }
 \f/*
 **  PRINTRULES -- print rewrite rules (for debugging)
 }
 \f/*
 **  PRINTRULES -- print rewrite rules (for debugging)
@@ -188,3 +280,61 @@ printrules()
                }
        }
 }
                }
        }
 }
+\f/*
+**  CRACKOPTS -- crack mailer options
+**
+**     These options modify the functioning of the mailer
+**     from the configuration table.
+**
+**     Parameters:
+**             p -- pointer to vector of options.
+**
+**     Returns:
+**             option list in binary.
+**
+**     Side Effects:
+**             none.
+*/
+
+struct optlist
+{
+       char    opt_name;       /* external name of option */
+       int     opt_value;      /* internal name of option */
+};
+struct optlist OptList[] =
+{
+       'f',    M_FOPT,
+       'r',    M_ROPT,
+       'q',    M_QUIET,
+       'S',    M_RESTR,
+       'n',    M_NHDR,
+       'l',    M_NOHOST,
+       's',    M_STRIPQ,
+       'm',    M_MUSER,
+       'F',    M_NEEDFROM,
+       'D',    M_NEEDDATE,
+       'M',    M_MSGID,
+       'u',    M_USR_UPPER,
+       'h',    M_HST_UPPER,
+       'x',    M_FULLNAME,
+       'A',    M_ARPAFMT,
+       0,      0
+};
+
+crackopts(p)
+       register char *p;
+{
+       register struct optlist *o;
+       register int opts = 0;
+
+       while (*p != '\0')
+       {
+               for (o = OptList; o->opt_name != '\0' && o->opt_name != *p; o++)
+                       continue;
+               if (o->opt_name == '\0')
+                       syserr("bad mailer option %c", *p);
+               opts |= o->opt_value;
+               p++;
+       }
+       return (opts);
+}
index 1a3e987..ea1cd76 100644 (file)
@@ -1,7 +1,7 @@
 /*
 **  SENDMAIL.H -- Global definitions for sendmail.
 **
 /*
 **  SENDMAIL.H -- Global definitions for sendmail.
 **
-**     @(#)sendmail.h  3.21    %G%
+**     @(#)sendmail.h  3.22    %G%
 */
 
 
 */
 
 
@@ -19,7 +19,9 @@
 # define MAXPV         40      /* maximum # of parms to mailers */
 # define MAXHOP                30      /* maximum value of HopCount */
 # define MAXATOM       15      /* max atoms per address */
 # define MAXPV         40      /* maximum # of parms to mailers */
 # define MAXHOP                30      /* maximum value of HopCount */
 # define MAXATOM       15      /* max atoms per address */
+# define MAXMAILERS    10      /* maximum mailers known to system */
 # define ALIASFILE     "/usr/lib/aliases"      /* location of alias file */
 # define ALIASFILE     "/usr/lib/aliases"      /* location of alias file */
+# define CONFFILE      "/usr/lib/sendmail.cf"  /* configuration file */
 
 
 
 
 
 
index edb3db0..71213f3 100644 (file)
@@ -1,3 +1,3 @@
-static char    SccsId[] = "@(#)SendMail version 3.3 of %G%";
+static char    SccsId[] = "@(#)SendMail version 3.4 of %G%";
 
 
-char   Version[] = "3.3 [%G%]";
+char   Version[] = "3.4 [%G%]";