xref: /illumos-gate/usr/src/cmd/sendmail/src/envelope.c (revision e9af4bc0)
17c478bd9Sstevel@tonic-gate /*
2058561cbSjbeck  * Copyright (c) 1998-2003, 2006 Sendmail, Inc. and its suppliers.
37c478bd9Sstevel@tonic-gate  *	All rights reserved.
47c478bd9Sstevel@tonic-gate  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
57c478bd9Sstevel@tonic-gate  * Copyright (c) 1988, 1993
67c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
97c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
107c478bd9Sstevel@tonic-gate  * the sendmail distribution.
117c478bd9Sstevel@tonic-gate  *
127c478bd9Sstevel@tonic-gate  */
137c478bd9Sstevel@tonic-gate 
147c478bd9Sstevel@tonic-gate #include <sendmail.h>
157c478bd9Sstevel@tonic-gate 
16*e9af4bc0SJohn Beck SM_RCSID("@(#)$Id: envelope.c,v 8.310 2009/12/18 17:08:01 ca Exp $")
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate /*
197c478bd9Sstevel@tonic-gate **  CLRSESSENVELOPE -- clear session oriented data in an envelope
207c478bd9Sstevel@tonic-gate **
217c478bd9Sstevel@tonic-gate **	Parameters:
227c478bd9Sstevel@tonic-gate **		e -- the envelope to clear.
237c478bd9Sstevel@tonic-gate **
247c478bd9Sstevel@tonic-gate **	Returns:
257c478bd9Sstevel@tonic-gate **		none.
267c478bd9Sstevel@tonic-gate */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate void
297c478bd9Sstevel@tonic-gate clrsessenvelope(e)
307c478bd9Sstevel@tonic-gate 	ENVELOPE *e;
317c478bd9Sstevel@tonic-gate {
327c478bd9Sstevel@tonic-gate #if SASL
337c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{auth_type}"), "");
347c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{auth_authen}"), "");
357c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{auth_author}"), "");
367c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{auth_ssf}"), "");
377c478bd9Sstevel@tonic-gate #endif /* SASL */
387c478bd9Sstevel@tonic-gate #if STARTTLS
397c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{cert_issuer}"), "");
407c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{cert_subject}"), "");
417c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{cipher_bits}"), "");
427c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{cipher}"), "");
437c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{tls_version}"), "");
447c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{verify}"), "");
457c478bd9Sstevel@tonic-gate # if _FFR_TLS_1
467c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{alg_bits}"), "");
477c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{cn_issuer}"), "");
487c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{cn_subject}"), "");
497c478bd9Sstevel@tonic-gate # endif /* _FFR_TLS_1 */
507c478bd9Sstevel@tonic-gate #endif /* STARTTLS */
517c478bd9Sstevel@tonic-gate }
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate **  NEWENVELOPE -- fill in a new envelope
557c478bd9Sstevel@tonic-gate **
567c478bd9Sstevel@tonic-gate **	Supports inheritance.
577c478bd9Sstevel@tonic-gate **
587c478bd9Sstevel@tonic-gate **	Parameters:
597c478bd9Sstevel@tonic-gate **		e -- the new envelope to fill in.
607c478bd9Sstevel@tonic-gate **		parent -- the envelope to be the parent of e.
617c478bd9Sstevel@tonic-gate **		rpool -- either NULL, or a pointer to a resource pool
627c478bd9Sstevel@tonic-gate **			from which envelope memory is allocated, and
637c478bd9Sstevel@tonic-gate **			to which envelope resources are attached.
647c478bd9Sstevel@tonic-gate **
657c478bd9Sstevel@tonic-gate **	Returns:
667c478bd9Sstevel@tonic-gate **		e.
677c478bd9Sstevel@tonic-gate **
687c478bd9Sstevel@tonic-gate **	Side Effects:
697c478bd9Sstevel@tonic-gate **		none.
707c478bd9Sstevel@tonic-gate */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate ENVELOPE *
737c478bd9Sstevel@tonic-gate newenvelope(e, parent, rpool)
747c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
757c478bd9Sstevel@tonic-gate 	register ENVELOPE *parent;
767c478bd9Sstevel@tonic-gate 	SM_RPOOL_T *rpool;
777c478bd9Sstevel@tonic-gate {
78d4660949Sjbeck 	int sendmode;
7949218d4fSjbeck 
807c478bd9Sstevel@tonic-gate 	/*
817c478bd9Sstevel@tonic-gate 	**  This code used to read:
827c478bd9Sstevel@tonic-gate 	**	if (e == parent && e->e_parent != NULL)
837c478bd9Sstevel@tonic-gate 	**		parent = e->e_parent;
847c478bd9Sstevel@tonic-gate 	**  So if e == parent && e->e_parent == NULL then we would
857c478bd9Sstevel@tonic-gate 	**  set e->e_parent = e, which creates a loop in the e_parent chain.
867c478bd9Sstevel@tonic-gate 	**  This meant macvalue() could go into an infinite loop.
877c478bd9Sstevel@tonic-gate 	*/
887c478bd9Sstevel@tonic-gate 
8949218d4fSjbeck 	if (parent != NULL)
9049218d4fSjbeck 		sendmode = parent->e_sendmode;
9149218d4fSjbeck 	else
9249218d4fSjbeck 		sendmode = DM_NOTSET;
9349218d4fSjbeck 
947c478bd9Sstevel@tonic-gate 	if (e == parent)
957c478bd9Sstevel@tonic-gate 		parent = e->e_parent;
967c478bd9Sstevel@tonic-gate 	clearenvelope(e, true, rpool);
977c478bd9Sstevel@tonic-gate 	if (e == CurEnv)
987c478bd9Sstevel@tonic-gate 		memmove((char *) &e->e_from,
997c478bd9Sstevel@tonic-gate 			(char *) &NullAddress,
100058561cbSjbeck 			sizeof(e->e_from));
1017c478bd9Sstevel@tonic-gate 	else
1027c478bd9Sstevel@tonic-gate 		memmove((char *) &e->e_from,
1037c478bd9Sstevel@tonic-gate 			(char *) &CurEnv->e_from,
104058561cbSjbeck 			sizeof(e->e_from));
1057c478bd9Sstevel@tonic-gate 	e->e_parent = parent;
1067c478bd9Sstevel@tonic-gate 	assign_queueid(e);
1077c478bd9Sstevel@tonic-gate 	e->e_ctime = curtime();
1087800901eSjbeck #if _FFR_SESSID
1097800901eSjbeck 	e->e_sessid = e->e_id;
1107800901eSjbeck #endif /* _FFR_SESSID */
1117c478bd9Sstevel@tonic-gate 	if (parent != NULL)
1127c478bd9Sstevel@tonic-gate 	{
1137c478bd9Sstevel@tonic-gate 		e->e_msgpriority = parent->e_msgsize;
1147800901eSjbeck #if _FFR_SESSID
1157800901eSjbeck 		if (parent->e_sessid != NULL)
1167800901eSjbeck 			e->e_sessid = sm_rpool_strdup_x(rpool,
1177800901eSjbeck 							parent->e_sessid);
1187800901eSjbeck #endif /* _FFR_SESSID */
1197800901eSjbeck 
1207c478bd9Sstevel@tonic-gate 		if (parent->e_quarmsg == NULL)
1217c478bd9Sstevel@tonic-gate 		{
1227c478bd9Sstevel@tonic-gate 			e->e_quarmsg = NULL;
1237c478bd9Sstevel@tonic-gate 			macdefine(&e->e_macro, A_PERM,
1247c478bd9Sstevel@tonic-gate 				  macid("{quarantine}"), "");
1257c478bd9Sstevel@tonic-gate 		}
1267c478bd9Sstevel@tonic-gate 		else
1277c478bd9Sstevel@tonic-gate 		{
1287c478bd9Sstevel@tonic-gate 			e->e_quarmsg = sm_rpool_strdup_x(rpool,
1297c478bd9Sstevel@tonic-gate 							 parent->e_quarmsg);
1307c478bd9Sstevel@tonic-gate 			macdefine(&e->e_macro, A_PERM,
1317c478bd9Sstevel@tonic-gate 				  macid("{quarantine}"), e->e_quarmsg);
1327c478bd9Sstevel@tonic-gate 		}
1337c478bd9Sstevel@tonic-gate 	}
1347c478bd9Sstevel@tonic-gate 	e->e_puthdr = putheader;
1357c478bd9Sstevel@tonic-gate 	e->e_putbody = putbody;
1367c478bd9Sstevel@tonic-gate 	if (CurEnv->e_xfp != NULL)
1377c478bd9Sstevel@tonic-gate 		(void) sm_io_flush(CurEnv->e_xfp, SM_TIME_DEFAULT);
13849218d4fSjbeck 	if (sendmode != DM_NOTSET)
139d4660949Sjbeck 		set_delivery_mode(sendmode, e);
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 	return e;
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate /* values for msg_timeout, see also IS_* below for usage (bit layout) */
1457c478bd9Sstevel@tonic-gate #define MSG_T_O		0x01	/* normal timeout */
1467c478bd9Sstevel@tonic-gate #define MSG_T_O_NOW	0x02	/* NOW timeout */
1477c478bd9Sstevel@tonic-gate #define MSG_NOT_BY	0x04	/* Deliver-By time exceeded, mode R */
1487c478bd9Sstevel@tonic-gate #define MSG_WARN	0x10	/* normal queue warning */
1497c478bd9Sstevel@tonic-gate #define MSG_WARN_BY	0x20	/* Deliver-By time exceeded, mode N */
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate #define IS_MSG_ERR(x)	(((x) & 0x0f) != 0)	/* return an error */
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /* immediate return */
1547c478bd9Sstevel@tonic-gate #define IS_IMM_RET(x)	(((x) & (MSG_T_O_NOW|MSG_NOT_BY)) != 0)
1557c478bd9Sstevel@tonic-gate #define IS_MSG_WARN(x)	(((x) & 0xf0) != 0)	/* return a warning */
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate /*
1587c478bd9Sstevel@tonic-gate **  DROPENVELOPE -- deallocate an envelope.
1597c478bd9Sstevel@tonic-gate **
1607c478bd9Sstevel@tonic-gate **	Parameters:
1617c478bd9Sstevel@tonic-gate **		e -- the envelope to deallocate.
1627c478bd9Sstevel@tonic-gate **		fulldrop -- if set, do return receipts.
1637c478bd9Sstevel@tonic-gate **		split -- if true, split by recipient if message is queued up
1647c478bd9Sstevel@tonic-gate **
1657c478bd9Sstevel@tonic-gate **	Returns:
166*e9af4bc0SJohn Beck **		EX_* status (currently: 0: success, EX_IOERR on panic)
1677c478bd9Sstevel@tonic-gate **
1687c478bd9Sstevel@tonic-gate **	Side Effects:
1697c478bd9Sstevel@tonic-gate **		housekeeping necessary to dispose of an envelope.
1707c478bd9Sstevel@tonic-gate **		Unlocks this queue file.
1717c478bd9Sstevel@tonic-gate */
1727c478bd9Sstevel@tonic-gate 
173*e9af4bc0SJohn Beck int
1747c478bd9Sstevel@tonic-gate dropenvelope(e, fulldrop, split)
1757c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
1767c478bd9Sstevel@tonic-gate 	bool fulldrop;
1777c478bd9Sstevel@tonic-gate 	bool split;
1787c478bd9Sstevel@tonic-gate {
1797c478bd9Sstevel@tonic-gate 	bool panic = false;
1807c478bd9Sstevel@tonic-gate 	bool queueit = false;
1817c478bd9Sstevel@tonic-gate 	int msg_timeout = 0;
1827c478bd9Sstevel@tonic-gate 	bool failure_return = false;
1837c478bd9Sstevel@tonic-gate 	bool delay_return = false;
1847c478bd9Sstevel@tonic-gate 	bool success_return = false;
1857c478bd9Sstevel@tonic-gate 	bool pmnotify = bitset(EF_PM_NOTIFY, e->e_flags);
1867c478bd9Sstevel@tonic-gate 	bool done = false;
1877c478bd9Sstevel@tonic-gate 	register ADDRESS *q;
1887c478bd9Sstevel@tonic-gate 	char *id = e->e_id;
1897c478bd9Sstevel@tonic-gate 	time_t now;
1907c478bd9Sstevel@tonic-gate 	char buf[MAXLINE];
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 	if (tTd(50, 1))
1937c478bd9Sstevel@tonic-gate 	{
1947c478bd9Sstevel@tonic-gate 		sm_dprintf("dropenvelope %p: id=", e);
1957c478bd9Sstevel@tonic-gate 		xputs(sm_debug_file(), e->e_id);
1967c478bd9Sstevel@tonic-gate 		sm_dprintf(", flags=");
1977c478bd9Sstevel@tonic-gate 		printenvflags(e);
1987c478bd9Sstevel@tonic-gate 		if (tTd(50, 10))
1997c478bd9Sstevel@tonic-gate 		{
2007c478bd9Sstevel@tonic-gate 			sm_dprintf("sendq=");
2017c478bd9Sstevel@tonic-gate 			printaddr(sm_debug_file(), e->e_sendqueue, true);
2027c478bd9Sstevel@tonic-gate 		}
2037c478bd9Sstevel@tonic-gate 	}
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	if (LogLevel > 84)
2067c478bd9Sstevel@tonic-gate 		sm_syslog(LOG_DEBUG, id,
2077c478bd9Sstevel@tonic-gate 			  "dropenvelope, e_flags=0x%lx, OpMode=%c, pid=%d",
2087c478bd9Sstevel@tonic-gate 			  e->e_flags, OpMode, (int) CurrentPid);
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	/* we must have an id to remove disk files */
2117c478bd9Sstevel@tonic-gate 	if (id == NULL)
212*e9af4bc0SJohn Beck 		return EX_OK;
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 	/* if verify-only mode, we can skip most of this */
2157c478bd9Sstevel@tonic-gate 	if (OpMode == MD_VERIFY)
2167c478bd9Sstevel@tonic-gate 		goto simpledrop;
2177c478bd9Sstevel@tonic-gate 
218*e9af4bc0SJohn Beck 	if (tTd(92, 2))
219*e9af4bc0SJohn Beck 		sm_dprintf("dropenvelope: e_id=%s, EF_LOGSENDER=%d, LogLevel=%d\n",
220*e9af4bc0SJohn Beck 			e->e_id, bitset(EF_LOGSENDER, e->e_flags), LogLevel);
2217c478bd9Sstevel@tonic-gate 	if (LogLevel > 4 && bitset(EF_LOGSENDER, e->e_flags))
2227c478bd9Sstevel@tonic-gate 		logsender(e, NULL);
2237c478bd9Sstevel@tonic-gate 	e->e_flags &= ~EF_LOGSENDER;
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	/* post statistics */
2267c478bd9Sstevel@tonic-gate 	poststats(StatFile);
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 	/*
2297c478bd9Sstevel@tonic-gate 	**  Extract state information from dregs of send list.
2307c478bd9Sstevel@tonic-gate 	*/
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 	now = curtime();
2337c478bd9Sstevel@tonic-gate 	if (now >= e->e_ctime + TimeOuts.to_q_return[e->e_timeoutclass])
2347c478bd9Sstevel@tonic-gate 		msg_timeout = MSG_T_O;
2357c478bd9Sstevel@tonic-gate 	if (IS_DLVR_RETURN(e) && e->e_deliver_by > 0 &&
2367c478bd9Sstevel@tonic-gate 	    now >= e->e_ctime + e->e_deliver_by &&
2377c478bd9Sstevel@tonic-gate 	    !bitset(EF_RESPONSE, e->e_flags))
2387c478bd9Sstevel@tonic-gate 	{
2397c478bd9Sstevel@tonic-gate 		msg_timeout = MSG_NOT_BY;
2407c478bd9Sstevel@tonic-gate 		e->e_flags |= EF_FATALERRS|EF_CLRQUEUE;
2417c478bd9Sstevel@tonic-gate 	}
2427c478bd9Sstevel@tonic-gate 	else if (TimeOuts.to_q_return[e->e_timeoutclass] == NOW &&
2437c478bd9Sstevel@tonic-gate 		 !bitset(EF_RESPONSE, e->e_flags))
2447c478bd9Sstevel@tonic-gate 	{
2457c478bd9Sstevel@tonic-gate 		msg_timeout = MSG_T_O_NOW;
2467c478bd9Sstevel@tonic-gate 		e->e_flags |= EF_FATALERRS|EF_CLRQUEUE;
2477c478bd9Sstevel@tonic-gate 	}
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	e->e_flags &= ~EF_QUEUERUN;
2507c478bd9Sstevel@tonic-gate 	for (q = e->e_sendqueue; q != NULL; q = q->q_next)
2517c478bd9Sstevel@tonic-gate 	{
2527c478bd9Sstevel@tonic-gate 		if (QS_IS_UNDELIVERED(q->q_state))
2537c478bd9Sstevel@tonic-gate 			queueit = true;
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 		/* see if a notification is needed */
2567c478bd9Sstevel@tonic-gate 		if (bitset(QPINGONFAILURE, q->q_flags) &&
2577c478bd9Sstevel@tonic-gate 		    ((IS_MSG_ERR(msg_timeout) &&
2587c478bd9Sstevel@tonic-gate 		      QS_IS_UNDELIVERED(q->q_state)) ||
2597c478bd9Sstevel@tonic-gate 		     QS_IS_BADADDR(q->q_state) ||
2607c478bd9Sstevel@tonic-gate 		     IS_IMM_RET(msg_timeout)))
2617c478bd9Sstevel@tonic-gate 		{
2627c478bd9Sstevel@tonic-gate 			failure_return = true;
2637c478bd9Sstevel@tonic-gate 			if (!done && q->q_owner == NULL &&
2647c478bd9Sstevel@tonic-gate 			    !emptyaddr(&e->e_from))
2657c478bd9Sstevel@tonic-gate 			{
2667c478bd9Sstevel@tonic-gate 				(void) sendtolist(e->e_from.q_paddr, NULLADDR,
2677c478bd9Sstevel@tonic-gate 						  &e->e_errorqueue, 0, e);
2687c478bd9Sstevel@tonic-gate 				done = true;
2697c478bd9Sstevel@tonic-gate 			}
2707c478bd9Sstevel@tonic-gate 		}
2717c478bd9Sstevel@tonic-gate 		else if ((bitset(QPINGONSUCCESS, q->q_flags) &&
2727c478bd9Sstevel@tonic-gate 			  ((QS_IS_SENT(q->q_state) &&
2737c478bd9Sstevel@tonic-gate 			    bitnset(M_LOCALMAILER, q->q_mailer->m_flags)) ||
2747c478bd9Sstevel@tonic-gate 			   bitset(QRELAYED|QEXPANDED|QDELIVERED, q->q_flags))) ||
2757c478bd9Sstevel@tonic-gate 			  bitset(QBYTRACE, q->q_flags) ||
2767c478bd9Sstevel@tonic-gate 			  bitset(QBYNRELAY, q->q_flags))
2777c478bd9Sstevel@tonic-gate 		{
2787c478bd9Sstevel@tonic-gate 			success_return = true;
2797c478bd9Sstevel@tonic-gate 		}
2807c478bd9Sstevel@tonic-gate 	}
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	if (e->e_class < 0)
2837c478bd9Sstevel@tonic-gate 		e->e_flags |= EF_NO_BODY_RETN;
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate 	/*
2867c478bd9Sstevel@tonic-gate 	**  See if the message timed out.
2877c478bd9Sstevel@tonic-gate 	*/
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate 	if (!queueit)
2907c478bd9Sstevel@tonic-gate 		/* EMPTY */
2917c478bd9Sstevel@tonic-gate 		/* nothing to do */ ;
2927c478bd9Sstevel@tonic-gate 	else if (IS_MSG_ERR(msg_timeout))
2937c478bd9Sstevel@tonic-gate 	{
2947c478bd9Sstevel@tonic-gate 		if (failure_return)
2957c478bd9Sstevel@tonic-gate 		{
2967c478bd9Sstevel@tonic-gate 			if (msg_timeout == MSG_NOT_BY)
2977c478bd9Sstevel@tonic-gate 			{
298058561cbSjbeck 				(void) sm_snprintf(buf, sizeof(buf),
2997c478bd9Sstevel@tonic-gate 					"delivery time expired %lds",
3007c478bd9Sstevel@tonic-gate 					e->e_deliver_by);
3017c478bd9Sstevel@tonic-gate 			}
3027c478bd9Sstevel@tonic-gate 			else
3037c478bd9Sstevel@tonic-gate 			{
304058561cbSjbeck 				(void) sm_snprintf(buf, sizeof(buf),
3057c478bd9Sstevel@tonic-gate 					"Cannot send message for %s",
3067c478bd9Sstevel@tonic-gate 					pintvl(TimeOuts.to_q_return[e->e_timeoutclass],
3077c478bd9Sstevel@tonic-gate 						false));
3087c478bd9Sstevel@tonic-gate 			}
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 			/* don't free, allocated from e_rpool */
3117c478bd9Sstevel@tonic-gate 			e->e_message = sm_rpool_strdup_x(e->e_rpool, buf);
3127c478bd9Sstevel@tonic-gate 			message(buf);
3137c478bd9Sstevel@tonic-gate 			e->e_flags |= EF_CLRQUEUE;
3147c478bd9Sstevel@tonic-gate 		}
3157c478bd9Sstevel@tonic-gate 		if (msg_timeout == MSG_NOT_BY)
3167c478bd9Sstevel@tonic-gate 		{
3177c478bd9Sstevel@tonic-gate 			(void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
3187c478bd9Sstevel@tonic-gate 				"Delivery time (%lds) expired\n",
3197c478bd9Sstevel@tonic-gate 				e->e_deliver_by);
3207c478bd9Sstevel@tonic-gate 		}
3217c478bd9Sstevel@tonic-gate 		else
3227c478bd9Sstevel@tonic-gate 			(void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
3237c478bd9Sstevel@tonic-gate 				"Message could not be delivered for %s\n",
3247c478bd9Sstevel@tonic-gate 				pintvl(TimeOuts.to_q_return[e->e_timeoutclass],
3257c478bd9Sstevel@tonic-gate 					false));
3267c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
3277c478bd9Sstevel@tonic-gate 			"Message will be deleted from queue\n");
3287c478bd9Sstevel@tonic-gate 		for (q = e->e_sendqueue; q != NULL; q = q->q_next)
3297c478bd9Sstevel@tonic-gate 		{
3307c478bd9Sstevel@tonic-gate 			if (QS_IS_UNDELIVERED(q->q_state))
3317c478bd9Sstevel@tonic-gate 			{
3327c478bd9Sstevel@tonic-gate 				q->q_state = QS_BADADDR;
3337c478bd9Sstevel@tonic-gate 				if (msg_timeout == MSG_NOT_BY)
3347c478bd9Sstevel@tonic-gate 					q->q_status = "5.4.7";
3357c478bd9Sstevel@tonic-gate 				else
3367c478bd9Sstevel@tonic-gate 					q->q_status = "4.4.7";
3377c478bd9Sstevel@tonic-gate 			}
3387c478bd9Sstevel@tonic-gate 		}
3397c478bd9Sstevel@tonic-gate 	}
3407c478bd9Sstevel@tonic-gate 	else
3417c478bd9Sstevel@tonic-gate 	{
3427c478bd9Sstevel@tonic-gate 		if (TimeOuts.to_q_warning[e->e_timeoutclass] > 0 &&
3437c478bd9Sstevel@tonic-gate 		    now >= e->e_ctime +
3447c478bd9Sstevel@tonic-gate 				TimeOuts.to_q_warning[e->e_timeoutclass])
3457c478bd9Sstevel@tonic-gate 			msg_timeout = MSG_WARN;
3467c478bd9Sstevel@tonic-gate 		else if (IS_DLVR_NOTIFY(e) &&
3477c478bd9Sstevel@tonic-gate 			 e->e_deliver_by > 0 &&
3487c478bd9Sstevel@tonic-gate 			 now >= e->e_ctime + e->e_deliver_by)
3497c478bd9Sstevel@tonic-gate 			msg_timeout = MSG_WARN_BY;
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 		if (IS_MSG_WARN(msg_timeout))
3527c478bd9Sstevel@tonic-gate 		{
3537c478bd9Sstevel@tonic-gate 			if (!bitset(EF_WARNING|EF_RESPONSE, e->e_flags) &&
3547c478bd9Sstevel@tonic-gate 			    e->e_class >= 0 &&
3557c478bd9Sstevel@tonic-gate 			    e->e_from.q_paddr != NULL &&
3567c478bd9Sstevel@tonic-gate 			    strcmp(e->e_from.q_paddr, "<>") != 0 &&
3577c478bd9Sstevel@tonic-gate 			    sm_strncasecmp(e->e_from.q_paddr, "owner-", 6) != 0 &&
3587c478bd9Sstevel@tonic-gate 			    (strlen(e->e_from.q_paddr) <= 8 ||
3597c478bd9Sstevel@tonic-gate 			     sm_strcasecmp(&e->e_from.q_paddr[strlen(e->e_from.q_paddr) - 8],
3607c478bd9Sstevel@tonic-gate 					   "-request") != 0))
3617c478bd9Sstevel@tonic-gate 			{
3627c478bd9Sstevel@tonic-gate 				for (q = e->e_sendqueue; q != NULL;
3637c478bd9Sstevel@tonic-gate 				     q = q->q_next)
3647c478bd9Sstevel@tonic-gate 				{
3657c478bd9Sstevel@tonic-gate 					if (QS_IS_UNDELIVERED(q->q_state)
3667c478bd9Sstevel@tonic-gate #if _FFR_NODELAYDSN_ON_HOLD
3677c478bd9Sstevel@tonic-gate 					    && !bitnset(M_HOLD,
3687c478bd9Sstevel@tonic-gate 							q->q_mailer->m_flags)
3697c478bd9Sstevel@tonic-gate #endif /* _FFR_NODELAYDSN_ON_HOLD */
3707c478bd9Sstevel@tonic-gate 					   )
3717c478bd9Sstevel@tonic-gate 					{
3727c478bd9Sstevel@tonic-gate 						if (msg_timeout ==
3737c478bd9Sstevel@tonic-gate 						    MSG_WARN_BY &&
3747c478bd9Sstevel@tonic-gate 						    (bitset(QPINGONDELAY,
3757c478bd9Sstevel@tonic-gate 							    q->q_flags) ||
3767c478bd9Sstevel@tonic-gate 						    !bitset(QHASNOTIFY,
3777c478bd9Sstevel@tonic-gate 							    q->q_flags))
3787c478bd9Sstevel@tonic-gate 						   )
3797c478bd9Sstevel@tonic-gate 						{
3807c478bd9Sstevel@tonic-gate 							q->q_flags |= QBYNDELAY;
3817c478bd9Sstevel@tonic-gate 							delay_return = true;
3827c478bd9Sstevel@tonic-gate 						}
3837c478bd9Sstevel@tonic-gate 						if (bitset(QPINGONDELAY,
3847c478bd9Sstevel@tonic-gate 							   q->q_flags))
3857c478bd9Sstevel@tonic-gate 						{
3867c478bd9Sstevel@tonic-gate 							q->q_flags |= QDELAYED;
3877c478bd9Sstevel@tonic-gate 							delay_return = true;
3887c478bd9Sstevel@tonic-gate 						}
3897c478bd9Sstevel@tonic-gate 					}
3907c478bd9Sstevel@tonic-gate 				}
3917c478bd9Sstevel@tonic-gate 			}
3927c478bd9Sstevel@tonic-gate 			if (delay_return)
3937c478bd9Sstevel@tonic-gate 			{
3947c478bd9Sstevel@tonic-gate 				if (msg_timeout == MSG_WARN_BY)
3957c478bd9Sstevel@tonic-gate 				{
396058561cbSjbeck 					(void) sm_snprintf(buf, sizeof(buf),
3977c478bd9Sstevel@tonic-gate 						"Warning: Delivery time (%lds) exceeded",
3987c478bd9Sstevel@tonic-gate 						e->e_deliver_by);
3997c478bd9Sstevel@tonic-gate 				}
4007c478bd9Sstevel@tonic-gate 				else
401058561cbSjbeck 					(void) sm_snprintf(buf, sizeof(buf),
4027c478bd9Sstevel@tonic-gate 						"Warning: could not send message for past %s",
4037c478bd9Sstevel@tonic-gate 						pintvl(TimeOuts.to_q_warning[e->e_timeoutclass],
4047c478bd9Sstevel@tonic-gate 							false));
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 				/* don't free, allocated from e_rpool */
4077c478bd9Sstevel@tonic-gate 				e->e_message = sm_rpool_strdup_x(e->e_rpool,
4087c478bd9Sstevel@tonic-gate 								 buf);
4097c478bd9Sstevel@tonic-gate 				message(buf);
4107c478bd9Sstevel@tonic-gate 				e->e_flags |= EF_WARNING;
4117c478bd9Sstevel@tonic-gate 			}
4127c478bd9Sstevel@tonic-gate 			if (msg_timeout == MSG_WARN_BY)
4137c478bd9Sstevel@tonic-gate 			{
4147c478bd9Sstevel@tonic-gate 				(void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
4157c478bd9Sstevel@tonic-gate 					"Warning: Delivery time (%lds) exceeded\n",
4167c478bd9Sstevel@tonic-gate 					e->e_deliver_by);
4177c478bd9Sstevel@tonic-gate 			}
4187c478bd9Sstevel@tonic-gate 			else
4197c478bd9Sstevel@tonic-gate 				(void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
4207c478bd9Sstevel@tonic-gate 					"Warning: message still undelivered after %s\n",
4217c478bd9Sstevel@tonic-gate 					pintvl(TimeOuts.to_q_warning[e->e_timeoutclass],
4227c478bd9Sstevel@tonic-gate 					     false));
4237c478bd9Sstevel@tonic-gate 			(void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
4247c478bd9Sstevel@tonic-gate 				      "Will keep trying until message is %s old\n",
4257c478bd9Sstevel@tonic-gate 				      pintvl(TimeOuts.to_q_return[e->e_timeoutclass],
4267c478bd9Sstevel@tonic-gate 					     false));
4277c478bd9Sstevel@tonic-gate 		}
4287c478bd9Sstevel@tonic-gate 	}
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 	if (tTd(50, 2))
4317c478bd9Sstevel@tonic-gate 		sm_dprintf("failure_return=%d delay_return=%d success_return=%d queueit=%d\n",
4327c478bd9Sstevel@tonic-gate 			failure_return, delay_return, success_return, queueit);
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate 	/*
4357c478bd9Sstevel@tonic-gate 	**  If we had some fatal error, but no addresses are marked as
4367c478bd9Sstevel@tonic-gate 	**  bad, mark them _all_ as bad.
4377c478bd9Sstevel@tonic-gate 	*/
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate 	if (bitset(EF_FATALERRS, e->e_flags) && !failure_return)
4407c478bd9Sstevel@tonic-gate 	{
4417c478bd9Sstevel@tonic-gate 		for (q = e->e_sendqueue; q != NULL; q = q->q_next)
4427c478bd9Sstevel@tonic-gate 		{
4437c478bd9Sstevel@tonic-gate 			if ((QS_IS_OK(q->q_state) ||
4447c478bd9Sstevel@tonic-gate 			     QS_IS_VERIFIED(q->q_state)) &&
4457c478bd9Sstevel@tonic-gate 			    bitset(QPINGONFAILURE, q->q_flags))
4467c478bd9Sstevel@tonic-gate 			{
4477c478bd9Sstevel@tonic-gate 				failure_return = true;
4487c478bd9Sstevel@tonic-gate 				q->q_state = QS_BADADDR;
4497c478bd9Sstevel@tonic-gate 			}
4507c478bd9Sstevel@tonic-gate 		}
4517c478bd9Sstevel@tonic-gate 	}
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate 	/*
4547c478bd9Sstevel@tonic-gate 	**  Send back return receipts as requested.
4557c478bd9Sstevel@tonic-gate 	*/
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate 	if (success_return && !failure_return && !delay_return && fulldrop &&
4587c478bd9Sstevel@tonic-gate 	    !bitset(PRIV_NORECEIPTS, PrivacyFlags) &&
4597c478bd9Sstevel@tonic-gate 	    strcmp(e->e_from.q_paddr, "<>") != 0)
4607c478bd9Sstevel@tonic-gate 	{
4617c478bd9Sstevel@tonic-gate 		auto ADDRESS *rlist = NULL;
4627c478bd9Sstevel@tonic-gate 
4637c478bd9Sstevel@tonic-gate 		if (tTd(50, 8))
4647c478bd9Sstevel@tonic-gate 			sm_dprintf("dropenvelope(%s): sending return receipt\n",
4657c478bd9Sstevel@tonic-gate 				id);
4667c478bd9Sstevel@tonic-gate 		e->e_flags |= EF_SENDRECEIPT;
4677c478bd9Sstevel@tonic-gate 		(void) sendtolist(e->e_from.q_paddr, NULLADDR, &rlist, 0, e);
4687c478bd9Sstevel@tonic-gate 		(void) returntosender("Return receipt", rlist, RTSF_NO_BODY, e);
4697c478bd9Sstevel@tonic-gate 	}
4707c478bd9Sstevel@tonic-gate 	e->e_flags &= ~EF_SENDRECEIPT;
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 	/*
4737c478bd9Sstevel@tonic-gate 	**  Arrange to send error messages if there are fatal errors.
4747c478bd9Sstevel@tonic-gate 	*/
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate 	if ((failure_return || delay_return) && e->e_errormode != EM_QUIET)
4777c478bd9Sstevel@tonic-gate 	{
4787c478bd9Sstevel@tonic-gate 		if (tTd(50, 8))
4797c478bd9Sstevel@tonic-gate 			sm_dprintf("dropenvelope(%s): saving mail\n", id);
4807c478bd9Sstevel@tonic-gate 		panic = savemail(e, !bitset(EF_NO_BODY_RETN, e->e_flags));
4817c478bd9Sstevel@tonic-gate 	}
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate 	/*
4847c478bd9Sstevel@tonic-gate 	**  Arrange to send warning messages to postmaster as requested.
4857c478bd9Sstevel@tonic-gate 	*/
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate 	if ((failure_return || pmnotify) &&
4887c478bd9Sstevel@tonic-gate 	    PostMasterCopy != NULL &&
4897c478bd9Sstevel@tonic-gate 	    !bitset(EF_RESPONSE, e->e_flags) &&
4907c478bd9Sstevel@tonic-gate 	    e->e_class >= 0)
4917c478bd9Sstevel@tonic-gate 	{
4927c478bd9Sstevel@tonic-gate 		auto ADDRESS *rlist = NULL;
4937c478bd9Sstevel@tonic-gate 		char pcopy[MAXNAME];
4947c478bd9Sstevel@tonic-gate 
4957c478bd9Sstevel@tonic-gate 		if (failure_return)
4967c478bd9Sstevel@tonic-gate 		{
497058561cbSjbeck 			expand(PostMasterCopy, pcopy, sizeof(pcopy), e);
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate 			if (tTd(50, 8))
5007c478bd9Sstevel@tonic-gate 				sm_dprintf("dropenvelope(%s): sending postmaster copy to %s\n",
5017c478bd9Sstevel@tonic-gate 					id, pcopy);
5027c478bd9Sstevel@tonic-gate 			(void) sendtolist(pcopy, NULLADDR, &rlist, 0, e);
5037c478bd9Sstevel@tonic-gate 		}
5047c478bd9Sstevel@tonic-gate 		if (pmnotify)
5057c478bd9Sstevel@tonic-gate 			(void) sendtolist("postmaster", NULLADDR,
5067c478bd9Sstevel@tonic-gate 					  &rlist, 0, e);
5077c478bd9Sstevel@tonic-gate 		(void) returntosender(e->e_message, rlist,
5087c478bd9Sstevel@tonic-gate 				      RTSF_PM_BOUNCE|RTSF_NO_BODY, e);
5097c478bd9Sstevel@tonic-gate 	}
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate 	/*
5127c478bd9Sstevel@tonic-gate 	**  Instantiate or deinstantiate the queue.
5137c478bd9Sstevel@tonic-gate 	*/
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate simpledrop:
5167c478bd9Sstevel@tonic-gate 	if (tTd(50, 8))
5177c478bd9Sstevel@tonic-gate 		sm_dprintf("dropenvelope(%s): at simpledrop, queueit=%d\n",
5187c478bd9Sstevel@tonic-gate 			id, queueit);
5197c478bd9Sstevel@tonic-gate 	if (!queueit || bitset(EF_CLRQUEUE, e->e_flags))
5207c478bd9Sstevel@tonic-gate 	{
5217c478bd9Sstevel@tonic-gate 		if (tTd(50, 1))
5227c478bd9Sstevel@tonic-gate 		{
5237c478bd9Sstevel@tonic-gate 			sm_dprintf("\n===== Dropping queue files for %s... queueit=%d, e_flags=",
5247c478bd9Sstevel@tonic-gate 				e->e_id, queueit);
5257c478bd9Sstevel@tonic-gate 			printenvflags(e);
5267c478bd9Sstevel@tonic-gate 		}
5277c478bd9Sstevel@tonic-gate 		if (!panic)
5283ee0e492Sjbeck 		{
5293ee0e492Sjbeck 			if (e->e_dfp != NULL)
5303ee0e492Sjbeck 			{
5313ee0e492Sjbeck 				(void) sm_io_close(e->e_dfp, SM_TIME_DEFAULT);
5323ee0e492Sjbeck 				e->e_dfp = NULL;
5333ee0e492Sjbeck 			}
5347c478bd9Sstevel@tonic-gate 			(void) xunlink(queuename(e, DATAFL_LETTER));
5353ee0e492Sjbeck 		}
5367c478bd9Sstevel@tonic-gate 		if (panic && QueueMode == QM_LOST)
5377c478bd9Sstevel@tonic-gate 		{
5387c478bd9Sstevel@tonic-gate 			/*
5397c478bd9Sstevel@tonic-gate 			**  leave the Qf file behind as
5407c478bd9Sstevel@tonic-gate 			**  the delivery attempt failed.
5417c478bd9Sstevel@tonic-gate 			*/
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate 			/* EMPTY */
5447c478bd9Sstevel@tonic-gate 		}
5457c478bd9Sstevel@tonic-gate 		else
5467c478bd9Sstevel@tonic-gate 		if (xunlink(queuename(e, ANYQFL_LETTER)) == 0)
5477c478bd9Sstevel@tonic-gate 		{
5487c478bd9Sstevel@tonic-gate 			/* add to available space in filesystem */
5497c478bd9Sstevel@tonic-gate 			updfs(e, -1, panic ? 0 : -1, "dropenvelope");
5507c478bd9Sstevel@tonic-gate 		}
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 		if (e->e_ntries > 0 && LogLevel > 9)
5537c478bd9Sstevel@tonic-gate 			sm_syslog(LOG_INFO, id, "done; delay=%s, ntries=%d",
5547c478bd9Sstevel@tonic-gate 				  pintvl(curtime() - e->e_ctime, true),
5557c478bd9Sstevel@tonic-gate 				  e->e_ntries);
5567c478bd9Sstevel@tonic-gate 	}
5577c478bd9Sstevel@tonic-gate 	else if (queueit || !bitset(EF_INQUEUE, e->e_flags))
5587c478bd9Sstevel@tonic-gate 	{
5597c478bd9Sstevel@tonic-gate 		if (!split)
5607c478bd9Sstevel@tonic-gate 			queueup(e, false, true);
5617c478bd9Sstevel@tonic-gate 		else
5627c478bd9Sstevel@tonic-gate 		{
5637c478bd9Sstevel@tonic-gate 			ENVELOPE *oldsib;
5647c478bd9Sstevel@tonic-gate 			ENVELOPE *ee;
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate 			/*
5677c478bd9Sstevel@tonic-gate 			**  Save old sibling and set it to NULL to avoid
5687c478bd9Sstevel@tonic-gate 			**  queueing up the same envelopes again.
5697c478bd9Sstevel@tonic-gate 			**  This requires that envelopes in that list have
5707c478bd9Sstevel@tonic-gate 			**  been take care of before (or at some other place).
5717c478bd9Sstevel@tonic-gate 			*/
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate 			oldsib = e->e_sibling;
5747c478bd9Sstevel@tonic-gate 			e->e_sibling = NULL;
5757c478bd9Sstevel@tonic-gate 			if (!split_by_recipient(e) &&
5767c478bd9Sstevel@tonic-gate 			    bitset(EF_FATALERRS, e->e_flags))
5777c478bd9Sstevel@tonic-gate 			{
5787c478bd9Sstevel@tonic-gate 				syserr("!dropenvelope(%s): cannot commit data file %s, uid=%d",
5797c478bd9Sstevel@tonic-gate 					e->e_id, queuename(e, DATAFL_LETTER),
5807c478bd9Sstevel@tonic-gate 					(int) geteuid());
5817c478bd9Sstevel@tonic-gate 			}
5827c478bd9Sstevel@tonic-gate 			for (ee = e->e_sibling; ee != NULL; ee = ee->e_sibling)
5837c478bd9Sstevel@tonic-gate 				queueup(ee, false, true);
5847c478bd9Sstevel@tonic-gate 			queueup(e, false, true);
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 			/* clean up */
5877c478bd9Sstevel@tonic-gate 			for (ee = e->e_sibling; ee != NULL; ee = ee->e_sibling)
5887c478bd9Sstevel@tonic-gate 			{
5897c478bd9Sstevel@tonic-gate 				/* now unlock the job */
5907c478bd9Sstevel@tonic-gate 				if (tTd(50, 8))
5917c478bd9Sstevel@tonic-gate 					sm_dprintf("dropenvelope(%s): unlocking job\n",
5927c478bd9Sstevel@tonic-gate 						   ee->e_id);
5937c478bd9Sstevel@tonic-gate 				closexscript(ee);
5947c478bd9Sstevel@tonic-gate 				unlockqueue(ee);
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate 				/* this envelope is marked unused */
5977c478bd9Sstevel@tonic-gate 				if (ee->e_dfp != NULL)
5987c478bd9Sstevel@tonic-gate 				{
5997c478bd9Sstevel@tonic-gate 					(void) sm_io_close(ee->e_dfp,
6007c478bd9Sstevel@tonic-gate 							   SM_TIME_DEFAULT);
6017c478bd9Sstevel@tonic-gate 					ee->e_dfp = NULL;
6027c478bd9Sstevel@tonic-gate 				}
6037c478bd9Sstevel@tonic-gate 				ee->e_id = NULL;
6047c478bd9Sstevel@tonic-gate 				ee->e_flags &= ~EF_HAS_DF;
6057c478bd9Sstevel@tonic-gate 			}
6067c478bd9Sstevel@tonic-gate 			e->e_sibling = oldsib;
6077c478bd9Sstevel@tonic-gate 		}
6087c478bd9Sstevel@tonic-gate 	}
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate 	/* now unlock the job */
6117c478bd9Sstevel@tonic-gate 	if (tTd(50, 8))
6127c478bd9Sstevel@tonic-gate 		sm_dprintf("dropenvelope(%s): unlocking job\n", id);
6137c478bd9Sstevel@tonic-gate 	closexscript(e);
6147c478bd9Sstevel@tonic-gate 	unlockqueue(e);
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate 	/* make sure that this envelope is marked unused */
6177c478bd9Sstevel@tonic-gate 	if (e->e_dfp != NULL)
6187c478bd9Sstevel@tonic-gate 	{
6197c478bd9Sstevel@tonic-gate 		(void) sm_io_close(e->e_dfp, SM_TIME_DEFAULT);
6207c478bd9Sstevel@tonic-gate 		e->e_dfp = NULL;
6217c478bd9Sstevel@tonic-gate 	}
6227c478bd9Sstevel@tonic-gate 	e->e_id = NULL;
6237c478bd9Sstevel@tonic-gate 	e->e_flags &= ~EF_HAS_DF;
624*e9af4bc0SJohn Beck 	if (panic)
625*e9af4bc0SJohn Beck 		return EX_IOERR;
626*e9af4bc0SJohn Beck 	return EX_OK;
6277c478bd9Sstevel@tonic-gate }
628*e9af4bc0SJohn Beck 
6297c478bd9Sstevel@tonic-gate /*
6307c478bd9Sstevel@tonic-gate **  CLEARENVELOPE -- clear an envelope without unlocking
6317c478bd9Sstevel@tonic-gate **
6327c478bd9Sstevel@tonic-gate **	This is normally used by a child process to get a clean
6337c478bd9Sstevel@tonic-gate **	envelope without disturbing the parent.
6347c478bd9Sstevel@tonic-gate **
6357c478bd9Sstevel@tonic-gate **	Parameters:
6367c478bd9Sstevel@tonic-gate **		e -- the envelope to clear.
6377c478bd9Sstevel@tonic-gate **		fullclear - if set, the current envelope is total
6387c478bd9Sstevel@tonic-gate **			garbage and should be ignored; otherwise,
6397c478bd9Sstevel@tonic-gate **			release any resources it may indicate.
6407c478bd9Sstevel@tonic-gate **		rpool -- either NULL, or a pointer to a resource pool
6417c478bd9Sstevel@tonic-gate **			from which envelope memory is allocated, and
6427c478bd9Sstevel@tonic-gate **			to which envelope resources are attached.
6437c478bd9Sstevel@tonic-gate **
6447c478bd9Sstevel@tonic-gate **	Returns:
6457c478bd9Sstevel@tonic-gate **		none.
6467c478bd9Sstevel@tonic-gate **
6477c478bd9Sstevel@tonic-gate **	Side Effects:
6487c478bd9Sstevel@tonic-gate **		Closes files associated with the envelope.
6497c478bd9Sstevel@tonic-gate **		Marks the envelope as unallocated.
6507c478bd9Sstevel@tonic-gate */
6517c478bd9Sstevel@tonic-gate 
6527c478bd9Sstevel@tonic-gate void
6537c478bd9Sstevel@tonic-gate clearenvelope(e, fullclear, rpool)
6547c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
6557c478bd9Sstevel@tonic-gate 	bool fullclear;
6567c478bd9Sstevel@tonic-gate 	SM_RPOOL_T *rpool;
6577c478bd9Sstevel@tonic-gate {
6587c478bd9Sstevel@tonic-gate 	register HDR *bh;
6597c478bd9Sstevel@tonic-gate 	register HDR **nhp;
6607c478bd9Sstevel@tonic-gate 	extern ENVELOPE BlankEnvelope;
6617c478bd9Sstevel@tonic-gate 	char **p;
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate 	if (!fullclear)
6647c478bd9Sstevel@tonic-gate 	{
6657c478bd9Sstevel@tonic-gate 		/* clear out any file information */
6667c478bd9Sstevel@tonic-gate 		if (e->e_xfp != NULL)
6677c478bd9Sstevel@tonic-gate 			(void) sm_io_close(e->e_xfp, SM_TIME_DEFAULT);
6687c478bd9Sstevel@tonic-gate 		if (e->e_dfp != NULL)
6697c478bd9Sstevel@tonic-gate 			(void) sm_io_close(e->e_dfp, SM_TIME_DEFAULT);
6707c478bd9Sstevel@tonic-gate 		e->e_xfp = e->e_dfp = NULL;
6717c478bd9Sstevel@tonic-gate 	}
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate 	/*
6747c478bd9Sstevel@tonic-gate 	**  Copy BlankEnvelope into *e.
6757c478bd9Sstevel@tonic-gate 	**  It is not safe to simply copy pointers to strings;
6767c478bd9Sstevel@tonic-gate 	**  the strings themselves must be copied (or set to NULL).
6777c478bd9Sstevel@tonic-gate 	**  The problem is that when we assign a new string value to
6787c478bd9Sstevel@tonic-gate 	**  a member of BlankEnvelope, we free the old string.
6797c478bd9Sstevel@tonic-gate 	**  We did not need to do this copying in sendmail 8.11 :-(
6807c478bd9Sstevel@tonic-gate 	**  and it is a potential performance hit.  Reference counted
6817c478bd9Sstevel@tonic-gate 	**  strings are one way out.
6827c478bd9Sstevel@tonic-gate 	*/
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate 	*e = BlankEnvelope;
6857c478bd9Sstevel@tonic-gate 	e->e_message = NULL;
6867c478bd9Sstevel@tonic-gate 	e->e_qfletter = '\0';
6877c478bd9Sstevel@tonic-gate 	e->e_quarmsg = NULL;
6887c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{quarantine}"), "");
6897c478bd9Sstevel@tonic-gate 
6907c478bd9Sstevel@tonic-gate 	/*
6917c478bd9Sstevel@tonic-gate 	**  Copy the macro table.
6927c478bd9Sstevel@tonic-gate 	**  We might be able to avoid this by zeroing the macro table
6937c478bd9Sstevel@tonic-gate 	**  and always searching BlankEnvelope.e_macro after e->e_macro
6947c478bd9Sstevel@tonic-gate 	**  in macvalue().
6957c478bd9Sstevel@tonic-gate 	*/
6967c478bd9Sstevel@tonic-gate 
6977c478bd9Sstevel@tonic-gate 	for (p = &e->e_macro.mac_table[0];
6987c478bd9Sstevel@tonic-gate 	     p <= &e->e_macro.mac_table[MAXMACROID];
6997c478bd9Sstevel@tonic-gate 	     ++p)
7007c478bd9Sstevel@tonic-gate 	{
7017c478bd9Sstevel@tonic-gate 		if (*p != NULL)
7027c478bd9Sstevel@tonic-gate 			*p = sm_rpool_strdup_x(rpool, *p);
7037c478bd9Sstevel@tonic-gate 	}
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate 	/*
7067c478bd9Sstevel@tonic-gate 	**  XXX There are many strings in the envelope structure
7077c478bd9Sstevel@tonic-gate 	**  XXX that we are not attempting to copy here.
7087c478bd9Sstevel@tonic-gate 	**  XXX Investigate this further.
7097c478bd9Sstevel@tonic-gate 	*/
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate 	e->e_rpool = rpool;
7127c478bd9Sstevel@tonic-gate 	e->e_macro.mac_rpool = rpool;
7137c478bd9Sstevel@tonic-gate 	if (Verbose)
7147c478bd9Sstevel@tonic-gate 		set_delivery_mode(SM_DELIVER, e);
7157c478bd9Sstevel@tonic-gate 	bh = BlankEnvelope.e_header;
7167c478bd9Sstevel@tonic-gate 	nhp = &e->e_header;
7177c478bd9Sstevel@tonic-gate 	while (bh != NULL)
7187c478bd9Sstevel@tonic-gate 	{
719058561cbSjbeck 		*nhp = (HDR *) sm_rpool_malloc_x(rpool, sizeof(*bh));
720058561cbSjbeck 		memmove((char *) *nhp, (char *) bh, sizeof(*bh));
7217c478bd9Sstevel@tonic-gate 		bh = bh->h_link;
7227c478bd9Sstevel@tonic-gate 		nhp = &(*nhp)->h_link;
7237c478bd9Sstevel@tonic-gate 	}
724*e9af4bc0SJohn Beck #if _FFR_MILTER_ENHSC
725*e9af4bc0SJohn Beck 	e->e_enhsc[0] = '\0';
726*e9af4bc0SJohn Beck #endif /* _FFR_MILTER_ENHSC */
7277c478bd9Sstevel@tonic-gate }
7287c478bd9Sstevel@tonic-gate /*
7297c478bd9Sstevel@tonic-gate **  INITSYS -- initialize instantiation of system
7307c478bd9Sstevel@tonic-gate **
7317c478bd9Sstevel@tonic-gate **	In Daemon mode, this is done in the child.
7327c478bd9Sstevel@tonic-gate **
7337c478bd9Sstevel@tonic-gate **	Parameters:
7347c478bd9Sstevel@tonic-gate **		e -- the envelope to use.
7357c478bd9Sstevel@tonic-gate **
7367c478bd9Sstevel@tonic-gate **	Returns:
7377c478bd9Sstevel@tonic-gate **		none.
7387c478bd9Sstevel@tonic-gate **
7397c478bd9Sstevel@tonic-gate **	Side Effects:
7407c478bd9Sstevel@tonic-gate **		Initializes the system macros, some global variables,
7417c478bd9Sstevel@tonic-gate **		etc.  In particular, the current time in various
7427c478bd9Sstevel@tonic-gate **		forms is set.
7437c478bd9Sstevel@tonic-gate */
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate void
7467c478bd9Sstevel@tonic-gate initsys(e)
7477c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
7487c478bd9Sstevel@tonic-gate {
7497c478bd9Sstevel@tonic-gate 	char buf[10];
7507c478bd9Sstevel@tonic-gate #ifdef TTYNAME
7517c478bd9Sstevel@tonic-gate 	static char ybuf[60];			/* holds tty id */
7527c478bd9Sstevel@tonic-gate 	register char *p;
7537c478bd9Sstevel@tonic-gate 	extern char *ttyname();
7547c478bd9Sstevel@tonic-gate #endif /* TTYNAME */
7557c478bd9Sstevel@tonic-gate 
7567c478bd9Sstevel@tonic-gate 	/*
7577c478bd9Sstevel@tonic-gate 	**  Give this envelope a reality.
7587c478bd9Sstevel@tonic-gate 	**	I.e., an id, a transcript, and a creation time.
7597c478bd9Sstevel@tonic-gate 	**  We don't select the queue until all of the recipients are known.
7607c478bd9Sstevel@tonic-gate 	*/
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate 	openxscript(e);
7637c478bd9Sstevel@tonic-gate 	e->e_ctime = curtime();
7647c478bd9Sstevel@tonic-gate 	e->e_qfletter = '\0';
7657c478bd9Sstevel@tonic-gate 
7667c478bd9Sstevel@tonic-gate 	/*
7677c478bd9Sstevel@tonic-gate 	**  Set OutChannel to something useful if stdout isn't it.
7687c478bd9Sstevel@tonic-gate 	**	This arranges that any extra stuff the mailer produces
7697c478bd9Sstevel@tonic-gate 	**	gets sent back to the user on error (because it is
7707c478bd9Sstevel@tonic-gate 	**	tucked away in the transcript).
7717c478bd9Sstevel@tonic-gate 	*/
7727c478bd9Sstevel@tonic-gate 
7737c478bd9Sstevel@tonic-gate 	if (OpMode == MD_DAEMON && bitset(EF_QUEUERUN, e->e_flags) &&
7747c478bd9Sstevel@tonic-gate 	    e->e_xfp != NULL)
7757c478bd9Sstevel@tonic-gate 		OutChannel = e->e_xfp;
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate 	/*
7787c478bd9Sstevel@tonic-gate 	**  Set up some basic system macros.
7797c478bd9Sstevel@tonic-gate 	*/
7807c478bd9Sstevel@tonic-gate 
7817c478bd9Sstevel@tonic-gate 	/* process id */
782058561cbSjbeck 	(void) sm_snprintf(buf, sizeof(buf), "%d", (int) CurrentPid);
7837c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_TEMP, 'p', buf);
7847c478bd9Sstevel@tonic-gate 
7857c478bd9Sstevel@tonic-gate 	/* hop count */
786058561cbSjbeck 	(void) sm_snprintf(buf, sizeof(buf), "%d", e->e_hopcount);
7877c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_TEMP, 'c', buf);
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate 	/* time as integer, unix time, arpa time */
7907c478bd9Sstevel@tonic-gate 	settime(e);
7917c478bd9Sstevel@tonic-gate 
7927c478bd9Sstevel@tonic-gate 	/* Load average */
7937c478bd9Sstevel@tonic-gate 	sm_getla();
7947c478bd9Sstevel@tonic-gate 
7957c478bd9Sstevel@tonic-gate #ifdef TTYNAME
7967c478bd9Sstevel@tonic-gate 	/* tty name */
7977c478bd9Sstevel@tonic-gate 	if (macvalue('y', e) == NULL)
7987c478bd9Sstevel@tonic-gate 	{
7997c478bd9Sstevel@tonic-gate 		p = ttyname(2);
8007c478bd9Sstevel@tonic-gate 		if (p != NULL)
8017c478bd9Sstevel@tonic-gate 		{
8027c478bd9Sstevel@tonic-gate 			if (strrchr(p, '/') != NULL)
8037c478bd9Sstevel@tonic-gate 				p = strrchr(p, '/') + 1;
804058561cbSjbeck 			(void) sm_strlcpy(ybuf, sizeof(ybuf), p);
8057c478bd9Sstevel@tonic-gate 			macdefine(&e->e_macro, A_PERM, 'y', ybuf);
8067c478bd9Sstevel@tonic-gate 		}
8077c478bd9Sstevel@tonic-gate 	}
8087c478bd9Sstevel@tonic-gate #endif /* TTYNAME */
8097c478bd9Sstevel@tonic-gate }
8107c478bd9Sstevel@tonic-gate /*
8117c478bd9Sstevel@tonic-gate **  SETTIME -- set the current time.
8127c478bd9Sstevel@tonic-gate **
8137c478bd9Sstevel@tonic-gate **	Parameters:
8147c478bd9Sstevel@tonic-gate **		e -- the envelope in which the macros should be set.
8157c478bd9Sstevel@tonic-gate **
8167c478bd9Sstevel@tonic-gate **	Returns:
8177c478bd9Sstevel@tonic-gate **		none.
8187c478bd9Sstevel@tonic-gate **
8197c478bd9Sstevel@tonic-gate **	Side Effects:
8207c478bd9Sstevel@tonic-gate **		Sets the various time macros -- $a, $b, $d, $t.
8217c478bd9Sstevel@tonic-gate */
8227c478bd9Sstevel@tonic-gate 
8237c478bd9Sstevel@tonic-gate void
8247c478bd9Sstevel@tonic-gate settime(e)
8257c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
8267c478bd9Sstevel@tonic-gate {
8277c478bd9Sstevel@tonic-gate 	register char *p;
8287c478bd9Sstevel@tonic-gate 	auto time_t now;
8297c478bd9Sstevel@tonic-gate 	char buf[30];
8307c478bd9Sstevel@tonic-gate 	register struct tm *tm;
8317c478bd9Sstevel@tonic-gate 
8327c478bd9Sstevel@tonic-gate 	now = curtime();
833058561cbSjbeck 	(void) sm_snprintf(buf, sizeof(buf), "%ld", (long) now);
8347c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_TEMP, macid("{time}"), buf);
8357c478bd9Sstevel@tonic-gate 	tm = gmtime(&now);
836058561cbSjbeck 	(void) sm_snprintf(buf, sizeof(buf), "%04d%02d%02d%02d%02d",
8377c478bd9Sstevel@tonic-gate 			   tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
8387c478bd9Sstevel@tonic-gate 			   tm->tm_hour, tm->tm_min);
8397c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_TEMP, 't', buf);
840058561cbSjbeck 	(void) sm_strlcpy(buf, ctime(&now), sizeof(buf));
8417c478bd9Sstevel@tonic-gate 	p = strchr(buf, '\n');
8427c478bd9Sstevel@tonic-gate 	if (p != NULL)
8437c478bd9Sstevel@tonic-gate 		*p = '\0';
8447c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_TEMP, 'd', buf);
8457c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_TEMP, 'b', arpadate(buf));
8467c478bd9Sstevel@tonic-gate 	if (macvalue('a', e) == NULL)
8477c478bd9Sstevel@tonic-gate 		macdefine(&e->e_macro, A_PERM, 'a', macvalue('b', e));
8487c478bd9Sstevel@tonic-gate }
8497c478bd9Sstevel@tonic-gate /*
8507c478bd9Sstevel@tonic-gate **  OPENXSCRIPT -- Open transcript file
8517c478bd9Sstevel@tonic-gate **
8527c478bd9Sstevel@tonic-gate **	Creates a transcript file for possible eventual mailing or
8537c478bd9Sstevel@tonic-gate **	sending back.
8547c478bd9Sstevel@tonic-gate **
8557c478bd9Sstevel@tonic-gate **	Parameters:
8567c478bd9Sstevel@tonic-gate **		e -- the envelope to create the transcript in/for.
8577c478bd9Sstevel@tonic-gate **
8587c478bd9Sstevel@tonic-gate **	Returns:
8597c478bd9Sstevel@tonic-gate **		none
8607c478bd9Sstevel@tonic-gate **
8617c478bd9Sstevel@tonic-gate **	Side Effects:
8627c478bd9Sstevel@tonic-gate **		Creates the transcript file.
8637c478bd9Sstevel@tonic-gate */
8647c478bd9Sstevel@tonic-gate 
8657c478bd9Sstevel@tonic-gate #ifndef O_APPEND
8667c478bd9Sstevel@tonic-gate # define O_APPEND	0
8677c478bd9Sstevel@tonic-gate #endif /* ! O_APPEND */
8687c478bd9Sstevel@tonic-gate 
8697c478bd9Sstevel@tonic-gate void
8707c478bd9Sstevel@tonic-gate openxscript(e)
8717c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
8727c478bd9Sstevel@tonic-gate {
8737c478bd9Sstevel@tonic-gate 	register char *p;
8747c478bd9Sstevel@tonic-gate 
8757c478bd9Sstevel@tonic-gate 	if (e->e_xfp != NULL)
8767c478bd9Sstevel@tonic-gate 		return;
8777c478bd9Sstevel@tonic-gate 
8787c478bd9Sstevel@tonic-gate #if 0
8797c478bd9Sstevel@tonic-gate 	if (e->e_lockfp == NULL && bitset(EF_INQUEUE, e->e_flags))
8807c478bd9Sstevel@tonic-gate 		syserr("openxscript: job not locked");
8817c478bd9Sstevel@tonic-gate #endif /* 0 */
8827c478bd9Sstevel@tonic-gate 
8837c478bd9Sstevel@tonic-gate 	p = queuename(e, XSCRPT_LETTER);
8847c478bd9Sstevel@tonic-gate 	e->e_xfp = bfopen(p, FileMode, XscriptFileBufferSize,
8857c478bd9Sstevel@tonic-gate 			  SFF_NOTEXCL|SFF_OPENASROOT);
8867c478bd9Sstevel@tonic-gate 
8877c478bd9Sstevel@tonic-gate 	if (e->e_xfp == NULL)
8887c478bd9Sstevel@tonic-gate 	{
8897c478bd9Sstevel@tonic-gate 		syserr("Can't create transcript file %s", p);
8907c478bd9Sstevel@tonic-gate 		e->e_xfp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT,
8917c478bd9Sstevel@tonic-gate 				      SM_PATH_DEVNULL, SM_IO_RDWR, NULL);
8927c478bd9Sstevel@tonic-gate 		if (e->e_xfp == NULL)
8937c478bd9Sstevel@tonic-gate 			syserr("!Can't open %s", SM_PATH_DEVNULL);
8947c478bd9Sstevel@tonic-gate 	}
8957c478bd9Sstevel@tonic-gate 	(void) sm_io_setvbuf(e->e_xfp, SM_TIME_DEFAULT, NULL, SM_IO_LBF, 0);
8967c478bd9Sstevel@tonic-gate 	if (tTd(46, 9))
8977c478bd9Sstevel@tonic-gate 	{
8987c478bd9Sstevel@tonic-gate 		sm_dprintf("openxscript(%s):\n  ", p);
8997c478bd9Sstevel@tonic-gate 		dumpfd(sm_io_getinfo(e->e_xfp, SM_IO_WHAT_FD, NULL), true,
9007c478bd9Sstevel@tonic-gate 		       false);
9017c478bd9Sstevel@tonic-gate 	}
9027c478bd9Sstevel@tonic-gate }
9037c478bd9Sstevel@tonic-gate /*
9047c478bd9Sstevel@tonic-gate **  CLOSEXSCRIPT -- close the transcript file.
9057c478bd9Sstevel@tonic-gate **
9067c478bd9Sstevel@tonic-gate **	Parameters:
9077c478bd9Sstevel@tonic-gate **		e -- the envelope containing the transcript to close.
9087c478bd9Sstevel@tonic-gate **
9097c478bd9Sstevel@tonic-gate **	Returns:
9107c478bd9Sstevel@tonic-gate **		none.
9117c478bd9Sstevel@tonic-gate **
9127c478bd9Sstevel@tonic-gate **	Side Effects:
9137c478bd9Sstevel@tonic-gate **		none.
9147c478bd9Sstevel@tonic-gate */
9157c478bd9Sstevel@tonic-gate 
9167c478bd9Sstevel@tonic-gate void
9177c478bd9Sstevel@tonic-gate closexscript(e)
9187c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
9197c478bd9Sstevel@tonic-gate {
9207c478bd9Sstevel@tonic-gate 	if (e->e_xfp == NULL)
9217c478bd9Sstevel@tonic-gate 		return;
9227c478bd9Sstevel@tonic-gate #if 0
9237c478bd9Sstevel@tonic-gate 	if (e->e_lockfp == NULL)
9247c478bd9Sstevel@tonic-gate 		syserr("closexscript: job not locked");
9257c478bd9Sstevel@tonic-gate #endif /* 0 */
9267c478bd9Sstevel@tonic-gate 	(void) sm_io_close(e->e_xfp, SM_TIME_DEFAULT);
9277c478bd9Sstevel@tonic-gate 	e->e_xfp = NULL;
9287c478bd9Sstevel@tonic-gate }
9297c478bd9Sstevel@tonic-gate /*
9307c478bd9Sstevel@tonic-gate **  SETSENDER -- set the person who this message is from
9317c478bd9Sstevel@tonic-gate **
9327c478bd9Sstevel@tonic-gate **	Under certain circumstances allow the user to say who
9337c478bd9Sstevel@tonic-gate **	s/he is (using -f or -r).  These are:
9347c478bd9Sstevel@tonic-gate **	1.  The user's uid is zero (root).
9357c478bd9Sstevel@tonic-gate **	2.  The user's login name is in an approved list (typically
9367c478bd9Sstevel@tonic-gate **	    from a network server).
9377c478bd9Sstevel@tonic-gate **	3.  The address the user is trying to claim has a
9387c478bd9Sstevel@tonic-gate **	    "!" character in it (since #2 doesn't do it for
9397c478bd9Sstevel@tonic-gate **	    us if we are dialing out for UUCP).
9407c478bd9Sstevel@tonic-gate **	A better check to replace #3 would be if the
9417c478bd9Sstevel@tonic-gate **	effective uid is "UUCP" -- this would require me
9427c478bd9Sstevel@tonic-gate **	to rewrite getpwent to "grab" uucp as it went by,
9437c478bd9Sstevel@tonic-gate **	make getname more nasty, do another passwd file
9447c478bd9Sstevel@tonic-gate **	scan, or compile the UID of "UUCP" into the code,
9457c478bd9Sstevel@tonic-gate **	all of which are reprehensible.
9467c478bd9Sstevel@tonic-gate **
9477c478bd9Sstevel@tonic-gate **	Assuming all of these fail, we figure out something
9487c478bd9Sstevel@tonic-gate **	ourselves.
9497c478bd9Sstevel@tonic-gate **
9507c478bd9Sstevel@tonic-gate **	Parameters:
9517c478bd9Sstevel@tonic-gate **		from -- the person we would like to believe this message
9527c478bd9Sstevel@tonic-gate **			is from, as specified on the command line.
9537c478bd9Sstevel@tonic-gate **		e -- the envelope in which we would like the sender set.
9547c478bd9Sstevel@tonic-gate **		delimptr -- if non-NULL, set to the location of the
9557c478bd9Sstevel@tonic-gate **			trailing delimiter.
9567c478bd9Sstevel@tonic-gate **		delimchar -- the character that will delimit the sender
9577c478bd9Sstevel@tonic-gate **			address.
9587c478bd9Sstevel@tonic-gate **		internal -- set if this address is coming from an internal
9597c478bd9Sstevel@tonic-gate **			source such as an owner alias.
9607c478bd9Sstevel@tonic-gate **
9617c478bd9Sstevel@tonic-gate **	Returns:
9627c478bd9Sstevel@tonic-gate **		none.
9637c478bd9Sstevel@tonic-gate **
9647c478bd9Sstevel@tonic-gate **	Side Effects:
9657c478bd9Sstevel@tonic-gate **		sets sendmail's notion of who the from person is.
9667c478bd9Sstevel@tonic-gate */
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate void
9697c478bd9Sstevel@tonic-gate setsender(from, e, delimptr, delimchar, internal)
9707c478bd9Sstevel@tonic-gate 	char *from;
9717c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
9727c478bd9Sstevel@tonic-gate 	char **delimptr;
9737c478bd9Sstevel@tonic-gate 	int delimchar;
9747c478bd9Sstevel@tonic-gate 	bool internal;
9757c478bd9Sstevel@tonic-gate {
9767c478bd9Sstevel@tonic-gate 	register char **pvp;
9777c478bd9Sstevel@tonic-gate 	char *realname = NULL;
9787c478bd9Sstevel@tonic-gate 	char *bp;
9797c478bd9Sstevel@tonic-gate 	char buf[MAXNAME + 2];
9807c478bd9Sstevel@tonic-gate 	char pvpbuf[PSBUFSIZE];
9817c478bd9Sstevel@tonic-gate 	extern char *FullName;
9827c478bd9Sstevel@tonic-gate 
9837c478bd9Sstevel@tonic-gate 	if (tTd(45, 1))
9847c478bd9Sstevel@tonic-gate 		sm_dprintf("setsender(%s)\n", from == NULL ? "" : from);
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate 	/* may be set from earlier calls */
9877c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, 'x', "");
9887c478bd9Sstevel@tonic-gate 
9897c478bd9Sstevel@tonic-gate 	/*
9907c478bd9Sstevel@tonic-gate 	**  Figure out the real user executing us.
9917c478bd9Sstevel@tonic-gate 	**	Username can return errno != 0 on non-errors.
9927c478bd9Sstevel@tonic-gate 	*/
9937c478bd9Sstevel@tonic-gate 
9947c478bd9Sstevel@tonic-gate 	if (bitset(EF_QUEUERUN, e->e_flags) || OpMode == MD_SMTP ||
9957c478bd9Sstevel@tonic-gate 	    OpMode == MD_ARPAFTP || OpMode == MD_DAEMON)
9967c478bd9Sstevel@tonic-gate 		realname = from;
9977c478bd9Sstevel@tonic-gate 	if (realname == NULL || realname[0] == '\0')
9987c478bd9Sstevel@tonic-gate 		realname = username();
9997c478bd9Sstevel@tonic-gate 
10007c478bd9Sstevel@tonic-gate 	if (ConfigLevel < 2)
10017c478bd9Sstevel@tonic-gate 		SuprErrs = true;
10027c478bd9Sstevel@tonic-gate 
10037c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{addr_type}"), "e s");
10047c478bd9Sstevel@tonic-gate 
10057c478bd9Sstevel@tonic-gate 	/* preset state for then clause in case from == NULL */
10067c478bd9Sstevel@tonic-gate 	e->e_from.q_state = QS_BADADDR;
10077c478bd9Sstevel@tonic-gate 	e->e_from.q_flags = 0;
10087c478bd9Sstevel@tonic-gate 	if (from == NULL ||
10097c478bd9Sstevel@tonic-gate 	    parseaddr(from, &e->e_from, RF_COPYALL|RF_SENDERADDR,
10107c478bd9Sstevel@tonic-gate 		      delimchar, delimptr, e, false) == NULL ||
10117c478bd9Sstevel@tonic-gate 	    QS_IS_BADADDR(e->e_from.q_state) ||
10127c478bd9Sstevel@tonic-gate 	    e->e_from.q_mailer == ProgMailer ||
10137c478bd9Sstevel@tonic-gate 	    e->e_from.q_mailer == FileMailer ||
10147c478bd9Sstevel@tonic-gate 	    e->e_from.q_mailer == InclMailer)
10157c478bd9Sstevel@tonic-gate 	{
10167c478bd9Sstevel@tonic-gate 		/* log garbage addresses for traceback */
10177c478bd9Sstevel@tonic-gate 		if (from != NULL && LogLevel > 2)
10187c478bd9Sstevel@tonic-gate 		{
10197c478bd9Sstevel@tonic-gate 			char *p;
10207c478bd9Sstevel@tonic-gate 			char ebuf[MAXNAME * 2 + 2];
10217c478bd9Sstevel@tonic-gate 
10227c478bd9Sstevel@tonic-gate 			p = macvalue('_', e);
10237c478bd9Sstevel@tonic-gate 			if (p == NULL)
10247c478bd9Sstevel@tonic-gate 			{
10257c478bd9Sstevel@tonic-gate 				char *host = RealHostName;
10267c478bd9Sstevel@tonic-gate 
10277c478bd9Sstevel@tonic-gate 				if (host == NULL)
10287c478bd9Sstevel@tonic-gate 					host = MyHostName;
1029058561cbSjbeck 				(void) sm_snprintf(ebuf, sizeof(ebuf),
10307c478bd9Sstevel@tonic-gate 						   "%.*s@%.*s", MAXNAME,
10317c478bd9Sstevel@tonic-gate 						   realname, MAXNAME, host);
10327c478bd9Sstevel@tonic-gate 				p = ebuf;
10337c478bd9Sstevel@tonic-gate 			}
10347c478bd9Sstevel@tonic-gate 			sm_syslog(LOG_NOTICE, e->e_id,
10357c478bd9Sstevel@tonic-gate 				  "setsender: %s: invalid or unparsable, received from %s",
10367c478bd9Sstevel@tonic-gate 				  shortenstring(from, 83), p);
10377c478bd9Sstevel@tonic-gate 		}
10387c478bd9Sstevel@tonic-gate 		if (from != NULL)
10397c478bd9Sstevel@tonic-gate 		{
10407c478bd9Sstevel@tonic-gate 			if (!QS_IS_BADADDR(e->e_from.q_state))
10417c478bd9Sstevel@tonic-gate 			{
10427c478bd9Sstevel@tonic-gate 				/* it was a bogus mailer in the from addr */
10437c478bd9Sstevel@tonic-gate 				e->e_status = "5.1.7";
10447c478bd9Sstevel@tonic-gate 				usrerrenh(e->e_status,
10457c478bd9Sstevel@tonic-gate 					  "553 Invalid sender address");
10467c478bd9Sstevel@tonic-gate 			}
10477c478bd9Sstevel@tonic-gate 			SuprErrs = true;
10487c478bd9Sstevel@tonic-gate 		}
10497c478bd9Sstevel@tonic-gate 		if (from == realname ||
10507c478bd9Sstevel@tonic-gate 		    parseaddr(from = realname,
10517c478bd9Sstevel@tonic-gate 			      &e->e_from, RF_COPYALL|RF_SENDERADDR, ' ',
10527c478bd9Sstevel@tonic-gate 			      NULL, e, false) == NULL)
10537c478bd9Sstevel@tonic-gate 		{
10547c478bd9Sstevel@tonic-gate 			char nbuf[100];
10557c478bd9Sstevel@tonic-gate 
10567c478bd9Sstevel@tonic-gate 			SuprErrs = true;
1057058561cbSjbeck 			expand("\201n", nbuf, sizeof(nbuf), e);
10587c478bd9Sstevel@tonic-gate 			from = sm_rpool_strdup_x(e->e_rpool, nbuf);
10597c478bd9Sstevel@tonic-gate 			if (parseaddr(from, &e->e_from, RF_COPYALL, ' ',
10607c478bd9Sstevel@tonic-gate 				      NULL, e, false) == NULL &&
10617c478bd9Sstevel@tonic-gate 			    parseaddr(from = "postmaster", &e->e_from,
10627c478bd9Sstevel@tonic-gate 				      RF_COPYALL, ' ', NULL, e, false) == NULL)
10637c478bd9Sstevel@tonic-gate 				syserr("553 5.3.0 setsender: can't even parse postmaster!");
10647c478bd9Sstevel@tonic-gate 		}
10657c478bd9Sstevel@tonic-gate 	}
10667c478bd9Sstevel@tonic-gate 	else
10677c478bd9Sstevel@tonic-gate 		FromFlag = true;
10687c478bd9Sstevel@tonic-gate 	e->e_from.q_state = QS_SENDER;
10697c478bd9Sstevel@tonic-gate 	if (tTd(45, 5))
10707c478bd9Sstevel@tonic-gate 	{
10717c478bd9Sstevel@tonic-gate 		sm_dprintf("setsender: QS_SENDER ");
10727c478bd9Sstevel@tonic-gate 		printaddr(sm_debug_file(), &e->e_from, false);
10737c478bd9Sstevel@tonic-gate 	}
10747c478bd9Sstevel@tonic-gate 	SuprErrs = false;
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate #if USERDB
10777c478bd9Sstevel@tonic-gate 	if (bitnset(M_CHECKUDB, e->e_from.q_mailer->m_flags))
10787c478bd9Sstevel@tonic-gate 	{
10797c478bd9Sstevel@tonic-gate 		register char *p;
10807c478bd9Sstevel@tonic-gate 
10817c478bd9Sstevel@tonic-gate 		p = udbsender(e->e_from.q_user, e->e_rpool);
10827c478bd9Sstevel@tonic-gate 		if (p != NULL)
10837c478bd9Sstevel@tonic-gate 			from = p;
10847c478bd9Sstevel@tonic-gate 	}
10857c478bd9Sstevel@tonic-gate #endif /* USERDB */
10867c478bd9Sstevel@tonic-gate 
10877c478bd9Sstevel@tonic-gate 	if (bitnset(M_HASPWENT, e->e_from.q_mailer->m_flags))
10887c478bd9Sstevel@tonic-gate 	{
10897c478bd9Sstevel@tonic-gate 		SM_MBDB_T user;
10907c478bd9Sstevel@tonic-gate 
10917c478bd9Sstevel@tonic-gate 		if (!internal)
10927c478bd9Sstevel@tonic-gate 		{
10937c478bd9Sstevel@tonic-gate 			/* if the user already given fullname don't redefine */
10947c478bd9Sstevel@tonic-gate 			if (FullName == NULL)
10957c478bd9Sstevel@tonic-gate 				FullName = macvalue('x', e);
10967c478bd9Sstevel@tonic-gate 			if (FullName != NULL)
10977c478bd9Sstevel@tonic-gate 			{
10987c478bd9Sstevel@tonic-gate 				if (FullName[0] == '\0')
10997c478bd9Sstevel@tonic-gate 					FullName = NULL;
11007c478bd9Sstevel@tonic-gate 				else
11017c478bd9Sstevel@tonic-gate 					FullName = newstr(FullName);
11027c478bd9Sstevel@tonic-gate 			}
11037c478bd9Sstevel@tonic-gate 		}
11047c478bd9Sstevel@tonic-gate 
11057c478bd9Sstevel@tonic-gate 		if (e->e_from.q_user[0] != '\0' &&
11067c478bd9Sstevel@tonic-gate 		    sm_mbdb_lookup(e->e_from.q_user, &user) == EX_OK)
11077c478bd9Sstevel@tonic-gate 		{
11087c478bd9Sstevel@tonic-gate 			/*
11097c478bd9Sstevel@tonic-gate 			**  Process passwd file entry.
11107c478bd9Sstevel@tonic-gate 			*/
11117c478bd9Sstevel@tonic-gate 
11127c478bd9Sstevel@tonic-gate 			/* extract home directory */
11137c478bd9Sstevel@tonic-gate 			if (*user.mbdb_homedir == '\0')
11147c478bd9Sstevel@tonic-gate 				e->e_from.q_home = NULL;
11157c478bd9Sstevel@tonic-gate 			else if (strcmp(user.mbdb_homedir, "/") == 0)
11167c478bd9Sstevel@tonic-gate 				e->e_from.q_home = "";
11177c478bd9Sstevel@tonic-gate 			else
11187c478bd9Sstevel@tonic-gate 				e->e_from.q_home = sm_rpool_strdup_x(e->e_rpool,
11197c478bd9Sstevel@tonic-gate 							user.mbdb_homedir);
11207c478bd9Sstevel@tonic-gate 			macdefine(&e->e_macro, A_PERM, 'z', e->e_from.q_home);
11217c478bd9Sstevel@tonic-gate 
11227c478bd9Sstevel@tonic-gate 			/* extract user and group id */
11237c478bd9Sstevel@tonic-gate 			if (user.mbdb_uid != SM_NO_UID)
11247c478bd9Sstevel@tonic-gate 			{
11257c478bd9Sstevel@tonic-gate 				e->e_from.q_uid = user.mbdb_uid;
11267c478bd9Sstevel@tonic-gate 				e->e_from.q_gid = user.mbdb_gid;
11277c478bd9Sstevel@tonic-gate 				e->e_from.q_flags |= QGOODUID;
11287c478bd9Sstevel@tonic-gate 			}
11297c478bd9Sstevel@tonic-gate 
11307c478bd9Sstevel@tonic-gate 			/* extract full name from passwd file */
11317c478bd9Sstevel@tonic-gate 			if (FullName == NULL && !internal &&
11327c478bd9Sstevel@tonic-gate 			    user.mbdb_fullname[0] != '\0' &&
11337c478bd9Sstevel@tonic-gate 			    strcmp(user.mbdb_name, e->e_from.q_user) == 0)
11347c478bd9Sstevel@tonic-gate 			{
11357c478bd9Sstevel@tonic-gate 				FullName = newstr(user.mbdb_fullname);
11367c478bd9Sstevel@tonic-gate 			}
11377c478bd9Sstevel@tonic-gate 		}
11387c478bd9Sstevel@tonic-gate 		else
11397c478bd9Sstevel@tonic-gate 		{
11407c478bd9Sstevel@tonic-gate 			e->e_from.q_home = NULL;
11417c478bd9Sstevel@tonic-gate 		}
11427c478bd9Sstevel@tonic-gate 		if (FullName != NULL && !internal)
11437c478bd9Sstevel@tonic-gate 			macdefine(&e->e_macro, A_TEMP, 'x', FullName);
11447c478bd9Sstevel@tonic-gate 	}
11457c478bd9Sstevel@tonic-gate 	else if (!internal && OpMode != MD_DAEMON && OpMode != MD_SMTP)
11467c478bd9Sstevel@tonic-gate 	{
11477c478bd9Sstevel@tonic-gate 		if (e->e_from.q_home == NULL)
11487c478bd9Sstevel@tonic-gate 		{
11497c478bd9Sstevel@tonic-gate 			e->e_from.q_home = getenv("HOME");
11507c478bd9Sstevel@tonic-gate 			if (e->e_from.q_home != NULL)
11517c478bd9Sstevel@tonic-gate 			{
11527c478bd9Sstevel@tonic-gate 				if (*e->e_from.q_home == '\0')
11537c478bd9Sstevel@tonic-gate 					e->e_from.q_home = NULL;
11547c478bd9Sstevel@tonic-gate 				else if (strcmp(e->e_from.q_home, "/") == 0)
11557c478bd9Sstevel@tonic-gate 					e->e_from.q_home++;
11567c478bd9Sstevel@tonic-gate 			}
11577c478bd9Sstevel@tonic-gate 		}
11587c478bd9Sstevel@tonic-gate 		e->e_from.q_uid = RealUid;
11597c478bd9Sstevel@tonic-gate 		e->e_from.q_gid = RealGid;
11607c478bd9Sstevel@tonic-gate 		e->e_from.q_flags |= QGOODUID;
11617c478bd9Sstevel@tonic-gate 	}
11627c478bd9Sstevel@tonic-gate 
11637c478bd9Sstevel@tonic-gate 	/*
11647c478bd9Sstevel@tonic-gate 	**  Rewrite the from person to dispose of possible implicit
11657c478bd9Sstevel@tonic-gate 	**	links in the net.
11667c478bd9Sstevel@tonic-gate 	*/
11677c478bd9Sstevel@tonic-gate 
1168058561cbSjbeck 	pvp = prescan(from, delimchar, pvpbuf, sizeof(pvpbuf), NULL,
1169058561cbSjbeck 			IntTokenTab, false);
11707c478bd9Sstevel@tonic-gate 	if (pvp == NULL)
11717c478bd9Sstevel@tonic-gate 	{
11727c478bd9Sstevel@tonic-gate 		/* don't need to give error -- prescan did that already */
11737c478bd9Sstevel@tonic-gate 		if (LogLevel > 2)
11747c478bd9Sstevel@tonic-gate 			sm_syslog(LOG_NOTICE, e->e_id,
11757c478bd9Sstevel@tonic-gate 				  "cannot prescan from (%s)",
11767c478bd9Sstevel@tonic-gate 				  shortenstring(from, MAXSHORTSTR));
11777c478bd9Sstevel@tonic-gate 		finis(true, true, ExitStat);
11787c478bd9Sstevel@tonic-gate 	}
11797c478bd9Sstevel@tonic-gate 	(void) REWRITE(pvp, 3, e);
11807c478bd9Sstevel@tonic-gate 	(void) REWRITE(pvp, 1, e);
11817c478bd9Sstevel@tonic-gate 	(void) REWRITE(pvp, 4, e);
11827c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{addr_type}"), NULL);
11837c478bd9Sstevel@tonic-gate 	bp = buf + 1;
1184058561cbSjbeck 	cataddr(pvp, NULL, bp, sizeof(buf) - 2, '\0', false);
11857c478bd9Sstevel@tonic-gate 	if (*bp == '@' && !bitnset(M_NOBRACKET, e->e_from.q_mailer->m_flags))
11867c478bd9Sstevel@tonic-gate 	{
11877c478bd9Sstevel@tonic-gate 		/* heuristic: route-addr: add angle brackets */
1188058561cbSjbeck 		(void) sm_strlcat(bp, ">", sizeof(buf) - 1);
11897c478bd9Sstevel@tonic-gate 		*--bp = '<';
11907c478bd9Sstevel@tonic-gate 	}
11917c478bd9Sstevel@tonic-gate 	e->e_sender = sm_rpool_strdup_x(e->e_rpool, bp);
11927c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, 'f', e->e_sender);
11937c478bd9Sstevel@tonic-gate 
11947c478bd9Sstevel@tonic-gate 	/* save the domain spec if this mailer wants it */
11957c478bd9Sstevel@tonic-gate 	if (e->e_from.q_mailer != NULL &&
11967c478bd9Sstevel@tonic-gate 	    bitnset(M_CANONICAL, e->e_from.q_mailer->m_flags))
11977c478bd9Sstevel@tonic-gate 	{
11987c478bd9Sstevel@tonic-gate 		char **lastat;
11997c478bd9Sstevel@tonic-gate 
12007c478bd9Sstevel@tonic-gate 		/* get rid of any pesky angle brackets */
12017c478bd9Sstevel@tonic-gate 		macdefine(&e->e_macro, A_PERM, macid("{addr_type}"), "e s");
12027c478bd9Sstevel@tonic-gate 		(void) REWRITE(pvp, 3, e);
12037c478bd9Sstevel@tonic-gate 		(void) REWRITE(pvp, 1, e);
12047c478bd9Sstevel@tonic-gate 		(void) REWRITE(pvp, 4, e);
12057c478bd9Sstevel@tonic-gate 		macdefine(&e->e_macro, A_PERM, macid("{addr_type}"), NULL);
12067c478bd9Sstevel@tonic-gate 
12077c478bd9Sstevel@tonic-gate 		/* strip off to the last "@" sign */
12087c478bd9Sstevel@tonic-gate 		for (lastat = NULL; *pvp != NULL; pvp++)
12097c478bd9Sstevel@tonic-gate 		{
12107c478bd9Sstevel@tonic-gate 			if (strcmp(*pvp, "@") == 0)
12117c478bd9Sstevel@tonic-gate 				lastat = pvp;
12127c478bd9Sstevel@tonic-gate 		}
12137c478bd9Sstevel@tonic-gate 		if (lastat != NULL)
12147c478bd9Sstevel@tonic-gate 		{
12157c478bd9Sstevel@tonic-gate 			e->e_fromdomain = copyplist(lastat, true, e->e_rpool);
12167c478bd9Sstevel@tonic-gate 			if (tTd(45, 3))
12177c478bd9Sstevel@tonic-gate 			{
12187c478bd9Sstevel@tonic-gate 				sm_dprintf("Saving from domain: ");
12197c478bd9Sstevel@tonic-gate 				printav(sm_debug_file(), e->e_fromdomain);
12207c478bd9Sstevel@tonic-gate 			}
12217c478bd9Sstevel@tonic-gate 		}
12227c478bd9Sstevel@tonic-gate 	}
12237c478bd9Sstevel@tonic-gate }
12247c478bd9Sstevel@tonic-gate /*
12257c478bd9Sstevel@tonic-gate **  PRINTENVFLAGS -- print envelope flags for debugging
12267c478bd9Sstevel@tonic-gate **
12277c478bd9Sstevel@tonic-gate **	Parameters:
12287c478bd9Sstevel@tonic-gate **		e -- the envelope with the flags to be printed.
12297c478bd9Sstevel@tonic-gate **
12307c478bd9Sstevel@tonic-gate **	Returns:
12317c478bd9Sstevel@tonic-gate **		none.
12327c478bd9Sstevel@tonic-gate */
12337c478bd9Sstevel@tonic-gate 
12347c478bd9Sstevel@tonic-gate struct eflags
12357c478bd9Sstevel@tonic-gate {
12367c478bd9Sstevel@tonic-gate 	char		*ef_name;
12377c478bd9Sstevel@tonic-gate 	unsigned long	ef_bit;
12387c478bd9Sstevel@tonic-gate };
12397c478bd9Sstevel@tonic-gate 
12407c478bd9Sstevel@tonic-gate static struct eflags	EnvelopeFlags[] =
12417c478bd9Sstevel@tonic-gate {
12427c478bd9Sstevel@tonic-gate 	{ "OLDSTYLE",		EF_OLDSTYLE	},
12437c478bd9Sstevel@tonic-gate 	{ "INQUEUE",		EF_INQUEUE	},
12447c478bd9Sstevel@tonic-gate 	{ "NO_BODY_RETN",	EF_NO_BODY_RETN	},
12457c478bd9Sstevel@tonic-gate 	{ "CLRQUEUE",		EF_CLRQUEUE	},
12467c478bd9Sstevel@tonic-gate 	{ "SENDRECEIPT",	EF_SENDRECEIPT	},
12477c478bd9Sstevel@tonic-gate 	{ "FATALERRS",		EF_FATALERRS	},
12487c478bd9Sstevel@tonic-gate 	{ "DELETE_BCC",		EF_DELETE_BCC	},
12497c478bd9Sstevel@tonic-gate 	{ "RESPONSE",		EF_RESPONSE	},
12507c478bd9Sstevel@tonic-gate 	{ "RESENT",		EF_RESENT	},
12517c478bd9Sstevel@tonic-gate 	{ "VRFYONLY",		EF_VRFYONLY	},
12527c478bd9Sstevel@tonic-gate 	{ "WARNING",		EF_WARNING	},
12537c478bd9Sstevel@tonic-gate 	{ "QUEUERUN",		EF_QUEUERUN	},
12547c478bd9Sstevel@tonic-gate 	{ "GLOBALERRS",		EF_GLOBALERRS	},
12557c478bd9Sstevel@tonic-gate 	{ "PM_NOTIFY",		EF_PM_NOTIFY	},
12567c478bd9Sstevel@tonic-gate 	{ "METOO",		EF_METOO	},
12577c478bd9Sstevel@tonic-gate 	{ "LOGSENDER",		EF_LOGSENDER	},
12587c478bd9Sstevel@tonic-gate 	{ "NORECEIPT",		EF_NORECEIPT	},
12597c478bd9Sstevel@tonic-gate 	{ "HAS8BIT",		EF_HAS8BIT	},
12607c478bd9Sstevel@tonic-gate 	{ "NL_NOT_EOL",		EF_NL_NOT_EOL	},
12617c478bd9Sstevel@tonic-gate 	{ "CRLF_NOT_EOL",	EF_CRLF_NOT_EOL	},
12627c478bd9Sstevel@tonic-gate 	{ "RET_PARAM",		EF_RET_PARAM	},
12637c478bd9Sstevel@tonic-gate 	{ "HAS_DF",		EF_HAS_DF	},
12647c478bd9Sstevel@tonic-gate 	{ "IS_MIME",		EF_IS_MIME	},
12657c478bd9Sstevel@tonic-gate 	{ "DONT_MIME",		EF_DONT_MIME	},
12667c478bd9Sstevel@tonic-gate 	{ "DISCARD",		EF_DISCARD	},
12677c478bd9Sstevel@tonic-gate 	{ "TOOBIG",		EF_TOOBIG	},
12687c478bd9Sstevel@tonic-gate 	{ "SPLIT",		EF_SPLIT	},
12697c478bd9Sstevel@tonic-gate 	{ "UNSAFE",		EF_UNSAFE	},
12707c478bd9Sstevel@tonic-gate 	{ NULL,			0		}
12717c478bd9Sstevel@tonic-gate };
12727c478bd9Sstevel@tonic-gate 
12737c478bd9Sstevel@tonic-gate void
12747c478bd9Sstevel@tonic-gate printenvflags(e)
12757c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
12767c478bd9Sstevel@tonic-gate {
12777c478bd9Sstevel@tonic-gate 	register struct eflags *ef;
12787c478bd9Sstevel@tonic-gate 	bool first = true;
12797c478bd9Sstevel@tonic-gate 
12807c478bd9Sstevel@tonic-gate 	sm_dprintf("%lx", e->e_flags);
12817c478bd9Sstevel@tonic-gate 	for (ef = EnvelopeFlags; ef->ef_name != NULL; ef++)
12827c478bd9Sstevel@tonic-gate 	{
12837c478bd9Sstevel@tonic-gate 		if (!bitset(ef->ef_bit, e->e_flags))
12847c478bd9Sstevel@tonic-gate 			continue;
12857c478bd9Sstevel@tonic-gate 		if (first)
12867c478bd9Sstevel@tonic-gate 			sm_dprintf("<%s", ef->ef_name);
12877c478bd9Sstevel@tonic-gate 		else
12887c478bd9Sstevel@tonic-gate 			sm_dprintf(",%s", ef->ef_name);
12897c478bd9Sstevel@tonic-gate 		first = false;
12907c478bd9Sstevel@tonic-gate 	}
12917c478bd9Sstevel@tonic-gate 	if (!first)
12927c478bd9Sstevel@tonic-gate 		sm_dprintf(">\n");
12937c478bd9Sstevel@tonic-gate }
1294