122704Sdist /*
234921Sbostic  * Copyright (c) 1983 Eric P. Allman
333729Sbostic  * Copyright (c) 1988 Regents of the University of California.
433729Sbostic  * All rights reserved.
533729Sbostic  *
633729Sbostic  * Redistribution and use in source and binary forms are permitted
734921Sbostic  * provided that the above copyright notice and this paragraph are
834921Sbostic  * duplicated in all such forms and that any documentation,
934921Sbostic  * advertising materials, and other materials related to such
1034921Sbostic  * distribution and use acknowledge that the software was developed
1134921Sbostic  * by the University of California, Berkeley.  The name of the
1234921Sbostic  * University may not be used to endorse or promote products derived
1334921Sbostic  * from this software without specific prior written permission.
1434921Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1534921Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1634921Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1733729Sbostic  */
1822704Sdist 
1922704Sdist #ifndef lint
20*40933Srick static char sccsid[] = "@(#)envelope.c	5.20 (Berkeley) 04/16/90";
2133729Sbostic #endif /* not lint */
2222704Sdist 
2336928Sbostic #include <sys/types.h>
2436928Sbostic #include <sys/time.h>
2536928Sbostic #include <sys/stat.h>
269536Seric #include <pwd.h>
27*40933Srick #include <sys/file.h>
289536Seric #include "sendmail.h"
299536Seric 
309536Seric /*
319536Seric **  NEWENVELOPE -- allocate a new envelope
329536Seric **
339536Seric **	Supports inheritance.
349536Seric **
359536Seric **	Parameters:
369536Seric **		e -- the new envelope to fill in.
379536Seric **
389536Seric **	Returns:
399536Seric **		e.
409536Seric **
419536Seric **	Side Effects:
429536Seric **		none.
439536Seric */
449536Seric 
459536Seric ENVELOPE *
469536Seric newenvelope(e)
479536Seric 	register ENVELOPE *e;
489536Seric {
499536Seric 	register ENVELOPE *parent;
509536Seric 	extern putheader(), putbody();
5125611Seric 	extern ENVELOPE BlankEnvelope;
529536Seric 
539536Seric 	parent = CurEnv;
549536Seric 	if (e == CurEnv)
559536Seric 		parent = e->e_parent;
5625611Seric 	clearenvelope(e, TRUE);
5724944Seric 	if (e == CurEnv)
5824944Seric 		bcopy((char *) &NullAddress, (char *) &e->e_from, sizeof e->e_from);
5924944Seric 	else
6024944Seric 		bcopy((char *) &CurEnv->e_from, (char *) &e->e_from, sizeof e->e_from);
619536Seric 	e->e_parent = parent;
629536Seric 	e->e_ctime = curtime();
6325014Seric 	e->e_msgpriority = parent->e_msgsize;
649536Seric 	e->e_puthdr = putheader;
659536Seric 	e->e_putbody = putbody;
669536Seric 	if (CurEnv->e_xfp != NULL)
679536Seric 		(void) fflush(CurEnv->e_xfp);
689536Seric 
699536Seric 	return (e);
709536Seric }
719536Seric /*
729536Seric **  DROPENVELOPE -- deallocate an envelope.
739536Seric **
749536Seric **	Parameters:
759536Seric **		e -- the envelope to deallocate.
769536Seric **
779536Seric **	Returns:
789536Seric **		none.
799536Seric **
809536Seric **	Side Effects:
819536Seric **		housekeeping necessary to dispose of an envelope.
829536Seric **		Unlocks this queue file.
839536Seric */
849536Seric 
859536Seric dropenvelope(e)
869536Seric 	register ENVELOPE *e;
879536Seric {
889536Seric 	bool queueit = FALSE;
899536Seric 	register ADDRESS *q;
909536Seric 
919536Seric 	if (tTd(50, 1))
929536Seric 	{
939536Seric 		printf("dropenvelope %x id=", e);
949536Seric 		xputs(e->e_id);
959536Seric 		printf(" flags=%o\n", e->e_flags);
969536Seric 	}
979536Seric #ifdef LOG
989536Seric 	if (LogLevel > 10)
999536Seric 		syslog(LOG_DEBUG, "dropenvelope, id=%s, flags=%o, pid=%d",
1009536Seric 				  e->e_id == NULL ? "(none)" : e->e_id,
1019536Seric 				  e->e_flags, getpid());
1029536Seric #endif LOG
1039536Seric 
1049536Seric 	/* we must have an id to remove disk files */
1059536Seric 	if (e->e_id == NULL)
1069536Seric 		return;
1079536Seric 
1089536Seric 	/*
1099536Seric 	**  Extract state information from dregs of send list.
1109536Seric 	*/
1119536Seric 
1129536Seric 	for (q = e->e_sendqueue; q != NULL; q = q->q_next)
1139536Seric 	{
1149536Seric 		if (bitset(QQUEUEUP, q->q_flags))
1159536Seric 			queueit = TRUE;
1169536Seric 	}
1179536Seric 
1189536Seric 	/*
1199536Seric 	**  Send back return receipts as requested.
1209536Seric 	*/
1219536Seric 
1229536Seric 	if (e->e_receiptto != NULL && bitset(EF_SENDRECEIPT, e->e_flags))
1239536Seric 	{
12410844Seric 		auto ADDRESS *rlist = NULL;
1259536Seric 
1269621Seric 		sendtolist(CurEnv->e_receiptto, (ADDRESS *) NULL, &rlist);
1279536Seric 		(void) returntosender("Return receipt", rlist, FALSE);
1289536Seric 	}
1299536Seric 
1309536Seric 	/*
1319536Seric 	**  Arrange to send error messages if there are fatal errors.
1329536Seric 	*/
1339536Seric 
13410754Seric 	if (bitset(EF_FATALERRS|EF_TIMEOUT, e->e_flags) && ErrorMode != EM_QUIET)
1359536Seric 		savemail(e);
1369536Seric 
1379536Seric 	/*
1389536Seric 	**  Instantiate or deinstantiate the queue.
1399536Seric 	*/
1409536Seric 
1419536Seric 	if ((!queueit && !bitset(EF_KEEPQUEUE, e->e_flags)) ||
1429536Seric 	    bitset(EF_CLRQUEUE, e->e_flags))
1439536Seric 	{
14423497Seric 		if (e->e_df != NULL)
14523497Seric 			xunlink(e->e_df);
1469536Seric 		xunlink(queuename(e, 'q'));
1479536Seric 	}
1489536Seric 	else if (queueit || !bitset(EF_INQUEUE, e->e_flags))
14910754Seric 	{
15010754Seric #ifdef QUEUE
151*40933Srick 		FILE *lockfp, *queueup();
152*40933Srick 		lockfp = queueup(e, FALSE, FALSE);
153*40933Srick 		if (lockfp != NULL)
154*40933Srick 			(void) fclose(lockfp);
15510754Seric #else QUEUE
15610754Seric 		syserr("dropenvelope: queueup");
15710754Seric #endif QUEUE
15810754Seric 	}
1599536Seric 
1609536Seric 	/* now unlock the job */
16110196Seric 	closexscript(e);
1629536Seric 	unlockqueue(e);
1639536Seric 
1649536Seric 	/* make sure that this envelope is marked unused */
1659536Seric 	e->e_id = e->e_df = NULL;
16624944Seric 	if (e->e_dfp != NULL)
16724944Seric 		(void) fclose(e->e_dfp);
16810196Seric 	e->e_dfp = NULL;
1699536Seric }
1709536Seric /*
1719536Seric **  CLEARENVELOPE -- clear an envelope without unlocking
1729536Seric **
1739536Seric **	This is normally used by a child process to get a clean
1749536Seric **	envelope without disturbing the parent.
1759536Seric **
1769536Seric **	Parameters:
1779536Seric **		e -- the envelope to clear.
17825611Seric **		fullclear - if set, the current envelope is total
17925611Seric **			garbage and should be ignored; otherwise,
18025611Seric **			release any resources it may indicate.
1819536Seric **
1829536Seric **	Returns:
1839536Seric **		none.
1849536Seric **
1859536Seric **	Side Effects:
1869536Seric **		Closes files associated with the envelope.
1879536Seric **		Marks the envelope as unallocated.
1889536Seric */
1899536Seric 
19025611Seric clearenvelope(e, fullclear)
1919536Seric 	register ENVELOPE *e;
19225611Seric 	bool fullclear;
1939536Seric {
19425514Seric 	register HDR *bh;
19525514Seric 	register HDR **nhp;
19625514Seric 	extern ENVELOPE BlankEnvelope;
19725514Seric 
19825611Seric 	if (!fullclear)
19925611Seric 	{
20025611Seric 		/* clear out any file information */
20125611Seric 		if (e->e_xfp != NULL)
20225611Seric 			(void) fclose(e->e_xfp);
20325611Seric 		if (e->e_dfp != NULL)
20425611Seric 			(void) fclose(e->e_dfp);
20525611Seric 	}
2069536Seric 
20724961Seric 	/* now clear out the data */
20824965Seric 	STRUCTCOPY(BlankEnvelope, *e);
20925514Seric 	bh = BlankEnvelope.e_header;
21025514Seric 	nhp = &e->e_header;
21125514Seric 	while (bh != NULL)
21225514Seric 	{
21325514Seric 		*nhp = (HDR *) xalloc(sizeof *bh);
21425514Seric 		bcopy((char *) bh, (char *) *nhp, sizeof *bh);
21525514Seric 		bh = bh->h_link;
21625514Seric 		nhp = &(*nhp)->h_link;
21725514Seric 	}
2189536Seric }
2199536Seric /*
2209536Seric **  INITSYS -- initialize instantiation of system
2219536Seric **
2229536Seric **	In Daemon mode, this is done in the child.
2239536Seric **
2249536Seric **	Parameters:
2259536Seric **		none.
2269536Seric **
2279536Seric **	Returns:
2289536Seric **		none.
2299536Seric **
2309536Seric **	Side Effects:
2319536Seric **		Initializes the system macros, some global variables,
2329536Seric **		etc.  In particular, the current time in various
2339536Seric **		forms is set.
2349536Seric */
2359536Seric 
2369536Seric initsys()
2379536Seric {
2389536Seric 	static char cbuf[5];			/* holds hop count */
2399536Seric 	static char pbuf[10];			/* holds pid */
24022963Smiriam #ifdef TTYNAME
2419536Seric 	static char ybuf[10];			/* holds tty id */
2429536Seric 	register char *p;
24322963Smiriam #endif TTYNAME
2449536Seric 	extern char *ttyname();
2459536Seric 	extern char *macvalue();
2469536Seric 	extern char Version[];
2479536Seric 
2489536Seric 	/*
2499536Seric 	**  Give this envelope a reality.
2509536Seric 	**	I.e., an id, a transcript, and a creation time.
2519536Seric 	*/
2529536Seric 
2539536Seric 	openxscript(CurEnv);
2549536Seric 	CurEnv->e_ctime = curtime();
2559536Seric 
2569536Seric 	/*
2579536Seric 	**  Set OutChannel to something useful if stdout isn't it.
2589536Seric 	**	This arranges that any extra stuff the mailer produces
2599536Seric 	**	gets sent back to the user on error (because it is
2609536Seric 	**	tucked away in the transcript).
2619536Seric 	*/
2629536Seric 
2639536Seric 	if (OpMode == MD_DAEMON && QueueRun)
2649536Seric 		OutChannel = CurEnv->e_xfp;
2659536Seric 
2669536Seric 	/*
2679536Seric 	**  Set up some basic system macros.
2689536Seric 	*/
2699536Seric 
2709536Seric 	/* process id */
2719536Seric 	(void) sprintf(pbuf, "%d", getpid());
2729536Seric 	define('p', pbuf, CurEnv);
2739536Seric 
2749536Seric 	/* hop count */
2759536Seric 	(void) sprintf(cbuf, "%d", CurEnv->e_hopcount);
2769536Seric 	define('c', cbuf, CurEnv);
2779536Seric 
2789536Seric 	/* time as integer, unix time, arpa time */
27911932Seric 	settime();
2809536Seric 
28117472Seric #ifdef TTYNAME
2829536Seric 	/* tty name */
2839536Seric 	if (macvalue('y', CurEnv) == NULL)
2849536Seric 	{
2859536Seric 		p = ttyname(2);
2869536Seric 		if (p != NULL)
2879536Seric 		{
2889536Seric 			if (rindex(p, '/') != NULL)
2899536Seric 				p = rindex(p, '/') + 1;
2909536Seric 			(void) strcpy(ybuf, p);
2919536Seric 			define('y', ybuf, CurEnv);
2929536Seric 		}
2939536Seric 	}
29417472Seric #endif TTYNAME
2959536Seric }
2969536Seric /*
29711932Seric **  SETTIME -- set the current time.
29811932Seric **
29911932Seric **	Parameters:
30011932Seric **		none.
30111932Seric **
30211932Seric **	Returns:
30311932Seric **		none.
30411932Seric **
30511932Seric **	Side Effects:
30611932Seric **		Sets the various time macros -- $a, $b, $d, $t.
30711932Seric */
30811932Seric 
30911932Seric settime()
31011932Seric {
31111932Seric 	register char *p;
31211932Seric 	auto time_t now;
31311932Seric 	static char tbuf[20];			/* holds "current" time */
31411932Seric 	static char dbuf[30];			/* holds ctime(tbuf) */
31511932Seric 	register struct tm *tm;
31611932Seric 	extern char *arpadate();
31711932Seric 	extern struct tm *gmtime();
31811932Seric 	extern char *macvalue();
31911932Seric 
32011932Seric 	now = curtime();
32111932Seric 	tm = gmtime(&now);
32211932Seric 	(void) sprintf(tbuf, "%02d%02d%02d%02d%02d", tm->tm_year, tm->tm_mon+1,
32311932Seric 			tm->tm_mday, tm->tm_hour, tm->tm_min);
32411932Seric 	define('t', tbuf, CurEnv);
32511932Seric 	(void) strcpy(dbuf, ctime(&now));
32611932Seric 	*index(dbuf, '\n') = '\0';
32711932Seric 	if (macvalue('d', CurEnv) == NULL)
32811932Seric 		define('d', dbuf, CurEnv);
32911932Seric 	p = newstr(arpadate(dbuf));
33011932Seric 	if (macvalue('a', CurEnv) == NULL)
33111932Seric 		define('a', p, CurEnv);
33211932Seric 	define('b', p, CurEnv);
33311932Seric }
33411932Seric /*
3359536Seric **  OPENXSCRIPT -- Open transcript file
3369536Seric **
3379536Seric **	Creates a transcript file for possible eventual mailing or
3389536Seric **	sending back.
3399536Seric **
3409536Seric **	Parameters:
3419536Seric **		e -- the envelope to create the transcript in/for.
3429536Seric **
3439536Seric **	Returns:
3449536Seric **		none
3459536Seric **
3469536Seric **	Side Effects:
3479536Seric **		Creates the transcript file.
3489536Seric */
3499536Seric 
3509536Seric openxscript(e)
3519536Seric 	register ENVELOPE *e;
3529536Seric {
3539536Seric 	register char *p;
354*40933Srick 	int fd;
3559536Seric 
35610196Seric # ifdef LOG
35710196Seric 	if (LogLevel > 19)
35810196Seric 		syslog(LOG_DEBUG, "%s: openx%s", e->e_id, e->e_xfp == NULL ? "" : " (no)");
35910196Seric # endif LOG
3609536Seric 	if (e->e_xfp != NULL)
3619536Seric 		return;
3629536Seric 	p = queuename(e, 'x');
363*40933Srick 	fd = open(p, O_WRONLY|O_CREAT, 0644);
364*40933Srick 	if (fd < 0)
3659536Seric 		syserr("Can't create %s", p);
3669536Seric 	else
367*40933Srick 		e->e_xfp = fdopen(fd, "w");
3689536Seric }
3699536Seric /*
37010196Seric **  CLOSEXSCRIPT -- close the transcript file.
37110196Seric **
37210196Seric **	Parameters:
37310196Seric **		e -- the envelope containing the transcript to close.
37410196Seric **
37510196Seric **	Returns:
37610196Seric **		none.
37710196Seric **
37810196Seric **	Side Effects:
37910196Seric **		none.
38010196Seric */
38110196Seric 
38210196Seric closexscript(e)
38310196Seric 	register ENVELOPE *e;
38410196Seric {
38510196Seric 	if (e->e_xfp == NULL)
38610196Seric 		return;
38710196Seric 	(void) fclose(e->e_xfp);
38810196Seric 	e->e_xfp = NULL;
38910196Seric }
39010196Seric /*
3919536Seric **  SETSENDER -- set the person who this message is from
3929536Seric **
3939536Seric **	Under certain circumstances allow the user to say who
3949536Seric **	s/he is (using -f or -r).  These are:
3959536Seric **	1.  The user's uid is zero (root).
3969536Seric **	2.  The user's login name is in an approved list (typically
3979536Seric **	    from a network server).
3989536Seric **	3.  The address the user is trying to claim has a
3999536Seric **	    "!" character in it (since #2 doesn't do it for
4009536Seric **	    us if we are dialing out for UUCP).
4019536Seric **	A better check to replace #3 would be if the
4029536Seric **	effective uid is "UUCP" -- this would require me
4039536Seric **	to rewrite getpwent to "grab" uucp as it went by,
4049536Seric **	make getname more nasty, do another passwd file
4059536Seric **	scan, or compile the UID of "UUCP" into the code,
4069536Seric **	all of which are reprehensible.
4079536Seric **
4089536Seric **	Assuming all of these fail, we figure out something
4099536Seric **	ourselves.
4109536Seric **
4119536Seric **	Parameters:
4129536Seric **		from -- the person we would like to believe this message
4139536Seric **			is from, as specified on the command line.
4149536Seric **
4159536Seric **	Returns:
4169536Seric **		none.
4179536Seric **
4189536Seric **	Side Effects:
4199536Seric **		sets sendmail's notion of who the from person is.
4209536Seric */
4219536Seric 
4229536Seric setsender(from)
4239536Seric 	char *from;
4249536Seric {
4259536Seric 	register char **pvp;
4269536Seric 	char *realname = NULL;
42718665Seric 	register struct passwd *pw;
4289536Seric 	char buf[MAXNAME];
42916913Seric 	char pvpbuf[PSBUFSIZE];
43018665Seric 	extern struct passwd *getpwnam();
4319536Seric 	extern char *macvalue();
4329536Seric 	extern char **prescan();
4339536Seric 	extern bool safefile();
4349536Seric 	extern char *FullName;
4359536Seric 
4369536Seric 	if (tTd(45, 1))
43714786Seric 		printf("setsender(%s)\n", from == NULL ? "" : from);
4389536Seric 
4399536Seric 	/*
4409536Seric 	**  Figure out the real user executing us.
4419536Seric 	**	Username can return errno != 0 on non-errors.
4429536Seric 	*/
4439536Seric 
4449536Seric 	if (QueueRun || OpMode == MD_SMTP || OpMode == MD_ARPAFTP)
4459536Seric 		realname = from;
4469536Seric 	if (realname == NULL || realname[0] == '\0')
4479536Seric 	{
4489536Seric 		extern char *username();
4499536Seric 
4509536Seric 		realname = username();
4519536Seric 	}
4529536Seric 
4539536Seric 	/*
4549536Seric 	**  Determine if this real person is allowed to alias themselves.
4559536Seric 	*/
4569536Seric 
4579536Seric 	if (from != NULL)
4589536Seric 	{
4599536Seric 		extern bool trusteduser();
4609536Seric 
46136230Skarels 		if (!trusteduser(realname) && getuid() != geteuid() &&
4629536Seric 		    index(from, '!') == NULL && getuid() != 0)
4639536Seric 		{
4649536Seric 			/* network sends -r regardless (why why why?) */
4659536Seric 			/* syserr("%s, you cannot use the -f flag", realname); */
4669536Seric 			from = NULL;
4679536Seric 		}
4689536Seric 	}
4699536Seric 
4709536Seric 	SuprErrs = TRUE;
47111447Seric 	if (from == NULL || parseaddr(from, &CurEnv->e_from, 1, '\0') == NULL)
4729536Seric 	{
47321750Seric 		/* log garbage addresses for traceback */
47421750Seric 		if (from != NULL)
47521750Seric 		{
47624944Seric # ifdef LOG
47724944Seric 			if (LogLevel >= 1)
47836230Skarels 			    if (realname == from && RealHostName != NULL)
47936230Skarels 				syslog(LOG_NOTICE,
48036230Skarels 				    "from=%s unparseable, received from %s",
48136230Skarels 				    from, RealHostName);
48236230Skarels 			    else
48336230Skarels 				syslog(LOG_NOTICE,
48436230Skarels 				    "Unparseable username %s wants from=%s",
48536230Skarels 				    realname, from);
48624944Seric # endif LOG
48721750Seric 		}
4889536Seric 		from = newstr(realname);
48924944Seric 		if (parseaddr(from, &CurEnv->e_from, 1, '\0') == NULL &&
49024944Seric 		    parseaddr("postmaster", &CurEnv->e_from, 1, '\0') == NULL)
49124944Seric 		{
49224944Seric 			syserr("setsender: can't even parse postmaster!");
49324944Seric 		}
4949536Seric 	}
4959536Seric 	else
4969536Seric 		FromFlag = TRUE;
4979536Seric 	CurEnv->e_from.q_flags |= QDONTSEND;
49816162Seric 	loweraddr(&CurEnv->e_from);
4999536Seric 	SuprErrs = FALSE;
5009536Seric 
50118665Seric 	if (CurEnv->e_from.q_mailer == LocalMailer &&
50218665Seric 	    (pw = getpwnam(CurEnv->e_from.q_user)) != NULL)
5039536Seric 	{
50417472Seric 		/*
50517472Seric 		**  Process passwd file entry.
50617472Seric 		*/
50717472Seric 
5089536Seric 
5099536Seric 		/* extract home directory */
5109536Seric 		CurEnv->e_from.q_home = newstr(pw->pw_dir);
51116481Seric 		define('z', CurEnv->e_from.q_home, CurEnv);
5129536Seric 
51311625Seric 		/* extract user and group id */
51411625Seric 		CurEnv->e_from.q_uid = pw->pw_uid;
51511625Seric 		CurEnv->e_from.q_gid = pw->pw_gid;
51611625Seric 
5179536Seric 		/* if the user has given fullname already, don't redefine */
5189536Seric 		if (FullName == NULL)
5199536Seric 			FullName = macvalue('x', CurEnv);
52011932Seric 		if (FullName != NULL && FullName[0] == '\0')
5219536Seric 			FullName = NULL;
5229536Seric 
5239536Seric 		/* extract full name from passwd file */
5249582Seric 		if (FullName == NULL && pw->pw_gecos != NULL &&
5259582Seric 		    strcmp(pw->pw_name, CurEnv->e_from.q_user) == 0)
5269536Seric 		{
5279536Seric 			buildfname(pw->pw_gecos, CurEnv->e_from.q_user, buf);
5289536Seric 			if (buf[0] != '\0')
5299536Seric 				FullName = newstr(buf);
5309536Seric 		}
5319536Seric 		if (FullName != NULL)
5329536Seric 			define('x', FullName, CurEnv);
5339536Seric 	}
53411625Seric 	else
53511625Seric 	{
53611625Seric 		if (CurEnv->e_from.q_home == NULL)
53711625Seric 			CurEnv->e_from.q_home = getenv("HOME");
53811625Seric 		CurEnv->e_from.q_uid = getuid();
53911625Seric 		CurEnv->e_from.q_gid = getgid();
54011625Seric 	}
54111625Seric 
5429536Seric 	if (CurEnv->e_from.q_uid != 0)
5439536Seric 	{
5449536Seric 		DefUid = CurEnv->e_from.q_uid;
5459536Seric 		DefGid = CurEnv->e_from.q_gid;
5469536Seric 	}
5479536Seric 
5489536Seric 	/*
5499536Seric 	**  Rewrite the from person to dispose of possible implicit
5509536Seric 	**	links in the net.
5519536Seric 	*/
5529536Seric 
55316913Seric 	pvp = prescan(from, '\0', pvpbuf);
5549536Seric 	if (pvp == NULL)
5559536Seric 	{
55636233Skarels # ifdef LOG
55736233Skarels 		if (LogLevel >= 1)
55836233Skarels 			syslog(LOG_NOTICE, "cannot prescan from (%s)", from);
55936233Skarels # endif
56036230Skarels 		usrerr("cannot prescan from (%s)", from);
5619536Seric 		finis();
5629536Seric 	}
5639536Seric 	rewrite(pvp, 3);
5649536Seric 	rewrite(pvp, 1);
56525032Seric 	rewrite(pvp, 4);
5669536Seric 	cataddr(pvp, buf, sizeof buf);
5679536Seric 	define('f', newstr(buf), CurEnv);
5689536Seric 
5699536Seric 	/* save the domain spec if this mailer wants it */
57024944Seric 	if (CurEnv->e_from.q_mailer != NULL &&
57124944Seric 	    bitnset(M_CANONICAL, CurEnv->e_from.q_mailer->m_flags))
5729536Seric 	{
5739536Seric 		extern char **copyplist();
5749536Seric 
5759536Seric 		while (*pvp != NULL && strcmp(*pvp, "@") != 0)
5769536Seric 			pvp++;
5779536Seric 		if (*pvp != NULL)
5789536Seric 			CurEnv->e_fromdomain = copyplist(pvp, TRUE);
5799536Seric 	}
5809536Seric }
5819536Seric /*
5829536Seric **  TRUSTEDUSER -- tell us if this user is to be trusted.
5839536Seric **
5849536Seric **	Parameters:
5859536Seric **		user -- the user to be checked.
5869536Seric **
5879536Seric **	Returns:
5889536Seric **		TRUE if the user is in an approved list.
5899536Seric **		FALSE otherwise.
5909536Seric **
5919536Seric **	Side Effects:
5929536Seric **		none.
5939536Seric */
5949536Seric 
5959536Seric bool
5969536Seric trusteduser(user)
5979536Seric 	char *user;
5989536Seric {
5999536Seric 	register char **ulist;
6009536Seric 	extern char *TrustedUsers[];
6019536Seric 
6029536Seric 	for (ulist = TrustedUsers; *ulist != NULL; ulist++)
6039536Seric 		if (strcmp(*ulist, user) == 0)
6049536Seric 			return (TRUE);
6059536Seric 	return (FALSE);
6069536Seric }
607