(no message)
[unix-history] / usr / src / usr.sbin / sendmail / src / envelope.c
index b584bc7..29a2531 100644 (file)
@@ -1,9 +1,9 @@
 #include <pwd.h>
 #include <pwd.h>
-#include <time.h>
+#include <sys/time.h>
 #include "sendmail.h"
 #include <sys/stat.h>
 
 #include "sendmail.h"
 #include <sys/stat.h>
 
-SCCSID(@(#)envelope.c  3.1             %G%);
+SCCSID(@(#)envelope.c  3.16            %G%);
 
 /*
 **  NEWENVELOPE -- allocate a new envelope
 
 /*
 **  NEWENVELOPE -- allocate a new envelope
@@ -108,24 +108,17 @@ dropenvelope(e)
 
        if (e->e_receiptto != NULL && bitset(EF_SENDRECEIPT, e->e_flags))
        {
 
        if (e->e_receiptto != NULL && bitset(EF_SENDRECEIPT, e->e_flags))
        {
-               auto ADDRESS *rlist;
+               auto ADDRESS *rlist = NULL;
 
 
-               sendto(CurEnv->e_receiptto, (ADDRESS *) NULL, &rlist);
+               sendtolist(CurEnv->e_receiptto, (ADDRESS *) NULL, &rlist);
                (void) returntosender("Return receipt", rlist, FALSE);
        }
 
                (void) returntosender("Return receipt", rlist, FALSE);
        }
 
-       /*
-       **  See if this message has timed out
-       */
-
-       if (bitset(EF_TIMEOUT, e->e_flags) && queueit)
-               timeout(e);
-
        /*
        **  Arrange to send error messages if there are fatal errors.
        */
 
        /*
        **  Arrange to send error messages if there are fatal errors.
        */
 
-       if (bitset(EF_FATALERRS, e->e_flags))
+       if (bitset(EF_FATALERRS|EF_TIMEOUT, e->e_flags) && ErrorMode != EM_QUIET)
                savemail(e);
 
        /*
                savemail(e);
 
        /*
@@ -142,16 +135,21 @@ dropenvelope(e)
                xunlink(queuename(e, 'q'));
        }
        else if (queueit || !bitset(EF_INQUEUE, e->e_flags))
                xunlink(queuename(e, 'q'));
        }
        else if (queueit || !bitset(EF_INQUEUE, e->e_flags))
+       {
+#ifdef QUEUE
                queueup(e, FALSE, FALSE);
                queueup(e, FALSE, FALSE);
+#else QUEUE
+               syserr("dropenvelope: queueup");
+#endif QUEUE
+       }
 
        /* now unlock the job */
 
        /* now unlock the job */
-       if (e->e_xfp != NULL)
-               (void) fclose(e->e_xfp);
+       closexscript(e);
        unlockqueue(e);
 
        /* make sure that this envelope is marked unused */
        e->e_id = e->e_df = NULL;
        unlockqueue(e);
 
        /* make sure that this envelope is marked unused */
        e->e_id = e->e_df = NULL;
-       e->e_dfp = e->e_xfp = NULL;
+       e->e_dfp = NULL;
 }
 \f/*
 **  CLEARENVELOPE -- clear an envelope without unlocking
 }
 \f/*
 **  CLEARENVELOPE -- clear an envelope without unlocking
@@ -204,12 +202,18 @@ unlockqueue(e)
 {
        /* remove the transcript */
 #ifdef DEBUG
 {
        /* remove the transcript */
 #ifdef DEBUG
+# ifdef LOG
+       if (LogLevel > 19)
+               syslog(LOG_DEBUG, "%s: unlock", e->e_id);
+# endif LOG
        if (!tTd(51, 4))
 #endif DEBUG
                xunlink(queuename(e, 'x'));
 
        if (!tTd(51, 4))
 #endif DEBUG
                xunlink(queuename(e, 'x'));
 
+# ifdef QUEUE
        /* last but not least, remove the lock */
        xunlink(queuename(e, 'l'));
        /* last but not least, remove the lock */
        xunlink(queuename(e, 'l'));
+# endif QUEUE
 }
 \f/*
 **  INITSYS -- initialize instantiation of system
 }
 \f/*
 **  INITSYS -- initialize instantiation of system
@@ -230,17 +234,11 @@ unlockqueue(e)
 
 initsys()
 {
 
 initsys()
 {
-       auto time_t now;
        static char cbuf[5];                    /* holds hop count */
        static char cbuf[5];                    /* holds hop count */
-       static char dbuf[30];                   /* holds ctime(tbuf) */
        static char pbuf[10];                   /* holds pid */
        static char pbuf[10];                   /* holds pid */
-       static char tbuf[20];                   /* holds "current" time */
        static char ybuf[10];                   /* holds tty id */
        register char *p;
        static char ybuf[10];                   /* holds tty id */
        register char *p;
-       register struct tm *tm;
        extern char *ttyname();
        extern char *ttyname();
-       extern char *arpadate();
-       extern struct tm *gmtime();
        extern char *macvalue();
        extern char Version[];
 
        extern char *macvalue();
        extern char Version[];
 
@@ -275,22 +273,7 @@ initsys()
        define('c', cbuf, CurEnv);
 
        /* time as integer, unix time, arpa time */
        define('c', cbuf, CurEnv);
 
        /* time as integer, unix time, arpa time */
-       now = curtime();
-       tm = gmtime(&now);
-       (void) sprintf(tbuf, "%02d%02d%02d%02d%02d", tm->tm_year, tm->tm_mon,
-                       tm->tm_mday, tm->tm_hour, tm->tm_min);
-       define('t', tbuf, CurEnv);
-       (void) strcpy(dbuf, ctime(&now));
-       *index(dbuf, '\n') = '\0';
-       if (macvalue('d', CurEnv) == NULL)
-               define('d', dbuf, CurEnv);
-       p = newstr(arpadate(dbuf));
-       if (macvalue('a', CurEnv) == NULL)
-               define('a', p, CurEnv);
-       define('b', p, CurEnv);
-
-       /* version */
-       define('v', Version, CurEnv);
+       settime();
 
        /* tty name */
        if (macvalue('y', CurEnv) == NULL)
 
        /* tty name */
        if (macvalue('y', CurEnv) == NULL)
@@ -306,6 +289,44 @@ initsys()
        }
 }
 \f/*
        }
 }
 \f/*
+**  SETTIME -- set the current time.
+**
+**     Parameters:
+**             none.
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             Sets the various time macros -- $a, $b, $d, $t.
+*/
+
+settime()
+{
+       register char *p;
+       auto time_t now;
+       static char tbuf[20];                   /* holds "current" time */
+       static char dbuf[30];                   /* holds ctime(tbuf) */
+       register struct tm *tm;
+       extern char *arpadate();
+       extern struct tm *gmtime();
+       extern char *macvalue();
+
+       now = curtime();
+       tm = gmtime(&now);
+       (void) sprintf(tbuf, "%02d%02d%02d%02d%02d", tm->tm_year, tm->tm_mon+1,
+                       tm->tm_mday, tm->tm_hour, tm->tm_min);
+       define('t', tbuf, CurEnv);
+       (void) strcpy(dbuf, ctime(&now));
+       *index(dbuf, '\n') = '\0';
+       if (macvalue('d', CurEnv) == NULL)
+               define('d', dbuf, CurEnv);
+       p = newstr(arpadate(dbuf));
+       if (macvalue('a', CurEnv) == NULL)
+               define('a', p, CurEnv);
+       define('b', p, CurEnv);
+}
+\f/*
 **  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.
@@ -374,6 +395,7 @@ queuename(e, type)
                        if (tTd(7, 20))
                                printf("queuename: trying \"%s\"\n", nf);
 # endif DEBUG
                        if (tTd(7, 20))
                                printf("queuename: trying \"%s\"\n", nf);
 # endif DEBUG
+# ifdef QUEUE
                        if (access(lf, 0) >= 0 || access(qf, 0) >= 0)
                                continue;
                        errno = 0;
                        if (access(lf, 0) >= 0 || access(qf, 0) >= 0)
                                continue;
                        errno = 0;
@@ -391,6 +413,10 @@ queuename(e, type)
                        if (link(lf, qf) >= 0)
                                break;
                        (void) unlink(lf);
                        if (link(lf, qf) >= 0)
                                break;
                        (void) unlink(lf);
+# else QUEUE
+                       if (close(creat(qf, FileMode)) < 0)
+                               continue;
+# endif QUEUE
                }
                if (c1 >= '~' && c2 >= 'Z')
                {
                }
                if (c1 >= '~' && c2 >= 'Z')
                {
@@ -403,6 +429,10 @@ queuename(e, type)
 # ifdef DEBUG
                if (tTd(7, 1))
                        printf("queuename: assigned id %s, env=%x\n", e->e_id, e);
 # ifdef DEBUG
                if (tTd(7, 1))
                        printf("queuename: assigned id %s, env=%x\n", e->e_id, e);
+# ifdef LOG
+               if (LogLevel > 16)
+                       syslog(LOG_DEBUG, "%s: assigned id", e->e_id);
+# endif LOG
 # endif DEBUG
        }
 
 # endif DEBUG
        }
 
@@ -436,6 +466,10 @@ openxscript(e)
 {
        register char *p;
 
 {
        register char *p;
 
+# ifdef LOG
+       if (LogLevel > 19)
+               syslog(LOG_DEBUG, "%s: openx%s", e->e_id, e->e_xfp == NULL ? "" : " (no)");
+# endif LOG
        if (e->e_xfp != NULL)
                return;
        p = queuename(e, 'x');
        if (e->e_xfp != NULL)
                return;
        p = queuename(e, 'x');
@@ -446,6 +480,27 @@ openxscript(e)
                (void) chmod(p, 0644);
 }
 \f/*
                (void) chmod(p, 0644);
 }
 \f/*
+**  CLOSEXSCRIPT -- close the transcript file.
+**
+**     Parameters:
+**             e -- the envelope containing the transcript to close.
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             none.
+*/
+
+closexscript(e)
+       register ENVELOPE *e;
+{
+       if (e->e_xfp == NULL)
+               return;
+       (void) fclose(e->e_xfp);
+       e->e_xfp = NULL;
+}
+\f/*
 **  SETSENDER -- set the person who this message is from
 **
 **     Under certain circumstances allow the user to say who
 **  SETSENDER -- set the person who this message is from
 **
 **     Under certain circumstances allow the user to say who
@@ -540,13 +595,15 @@ setsender(from)
                        /* syserr("%s, you cannot use the -f flag", realname); */
                        from = NULL;
                }
                        /* syserr("%s, you cannot use the -f flag", realname); */
                        from = NULL;
                }
