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