(no message)
[unix-history] / usr / src / usr.sbin / sendmail / src / envelope.c
index f6c145f..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.13            %G%);
+SCCSID(@(#)envelope.c  3.16            %G%);
 
 /*
 **  NEWENVELOPE -- allocate a new envelope
 
 /*
 **  NEWENVELOPE -- allocate a new envelope
@@ -234,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[];
 
@@ -279,19 +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+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);
+       settime();
 
        /* tty name */
        if (macvalue('y', CurEnv) == NULL)
 
        /* tty name */
        if (macvalue('y', CurEnv) == NULL)
@@ -307,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.
@@ -606,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);
@@ -615,7 +639,7 @@ 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 */
@@ -629,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;