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