- CurEnv->e_df = CurEnv->e_qf = NULL;
- finis();
-}
-\f/*
-** OPENXSCRPT -- Open transcript file
-**
-** Creates a transcript file for possible eventual mailing or
-** sending back.
-**
-** Parameters:
-** none
-**
-** Returns:
-** none
-**
-** Side Effects:
-** Open the transcript file.
-*/
-
-openxscrpt()
-{
- register char *p;
-
- p = queuename(CurEnv, 'x');
- Xscript = fopen(p, "w");
- if (Xscript == NULL)
- {
- Xscript = stdout;
- syserr("Can't create %s", p);
- }
- (void) chmod(p, 0644);
- Transcript = newstr(p);
-}
-\f/*
-** SETSENDER -- set sendmail's idea of the sender.
-**
-** Parameters:
-** from -- the person we would like to believe this
-** is from.
-**
-** Returns:
-** none.
-**
-** Side Effects:
-** Sets the idea of the sender.
-*/
-
-setsender(from)
- char *from;
-{
- register char *p;
- extern char *getlogin();
- register struct passwd *pw;
- char *realname;
- char cfbuf[40];
- bool nofullname;
- extern char *macvalue();
-
- /*
- ** Figure out the real user executing us.
- ** Getlogin can return errno != 0 on non-errors.
- */
-
- if (OpMode != MD_SMTP && !QueueRun)
- {
- errno = 0;
- p = getlogin();
- errno = 0;
- nofullname = (from != NULL);
- }
- else
- {
- p = from;
- nofullname = FALSE;
- }
- if (p != NULL && p[0] != '\0')
- {
- extern struct passwd *getpwnam();
-
- pw = getpwnam(p);
- if (pw == NULL)
- {
- if (OpMode != MD_SMTP && !QueueRun)
- syserr("Who are you? (name=%s)", p);
- p = NULL;
- }
- }
- if (p == NULL || p[0] == '\0')
- {
- extern struct passwd *getpwuid();
- int uid;
-
- nofullname = TRUE;
- uid = getruid();
- pw = getpwuid(uid);
- if (pw == NULL)
- syserr("Who are you? (uid=%d)", uid);
- else
- p = pw->pw_name;
- }
- if (p == NULL || p[0] == '\0' || pw == NULL)
- finis();
-
- realname = p;
-
- /*
- ** Process passwd file entry.
- */
-
- /* run user's .mailcf file */
- define('z', pw->pw_dir);
- expand("$z/.mailcf", cfbuf, &cfbuf[sizeof cfbuf - 1], CurEnv);
- if (!nofullname && safefile(cfbuf, getruid(), S_IREAD))
- readcf(cfbuf, FALSE);
-
- /* if the user has given fullname already, don't redefine */
- if (FullName == NULL)
- FullName = macvalue('x', CurEnv);
-
- /* extract full name from passwd file */
- if (!nofullname && (FullName == NULL || FullName[0] == '\0') &&
- pw != NULL && pw->pw_gecos != NULL)
- {
- char nbuf[MAXNAME];
-
- fullname(pw, nbuf);
- if (nbuf[0] != '\0')
- FullName = newstr(nbuf);
- }
- if (FullName != NULL && FullName[0] != '\0')
- define('x', FullName);
-
- setfrom(from, realname);
-}
-\f/*
-** INITSYS -- initialize instantiation of system
-**
-** In Daemon mode, this is done in the child.
-**
-** Parameters:
-** none.
-**
-** Returns:
-** none.
-**
-** Side Effects:
-** Initializes the system macros, some global variables,
-** etc. In particular, the current time in various
-** forms is set.
-*/
-
-initsys()
-{
- static char cbuf[5]; /* holds hop count */
- static char dbuf[30]; /* holds ctime(tbuf) */
- static char pbuf[10]; /* holds pid */
- static char tbuf[20]; /* holds "current" time */
- static char ybuf[10]; /* holds tty id */
- register char *p;
- extern char *ttyname();
- extern char *arpadate();
- register struct tm *tm;
- extern struct tm *gmtime();
- auto time_t now;
-
- /*
- ** Give this envelope a reality.
- ** I.e., an id, a transcript, and a creation time.
- */
-
- openxscrpt();
- CurEnv->e_ctime = curtime();
-
- /*
- ** Set OutChannel to something useful if stdout isn't it.
- ** This arranges that any extra stuff the mailer produces
- ** gets sent back to the user on error (because it is
- ** tucked away in the transcript).
- */
-
- if (OpMode == MD_DAEMON && QueueRun)
- OutChannel = Xscript;
-
- /*
- ** Set up some basic system macros.
- */
-
- /* process id */
- (void) sprintf(pbuf, "%d", getpid());
- define('p', pbuf);
-
- /* hop count */
- (void) sprintf(cbuf, "%d", HopCount);
- define('c', cbuf);
-
- /* 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);
- (void) strcpy(dbuf, ctime(&now));
- *index(dbuf, '\n') = '\0';
- if (macvalue('d', CurEnv) == NULL)
- define('d', dbuf);
- p = newstr(arpadate(dbuf));
- if (macvalue('a', CurEnv) == NULL)
- define('a', p);
- define('b', p);
-
- /* version */
- define('v', Version);
-
- /* tty name */
- if (macvalue('y', CurEnv) == NULL)
- {
- p = ttyname(2);
- if (p != NULL)
- {
- if (rindex(p, '/') != NULL)
- p = rindex(p, '/') + 1;
- (void) strcpy(ybuf, p);
- define('y', ybuf);
- }
- }