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