completely instantiate queue files for all mail, even if not needed;
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Mon, 27 Sep 1982 06:46:21 +0000 (22:46 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Mon, 27 Sep 1982 06:46:21 +0000 (22:46 -0800)
fix a bug that would probably come up once every ten years in creating
the queue id.  should merge argv flag processing with option processing.

SCCS-vsn: usr.sbin/sendmail/src/main.c 3.117
SCCS-vsn: usr.sbin/sendmail/src/conf.c 3.58
SCCS-vsn: usr.sbin/sendmail/src/deliver.c 3.117
SCCS-vsn: usr.sbin/sendmail/src/sendmail.h 3.90
SCCS-vsn: usr.sbin/sendmail/src/version.c 3.206
SCCS-vsn: usr.sbin/sendmail/src/util.c 3.32
SCCS-vsn: usr.sbin/sendmail/src/queue.c 3.45
SCCS-vsn: usr.sbin/sendmail/src/readcf.c 3.34

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

index e5fed2b..b93dbe7 100644 (file)
@@ -36,7 +36,7 @@
 
 
 
 
 
 
-SCCSID(@(#)conf.c      3.57            %G%);
+SCCSID(@(#)conf.c      3.58            %G%);
 \f/*
 **  Header info table
 **     Final (null) entry contains the flags used for any other field.
 \f/*
 **  Header info table
 **     Final (null) entry contains the flags used for any other field.
@@ -123,6 +123,7 @@ int DefGid =        1;              /* ditto for gid */
 time_t TimeOut =       3*24*60*60L;    /* default timeout for queue files */
 int    ReadTimeout =   10*60;          /* timeout on external reads */
 int    LogLevel =      9;              /* default logging level */
 time_t TimeOut =       3*24*60*60L;    /* default timeout for queue files */
 int    ReadTimeout =   10*60;          /* timeout on external reads */
 int    LogLevel =      9;              /* default logging level */
+bool   SuperSafe =     TRUE;           /* always create qf file */
 
 
 
 
 
 
index 15b946a..cb4449c 100644 (file)
@@ -3,7 +3,7 @@
 # include "sendmail.h"
 # include <sys/stat.h>
 
 # include "sendmail.h"
 # include <sys/stat.h>
 
-SCCSID(@(#)deliver.c   3.116           %G%);
+SCCSID(@(#)deliver.c   3.117           %G%);
 
 /*
 **  DELIVER -- Deliver a message to a list of addresses.
 
 /*
 **  DELIVER -- Deliver a message to a list of addresses.
@@ -1533,6 +1533,8 @@ checkerrors(e)
                {
 # ifdef QUEUE
                        queueup(e, FALSE);
                {
 # ifdef QUEUE
                        queueup(e, FALSE);
+                       e->e_df = e->e_qf = NULL;
+                       e->e_dontqueue = TRUE;
 # else QUEUE
                        syserr("checkerrors: trying to queue %s", e->e_df);
 # endif QUEUE
 # else QUEUE
                        syserr("checkerrors: trying to queue %s", e->e_df);
 # endif QUEUE
index 6f9764d..ef49783 100644 (file)
@@ -6,7 +6,7 @@
 # include "sendmail.h"
 # include <sys/stat.h>
 
 # include "sendmail.h"
 # include <sys/stat.h>
 
-SCCSID(@(#)main.c      3.116           %G%);
+SCCSID(@(#)main.c      3.117           %G%);
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
@@ -633,6 +633,10 @@ main(argc, argv)
        **              slower than it must be.
        */
 
        **              slower than it must be.
        */
 
+       if (Mode == MD_QUEUE || Mode == MD_FORK ||
+           (Mode != MD_VERIFY && SuperSafe))
+               queueup(CurEnv, TRUE);
+
        if (Mode == MD_FORK)
        {
                if (fork() > 0)
        if (Mode == MD_FORK)
        {
                if (fork() > 0)
@@ -647,7 +651,8 @@ main(argc, argv)
        }
        else if (Mode == MD_QUEUE)
        {
        }
        else if (Mode == MD_QUEUE)
        {
-               queueup(CurEnv, TRUE);
+               CurEnv->e_df = CurEnv->e_qf = NULL;
+               CurEnv->e_dontqueue = TRUE;
                finis();
        }
 
                finis();
        }
 
@@ -1213,6 +1218,11 @@ dropenvelope(e)
 **  QUEUENAME -- build a file name in the queue directory for this envelope.
 **
 **     Assigns an id code if one does not already exist.
 **  QUEUENAME -- build a file name in the queue directory for this envelope.
 **
 **     Assigns an id code if one does not already exist.
+**     This code is very careful to avoid trashing existing files
+**     under any circumstances.
+**             We first create an xf file that is only used when
+**             assigning an id.  This file is always empty, so that
+**             we can never accidently truncate an lf file.
 **
 **     Parameters:
 **             e -- envelope to build it in/from.
 **
 **     Parameters:
 **             e -- envelope to build it in/from.
@@ -1240,35 +1250,41 @@ queuename(e, type)
                char counter = 'A' - 1;
                char qf[20];
                char lf[20];
                char counter = 'A' - 1;
                char qf[20];
                char lf[20];
+               char xf[20];
 
                /* find a unique id */
                (void) sprintf(qf, "qf_%05d", getpid());
                strcpy(lf, qf);
                lf[0] = 'l';
 
                /* find a unique id */
                (void) sprintf(qf, "qf_%05d", getpid());
                strcpy(lf, qf);
                lf[0] = 'l';
+               strcpy(xf, qf);
+               xf[0] = 'x';
 
                while (counter < '~')
                {
 
                while (counter < '~')
                {
-                       int fd;
+                       int i;
 
 
-                       qf[2] = lf[2] = ++counter;
+                       qf[2] = lf[2] = xf[2] = ++counter;
 # ifdef DEBUG
                        if (tTd(7, 20))
 # ifdef DEBUG
                        if (tTd(7, 20))
-                               printf("queuename: trying \"%s\"\n", lf);
+                               printf("queuename: trying \"%s\"\n", xf);
 # endif DEBUG
                        if (access(lf, 0) >= 0 || access(qf, 0) >= 0)
                                continue;
                        errno = 0;
 # endif DEBUG
                        if (access(lf, 0) >= 0 || access(qf, 0) >= 0)
                                continue;
                        errno = 0;
-                       fd = creat(lf, 0600);
-                       if (fd < 0)
+                       i = creat(xf, 0600);
+                       if (i < 0)
                        {
                        {
-                               (void) unlink(lf);      /* kernel bug on ENFILE */
+                               (void) unlink(xf);      /* kernel bug */
                                continue;
                        }
                                continue;
                        }
-                       (void) close(fd);
-                       if (link(lf, qf) < 0)
-                               (void) unlink(lf);
-                       else
+                       (void) close(i);
+                       i = link(xf, lf);
+                       (void) unlink(xf);
+                       if (i < 0)
+                               continue;
+                       if (link(lf, qf) >= 0)
                                break;
                                break;
+                       (void) unlink(lf);
                }
                if (counter >= '~')
                {
                }
                if (counter >= '~')
                {
index 3b32a04..103ebe6 100644 (file)
@@ -5,10 +5,10 @@
 # include <errno.h>
 
 # ifndef QUEUE
 # include <errno.h>
 
 # ifndef QUEUE
-SCCSID(@(#)queue.c     3.44            %G%     (no queueing));
+SCCSID(@(#)queue.c     3.45            %G%     (no queueing));
 # else QUEUE
 
 # else QUEUE
 
-SCCSID(@(#)queue.c     3.44            %G%);
+SCCSID(@(#)queue.c     3.45            %G%);
 
 /*
 **  QUEUEUP -- queue a message up for future transmission.
 
 /*
 **  QUEUEUP -- queue a message up for future transmission.
@@ -158,17 +158,12 @@ queueup(e, queueall)
                syserr("cannot link(%s, %s), df=%s", tf, qf, e->e_df);
        else
                (void) unlink(tf);
                syserr("cannot link(%s, %s), df=%s", tf, qf, e->e_df);
        else
                (void) unlink(tf);
-       e->e_qf = NULL;
 
 # ifdef LOG
        /* save log info */
        if (LogLevel > 15)
                syslog(LOG_DEBUG, "%s: queueup, qf=%s, df=%s\n", e->e_id, qf, e->e_df);
 # endif LOG
 
 # ifdef LOG
        /* save log info */
        if (LogLevel > 15)
                syslog(LOG_DEBUG, "%s: queueup, qf=%s, df=%s\n", e->e_id, qf, e->e_df);
 # endif LOG
-
-       /* disconnect this temp file from the job; don't requeue later */
-       e->e_df = NULL;
-       e->e_dontqueue = TRUE;
 }
 \f/*
 **  RUNQUEUE -- run the jobs in the queue.
 }
 \f/*
 **  RUNQUEUE -- run the jobs in the queue.
index 2b94efb..65b9098 100644 (file)
@@ -1,6 +1,6 @@
 # include "sendmail.h"
 
 # include "sendmail.h"
 
-SCCSID(@(#)readcf.c    3.33            %G%);
+SCCSID(@(#)readcf.c    3.34            %G%);
 
 /*
 **  READCF -- read control file.
 
 /*
 **  READCF -- read control file.
@@ -530,7 +530,9 @@ setoption(opt, val)
 {
        time_t tval;
        int ival;
 {
        time_t tval;
        int ival;
+       bool bval;
        extern char *HelpFile;                  /* defined in conf.c */
        extern char *HelpFile;                  /* defined in conf.c */
+       extern bool atobool();
 
 # ifdef DEBUG
        if (tTd(37, 1))
 
 # ifdef DEBUG
        if (tTd(37, 1))
@@ -545,6 +547,8 @@ setoption(opt, val)
                tval = convtime(val);
        else if (index("gLu", opt) != NULL)
                ival = atoi(val);
                tval = convtime(val);
        else if (index("gLu", opt) != NULL)
                ival = atoi(val);
+       else if (index("s", opt) != NULL)
+               bval = atobool(val);
        else if (val[0] == '\0')
                val = "";
        else
        else if (val[0] == '\0')
                val = "";
        else
@@ -560,12 +564,6 @@ setoption(opt, val)
                AliasFile = val;
                break;
 
                AliasFile = val;
                break;
 
-# ifdef V6
-         case 'd':             /* dst timezone name */
-               DstTimeZone = val;
-               break;
-# endif V6
-
          case 'g':             /* default gid */
                DefGid = ival;
                break;
          case 'g':             /* default gid */
                DefGid = ival;
                break;
@@ -590,16 +588,24 @@ setoption(opt, val)
                StatFile = val;
                break;
 
                StatFile = val;
                break;
 
-# ifdef V6
-         case 's':             /* standard time time zone */
-               StdTimeZone = val;
+         case 's':             /* be super safe, even if expensive */
+               SuperSafe = bval;
                break;
                break;
-# endif V6
 
          case 'T':             /* queue timeout */
                TimeOut = tval;
                break;
 
 
          case 'T':             /* queue timeout */
                TimeOut = tval;
                break;
 
+         case 't':             /* time zone name */
+# ifdef V6
+               StdTimezone = val;
+               DstTimezone = index(val, ',');
+               if (DstTimezone == NULL)
+                       goto syntax;
+               *DstTimezone++ = '\0';
+# endif V6
+               break;
+
          case 'u':             /* set default uid */
                DefUid = ival;
                break;
          case 'u':             /* set default uid */
                DefUid = ival;
                break;
@@ -609,7 +615,9 @@ setoption(opt, val)
                break;
 
          default:
                break;
 
          default:
-               syserr("setoption: line %d: illegal option %c", LineNumber, opt);
+         syntax:
+               syserr("setoption: line %d: syntax error on \"%c%s\"",
+                      LineNumber, opt, val);
                break;
        }
 }
                break;
        }
 }
index 189e5cc..b420f45 100644 (file)
@@ -7,7 +7,7 @@
 # ifdef _DEFINE
 # define EXTERN
 # ifndef lint
 # ifdef _DEFINE
 # define EXTERN
 # ifndef lint
-static char SmailSccsId[] =    "@(#)sendmail.h 3.89            %G%";
+static char SmailSccsId[] =    "@(#)sendmail.h 3.90            %G%";
 # endif lint
 # else  _DEFINE
 # define EXTERN extern
 # endif lint
 # else  _DEFINE
 # define EXTERN extern
@@ -405,6 +405,7 @@ EXTERN bool HoldErrs;       /* only output errors to transcript */
 EXTERN bool    ArpaMode;       /* set if running arpanet protocol */
 EXTERN bool    NoConnect;      /* don't connect to non-local mailers */
 EXTERN bool    FatalErrors;    /* set if fatal errors during processing */
 EXTERN bool    ArpaMode;       /* set if running arpanet protocol */
 EXTERN bool    NoConnect;      /* don't connect to non-local mailers */
 EXTERN bool    FatalErrors;    /* set if fatal errors during processing */
+extern bool    SuperSafe;      /* be extra careful, despite cost [conf.c] */
 extern time_t  TimeOut;        /* time until timeout [conf.c] */
 EXTERN FILE    *InChannel;     /* input connection */
 EXTERN FILE    *OutChannel;    /* output connection */
 extern time_t  TimeOut;        /* time until timeout [conf.c] */
 EXTERN FILE    *InChannel;     /* input connection */
 EXTERN FILE    *OutChannel;    /* output connection */
index 9e6a255..a7a4b33 100644 (file)
@@ -8,7 +8,7 @@
 # include "sendmail.h"
 # include "conf.h"
 
 # include "sendmail.h"
 # include "conf.h"
 
-SCCSID(@(#)util.c      3.31            %G%);
+SCCSID(@(#)util.c      3.32            %G%);
 
 /*
 **  STRIPQUOTES -- Strip quotes & quote bits from a string.
 
 /*
 **  STRIPQUOTES -- Strip quotes & quote bits from a string.
@@ -791,3 +791,27 @@ curtime()
        (void) time(&t);
        return (t);
 }
        (void) time(&t);
        return (t);
 }
+\f/*
+**  ATOBOOL -- convert a string representation to boolean.
+**
+**     Defaults to "TRUE"
+**
+**     Parameters:
+**             s -- string to convert.  Takes "tTyY" as true,
+**                     others as false.
+**
+**     Returns:
+**             A boolean representation of the string.
+**
+**     Side Effects:
+**             none.
+*/
+
+bool
+atobool(s)
+       register char *s;
+{
+       if (*s == '\0' || index("tTyY", *s) != NULL)
+               return (TRUE);
+       return (FALSE);
+}
index fa80cba..0c6f042 100644 (file)
@@ -1,5 +1,5 @@
 # ifndef lint
 # ifndef lint
-static char    SccsId[] = "@(#)SendMail version 3.205 of %G%";
+static char    SccsId[] = "@(#)SendMail version 3.206 of %G%";
 # endif lint
 
 # endif lint
 
-char   Version[] = "3.205 [%G%]";
+char   Version[] = "3.206 [%G%]";