+               else if (strcmp(from, realname) != 0)
+                       pw = NULL;
        }
 
        SuprErrs = TRUE;
        }
 
        SuprErrs = TRUE;
-       if (from == NULL || parse(from, &CurEnv->e_from, 1) == NULL)
+       if (from == NULL || parseaddr(from, &CurEnv->e_from, 1, '\0') == NULL)
        {
                from = newstr(realname);
        {
                from = newstr(realname);
-               (void) parse(from, &CurEnv->e_from, 1);
+               (void) parseaddr(from, &CurEnv->e_from, 1, '\0');
        }
        else
                FromFlag = TRUE;
        }
        else
                FromFlag = TRUE;
@@ -569,6 +626,10 @@ setsender(from)
                /* extract home directory */
                CurEnv->e_from.q_home = newstr(pw->pw_dir);
 
                /* extract home directory */
                CurEnv->e_from.q_home = newstr(pw->pw_dir);
 
+               /* extract user and group id */
+               CurEnv->e_from.q_uid = pw->pw_uid;
+               CurEnv->e_from.q_gid = pw->pw_gid;
+
                /* run user's .mailcf file */
                define('z', CurEnv->e_from.q_home, CurEnv);
                expand("$z/.mailcf", buf, &buf[sizeof buf - 1], CurEnv);
                /* run user's .mailcf file */
                define('z', CurEnv->e_from.q_home, CurEnv);
                expand("$z/.mailcf", buf, &buf[sizeof buf - 1], CurEnv);
