xref: /freebsd/contrib/sendmail/src/sendmail.h (revision b6bacd3150f411c3de886f7615bc22129b6974ad)
1 /*
2  * Copyright (c) 1998-2004 Sendmail, Inc. and its suppliers.
3  *	All rights reserved.
4  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
5  * Copyright (c) 1988, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * By using this file, you agree to the terms and conditions set
9  * forth in the LICENSE file which can be found at the top level of
10  * the sendmail distribution.
11  */
12 
13 /*
14 **  SENDMAIL.H -- MTA-specific definitions for sendmail.
15 */
16 
17 #ifndef _SENDMAIL_H
18 # define _SENDMAIL_H 1
19 
20 #ifndef MILTER
21 # define MILTER	1	/* turn on MILTER by default */
22 #endif /* MILTER */
23 
24 #ifdef _DEFINE
25 # define EXTERN
26 #else /* _DEFINE */
27 # define EXTERN extern
28 #endif /* _DEFINE */
29 
30 
31 #include <unistd.h>
32 
33 #include <stddef.h>
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <ctype.h>
37 #include <setjmp.h>
38 #include <string.h>
39 #include <time.h>
40 # ifdef EX_OK
41 #  undef EX_OK			/* for SVr4.2 SMP */
42 # endif /* EX_OK */
43 
44 #include "sendmail/sendmail.h"
45 
46 /* profiling? */
47 #if MONCONTROL
48 # define SM_PROF(x)	moncontrol(x)
49 #else /* MONCONTROL */
50 # define SM_PROF(x)
51 #endif /* MONCONTROL */
52 
53 #ifdef _DEFINE
54 # ifndef lint
55 SM_UNUSED(static char SmailId[]) = "@(#)$Id: sendmail.h,v 8.990 2004/11/09 19:45:46 ca Exp $";
56 # endif /* ! lint */
57 #endif /* _DEFINE */
58 
59 #include "bf.h"
60 #include "timers.h"
61 #include <sm/exc.h>
62 #include <sm/heap.h>
63 #include <sm/debug.h>
64 #include <sm/rpool.h>
65 #include <sm/io.h>
66 #include <sm/path.h>
67 #include <sm/signal.h>
68 #include <sm/clock.h>
69 #include <sm/mbdb.h>
70 #include <sm/errstring.h>
71 #include <sm/sysexits.h>
72 #include <sm/shm.h>
73 
74 #ifdef LOG
75 # include <syslog.h>
76 #endif /* LOG */
77 
78 
79 
80 # if NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25
81 #  include <sys/socket.h>
82 # endif /* NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25 */
83 # if NETUNIX
84 #  include <sys/un.h>
85 # endif /* NETUNIX */
86 # if NETINET || NETINET6
87 #  include <netinet/in.h>
88 # endif /* NETINET || NETINET6 */
89 # if NETINET6
90 /*
91 **  There is no standard yet for IPv6 includes.
92 **  Specify OS specific implementation in conf.h
93 */
94 # endif /* NETINET6 */
95 # if NETISO
96 #  include <netiso/iso.h>
97 # endif /* NETISO */
98 # if NETNS
99 #  include <netns/ns.h>
100 # endif /* NETNS */
101 # if NETX25
102 #  include <netccitt/x25.h>
103 # endif /* NETX25 */
104 
105 # if NAMED_BIND
106 #  include <arpa/nameser.h>
107 #  ifdef NOERROR
108 #   undef NOERROR		/* avoid <sys/streams.h> conflict */
109 #  endif /* NOERROR */
110 #  include <resolv.h>
111 # else /* NAMED_BIND */
112 #   undef SM_SET_H_ERRNO
113 #   define SM_SET_H_ERRNO(err)
114 # endif /* NAMED_BIND */
115 
116 # if HESIOD
117 #  include <hesiod.h>
118 #  if !defined(HES_ER_OK) || defined(HESIOD_INTERFACES)
119 #   define HESIOD_INIT		/* support for the new interface */
120 #  endif /* !defined(HES_ER_OK) || defined(HESIOD_INTERFACES) */
121 # endif /* HESIOD */
122 
123 #if STARTTLS
124 #  include <openssl/ssl.h>
125 # if !TLS_NO_RSA
126 #  define RSA_KEYLENGTH	512
127 # endif /* !TLS_NO_RSA */
128 #endif /* STARTTLS */
129 
130 #if SASL  /* include the sasl include files if we have them */
131 
132 
133 # if SASL == 2 || SASL >= 20000
134 #  include <sasl/sasl.h>
135 #  include <sasl/saslutil.h>
136 # else /* SASL == 2 || SASL >= 20000 */
137 #  include <sasl.h>
138 #  include <saslutil.h>
139 # endif /* SASL == 2 || SASL >= 20000 */
140 # if defined(SASL_VERSION_MAJOR) && defined(SASL_VERSION_MINOR) && defined(SASL_VERSION_STEP)
141 #  define SASL_VERSION (SASL_VERSION_MAJOR * 10000)  + (SASL_VERSION_MINOR * 100) + SASL_VERSION_STEP
142 #  if SASL == 1 || SASL == 2
143 #   undef SASL
144 #   define SASL SASL_VERSION
145 #  else /* SASL == 1 || SASL == 2 */
146 #   if SASL != SASL_VERSION
147   ERROR README: -DSASL (SASL) does not agree with the version of the CYRUS_SASL library (SASL_VERSION)
148   ERROR README: see README!
149 #   endif /* SASL != SASL_VERSION */
150 #  endif /* SASL == 1 || SASL == 2 */
151 # else /* defined(SASL_VERSION_MAJOR) && defined(SASL_VERSION_MINOR) && defined(SASL_VERSION_STEP) */
152 #  if SASL == 1
153   ERROR README: please set -DSASL to the version of the CYRUS_SASL library
154   ERROR README: see README!
155 #  endif /* SASL == 1 */
156 # endif /* defined(SASL_VERSION_MAJOR) && defined(SASL_VERSION_MINOR) && defined(SASL_VERSION_STEP) */
157 #endif /* SASL */
158 
159 /*
160 **  Following are "sort of" configuration constants, but they should
161 **  be pretty solid on most architectures today.  They have to be
162 **  defined after <arpa/nameser.h> because some versions of that
163 **  file also define them.  In all cases, we can't use sizeof because
164 **  some systems (e.g., Crays) always treat everything as being at
165 **  least 64 bits.
166 */
167 
168 #ifndef INADDRSZ
169 # define INADDRSZ	4		/* size of an IPv4 address in bytes */
170 #endif /* ! INADDRSZ */
171 #ifndef IN6ADDRSZ
172 # define IN6ADDRSZ	16		/* size of an IPv6 address in bytes */
173 #endif /* ! IN6ADDRSZ */
174 #ifndef INT16SZ
175 # define INT16SZ	2		/* size of a 16 bit integer in bytes */
176 #endif /* ! INT16SZ */
177 #ifndef INT32SZ
178 # define INT32SZ	4		/* size of a 32 bit integer in bytes */
179 #endif /* ! INT32SZ */
180 #ifndef INADDR_LOOPBACK
181 # define INADDR_LOOPBACK	0x7f000001	/* loopback address */
182 #endif /* ! INADDR_LOOPBACK */
183 
184 /*
185 **  Error return from inet_addr(3), in case not defined in /usr/include.
186 */
187 
188 #ifndef INADDR_NONE
189 # define INADDR_NONE	0xffffffff
190 #endif /* ! INADDR_NONE */
191 
192 
193 /* (f)open() modes for queue files */
194 # define QF_O_EXTRA	0
195 
196 
197 /*
198 **  An 'argument class' describes the storage allocation status
199 **  of an object pointed to by an argument to a function.
200 */
201 
202 typedef enum
203 {
204 	A_HEAP,	/* the storage was allocated by malloc, and the
205 		 * ownership of the storage is ceded by the caller
206 		 * to the called function. */
207 	A_TEMP, /* The storage is temporary, and is only guaranteed
208 		 * to be valid for the duration of the function call. */
209 	A_PERM	/* The storage is 'permanent': this might mean static
210 		 * storage, or rpool storage. */
211 } ARGCLASS_T;
212 
213 /* forward references for prototypes */
214 typedef struct envelope	ENVELOPE;
215 typedef struct mailer	MAILER;
216 typedef struct queuegrp	QUEUEGRP;
217 
218 /*
219 **  Address structure.
220 **	Addresses are stored internally in this structure.
221 */
222 
223 struct address
224 {
225 	char		*q_paddr;	/* the printname for the address */
226 	char		*q_user;	/* user name */
227 	char		*q_ruser;	/* real user name, or NULL if q_user */
228 	char		*q_host;	/* host name */
229 	struct mailer	*q_mailer;	/* mailer to use */
230 	unsigned long	q_flags;	/* status flags, see below */
231 	uid_t		q_uid;		/* user-id of receiver (if known) */
232 	gid_t		q_gid;		/* group-id of receiver (if known) */
233 	char		*q_home;	/* home dir (local mailer only) */
234 	char		*q_fullname;	/* full name if known */
235 	struct address	*q_next;	/* chain */
236 	struct address	*q_alias;	/* address this results from */
237 	char		*q_owner;	/* owner of q_alias */
238 	struct address	*q_tchain;	/* temporary use chain */
239 #if PIPELINING
240 	struct address	*q_pchain;	/* chain for pipelining */
241 #endif /* PIPELINING */
242 	char		*q_finalrcpt;	/* Final-Recipient: DSN header */
243 	char		*q_orcpt;	/* ORCPT parameter from RCPT TO: line */
244 	char		*q_status;	/* status code for DSNs */
245 	char		*q_rstatus;	/* remote status message for DSNs */
246 	time_t		q_statdate;	/* date of status messages */
247 	char		*q_statmta;	/* MTA generating q_rstatus */
248 	short		q_state;	/* address state, see below */
249 	char		*q_signature;	/* MX-based sorting value */
250 	int		q_qgrp;		/* index into queue groups */
251 	int		q_qdir;		/* queue directory inside group */
252 	char		*q_message;	/* error message */
253 };
254 
255 typedef struct address ADDRESS;
256 
257 /* bit values for q_flags */
258 #define QGOODUID	0x00000001	/* the q_uid q_gid fields are good */
259 #define QPRIMARY	0x00000002	/* set from RCPT or argv */
260 #define QNOTREMOTE	0x00000004	/* address not for remote forwarding */
261 #define QSELFREF	0x00000008	/* this address references itself */
262 #define QBOGUSSHELL	0x00000010	/* user has no valid shell listed */
263 #define QUNSAFEADDR	0x00000020	/* address acquired via unsafe path */
264 #define QPINGONSUCCESS	0x00000040	/* give return on successful delivery */
265 #define QPINGONFAILURE	0x00000080	/* give return on failure */
266 #define QPINGONDELAY	0x00000100	/* give return on message delay */
267 #define QHASNOTIFY	0x00000200	/* propagate notify parameter */
268 #define QRELAYED	0x00000400	/* DSN: relayed to non-DSN aware sys */
269 #define QEXPANDED	0x00000800	/* DSN: undergone list expansion */
270 #define QDELIVERED	0x00001000	/* DSN: successful final delivery */
271 #define QDELAYED	0x00002000	/* DSN: message delayed */
272 #define QALIAS		0x00004000	/* expanded alias */
273 #define QBYTRACE	0x00008000	/* DeliverBy: trace */
274 #define QBYNDELAY	0x00010000	/* DeliverBy: notify, delay */
275 #define QBYNRELAY	0x00020000	/* DeliverBy: notify, relayed */
276 #define QTHISPASS	0x40000000	/* temp: address set this pass */
277 #define QRCPTOK		0x80000000	/* recipient() processed address */
278 
279 #define Q_PINGFLAGS	(QPINGONSUCCESS|QPINGONFAILURE|QPINGONDELAY)
280 
281 /* values for q_state */
282 #define QS_OK		0		/* address ok (for now)/not yet tried */
283 #define QS_SENT		1		/* good address, delivery complete */
284 #define QS_BADADDR	2		/* illegal address */
285 #define QS_QUEUEUP	3		/* save address in queue */
286 #define QS_RETRY	4		/* retry delivery for next MX */
287 #define QS_VERIFIED	5		/* verified, but not expanded */
288 
289 /*
290 **  Notice: all of the following values are variations of QS_DONTSEND.
291 **	If new states are added, they must be inserted in the proper place!
292 **	See the macro definition of QS_IS_DEAD() down below.
293 */
294 
295 #define QS_DONTSEND	6		/* don't send to this address */
296 #define QS_EXPANDED	7		/* expanded */
297 #define QS_SENDER	8		/* message sender (MeToo) */
298 #define QS_CLONED	9		/* addr cloned to split envelope */
299 #define QS_DISCARDED	10		/* rcpt discarded (EF_DISCARD) */
300 #define QS_REPLACED	11		/* maplocaluser()/UserDB replaced */
301 #define QS_REMOVED	12		/* removed (removefromlist()) */
302 #define QS_DUPLICATE	13		/* duplicate suppressed */
303 #define QS_INCLUDED	14		/* :include: delivery */
304 #define QS_FATALERR	15		/* fatal error, don't deliver */
305 
306 /* address state testing primitives */
307 #define QS_IS_OK(s)		((s) == QS_OK)
308 #define QS_IS_SENT(s)		((s) == QS_SENT)
309 #define QS_IS_BADADDR(s)	((s) == QS_BADADDR)
310 #define QS_IS_QUEUEUP(s)	((s) == QS_QUEUEUP)
311 #define QS_IS_RETRY(s)		((s) == QS_RETRY)
312 #define QS_IS_VERIFIED(s)	((s) == QS_VERIFIED)
313 #define QS_IS_EXPANDED(s)	((s) == QS_EXPANDED)
314 #define QS_IS_REMOVED(s)	((s) == QS_REMOVED)
315 #define QS_IS_UNDELIVERED(s)	((s) == QS_OK || \
316 				 (s) == QS_QUEUEUP || \
317 				 (s) == QS_RETRY || \
318 				 (s) == QS_VERIFIED)
319 #define QS_IS_UNMARKED(s)	((s) == QS_OK || \
320 				 (s) == QS_RETRY)
321 #define QS_IS_SENDABLE(s)	((s) == QS_OK || \
322 				 (s) == QS_QUEUEUP || \
323 				 (s) == QS_RETRY)
324 #define QS_IS_ATTEMPTED(s)	((s) == QS_QUEUEUP || \
325 				 (s) == QS_RETRY || \
326 				 (s) == QS_SENT)
327 #define QS_IS_DEAD(s)		((s) >= QS_DONTSEND)
328 
329 
330 #define NULLADDR	((ADDRESS *) NULL)
331 
332 extern ADDRESS	NullAddress;	/* a null (template) address [main.c] */
333 
334 /* functions */
335 extern void	cataddr __P((char **, char **, char *, int, int));
336 extern char	*crackaddr __P((char *, ENVELOPE *));
337 extern bool	emptyaddr __P((ADDRESS *));
338 extern ADDRESS	*getctladdr __P((ADDRESS *));
339 extern int	include __P((char *, bool, ADDRESS *, ADDRESS **, int, ENVELOPE *));
340 extern bool	invalidaddr __P((char *, char *, bool));
341 extern ADDRESS	*parseaddr __P((char *, ADDRESS *, int, int, char **,
342 				ENVELOPE *, bool));
343 extern char	**prescan __P((char *, int, char[], int, char **, unsigned char *, bool));
344 extern void	printaddr __P((SM_FILE_T *, ADDRESS *, bool));
345 extern ADDRESS	*recipient __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
346 extern char	*remotename __P((char *, MAILER *, int, int *, ENVELOPE *));
347 extern int	rewrite __P((char **, int, int, ENVELOPE *, int));
348 extern bool	sameaddr __P((ADDRESS *, ADDRESS *));
349 extern int	sendtolist __P((char *, ADDRESS *, ADDRESS **, int, ENVELOPE *));
350 #if MILTER
351 extern int	removefromlist __P((char *, ADDRESS **, ENVELOPE *));
352 #endif /* MILTER */
353 extern void	setsender __P((char *, ENVELOPE *, char **, int, bool));
354 
355 /* macro to simplify the common call to rewrite() */
356 #define REWRITE(pvp, rs, env)	rewrite(pvp, rs, 0, env, MAXATOM)
357 
358 /*
359 **  Mailer definition structure.
360 **	Every mailer known to the system is declared in this
361 **	structure.  It defines the pathname of the mailer, some
362 **	flags associated with it, and the argument vector to
363 **	pass to it.  The flags are defined in conf.c
364 **
365 **	The argument vector is expanded before actual use.  All
366 **	words except the first are passed through the macro
367 **	processor.
368 */
369 
370 struct mailer
371 {
372 	char	*m_name;	/* symbolic name of this mailer */
373 	char	*m_mailer;	/* pathname of the mailer to use */
374 	char	*m_mtatype;	/* type of this MTA */
375 	char	*m_addrtype;	/* type for addresses */
376 	char	*m_diagtype;	/* type for diagnostics */
377 	BITMAP256 m_flags;	/* status flags, see below */
378 	short	m_mno;		/* mailer number internally */
379 	short	m_nice;		/* niceness to run at (mostly for prog) */
380 	char	**m_argv;	/* template argument vector */
381 	short	m_sh_rwset;	/* rewrite set: sender header addresses */
382 	short	m_se_rwset;	/* rewrite set: sender envelope addresses */
383 	short	m_rh_rwset;	/* rewrite set: recipient header addresses */
384 	short	m_re_rwset;	/* rewrite set: recipient envelope addresses */
385 	char	*m_eol;		/* end of line string */
386 	long	m_maxsize;	/* size limit on message to this mailer */
387 	int	m_linelimit;	/* max # characters per line */
388 	int	m_maxdeliveries; /* max deliveries per mailer connection */
389 	char	*m_execdir;	/* directory to chdir to before execv */
390 	char	*m_rootdir;	/* directory to chroot to before execv */
391 	uid_t	m_uid;		/* UID to run as */
392 	gid_t	m_gid;		/* GID to run as */
393 	char	*m_defcharset;	/* default character set */
394 	time_t	m_wait;		/* timeout to wait for end */
395 	int	m_maxrcpt;	/* max recipients per envelope client-side */
396 	short	m_qgrp;		/* queue group for this mailer */
397 };
398 
399 /* bits for m_flags */
400 #define M_ESMTP		'a'	/* run Extended SMTP */
401 #define M_ALIASABLE	'A'	/* user can be LHS of an alias */
402 #define M_BLANKEND	'b'	/* ensure blank line at end of message */
403 #define M_STRIPBACKSL	'B'	/* strip all leading backslashes from user */
404 #define M_NOCOMMENT	'c'	/* don't include comment part of address */
405 #define M_CANONICAL	'C'	/* make addresses canonical "u@dom" */
406 #define M_NOBRACKET	'd'	/* never angle bracket envelope route-addrs */
407 		/*	'D'	   CF: include Date: */
408 #define M_EXPENSIVE	'e'	/* it costs to use this mailer.... */
409 #define M_ESCFROM	'E'	/* escape From lines to >From */
410 #define M_FOPT		'f'	/* mailer takes picky -f flag */
411 		/*	'F'	   CF: include From: or Resent-From: */
412 #define M_NO_NULL_FROM	'g'	/* sender of errors should be $g */
413 #define M_HST_UPPER	'h'	/* preserve host case distinction */
414 #define M_PREHEAD	'H'	/* MAIL11V3: preview headers */
415 #define M_UDBENVELOPE	'i'	/* do udbsender rewriting on envelope */
416 #define M_INTERNAL	'I'	/* SMTP to another sendmail site */
417 #define M_UDBRECIPIENT	'j'	/* do udbsender rewriting on recipient lines */
418 #define M_NOLOOPCHECK	'k'	/* don't check for loops in HELO command */
419 #define M_CHUNKING	'K'	/* CHUNKING: reserved for future use */
420 #define M_LOCALMAILER	'l'	/* delivery is to this host */
421 #define M_LIMITS	'L'	/* must enforce SMTP line limits */
422 #define M_MUSER		'm'	/* can handle multiple users at once */
423 		/*	'M'	   CF: include Message-Id: */
424 #define M_NHDR		'n'	/* don't insert From line */
425 #define M_MANYSTATUS	'N'	/* MAIL11V3: DATA returns multi-status */
426 #define M_RUNASRCPT	'o'	/* always run mailer as recipient */
427 #define M_FROMPATH	'p'	/* use reverse-path in MAIL FROM: */
428 		/*	'P'	   CF: include Return-Path: */
429 #define M_VRFY250	'q'	/* VRFY command returns 250 instead of 252 */
430 #define M_ROPT		'r'	/* mailer takes picky -r flag */
431 #define M_SECURE_PORT	'R'	/* try to send on a reserved TCP port */
432 #define M_STRIPQ	's'	/* strip quote chars from user/host */
433 #define M_SPECIFIC_UID	'S'	/* run as specific uid/gid */
434 #define M_USR_UPPER	'u'	/* preserve user case distinction */
435 #define M_UGLYUUCP	'U'	/* this wants an ugly UUCP from line */
436 #define M_CONTENT_LEN	'v'	/* add Content-Length: header (SVr4) */
437 		/*	'V'	   UIUC: !-relativize all addresses */
438 #define M_HASPWENT	'w'	/* check for /etc/passwd entry */
439 #define M_NOHOSTSTAT	'W'	/* ignore long term host status information */
440 		/*	'x'	   CF: include Full-Name: */
441 #define M_XDOT		'X'	/* use hidden-dot algorithm */
442 #define M_LMTP		'z'	/* run Local Mail Transport Protocol */
443 #define M_DIALDELAY	'Z'	/* apply dial delay sleeptime */
444 #define M_NOMX		'0'	/* turn off MX lookups */
445 #define M_NONULLS	'1'	/* don't send null bytes */
446 #define M_FSMTP		'2'	/* force SMTP (no ESMTP even if offered) */
447 #define M_EBCDIC	'3'	/* extend Q-P encoding for EBCDIC */
448 #define M_TRYRULESET5	'5'	/* use ruleset 5 after local aliasing */
449 #define M_7BITHDRS	'6'	/* strip headers to 7 bits even in 8 bit path */
450 #define M_7BITS		'7'	/* use 7-bit path */
451 #define M_8BITS		'8'	/* force "just send 8" behaviour */
452 #define M_MAKE8BIT	'9'	/* convert 7 -> 8 bit if appropriate */
453 #define M_CHECKINCLUDE	':'	/* check for :include: files */
454 #define M_CHECKPROG	'|'	/* check for |program addresses */
455 #define M_CHECKFILE	'/'	/* check for /file addresses */
456 #define M_CHECKUDB	'@'	/* user can be user database key */
457 #define M_CHECKHDIR	'~'	/* SGI: check for valid home directory */
458 #define M_HOLD		'%'	/* Hold delivery until ETRN/-qI/-qR/-qS */
459 #define M_PLUS		'+'	/* Reserved: Used in mc for adding new flags */
460 #define M_MINUS		'-'	/* Reserved: Used in mc for removing flags */
461 
462 /* functions */
463 extern void	initerrmailers __P((void));
464 extern void	makemailer __P((char *));
465 extern void	makequeue __P((char *, bool));
466 extern void	runqueueevent __P((int));
467 #if _FFR_QUEUE_RUN_PARANOIA
468 extern bool	checkqueuerunner __P((void));
469 #endif /* _FFR_QUEUE_RUN_PARANOIA */
470 
471 EXTERN MAILER	*FileMailer;	/* ptr to *file* mailer */
472 EXTERN MAILER	*InclMailer;	/* ptr to *include* mailer */
473 EXTERN MAILER	*LocalMailer;	/* ptr to local mailer */
474 EXTERN MAILER	*ProgMailer;	/* ptr to program mailer */
475 EXTERN MAILER	*Mailer[MAXMAILERS + 1];
476 
477 /*
478 **  Queue group definition structure.
479 **	Every queue group known to the system is declared in this structure.
480 **	It defines the basic pathname of the queue group, some flags
481 **	associated with it, and the argument vector to pass to it.
482 */
483 
484 struct qpaths_s
485 {
486 	char	*qp_name;	/* name of queue dir, relative path */
487 	short	qp_subdirs;	/* use subdirs? */
488 	short	qp_fsysidx;	/* file system index of this directory */
489 # if SM_CONF_SHM
490 	int	qp_idx;		/* index into array for queue information */
491 # endif /* SM_CONF_SHM */
492 };
493 
494 typedef struct qpaths_s QPATHS;
495 
496 struct queuegrp
497 {
498 	char	*qg_name;	/* symbolic name of this queue group */
499 
500 	/*
501 	**  For now this is the same across all queue groups.
502 	**  Otherwise we have to play around with chdir().
503 	*/
504 
505 	char	*qg_qdir;	/* common component of queue directory */
506 	short	qg_index;	/* queue number internally, index in Queue[] */
507 	int	qg_maxqrun;	/* max # of jobs in 1 queuerun */
508 	int	qg_numqueues;	/* number of queues in this queue */
509 
510 	/*
511 	**  qg_queueintvl == 0 denotes that no individual value is used.
512 	**  Whatever accesses this must deal with "<= 0" as
513 	**  "not set, use appropriate default".
514 	*/
515 
516 	time_t	qg_queueintvl;	/* interval for queue runs */
517 	QPATHS	*qg_qpaths;	/* list of queue directories */
518 	BITMAP256 qg_flags;	/* status flags, see below */
519 	short	qg_nice;	/* niceness for queue run */
520 	int	qg_wgrp;	/* Assigned to this work group */
521 	int     qg_maxlist;	/* max items in work queue for this group */
522 	int     qg_curnum;	/* current number of queue for queue runs */
523 	int	qg_maxrcpt;	/* max recipients per envelope, 0==no limit */
524 
525 	time_t	qg_nextrun;	/* time for next queue runs */
526 #if _FFR_QUEUE_GROUP_SORTORDER
527 	short	qg_sortorder;	/* how do we sort this queuerun */
528 #endif /* _FFR_QUEUE_GROUP_SORTORDER */
529 #if 0
530 	long	qg_wkrcptfact;	/* multiplier for # recipients -> priority */
531 	long	qg_qfactor;	/* slope of queue function */
532 	bool	qg_doqueuerun;	/* XXX flag is it time to do a queuerun */
533 #endif /* 0 */
534 };
535 
536 /* bits for qg_flags (XXX: unused as of now) */
537 #define QD_DEFINED	((char) 1)	/* queue group has been defined */
538 #define QD_FORK		'f'	/* fork queue runs */
539 
540 extern void	filesys_update __P((void));
541 #if _FFR_ANY_FREE_FS
542 extern bool	filesys_free __P((long));
543 #endif /* _FFR_ANY_FREE_FS */
544 
545 #if SASL
546 /*
547 **  SASL
548 */
549 
550 /* lines in authinfo file or index into SASL_AI_T */
551 # define SASL_WRONG	(-1)
552 # define SASL_USER	0	/* authorization id (user) */
553 # define SASL_AUTHID	1	/* authentication id */
554 # define SASL_PASSWORD	2	/* password fuer authid */
555 # define SASL_DEFREALM	3	/* realm to use */
556 # define SASL_MECHLIST	4	/* list of mechanisms to try */
557 # define SASL_ID_REALM	5	/* authid@defrealm */
558 
559 /*
560 **  Current mechanism; this is just used to convey information between
561 **  invocation of SASL callback functions.
562 **  It must be last in the list, because it's not allocated by us
563 **  and hence we don't free() it.
564 */
565 # define SASL_MECH	6
566 # define SASL_ENTRIES	7	/* number of entries in array */
567 
568 # define SASL_USER_BIT		(1 << SASL_USER)
569 # define SASL_AUTHID_BIT	(1 << SASL_AUTHID)
570 # define SASL_PASSWORD_BIT	(1 << SASL_PASSWORD)
571 # define SASL_DEFREALM_BIT	(1 << SASL_DEFREALM)
572 # define SASL_MECHLIST_BIT	(1 << SASL_MECHLIST)
573 
574 /* authenticated? */
575 # define SASL_NOT_AUTH	0		/* not authenticated */
576 # define SASL_PROC_AUTH	1		/* in process of authenticating */
577 # define SASL_IS_AUTH	2		/* authenticated */
578 
579 /* SASL options */
580 # define SASL_AUTH_AUTH	0x1000		/* use auth= only if authenticated */
581 # if SASL >= 20101
582 #  define SASL_SEC_MASK	SASL_SEC_MAXIMUM /* mask for SASL_SEC_* values: sasl.h */
583 # else /* SASL >= 20101 */
584 #  define SASL_SEC_MASK	0x0fff		/* mask for SASL_SEC_* values: sasl.h */
585 #  if (SASL_SEC_NOPLAINTEXT & SASL_SEC_MASK) == 0 || \
586 	(SASL_SEC_NOACTIVE & SASL_SEC_MASK) == 0 || \
587 	(SASL_SEC_NODICTIONARY & SASL_SEC_MASK) == 0 || \
588 	(SASL_SEC_FORWARD_SECRECY & SASL_SEC_MASK) == 0 || \
589 	(SASL_SEC_NOANONYMOUS & SASL_SEC_MASK) == 0 || \
590 	(SASL_SEC_PASS_CREDENTIALS & SASL_SEC_MASK) == 0
591 ERROR: change SASL_SEC_MASK_ notify sendmail.org!
592 #  endif /* SASL_SEC_NOPLAINTEXT & SASL_SEC_MASK) == 0 ... */
593 # endif /* SASL >= 20101 */
594 # define MAXOUTLEN 8192			/* length of output buffer */
595 
596 /* functions */
597 extern char	*intersect __P((char *, char *, SM_RPOOL_T *));
598 extern char	*iteminlist __P((char *, char *, char *));
599 # if SASL >= 20000
600 extern int	proxy_policy __P((sasl_conn_t *, void *, const char *, unsigned, const char *, unsigned, const char *, unsigned, struct propctx *));
601 extern int	safesaslfile __P((void *, const char *, sasl_verify_type_t));
602 # else /* SASL >= 20000 */
603 extern int	proxy_policy __P((void *, const char *, const char *, const char **, const char **));
604 #  if SASL > 10515
605 extern int	safesaslfile __P((void *, char *, int));
606 #  else /* SASL > 10515 */
607 extern int	safesaslfile __P((void *, char *));
608 #  endif /* SASL > 10515 */
609 # endif /* SASL >= 20000 */
610 extern void	stop_sasl_client __P((void));
611 
612 /* structure to store authinfo */
613 typedef char *SASL_AI_T[SASL_ENTRIES];
614 
615 EXTERN char	*AuthMechanisms;	/* AUTH mechanisms */
616 EXTERN char	*AuthRealm;	/* AUTH realm */
617 EXTERN char	*SASLInfo;	/* file with AUTH info */
618 EXTERN int	SASLOpts;	/* options for SASL */
619 EXTERN int	MaxSLBits;	/* max. encryption bits for SASL */
620 #endif /* SASL */
621 
622 /*
623 **  Structure to store macros.
624 */
625 typedef struct
626 {
627 	SM_RPOOL_T	*mac_rpool;		/* resource pool */
628 	BITMAP256	mac_allocated;		/* storage has been alloc()? */
629 	char		*mac_table[MAXMACROID + 1];	/* macros */
630 } MACROS_T;
631 
632 EXTERN MACROS_T		GlobalMacros;
633 
634 /*
635 **  Information about currently open connections to mailers, or to
636 **  hosts that we have looked up recently.
637 */
638 
639 #define MCI		struct mailer_con_info
640 
641 MCI
642 {
643 	unsigned long	mci_flags;	/* flag bits, see below */
644 	short		mci_errno;	/* error number on last connection */
645 	short		mci_herrno;	/* h_errno from last DNS lookup */
646 	short		mci_exitstat;	/* exit status from last connection */
647 	short		mci_state;	/* SMTP state */
648 	int		mci_deliveries;	/* delivery attempts for connection */
649 	long		mci_maxsize;	/* max size this server will accept */
650 	SM_FILE_T	*mci_in;	/* input side of connection */
651 	SM_FILE_T	*mci_out;	/* output side of connection */
652 	pid_t		mci_pid;	/* process id of subordinate proc */
653 	char		*mci_phase;	/* SMTP phase string */
654 	struct mailer	*mci_mailer;	/* ptr to the mailer for this conn */
655 	char		*mci_host;	/* host name */
656 	char		*mci_status;	/* DSN status to be copied to addrs */
657 	char		*mci_rstatus;	/* SMTP status to be copied to addrs */
658 	time_t		mci_lastuse;	/* last usage time */
659 	SM_FILE_T	*mci_statfile;	/* long term status file */
660 	char		*mci_heloname;	/* name to use as HELO arg */
661 	long		mci_min_by;	/* minimum DELIVERBY */
662 	bool		mci_retryrcpt;	/* tempfail for at least one rcpt */
663 	char		*mci_tolist;	/* list of valid recipients */
664 	SM_RPOOL_T	*mci_rpool;	/* resource pool */
665 #if PIPELINING
666 	int		mci_okrcpts;	/* number of valid recipients */
667 	ADDRESS		*mci_nextaddr;	/* next address for pipelined status */
668 #endif /* PIPELINING */
669 #if SASL
670 	SASL_AI_T	mci_sai;	/* authentication info */
671 	bool		mci_sasl_auth;	/* authenticated? */
672 	int		mci_sasl_string_len;
673 	char		*mci_sasl_string;	/* sasl reply string */
674 	char		*mci_saslcap;	/* SASL list of mechanisms */
675 	sasl_conn_t	*mci_conn;	/* SASL connection */
676 #endif /* SASL */
677 #if STARTTLS
678 	SSL		*mci_ssl;	/* SSL connection */
679 #endif /* STARTTLS */
680 	MACROS_T	mci_macro;	/* macro definitions */
681 };
682 
683 
684 /* flag bits */
685 #define MCIF_VALID	0x00000001	/* this entry is valid */
686 /* 0x00000002 unused, was MCIF_TEMP */
687 #define MCIF_CACHED	0x00000004	/* currently in open cache */
688 #define MCIF_ESMTP	0x00000008	/* this host speaks ESMTP */
689 #define MCIF_EXPN	0x00000010	/* EXPN command supported */
690 #define MCIF_SIZE	0x00000020	/* SIZE option supported */
691 #define MCIF_8BITMIME	0x00000040	/* BODY=8BITMIME supported */
692 #define MCIF_7BIT	0x00000080	/* strip this message to 7 bits */
693 /* 0x00000100 unused, was MCIF_MULTSTAT: MAIL11V3: handles MULT status */
694 #define MCIF_INHEADER	0x00000200	/* currently outputing header */
695 #define MCIF_CVT8TO7	0x00000400	/* convert from 8 to 7 bits */
696 #define MCIF_DSN	0x00000800	/* DSN extension supported */
697 #define MCIF_8BITOK	0x00001000	/* OK to send 8 bit characters */
698 #define MCIF_CVT7TO8	0x00002000	/* convert from 7 to 8 bits */
699 #define MCIF_INMIME	0x00004000	/* currently reading MIME header */
700 #define MCIF_AUTH	0x00008000	/* AUTH= supported */
701 #define MCIF_AUTHACT	0x00010000	/* SASL (AUTH) active */
702 #define MCIF_ENHSTAT	0x00020000	/* ENHANCEDSTATUSCODES supported */
703 #define MCIF_PIPELINED	0x00040000	/* PIPELINING supported */
704 #define MCIF_VERB	0x00080000	/* VERB supported */
705 #if STARTTLS
706 #define MCIF_TLS	0x00100000	/* STARTTLS supported */
707 #define MCIF_TLSACT	0x00200000	/* STARTTLS active */
708 #define MCIF_EXTENS	(MCIF_EXPN | MCIF_SIZE | MCIF_8BITMIME | MCIF_DSN | MCIF_8BITOK | MCIF_AUTH | MCIF_ENHSTAT | MCIF_TLS)
709 #else /* STARTTLS */
710 #define MCIF_EXTENS	(MCIF_EXPN | MCIF_SIZE | MCIF_8BITMIME | MCIF_DSN | MCIF_8BITOK | MCIF_AUTH | MCIF_ENHSTAT)
711 #endif /* STARTTLS */
712 #define MCIF_DLVR_BY	0x00400000	/* DELIVERBY */
713 #if _FFR_IGNORE_EXT_ON_HELO
714 # define MCIF_HELO	0x00800000	/* we used HELO: ignore extensions */
715 #endif /* _FFR_IGNORE_EXT_ON_HELO */
716 #define MCIF_ONLY_EHLO	0x10000000	/* use only EHLO in smtpinit */
717 
718 /* states */
719 #define MCIS_CLOSED	0		/* no traffic on this connection */
720 #define MCIS_OPENING	1		/* sending initial protocol */
721 #define MCIS_OPEN	2		/* open, initial protocol sent */
722 #define MCIS_MAIL	3		/* MAIL command sent */
723 #define MCIS_RCPT	4		/* RCPT commands being sent */
724 #define MCIS_DATA	5		/* DATA command sent */
725 #define MCIS_QUITING	6		/* running quit protocol */
726 #define MCIS_SSD	7		/* service shutting down */
727 #define MCIS_ERROR	8		/* I/O error on connection */
728 
729 /* functions */
730 extern void	mci_cache __P((MCI *));
731 extern void	mci_dump __P((SM_FILE_T *, MCI *, bool));
732 extern void	mci_dump_all __P((SM_FILE_T *, bool));
733 extern void	mci_flush __P((bool, MCI *));
734 extern MCI	*mci_get __P((char *, MAILER *));
735 extern int	mci_lock_host __P((MCI *));
736 extern bool	mci_match __P((char *, MAILER *));
737 extern int	mci_print_persistent __P((char *, char *));
738 extern int	mci_purge_persistent __P((char *, char *));
739 extern MCI	**mci_scan __P((MCI *));
740 extern void	mci_setstat __P((MCI *, int, char *, char *));
741 extern void	mci_store_persistent __P((MCI *));
742 extern int	mci_traverse_persistent __P((int (*)(), char *));
743 extern void	mci_unlock_host __P((MCI *));
744 
745 EXTERN int	MaxMciCache;		/* maximum entries in MCI cache */
746 EXTERN time_t	MciCacheTimeout;	/* maximum idle time on connections */
747 EXTERN time_t	MciInfoTimeout;		/* how long 'til we retry down hosts */
748 
749 /*
750 **  Header structure.
751 **	This structure is used internally to store header items.
752 */
753 
754 struct header
755 {
756 	char		*h_field;	/* the name of the field */
757 	char		*h_value;	/* the value of that field */
758 	struct header	*h_link;	/* the next header */
759 	unsigned char	h_macro;	/* include header if macro defined */
760 	unsigned long	h_flags;	/* status bits, see below */
761 	BITMAP256	h_mflags;	/* m_flags bits needed */
762 };
763 
764 typedef struct header	HDR;
765 
766 /*
767 **  Header information structure.
768 **	Defined in conf.c, this struct declares the header fields
769 **	that have some magic meaning.
770 */
771 
772 struct hdrinfo
773 {
774 	char		*hi_field;	/* the name of the field */
775 	unsigned long	hi_flags;	/* status bits, see below */
776 	char		*hi_ruleset;	/* validity check ruleset */
777 };
778 
779 extern struct hdrinfo	HdrInfo[];
780 
781 /* bits for h_flags and hi_flags */
782 #define H_EOH		0x00000001	/* field terminates header */
783 #define H_RCPT		0x00000002	/* contains recipient addresses */
784 #define H_DEFAULT	0x00000004	/* if another value is found, drop this */
785 #define H_RESENT	0x00000008	/* this address is a "Resent-..." address */
786 #define H_CHECK		0x00000010	/* check h_mflags against m_flags */
787 #define H_ACHECK	0x00000020	/* ditto, but always (not just default) */
788 #define H_FORCE		0x00000040	/* force this field, even if default */
789 #define H_TRACE		0x00000080	/* this field contains trace information */
790 #define H_FROM		0x00000100	/* this is a from-type field */
791 #define H_VALID		0x00000200	/* this field has a validated value */
792 #define H_RECEIPTTO	0x00000400	/* field has return receipt info */
793 #define H_ERRORSTO	0x00000800	/* field has error address info */
794 #define H_CTE		0x00001000	/* field is a content-transfer-encoding */
795 #define H_CTYPE		0x00002000	/* this is a content-type field */
796 #define H_BCC		0x00004000	/* Bcc: header: strip value or delete */
797 #define H_ENCODABLE	0x00008000	/* field can be RFC 1522 encoded */
798 #define H_STRIPCOMM	0x00010000	/* header check: strip comments */
799 #define H_BINDLATE	0x00020000	/* only expand macros at deliver */
800 #define H_USER		0x00040000	/* header came from the user/SMTP */
801 
802 /* bits for chompheader() */
803 #define CHHDR_DEF	0x0001	/* default header */
804 #define CHHDR_CHECK	0x0002	/* call ruleset for header */
805 #define CHHDR_USER	0x0004	/* header from user */
806 #define CHHDR_QUEUE	0x0008	/* header from queue file */
807 
808 /* functions */
809 extern void	addheader __P((char *, char *, int, ENVELOPE *));
810 extern unsigned long	chompheader __P((char *, int, HDR **, ENVELOPE *));
811 extern void	commaize __P((HDR *, char *, bool, MCI *, ENVELOPE *));
812 extern HDR	*copyheader __P((HDR *, SM_RPOOL_T *));
813 extern void	eatheader __P((ENVELOPE *, bool, bool));
814 extern char	*hvalue __P((char *, HDR *));
815 extern void	insheader __P((int, char *, char *, int, ENVELOPE *));
816 extern bool	isheader __P((char *));
817 extern void	putfromline __P((MCI *, ENVELOPE *));
818 extern void	setupheaders __P((void));
819 
820 /*
821 **  Performance monitoring
822 */
823 
824 #define TIMERS		struct sm_timers
825 
826 TIMERS
827 {
828 	TIMER	ti_overall;	/* the whole process */
829 };
830 
831 
832 #define PUSHTIMER(l, t)	{ if (tTd(98, l)) pushtimer(&t); }
833 #define POPTIMER(l, t)	{ if (tTd(98, l)) poptimer(&t); }
834 
835 /*
836 **  Envelope structure.
837 **	This structure defines the message itself.  There is usually
838 **	only one of these -- for the message that we originally read
839 **	and which is our primary interest -- but other envelopes can
840 **	be generated during processing.  For example, error messages
841 **	will have their own envelope.
842 */
843 
844 struct envelope
845 {
846 	HDR		*e_header;	/* head of header list */
847 	long		e_msgpriority;	/* adjusted priority of this message */
848 	time_t		e_ctime;	/* time message appeared in the queue */
849 	char		*e_to;		/* (list of) target person(s) */
850 	ADDRESS		e_from;		/* the person it is from */
851 	char		*e_sender;	/* e_from.q_paddr w comments stripped */
852 	char		**e_fromdomain;	/* the domain part of the sender */
853 	ADDRESS		*e_sendqueue;	/* list of message recipients */
854 	ADDRESS		*e_errorqueue;	/* the queue for error responses */
855 
856 	/*
857 	**  Overflow detection is based on < 0, so don't change this
858 	**  to unsigned.  We don't use unsigned and == ULONG_MAX because
859 	**  some libc's don't have strtoul(), see mail_esmtp_args().
860 	*/
861 
862 	long		e_msgsize;	/* size of the message in bytes */
863 	char		*e_msgid;	/* message id (for logging) */
864 	unsigned long	e_flags;	/* flags, see below */
865 	int		e_nrcpts;	/* number of recipients */
866 	short		e_class;	/* msg class (priority, junk, etc.) */
867 	short		e_hopcount;	/* number of times processed */
868 	short		e_nsent;	/* number of sends since checkpoint */
869 	short		e_sendmode;	/* message send mode */
870 	short		e_errormode;	/* error return mode */
871 	short		e_timeoutclass;	/* message timeout class */
872 	void		(*e_puthdr)__P((MCI *, HDR *, ENVELOPE *, int));
873 					/* function to put header of message */
874 	void		(*e_putbody)__P((MCI *, ENVELOPE *, char *));
875 					/* function to put body of message */
876 	ENVELOPE	*e_parent;	/* the message this one encloses */
877 	ENVELOPE	*e_sibling;	/* the next envelope of interest */
878 	char		*e_bodytype;	/* type of message body */
879 	SM_FILE_T	*e_dfp;		/* data file */
880 	char		*e_id;		/* code for this entry in queue */
881 	int		e_qgrp;		/* queue group (index into queues) */
882 	int		e_qdir;		/* index into queue directories */
883 	int		e_dfqgrp;	/* data file queue group index */
884 	int		e_dfqdir;	/* data file queue directory index */
885 	int		e_xfqgrp;	/* queue group (index into queues) */
886 	int		e_xfqdir;	/* index into queue directories (xf) */
887 	SM_FILE_T	*e_xfp;		/* transcript file */
888 	SM_FILE_T	*e_lockfp;	/* the lock file for this message */
889 	char		*e_message;	/* error message; readonly; NULL, or
890 					 * static storage, or allocated from
891 					 * e_rpool */
892 	char		*e_statmsg;	/* stat msg (changes per delivery).
893 					 * readonly. NULL or allocated from
894 					 * e_rpool. */
895 	char		*e_quarmsg;	/* why envelope is quarantined */
896 	char		e_qfletter;	/* queue file letter on disk */
897 	char		*e_msgboundary;	/* MIME-style message part boundary */
898 	char		*e_origrcpt;	/* original recipient (one only) */
899 	char		*e_envid;	/* envelope id from MAIL FROM: line */
900 	char		*e_status;	/* DSN status for this message */
901 	time_t		e_dtime;	/* time of last delivery attempt */
902 	int		e_ntries;	/* number of delivery attempts */
903 	dev_t		e_dfdev;	/* data file device (crash recovery) */
904 	ino_t		e_dfino;	/* data file inode (crash recovery) */
905 	MACROS_T	e_macro;	/* macro definitions */
906 	MCI		*e_mci;		/* connection info */
907 	char		*e_auth_param;	/* readonly; NULL or static storage or
908 					 * allocated from e_rpool */
909 	TIMERS		e_timers;	/* per job timers */
910 	long		e_deliver_by;	/* deliver by */
911 	int		e_dlvr_flag;	/* deliver by flag */
912 	SM_RPOOL_T	*e_rpool;	/* resource pool for this envelope */
913 };
914 
915 /* values for e_flags */
916 #define EF_OLDSTYLE	0x00000001L	/* use spaces (not commas) in hdrs */
917 #define EF_INQUEUE	0x00000002L	/* this message is fully queued */
918 #define EF_NO_BODY_RETN	0x00000004L	/* omit message body on error */
919 #define EF_CLRQUEUE	0x00000008L	/* disk copy is no longer needed */
920 #define EF_SENDRECEIPT	0x00000010L	/* send a return receipt */
921 #define EF_FATALERRS	0x00000020L	/* fatal errors occurred */
922 #define EF_DELETE_BCC	0x00000040L	/* delete Bcc: headers entirely */
923 #define EF_RESPONSE	0x00000080L	/* this is an error or return receipt */
924 #define EF_RESENT	0x00000100L	/* this message is being forwarded */
925 #define EF_VRFYONLY	0x00000200L	/* verify only (don't expand aliases) */
926 #define EF_WARNING	0x00000400L	/* warning message has been sent */
927 #define EF_QUEUERUN	0x00000800L	/* this envelope is from queue */
928 #define EF_GLOBALERRS	0x00001000L	/* treat errors as global */
929 #define EF_PM_NOTIFY	0x00002000L	/* send return mail to postmaster */
930 #define EF_METOO	0x00004000L	/* send to me too */
931 #define EF_LOGSENDER	0x00008000L	/* need to log the sender */
932 #define EF_NORECEIPT	0x00010000L	/* suppress all return-receipts */
933 #define EF_HAS8BIT	0x00020000L	/* at least one 8-bit char in body */
934 #define EF_NL_NOT_EOL	0x00040000L	/* don't accept raw NL as EOLine */
935 #define EF_CRLF_NOT_EOL	0x00080000L	/* don't accept CR-LF as EOLine */
936 #define EF_RET_PARAM	0x00100000L	/* RCPT command had RET argument */
937 #define EF_HAS_DF	0x00200000L	/* set when data file is instantiated */
938 #define EF_IS_MIME	0x00400000L	/* really is a MIME message */
939 #define EF_DONT_MIME	0x00800000L	/* never MIME this message */
940 #define EF_DISCARD	0x01000000L	/* discard the message */
941 #define EF_TOOBIG	0x02000000L	/* message is too big */
942 #define EF_SPLIT	0x04000000L	/* envelope has been split */
943 #define EF_UNSAFE	0x08000000L	/* unsafe: read from untrusted source */
944 
945 #define DLVR_NOTIFY	0x01
946 #define DLVR_RETURN	0x02
947 #define DLVR_TRACE	0x10
948 #define IS_DLVR_NOTIFY(e)	(((e)->e_dlvr_flag & DLVR_NOTIFY) != 0)
949 #define IS_DLVR_RETURN(e)	(((e)->e_dlvr_flag & DLVR_RETURN) != 0)
950 #define IS_DLVR_TRACE(e)	(((e)->e_dlvr_flag & DLVR_TRACE) != 0)
951 #define IS_DLVR_BY(e)		((e)->e_dlvr_flag != 0)
952 
953 #define BODYTYPE_NONE	(0)
954 #define BODYTYPE_7BIT	(1)
955 #define BODYTYPE_8BITMIME	(2)
956 #define BODYTYPE_ILLEGAL	(-1)
957 #define BODYTYPE_VALID(b) ((b) == BODYTYPE_7BIT || (b) == BODYTYPE_8BITMIME)
958 
959 extern ENVELOPE	BlankEnvelope;
960 
961 /* functions */
962 extern void	clearenvelope __P((ENVELOPE *, bool, SM_RPOOL_T *));
963 extern void	dropenvelope __P((ENVELOPE *, bool, bool));
964 extern ENVELOPE	*newenvelope __P((ENVELOPE *, ENVELOPE *, SM_RPOOL_T *));
965 extern void	clrsessenvelope __P((ENVELOPE *));
966 extern void	printenvflags __P((ENVELOPE *));
967 extern void	putbody __P((MCI *, ENVELOPE *, char *));
968 extern void	putheader __P((MCI *, HDR *, ENVELOPE *, int));
969 
970 /*
971 **  Message priority classes.
972 **
973 **	The message class is read directly from the Priority: header
974 **	field in the message.
975 **
976 **	CurEnv->e_msgpriority is the number of bytes in the message plus
977 **	the creation time (so that jobs ``tend'' to be ordered correctly),
978 **	adjusted by the message class, the number of recipients, and the
979 **	amount of time the message has been sitting around.  This number
980 **	is used to order the queue.  Higher values mean LOWER priority.
981 **
982 **	Each priority class point is worth WkClassFact priority points;
983 **	each recipient is worth WkRecipFact priority points.  Each time
984 **	we reprocess a message the priority is adjusted by WkTimeFact.
985 **	WkTimeFact should normally decrease the priority so that jobs
986 **	that have historically failed will be run later; thanks go to
987 **	Jay Lepreau at Utah for pointing out the error in my thinking.
988 **
989 **	The "class" is this number, unadjusted by the age or size of
990 **	this message.  Classes with negative representations will have
991 **	error messages thrown away if they are not local.
992 */
993 
994 struct priority
995 {
996 	char	*pri_name;	/* external name of priority */
997 	int	pri_val;	/* internal value for same */
998 };
999 
1000 EXTERN int	NumPriorities;	/* pointer into Priorities */
1001 EXTERN struct priority	Priorities[MAXPRIORITIES];
1002 
1003 /*
1004 **  Rewrite rules.
1005 */
1006 
1007 struct rewrite
1008 {
1009 	char	**r_lhs;	/* pattern match */
1010 	char	**r_rhs;	/* substitution value */
1011 	struct rewrite	*r_next;/* next in chain */
1012 	int	r_line;		/* rule line in sendmail.cf */
1013 };
1014 
1015 /*
1016 **  Special characters in rewriting rules.
1017 **	These are used internally only.
1018 **	The COND* rules are actually used in macros rather than in
1019 **		rewriting rules, but are given here because they
1020 **		cannot conflict.
1021 */
1022 
1023 /* left hand side items */
1024 #define MATCHZANY	((unsigned char)0220)	/* match zero or more tokens */
1025 #define MATCHANY	((unsigned char)0221)	/* match one or more tokens */
1026 #define MATCHONE	((unsigned char)0222)	/* match exactly one token */
1027 #define MATCHCLASS	((unsigned char)0223)	/* match one token in a class */
1028 #define MATCHNCLASS	((unsigned char)0224)	/* match anything not in class */
1029 #define MATCHREPL	((unsigned char)0225)	/* replacement on RHS for above */
1030 
1031 /* right hand side items */
1032 #define CANONNET	((unsigned char)0226)	/* canonical net, next token */
1033 #define CANONHOST	((unsigned char)0227)	/* canonical host, next token */
1034 #define CANONUSER	((unsigned char)0230)	/* canonical user, next N tokens */
1035 #define CALLSUBR	((unsigned char)0231)	/* call another rewriting set */
1036 
1037 /* conditionals in macros */
1038 #define CONDIF		((unsigned char)0232)	/* conditional if-then */
1039 #define CONDELSE	((unsigned char)0233)	/* conditional else */
1040 #define CONDFI		((unsigned char)0234)	/* conditional fi */
1041 
1042 /* bracket characters for host name lookup */
1043 #define HOSTBEGIN	((unsigned char)0235)	/* hostname lookup begin */
1044 #define HOSTEND	((unsigned char)0236)	/* hostname lookup end */
1045 
1046 /* bracket characters for generalized lookup */
1047 #define LOOKUPBEGIN	((unsigned char)0205)	/* generalized lookup begin */
1048 #define LOOKUPEND	((unsigned char)0206)	/* generalized lookup end */
1049 
1050 /* macro substitution character */
1051 #define MACROEXPAND	((unsigned char)0201)	/* macro expansion */
1052 #define MACRODEXPAND	((unsigned char)0202)	/* deferred macro expansion */
1053 
1054 /* to make the code clearer */
1055 #define MATCHZERO	CANONHOST
1056 
1057 #define MAXMATCH	9	/* max params per rewrite */
1058 #define MAX_MAP_ARGS	10	/* max arguments for map */
1059 
1060 /* external <==> internal mapping table */
1061 struct metamac
1062 {
1063 	char		metaname;	/* external code (after $) */
1064 	unsigned char	metaval;	/* internal code (as above) */
1065 };
1066 
1067 /* values for macros with external names only */
1068 #define MID_OPMODE	0202	/* operation mode */
1069 
1070 /* functions */
1071 #if SM_HEAP_CHECK
1072 extern void
1073 macdefine_tagged __P((
1074 	MACROS_T *_mac,
1075 	ARGCLASS_T _vclass,
1076 	int _id,
1077 	char *_value,
1078 	char *_file,
1079 	int _line,
1080 	int _group));
1081 # define macdefine(mac,c,id,v) \
1082 	macdefine_tagged(mac,c,id,v,__FILE__,__LINE__,sm_heap_group())
1083 #else /* SM_HEAP_CHECK */
1084 extern void
1085 macdefine __P((
1086 	MACROS_T *_mac,
1087 	ARGCLASS_T _vclass,
1088 	int _id,
1089 	char *_value));
1090 # define macdefine_tagged(mac,c,id,v,file,line,grp) macdefine(mac,c,id,v)
1091 #endif /* SM_HEAP_CHECK */
1092 extern void	macset __P((MACROS_T *, int, char *));
1093 #define macget(mac, i) (mac)->mac_table[i]
1094 extern void	expand __P((char *, char *, size_t, ENVELOPE *));
1095 extern int	macid_parse __P((char *, char **));
1096 #define macid(name)  macid_parse(name, NULL)
1097 extern char	*macname __P((int));
1098 extern char	*macvalue __P((int, ENVELOPE *));
1099 extern int	rscheck __P((char *, char *, char *, ENVELOPE *, int, int, char *, char *));
1100 extern int	rscap __P((char *, char *, char *, ENVELOPE *, char ***, char *, int));
1101 extern void	setclass __P((int, char *));
1102 extern int	strtorwset __P((char *, char **, int));
1103 extern void	translate_dollars __P((char *));
1104 extern bool	wordinclass __P((char *, int));
1105 
1106 /*
1107 **  Name canonification short circuit.
1108 **
1109 **	If the name server for a host is down, the process of trying to
1110 **	canonify the name can hang.  This is similar to (but alas, not
1111 **	identical to) looking up the name for delivery.  This stab type
1112 **	caches the result of the name server lookup so we don't hang
1113 **	multiple times.
1114 */
1115 
1116 #define NAMECANON	struct _namecanon
1117 
1118 NAMECANON
1119 {
1120 	short		nc_errno;	/* cached errno */
1121 	short		nc_herrno;	/* cached h_errno */
1122 	short		nc_stat;	/* cached exit status code */
1123 	short		nc_flags;	/* flag bits */
1124 	char		*nc_cname;	/* the canonical name */
1125 	time_t		nc_exp;		/* entry expires at */
1126 };
1127 
1128 /* values for nc_flags */
1129 #define NCF_VALID	0x0001	/* entry valid */
1130 
1131 /* hostsignature structure */
1132 
1133 struct hostsig_t
1134 {
1135 	char		*hs_sig;	/* hostsignature */
1136 	time_t		hs_exp;		/* entry expires at */
1137 };
1138 
1139 typedef struct hostsig_t HOSTSIG_T;
1140 
1141 /* functions */
1142 extern bool	getcanonname __P((char *, int, bool, int *));
1143 extern int	getmxrr __P((char *, char **, unsigned short *, bool, int *, bool, int *));
1144 extern char	*hostsignature __P((MAILER *, char *));
1145 extern int	getfallbackmxrr __P((char *));
1146 
1147 /*
1148 **  Mapping functions
1149 **
1150 **	These allow arbitrary mappings in the config file.  The idea
1151 **	(albeit not the implementation) comes from IDA sendmail.
1152 */
1153 
1154 #define MAPCLASS	struct _mapclass
1155 #define MAP		struct _map
1156 #define MAXMAPACTIONS	5		/* size of map_actions array */
1157 
1158 
1159 /*
1160 **  An actual map.
1161 */
1162 
1163 MAP
1164 {
1165 	MAPCLASS	*map_class;	/* the class of this map */
1166 	MAPCLASS	*map_orgclass;	/* the original class of this map */
1167 	char		*map_mname;	/* name of this map */
1168 	long		map_mflags;	/* flags, see below */
1169 	char		*map_file;	/* the (nominal) filename */
1170 	ARBPTR_T	map_db1;	/* the open database ptr */
1171 	ARBPTR_T	map_db2;	/* an "extra" database pointer */
1172 	char		*map_keycolnm;	/* key column name */
1173 	char		*map_valcolnm;	/* value column name */
1174 	unsigned char	map_keycolno;	/* key column number */
1175 	unsigned char	map_valcolno;	/* value column number */
1176 	char		map_coldelim;	/* column delimiter */
1177 	char		map_spacesub;	/* spacesub */
1178 	char		*map_app;	/* to append to successful matches */
1179 	char		*map_tapp;	/* to append to "tempfail" matches */
1180 	char		*map_domain;	/* the (nominal) NIS domain */
1181 	char		*map_rebuild;	/* program to run to do auto-rebuild */
1182 	time_t		map_mtime;	/* last database modification time */
1183 	time_t		map_timeout;	/* timeout for map accesses */
1184 	int		map_retry;	/* # of retries for map accesses */
1185 	pid_t		map_pid;	/* PID of process which opened map */
1186 	int		map_lockfd;	/* auxiliary lock file descriptor */
1187 	short		map_specificity;	/* specificity of aliases */
1188 	MAP		*map_stack[MAXMAPSTACK];   /* list for stacked maps */
1189 	short		map_return[MAXMAPACTIONS]; /* return bitmaps for stacked maps */
1190 };
1191 
1192 
1193 /* bit values for map_mflags */
1194 #define MF_VALID	0x00000001	/* this entry is valid */
1195 #define MF_INCLNULL	0x00000002	/* include null byte in key */
1196 #define MF_OPTIONAL	0x00000004	/* don't complain if map not found */
1197 #define MF_NOFOLDCASE	0x00000008	/* don't fold case in keys */
1198 #define MF_MATCHONLY	0x00000010	/* don't use the map value */
1199 #define MF_OPEN		0x00000020	/* this entry is open */
1200 #define MF_WRITABLE	0x00000040	/* open for writing */
1201 #define MF_ALIAS	0x00000080	/* this is an alias file */
1202 #define MF_TRY0NULL	0x00000100	/* try with no null byte */
1203 #define MF_TRY1NULL	0x00000200	/* try with the null byte */
1204 #define MF_LOCKED	0x00000400	/* this map is currently locked */
1205 #define MF_ALIASWAIT	0x00000800	/* alias map in aliaswait state */
1206 #define MF_IMPL_HASH	0x00001000	/* implicit: underlying hash database */
1207 #define MF_IMPL_NDBM	0x00002000	/* implicit: underlying NDBM database */
1208 /* 0x00004000	*/
1209 #define MF_APPEND	0x00008000	/* append new entry on rebuild */
1210 #define MF_KEEPQUOTES	0x00010000	/* don't dequote key before lookup */
1211 #define MF_NODEFER	0x00020000	/* don't defer if map lookup fails */
1212 #define MF_REGEX_NOT	0x00040000	/* regular expression negation */
1213 #define MF_DEFER	0x00080000	/* don't lookup map in defer mode */
1214 #define MF_SINGLEMATCH	0x00100000	/* successful only if match one key */
1215 /*			0x00200000	   available for use */
1216 #define MF_FILECLASS	0x00400000	/* this is a file class map */
1217 #define MF_OPENBOGUS	0x00800000	/* open failed, don't call map_close */
1218 #define MF_CLOSING	0x01000000	/* map is being closed */
1219 
1220 #define DYNOPENMAP(map) if (!bitset(MF_OPEN, (map)->map_mflags)) \
1221 	{	\
1222 		if (!openmap(map))	\
1223 			return NULL;	\
1224 	}
1225 
1226 
1227 /* indices for map_actions */
1228 #define MA_NOTFOUND	0		/* member map returned "not found" */
1229 #define MA_UNAVAIL	1		/* member map is not available */
1230 #define MA_TRYAGAIN	2		/* member map returns temp failure */
1231 
1232 /* macros to handle MapTempFail */
1233 #define BIT_IS_MTP	0x01	/* temp.failure occurred */
1234 #define BIT_ASK_MTP	0x02	/* do we care about MapTempFail? */
1235 #define RESET_MAPTEMPFAIL	MapTempFail = 0
1236 #define INIT_MAPTEMPFAIL	MapTempFail = BIT_ASK_MTP
1237 #define SET_MAPTEMPFAIL		MapTempFail |= BIT_IS_MTP
1238 #define IS_MAPTEMPFAIL		bitset(BIT_IS_MTP, MapTempFail)
1239 #define ASK_MAPTEMPFAIL		bitset(BIT_ASK_MTP, MapTempFail)
1240 
1241 /*
1242 **  The class of a map -- essentially the functions to call
1243 */
1244 
1245 MAPCLASS
1246 {
1247 	char	*map_cname;		/* name of this map class */
1248 	char	*map_ext;		/* extension for database file */
1249 	short	map_cflags;		/* flag bits, see below */
1250 	bool	(*map_parse)__P((MAP *, char *));
1251 					/* argument parsing function */
1252 	char	*(*map_lookup)__P((MAP *, char *, char **, int *));
1253 					/* lookup function */
1254 	void	(*map_store)__P((MAP *, char *, char *));
1255 					/* store function */
1256 	bool	(*map_open)__P((MAP *, int));
1257 					/* open function */
1258 	void	(*map_close)__P((MAP *));
1259 					/* close function */
1260 };
1261 
1262 /* bit values for map_cflags */
1263 #define MCF_ALIASOK	0x0001		/* can be used for aliases */
1264 #define MCF_ALIASONLY	0x0002		/* usable only for aliases */
1265 #define MCF_REBUILDABLE	0x0004		/* can rebuild alias files */
1266 #define MCF_OPTFILE	0x0008		/* file name is optional */
1267 #define MCF_NOTPERSIST	0x0010		/* don't keep map open all the time */
1268 
1269 /* functions */
1270 extern void	closemaps __P((bool));
1271 extern bool	impl_map_open __P((MAP *, int));
1272 extern void	initmaps __P((void));
1273 extern MAP	*makemapentry __P((char *));
1274 extern void	maplocaluser __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
1275 extern char	*map_rewrite __P((MAP *, const char *, size_t, char **));
1276 #if NETINFO
1277 extern char	*ni_propval __P((char *, char *, char *, char *, int));
1278 #endif /* NETINFO */
1279 extern bool	openmap __P((MAP *));
1280 #if USERDB
1281 extern void	_udbx_close __P((void));
1282 extern int	udbexpand __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
1283 extern char	*udbsender __P((char *, SM_RPOOL_T *));
1284 #endif /* USERDB */
1285 
1286 /*
1287 **  LDAP related items
1288 */
1289 #if LDAPMAP
1290 /* struct defining LDAP Auth Methods */
1291 struct lamvalues
1292 {
1293 	char	*lam_name;	/* name of LDAP auth method */
1294 	int	lam_code;	/* numeric code */
1295 };
1296 
1297 /* struct defining LDAP Alias Dereferencing */
1298 struct ladvalues
1299 {
1300 	char	*lad_name;	/* name of LDAP alias dereferencing method */
1301 	int	lad_code;	/* numeric code */
1302 };
1303 
1304 /* struct defining LDAP Search Scope */
1305 struct lssvalues
1306 {
1307 	char	*lss_name;	/* name of LDAP search scope */
1308 	int	lss_code;	/* numeric code */
1309 };
1310 
1311 /* functions */
1312 extern bool	ldapmap_parseargs __P((MAP *, char *));
1313 extern void	ldapmap_set_defaults __P((char *));
1314 #endif /* LDAPMAP */
1315 
1316 /*
1317 **  PH related items
1318 */
1319 
1320 #if PH_MAP
1321 
1322 # include <phclient.h>
1323 
1324 struct ph_map_struct
1325 {
1326 	char	*ph_servers;	 /* list of ph servers */
1327 	char	*ph_field_list;	 /* list of fields to search for match */
1328 	PH	*ph;		 /* PH server handle */
1329 	int	ph_fastclose;	 /* send "quit" command on close */
1330 	time_t	ph_timeout;	 /* timeout interval */
1331 };
1332 typedef struct ph_map_struct	PH_MAP_STRUCT;
1333 
1334 #endif /* PH_MAP */
1335 
1336 /*
1337 **  Regular UNIX sockaddrs are too small to handle ISO addresses, so
1338 **  we are forced to declare a supertype here.
1339 */
1340 
1341 #if NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25
1342 union bigsockaddr
1343 {
1344 	struct sockaddr		sa;	/* general version */
1345 # if NETUNIX
1346 	struct sockaddr_un	sunix;	/* UNIX family */
1347 # endif /* NETUNIX */
1348 # if NETINET
1349 	struct sockaddr_in	sin;	/* INET family */
1350 # endif /* NETINET */
1351 # if NETINET6
1352 	struct sockaddr_in6	sin6;	/* INET/IPv6 */
1353 # endif /* NETINET6 */
1354 # if NETISO
1355 	struct sockaddr_iso	siso;	/* ISO family */
1356 # endif /* NETISO */
1357 # if NETNS
1358 	struct sockaddr_ns	sns;	/* XNS family */
1359 # endif /* NETNS */
1360 # if NETX25
1361 	struct sockaddr_x25	sx25;	/* X.25 family */
1362 # endif /* NETX25 */
1363 };
1364 
1365 # define SOCKADDR	union bigsockaddr
1366 
1367 /* functions */
1368 extern char	*anynet_ntoa __P((SOCKADDR *));
1369 # if NETINET6
1370 extern char	*anynet_ntop __P((struct in6_addr *, char *, size_t));
1371 extern int	anynet_pton __P((int, const char *, void *));
1372 # endif /* NETINET6 */
1373 extern char	*hostnamebyanyaddr __P((SOCKADDR *));
1374 extern char	*validate_connection __P((SOCKADDR *, char *, ENVELOPE *));
1375 # if SASL >= 20000
1376 extern bool	iptostring __P((SOCKADDR *, SOCKADDR_LEN_T, char *, unsigned));
1377 # endif /* SASL >= 20000 */
1378 
1379 #endif /* NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25 */
1380 
1381 /*
1382 **  Process List (proclist)
1383 */
1384 
1385 #define NO_PID		((pid_t) 0)
1386 #ifndef PROC_LIST_SEG
1387 # define PROC_LIST_SEG	32		/* number of pids to alloc at a time */
1388 #endif /* ! PROC_LIST_SEG */
1389 
1390 /* process types */
1391 #define PROC_NONE		0
1392 #define PROC_DAEMON		1
1393 #define PROC_DAEMON_CHILD	2
1394 #define PROC_QUEUE		3
1395 #define PROC_QUEUE_CHILD	3
1396 #define PROC_CONTROL		4
1397 #define PROC_CONTROL_CHILD	5
1398 
1399 /* functions */
1400 extern void	proc_list_add __P((pid_t, char *, int, int, int, SOCKADDR *));
1401 extern void	proc_list_clear __P((void));
1402 extern void	proc_list_display __P((SM_FILE_T *, char *));
1403 extern void	proc_list_drop __P((pid_t, int, int *));
1404 extern void	proc_list_probe __P((void));
1405 extern void	proc_list_set __P((pid_t, char *));
1406 extern void	proc_list_signal __P((int, int));
1407 
1408 /*
1409 **  Symbol table definitions
1410 */
1411 
1412 struct symtab
1413 {
1414 	char		*s_name;	/* name to be entered */
1415 	short		s_symtype;	/* general type (see below) */
1416 	struct symtab	*s_next;	/* pointer to next in chain */
1417 	union
1418 	{
1419 		BITMAP256	sv_class;	/* bit-map of word classes */
1420 		ADDRESS		*sv_addr;	/* pointer to address header */
1421 		MAILER		*sv_mailer;	/* pointer to mailer */
1422 		char		*sv_alias;	/* alias */
1423 		MAPCLASS	sv_mapclass;	/* mapping function class */
1424 		MAP		sv_map;		/* mapping function */
1425 		HOSTSIG_T	sv_hostsig;	/* host signature */
1426 		MCI		sv_mci;		/* mailer connection info */
1427 		NAMECANON	sv_namecanon;	/* canonical name cache */
1428 		int		sv_macro;	/* macro name => id mapping */
1429 		int		sv_ruleset;	/* ruleset index */
1430 		struct hdrinfo	sv_header;	/* header metainfo */
1431 		char		*sv_service[MAXMAPSTACK]; /* service switch */
1432 #if LDAPMAP
1433 		MAP		*sv_lmap;	/* Maps for LDAP connection */
1434 #endif /* LDAPMAP */
1435 #if SOCKETMAP
1436 		MAP		*sv_socketmap;	/* Maps for SOCKET connection */
1437 #endif /* SOCKETMAP */
1438 #if MILTER
1439 		struct milter	*sv_milter;	/* milter filter name */
1440 #endif /* MILTER */
1441 		QUEUEGRP	*sv_queue;	/* pointer to queue */
1442 	}	s_value;
1443 };
1444 
1445 typedef struct symtab	STAB;
1446 
1447 /* symbol types */
1448 #define ST_UNDEF	0	/* undefined type */
1449 #define ST_CLASS	1	/* class map */
1450 #define ST_ADDRESS	2	/* an address in parsed format */
1451 #define ST_MAILER	3	/* a mailer header */
1452 #define ST_ALIAS	4	/* an alias */
1453 #define ST_MAPCLASS	5	/* mapping function class */
1454 #define ST_MAP		6	/* mapping function */
1455 #define ST_HOSTSIG	7	/* host signature */
1456 #define ST_NAMECANON	8	/* cached canonical name */
1457 #define ST_MACRO	9	/* macro name to id mapping */
1458 #define ST_RULESET	10	/* ruleset index */
1459 #define ST_SERVICE	11	/* service switch entry */
1460 #define ST_HEADER	12	/* special header flags */
1461 #if LDAPMAP
1462 # define ST_LMAP	13	/* List head of maps for LDAP connection */
1463 #endif /* LDAPMAP */
1464 #if MILTER
1465 # define ST_MILTER	14	/* milter filter */
1466 #endif /* MILTER */
1467 #define ST_QUEUE	15	/* a queue entry */
1468 
1469 #if SOCKETMAP
1470 # define ST_SOCKETMAP   16      /* List head of maps for SOCKET connection */
1471 #endif /* SOCKETMAP */
1472 
1473 /* This entry must be last */
1474 #define ST_MCI		17	/* mailer connection info (offset) */
1475 
1476 #define s_class		s_value.sv_class
1477 #define s_address	s_value.sv_addr
1478 #define s_mailer	s_value.sv_mailer
1479 #define s_alias		s_value.sv_alias
1480 #define s_mci		s_value.sv_mci
1481 #define s_mapclass	s_value.sv_mapclass
1482 #define s_hostsig	s_value.sv_hostsig
1483 #define s_map		s_value.sv_map
1484 #define s_namecanon	s_value.sv_namecanon
1485 #define s_macro		s_value.sv_macro
1486 #define s_ruleset	s_value.sv_ruleset
1487 #define s_service	s_value.sv_service
1488 #define s_header	s_value.sv_header
1489 #if LDAPMAP
1490 # define s_lmap		s_value.sv_lmap
1491 #endif /* LDAPMAP */
1492 #if SOCKETMAP
1493 # define s_socketmap    s_value.sv_socketmap
1494 #endif /* SOCKETMAP */
1495 #if MILTER
1496 # define s_milter	s_value.sv_milter
1497 #endif /* MILTER */
1498 #define s_quegrp	s_value.sv_queue
1499 
1500 /* opcodes to stab */
1501 #define ST_FIND		0	/* find entry */
1502 #define ST_ENTER	1	/* enter if not there */
1503 
1504 /* functions */
1505 extern STAB	*stab __P((char *, int, int));
1506 extern void	stabapply __P((void (*)(STAB *, int), int));
1507 
1508 /*
1509 **  Operation, send, error, and MIME modes
1510 **
1511 **	The operation mode describes the basic operation of sendmail.
1512 **	This can be set from the command line, and is "send mail" by
1513 **	default.
1514 **
1515 **	The send mode tells how to send mail.  It can be set in the
1516 **	configuration file.  Its setting determines how quickly the
1517 **	mail will be delivered versus the load on your system.  If the
1518 **	-v (verbose) flag is given, it will be forced to SM_DELIVER
1519 **	mode.
1520 **
1521 **	The error mode tells how to return errors.
1522 */
1523 
1524 #define MD_DELIVER	'm'		/* be a mail sender */
1525 #define MD_SMTP		's'		/* run SMTP on standard input */
1526 #define MD_ARPAFTP	'a'		/* obsolete ARPANET mode (Grey Book) */
1527 #define MD_DAEMON	'd'		/* run as a daemon */
1528 #define MD_FGDAEMON	'D'		/* run daemon in foreground */
1529 #define MD_VERIFY	'v'		/* verify: don't collect or deliver */
1530 #define MD_TEST		't'		/* test mode: resolve addrs only */
1531 #define MD_INITALIAS	'i'		/* initialize alias database */
1532 #define MD_PRINT	'p'		/* print the queue */
1533 #define MD_PRINTNQE	'P'		/* print number of entries in queue */
1534 #define MD_FREEZE	'z'		/* freeze the configuration file */
1535 #define MD_HOSTSTAT	'h'		/* print persistent host stat info */
1536 #define MD_PURGESTAT	'H'		/* purge persistent host stat info */
1537 #define MD_QUEUERUN	'q'		/* queue run */
1538 
1539 /* Note: see also include/sendmail/pathnames.h: GET_CLIENT_CF */
1540 
1541 /* values for e_sendmode -- send modes */
1542 #define SM_DELIVER	'i'		/* interactive delivery */
1543 #define SM_FORK		'b'		/* deliver in background */
1544 #define SM_QUEUE	'q'		/* queue, don't deliver */
1545 #define SM_DEFER	'd'		/* defer map lookups as well as queue */
1546 #define SM_VERIFY	'v'		/* verify only (used internally) */
1547 
1548 #define WILL_BE_QUEUED(m)	((m) == SM_QUEUE || (m) == SM_DEFER)
1549 
1550 /* used only as a parameter to sendall */
1551 #define SM_DEFAULT	'\0'		/* unspecified, use SendMode */
1552 
1553 /* functions */
1554 extern void	set_delivery_mode __P((int, ENVELOPE *));
1555 
1556 /* values for e_errormode -- error handling modes */
1557 #define EM_PRINT	'p'		/* print errors */
1558 #define EM_MAIL		'm'		/* mail back errors */
1559 #define EM_WRITE	'w'		/* write back errors */
1560 #define EM_BERKNET	'e'		/* special berknet processing */
1561 #define EM_QUIET	'q'		/* don't print messages (stat only) */
1562 
1563 
1564 /* bit values for MimeMode */
1565 #define MM_CVTMIME	0x0001		/* convert 8 to 7 bit MIME */
1566 #define MM_PASS8BIT	0x0002		/* just send 8 bit data blind */
1567 #define MM_MIME8BIT	0x0004		/* convert 8-bit data to MIME */
1568 
1569 
1570 /* how to handle messages without any recipient addresses */
1571 #define NRA_NO_ACTION		0	/* just leave it as is */
1572 #define NRA_ADD_TO		1	/* add To: header */
1573 #define NRA_ADD_APPARENTLY_TO	2	/* add Apparently-To: header */
1574 #define NRA_ADD_BCC		3	/* add empty Bcc: header */
1575 #define NRA_ADD_TO_UNDISCLOSED	4	/* add To: undisclosed:; header */
1576 
1577 
1578 /* flags to putxline */
1579 #define PXLF_NOTHINGSPECIAL	0	/* no special mapping */
1580 #define PXLF_MAPFROM		0x0001	/* map From_ to >From_ */
1581 #define PXLF_STRIP8BIT		0x0002	/* strip 8th bit */
1582 #define PXLF_HEADER		0x0004	/* map newlines in headers */
1583 #define PXLF_NOADDEOL		0x0008	/* if EOL not present, don't add one */
1584 
1585 /*
1586 **  Privacy flags
1587 **	These are bit values for the PrivacyFlags word.
1588 */
1589 
1590 #define PRIV_PUBLIC		0		/* what have I got to hide? */
1591 #define PRIV_NEEDMAILHELO	0x00000001	/* insist on HELO for MAIL */
1592 #define PRIV_NEEDEXPNHELO	0x00000002	/* insist on HELO for EXPN */
1593 #define PRIV_NEEDVRFYHELO	0x00000004	/* insist on HELO for VRFY */
1594 #define PRIV_NOEXPN		0x00000008	/* disallow EXPN command */
1595 #define PRIV_NOVRFY		0x00000010	/* disallow VRFY command */
1596 #define PRIV_AUTHWARNINGS	0x00000020	/* flag possible auth probs */
1597 #define PRIV_NOVERB		0x00000040	/* disallow VERB command */
1598 #define PRIV_RESTRICTMAILQ	0x00010000	/* restrict mailq command */
1599 #define PRIV_RESTRICTQRUN	0x00020000	/* restrict queue run */
1600 #define PRIV_RESTRICTEXPAND	0x00040000	/* restrict alias/forward expansion */
1601 #define PRIV_NOETRN		0x00080000	/* disallow ETRN command */
1602 #define PRIV_NOBODYRETN		0x00100000	/* do not return bodies on bounces */
1603 #define PRIV_NORECEIPTS		0x00200000	/* disallow return receipts */
1604 #if _FFR_PRIV_NOACTUALRECIPIENT
1605 # define PRIV_NOACTUALRECIPIENT	0x00400000 /* no X-Actual-Recipient in DSNs */
1606 #endif /* _FFR_PRIV_NOACTUALRECIPIENT */
1607 
1608 /* don't give no info, anyway, anyhow */
1609 #define PRIV_GOAWAY		0x0000ffff
1610 
1611 /* struct defining such things */
1612 struct prival
1613 {
1614 	char		*pv_name;	/* name of privacy flag */
1615 	unsigned long	pv_flag;	/* numeric level */
1616 };
1617 
1618 EXTERN unsigned long	PrivacyFlags;	/* privacy flags */
1619 
1620 
1621 /*
1622 **  Flags passed to remotename, parseaddr, allocaddr, and buildaddr.
1623 */
1624 
1625 #define RF_SENDERADDR		0x001	/* this is a sender address */
1626 #define RF_HEADERADDR		0x002	/* this is a header address */
1627 #define RF_CANONICAL		0x004	/* strip comment information */
1628 #define RF_ADDDOMAIN		0x008	/* OK to do domain extension */
1629 #define RF_COPYPARSE		0x010	/* copy parsed user & host */
1630 #define RF_COPYPADDR		0x020	/* copy print address */
1631 #define RF_COPYALL		(RF_COPYPARSE|RF_COPYPADDR)
1632 #define RF_COPYNONE		0
1633 
1634 /*
1635 **  Flags passed to rscheck
1636 */
1637 
1638 #define RSF_RMCOMM		0x0001	/* strip comments */
1639 #define RSF_UNSTRUCTURED	0x0002	/* unstructured, ignore syntax errors */
1640 #define RSF_COUNT		0x0004	/* count rejections (statistics)? */
1641 
1642 /*
1643 **  Flags passed to mime8to7 and putheader.
1644 */
1645 
1646 #define M87F_OUTER		0	/* outer context */
1647 #define M87F_NO8BIT		0x0001	/* can't have 8-bit in this section */
1648 #define M87F_DIGEST		0x0002	/* processing multipart/digest */
1649 #define M87F_NO8TO7		0x0004	/* don't do 8->7 bit conversions */
1650 
1651 /* functions */
1652 extern void	mime7to8 __P((MCI *, HDR *, ENVELOPE *));
1653 extern int	mime8to7 __P((MCI *, HDR *, ENVELOPE *, char **, int));
1654 
1655 /*
1656 **  Flags passed to returntosender.
1657 */
1658 
1659 #define RTSF_NO_BODY		0	/* send headers only */
1660 #define RTSF_SEND_BODY		0x0001	/* include body of message in return */
1661 #define RTSF_PM_BOUNCE		0x0002	/* this is a postmaster bounce */
1662 
1663 /* functions */
1664 extern int	returntosender __P((char *, ADDRESS *, int, ENVELOPE *));
1665 
1666 /*
1667 **  Mail Filters (milter)
1668 */
1669 
1670 /*
1671 **  32-bit type used by milter
1672 **  (needed by libmilter even if MILTER isn't defined)
1673 */
1674 
1675 typedef SM_INT32	mi_int32;
1676 
1677 #if MILTER
1678 # define SMFTO_WRITE	0		/* Timeout for sending information */
1679 # define SMFTO_READ	1		/* Timeout waiting for a response */
1680 # define SMFTO_EOM	2		/* Timeout for ACK/NAK to EOM */
1681 # define SMFTO_CONNECT	3		/* Timeout for connect() */
1682 
1683 # define SMFTO_NUM_TO	4		/* Total number of timeouts */
1684 
1685 struct milter
1686 {
1687 	char		*mf_name;	/* filter name */
1688 	BITMAP256	mf_flags;	/* MTA flags */
1689 	mi_int32	mf_fvers;	/* filter version */
1690 	mi_int32	mf_fflags;	/* filter flags */
1691 	mi_int32	mf_pflags;	/* protocol flags */
1692 	char		*mf_conn;	/* connection info */
1693 	int		mf_sock;	/* connected socket */
1694 	char		mf_state;	/* state of filter */
1695 	time_t		mf_timeout[SMFTO_NUM_TO]; /* timeouts */
1696 };
1697 
1698 /* MTA flags */
1699 # define SMF_REJECT		'R'	/* Reject connection on filter fail */
1700 # define SMF_TEMPFAIL		'T'	/* tempfail connection on failure */
1701 # define SMF_TEMPDROP		'4'	/* 421 connection on failure */
1702 
1703 /* states */
1704 # define SMFS_CLOSED		'C'	/* closed for all further actions */
1705 # define SMFS_OPEN		'O'	/* connected to remote milter filter */
1706 # define SMFS_INMSG		'M'	/* currently servicing a message */
1707 # define SMFS_DONE		'D'	/* done with current message */
1708 # define SMFS_CLOSABLE		'Q'	/* done with current connection */
1709 # define SMFS_ERROR		'E'	/* error state */
1710 # define SMFS_READY		'R'	/* ready for action */
1711 
1712 EXTERN struct milter	*InputFilters[MAXFILTERS];
1713 EXTERN char		*InputFilterList;
1714 EXTERN int		MilterLogLevel;
1715 
1716 /* functions */
1717 extern void	setup_daemon_milters __P((void));
1718 #endif /* MILTER */
1719 
1720 /*
1721 **  Vendor codes
1722 **
1723 **	Vendors can customize sendmail to add special behaviour,
1724 **	generally for back compatibility.  Ideally, this should
1725 **	be set up in the .cf file using the "V" command.  However,
1726 **	it's quite reasonable for some vendors to want the default
1727 **	be their old version; this can be set using
1728 **		-DVENDOR_DEFAULT=VENDOR_xxx
1729 **	in the Makefile.
1730 **
1731 **	Vendors should apply to sendmail@sendmail.org for
1732 **	unique vendor codes.
1733 */
1734 
1735 #define VENDOR_BERKELEY	1	/* Berkeley-native configuration file */
1736 #define VENDOR_SUN	2	/* Sun-native configuration file */
1737 #define VENDOR_HP	3	/* Hewlett-Packard specific config syntax */
1738 #define VENDOR_IBM	4	/* IBM specific config syntax */
1739 #define VENDOR_SENDMAIL	5	/* Sendmail, Inc. specific config syntax */
1740 #define VENDOR_DEC	6	/* Compaq, DEC, Digital */
1741 
1742 /* prototypes for vendor-specific hook routines */
1743 extern void	vendor_daemon_setup __P((ENVELOPE *));
1744 extern void	vendor_set_uid __P((UID_T));
1745 
1746 
1747 /*
1748 **  Terminal escape codes.
1749 **
1750 **	To make debugging output clearer.
1751 */
1752 
1753 struct termescape
1754 {
1755 	char	*te_rv_on;	/* turn reverse-video on */
1756 	char	*te_rv_off;	/* turn reverse-video off */
1757 };
1758 
1759 /*
1760 **  Additional definitions
1761 */
1762 
1763 /*
1764 **  d_flags, see daemon.c
1765 **  general rule: lower case: required, upper case: No
1766 */
1767 
1768 #define D_AUTHREQ	'a'	/* authentication required */
1769 #define D_BINDIF	'b'	/* use if_addr for outgoing connection */
1770 #define D_CANONREQ	'c'	/* canonification required (cf) */
1771 #define D_IFNHELO	'h'	/* use if name for HELO */
1772 #define D_FQMAIL	'f'	/* fq sender address required (cf) */
1773 #define D_FQRCPT	'r'	/* fq recipient address required (cf) */
1774 #define D_SMTPS		's'	/* SMTP over SSL (smtps) */
1775 #define D_UNQUALOK	'u'	/* unqualified address is ok (cf) */
1776 #define D_NOAUTH	'A'	/* no AUTH */
1777 #define D_NOCANON	'C'	/* no canonification (cf) */
1778 #define D_NOETRN	'E'	/* no ETRN (MSA) */
1779 #define D_NOTLS		'S'	/* don't use STARTTLS */
1780 #define D_ETRNONLY	((char)0x01)	/* allow only ETRN (disk low) */
1781 #define D_OPTIONAL	'O'	/* optional socket */
1782 #define D_DISABLE	((char)0x02)	/* optional socket disabled */
1783 #define D_ISSET		((char)0x03)	/* this client struct is set */
1784 
1785 #if STARTTLS
1786 /*
1787 **  TLS
1788 */
1789 
1790 /* what to do in the TLS initialization */
1791 #define TLS_I_NONE	0x00000000	/* no requirements... */
1792 #define TLS_I_CERT_EX	0x00000001	/* cert must exist */
1793 #define TLS_I_CERT_UNR	0x00000002	/* cert must be g/o unreadable */
1794 #define TLS_I_KEY_EX	0x00000004	/* key must exist */
1795 #define TLS_I_KEY_UNR	0x00000008	/* key must be g/o unreadable */
1796 #define TLS_I_CERTP_EX	0x00000010	/* CA cert path must exist */
1797 #define TLS_I_CERTP_UNR	0x00000020	/* CA cert path must be g/o unreadable */
1798 #define TLS_I_CERTF_EX	0x00000040	/* CA cert file must exist */
1799 #define TLS_I_CERTF_UNR	0x00000080	/* CA cert file must be g/o unreadable */
1800 #define TLS_I_RSA_TMP	0x00000100	/* RSA TMP must be generated */
1801 #define TLS_I_USE_KEY	0x00000200	/* private key must usable */
1802 #define TLS_I_USE_CERT	0x00000400	/* certificate must be usable */
1803 #define TLS_I_VRFY_PATH	0x00000800	/* load verify path must succeed */
1804 #define TLS_I_VRFY_LOC	0x00001000	/* load verify default must succeed */
1805 #define TLS_I_CACHE	0x00002000	/* require cache */
1806 #define TLS_I_TRY_DH	0x00004000	/* try DH certificate */
1807 #define TLS_I_REQ_DH	0x00008000	/* require DH certificate */
1808 #define TLS_I_DHPAR_EX	0x00010000	/* require DH parameters */
1809 #define TLS_I_DHPAR_UNR	0x00020000	/* DH param. must be g/o unreadable */
1810 #define TLS_I_DH512	0x00040000	/* generate 512bit DH param */
1811 #define TLS_I_DH1024	0x00080000	/* generate 1024bit DH param */
1812 #define TLS_I_DH2048	0x00100000	/* generate 2048bit DH param */
1813 #define TLS_I_NO_VRFY	0x00200000	/* do not require authentication */
1814 #define TLS_I_KEY_OUNR	0x00400000	/* Key must be other unreadable */
1815 #define TLS_I_CRLF_EX	0x00800000	/* CRL file must exist */
1816 #define TLS_I_CRLF_UNR	0x01000000	/* CRL file must be g/o unreadable */
1817 
1818 /* require server cert */
1819 #define TLS_I_SRV_CERT	 (TLS_I_CERT_EX | TLS_I_KEY_EX | \
1820 			  TLS_I_KEY_UNR | TLS_I_KEY_OUNR | \
1821 			  TLS_I_CERTP_EX | TLS_I_CERTF_EX | \
1822 			  TLS_I_USE_KEY | TLS_I_USE_CERT)
1823 
1824 /* server requirements */
1825 #define TLS_I_SRV	(TLS_I_SRV_CERT | TLS_I_RSA_TMP | TLS_I_VRFY_PATH | \
1826 			 TLS_I_VRFY_LOC | TLS_I_TRY_DH | TLS_I_DH512)
1827 
1828 /* client requirements */
1829 #define TLS_I_CLT	(TLS_I_KEY_UNR | TLS_I_KEY_OUNR)
1830 
1831 #define TLS_AUTH_OK	0
1832 #define TLS_AUTH_NO	1
1833 #define TLS_AUTH_FAIL	(-1)
1834 
1835 /* functions */
1836 extern bool	init_tls_library __P((void));
1837 extern bool	inittls __P((SSL_CTX **, unsigned long, bool, char *, char *, char *, char *, char *));
1838 extern bool	initclttls __P((bool));
1839 extern void	setclttls __P((bool));
1840 extern bool	initsrvtls __P((bool));
1841 extern int	tls_get_info __P((SSL *, bool, char *, MACROS_T *, bool));
1842 extern int	endtls __P((SSL *, char *));
1843 extern void	tlslogerr __P((char *));
1844 
1845 
1846 EXTERN char	*CACertPath;	/* path to CA certificates (dir. with hashes) */
1847 EXTERN char	*CACertFile;	/* file with CA certificate */
1848 EXTERN char	*CltCertFile;	/* file with client certificate */
1849 EXTERN char	*CltKeyFile;	/* file with client private key */
1850 # if _FFR_TLS_1
1851 EXTERN char	*CipherList;	/* list of ciphers */
1852 EXTERN char	*DHParams5;	/* file with DH parameters (512) */
1853 # endif /* _FFR_TLS_1 */
1854 EXTERN char	*DHParams;	/* file with DH parameters */
1855 EXTERN char	*RandFile;	/* source of random data */
1856 EXTERN char	*SrvCertFile;	/* file with server certificate */
1857 EXTERN char	*SrvKeyFile;	/* file with server private key */
1858 EXTERN char	*CRLFile;	/* file CRLs */
1859 #if _FFR_CRLPATH
1860 EXTERN char	*CRLPath;	/* path to CRLs (dir. with hashes) */
1861 #endif /* _FFR_CRLPATH */
1862 EXTERN unsigned long	TLS_Srv_Opts;	/* TLS server options */
1863 #endif /* STARTTLS */
1864 
1865 /*
1866 **  Queue related items
1867 */
1868 
1869 /* queue file names */
1870 #define ANYQFL_LETTER '?'
1871 #define QUARQF_LETTER 'h'
1872 #define DATAFL_LETTER 'd'
1873 #define XSCRPT_LETTER 'x'
1874 #define NORMQF_LETTER 'q'
1875 #define NEWQFL_LETTER 't'
1876 
1877 # define TEMPQF_LETTER 'T'
1878 # define LOSEQF_LETTER 'Q'
1879 
1880 /* queue sort order */
1881 #define QSO_BYPRIORITY	0		/* sort by message priority */
1882 #define QSO_BYHOST	1		/* sort by first host name */
1883 #define QSO_BYTIME	2		/* sort by submission time */
1884 #define QSO_BYFILENAME	3		/* sort by file name only */
1885 #define QSO_RANDOM	4		/* sort in random order */
1886 #define QSO_BYMODTIME	5		/* sort by modification time */
1887 #define QSO_NONE	6		/* do not sort */
1888 #if _FFR_RHS
1889 # define QSO_BYSHUFFLE	7		/* sort by shuffled host name */
1890 #endif /* _FFR_RHS */
1891 
1892 #define NOQGRP	(-1)		/* no queue group (yet) */
1893 #define ENVQGRP	(-2)		/* use queue group of envelope */
1894 #define NOAQGRP	(-3)		/* no queue group in addr (yet) */
1895 #define ISVALIDQGRP(x)	((x) >= 0)	/* valid queue group? */
1896 #define NOQDIR	(-1)		/* no queue directory (yet) */
1897 #define ENVQDIR	(-2)		/* use queue directory of envelope */
1898 #define NOAQDIR	(-3)		/* no queue directory in addr (yet) */
1899 #define ISVALIDQDIR(x)	((x) >= 0)	/* valid queue directory? */
1900 #define RS_QUEUEGROUP	"queuegroup"	/* ruleset for queue group selection */
1901 
1902 #define NOW	((time_t) (-1))		/* queue return: now */
1903 
1904 /* SuperSafe values */
1905 #define SAFE_NO			0	/* no fsync(): don't use... */
1906 #define SAFE_INTERACTIVE	1	/* limit fsync() in -odi */
1907 #define SAFE_REALLY		2	/* always fsync() */
1908 #define SAFE_REALLY_POSTMILTER	3	/* fsync() if milter says OK */
1909 
1910 /* QueueMode bits */
1911 #define QM_NORMAL		' '
1912 #define QM_QUARANTINE		'Q'
1913 #define QM_LOST			'L'
1914 
1915 /* Queue Run Limitations */
1916 struct queue_char
1917 {
1918 	char			*queue_match;	/* string to match */
1919 	bool			queue_negate;	/* or not match, if set */
1920 	struct queue_char	*queue_next;
1921 };
1922 
1923 /* run_work_group() flags */
1924 #define RWG_NONE		0x0000
1925 #define RWG_FORK		0x0001
1926 #define RWG_VERBOSE		0x0002
1927 #define RWG_PERSISTENT		0x0004
1928 #define RWG_FORCE		0x0008
1929 #define RWG_RUNALL		0x0010
1930 
1931 typedef struct queue_char	QUEUE_CHAR;
1932 
1933 EXTERN int	volatile CurRunners;	/* current number of runner children */
1934 EXTERN int	MaxQueueRun;	/* maximum number of jobs in one queue run */
1935 EXTERN int	MaxQueueChildren;	/* max # of forked queue children */
1936 EXTERN int	MaxRunnersPerQueue;	/* max # proc's active in queue group */
1937 EXTERN int	NiceQueueRun;	/* nice queue runs to this value */
1938 EXTERN int	NumQueue;	/* number of queue groups */
1939 EXTERN int	QueueFileMode;	/* mode on files in mail queue */
1940 EXTERN int	QueueMode;	/* which queue items to act upon */
1941 EXTERN int	QueueSortOrder;	/* queue sorting order algorithm */
1942 EXTERN time_t	MinQueueAge;	/* min delivery interval */
1943 EXTERN time_t	QueueIntvl;	/* intervals between running the queue */
1944 EXTERN char	*QueueDir;	/* location of queue directory */
1945 EXTERN QUEUE_CHAR	*QueueLimitId;		/* limit queue run to id */
1946 EXTERN QUEUE_CHAR	*QueueLimitQuarantine;	/* limit queue run to quarantine reason */
1947 EXTERN QUEUE_CHAR	*QueueLimitRecipient;	/* limit queue run to rcpt */
1948 EXTERN QUEUE_CHAR	*QueueLimitSender;	/* limit queue run to sender */
1949 EXTERN QUEUEGRP	*Queue[MAXQUEUEGROUPS + 1];	/* queue groups */
1950 
1951 /* functions */
1952 extern void	assign_queueid __P((ENVELOPE *));
1953 extern ADDRESS	*copyqueue __P((ADDRESS *, SM_RPOOL_T *));
1954 extern void	cleanup_queues __P((void));
1955 extern bool	doqueuerun __P((void));
1956 extern void	initsys __P((ENVELOPE *));
1957 extern void	loseqfile __P((ENVELOPE *, char *));
1958 extern int	name2qid __P((char *));
1959 extern char	*qid_printname __P((ENVELOPE *));
1960 extern char	*qid_printqueue __P((int, int));
1961 extern void	quarantine_queue __P((char *, int));
1962 extern char	*queuename __P((ENVELOPE *, int));
1963 extern void	queueup __P((ENVELOPE *, bool, bool));
1964 extern bool	runqueue __P((bool, bool, bool, bool));
1965 extern bool	run_work_group __P((int, int));
1966 extern void	set_def_queueval __P((QUEUEGRP *, bool));
1967 extern void	setup_queues __P((bool));
1968 extern bool	setnewqueue __P((ENVELOPE *));
1969 extern bool	shouldqueue __P((long, time_t));
1970 extern void	sync_queue_time __P((void));
1971 extern void	init_qid_alg __P((void));
1972 extern int	print_single_queue __P((int, int));
1973 #if REQUIRES_DIR_FSYNC
1974 # define SYNC_DIR(path, panic) sync_dir(path, panic)
1975 extern void	sync_dir __P((char *, bool));
1976 #else /* REQUIRES_DIR_FSYNC */
1977 # define SYNC_DIR(path, panic) ((void) 0)
1978 #endif /* REQUIRES_DIR_FSYNC */
1979 
1980 /*
1981 **  Timeouts
1982 **
1983 **	Indicated values are the MINIMUM per RFC 1123 section 5.3.2.
1984 */
1985 
1986 EXTERN struct
1987 {
1988 			/* RFC 1123-specified timeouts [minimum value] */
1989 	time_t	to_initial;	/* initial greeting timeout [5m] */
1990 	time_t	to_mail;	/* MAIL command [5m] */
1991 	time_t	to_rcpt;	/* RCPT command [5m] */
1992 	time_t	to_datainit;	/* DATA initiation [2m] */
1993 	time_t	to_datablock;	/* DATA block [3m] */
1994 	time_t	to_datafinal;	/* DATA completion [10m] */
1995 	time_t	to_nextcommand;	/* next command [5m] */
1996 			/* following timeouts are not mentioned in RFC 1123 */
1997 	time_t	to_iconnect;	/* initial connection timeout (first try) */
1998 	time_t	to_connect;	/* initial connection timeout (later tries) */
1999 	time_t	to_aconnect;	/* all connections timeout (MX and A records) */
2000 	time_t	to_rset;	/* RSET command */
2001 	time_t	to_helo;	/* HELO command */
2002 	time_t	to_quit;	/* QUIT command */
2003 	time_t	to_miscshort;	/* misc short commands (NOOP, VERB, etc) */
2004 	time_t	to_ident;	/* IDENT protocol requests */
2005 	time_t	to_fileopen;	/* opening :include: and .forward files */
2006 	time_t	to_control;	/* process a control socket command */
2007 	time_t	to_lhlo;	/* LMTP: LHLO command */
2008 #if SASL
2009 	time_t	to_auth;	/* AUTH dialogue [10m] */
2010 #endif /* SASL */
2011 #if STARTTLS
2012 	time_t	to_starttls;	/* STARTTLS dialogue [10m] */
2013 #endif /* STARTTLS */
2014 			/* following are per message */
2015 	time_t	to_q_return[MAXTOCLASS];	/* queue return timeouts */
2016 	time_t	to_q_warning[MAXTOCLASS];	/* queue warning timeouts */
2017 	time_t	res_retrans[MAXRESTOTYPES];	/* resolver retransmit */
2018 	int	res_retry[MAXRESTOTYPES];	/* resolver retry */
2019 } TimeOuts;
2020 
2021 /* timeout classes for return and warning timeouts */
2022 #define TOC_NORMAL	0	/* normal delivery */
2023 #define TOC_URGENT	1	/* urgent delivery */
2024 #define TOC_NONURGENT	2	/* non-urgent delivery */
2025 #define TOC_DSN		3	/* DSN delivery */
2026 
2027 /* resolver timeout specifiers */
2028 #define RES_TO_FIRST	0	/* first attempt */
2029 #define RES_TO_NORMAL	1	/* subsequent attempts */
2030 #define RES_TO_DEFAULT	2	/* default value */
2031 
2032 /* functions */
2033 extern void	inittimeouts __P((char *, bool));
2034 
2035 /*
2036 **  Interface probing
2037 */
2038 
2039 #define DPI_PROBENONE		0	/* Don't probe any interfaces */
2040 #define DPI_PROBEALL		1	/* Probe all interfaces */
2041 #define DPI_SKIPLOOPBACK	2	/* Don't probe loopback interfaces */
2042 
2043 /*
2044 **  Trace information
2045 */
2046 
2047 /* macros for debugging flags */
2048 #define tTd(flag, level)	(tTdvect[flag] >= (unsigned char)level)
2049 #define tTdlevel(flag)		(tTdvect[flag])
2050 
2051 /* variables */
2052 extern unsigned char	tTdvect[100];	/* trace vector */
2053 
2054 /*
2055 **  Miscellaneous information.
2056 */
2057 
2058 /*
2059 **  The "no queue id" queue id for sm_syslog
2060 */
2061 
2062 #define NOQID		"*~*"
2063 
2064 /* use id or NOQID (to avoid NOQUEUE in logfile) */
2065 #define E_ID(id)	((id) == NULL ? NOQID : (id))
2066 
2067 #define CURHOSTNAME	(CurHostName == NULL ? "local" : CurHostName)
2068 
2069 /*
2070 **  Some in-line functions
2071 */
2072 
2073 /* set exit status */
2074 #define setstat(s)	{ \
2075 				if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \
2076 					ExitStat = s; \
2077 			}
2078 
2079 
2080 #define STRUCTCOPY(s, d)	d = s
2081 
2082 /* free a pointer if it isn't NULL and set it to NULL */
2083 #define SM_FREE_CLR(p)	\
2084 			if ((p) != NULL) \
2085 			{ \
2086 				sm_free(p); \
2087 				(p) = NULL; \
2088 			} \
2089 			else
2090 
2091 /*
2092 **  Update a permanent string variable with a new value.
2093 **  The old value is freed, the new value is strdup'ed.
2094 **
2095 **  We use sm_pstrdup_x to duplicate the string because it raises
2096 **  an exception on error, and because it allocates "permanent storage"
2097 **  which is not expected to be freed before process exit.
2098 **  The latter is important for memory leak analysis.
2099 **
2100 **  If an exception occurs while strdup'ing the new value,
2101 **  then the variable remains set to the old value.
2102 **  That's why the strdup must occur before we free the old value.
2103 **
2104 **  The macro uses a do loop so that this idiom will work:
2105 **	if (...)
2106 **		PSTRSET(var, val1);
2107 **	else
2108 **		PSTRSET(var, val2);
2109 */
2110 #define PSTRSET(var, val) \
2111 	do \
2112 	{ \
2113 		char *_newval = sm_pstrdup_x(val); \
2114 		if (var != NULL) \
2115 			sm_free(var); \
2116 		var = _newval; \
2117 	} while (0)
2118 
2119 #define _CHECK_RESTART \
2120 	do \
2121 	{ \
2122 		if (ShutdownRequest != NULL) \
2123 			shutdown_daemon(); \
2124 		else if (RestartRequest != NULL) \
2125 			restart_daemon(); \
2126 		else if (RestartWorkGroup) \
2127 			restart_marked_work_groups(); \
2128 	} while (0)
2129 
2130 # define CHECK_RESTART _CHECK_RESTART
2131 
2132 /* reply types (text in SmtpMsgBuffer) */
2133 #define XS_DEFAULT	0
2134 #define XS_STARTTLS	1
2135 #define XS_AUTH		2
2136 
2137 /*
2138 **  Global variables.
2139 */
2140 
2141 EXTERN bool	AllowBogusHELO;	/* allow syntax errors on HELO command */
2142 EXTERN bool	CheckAliases;	/* parse addresses during newaliases */
2143 EXTERN bool	ColonOkInAddr;	/* single colon legal in address */
2144 #if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_)
2145 EXTERN bool	ConfigFileRead;	/* configuration file has been read */
2146 #endif /* !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) */
2147 EXTERN bool	volatile DataProgress;	/* have we sent anything since last check */
2148 EXTERN bool	DisConnected;	/* running with OutChannel redirect to transcript file */
2149 EXTERN bool	DontExpandCnames;	/* do not $[...$] expand CNAMEs */
2150 EXTERN bool	DontInitGroups;	/* avoid initgroups() because of NIS cost */
2151 EXTERN bool	DontLockReadFiles;	/* don't read lock support files */
2152 EXTERN bool	DontPruneRoutes;	/* don't prune source routes */
2153 EXTERN bool	ForkQueueRuns;	/* fork for each job when running the queue */
2154 EXTERN bool	FromFlag;	/* if set, "From" person is explicit */
2155 EXTERN bool	GrabTo;		/* if set, get recipients from msg */
2156 EXTERN bool	HasEightBits;	/* has at least one eight bit input byte */
2157 EXTERN bool	HasWildcardMX;	/* don't use MX records when canonifying */
2158 EXTERN bool	HoldErrs;	/* only output errors to transcript */
2159 EXTERN bool	IgnoreHostStatus;	/* ignore long term host status files */
2160 EXTERN bool	IgnrDot;	/* don't let dot end messages */
2161 EXTERN bool	LogUsrErrs;	/* syslog user errors (e.g., SMTP RCPT cmd) */
2162 EXTERN bool	MatchGecos;	/* look for user names in gecos field */
2163 EXTERN bool	MeToo;		/* send to the sender also */
2164 EXTERN bool	NoAlias;	/* suppress aliasing */
2165 EXTERN bool	NoConnect;	/* don't connect to non-local mailers */
2166 EXTERN bool	OnlyOneError;	/*  .... or only want to give one SMTP reply */
2167 EXTERN bool	QuickAbort;	/*  .... but only if we want a quick abort */
2168 #if REQUIRES_DIR_FSYNC
2169 EXTERN bool	RequiresDirfsync;	/* requires fsync() for directory */
2170 #endif /* REQUIRES_DIR_FSYNC */
2171 EXTERN bool	volatile RestartWorkGroup; /* daemon needs to restart some work groups */
2172 EXTERN bool	RrtImpliesDsn;	/* turn Return-Receipt-To: into DSN */
2173 EXTERN bool	SaveFrom;	/* save leading "From" lines */
2174 EXTERN bool	SendMIMEErrors;	/* send error messages in MIME format */
2175 EXTERN bool	SevenBitInput;	/* force 7-bit data on input */
2176 EXTERN bool	SingleLineFromHeader;	/* force From: header to be one line */
2177 EXTERN bool	SingleThreadDelivery;	/* single thread hosts on delivery */
2178 #if _FFR_SOFT_BOUNCE
2179 EXTERN bool	SoftBounce;	/* replace 5xy by 4xy (for testing) */
2180 #endif /* _FFR_SOFT_BOUNCE */
2181 EXTERN bool	volatile StopRequest;	/* stop sending output */
2182 EXTERN bool	SuprErrs;	/* set if we are suppressing errors */
2183 EXTERN bool	TryNullMXList;	/* if we are the best MX, try host directly */
2184 EXTERN bool	UseMSP;		/* mail submission: group writable queue ok? */
2185 EXTERN bool	WorkAroundBrokenAAAA;	/* some nameservers return SERVFAIL on AAAA queries */
2186 EXTERN bool	UseErrorsTo;	/* use Errors-To: header (back compat) */
2187 EXTERN bool	UseNameServer;	/* using DNS -- interpret h_errno & MX RRs */
2188 EXTERN char	InetMode;		/* default network for daemon mode */
2189 EXTERN char	OpMode;		/* operation mode, see below */
2190 EXTERN char	SpaceSub;	/* substitution for <lwsp> */
2191 EXTERN int	BadRcptThrottle; /* Throttle rejected RCPTs per SMTP message */
2192 EXTERN int	CheckpointInterval;	/* queue file checkpoint interval */
2193 EXTERN int	ConfigLevel;	/* config file level */
2194 EXTERN int	ConnRateThrottle;	/* throttle for SMTP connection rate */
2195 EXTERN int	volatile CurChildren;	/* current number of daemonic children */
2196 EXTERN int	CurrentLA;	/* current load average */
2197 EXTERN int	DefaultNotify;	/* default DSN notification flags */
2198 EXTERN int	DelayLA;	/* load average to delay connections */
2199 EXTERN int	DontProbeInterfaces;	/* don't probe interfaces for names */
2200 EXTERN int	Errors;		/* set if errors (local to single pass) */
2201 EXTERN int	ExitStat;	/* exit status code */
2202 EXTERN int	FastSplit;	/* fast initial splitting of envelopes */
2203 EXTERN int	FileMode;	/* mode on files */
2204 EXTERN int	LineNumber;	/* line number in current input */
2205 EXTERN int	LogLevel;	/* level of logging to perform */
2206 EXTERN int	MaxAliasRecursion;	/* maximum depth of alias recursion */
2207 EXTERN int	MaxChildren;	/* maximum number of daemonic children */
2208 EXTERN int	MaxForwardEntries;	/* maximum number of forward entries */
2209 EXTERN int	MaxHeadersLength;	/* max length of headers */
2210 EXTERN int	MaxHopCount;	/* max # of hops until bounce */
2211 EXTERN int	MaxMacroRecursion;	/* maximum depth of macro recursion */
2212 EXTERN int	MaxMimeFieldLength;	/* maximum MIME field length */
2213 EXTERN int	MaxMimeHeaderLength;	/* maximum MIME header length */
2214 
2215 EXTERN int	MaxRcptPerMsg;	/* max recipients per SMTP message */
2216 EXTERN int	MaxRuleRecursion;	/* maximum depth of ruleset recursion */
2217 EXTERN int	MimeMode;	/* MIME processing mode */
2218 EXTERN int	NoRecipientAction;
2219 
2220 #if SM_CONF_SHM
2221 EXTERN int	Numfilesys;	/* number of queue file systems */
2222 EXTERN int	*PNumFileSys;
2223 # define NumFileSys	(*PNumFileSys)
2224 # else /* SM_CONF_SHM */
2225 EXTERN int	NumFileSys;	/* number of queue file systems */
2226 # endif /* SM_CONF_SHM */
2227 
2228 EXTERN int	QueueLA;	/* load average starting forced queueing */
2229 EXTERN int	RefuseLA;	/* load average refusing connections */
2230 EXTERN time_t	RejectLogInterval;	/* time btwn log msgs while refusing */
2231 EXTERN int	SuperSafe;	/* be extra careful, even if expensive */
2232 EXTERN int	VendorCode;	/* vendor-specific operation enhancements */
2233 EXTERN int	Verbose;	/* set if blow-by-blow desired */
2234 EXTERN gid_t	DefGid;		/* default gid to run as */
2235 EXTERN gid_t	RealGid;	/* real gid of caller */
2236 EXTERN gid_t	RunAsGid;	/* GID to become for bulk of run */
2237 EXTERN gid_t	EffGid;		/* effective gid */
2238 #if SM_CONF_SHM
2239 EXTERN key_t	ShmKey;		/* shared memory key */
2240 # if _FFR_SELECT_SHM
2241 EXTERN char	*ShmKeyFile;	/* shared memory key file */
2242 # endif /* _FFR_SELECT_SHM */
2243 #endif /* SM_CONF_SHM */
2244 EXTERN pid_t	CurrentPid;	/* current process id */
2245 EXTERN pid_t	DaemonPid;	/* process id of daemon */
2246 EXTERN pid_t	PidFilePid;	/* daemon/queue runner who wrote pid file */
2247 EXTERN uid_t	DefUid;		/* default uid to run as */
2248 EXTERN uid_t	RealUid;	/* real uid of caller */
2249 EXTERN uid_t	RunAsUid;	/* UID to become for bulk of run */
2250 EXTERN uid_t	TrustedUid;	/* uid of trusted user for files and startup */
2251 EXTERN size_t	DataFileBufferSize;	/* size of buf for in-core data file */
2252 EXTERN time_t	DeliverByMin;	/* deliver by minimum time */
2253 EXTERN time_t	DialDelay;	/* delay between dial-on-demand tries */
2254 EXTERN time_t	SafeAlias;	/* interval to wait until @:@ in alias file */
2255 EXTERN time_t	ServiceCacheMaxAge;	/* refresh interval for cache */
2256 EXTERN size_t	XscriptFileBufferSize;	/* size of buf for in-core transcript file */
2257 EXTERN MODE_T	OldUmask;	/* umask when sendmail starts up */
2258 EXTERN long	MaxMessageSize;	/* advertised max size we will accept */
2259 EXTERN long	MinBlocksFree;	/* min # of blocks free on queue fs */
2260 EXTERN long	QueueFactor;	/* slope of queue function */
2261 EXTERN long	WkClassFact;	/* multiplier for message class -> priority */
2262 EXTERN long	WkRecipFact;	/* multiplier for # of recipients -> priority */
2263 EXTERN long	WkTimeFact;	/* priority offset each time this job is run */
2264 EXTERN char	*ControlSocketName; /* control socket filename [control.c] */
2265 EXTERN char	*CurHostName;	/* current host we are dealing with */
2266 EXTERN char	*DeadLetterDrop;	/* path to dead letter office */
2267 EXTERN char	*DefUser;	/* default user to run as (from DefUid) */
2268 EXTERN char	*DefaultCharSet;	/* default character set for MIME */
2269 EXTERN char	*DoubleBounceAddr;	/* where to send double bounces */
2270 EXTERN char	*ErrMsgFile;	/* file to prepend to all error messages */
2271 EXTERN char	*FallbackMX;	/* fall back MX host */
2272 EXTERN char	*FallbackSmartHost;	/* fall back smart host */
2273 EXTERN char	*FileName;	/* name to print on error messages */
2274 EXTERN char	*ForwardPath;	/* path to search for .forward files */
2275 #if _FFR_HELONAME
2276 EXTERN char	*HeloName;	/* hostname to announce in HELO */
2277 #endif /* _FFR_HELONAME */
2278 EXTERN char	*HelpFile;	/* location of SMTP help file */
2279 EXTERN char	*HostStatDir;	/* location of host status information */
2280 EXTERN char	*HostsFile;	/* path to /etc/hosts file */
2281 extern char	*Mbdb;		/* mailbox database type */
2282 EXTERN char	*MustQuoteChars;	/* quote these characters in phrases */
2283 EXTERN char	*MyHostName;	/* name of this host for SMTP messages */
2284 EXTERN char	*OperatorChars;	/* operators (old $o macro) */
2285 EXTERN char	*PidFile;	/* location of proc id file [conf.c] */
2286 EXTERN char	*PostMasterCopy;	/* address to get errs cc's */
2287 EXTERN char	*ProcTitlePrefix; /* process title prefix */
2288 EXTERN char	*RealHostName;	/* name of host we are talking to */
2289 EXTERN char	*RealUserName;	/* real user name of caller */
2290 EXTERN char	*volatile RestartRequest;/* a sendmail restart has been requested */
2291 EXTERN char	*RunAsUserName;	/* user to become for bulk of run */
2292 EXTERN char	*SafeFileEnv;	/* chroot location for file delivery */
2293 EXTERN char	*ServiceSwitchFile;	/* backup service switch */
2294 EXTERN char	*volatile ShutdownRequest;/* a sendmail shutdown has been requested */
2295 EXTERN char	*SmtpGreeting;	/* SMTP greeting message (old $e macro) */
2296 EXTERN char	*SmtpPhase;	/* current phase in SMTP processing */
2297 EXTERN char	SmtpError[MAXLINE];	/* save failure error messages */
2298 EXTERN char	*StatFile;	/* location of statistics summary */
2299 EXTERN char	*TimeZoneSpec;	/* override time zone specification */
2300 EXTERN char	*UdbSpec;	/* user database source spec */
2301 EXTERN char	*UnixFromLine;	/* UNIX From_ line (old $l macro) */
2302 EXTERN char	**ExternalEnviron;	/* saved user (input) environment */
2303 EXTERN char	**SaveArgv;	/* argument vector for re-execing */
2304 EXTERN BITMAP256	DontBlameSendmail;	/* DontBlameSendmail bits */
2305 EXTERN SM_FILE_T	*InChannel;	/* input connection */
2306 EXTERN SM_FILE_T	*OutChannel;	/* output connection */
2307 EXTERN SM_FILE_T	*TrafficLogFile; /* file in which to log all traffic */
2308 #if HESIOD
2309 EXTERN void	*HesiodContext;
2310 #endif /* HESIOD */
2311 EXTERN ENVELOPE	*CurEnv;	/* envelope currently being processed */
2312 EXTERN char	*RuleSetNames[MAXRWSETS];	/* ruleset number to name */
2313 EXTERN char	*UserEnviron[MAXUSERENVIRON + 1];
2314 EXTERN struct rewrite	*RewriteRules[MAXRWSETS];
2315 EXTERN struct termescape	TermEscape;	/* terminal escape codes */
2316 EXTERN SOCKADDR	ConnectOnlyTo;	/* override connection address (for testing) */
2317 EXTERN SOCKADDR RealHostAddr;	/* address of host we are talking to */
2318 extern const SM_EXC_TYPE_T EtypeQuickAbort; /* type of a QuickAbort exception */
2319 
2320 
2321 EXTERN int ConnectionRateWindowSize;
2322 
2323 /*
2324 **  Declarations of useful functions
2325 */
2326 
2327 /* Transcript file */
2328 extern void	closexscript __P((ENVELOPE *));
2329 extern void	openxscript __P((ENVELOPE *));
2330 
2331 /* error related */
2332 extern void	buffer_errors __P((void));
2333 extern void	flush_errors __P((bool));
2334 extern void PRINTFLIKE(1, 2)	message __P((const char *, ...));
2335 extern void PRINTFLIKE(1, 2)	nmessage __P((const char *, ...));
2336 extern void PRINTFLIKE(1, 2)	syserr __P((const char *, ...));
2337 extern void PRINTFLIKE(2, 3)	usrerrenh __P((char *, const char *, ...));
2338 extern void PRINTFLIKE(1, 2)	usrerr __P((const char *, ...));
2339 extern int	isenhsc __P((const char *, int));
2340 extern int	extenhsc __P((const char *, int, char *));
2341 
2342 /* alias file */
2343 extern void	alias __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
2344 extern bool	aliaswait __P((MAP *, char *, bool));
2345 extern void	forward __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
2346 extern void	readaliases __P((MAP *, SM_FILE_T *, bool, bool));
2347 extern bool	rebuildaliases __P((MAP *, bool));
2348 extern void	setalias __P((char *));
2349 
2350 /* logging */
2351 extern void	logdelivery __P((MAILER *, MCI *, char *, const char *, ADDRESS *, time_t, ENVELOPE *));
2352 extern void	logsender __P((ENVELOPE *, char *));
2353 extern void PRINTFLIKE(3, 4) sm_syslog __P((int, const char *, const char *, ...));
2354 
2355 /* SMTP */
2356 extern void	giveresponse __P((int, char *, MAILER *, MCI *, ADDRESS *, time_t, ENVELOPE *, ADDRESS *));
2357 extern int	reply __P((MAILER *, MCI *, ENVELOPE *, time_t, void (*)__P((char *, bool, MAILER *, MCI *, ENVELOPE *)), char **, int));
2358 extern void	smtp __P((char *volatile, BITMAP256, ENVELOPE *volatile));
2359 #if SASL
2360 extern int	smtpauth __P((MAILER *, MCI *, ENVELOPE *));
2361 #endif /* SASL */
2362 extern int	smtpdata __P((MAILER *, MCI *, ENVELOPE *, ADDRESS *, time_t));
2363 extern int	smtpgetstat __P((MAILER *, MCI *, ENVELOPE *));
2364 extern int	smtpmailfrom __P((MAILER *, MCI *, ENVELOPE *));
2365 extern void	smtpmessage __P((char *, MAILER *, MCI *, ...));
2366 extern void	smtpinit __P((MAILER *, MCI *, ENVELOPE *, bool));
2367 extern char	*smtptodsn __P((int));
2368 extern int	smtpprobe __P((MCI *));
2369 extern void	smtpquit __P((MAILER *, MCI *, ENVELOPE *));
2370 extern int	smtprcpt __P((ADDRESS *, MAILER *, MCI *, ENVELOPE *, ADDRESS *, time_t));
2371 extern void	smtprset __P((MAILER *, MCI *, ENVELOPE *));
2372 
2373 #define ISSMTPCODE(c)	(isascii(c[0]) && isdigit(c[0]) && \
2374 		    isascii(c[1]) && isdigit(c[1]) && \
2375 		    isascii(c[2]) && isdigit(c[2]))
2376 #define ISSMTPREPLY(c)	(ISSMTPCODE(c) && \
2377 		    (c[3] == ' ' || c[3] == '-' || c[3] == '\0'))
2378 
2379 /* delivery */
2380 extern pid_t	dowork __P((int, int, char *, bool, bool, ENVELOPE *));
2381 extern pid_t	doworklist __P((ENVELOPE *, bool, bool));
2382 extern int	endmailer __P((MCI *, ENVELOPE *, char **));
2383 extern int	mailfile __P((char *volatile, MAILER *volatile, ADDRESS *, volatile long, ENVELOPE *));
2384 extern void	sendall __P((ENVELOPE *, int));
2385 
2386 /* stats */
2387 #define STATS_NORMAL		'n'
2388 #define STATS_QUARANTINE	'q'
2389 #define STATS_REJECT		'r'
2390 #define STATS_CONNECT		'c'
2391 
2392 extern void	markstats __P((ENVELOPE *, ADDRESS *, int));
2393 extern void	clearstats __P((void));
2394 extern void	poststats __P((char *));
2395 
2396 /* control socket */
2397 extern void	closecontrolsocket  __P((bool));
2398 extern void	clrcontrol  __P((void));
2399 extern void	control_command __P((int, ENVELOPE *));
2400 extern int	opencontrolsocket __P((void));
2401 
2402 #if MILTER
2403 /* milter functions */
2404 extern void	milter_config __P((char *, struct milter **, int));
2405 extern void	milter_setup __P((char *));
2406 extern void	milter_set_option __P((char *, char *, bool));
2407 extern bool	milter_can_delrcpts __P((void));
2408 extern bool	milter_init __P((ENVELOPE *, char *));
2409 extern void	milter_quit __P((ENVELOPE *));
2410 extern void	milter_abort __P((ENVELOPE *));
2411 extern char	*milter_connect __P((char *, SOCKADDR, ENVELOPE *, char *));
2412 extern char	*milter_helo __P((char *, ENVELOPE *, char *));
2413 extern char	*milter_envfrom __P((char **, ENVELOPE *, char *));
2414 extern char	*milter_data_cmd __P((ENVELOPE *, char *));
2415 extern char	*milter_envrcpt __P((char **, ENVELOPE *, char *));
2416 extern char	*milter_data __P((ENVELOPE *, char *));
2417 extern char	*milter_unknown __P((char *, ENVELOPE *, char *));
2418 #endif /* MILTER */
2419 
2420 extern char	*addquotes __P((char *, SM_RPOOL_T *));
2421 extern char	*arpadate __P((char *));
2422 extern bool	atobool __P((char *));
2423 extern int	atooct __P((char *));
2424 extern void	auth_warning __P((ENVELOPE *, const char *, ...));
2425 extern int	blocksignal __P((int));
2426 extern bool	bitintersect __P((BITMAP256, BITMAP256));
2427 extern bool	bitzerop __P((BITMAP256));
2428 extern int	check_bodytype __P((char *));
2429 extern void	buildfname __P((char *, char *, char *, int));
2430 extern bool	chkclientmodifiers __P((int));
2431 extern bool	chkdaemonmodifiers __P((int));
2432 extern int	checkcompat __P((ADDRESS *, ENVELOPE *));
2433 #ifdef XDEBUG
2434 extern void	checkfd012 __P((char *));
2435 extern void	checkfdopen __P((int, char *));
2436 #endif /* XDEBUG */
2437 extern void	checkfds __P((char *));
2438 extern bool	chownsafe __P((int, bool));
2439 extern void	cleanstrcpy __P((char *, char *, int));
2440 #if SM_CONF_SHM
2441 extern void	cleanup_shm __P((bool));
2442 #endif /* SM_CONF_SHM */
2443 extern void	close_sendmail_pid __P((void));
2444 extern void	clrdaemon __P((void));
2445 extern void	collect __P((SM_FILE_T *, bool, HDR **, ENVELOPE *, bool));
2446 extern bool	connection_rate_check __P((SOCKADDR *, ENVELOPE *));
2447 extern time_t	convtime __P((char *, int));
2448 extern char	**copyplist __P((char **, bool, SM_RPOOL_T *));
2449 extern void	copy_class __P((int, int));
2450 extern int	count_open_connections __P((SOCKADDR *));
2451 extern time_t	curtime __P((void));
2452 extern char	*defcharset __P((ENVELOPE *));
2453 extern char	*denlstring __P((char *, bool, bool));
2454 extern void	dferror __P((SM_FILE_T *volatile, char *, ENVELOPE *));
2455 extern void	disconnect __P((int, ENVELOPE *));
2456 #if _FFR_CONTROL_MSTAT
2457 extern void	disk_status __P((SM_FILE_T *, char *));
2458 #endif /* _FFR_CONTROL_MSTAT */
2459 extern bool	dns_getcanonname __P((char *, int, bool, int *, int *));
2460 extern pid_t	dofork __P((void));
2461 extern int	drop_privileges __P((bool));
2462 extern int	dsntoexitstat __P((char *));
2463 extern void	dumpfd __P((int, bool, bool));
2464 extern void	dumpstate __P((char *));
2465 extern bool	enoughdiskspace __P((long, ENVELOPE *));
2466 extern char	*exitstat __P((char *));
2467 extern void	fatal_error __P((SM_EXC_T *));
2468 extern char	*fgetfolded __P((char *, int, SM_FILE_T *));
2469 extern void	fill_fd __P((int, char *));
2470 extern char	*find_character __P((char *, int));
2471 extern int	finduser __P((char *, bool *, SM_MBDB_T *));
2472 extern void	finis __P((bool, bool, volatile int));
2473 extern void	fixcrlf __P((char *, bool));
2474 extern long	freediskspace __P((char *, long *));
2475 #if NETINET6 && NEEDSGETIPNODE
2476 extern void	freehostent __P((struct hostent *));
2477 #endif /* NETINET6 && NEEDSGETIPNODE */
2478 extern char	*get_column __P((char *, int, int, char *, int));
2479 extern char	*getauthinfo __P((int, bool *));
2480 extern int	getdtsize __P((void));
2481 extern int	getla __P((void));
2482 extern char	*getmodifiers __P((char *, BITMAP256));
2483 extern BITMAP256	*getrequests __P((ENVELOPE *));
2484 extern char	*getvendor __P((int));
2485 extern void	help __P((char *, ENVELOPE *));
2486 extern void	init_md __P((int, char **));
2487 extern void	initdaemon __P((void));
2488 extern void	inithostmaps __P((void));
2489 extern void	initmacros __P((ENVELOPE *));
2490 extern void	initsetproctitle __P((int, char **, char **));
2491 extern void	init_vendor_macros __P((ENVELOPE *));
2492 extern SIGFUNC_DECL	intsig __P((int));
2493 extern bool	isloopback __P((SOCKADDR sa));
2494 extern void	load_if_names __P((void));
2495 extern bool	lockfile __P((int, char *, char *, int));
2496 extern void	log_sendmail_pid __P((ENVELOPE *));
2497 extern void	logundelrcpts __P((ENVELOPE *, char *, int, bool));
2498 extern char	lower __P((int));
2499 extern void	makelower __P((char *));
2500 extern int	makeconnection_ds __P((char *, MCI *));
2501 extern int	makeconnection __P((char *, volatile unsigned int, MCI *, ENVELOPE *, time_t));
2502 extern void	makeworkgroups __P((void));
2503 extern void	markfailure __P((ENVELOPE *, ADDRESS *, MCI *, int, bool));
2504 extern void	mark_work_group_restart __P((int, int));
2505 extern char *	munchstring __P((char *, char **, int));
2506 extern struct hostent	*myhostname __P((char *, int));
2507 extern char	*newstr __P((const char *));
2508 #if NISPLUS
2509 extern char	*nisplus_default_domain __P((void));	/* extern for Sun */
2510 #endif /* NISPLUS */
2511 extern bool	path_is_dir __P((char *, bool));
2512 extern int	pickqdir __P((QUEUEGRP *qg, long fsize, ENVELOPE *e));
2513 extern char	*pintvl __P((time_t, bool));
2514 extern void	printav __P((SM_FILE_T *, char **));
2515 extern void	printmailer __P((SM_FILE_T *, MAILER *));
2516 extern void	printnqe __P((SM_FILE_T *, char *));
2517 extern void	printopenfds __P((bool));
2518 extern void	printqueue __P((void));
2519 extern void	printrules __P((void));
2520 extern pid_t	prog_open __P((char **, int *, ENVELOPE *));
2521 extern void	putline __P((char *, MCI *));
2522 extern void	putxline __P((char *, size_t, MCI *, int));
2523 extern void	queueup_macros __P((int, SM_FILE_T *, ENVELOPE *));
2524 extern void	readcf __P((char *, bool, ENVELOPE *));
2525 extern SIGFUNC_DECL	reapchild __P((int));
2526 extern int	releasesignal __P((int));
2527 extern void	resetlimits __P((void));
2528 extern void	restart_daemon __P((void));
2529 extern void	restart_marked_work_groups __P((void));
2530 extern bool	rfc822_string __P((char *));
2531 extern bool	savemail __P((ENVELOPE *, bool));
2532 extern void	seed_random __P((void));
2533 extern void	sendtoargv __P((char **, ENVELOPE *));
2534 extern void	setclientoptions __P((char *));
2535 extern bool	setdaemonoptions __P((char *));
2536 extern void	setdefaults __P((ENVELOPE *));
2537 extern void	setdefuser __P((void));
2538 extern bool	setvendor __P((char *));
2539 extern void	set_op_mode __P((int));
2540 extern void	setoption __P((int, char *, bool, bool, ENVELOPE *));
2541 extern sigfunc_t	setsignal __P((int, sigfunc_t));
2542 extern void	setuserenv __P((const char *, const char *));
2543 extern void	settime __P((ENVELOPE *));
2544 extern char	*sfgets __P((char *, int, SM_FILE_T *, time_t, char *));
2545 extern char	*shortenstring __P((const char *, size_t));
2546 extern char	*shorten_hostname __P((char []));
2547 extern bool	shorten_rfc822_string __P((char *, size_t));
2548 extern void	shutdown_daemon __P((void));
2549 extern void	sm_closefrom __P((int lowest, int highest));
2550 extern void	sm_close_on_exec __P((int lowest, int highest));
2551 extern struct hostent	*sm_gethostbyname __P((char *, int));
2552 extern struct hostent	*sm_gethostbyaddr __P((char *, int, int));
2553 extern void	sm_getla __P((void));
2554 extern struct passwd	*sm_getpwnam __P((char *));
2555 extern struct passwd	*sm_getpwuid __P((UID_T));
2556 extern void	sm_setproctitle __P((bool, ENVELOPE *, const char *, ...));
2557 extern pid_t	sm_wait __P((int *));
2558 extern bool	split_by_recipient __P((ENVELOPE *e));
2559 extern void	stop_sendmail __P((void));
2560 extern char	*str2prt __P((char *));
2561 extern void	stripbackslash __P((char *));
2562 extern bool	strreplnonprt __P((char *, int));
2563 extern bool	strcontainedin __P((bool, char *, char *));
2564 extern int	switch_map_find __P((char *, char *[], short []));
2565 extern bool	transienterror __P((int));
2566 #if _FFR_BESTMX_BETTER_TRUNCATION || _FFR_DNSMAP_MULTI
2567 extern void	truncate_at_delim __P((char *, size_t, int));
2568 #endif /* _FFR_BESTMX_BETTER_TRUNCATION || _FFR_DNSMAP_MULTI */
2569 extern void	tTflag __P((char *));
2570 extern void	tTsetup __P((unsigned char *, unsigned int, char *));
2571 extern SIGFUNC_DECL	tick __P((int));
2572 extern char	*ttypath __P((void));
2573 extern void	unlockqueue __P((ENVELOPE *));
2574 #if !HASUNSETENV
2575 extern void	unsetenv __P((char *));
2576 #endif /* !HASUNSETENV */
2577 
2578 /* update file system information: +/- some blocks */
2579 #if SM_CONF_SHM
2580 extern void	upd_qs __P((ENVELOPE *, bool, bool));
2581 # define updfs(e, delete, avail) upd_qs(e, delete, avail)
2582 #else /* SM_CONF_SHM */
2583 # define updfs(e, delete, avail)
2584 #endif /* SM_CONF_SHM */
2585 
2586 extern char	*username __P((void));
2587 extern bool	usershellok __P((char *, char *));
2588 extern void	vendor_post_defaults __P((ENVELOPE *));
2589 extern void	vendor_pre_defaults __P((ENVELOPE *));
2590 extern int	waitfor __P((pid_t));
2591 extern bool	writable __P((char *, ADDRESS *, long));
2592 #if SM_HEAP_CHECK
2593 # define xalloc(size)	xalloc_tagged(size, __FILE__, __LINE__)
2594 extern char *xalloc_tagged __P((int, char*, int));
2595 #else /* SM_HEAP_CHECK */
2596 extern char *xalloc __P((int));
2597 #endif /* SM_HEAP_CHECK */
2598 extern void	xputs __P((SM_FILE_T *, const char *));
2599 extern char	*xtextify __P((char *, char *));
2600 extern bool	xtextok __P((char *));
2601 extern int	xunlink __P((char *));
2602 extern char	*xuntextify __P((char *));
2603 
2604 
2605 #endif /* ! _SENDMAIL_H */
2606