1 /*
2  * Copyright (c) 1983, 1995 Eric P. Allman
3  * Copyright (c) 1988, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * %sccs.include.redist.c%
7  *
8  *	@(#)sendmail.h	8.144 (Berkeley) 06/18/95
9  */
10 
11 /*
12 **  SENDMAIL.H -- Global definitions for sendmail.
13 */
14 
15 # ifdef _DEFINE
16 # define EXTERN
17 # ifndef lint
18 static char SmailSccsId[] =	"@(#)sendmail.h	8.144		06/18/95";
19 # endif
20 # else /*  _DEFINE */
21 # define EXTERN extern
22 # endif /* _DEFINE */
23 
24 # include <unistd.h>
25 # include <stddef.h>
26 # include <stdlib.h>
27 # include <stdio.h>
28 # include <ctype.h>
29 # include <setjmp.h>
30 # include <string.h>
31 # include <time.h>
32 # include <errno.h>
33 # ifdef EX_OK
34 #  undef EX_OK			/* for SVr4.2 SMP */
35 # endif
36 # include <sysexits.h>
37 
38 # include "conf.h"
39 # include "useful.h"
40 
41 # ifdef LOG
42 # include <syslog.h>
43 # endif /* LOG */
44 
45 # ifdef DAEMON
46 # include <sys/socket.h>
47 # endif
48 # if NETUNIX
49 # include <sys/un.h>
50 # endif
51 # if NETINET
52 # include <netinet/in.h>
53 # endif
54 # if NETISO
55 # include <netiso/iso.h>
56 # endif
57 # if NETNS
58 # include <netns/ns.h>
59 # endif
60 # if NETX25
61 # include <netccitt/x25.h>
62 # endif
63 
64 
65 
66 /* forward references for prototypes */
67 typedef struct envelope	ENVELOPE;
68 typedef struct mailer	MAILER;
69 
70 
71 /*
72 **  Data structure for bit maps.
73 **
74 **	Each bit in this map can be referenced by an ascii character.
75 **	This is 256 possible bits, or 32 8-bit bytes.
76 */
77 
78 #define BITMAPBYTES	32	/* number of bytes in a bit map */
79 #define BYTEBITS	8	/* number of bits in a byte */
80 
81 /* internal macros */
82 #define _BITWORD(bit)	((bit) / (BYTEBITS * sizeof (int)))
83 #define _BITBIT(bit)	(1 << ((bit) % (BYTEBITS * sizeof (int))))
84 
85 typedef int	BITMAP[BITMAPBYTES / sizeof (int)];
86 
87 /* test bit number N */
88 #define bitnset(bit, map)	((map)[_BITWORD(bit)] & _BITBIT(bit))
89 
90 /* set bit number N */
91 #define setbitn(bit, map)	(map)[_BITWORD(bit)] |= _BITBIT(bit)
92 
93 /* clear bit number N */
94 #define clrbitn(bit, map)	(map)[_BITWORD(bit)] &= ~_BITBIT(bit)
95 
96 /* clear an entire bit map */
97 #define clrbitmap(map)		bzero((char *) map, BITMAPBYTES)
98 /*
99 **  Address structure.
100 **	Addresses are stored internally in this structure.
101 */
102 
103 struct address
104 {
105 	char		*q_paddr;	/* the printname for the address */
106 	char		*q_user;	/* user name */
107 	char		*q_ruser;	/* real user name, or NULL if q_user */
108 	char		*q_host;	/* host name */
109 	struct mailer	*q_mailer;	/* mailer to use */
110 	u_long		q_flags;	/* status flags, see below */
111 	uid_t		q_uid;		/* user-id of receiver (if known) */
112 	gid_t		q_gid;		/* group-id of receiver (if known) */
113 	char		*q_home;	/* home dir (local mailer only) */
114 	char		*q_fullname;	/* full name if known */
115 	struct address	*q_next;	/* chain */
116 	struct address	*q_alias;	/* address this results from */
117 	char		*q_owner;	/* owner of q_alias */
118 	struct address	*q_tchain;	/* temporary use chain */
119 	char		*q_orcpt;	/* ORCPT parameter from RCPT TO: line */
120 	char		*q_status;	/* status code for DSNs */
121 	char		*q_fstatus;	/* final status code for DSNs */
122 	char		*q_rstatus;	/* remote status message for DSNs */
123 	time_t		q_statdate;	/* date of status messages */
124 	char		*q_statmta;	/* MTA generating q_rstatus */
125 	short		q_specificity;	/* how "specific" this address is */
126 };
127 
128 typedef struct address ADDRESS;
129 
130 # define QDONTSEND	0x00000001	/* don't send to this address */
131 # define QBADADDR	0x00000002	/* this address is verified bad */
132 # define QGOODUID	0x00000004	/* the q_uid q_gid fields are good */
133 # define QPRIMARY	0x00000008	/* set from RCPT or argv */
134 # define QQUEUEUP	0x00000010	/* queue for later transmission */
135 # define QSENT		0x00000020	/* has been successfully delivered */
136 # define QNOTREMOTE	0x00000040	/* address not for remote forwarding */
137 # define QSELFREF	0x00000080	/* this address references itself */
138 # define QVERIFIED	0x00000100	/* verified, but not expanded */
139 # define QBOGUSSHELL	0x00000400	/* user has no valid shell listed */
140 # define QUNSAFEADDR	0x00000800	/* address aquired via unsafe path */
141 # define QPINGONSUCCESS	0x00001000	/* give return on successful delivery */
142 # define QPINGONFAILURE	0x00002000	/* give return on failure */
143 # define QPINGONDELAY	0x00004000	/* give return on message delay */
144 # define QHASNOTIFY	0x00008000	/* propogate notify parameter */
145 # define QRELAYED	0x00010000	/* DSN: relayed to non-DSN aware sys */
146 # define QEXPANDED	0x00020000	/* DSN: undergone list expansion */
147 # define QDELIVERED	0x00040000	/* DSN: successful final delivery */
148 # define QDELAYED	0x00080000	/* DSN: message delayed */
149 # define QTHISPASS	0x80000000	/* temp: address set this pass */
150 
151 # define NULLADDR	((ADDRESS *) NULL)
152 
153 /* functions */
154 extern ADDRESS	*parseaddr __P((char *, ADDRESS *, int, int, char **, ENVELOPE *));
155 extern ADDRESS	*recipient __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
156 extern char	**prescan __P((char *, int, char[], int, char **, u_char *));
157 extern int	rewrite __P((char **, int, int, ENVELOPE *));
158 extern char	*remotename __P((char *, MAILER *, int, int *, ENVELOPE *));
159 extern ADDRESS	*getctladdr __P((ADDRESS *));
160 extern bool	sameaddr __P((ADDRESS *, ADDRESS *));
161 extern bool	emptyaddr __P((ADDRESS *));
162 extern void	printaddr __P((ADDRESS *, bool));
163 extern void	cataddr __P((char **, char **, char *, int, int));
164 extern int	sendtolist __P((char *, ADDRESS *, ADDRESS **, int, ENVELOPE *));
165 /*
166 **  Mailer definition structure.
167 **	Every mailer known to the system is declared in this
168 **	structure.  It defines the pathname of the mailer, some
169 **	flags associated with it, and the argument vector to
170 **	pass to it.  The flags are defined in conf.c
171 **
172 **	The argument vector is expanded before actual use.  All
173 **	words except the first are passed through the macro
174 **	processor.
175 */
176 
177 struct mailer
178 {
179 	char	*m_name;	/* symbolic name of this mailer */
180 	char	*m_mailer;	/* pathname of the mailer to use */
181 	char	*m_mtatype;	/* type of this MTA */
182 	char	*m_addrtype;	/* type for addresses */
183 	char	*m_diagtype;	/* type for diagnostics */
184 	BITMAP	m_flags;	/* status flags, see below */
185 	short	m_mno;		/* mailer number internally */
186 	short	m_nice;		/* niceness to run at (mostly for prog) */
187 	char	**m_argv;	/* template argument vector */
188 	short	m_sh_rwset;	/* rewrite set: sender header addresses */
189 	short	m_se_rwset;	/* rewrite set: sender envelope addresses */
190 	short	m_rh_rwset;	/* rewrite set: recipient header addresses */
191 	short	m_re_rwset;	/* rewrite set: recipient envelope addresses */
192 	char	*m_eol;		/* end of line string */
193 	long	m_maxsize;	/* size limit on message to this mailer */
194 	int	m_linelimit;	/* max # characters per line */
195 	char	*m_execdir;	/* directory to chdir to before execv */
196 	uid_t	m_uid;		/* UID to run as */
197 	gid_t	m_gid;		/* GID to run as */
198 	char	*m_defcharset;	/* default character set */
199 };
200 
201 /* bits for m_flags */
202 # define M_ESMTP	'a'	/* run Extended SMTP protocol */
203 # define M_ALIASABLE	'A'	/* user can be LHS of an alias */
204 # define M_BLANKEND	'b'	/* ensure blank line at end of message */
205 # define M_NOCOMMENT	'c'	/* don't include comment part of address */
206 # define M_CANONICAL	'C'	/* make addresses canonical "u@dom" */
207 # define M_NOBRACKET	'd'	/* never angle bracket envelope route-addrs */
208 		/*	'D'	/* CF: include Date: */
209 # define M_EXPENSIVE	'e'	/* it costs to use this mailer.... */
210 # define M_ESCFROM	'E'	/* escape From lines to >From */
211 # define M_FOPT		'f'	/* mailer takes picky -f flag */
212 		/*	'F'	/* CF: include From: or Resent-From: */
213 # define M_NO_NULL_FROM	'g'	/* sender of errors should be $g */
214 # define M_HST_UPPER	'h'	/* preserve host case distinction */
215 # define M_PREHEAD	'H'	/* MAIL11V3: preview headers */
216 # define M_UDBENVELOPE	'i'	/* do udbsender rewriting on envelope */
217 # define M_INTERNAL	'I'	/* SMTP to another sendmail site */
218 # define M_UDBRECIPIENT	'j'	/* do udbsender rewriting on recipient lines */
219 # define M_NOLOOPCHECK	'k'	/* don't check for loops in HELO command */
220 # define M_LOCALMAILER	'l'	/* delivery is to this host */
221 # define M_LIMITS	'L'	/* must enforce SMTP line limits */
222 # define M_MUSER	'm'	/* can handle multiple users at once */
223 		/*	'M'	/* CF: include Message-Id: */
224 # define M_NHDR		'n'	/* don't insert From line */
225 # define M_MANYSTATUS	'N'	/* MAIL11V3: DATA returns multi-status */
226 # define M_RUNASRCPT	'o'	/* always run mailer as recipient */
227 # define M_FROMPATH	'p'	/* use reverse-path in MAIL FROM: */
228 		/*	'P'	/* CF: include Return-Path: */
229 # define M_ROPT		'r'	/* mailer takes picky -r flag */
230 # define M_SECURE_PORT	'R'	/* try to send on a reserved TCP port */
231 # define M_STRIPQ	's'	/* strip quote chars from user/host */
232 # define M_SPECIFIC_UID	'S'	/* run as specific uid/gid */
233 # define M_USR_UPPER	'u'	/* preserve user case distinction */
234 # define M_UGLYUUCP	'U'	/* this wants an ugly UUCP from line */
235 # define M_CONTENT_LEN	'v'	/* add Content-Length: header (SVr4) */
236 		/*	'V'	/* UIUC: !-relativize all addresses */
237 # define M_HASPWENT	'w'	/* check for /etc/passwd entry */
238 		/*	'x'	/* CF: include Full-Name: */
239 # define M_XDOT		'X'	/* use hidden-dot algorithm */
240 # define M_EBCDIC	'3'	/* extend Q-P encoding for EBCDIC */
241 # define M_TRYRULESET5	'5'	/* use ruleset 5 after local aliasing */
242 # define M_7BITS	'7'	/* use 7-bit path */
243 # define M_8BITS	'8'	/* force "just send 8" behaviour */
244 # define M_MAKE8BIT	'9'	/* convert 7 -> 8 bit if appropriate */
245 # define M_CHECKINCLUDE	':'	/* check for :include: files */
246 # define M_CHECKPROG	'|'	/* check for |program addresses */
247 # define M_CHECKFILE	'/'	/* check for /file addresses */
248 # define M_CHECKUDB	'@'	/* user can be user database key */
249 
250 EXTERN MAILER	*Mailer[MAXMAILERS+1];
251 
252 EXTERN MAILER	*LocalMailer;		/* ptr to local mailer */
253 EXTERN MAILER	*ProgMailer;		/* ptr to program mailer */
254 EXTERN MAILER	*FileMailer;		/* ptr to *file* mailer */
255 EXTERN MAILER	*InclMailer;		/* ptr to *include* mailer */
256 /*
257 **  Header structure.
258 **	This structure is used internally to store header items.
259 */
260 
261 struct header
262 {
263 	char		*h_field;	/* the name of the field */
264 	char		*h_value;	/* the value of that field */
265 	struct header	*h_link;	/* the next header */
266 	u_short		h_flags;	/* status bits, see below */
267 	BITMAP		h_mflags;	/* m_flags bits needed */
268 };
269 
270 typedef struct header	HDR;
271 
272 /*
273 **  Header information structure.
274 **	Defined in conf.c, this struct declares the header fields
275 **	that have some magic meaning.
276 */
277 
278 struct hdrinfo
279 {
280 	char	*hi_field;	/* the name of the field */
281 	u_short	hi_flags;	/* status bits, see below */
282 };
283 
284 extern struct hdrinfo	HdrInfo[];
285 
286 /* bits for h_flags and hi_flags */
287 # define H_EOH		0x0001	/* this field terminates header */
288 # define H_RCPT		0x0002	/* contains recipient addresses */
289 # define H_DEFAULT	0x0004	/* if another value is found, drop this */
290 # define H_RESENT	0x0008	/* this address is a "Resent-..." address */
291 # define H_CHECK	0x0010	/* check h_mflags against m_flags */
292 # define H_ACHECK	0x0020	/* ditto, but always (not just default) */
293 # define H_FORCE	0x0040	/* force this field, even if default */
294 # define H_TRACE	0x0080	/* this field contains trace information */
295 # define H_FROM		0x0100	/* this is a from-type field */
296 # define H_VALID	0x0200	/* this field has a validated value */
297 # define H_RECEIPTTO	0x0400	/* this field has return receipt info */
298 # define H_ERRORSTO	0x0800	/* this field has error address info */
299 # define H_CTE		0x1000	/* this field is a content-transfer-encoding */
300 # define H_CTYPE	0x2000	/* this is a content-type field */
301 # define H_STRIPVAL	0x4000	/* strip value from header (Bcc:) */
302 /*
303 **  Information about currently open connections to mailers, or to
304 **  hosts that we have looked up recently.
305 */
306 
307 # define MCI		struct mailer_con_info
308 
309 MCI
310 {
311 	short		mci_flags;	/* flag bits, see below */
312 	short		mci_errno;	/* error number on last connection */
313 	short		mci_herrno;	/* h_errno from last DNS lookup */
314 	short		mci_exitstat;	/* exit status from last connection */
315 	short		mci_state;	/* SMTP state */
316 	long		mci_maxsize;	/* max size this server will accept */
317 	FILE		*mci_in;	/* input side of connection */
318 	FILE		*mci_out;	/* output side of connection */
319 	int		mci_pid;	/* process id of subordinate proc */
320 	char		*mci_phase;	/* SMTP phase string */
321 	struct mailer	*mci_mailer;	/* ptr to the mailer for this conn */
322 	char		*mci_host;	/* host name */
323 	char		*mci_status;	/* DSN status to be copied to addrs */
324 	time_t		mci_lastuse;	/* last usage time */
325 };
326 
327 
328 /* flag bits */
329 #define MCIF_VALID	0x0001		/* this entry is valid */
330 #define MCIF_TEMP	0x0002		/* don't cache this connection */
331 #define MCIF_CACHED	0x0004		/* currently in open cache */
332 #define MCIF_ESMTP	0x0008		/* this host speaks ESMTP */
333 #define MCIF_EXPN	0x0010		/* EXPN command supported */
334 #define MCIF_SIZE	0x0020		/* SIZE option supported */
335 #define MCIF_8BITMIME	0x0040		/* BODY=8BITMIME supported */
336 #define MCIF_7BIT	0x0080		/* strip this message to 7 bits */
337 #define MCIF_MULTSTAT	0x0100		/* MAIL11V3: handles MULT status */
338 #define MCIF_INHEADER	0x0200		/* currently outputing header */
339 #define MCIF_CVT8TO7	0x0400		/* convert from 8 to 7 bits */
340 #define MCIF_DSN	0x0800		/* DSN extension supported */
341 #define MCIF_8BITOK	0x1000		/* OK to send 8 bit characters */
342 #define MCIF_CVT7TO8	0x2000		/* convert from 7 to 8 bits */
343 #define MCIF_INMIME	0x4000		/* currently reading MIME header */
344 
345 /* states */
346 #define MCIS_CLOSED	0		/* no traffic on this connection */
347 #define MCIS_OPENING	1		/* sending initial protocol */
348 #define MCIS_OPEN	2		/* open, initial protocol sent */
349 #define MCIS_ACTIVE	3		/* message being sent */
350 #define MCIS_QUITING	4		/* running quit protocol */
351 #define MCIS_SSD	5		/* service shutting down */
352 #define MCIS_ERROR	6		/* I/O error on connection */
353 
354 /* functions */
355 extern MCI	*mci_get __P((char *, MAILER *));
356 extern void	mci_cache __P((MCI *));
357 extern void	mci_flush __P((bool, MCI *));
358 /*
359 **  Envelope structure.
360 **	This structure defines the message itself.  There is usually
361 **	only one of these -- for the message that we originally read
362 **	and which is our primary interest -- but other envelopes can
363 **	be generated during processing.  For example, error messages
364 **	will have their own envelope.
365 */
366 
367 struct envelope
368 {
369 	HDR		*e_header;	/* head of header list */
370 	long		e_msgpriority;	/* adjusted priority of this message */
371 	time_t		e_ctime;	/* time message appeared in the queue */
372 	char		*e_to;		/* the target person */
373 	char		*e_receiptto;	/* return receipt address */
374 	ADDRESS		e_from;		/* the person it is from */
375 	char		*e_sender;	/* e_from.q_paddr w comments stripped */
376 	char		**e_fromdomain;	/* the domain part of the sender */
377 	ADDRESS		*e_sendqueue;	/* list of message recipients */
378 	ADDRESS		*e_errorqueue;	/* the queue for error responses */
379 	long		e_msgsize;	/* size of the message in bytes */
380 	long		e_flags;	/* flags, see below */
381 	int		e_nrcpts;	/* number of recipients */
382 	short		e_class;	/* msg class (priority, junk, etc.) */
383 	short		e_hopcount;	/* number of times processed */
384 	short		e_nsent;	/* number of sends since checkpoint */
385 	short		e_sendmode;	/* message send mode */
386 	short		e_errormode;	/* error return mode */
387 	short		e_timeoutclass;	/* message timeout class */
388 	void		(*e_puthdr)__P((MCI *, HDR *, ENVELOPE *));
389 					/* function to put header of message */
390 	void		(*e_putbody)__P((MCI *, ENVELOPE *, char *));
391 					/* function to put body of message */
392 	struct envelope	*e_parent;	/* the message this one encloses */
393 	struct envelope *e_sibling;	/* the next envelope of interest */
394 	char		*e_bodytype;	/* type of message body */
395 	FILE		*e_dfp;		/* temporary file */
396 	char		*e_id;		/* code for this entry in queue */
397 	FILE		*e_xfp;		/* transcript file */
398 	FILE		*e_lockfp;	/* the lock file for this message */
399 	char		*e_message;	/* error message */
400 	char		*e_statmsg;	/* stat msg (changes per delivery) */
401 	char		*e_msgboundary;	/* MIME-style message part boundary */
402 	char		*e_origrcpt;	/* original recipient (one only) */
403 	char		*e_envid;	/* envelope id from MAIL FROM: line */
404 	char		*e_status;	/* DSN status for this message */
405 	time_t		e_dtime;	/* time of last delivery attempt */
406 	int		e_ntries;	/* number of delivery attempts */
407 	dev_t		e_dfdev;	/* df file's device, for crash recov */
408 	ino_t		e_dfino;	/* df file's ino, for crash recovery */
409 	char		*e_macro[256];	/* macro definitions */
410 };
411 
412 /* values for e_flags */
413 #define EF_OLDSTYLE	0x0000001	/* use spaces (not commas) in hdrs */
414 #define EF_INQUEUE	0x0000002	/* this message is fully queued */
415 #define EF_NO_BODY_RETN	0x0000004	/* omit message body on error */
416 #define EF_CLRQUEUE	0x0000008	/* disk copy is no longer needed */
417 #define EF_SENDRECEIPT	0x0000010	/* send a return receipt */
418 #define EF_FATALERRS	0x0000020	/* fatal errors occured */
419 #define EF_KEEPQUEUE	0x0000040	/* keep queue files always */
420 #define EF_RESPONSE	0x0000080	/* this is an error or return receipt */
421 #define EF_RESENT	0x0000100	/* this message is being forwarded */
422 #define EF_VRFYONLY	0x0000200	/* verify only (don't expand aliases) */
423 #define EF_WARNING	0x0000400	/* warning message has been sent */
424 #define EF_QUEUERUN	0x0000800	/* this envelope is from queue */
425 #define EF_GLOBALERRS	0x0001000	/* treat errors as global */
426 #define EF_PM_NOTIFY	0x0002000	/* send return mail to postmaster */
427 #define EF_METOO	0x0004000	/* send to me too */
428 #define EF_LOGSENDER	0x0008000	/* need to log the sender */
429 #define EF_NORECEIPT	0x0010000	/* suppress all return-receipts */
430 #define EF_HAS8BIT	0x0020000	/* at least one 8-bit char in body */
431 #define EF_NL_NOT_EOL	0x0040000	/* don't accept raw NL as EOLine */
432 #define EF_CRLF_NOT_EOL	0x0080000	/* don't accept CR-LF as EOLine */
433 #define EF_RET_PARAM	0x0100000	/* RCPT command had RET argument */
434 #define EF_HAS_DF	0x0200000	/* set when df file is instantiated */
435 #define EF_IS_MIME	0x0400000	/* really is a MIME message */
436 #define EF_DONT_MIME	0x0800000	/* never MIME this message */
437 
438 EXTERN ENVELOPE	*CurEnv;	/* envelope currently being processed */
439 
440 /* functions */
441 extern ENVELOPE	*newenvelope __P((ENVELOPE *, ENVELOPE *));
442 extern void	dropenvelope __P((ENVELOPE *));
443 extern void	clearenvelope __P((ENVELOPE *, bool));
444 
445 extern void	putheader __P((MCI *, HDR *, ENVELOPE *));
446 extern void	putbody __P((MCI *, ENVELOPE *, char *));
447 /*
448 **  Message priority classes.
449 **
450 **	The message class is read directly from the Priority: header
451 **	field in the message.
452 **
453 **	CurEnv->e_msgpriority is the number of bytes in the message plus
454 **	the creation time (so that jobs ``tend'' to be ordered correctly),
455 **	adjusted by the message class, the number of recipients, and the
456 **	amount of time the message has been sitting around.  This number
457 **	is used to order the queue.  Higher values mean LOWER priority.
458 **
459 **	Each priority class point is worth WkClassFact priority points;
460 **	each recipient is worth WkRecipFact priority points.  Each time
461 **	we reprocess a message the priority is adjusted by WkTimeFact.
462 **	WkTimeFact should normally decrease the priority so that jobs
463 **	that have historically failed will be run later; thanks go to
464 **	Jay Lepreau at Utah for pointing out the error in my thinking.
465 **
466 **	The "class" is this number, unadjusted by the age or size of
467 **	this message.  Classes with negative representations will have
468 **	error messages thrown away if they are not local.
469 */
470 
471 struct priority
472 {
473 	char	*pri_name;	/* external name of priority */
474 	int	pri_val;	/* internal value for same */
475 };
476 
477 EXTERN struct priority	Priorities[MAXPRIORITIES];
478 EXTERN int		NumPriorities;	/* pointer into Priorities */
479 /*
480 **  Rewrite rules.
481 */
482 
483 struct rewrite
484 {
485 	char	**r_lhs;	/* pattern match */
486 	char	**r_rhs;	/* substitution value */
487 	struct rewrite	*r_next;/* next in chain */
488 };
489 
490 EXTERN struct rewrite	*RewriteRules[MAXRWSETS];
491 
492 /*
493 **  Special characters in rewriting rules.
494 **	These are used internally only.
495 **	The COND* rules are actually used in macros rather than in
496 **		rewriting rules, but are given here because they
497 **		cannot conflict.
498 */
499 
500 /* left hand side items */
501 # define MATCHZANY	((u_char)0220)	/* match zero or more tokens */
502 # define MATCHANY	((u_char)0221)	/* match one or more tokens */
503 # define MATCHONE	((u_char)0222)	/* match exactly one token */
504 # define MATCHCLASS	((u_char)0223)	/* match one token in a class */
505 # define MATCHNCLASS	((u_char)0224)	/* match anything not in class */
506 # define MATCHREPL	((u_char)0225)	/* replacement on RHS for above */
507 
508 /* right hand side items */
509 # define CANONNET	((u_char)0226)	/* canonical net, next token */
510 # define CANONHOST	((u_char)0227)	/* canonical host, next token */
511 # define CANONUSER	((u_char)0230)	/* canonical user, next N tokens */
512 # define CALLSUBR	((u_char)0231)	/* call another rewriting set */
513 
514 /* conditionals in macros */
515 # define CONDIF		((u_char)0232)	/* conditional if-then */
516 # define CONDELSE	((u_char)0233)	/* conditional else */
517 # define CONDFI		((u_char)0234)	/* conditional fi */
518 
519 /* bracket characters for host name lookup */
520 # define HOSTBEGIN	((u_char)0235)	/* hostname lookup begin */
521 # define HOSTEND	((u_char)0236)	/* hostname lookup end */
522 
523 /* bracket characters for generalized lookup */
524 # define LOOKUPBEGIN	((u_char)0205)	/* generalized lookup begin */
525 # define LOOKUPEND	((u_char)0206)	/* generalized lookup end */
526 
527 /* macro substitution character */
528 # define MACROEXPAND	((u_char)0201)	/* macro expansion */
529 # define MACRODEXPAND	((u_char)0202)	/* deferred macro expansion */
530 
531 /* to make the code clearer */
532 # define MATCHZERO	CANONHOST
533 
534 /* external <==> internal mapping table */
535 struct metamac
536 {
537 	char	metaname;	/* external code (after $) */
538 	u_char	metaval;	/* internal code (as above) */
539 };
540 
541 /* functions */
542 extern void	expand __P((char *, char *, size_t, ENVELOPE *));
543 extern void	define __P((int, char *, ENVELOPE *));
544 extern char	*macvalue __P((int, ENVELOPE *));
545 extern char	*macname __P((int));
546 extern int	macid __P((char *, char **));
547 /*
548 **  Name canonification short circuit.
549 **
550 **	If the name server for a host is down, the process of trying to
551 **	canonify the name can hang.  This is similar to (but alas, not
552 **	identical to) looking up the name for delivery.  This stab type
553 **	caches the result of the name server lookup so we don't hang
554 **	multiple times.
555 */
556 
557 #define NAMECANON	struct _namecanon
558 
559 NAMECANON
560 {
561 	short		nc_errno;	/* cached errno */
562 	short		nc_herrno;	/* cached h_errno */
563 	short		nc_stat;	/* cached exit status code */
564 	short		nc_flags;	/* flag bits */
565 	char		*nc_cname;	/* the canonical name */
566 };
567 
568 /* values for nc_flags */
569 #define NCF_VALID	0x0001	/* entry valid */
570 /*
571 **  Mapping functions
572 **
573 **	These allow arbitrary mappings in the config file.  The idea
574 **	(albeit not the implementation) comes from IDA sendmail.
575 */
576 
577 # define MAPCLASS	struct _mapclass
578 # define MAP		struct _map
579 # define MAXMAPACTIONS	3		/* size of map_actions array */
580 
581 
582 /*
583 **  An actual map.
584 */
585 
586 MAP
587 {
588 	MAPCLASS	*map_class;	/* the class of this map */
589 	char		*map_mname;	/* name of this map */
590 	long		map_mflags;	/* flags, see below */
591 	char		*map_file;	/* the (nominal) filename */
592 	ARBPTR_T	map_db1;	/* the open database ptr */
593 	ARBPTR_T	map_db2;	/* an "extra" database pointer */
594 	char		*map_keycolnm;	/* key column name */
595 	char		*map_valcolnm;	/* value column name */
596 	u_char		map_keycolno;	/* key column number */
597 	u_char		map_valcolno;	/* value column number */
598 	char		map_coldelim;	/* column delimiter */
599 	char		*map_app;	/* to append to successful matches */
600 	char		*map_domain;	/* the (nominal) NIS domain */
601 	char		*map_rebuild;	/* program to run to do auto-rebuild */
602 	time_t		map_mtime;	/* last database modification time */
603 	short		map_specificity;	/* specificity of alaases */
604 	MAP		*map_stack[MAXMAPSTACK];   /* list for stacked maps */
605 	short		map_return[MAXMAPACTIONS]; /* return bitmaps for stacked maps */
606 };
607 
608 /* bit values for map_mflags */
609 # define MF_VALID	0x00000001	/* this entry is valid */
610 # define MF_INCLNULL	0x00000002	/* include null byte in key */
611 # define MF_OPTIONAL	0x00000004	/* don't complain if map not found */
612 # define MF_NOFOLDCASE	0x00000008	/* don't fold case in keys */
613 # define MF_MATCHONLY	0x00000010	/* don't use the map value */
614 # define MF_OPEN	0x00000020	/* this entry is open */
615 # define MF_WRITABLE	0x00000040	/* open for writing */
616 # define MF_ALIAS	0x00000080	/* this is an alias file */
617 # define MF_TRY0NULL	0x00000100	/* try with no null byte */
618 # define MF_TRY1NULL	0x00000200	/* try with the null byte */
619 # define MF_LOCKED	0x00000400	/* this map is currently locked */
620 # define MF_ALIASWAIT	0x00000800	/* alias map in aliaswait state */
621 # define MF_IMPL_HASH	0x00001000	/* implicit: underlying hash database */
622 # define MF_IMPL_NDBM	0x00002000	/* implicit: underlying NDBM database */
623 # define MF_UNSAFEDB	0x00004000	/* this map is world writable */
624 # define MF_APPEND	0x00008000	/* append new entry on rebuiled */
625 # define MF_KEEPQUOTES	0x00010000	/* don't dequote key before lookup */
626 
627 /* indices for map_actions */
628 # define MA_NOTFOUND	0		/* member map returned "not found" */
629 # define MA_UNAVAIL	1		/* member map is not available */
630 # define MA_TRYAGAIN	2		/* member map returns temp failure */
631 
632 /*
633 **  The class of a map -- essentially the functions to call
634 */
635 
636 MAPCLASS
637 {
638 	char	*map_cname;		/* name of this map class */
639 	char	*map_ext;		/* extension for database file */
640 	short	map_cflags;		/* flag bits, see below */
641 	bool	(*map_parse)__P((MAP *, char *));
642 					/* argument parsing function */
643 	char	*(*map_lookup)__P((MAP *, char *, char **, int *));
644 					/* lookup function */
645 	void	(*map_store)__P((MAP *, char *, char *));
646 					/* store function */
647 	bool	(*map_open)__P((MAP *, int));
648 					/* open function */
649 	void	(*map_close)__P((MAP *));
650 					/* close function */
651 };
652 
653 /* bit values for map_cflags */
654 #define MCF_ALIASOK	0x0001		/* can be used for aliases */
655 #define MCF_ALIASONLY	0x0002		/* usable only for aliases */
656 #define MCF_REBUILDABLE	0x0004		/* can rebuild alias files */
657 #define MCF_OPTFILE	0x0008		/* file name is optional */
658 
659 /* functions */
660 extern char	*map_rewrite __P((MAP *, char *, int, char **));
661 extern MAP	*makemapentry __P((char *));
662 /*
663 **  Symbol table definitions
664 */
665 
666 struct symtab
667 {
668 	char		*s_name;	/* name to be entered */
669 	char		s_type;		/* general type (see below) */
670 	struct symtab	*s_next;	/* pointer to next in chain */
671 	union
672 	{
673 		BITMAP		sv_class;	/* bit-map of word classes */
674 		ADDRESS		*sv_addr;	/* pointer to address header */
675 		MAILER		*sv_mailer;	/* pointer to mailer */
676 		char		*sv_alias;	/* alias */
677 		MAPCLASS	sv_mapclass;	/* mapping function class */
678 		MAP		sv_map;		/* mapping function */
679 		char		*sv_hostsig;	/* host signature */
680 		MCI		sv_mci;		/* mailer connection info */
681 		NAMECANON	sv_namecanon;	/* canonical name cache */
682 		int		sv_macro;	/* macro name => id mapping */
683 		int		sv_ruleset;	/* ruleset index */
684 	}	s_value;
685 };
686 
687 typedef struct symtab	STAB;
688 
689 /* symbol types */
690 # define ST_UNDEF	0	/* undefined type */
691 # define ST_CLASS	1	/* class map */
692 # define ST_ADDRESS	2	/* an address in parsed format */
693 # define ST_MAILER	3	/* a mailer header */
694 # define ST_ALIAS	4	/* an alias */
695 # define ST_MAPCLASS	5	/* mapping function class */
696 # define ST_MAP		6	/* mapping function */
697 # define ST_HOSTSIG	7	/* host signature */
698 # define ST_NAMECANON	8	/* cached canonical name */
699 # define ST_MACRO	9	/* macro name to id mapping */
700 # define ST_RULESET	10	/* ruleset index */
701 # define ST_MCI		16	/* mailer connection info (offset) */
702 
703 # define s_class	s_value.sv_class
704 # define s_address	s_value.sv_addr
705 # define s_mailer	s_value.sv_mailer
706 # define s_alias	s_value.sv_alias
707 # define s_mci		s_value.sv_mci
708 # define s_mapclass	s_value.sv_mapclass
709 # define s_hostsig	s_value.sv_hostsig
710 # define s_map		s_value.sv_map
711 # define s_namecanon	s_value.sv_namecanon
712 # define s_macro	s_value.sv_macro
713 # define s_ruleset	s_value.sv_ruleset
714 
715 extern STAB		*stab __P((char *, int, int));
716 extern void		stabapply __P((void (*)(STAB *, int), int));
717 
718 /* opcodes to stab */
719 # define ST_FIND	0	/* find entry */
720 # define ST_ENTER	1	/* enter if not there */
721 /*
722 **  STRUCT EVENT -- event queue.
723 **
724 **	Maintained in sorted order.
725 **
726 **	We store the pid of the process that set this event to insure
727 **	that when we fork we will not take events intended for the parent.
728 */
729 
730 struct event
731 {
732 	time_t		ev_time;	/* time of the function call */
733 	void		(*ev_func)__P((int));
734 					/* function to call */
735 	int		ev_arg;		/* argument to ev_func */
736 	int		ev_pid;		/* pid that set this event */
737 	struct event	*ev_link;	/* link to next item */
738 };
739 
740 typedef struct event	EVENT;
741 
742 EXTERN EVENT	*EventQueue;		/* head of event queue */
743 
744 /* functions */
745 extern EVENT	*setevent __P((time_t, void(*)(), int));
746 extern void	clrevent __P((EVENT *));
747 /*
748 **  Operation, send, error, and MIME modes
749 **
750 **	The operation mode describes the basic operation of sendmail.
751 **	This can be set from the command line, and is "send mail" by
752 **	default.
753 **
754 **	The send mode tells how to send mail.  It can be set in the
755 **	configuration file.  It's setting determines how quickly the
756 **	mail will be delivered versus the load on your system.  If the
757 **	-v (verbose) flag is given, it will be forced to SM_DELIVER
758 **	mode.
759 **
760 **	The error mode tells how to return errors.
761 */
762 
763 EXTERN char	OpMode;		/* operation mode, see below */
764 
765 #define MD_DELIVER	'm'		/* be a mail sender */
766 #define MD_SMTP		's'		/* run SMTP on standard input */
767 #define MD_ARPAFTP	'a'		/* obsolete ARPANET mode (Grey Book) */
768 #define MD_DAEMON	'd'		/* run as a daemon */
769 #define MD_VERIFY	'v'		/* verify: don't collect or deliver */
770 #define MD_TEST		't'		/* test mode: resolve addrs only */
771 #define MD_INITALIAS	'i'		/* initialize alias database */
772 #define MD_PRINT	'p'		/* print the queue */
773 #define MD_FREEZE	'z'		/* freeze the configuration file */
774 
775 
776 /* values for e_sendmode -- send modes */
777 #define SM_DELIVER	'i'		/* interactive delivery */
778 #define SM_FORK		'b'		/* deliver in background */
779 #define SM_QUEUE	'q'		/* queue, don't deliver */
780 #define SM_VERIFY	'v'		/* verify only (used internally) */
781 
782 /* used only as a parameter to sendall */
783 #define SM_DEFAULT	'\0'		/* unspecified, use SendMode */
784 
785 
786 /* values for e_errormode -- error handling modes */
787 #define EM_PRINT	'p'		/* print errors */
788 #define EM_MAIL		'm'		/* mail back errors */
789 #define EM_WRITE	'w'		/* write back errors */
790 #define EM_BERKNET	'e'		/* special berknet processing */
791 #define EM_QUIET	'q'		/* don't print messages (stat only) */
792 
793 
794 /* MIME processing mode */
795 EXTERN int	MimeMode;
796 
797 /* bit values for MimeMode */
798 #define MM_CVTMIME	0x0001		/* convert 8 to 7 bit MIME */
799 #define MM_PASS8BIT	0x0002		/* just send 8 bit data blind */
800 #define MM_MIME8BIT	0x0004		/* convert 8-bit data to MIME */
801 
802 /* queue sorting order algorithm */
803 EXTERN int	QueueSortOrder;
804 
805 #define QS_BYPRIORITY	0		/* sort by message priority */
806 #define QS_BYHOST	1		/* sort by first host name */
807 
808 
809 /* how to handle messages without any recipient addresses */
810 EXTERN int		NoRecipientAction;
811 
812 #define NRA_NO_ACTION		0	/* just leave it as is */
813 #define NRA_ADD_TO		1	/* add To: header */
814 #define NRA_ADD_APPARENTLY_TO	2	/* add Apparently-To: header */
815 #define NRA_ADD_BCC		3	/* add empty Bcc: header */
816 #define NRA_ADD_TO_UNDISCLOSED	4	/* add To: undisclosed:; header */
817 
818 
819 /* flags to putxline */
820 #define PXLF_NOTHINGSPECIAL	0	/* no special mapping */
821 #define PXLF_MAPFROM		0x0001	/* map From_ to >From_ */
822 #define PXLF_STRIP8BIT		0x0002	/* strip 8th bit *e
823 /*
824 **  Additional definitions
825 */
826 
827 
828 /*
829 **  Privacy flags
830 **	These are bit values for the PrivacyFlags word.
831 */
832 
833 #define PRIV_PUBLIC		0	/* what have I got to hide? */
834 #define PRIV_NEEDMAILHELO	0x0001	/* insist on HELO for MAIL, at least */
835 #define PRIV_NEEDEXPNHELO	0x0002	/* insist on HELO for EXPN */
836 #define PRIV_NEEDVRFYHELO	0x0004	/* insist on HELO for VRFY */
837 #define PRIV_NOEXPN		0x0008	/* disallow EXPN command entirely */
838 #define PRIV_NOVRFY		0x0010	/* disallow VRFY command entirely */
839 #define PRIV_AUTHWARNINGS	0x0020	/* flag possible authorization probs */
840 #define PRIV_NORECEIPTS		0x0040	/* disallow return receipts */
841 #define PRIV_RESTRICTMAILQ	0x1000	/* restrict mailq command */
842 #define PRIV_RESTRICTQRUN	0x2000	/* restrict queue run */
843 #define PRIV_GOAWAY		0x0fff	/* don't give no info, anyway, anyhow */
844 
845 /* struct defining such things */
846 struct prival
847 {
848 	char	*pv_name;	/* name of privacy flag */
849 	int	pv_flag;	/* numeric level */
850 };
851 
852 
853 /*
854 **  Flags passed to remotename, parseaddr, allocaddr, and buildaddr.
855 */
856 
857 #define RF_SENDERADDR		0x001	/* this is a sender address */
858 #define RF_HEADERADDR		0x002	/* this is a header address */
859 #define RF_CANONICAL		0x004	/* strip comment information */
860 #define RF_ADDDOMAIN		0x008	/* OK to do domain extension */
861 #define RF_COPYPARSE		0x010	/* copy parsed user & host */
862 #define RF_COPYPADDR		0x020	/* copy print address */
863 #define RF_COPYALL		(RF_COPYPARSE|RF_COPYPADDR)
864 #define RF_COPYNONE		0
865 
866 
867 /*
868 **  Flags passed to safefile.
869 */
870 
871 #define SFF_ANYFILE		0	/* no special restrictions */
872 #define SFF_MUSTOWN		0x0001	/* user must own this file */
873 #define SFF_NOSLINK		0x0002	/* file cannot be a symbolic link */
874 #define SFF_ROOTOK		0x0004	/* ok for root to own this file */
875 #define SFF_RUNASREALUID	0x0008	/* if no ctladdr, run as real uid */
876 #define SFF_NOPATHCHECK		0x0010	/* don't bother checking dir path */
877 #define SFF_SETUIDOK		0x0020	/* setuid files are ok */
878 #define SFF_CREAT		0x0040	/* ok to create file if necessary */
879 #define SFF_REGONLY		0x0080	/* regular files only */
880 
881 /* flags that are actually specific to safefopen */
882 #define SFF_OPENASROOT		0x1000	/* open as root instead of real user */
883 
884 
885 /*
886 **  Flags passed to mime8to7.
887 */
888 
889 #define M87F_OUTER		0	/* outer context */
890 #define M87F_NO8BIT		0x0001	/* can't have 8-bit in this section */
891 #define M87F_DIGEST		0x0002	/* processing multipart/digest */
892 
893 
894 /*
895 **  Regular UNIX sockaddrs are too small to handle ISO addresses, so
896 **  we are forced to declare a supertype here.
897 */
898 
899 union bigsockaddr
900 {
901 	struct sockaddr		sa;	/* general version */
902 #if NETUNIX
903 	struct sockaddr_un	sunix;	/* UNIX family */
904 #endif
905 #if NETINET
906 	struct sockaddr_in	sin;	/* INET family */
907 #endif
908 #if NETISO
909 	struct sockaddr_iso	siso;	/* ISO family */
910 #endif
911 #if NETNS
912 	struct sockaddr_ns	sns;	/* XNS family */
913 #endif
914 #if NETX25
915 	struct sockaddr_x25	sx25;	/* X.25 family */
916 #endif
917 };
918 
919 #define SOCKADDR	union bigsockaddr
920 
921 
922 /*
923 **  Vendor codes
924 **
925 **	Vendors can customize sendmail to add special behaviour,
926 **	generally for back compatibility.  Ideally, this should
927 **	be set up in the .cf file using the "V" command.  However,
928 **	it's quite reasonable for some vendors to want the default
929 **	be their old version; this can be set using
930 **		-DVENDOR_DEFAULT=VENDOR_xxx
931 **	in the Makefile.
932 **
933 **	Vendors should apply to sendmail@CS.Berkeley.EDU for
934 **	unique vendor codes.
935 */
936 
937 #define VENDOR_BERKELEY	1	/* Berkeley-native configuration file */
938 #define VENDOR_SUN	2	/* Sun-native configuration file */
939 #define VENDOR_HP	3	/* Hewlett-Packard specific config syntax */
940 
941 EXTERN int	VendorCode;	/* vendor-specific operation enhancements */
942 /*
943 **  Global variables.
944 */
945 
946 EXTERN bool	FromFlag;	/* if set, "From" person is explicit */
947 EXTERN bool	MeToo;		/* send to the sender also */
948 EXTERN bool	IgnrDot;	/* don't let dot end messages */
949 EXTERN bool	SaveFrom;	/* save leading "From" lines */
950 EXTERN bool	Verbose;	/* set if blow-by-blow desired */
951 EXTERN bool	GrabTo;		/* if set, get recipients from msg */
952 EXTERN bool	SuprErrs;	/* set if we are suppressing errors */
953 EXTERN bool	HoldErrs;	/* only output errors to transcript */
954 EXTERN bool	NoConnect;	/* don't connect to non-local mailers */
955 EXTERN bool	SuperSafe;	/* be extra careful, even if expensive */
956 EXTERN bool	ForkQueueRuns;	/* fork for each job when running the queue */
957 EXTERN bool	AutoRebuild;	/* auto-rebuild the alias database as needed */
958 EXTERN bool	CheckAliases;	/* parse addresses during newaliases */
959 EXTERN bool	NoAlias;	/* suppress aliasing */
960 EXTERN bool	UseNameServer;	/* using DNS -- interpret h_errno & MX RRs */
961 EXTERN bool	UseHesiod;	/* using Hesiod -- interpret Hesiod errors */
962 EXTERN bool	SevenBitInput;	/* force 7-bit data on input */
963 EXTERN bool	HasEightBits;	/* has at least one eight bit input byte */
964 EXTERN time_t	SafeAlias;	/* interval to wait until @:@ in alias file */
965 EXTERN FILE	*InChannel;	/* input connection */
966 EXTERN FILE	*OutChannel;	/* output connection */
967 EXTERN char	*RealUserName;	/* real user name of caller */
968 EXTERN uid_t	RealUid;	/* real uid of caller */
969 EXTERN gid_t	RealGid;	/* real gid of caller */
970 EXTERN uid_t	DefUid;		/* default uid to run as */
971 EXTERN gid_t	DefGid;		/* default gid to run as */
972 EXTERN char	*DefUser;	/* default user to run as (from DefUid) */
973 EXTERN int	OldUmask;	/* umask when sendmail starts up */
974 EXTERN int	Errors;		/* set if errors (local to single pass) */
975 EXTERN int	ExitStat;	/* exit status code */
976 EXTERN int	LineNumber;	/* line number in current input */
977 EXTERN int	LogLevel;	/* level of logging to perform */
978 EXTERN int	FileMode;	/* mode on files */
979 EXTERN int	QueueLA;	/* load average starting forced queueing */
980 EXTERN int	RefuseLA;	/* load average refusing connections are */
981 EXTERN int	CurrentLA;	/* current load average */
982 EXTERN long	QueueFactor;	/* slope of queue function */
983 EXTERN time_t	QueueIntvl;	/* intervals between running the queue */
984 EXTERN char	*HelpFile;	/* location of SMTP help file */
985 EXTERN char	*ErrMsgFile;	/* file to prepend to all error messages */
986 EXTERN char	*StatFile;	/* location of statistics summary */
987 EXTERN char	*QueueDir;	/* location of queue directory */
988 EXTERN char	*FileName;	/* name to print on error messages */
989 EXTERN char	*SmtpPhase;	/* current phase in SMTP processing */
990 EXTERN char	*MyHostName;	/* name of this host for SMTP messages */
991 EXTERN char	*RealHostName;	/* name of host we are talking to */
992 EXTERN SOCKADDR RealHostAddr;	/* address of host we are talking to */
993 EXTERN char	*CurHostName;	/* current host we are dealing with */
994 EXTERN jmp_buf	TopFrame;	/* branch-to-top-of-loop-on-error frame */
995 EXTERN bool	QuickAbort;	/*  .... but only if we want a quick abort */
996 EXTERN bool	LogUsrErrs;	/* syslog user errors (e.g., SMTP RCPT cmd) */
997 EXTERN bool	SendMIMEErrors;	/* send error messages in MIME format */
998 EXTERN bool	MatchGecos;	/* look for user names in gecos field */
999 EXTERN bool	UseErrorsTo;	/* use Errors-To: header (back compat) */
1000 EXTERN bool	TryNullMXList;	/* if we are the best MX, try host directly */
1001 EXTERN bool	InChild;	/* true if running in an SMTP subprocess */
1002 EXTERN bool	DisConnected;	/* running with OutChannel redirected to xf */
1003 EXTERN bool	ColonOkInAddr;	/* single colon legal in address */
1004 EXTERN bool	HasWildcardMX;	/* don't use MX records when canonifying */
1005 EXTERN char	SpaceSub;	/* substitution for <lwsp> */
1006 EXTERN int	PrivacyFlags;	/* privacy flags */
1007 EXTERN char	*ConfFile;	/* location of configuration file [conf.c] */
1008 extern char	*PidFile;	/* location of proc id file [conf.c] */
1009 extern ADDRESS	NullAddress;	/* a null (template) address [main.c] */
1010 EXTERN long	WkClassFact;	/* multiplier for message class -> priority */
1011 EXTERN long	WkRecipFact;	/* multiplier for # of recipients -> priority */
1012 EXTERN long	WkTimeFact;	/* priority offset each time this job is run */
1013 EXTERN char	*UdbSpec;	/* user database source spec */
1014 EXTERN int	MaxHopCount;	/* max # of hops until bounce */
1015 EXTERN int	ConfigLevel;	/* config file level */
1016 EXTERN char	*TimeZoneSpec;	/* override time zone specification */
1017 EXTERN char	*ForwardPath;	/* path to search for .forward files */
1018 EXTERN long	MinBlocksFree;	/* min # of blocks free on queue fs */
1019 EXTERN char	*FallBackMX;	/* fall back MX host */
1020 EXTERN long	MaxMessageSize;	/* advertised max size we will accept */
1021 EXTERN time_t	MaxHostStatAge;	/* max age of cached host status info */
1022 EXTERN time_t	MinQueueAge;	/* min delivery interval */
1023 EXTERN time_t	DialDelay;	/* delay between dial-on-demand tries */
1024 EXTERN char	*SafeFileEnv;	/* chroot location for file delivery */
1025 EXTERN char	*HostsFile;	/* path to /etc/hosts file */
1026 EXTERN int	MaxQueueRun;	/* maximum number of jobs in one queue run */
1027 EXTERN int	MaxChildren;	/* maximum number of daemonic children */
1028 EXTERN int	CurChildren;	/* current number of daemonic children */
1029 EXTERN char	*ServiceSwitchFile;	/* backup service switch */
1030 EXTERN char	*DefaultCharSet;	/* default character set for MIME */
1031 EXTERN int	DeliveryNiceness;	/* how nice to be during delivery */
1032 EXTERN char	*PostMasterCopy;	/* address to get errs cc's */
1033 EXTERN int	CheckpointInterval;	/* queue file checkpoint interval */
1034 EXTERN bool	DontPruneRoutes;	/* don't prune source routes */
1035 EXTERN bool	DontExpandCnames;	/* do not $[...$] expand CNAMEs */
1036 EXTERN int	MaxMciCache;		/* maximum entries in MCI cache */
1037 EXTERN time_t	MciCacheTimeout;	/* maximum idle time on connections */
1038 EXTERN char	*QueueLimitRecipient;	/* limit queue runs to this recipient */
1039 EXTERN char	*QueueLimitSender;	/* limit queue runs to this sender */
1040 EXTERN char	*QueueLimitId;		/* limit queue runs to this id */
1041 EXTERN FILE	*TrafficLogFile;	/* file in which to log all traffic */
1042 EXTERN char	*UserEnviron[MAXUSERENVIRON + 1];
1043 					/* saved user environment */
1044 extern int	errno;
1045 
1046 
1047 /*
1048 **  Timeouts
1049 **
1050 **	Indicated values are the MINIMUM per RFC 1123 section 5.3.2.
1051 */
1052 
1053 EXTERN struct
1054 {
1055 			/* RFC 1123-specified timeouts [minimum value] */
1056 	time_t	to_initial;	/* initial greeting timeout [5m] */
1057 	time_t	to_mail;	/* MAIL command [5m] */
1058 	time_t	to_rcpt;	/* RCPT command [5m] */
1059 	time_t	to_datainit;	/* DATA initiation [2m] */
1060 	time_t	to_datablock;	/* DATA block [3m] */
1061 	time_t	to_datafinal;	/* DATA completion [10m] */
1062 	time_t	to_nextcommand;	/* next command [5m] */
1063 			/* following timeouts are not mentioned in RFC 1123 */
1064 	time_t	to_rset;	/* RSET command */
1065 	time_t	to_helo;	/* HELO command */
1066 	time_t	to_quit;	/* QUIT command */
1067 	time_t	to_miscshort;	/* misc short commands (NOOP, VERB, etc) */
1068 	time_t	to_ident;	/* IDENT protocol requests */
1069 	time_t	to_fileopen;	/* opening :include: and .forward files */
1070 			/* following are per message */
1071 	time_t	to_q_return[MAXTOCLASS];	/* queue return timeouts */
1072 	time_t	to_q_warning[MAXTOCLASS];	/* queue warning timeouts */
1073 } TimeOuts;
1074 
1075 /* timeout classes for return and warning timeouts */
1076 # define TOC_NORMAL	0	/* normal delivery */
1077 # define TOC_URGENT	1	/* urgent delivery */
1078 # define TOC_NONURGENT	2	/* non-urgent delivery */
1079 
1080 
1081 /*
1082 **  Trace information
1083 */
1084 
1085 /* trace vector and macros for debugging flags */
1086 EXTERN u_char	tTdvect[100];
1087 # define tTd(flag, level)	(tTdvect[flag] >= level)
1088 # define tTdlevel(flag)		(tTdvect[flag])
1089 /*
1090 **  Miscellaneous information.
1091 */
1092 
1093 
1094 
1095 /*
1096 **  Some in-line functions
1097 */
1098 
1099 /* set exit status */
1100 #define setstat(s)	{ \
1101 				if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \
1102 					ExitStat = s; \
1103 			}
1104 
1105 /* make a copy of a string */
1106 #define newstr(s)	strcpy(xalloc(strlen(s) + 1), s)
1107 
1108 #define STRUCTCOPY(s, d)	d = s
1109 
1110 
1111 /*
1112 **  Declarations of useful functions
1113 */
1114 
1115 extern char	*xalloc __P((int));
1116 extern FILE	*dfopen __P((char *, int, int));
1117 extern char	*sfgets __P((char *, int, FILE *, time_t, char *));
1118 extern char	*queuename __P((ENVELOPE *, int));
1119 extern time_t	curtime __P(());
1120 extern bool	transienterror __P((int));
1121 extern char	*fgetfolded __P((char *, int, FILE *));
1122 extern char	*username __P(());
1123 extern char	*pintvl __P((time_t, bool));
1124 extern char	*anynet_ntoa __P((SOCKADDR *));
1125 extern bool	shouldqueue __P((long, time_t));
1126 extern bool	lockfile __P((int, char *, char *, int));
1127 extern char	*hostsignature __P((MAILER *, char *, ENVELOPE *));
1128 extern void	openxscript __P((ENVELOPE *));
1129 extern void	closexscript __P((ENVELOPE *));
1130 extern char	*shortenstring __P((const char *, int));
1131 extern bool	usershellok __P((char *, char *));
1132 extern void	commaize __P((HDR *, char *, bool, MCI *, ENVELOPE *));
1133 extern char	*hvalue __P((char *, HDR *));
1134 extern char	*defcharset __P((ENVELOPE *));
1135 extern bool	wordinclass __P((char *, int));
1136 extern char	*denlstring __P((char *, bool, bool));
1137 extern void	makelower __P((char *));
1138 extern void	rebuildaliases __P((MAP *, bool));
1139 extern void	readaliases __P((MAP *, FILE *, bool, bool));
1140 extern void	finis __P(());
1141 extern void	setsender __P((char *, ENVELOPE *, char **, bool));
1142 extern FILE	*safefopen __P((char *, int, int, int));
1143 extern void	xputs __P((const char *));
1144 extern void	logsender __P((ENVELOPE *, char *));
1145 extern void	smtprset __P((MAILER *, MCI *, ENVELOPE *));
1146 extern void	smtpquit __P((MAILER *, MCI *, ENVELOPE *));
1147 extern void	setuserenv __P((const char *, const char *));
1148 extern void	disconnect __P((int, ENVELOPE *));
1149 extern void	putxline __P((char *, MCI *, int));
1150 extern void	dumpfd __P((int, bool, bool));
1151 extern void	makemailer __P((char *));
1152 extern void	putfromline __P((MCI *, ENVELOPE *));
1153 extern void	setoption __P((int, char *, bool, bool, ENVELOPE *));
1154 extern void	setclass __P((int, char *));
1155 extern void	inittimeouts __P((char *));
1156 extern void	logdelivery __P((MAILER *, MCI *, const char *, ADDRESS *, time_t, ENVELOPE *));
1157 extern void	giveresponse __P((int, MAILER *, MCI *, ADDRESS *, time_t, ENVELOPE *));
1158 
1159 extern const char	*errstring __P((int));
1160 extern sigfunc_t	setsignal __P((int, sigfunc_t));
1161 extern struct hostent	*sm_gethostbyname __P((char *));
1162 extern struct hostent	*sm_gethostbyaddr __P((char *, int, int));
1163 extern struct passwd	*sm_getpwnam __P((char *));
1164 extern struct passwd	*sm_getpwuid __P((UID_T));
1165 
1166 #ifdef XDEBUG
1167 extern void		checkfd012 __P((char *));
1168 #endif
1169 
1170 /* ellipsis is a different case though */
1171 #ifdef __STDC__
1172 extern void		auth_warning(ENVELOPE *, const char *, ...);
1173 extern void		syserr(const char *, ...);
1174 extern void		usrerr(const char *, ...);
1175 extern void		message(const char *, ...);
1176 extern void		nmessage(const char *, ...);
1177 #else
1178 extern void		auth_warning();
1179 extern void		syserr();
1180 extern void		usrerr();
1181 extern void		message();
1182 extern void		nmessage();
1183 #endif
1184