@@ -578,11 +639,12 @@ setsender(from)
                /* if the user has given fullname already, don't redefine */
                if (FullName == NULL)
                        FullName = macvalue('x', CurEnv);
                /* if the user has given fullname already, don't redefine */
                if (FullName == NULL)
                        FullName = macvalue('x', CurEnv);
-               if (FullName[0] == '\0')
+               if (FullName != NULL && FullName[0] == '\0')
                        FullName = NULL;
 
                /* extract full name from passwd file */
                        FullName = NULL;
 
                /* extract full name from passwd file */
-               if (FullName == NULL && pw->pw_gecos != NULL)
+               if (FullName == NULL && pw->pw_gecos != NULL &&
+                   strcmp(pw->pw_name, CurEnv->e_from.q_user) == 0)
                {
                        buildfname(pw->pw_gecos, CurEnv->e_from.q_user, buf);
                        if (buf[0] != '\0')
                {
                        buildfname(pw->pw_gecos, CurEnv->e_from.q_user, buf);
                        if (buf[0] != '\0')
@@ -591,13 +653,16 @@ setsender(from)
                if (FullName != NULL)
                        define('x', FullName, CurEnv);
        }
                if (FullName != NULL)
                        define('x', FullName, CurEnv);
        }
-
+       else
+       {
 #ifndef V6
 #ifndef V6
-       if (CurEnv->e_from.q_home == NULL)
-               CurEnv->e_from.q_home = getenv("HOME");
+               if (CurEnv->e_from.q_home == NULL)
+                       CurEnv->e_from.q_home = getenv("HOME");
 #endif V6
 #endif V6
-       CurEnv->e_from.q_uid = getuid();
-       CurEnv->e_from.q_gid = getgid();
+               CurEnv->e_from.q_uid = getuid();
+               CurEnv->e_from.q_gid = getgid();
+       }
+
        if (CurEnv->e_from.q_uid != 0)
        {
                DefUid = CurEnv->e_from.q_uid;
        if (CurEnv->e_from.q_uid != 0)
        {
                DefUid = CurEnv->e_from.q_uid;
@@ -617,11 +682,12 @@ setsender(from)
        }
        rewrite(pvp, 3);
        rewrite(pvp, 1);
        }
        rewrite(pvp, 3);
        rewrite(pvp, 1);
+       rewrite(pvp, 4);
        cataddr(pvp, buf, sizeof buf);
        define('f', newstr(buf), CurEnv);
 
        /* save the domain spec if this mailer wants it */
        cataddr(pvp, buf, sizeof buf);
        define('f', newstr(buf), CurEnv);
 
        /* save the domain spec if this mailer wants it */
-       if (bitset(M_CANONICAL, CurEnv->e_from.q_mailer->m_flags))
+       if (bitnset(M_CANONICAL, CurEnv->e_from.q_mailer->m_flags))
        {
                extern char **copyplist();
 
        {
                extern char **copyplist();