xref: /freebsd/contrib/sendmail/src/sendmail.h (revision 7a8d62cd046942ab34fcf282ecbbb0747a08a4ee)
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	0x10000		/* 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 # if (SASL_AUTH_AUTH & SASL_SEC_MASK) != 0
725 #  ERROR "change SASL_AUTH_AUTH notify sendmail.org!"
726 # endif
727 
728 /* functions */
729 extern char	*intersect __P((char *, char *, SM_RPOOL_T *));
730 extern char	*iteminlist __P((char *, char *, char *));
731 # if SASL >= 20000
732 extern int	proxy_policy __P((sasl_conn_t *, void *, const char *, unsigned, const char *, unsigned, const char *, unsigned, struct propctx *));
733 extern int	safesaslfile __P((void *, const char *, sasl_verify_type_t));
734 # else /* SASL >= 20000 */
735 extern int	proxy_policy __P((void *, const char *, const char *, const char **, const char **));
736 #  if SASL > 10515
737 extern int	safesaslfile __P((void *, char *, int));
738 #  else /* SASL > 10515 */
739 extern int	safesaslfile __P((void *, char *));
740 #  endif /* SASL > 10515 */
741 # endif /* SASL >= 20000 */
742 extern void	stop_sasl_client __P((void));
743 
744 /* structure to store authinfo */
745 typedef char *SASL_AI_T[SASL_ENTRIES];
746 
747 EXTERN char	*AuthMechanisms;	/* AUTH mechanisms */
748 EXTERN char	*AuthRealm;	/* AUTH realm */
749 EXTERN char	*SASLInfo;	/* file with AUTH info */
750 EXTERN int	SASLOpts;	/* options for SASL */
751 EXTERN int	MaxSLBits;	/* max. encryption bits for SASL */
752 #endif /* SASL */
753 
754 /*
755 **  Structure to store macros.
756 */
757 typedef struct
758 {
759 	SM_RPOOL_T	*mac_rpool;		/* resource pool */
760 	BITMAP256	mac_allocated;		/* storage has been alloc()? */
761 	char		*mac_table[MAXMACROID + 1];	/* macros */
762 } MACROS_T;
763 
764 EXTERN MACROS_T		GlobalMacros;
765 
766 /*
767 **  Information about currently open connections to mailers, or to
768 **  hosts that we have looked up recently.
769 */
770 
771 #define MCI		struct mailer_con_info
772 
773 MCI
774 {
775 	unsigned long	mci_flags;	/* flag bits, see below */
776 	short		mci_errno;	/* error number on last connection */
777 	short		mci_herrno;	/* h_errno from last DNS lookup */
778 	short		mci_exitstat;	/* exit status from last connection */
779 	short		mci_state;	/* SMTP state */
780 	int		mci_deliveries;	/* delivery attempts for connection */
781 	long		mci_maxsize;	/* max size this server will accept */
782 	SM_FILE_T	*mci_in;	/* input side of connection */
783 	SM_FILE_T	*mci_out;	/* output side of connection */
784 	pid_t		mci_pid;	/* process id of subordinate proc */
785 	char		*mci_phase;	/* SMTP phase string */
786 	struct mailer	*mci_mailer;	/* ptr to the mailer for this conn */
787 	char		*mci_host;	/* host name */
788 	char		*mci_status;	/* DSN status to be copied to addrs */
789 	char		*mci_rstatus;	/* SMTP status to be copied to addrs */
790 	time_t		mci_lastuse;	/* last usage time */
791 	SM_FILE_T	*mci_statfile;	/* long term status file */
792 	char		*mci_heloname;	/* name to use as HELO arg */
793 	long		mci_min_by;	/* minimum DELIVERBY */
794 	bool		mci_retryrcpt;	/* tempfail for at least one rcpt */
795 	char		*mci_tolist;	/* list of valid recipients */
796 	SM_RPOOL_T	*mci_rpool;	/* resource pool */
797 #if PIPELINING
798 	int		mci_okrcpts;	/* number of valid recipients */
799 	ADDRESS		*mci_nextaddr;	/* next address for pipelined status */
800 #endif
801 #if SASL
802 	SASL_AI_T	mci_sai;	/* authentication info */
803 	bool		mci_sasl_auth;	/* authenticated? */
804 	int		mci_sasl_string_len;
805 	char		*mci_sasl_string;	/* sasl reply string */
806 	char		*mci_saslcap;	/* SASL list of mechanisms */
807 	sasl_conn_t	*mci_conn;	/* SASL connection */
808 #endif /* SASL */
809 #if STARTTLS
810 	SSL		*mci_ssl;	/* SSL connection */
811 	tlsi_ctx_T	mci_tlsi;
812 #endif
813 	MACROS_T	mci_macro;	/* macro definitions */
814 };
815 
816 
817 /* MCI flag bits */
818 /* XREF: mci.c: MciFlags[]: needs to be kept in sync! */
819 /* 0x00000001 unused, was MCIF_VALID: this entry is valid */
820 #define MCIF_OCC_INCR	0x00000002	/* occ values increased */
821 #define MCIF_CACHED	0x00000004	/* currently in open cache */
822 #define MCIF_ESMTP	0x00000008	/* this host speaks ESMTP */
823 #define MCIF_EXPN	0x00000010	/* EXPN command supported */
824 #define MCIF_SIZE	0x00000020	/* SIZE option supported */
825 #define MCIF_8BITMIME	0x00000040	/* BODY=8BITMIME supported */
826 #define MCIF_7BIT	0x00000080	/* strip this message to 7 bits */
827 /* 0x00000100 unused, was MCIF_MULTSTAT: MAIL11V3: handles MULT status */
828 #define MCIF_INHEADER	0x00000200	/* currently outputing header */
829 #define MCIF_CVT8TO7	0x00000400	/* convert from 8 to 7 bits */
830 #define MCIF_DSN	0x00000800	/* DSN extension supported */
831 #define MCIF_8BITOK	0x00001000	/* OK to send 8 bit characters */
832 #define MCIF_CVT7TO8	0x00002000	/* convert from 7 to 8 bits */
833 #define MCIF_INMIME	0x00004000	/* currently reading MIME header */
834 #define MCIF_AUTH	0x00008000	/* AUTH= supported */
835 #define MCIF_AUTHACT	0x00010000	/* SASL (AUTH) active */
836 #define MCIF_ENHSTAT	0x00020000	/* ENHANCEDSTATUSCODES supported */
837 #define MCIF_PIPELINED	0x00040000	/* PIPELINING supported */
838 #define MCIF_VERB	0x00080000	/* VERB supported */
839 #if STARTTLS
840 #define MCIF_TLS	0x00100000	/* STARTTLS supported */
841 #define MCIF_TLSACT	0x00200000	/* STARTTLS active */
842 #else /* STARTTLS */
843 #define MCIF_TLS	0
844 #define MCIF_TLSACT	0
845 #endif /* STARTTLS */
846 #define MCIF_DLVR_BY	0x00400000	/* DELIVERBY */
847 #if _FFR_IGNORE_EXT_ON_HELO
848 # define MCIF_HELO	0x00800000	/* we used HELO: ignore extensions */
849 #endif
850 #define MCIF_INLONGLINE 0x01000000	/* in the middle of a long line */
851 #define MCIF_AUTH2	0x02000000	/* got 2 AUTH lines */
852 #define MCIF_ONLY_EHLO	0x10000000	/* use only EHLO in smtpinit */
853 #if _FFR_HANDLE_HDR_RW_TEMPFAIL
854 /* an error is not sticky (if put{header,body}() etc fail) */
855 # define MCIF_NOTSTICKY	0x20000000
856 #else
857 # define MCIF_NOTSTICKY	0
858 #endif
859 #if _FFR_EAI
860 # define MCIF_EAI	0x40000000	/* SMTPUTF8 supported */
861 #else
862 # define MCIF_EAI	0x00000000	/* for MCIF_EXTENS */
863 #endif
864 
865 #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)
866 
867 /* states */
868 #define MCIS_CLOSED	0		/* no traffic on this connection */
869 #define MCIS_OPENING	1		/* sending initial protocol */
870 #define MCIS_OPEN	2		/* open, initial protocol sent */
871 #define MCIS_MAIL	3		/* MAIL command sent */
872 #define MCIS_RCPT	4		/* RCPT commands being sent */
873 #define MCIS_DATA	5		/* DATA command sent */
874 #define MCIS_QUITING	6		/* running quit protocol */
875 #define MCIS_SSD	7		/* service shutting down */
876 #define MCIS_ERROR	8		/* I/O error on connection */
877 
878 /* functions */
879 extern void	mci_cache __P((MCI *));
880 extern void	mci_close __P((MCI *, char *where));
881 extern void	mci_dump __P((SM_FILE_T *, MCI *, bool));
882 extern void	mci_dump_all __P((SM_FILE_T *, bool));
883 extern void	mci_flush __P((bool, MCI *));
884 extern void	mci_clr_extensions __P((MCI *));
885 extern MCI	*mci_get __P((char *, MAILER *));
886 extern int	mci_lock_host __P((MCI *));
887 extern bool	mci_match __P((char *, MAILER *));
888 extern int	mci_print_persistent __P((char *, char *));
889 extern int	mci_purge_persistent __P((char *, char *));
890 extern MCI	**mci_scan __P((MCI *));
891 extern void	mci_setstat __P((MCI *, int, char *, char *));
892 extern void	mci_store_persistent __P((MCI *));
893 extern int	mci_traverse_persistent __P((int (*)(char *, char *), char *));
894 extern void	mci_unlock_host __P((MCI *));
895 
896 EXTERN int	MaxMciCache;		/* maximum entries in MCI cache */
897 EXTERN time_t	MciCacheTimeout;	/* maximum idle time on connections */
898 EXTERN time_t	MciInfoTimeout;		/* how long 'til we retry down hosts */
899 
900 /*
901 **  Header structure.
902 **	This structure is used internally to store header items.
903 */
904 
905 struct header
906 {
907 	char		*h_field;	/* the name of the field */
908 	char		*h_value;	/* the value of that field */
909 	struct header	*h_link;	/* the next header */
910 	unsigned char	h_macro;	/* include header if macro defined */
911 	unsigned long	h_flags;	/* status bits, see below */
912 	BITMAP256	h_mflags;	/* m_flags bits needed */
913 };
914 
915 typedef struct header	HDR;
916 
917 /*
918 **  Header information structure.
919 **	Defined in conf.c, this struct declares the header fields
920 **	that have some magic meaning.
921 */
922 
923 struct hdrinfo
924 {
925 	char		*hi_field;	/* the name of the field */
926 	unsigned long	hi_flags;	/* status bits, see below */
927 	char		*hi_ruleset;	/* validity check ruleset */
928 };
929 
930 extern struct hdrinfo	HdrInfo[];
931 
932 /* bits for h_flags and hi_flags */
933 #define H_EOH		0x00000001	/* field terminates header */
934 #define H_RCPT		0x00000002	/* contains recipient addresses */
935 #define H_DEFAULT	0x00000004	/* if another value is found, drop this */
936 #define H_RESENT	0x00000008	/* this address is a "Resent-..." address */
937 #define H_CHECK		0x00000010	/* check h_mflags against m_flags */
938 #define H_ACHECK	0x00000020	/* ditto, but always (not just default) */
939 #define H_FORCE		0x00000040	/* force this field, even if default */
940 #define H_TRACE		0x00000080	/* this field contains trace information */
941 #define H_FROM		0x00000100	/* this is a from-type field */
942 #define H_VALID		0x00000200	/* this field has a validated value */
943 #define H_RECEIPTTO	0x00000400	/* field has return receipt info */
944 #define H_ERRORSTO	0x00000800	/* field has error address info */
945 #define H_CTE		0x00001000	/* field is a content-transfer-encoding */
946 #define H_CTYPE		0x00002000	/* this is a content-type field */
947 #define H_BCC		0x00004000	/* Bcc: header: strip value or delete */
948 #define H_ENCODABLE	0x00008000	/* field can be RFC 1522 encoded */
949 #define H_STRIPCOMM	0x00010000	/* header check: strip comments */
950 #define H_BINDLATE	0x00020000	/* only expand macros at deliver */
951 #define H_USER		0x00040000	/* header came from the user/SMTP */
952 
953 /* bits for chompheader() */
954 #define CHHDR_DEF	0x0001	/* default header */
955 #define CHHDR_CHECK	0x0002	/* call ruleset for header */
956 #define CHHDR_USER	0x0004	/* header from user */
957 #define CHHDR_QUEUE	0x0008	/* header from queue file */
958 
959 /* functions */
960 extern void	addheader __P((char *, char *, int, ENVELOPE *, bool));
961 extern unsigned long	chompheader __P((char *, int, HDR **, ENVELOPE *));
962 extern bool	commaize __P((HDR *, char *, bool, MCI *, ENVELOPE *, int));
963 extern HDR	*copyheader __P((HDR *, SM_RPOOL_T *));
964 extern void	eatheader __P((ENVELOPE *, bool, bool));
965 extern char	*hvalue __P((char *, HDR *));
966 extern void	insheader __P((int, char *, char *, int, ENVELOPE *, bool));
967 extern bool	isheader __P((char *));
968 extern bool	putfromline __P((MCI *, ENVELOPE *));
969 extern void	setupheaders __P((void));
970 
971 /*
972 **  Performance monitoring
973 */
974 
975 #define TIMERS		struct sm_timers
976 
977 TIMERS
978 {
979 	TIMER	ti_overall;	/* the whole process */
980 };
981 
982 
983 #define PUSHTIMER(l, t)	{ if (tTd(98, l)) pushtimer(&t); }
984 #define POPTIMER(l, t)	{ if (tTd(98, l)) poptimer(&t); }
985 
986 /*
987 **  Envelope structure.
988 **	This structure defines the message itself.  There is usually
989 **	only one of these -- for the message that we originally read
990 **	and which is our primary interest -- but other envelopes can
991 **	be generated during processing.  For example, error messages
992 **	will have their own envelope.
993 */
994 
995 struct envelope
996 {
997 	HDR		*e_header;	/* head of header list */
998 	long		e_msgpriority;	/* adjusted priority of this message */
999 	time_t		e_ctime;	/* time message appeared in the queue */
1000 	char		*e_to;		/* (list of) target person(s) */
1001 	ADDRESS		e_from;		/* the person it is from */
1002 	char		*e_sender;	/* e_from.q_paddr w comments stripped */
1003 	char		**e_fromdomain;	/* the domain part of the sender */
1004 #if _FFR_EAI
1005 	bool		e_smtputf8; /* whether the sender demanded SMTPUTF8 */
1006 #endif
1007 	ADDRESS		*e_sendqueue;	/* list of message recipients */
1008 	ADDRESS		*e_errorqueue;	/* the queue for error responses */
1009 
1010 	/*
1011 	**  Overflow detection is based on < 0, so don't change this
1012 	**  to unsigned.  We don't use unsigned and == ULONG_MAX because
1013 	**  some libc's don't have strtoul(), see mail_esmtp_args().
1014 	*/
1015 
1016 	long		e_msgsize;	/* size of the message in bytes */
1017 	char		*e_msgid;	/* message id (for logging) */
1018 	unsigned long	e_flags;	/* flags, see below */
1019 	int		e_nrcpts;	/* number of recipients */
1020 	short		e_class;	/* msg class (priority, junk, etc.) */
1021 	short		e_hopcount;	/* number of times processed */
1022 	short		e_nsent;	/* number of sends since checkpoint */
1023 	short		e_sendmode;	/* message send mode */
1024 	short		e_errormode;	/* error return mode */
1025 	short		e_timeoutclass;	/* message timeout class */
1026 	bool		(*e_puthdr)__P((MCI *, HDR *, ENVELOPE *, int));
1027 					/* function to put header of message */
1028 	bool		(*e_putbody)__P((MCI *, ENVELOPE *, char *));
1029 					/* function to put body of message */
1030 	ENVELOPE	*e_parent;	/* the message this one encloses */
1031 	ENVELOPE	*e_sibling;	/* the next envelope of interest */
1032 	char		*e_bodytype;	/* type of message body */
1033 	SM_FILE_T	*e_dfp;		/* data file */
1034 	char		*e_id;		/* code for this entry in queue */
1035 #if _FFR_SESSID
1036 	char		*e_sessid;	/* session ID for this envelope */
1037 #endif
1038 	int		e_qgrp;		/* queue group (index into queues) */
1039 	int		e_qdir;		/* index into queue directories */
1040 	int		e_dfqgrp;	/* data file queue group index */
1041 	int		e_dfqdir;	/* data file queue directory index */
1042 	int		e_xfqgrp;	/* queue group (index into queues) */
1043 	int		e_xfqdir;	/* index into queue directories (xf) */
1044 	SM_FILE_T	*e_xfp;		/* transcript file */
1045 	SM_FILE_T	*e_lockfp;	/* the lock file for this message */
1046 	char		*e_message;	/* error message; readonly; NULL,
1047 					 * or allocated from e_rpool */
1048 	char		*e_statmsg;	/* stat msg (changes per delivery).
1049 					 * readonly. NULL or allocated from
1050 					 * e_rpool. */
1051 	char		*e_quarmsg;	/* why envelope is quarantined */
1052 	char		e_qfletter;	/* queue file letter on disk */
1053 	char		*e_msgboundary;	/* MIME-style message part boundary */
1054 	char		*e_origrcpt;	/* original recipient (one only) */
1055 	char		*e_envid;	/* envelope id from MAIL FROM: line */
1056 	char		*e_status;	/* DSN status for this message */
1057 	time_t		e_dtime;	/* time of last delivery attempt */
1058 	int		e_ntries;	/* number of delivery attempts */
1059 	dev_t		e_dfdev;	/* data file device (crash recovery) */
1060 	ino_t		e_dfino;	/* data file inode (crash recovery) */
1061 	MACROS_T	e_macro;	/* macro definitions */
1062 	MCI		*e_mci;		/* connection info */
1063 	char		*e_auth_param;	/* readonly; NULL or static storage or
1064 					 * allocated from e_rpool */
1065 	TIMERS		e_timers;	/* per job timers */
1066 	long		e_deliver_by;	/* deliver by */
1067 	int		e_dlvr_flag;	/* deliver by flag */
1068 	SM_RPOOL_T	*e_rpool;	/* resource pool for this envelope */
1069 	unsigned int	e_features;	/* server features */
1070 #define ENHSC_LEN	11
1071 #if _FFR_MILTER_ENHSC
1072 	char		e_enhsc[ENHSC_LEN];	/* enhanced status code */
1073 #endif
1074 	/* smtp error codes during delivery */
1075 	int		e_rcode;	/* reply code */
1076 	char		e_renhsc[ENHSC_LEN];	/* enhanced status code */
1077 	char		*e_text;	/* reply text */
1078 };
1079 
1080 #define PRT_NONNEGL(v)	((v) < 0 ? LONG_MAX : (v))
1081 
1082 /* values for e_flags */
1083 #define EF_OLDSTYLE	0x00000001L	/* use spaces (not commas) in hdrs */
1084 #define EF_INQUEUE	0x00000002L	/* this message is fully queued */
1085 #define EF_NO_BODY_RETN	0x00000004L	/* omit message body on error */
1086 #define EF_CLRQUEUE	0x00000008L	/* disk copy is no longer needed */
1087 #define EF_SENDRECEIPT	0x00000010L	/* send a return receipt */
1088 #define EF_FATALERRS	0x00000020L	/* fatal errors occurred */
1089 #define EF_DELETE_BCC	0x00000040L	/* delete Bcc: headers entirely */
1090 #define EF_RESPONSE	0x00000080L	/* this is an error or return receipt */
1091 #define EF_RESENT	0x00000100L	/* this message is being forwarded */
1092 #define EF_VRFYONLY	0x00000200L	/* verify only (don't expand aliases) */
1093 #define EF_WARNING	0x00000400L	/* warning message has been sent */
1094 #define EF_QUEUERUN	0x00000800L	/* this envelope is from queue */
1095 #define EF_GLOBALERRS	0x00001000L	/* treat errors as global */
1096 #define EF_PM_NOTIFY	0x00002000L	/* send return mail to postmaster */
1097 #define EF_METOO	0x00004000L	/* send to me too */
1098 #define EF_LOGSENDER	0x00008000L	/* need to log the sender */
1099 #define EF_NORECEIPT	0x00010000L	/* suppress all return-receipts */
1100 #define EF_HAS8BIT	0x00020000L	/* at least one 8-bit char in body */
1101 /* was: EF_NL_NOT_EOL	0x00040000L	* don't accept raw NL as EOLine */
1102 /* was: EF_CRLF_NOT_EOL	0x00080000L	* don't accept CR-LF as EOLine */
1103 #define EF_RET_PARAM	0x00100000L	/* RCPT command had RET argument */
1104 #define EF_HAS_DF	0x00200000L	/* set when data file is instantiated */
1105 #define EF_IS_MIME	0x00400000L	/* really is a MIME message */
1106 #define EF_DONT_MIME	0x00800000L	/* never MIME this message */
1107 #define EF_DISCARD	0x01000000L	/* discard the message */
1108 #define EF_TOOBIG	0x02000000L	/* message is too big */
1109 #define EF_SPLIT	0x04000000L	/* envelope has been split */
1110 #define EF_UNSAFE	0x08000000L	/* unsafe: read from untrusted source */
1111 #define EF_TOODEEP	0x10000000L	/* message is nested too deep */
1112 #define EF_SECURE	0x20000000L	/* DNSSEC for currently parsed addr */
1113 
1114 #define DLVR_NOTIFY	0x01
1115 #define DLVR_RETURN	0x02
1116 #define DLVR_TRACE	0x10
1117 #define IS_DLVR_NOTIFY(e)	(((e)->e_dlvr_flag & DLVR_NOTIFY) != 0)
1118 #define IS_DLVR_RETURN(e)	(((e)->e_dlvr_flag & DLVR_RETURN) != 0)
1119 #define IS_DLVR_TRACE(e)	(((e)->e_dlvr_flag & DLVR_TRACE) != 0)
1120 #define IS_DLVR_BY(e)		((e)->e_dlvr_flag != 0)
1121 
1122 #define BODYTYPE_NONE	(0)
1123 #define BODYTYPE_7BIT	(1)
1124 #define BODYTYPE_8BITMIME	(2)
1125 #define BODYTYPE_ILLEGAL	(-1)
1126 #define BODYTYPE_VALID(b) ((b) == BODYTYPE_7BIT || (b) == BODYTYPE_8BITMIME)
1127 
1128 extern ENVELOPE	BlankEnvelope;
1129 
1130 /* functions */
1131 extern void	clearenvelope __P((ENVELOPE *, bool, SM_RPOOL_T *));
1132 extern int	dropenvelope __P((ENVELOPE *, bool, bool));
1133 extern ENVELOPE	*newenvelope __P((ENVELOPE *, ENVELOPE *, SM_RPOOL_T *));
1134 extern void	clrsessenvelope __P((ENVELOPE *));
1135 extern void	printenvflags __P((ENVELOPE *));
1136 extern bool	putbody __P((MCI *, ENVELOPE *, char *));
1137 extern bool	putheader __P((MCI *, HDR *, ENVELOPE *, int));
1138 
1139 /*
1140 **  Message priority classes.
1141 **
1142 **	The message class is read directly from the Priority: header
1143 **	field in the message.
1144 **
1145 **	CurEnv->e_msgpriority is the number of bytes in the message plus
1146 **	the creation time (so that jobs ``tend'' to be ordered correctly),
1147 **	adjusted by the message class, the number of recipients, and the
1148 **	amount of time the message has been sitting around.  This number
1149 **	is used to order the queue.  Higher values mean LOWER priority.
1150 **
1151 **	Each priority class point is worth WkClassFact priority points;
1152 **	each recipient is worth WkRecipFact priority points.  Each time
1153 **	we reprocess a message the priority is adjusted by WkTimeFact.
1154 **	WkTimeFact should normally decrease the priority so that jobs
1155 **	that have historically failed will be run later; thanks go to
1156 **	Jay Lepreau at Utah for pointing out the error in my thinking.
1157 **
1158 **	The "class" is this number, unadjusted by the age or size of
1159 **	this message.  Classes with negative representations will have
1160 **	error messages thrown away if they are not local.
1161 */
1162 
1163 struct priority
1164 {
1165 	char	*pri_name;	/* external name of priority */
1166 	int	pri_val;	/* internal value for same */
1167 };
1168 
1169 EXTERN int	NumPriorities;	/* pointer into Priorities */
1170 EXTERN struct priority	Priorities[MAXPRIORITIES];
1171 
1172 /*
1173 **  Rewrite rules.
1174 */
1175 
1176 struct rewrite
1177 {
1178 	char	**r_lhs;	/* pattern match */
1179 	char	**r_rhs;	/* substitution value */
1180 	struct rewrite	*r_next;/* next in chain */
1181 	int	r_line;		/* rule line in sendmail.cf */
1182 };
1183 
1184 /*
1185 **  Special characters in rewriting rules.
1186 **	These are used internally only.
1187 **	The COND* rules are actually used in macros rather than in
1188 **		rewriting rules, but are given here because they
1189 **		cannot conflict.
1190 */
1191 
1192 /* "out of band" indicator */
1193 /* sm/sendmail.h #define METAQUOTE ((unsigned char)0377) quotes the next octet */
1194 
1195 /* left hand side items */
1196 #define MATCHZANY	((unsigned char)0220)	/* match zero or more tokens */
1197 #define MATCHANY	((unsigned char)0221)	/* match one or more tokens */
1198 #define MATCHONE	((unsigned char)0222)	/* match exactly one token */
1199 #define MATCHCLASS	((unsigned char)0223)	/* match one token in a class */
1200 #define MATCHNCLASS	((unsigned char)0224)	/* match tokens not in class */
1201 
1202 /* right hand side items */
1203 #define MATCHREPL	((unsigned char)0225)	/* RHS replacement for above */
1204 #define CANONNET	((unsigned char)0226)	/* canonical net, next token */
1205 #define CANONHOST	((unsigned char)0227)	/* canonical host, next token */
1206 #define CANONUSER	((unsigned char)0230)	/* canonical user, next N tokens */
1207 #define CALLSUBR	((unsigned char)0231)	/* call another rewriting set */
1208 
1209 /* conditionals in macros (anywhere) */
1210 #define CONDIF		((unsigned char)0232)	/* conditional if-then */
1211 #define CONDELSE	((unsigned char)0233)	/* conditional else */
1212 #define CONDFI		((unsigned char)0234)	/* conditional fi */
1213 
1214 /* bracket characters for RHS host name lookup */
1215 #define HOSTBEGIN	((unsigned char)0235)	/* hostname lookup begin */
1216 #define HOSTEND		((unsigned char)0236)	/* hostname lookup end */
1217 
1218 /* bracket characters for RHS generalized lookup */
1219 #define LOOKUPBEGIN	((unsigned char)0205)	/* generalized lookup begin */
1220 #define LOOKUPEND	((unsigned char)0206)	/* generalized lookup end */
1221 
1222 /* macro substitution characters (anywhere) */
1223 #define MACROEXPAND	((unsigned char)0201)	/* macro expansion */
1224 #define MACRODEXPAND	((unsigned char)0202)	/* deferred macro expansion */
1225 
1226 /* to make the code clearer */
1227 #define MATCHZERO	CANONHOST
1228 
1229 #define MAXMATCH	9	/* max params per rewrite */
1230 #define MAX_MAP_ARGS	10	/* max arguments for map */
1231 
1232 /* external <==> internal mapping table */
1233 struct metamac
1234 {
1235 	char		metaname;	/* external code (after $) */
1236 	unsigned char	metaval;	/* internal code (as above) */
1237 };
1238 
1239 /* values for macros with external names only */
1240 #define MID_OPMODE	0202	/* operation mode */
1241 
1242 /* functions */
1243 #if SM_HEAP_CHECK
1244 extern void
1245 macdefine_tagged __P((
1246 	MACROS_T *_mac,
1247 	ARGCLASS_T _vclass,
1248 	int _id,
1249 	char *_value,
1250 	char *_file,
1251 	int _line,
1252 	int _group));
1253 # define macdefine(mac,c,id,v) \
1254 	macdefine_tagged(mac,c,id,v,__FILE__,__LINE__,sm_heap_group())
1255 #else /* SM_HEAP_CHECK */
1256 extern void
1257 macdefine __P((
1258 	MACROS_T *_mac,
1259 	ARGCLASS_T _vclass,
1260 	int _id,
1261 	char *_value));
1262 # define macdefine_tagged(mac,c,id,v,file,line,grp) macdefine(mac,c,id,v)
1263 #endif /* SM_HEAP_CHECK */
1264 extern void	macset __P((MACROS_T *, int, char *));
1265 #define macget(mac, i) (mac)->mac_table[i]
1266 extern void	expand __P((char *, char *, size_t, ENVELOPE *));
1267 extern int	macid_parse __P((char *, char **));
1268 #define macid(name)	macid_parse(name, NULL)
1269 extern char	*macname __P((int));
1270 extern char	*macvalue __P((int, ENVELOPE *));
1271 extern void	mactabclear __P((MACROS_T *));
1272 extern int	rscheck __P((char *, const char *, const char *, ENVELOPE *, int, int, const char *, const char *, ADDRESS *, char **));
1273 extern int	rscap __P((char *, char *, char *, ENVELOPE *, char ***, char *, int));
1274 extern void	setclass __P((int, char *));
1275 extern int	strtorwset __P((char *, char **, int));
1276 extern char	*translate_dollars __P((char *, char *, int *));
1277 extern bool	wordinclass __P((char *, int));
1278 
1279 /*
1280 **  Name canonification short circuit.
1281 **
1282 **	If the name server for a host is down, the process of trying to
1283 **	canonify the name can hang.  This is similar to (but alas, not
1284 **	identical to) looking up the name for delivery.  This stab type
1285 **	caches the result of the name server lookup so we don't hang
1286 **	multiple times.
1287 */
1288 
1289 #define NAMECANON	struct _namecanon
1290 
1291 NAMECANON
1292 {
1293 	short		nc_errno;	/* cached errno */
1294 	short		nc_herrno;	/* cached h_errno */
1295 	short		nc_stat;	/* cached exit status code */
1296 	short		nc_flags;	/* flag bits */
1297 	char		*nc_cname;	/* the canonical name */
1298 	time_t		nc_exp;		/* entry expires at */
1299 };
1300 
1301 /* values for nc_flags */
1302 #define NCF_VALID	0x0001	/* entry valid */
1303 #define NCF_VALID	0x0001	/* entry valid */
1304 #define NCF_SECURE	0x0002	/* entry secure (DNSSEC) */
1305 
1306 /* hostsignature structure */
1307 
1308 struct hostsig_t
1309 {
1310 	char		*hs_sig;	/* hostsignature */
1311 	time_t		hs_exp;		/* entry expires at */
1312 };
1313 
1314 typedef struct hostsig_t HOSTSIG_T;
1315 
1316 /*
1317 **  The standard udp packet size PACKETSZ (512) is not sufficient for some
1318 **  nameserver answers containing very many resource records. The resolver
1319 **  may switch to tcp and retry if it detects udp packet overflow.
1320 **  Also note that the resolver routines res_query and res_search return
1321 **  the size of the *un*truncated answer in case the supplied answer buffer
1322 **  it not big enough to accommodate the entire answer.
1323 */
1324 
1325 #ifndef MAXPACKET
1326 # define MAXPACKET 8192	/* max packet size used internally by BIND */
1327 #endif
1328 
1329 /*
1330 **  The resolver functions res_{send,query,querydomain} expect the
1331 **  answer buffer to be aligned, but some versions of gcc4 reverse
1332 **  25 years of history and no longer align char buffers on the
1333 **  stack, resulting in crashes on strict-alignment platforms.  Use
1334 **  this union when putting the buffer on the stack to force the
1335 **  alignment, then cast to (HEADER *) or (unsigned char *) as needed.
1336 */
1337 typedef union
1338 {
1339 	HEADER		qb1;
1340 	unsigned char	qb2[MAXPACKET];
1341 } querybuf;
1342 
1343 
1344 /* result values for getcanonname() etc */
1345 #define HOST_NOTFOUND	0
1346 #define HOST_OK		1
1347 #define HOST_SECURE	2
1348 
1349 /* flags for getmxrr() */
1350 #define DROPLOCALHOST	0x01
1351 #define TRYFALLBACK	0x02
1352 #define ISAD		0x04
1353 
1354 /* RFC7505: Null MX */
1355 #define NULLMX		(-2)
1356 
1357 /* functions */
1358 extern int	getcanonname __P((char *, int, bool, int *));
1359 extern int	getmxrr __P((char *, char **, unsigned short *, unsigned int, int *, int *, int));
1360 extern char	*hostsignature __P((MAILER *, char *, bool));
1361 extern int	getfallbackmxrr __P((char *));
1362 
1363 /*
1364 **  Mapping functions
1365 **
1366 **	These allow arbitrary mappings in the config file.  The idea
1367 **	(albeit not the implementation) comes from IDA sendmail.
1368 */
1369 
1370 #define MAPCLASS	struct _mapclass
1371 #define MAP		struct _map
1372 #define MAXMAPACTIONS	5		/* size of map_actions array */
1373 
1374 
1375 /*
1376 **  An actual map.
1377 */
1378 
1379 MAP
1380 {
1381 	MAPCLASS	*map_class;	/* the class of this map */
1382 	MAPCLASS	*map_orgclass;	/* the original class of this map */
1383 	char		*map_mname;	/* name of this map */
1384 	long		map_mflags;	/* flags, see below */
1385 	char		*map_file;	/* the (nominal) filename */
1386 	ARBPTR_T	map_db1;	/* the open database ptr */
1387 	ARBPTR_T	map_db2;	/* an "extra" database pointer */
1388 	char		*map_keycolnm;	/* key column name */
1389 	char		*map_valcolnm;	/* value column name */
1390 	unsigned char	map_keycolno;	/* key column number */
1391 	unsigned char	map_valcolno;	/* value column number */
1392 	char		map_coldelim;	/* column delimiter */
1393 	char		map_spacesub;	/* spacesub */
1394 	char		*map_app;	/* to append to successful matches */
1395 	char		*map_tapp;	/* to append to "tempfail" matches */
1396 	char		*map_domain;	/* the (nominal) NIS domain */
1397 	char		*map_rebuild;	/* program to run to do auto-rebuild */
1398 	time_t		map_mtime;	/* last database modification time */
1399 	time_t		map_timeout;	/* timeout for map accesses */
1400 	int		map_retry;	/* # of retries for map accesses */
1401 	pid_t		map_pid;	/* PID of process which opened map */
1402 	int		map_lockfd;	/* auxiliary lock file descriptor */
1403 	MAP		*map_stack[MAXMAPSTACK];   /* list for stacked maps */
1404 	short		map_return[MAXMAPACTIONS]; /* return bitmaps for stacked maps */
1405 };
1406 
1407 
1408 /* bit values for map_mflags */
1409 #define MF_VALID	0x00000001	/* this entry is valid */
1410 #define MF_INCLNULL	0x00000002	/* include null byte in key */
1411 #define MF_OPTIONAL	0x00000004	/* don't complain if map not found */
1412 #define MF_NOFOLDCASE	0x00000008	/* don't fold case in keys */
1413 #define MF_MATCHONLY	0x00000010	/* don't use the map value */
1414 #define MF_OPEN		0x00000020	/* this entry is open */
1415 #define MF_WRITABLE	0x00000040	/* open for writing */
1416 #define MF_ALIAS	0x00000080	/* this is an alias file */
1417 #define MF_TRY0NULL	0x00000100	/* try with no null byte */
1418 #define MF_TRY1NULL	0x00000200	/* try with the null byte */
1419 #define MF_LOCKED	0x00000400	/* this map is currently locked */
1420 #define MF_ALIASWAIT	0x00000800	/* alias map in aliaswait state */
1421 #define MF_IMPL_HASH	0x00001000	/* implicit: underlying hash database */
1422 #define MF_IMPL_NDBM	0x00002000	/* implicit: underlying NDBM database */
1423 #define MF_IMPL_CDB	0x00004000	/* implicit: underlying CDB database */
1424 #define MF_APPEND	0x00008000	/* append new entry on rebuild */
1425 #define MF_KEEPQUOTES	0x00010000	/* don't dequote key before lookup */
1426 #define MF_NODEFER	0x00020000	/* don't defer if map lookup fails */
1427 #define MF_REGEX_NOT	0x00040000	/* regular expression negation */
1428 #define MF_DEFER	0x00080000	/* don't lookup map in defer mode */
1429 #define MF_SINGLEMATCH	0x00100000	/* successful only if match one key */
1430 #define MF_SINGLEDN	0x00200000	/* only one match, but multi values */
1431 #define MF_FILECLASS	0x00400000	/* this is a file class map */
1432 #define MF_OPENBOGUS	0x00800000	/* open failed, don't call map_close */
1433 #define MF_CLOSING	0x01000000	/* map is being closed */
1434 #define MF_SECURE	0x02000000	/* DNSSEC result is "secure" */
1435 
1436 #define DYNOPENMAP(map) \
1437 	do		\
1438 	{		\
1439 		if (!bitset(MF_OPEN, (map)->map_mflags)) \
1440 		{	\
1441 			if (!openmap(map))	\
1442 				return NULL;	\
1443 		}	\
1444 	} while (0)
1445 
1446 
1447 /* indices for map_actions */
1448 #define MA_NOTFOUND	0		/* member map returned "not found" */
1449 #define MA_UNAVAIL	1		/* member map is not available */
1450 #define MA_TRYAGAIN	2		/* member map returns temp failure */
1451 
1452 /*
1453 **  The class of a map -- essentially the functions to call
1454 */
1455 
1456 MAPCLASS
1457 {
1458 	char	*map_cname;		/* name of this map class */
1459 	char	*map_ext;		/* extension for database file */
1460 	short	map_cflags;		/* flag bits, see below */
1461 	bool	(*map_parse)__P((MAP *, char *));
1462 					/* argument parsing function */
1463 	char	*(*map_lookup)__P((MAP *, char *, char **, int *));
1464 					/* lookup function */
1465 	void	(*map_store)__P((MAP *, char *, char *));
1466 					/* store function */
1467 	bool	(*map_open)__P((MAP *, int));
1468 					/* open function */
1469 	void	(*map_close)__P((MAP *));
1470 					/* close function */
1471 };
1472 
1473 /* bit values for map_cflags */
1474 #define MCF_ALIASOK	0x0001		/* can be used for aliases */
1475 /* #define MCF_ALIASONLY	0x0002		* usable only for aliases */
1476 #define MCF_REBUILDABLE	0x0004		/* can rebuild alias files */
1477 #define MCF_OPTFILE	0x0008		/* file name is optional */
1478 #define MCF_NOTPERSIST	0x0010		/* don't keep map open all the time */
1479 
1480 /* functions */
1481 extern void	closemaps __P((bool));
1482 extern bool	impl_map_open __P((MAP *, int));
1483 extern void	initmaps __P((void));
1484 extern MAP	*makemapentry __P((char *));
1485 extern void	maplocaluser __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
1486 extern char	*map_rewrite __P((MAP *, const char *, size_t, char **));
1487 #if NETINFO
1488 extern char	*ni_propval __P((char *, char *, char *, char *, int));
1489 #endif
1490 extern bool	openmap __P((MAP *));
1491 extern int	udbexpand __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
1492 #if USERDB
1493 extern void	_udbx_close __P((void));
1494 extern char	*udbsender __P((char *, SM_RPOOL_T *));
1495 #endif
1496 
1497 /*
1498 **  LDAP related items
1499 */
1500 #if LDAPMAP
1501 /* struct defining LDAP Auth Methods */
1502 struct lamvalues
1503 {
1504 	char	*lam_name;	/* name of LDAP auth method */
1505 	int	lam_code;	/* numeric code */
1506 };
1507 
1508 /* struct defining LDAP Alias Dereferencing */
1509 struct ladvalues
1510 {
1511 	char	*lad_name;	/* name of LDAP alias dereferencing method */
1512 	int	lad_code;	/* numeric code */
1513 };
1514 
1515 /* struct defining LDAP Search Scope */
1516 struct lssvalues
1517 {
1518 	char	*lss_name;	/* name of LDAP search scope */
1519 	int	lss_code;	/* numeric code */
1520 };
1521 
1522 /* functions */
1523 extern bool	ldapmap_parseargs __P((MAP *, char *));
1524 extern void	ldapmap_set_defaults __P((char *));
1525 #endif /* LDAPMAP */
1526 
1527 /*
1528 **  PH related items
1529 */
1530 
1531 #if PH_MAP
1532 
1533 # include <phclient.h>
1534 
1535 struct ph_map_struct
1536 {
1537 	char	*ph_servers;	 /* list of ph servers */
1538 	char	*ph_field_list;	 /* list of fields to search for match */
1539 	PH	*ph;		 /* PH server handle */
1540 	int	ph_fastclose;	 /* send "quit" command on close */
1541 	time_t	ph_timeout;	 /* timeout interval */
1542 };
1543 typedef struct ph_map_struct	PH_MAP_STRUCT;
1544 
1545 #endif /* PH_MAP */
1546 
1547 /*
1548 **  Regular UNIX sockaddrs are too small to handle ISO addresses, so
1549 **  we are forced to declare a supertype here.
1550 */
1551 
1552 #if NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25
1553 union bigsockaddr
1554 {
1555 	struct sockaddr		sa;	/* general version */
1556 # if NETUNIX
1557 	struct sockaddr_un	sunix;	/* UNIX family */
1558 # endif
1559 # if NETINET
1560 	struct sockaddr_in	sin;	/* INET family */
1561 # endif
1562 # if NETINET6
1563 	struct sockaddr_in6	sin6;	/* INET/IPv6 */
1564 # endif
1565 # if NETISO
1566 	struct sockaddr_iso	siso;	/* ISO family */
1567 # endif
1568 # if NETNS
1569 	struct sockaddr_ns	sns;	/* XNS family */
1570 # endif
1571 # if NETX25
1572 	struct sockaddr_x25	sx25;	/* X.25 family */
1573 # endif
1574 };
1575 
1576 # define SOCKADDR	union bigsockaddr
1577 
1578 /* functions */
1579 extern char	*anynet_ntoa __P((SOCKADDR *));
1580 # if NETINET6
1581 extern char	*anynet_ntop __P((struct in6_addr *, char *, size_t));
1582 extern int	anynet_pton __P((int, const char *, void *));
1583 # endif
1584 extern char	*hostnamebyanyaddr __P((SOCKADDR *));
1585 extern char	*validate_connection __P((SOCKADDR *, char *, ENVELOPE *));
1586 # if SASL >= 20000
1587 extern bool	iptostring __P((SOCKADDR *, SOCKADDR_LEN_T, char *, unsigned));
1588 # endif
1589 
1590 #endif /* NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25 */
1591 
1592 /*
1593 **  Process List (proclist)
1594 */
1595 
1596 #define NO_PID		((pid_t) 0)
1597 #ifndef PROC_LIST_SEG
1598 # define PROC_LIST_SEG	32		/* number of pids to alloc at a time */
1599 #endif
1600 
1601 /* process types */
1602 #define PROC_NONE		0
1603 #define PROC_DAEMON		1
1604 #define PROC_DAEMON_CHILD	2
1605 #define PROC_QUEUE		3
1606 #define PROC_QUEUE_CHILD	3
1607 #define PROC_CONTROL		4
1608 #define PROC_CONTROL_CHILD	5
1609 
1610 /* functions */
1611 extern void	proc_list_add __P((pid_t, char *, int, int, int, SOCKADDR *));
1612 extern void	proc_list_clear __P((void));
1613 extern void	proc_list_display __P((SM_FILE_T *, char *));
1614 extern void	proc_list_drop __P((pid_t, int, int *));
1615 extern void	proc_list_probe __P((void));
1616 extern void	proc_list_set __P((pid_t, char *));
1617 extern void	proc_list_signal __P((int, int));
1618 
1619 /*
1620 **  Symbol table definitions
1621 */
1622 
1623 struct symtab
1624 {
1625 	char		*s_name;	/* name to be entered */
1626 	short		s_symtype;	/* general type (see below) */
1627 	struct symtab	*s_next;	/* pointer to next in chain */
1628 	union
1629 	{
1630 		BITMAP256	sv_class;	/* bit-map of word classes */
1631 		MAILER		*sv_mailer;	/* pointer to mailer */
1632 		char		*sv_alias;	/* alias */
1633 		MAPCLASS	sv_mapclass;	/* mapping function class */
1634 		MAP		sv_map;		/* mapping function */
1635 		HOSTSIG_T	sv_hostsig;	/* host signature */
1636 		MCI		sv_mci;		/* mailer connection info */
1637 		NAMECANON	sv_namecanon;	/* canonical name cache */
1638 		int		sv_macro;	/* macro name => id mapping */
1639 		int		sv_ruleset;	/* ruleset index */
1640 		struct hdrinfo	sv_header;	/* header metainfo */
1641 		char		*sv_service[MAXMAPSTACK]; /* service switch */
1642 #if LDAPMAP
1643 		MAP		*sv_lmap;	/* Maps for LDAP connection */
1644 #endif
1645 #if SOCKETMAP
1646 		MAP		*sv_socketmap;	/* Maps for SOCKET connection */
1647 #endif
1648 #if MILTER
1649 		struct milter	*sv_milter;	/* milter filter name */
1650 #endif
1651 		QUEUEGRP	*sv_queue;	/* pointer to queue */
1652 #if DANE
1653 		dane_tlsa_P	 sv_tlsa;	/* pointer to TLSA RRs */
1654 #endif
1655 	}	s_value;
1656 };
1657 
1658 typedef struct symtab	STAB;
1659 
1660 /* symbol types */
1661 #define ST_UNDEF	0	/* undefined type */
1662 #define ST_CLASS	1	/* class map */
1663 /* #define ST_unused	2	UNUSED */
1664 #define ST_MAILER	3	/* a mailer header */
1665 #define ST_ALIAS	4	/* an alias */
1666 #define ST_MAPCLASS	5	/* mapping function class */
1667 #define ST_MAP		6	/* mapping function */
1668 #define ST_HOSTSIG	7	/* host signature */
1669 #define ST_NAMECANON	8	/* cached canonical name */
1670 #define ST_MACRO	9	/* macro name to id mapping */
1671 #define ST_RULESET	10	/* ruleset index */
1672 #define ST_SERVICE	11	/* service switch entry */
1673 #define ST_HEADER	12	/* special header flags */
1674 #if LDAPMAP
1675 # define ST_LMAP	13	/* List head of maps for LDAP connection */
1676 #endif
1677 #if MILTER
1678 # define ST_MILTER	14	/* milter filter */
1679 #endif
1680 #define ST_QUEUE	15	/* a queue entry */
1681 
1682 #if SOCKETMAP
1683 # define ST_SOCKETMAP	16	/* List head of maps for SOCKET connection */
1684 #endif
1685 
1686 #if DANE
1687 # define ST_TLSA_RR	17	/* cached TLSA RRs */
1688 #endif
1689 
1690 /* This entry must be last */
1691 #define ST_MCI		18	/* mailer connection info (offset) */
1692 
1693 #define s_class		s_value.sv_class
1694 #define s_mailer	s_value.sv_mailer
1695 #define s_alias		s_value.sv_alias
1696 #define s_mci		s_value.sv_mci
1697 #define s_mapclass	s_value.sv_mapclass
1698 #define s_hostsig	s_value.sv_hostsig
1699 #define s_map		s_value.sv_map
1700 #define s_namecanon	s_value.sv_namecanon
1701 #define s_macro		s_value.sv_macro
1702 #define s_ruleset	s_value.sv_ruleset
1703 #define s_service	s_value.sv_service
1704 #define s_header	s_value.sv_header
1705 #if LDAPMAP
1706 # define s_lmap		s_value.sv_lmap
1707 #endif
1708 #if SOCKETMAP
1709 # define s_socketmap	s_value.sv_socketmap
1710 #endif
1711 #if MILTER
1712 # define s_milter	s_value.sv_milter
1713 #endif
1714 #define s_quegrp	s_value.sv_queue
1715 #if DANE
1716 # define s_tlsa		s_value.sv_tlsa
1717 #endif
1718 
1719 /* opcodes to stab */
1720 #define ST_FIND		0	/* find entry */
1721 #define ST_ENTER	1	/* enter if not there */
1722 
1723 /* functions */
1724 extern STAB	*stab __P((char *, int, int));
1725 extern void	stabapply __P((void (*)(STAB *, int), int));
1726 
1727 /*
1728 **  Operation, send, error, and MIME modes
1729 **
1730 **	The operation mode describes the basic operation of sendmail.
1731 **	This can be set from the command line, and is "send mail" by
1732 **	default.
1733 **
1734 **	The send mode tells how to send mail.  It can be set in the
1735 **	configuration file.  Its setting determines how quickly the
1736 **	mail will be delivered versus the load on your system.  If the
1737 **	-v (verbose) flag is given, it will be forced to SM_DELIVER
1738 **	mode.
1739 **
1740 **	The error mode tells how to return errors.
1741 */
1742 
1743 #define MD_DELIVER	'm'		/* be a mail sender */
1744 #define MD_SMTP		's'		/* run SMTP on standard input */
1745 #define MD_ARPAFTP	'a'		/* obsolete ARPANET mode (Grey Book) */
1746 #define MD_DAEMON	'd'		/* run as a daemon */
1747 #define MD_FGDAEMON	'D'		/* run daemon in foreground */
1748 #define MD_LOCAL	'l'		/* like daemon, but localhost only */
1749 #define MD_VERIFY	'v'		/* verify: don't collect or deliver */
1750 #define MD_TEST		't'		/* test mode: resolve addrs only */
1751 #define MD_INITALIAS	'i'		/* initialize alias database */
1752 #define MD_PRINT	'p'		/* print the queue */
1753 #define MD_PRINTNQE	'P'		/* print number of entries in queue */
1754 #define MD_FREEZE	'z'		/* freeze the configuration file */
1755 #define MD_HOSTSTAT	'h'		/* print persistent host stat info */
1756 #define MD_PURGESTAT	'H'		/* purge persistent host stat info */
1757 #define MD_QUEUERUN	'q'		/* queue run */
1758 #define MD_CHECKCONFIG	'C'		/* check configuration file */
1759 
1760 #if _FFR_LOCAL_DAEMON
1761 EXTERN bool	LocalDaemon;
1762 # if NETINET6
1763 EXTERN bool	V6LoopbackAddrFound;	/* found an IPv6 loopback address */
1764 #  define SETV6LOOPBACKADDRFOUND(sa)	\
1765 	do	\
1766 	{	\
1767 		if (isloopback(sa))	\
1768 			V6LoopbackAddrFound = true;	\
1769 	} while (0)
1770 # endif /* NETINET6 */
1771 #else /* _FFR_LOCAL_DAEMON */
1772 # define LocalDaemon	false
1773 # define V6LoopbackAddrFound	false
1774 # define SETV6LOOPBACKADDRFOUND(sa)
1775 #endif /* _FFR_LOCAL_DAEMON */
1776 
1777 /* Note: see also include/sendmail/pathnames.h: GET_CLIENT_CF */
1778 
1779 /* values for e_sendmode -- send modes */
1780 #define SM_DELIVER	'i'		/* interactive delivery */
1781 #if _FFR_PROXY
1782 #define SM_PROXY_REQ	's'		/* synchronous mode requested */
1783 #define SM_PROXY	'S'		/* synchronous mode activated */
1784 #endif
1785 #define SM_FORK		'b'		/* deliver in background */
1786 #if _FFR_DM_ONE
1787 #define SM_DM_ONE	'o' /* deliver first TA in background, then queue */
1788 #endif
1789 #define SM_QUEUE	'q'		/* queue, don't deliver */
1790 #define SM_DEFER	'd'		/* defer map lookups as well as queue */
1791 #define SM_VERIFY	'v'		/* verify only (used internally) */
1792 #define DM_NOTSET	(-1)	/* DeliveryMode (per daemon) option not set */
1793 #if _FFR_PROXY
1794 # define SM_IS_INTERACTIVE(m)	((m) == SM_DELIVER || (m) == SM_PROXY_REQ || (m) == SM_PROXY)
1795 #else
1796 # define SM_IS_INTERACTIVE(m)	((m) == SM_DELIVER)
1797 #endif
1798 
1799 #define WILL_BE_QUEUED(m)	((m) == SM_QUEUE || (m) == SM_DEFER)
1800 
1801 /* used only as a parameter to sendall */
1802 #define SM_DEFAULT	'\0'		/* unspecified, use SendMode */
1803 
1804 /* functions */
1805 extern void	set_delivery_mode __P((int, ENVELOPE *));
1806 
1807 /* values for e_errormode -- error handling modes */
1808 #define EM_PRINT	'p'		/* print errors */
1809 #define EM_MAIL		'm'		/* mail back errors */
1810 #define EM_WRITE	'w'		/* write back errors */
1811 #define EM_BERKNET	'e'		/* special berknet processing */
1812 #define EM_QUIET	'q'		/* don't print messages (stat only) */
1813 
1814 
1815 /* bit values for MimeMode */
1816 #define MM_CVTMIME	0x0001		/* convert 8 to 7 bit MIME */
1817 #define MM_PASS8BIT	0x0002		/* just send 8 bit data blind */
1818 #define MM_MIME8BIT	0x0004		/* convert 8-bit data to MIME */
1819 
1820 
1821 /* how to handle messages without any recipient addresses */
1822 #define NRA_NO_ACTION		0	/* just leave it as is */
1823 #define NRA_ADD_TO		1	/* add To: header */
1824 #define NRA_ADD_APPARENTLY_TO	2	/* add Apparently-To: header */
1825 #define NRA_ADD_BCC		3	/* add empty Bcc: header */
1826 #define NRA_ADD_TO_UNDISCLOSED	4	/* add To: undisclosed:; header */
1827 
1828 
1829 /* flags to putxline */
1830 #define PXLF_NOTHINGSPECIAL	0	/* no special mapping */
1831 #define PXLF_MAPFROM		0x0001	/* map From_ to >From_ */
1832 #define PXLF_STRIP8BIT		0x0002	/* strip 8th bit */
1833 #define PXLF_HEADER		0x0004	/* map newlines in headers */
1834 #define PXLF_NOADDEOL		0x0008	/* if EOL not present, don't add one */
1835 #define PXLF_STRIPMQUOTE	0x0010	/* strip METAQUOTEs */
1836 
1837 /*
1838 **  Privacy flags
1839 **	These are bit values for the PrivacyFlags word.
1840 */
1841 
1842 #define PRIV_PUBLIC		0		/* what have I got to hide? */
1843 #define PRIV_NEEDMAILHELO	0x00000001	/* insist on HELO for MAIL */
1844 #define PRIV_NEEDEXPNHELO	0x00000002	/* insist on HELO for EXPN */
1845 #define PRIV_NEEDVRFYHELO	0x00000004	/* insist on HELO for VRFY */
1846 #define PRIV_NOEXPN		0x00000008	/* disallow EXPN command */
1847 #define PRIV_NOVRFY		0x00000010	/* disallow VRFY command */
1848 #define PRIV_AUTHWARNINGS	0x00000020	/* flag possible auth probs */
1849 #define PRIV_NOVERB		0x00000040	/* disallow VERB command */
1850 #define PRIV_RESTRICTMAILQ	0x00010000	/* restrict mailq command */
1851 #define PRIV_RESTRICTQRUN	0x00020000	/* restrict queue run */
1852 #define PRIV_RESTRICTEXPAND	0x00040000	/* restrict alias/forward expansion */
1853 #define PRIV_NOETRN		0x00080000	/* disallow ETRN command */
1854 #define PRIV_NOBODYRETN		0x00100000	/* do not return bodies on bounces */
1855 #define PRIV_NORECEIPTS		0x00200000	/* disallow return receipts */
1856 #define PRIV_NOACTUALRECIPIENT	0x00400000 /* no X-Actual-Recipient in DSNs */
1857 
1858 /* don't give no info, anyway, anyhow (in the main SMTP transaction) */
1859 #define PRIV_GOAWAY		0x0000ffff
1860 
1861 /* struct defining such things */
1862 struct prival
1863 {
1864 	char		*pv_name;	/* name of privacy flag */
1865 	unsigned long	pv_flag;	/* numeric level */
1866 };
1867 
1868 EXTERN unsigned long	PrivacyFlags;	/* privacy flags */
1869 
1870 
1871 /*
1872 **  Flags passed to remotename, parseaddr, allocaddr, and buildaddr.
1873 */
1874 
1875 #define RF_SENDERADDR		0x001	/* this is a sender address */
1876 #define RF_HEADERADDR		0x002	/* this is a header address */
1877 #define RF_CANONICAL		0x004	/* strip comment information */
1878 #define RF_ADDDOMAIN		0x008	/* OK to do domain extension */
1879 #define RF_COPYPARSE		0x010	/* copy parsed user & host */
1880 #define RF_COPYPADDR		0x020	/* copy print address */
1881 #define RF_COPYALL		(RF_COPYPARSE|RF_COPYPADDR)
1882 #define RF_COPYNONE		0
1883 #define RF_RM_ADDR		0x040	/* address to be removed */
1884 
1885 /*
1886 **  Flags passed to rscheck
1887 */
1888 
1889 #define RSF_RMCOMM		0x0001	/* strip comments */
1890 #define RSF_UNSTRUCTURED	0x0002	/* unstructured, ignore syntax errors */
1891 #define RSF_COUNT		0x0004	/* count rejections (statistics)? */
1892 #define RSF_ADDR		0x0008	/* reassemble address */
1893 #define RSF_STRING		0x0010	/* reassemble address as string */
1894 
1895 /*
1896 **  Flags passed to mime8to7 and putheader.
1897 */
1898 
1899 #define M87F_OUTER		0	/* outer context */
1900 #define M87F_NO8BIT		0x0001	/* can't have 8-bit in this section */
1901 #define M87F_DIGEST		0x0002	/* processing multipart/digest */
1902 #define M87F_NO8TO7		0x0004	/* don't do 8->7 bit conversions */
1903 
1904 /* functions */
1905 extern bool	mime7to8 __P((MCI *, HDR *, ENVELOPE *));
1906 extern int	mime8to7 __P((MCI *, HDR *, ENVELOPE *, char **, int, int));
1907 
1908 /*
1909 **  Flags passed to returntosender.
1910 */
1911 
1912 #define RTSF_NO_BODY		0	/* send headers only */
1913 #define RTSF_SEND_BODY		0x0001	/* include body of message in return */
1914 #define RTSF_PM_BOUNCE		0x0002	/* this is a postmaster bounce */
1915 
1916 /* functions */
1917 extern int	returntosender __P((char *, ADDRESS *, int, ENVELOPE *));
1918 
1919 /*
1920 **  Mail Filters (milter)
1921 */
1922 
1923 /*
1924 **  32-bit type used by milter
1925 **  (needed by libmilter even if MILTER isn't defined)
1926 */
1927 
1928 typedef SM_INT32	mi_int32;
1929 
1930 #if MILTER
1931 # define SMFTO_WRITE	0		/* Timeout for sending information */
1932 # define SMFTO_READ	1		/* Timeout waiting for a response */
1933 # define SMFTO_EOM	2		/* Timeout for ACK/NAK to EOM */
1934 # define SMFTO_CONNECT	3		/* Timeout for connect() */
1935 
1936 # define SMFTO_NUM_TO	4		/* Total number of timeouts */
1937 
1938 struct milter
1939 {
1940 	char		*mf_name;	/* filter name */
1941 	BITMAP256	mf_flags;	/* MTA flags */
1942 	mi_int32	mf_fvers;	/* filter version */
1943 	mi_int32	mf_fflags;	/* filter flags */
1944 	mi_int32	mf_pflags;	/* protocol flags */
1945 	char		*mf_conn;	/* connection info */
1946 	int		mf_sock;	/* connected socket */
1947 	char		mf_state;	/* state of filter */
1948 	char		mf_lflags;	/* "local" flags */
1949 	int		mf_idx;		/* milter number (index) */
1950 	time_t		mf_timeout[SMFTO_NUM_TO]; /* timeouts */
1951 # if _FFR_MILTER_CHECK
1952 	/* for testing only */
1953 	mi_int32	mf_mta_prot_version;
1954 	mi_int32	mf_mta_prot_flags;
1955 	mi_int32	mf_mta_actions;
1956 # endif /* _FFR_MILTER_CHECK */
1957 };
1958 
1959 # define MI_LFL_NONE	0x00000000
1960 # define MI_LFLAGS_SYM(st) (1 << (st))	/* has its own symlist for stage st */
1961 
1962 struct milters
1963 {
1964 	mi_int32	mis_flags;	/* filter flags */
1965 };
1966 typedef struct milters	milters_T;
1967 
1968 # define MIS_FL_NONE	0x00000000	/* no requirements... */
1969 # define MIS_FL_DEL_RCPT	0x00000001	/* can delete rcpt */
1970 # define MIS_FL_REJ_RCPT	0x00000002	/* can reject rcpt */
1971 
1972 
1973 /* MTA flags */
1974 # define SMF_REJECT		'R'	/* Reject connection on filter fail */
1975 # define SMF_TEMPFAIL		'T'	/* tempfail connection on failure */
1976 # define SMF_TEMPDROP		'4'	/* 421 connection on failure */
1977 
1978 EXTERN struct milter	*InputFilters[MAXFILTERS];
1979 EXTERN char		*InputFilterList;
1980 EXTERN int		MilterLogLevel;
1981 
1982 /* functions */
1983 extern void	setup_daemon_milters __P((void));
1984 #endif /* MILTER */
1985 
1986 /*
1987 **  Vendor codes
1988 **
1989 **	Vendors can customize sendmail to add special behaviour,
1990 **	generally for back compatibility.  Ideally, this should
1991 **	be set up in the .cf file using the "V" command.  However,
1992 **	it's quite reasonable for some vendors to want the default
1993 **	be their old version; this can be set using
1994 **		-DVENDOR_DEFAULT=VENDOR_xxx
1995 **	in the Makefile.
1996 **
1997 **	Vendors should apply to sendmail-YYYY@support.sendmail.org
1998 **	(replace YYYY with the current year)
1999 **	for unique vendor codes.
2000 */
2001 
2002 #define VENDOR_BERKELEY	1	/* Berkeley-native configuration file */
2003 #define VENDOR_SUN	2	/* Sun-native configuration file */
2004 #define VENDOR_HP	3	/* Hewlett-Packard specific config syntax */
2005 #define VENDOR_IBM	4	/* IBM specific config syntax */
2006 #define VENDOR_SENDMAIL	5	/* Proofpoint, Inc. specific config syntax */
2007 #define VENDOR_DEC	6	/* Compaq, DEC, Digital */
2008 
2009 /* prototypes for vendor-specific hook routines */
2010 extern void	vendor_daemon_setup __P((ENVELOPE *));
2011 extern void	vendor_set_uid __P((UID_T));
2012 
2013 
2014 /*
2015 **  Terminal escape codes.
2016 **
2017 **	To make debugging output clearer.
2018 */
2019 
2020 struct termescape
2021 {
2022 	char	*te_rv_on;	/* turn reverse-video on */
2023 	char	*te_under_on;	/* turn underlining on */
2024 	char	*te_normal;	/* revert to normal output */
2025 };
2026 
2027 /*
2028 **  Additional definitions
2029 */
2030 
2031 /*
2032 **  d_flags, see daemon.c
2033 **  general rule: lower case: required, upper case: No
2034 */
2035 
2036 #define D_AUTHREQ	'a'	/* authentication required */
2037 #define D_BINDIF	'b'	/* use if_addr for outgoing connection */
2038 #define D_CANONREQ	'c'	/* canonification required (cf) */
2039 #define D_IFNHELO	'h'	/* use if name for HELO */
2040 #define D_FQMAIL	'f'	/* fq sender address required (cf) */
2041 #if _FFR_EAI
2042 #define D_EAI		'I'	/* EAI supported */
2043 #endif
2044 #define D_FQRCPT	'r'	/* fq recipient address required (cf) */
2045 #define D_SMTPS		's'	/* SMTP over SSL (smtps) */
2046 #define D_UNQUALOK	'u'	/* unqualified address is ok (cf) */
2047 #define D_NOAUTH	'A'	/* no AUTH */
2048 #define D_NOCANON	'C'	/* no canonification (cf) */
2049 #define D_NOETRN	'E'	/* no ETRN (MSA) */
2050 #define D_NOTLS		'S'	/* don't use STARTTLS */
2051 #define D_ETRNONLY	((char)0x01)	/* allow only ETRN (disk low) */
2052 #define D_OPTIONAL	'O'	/* optional socket */
2053 #define D_DISABLE	((char)0x02)	/* optional socket disabled */
2054 #define D_ISSET		((char)0x03)	/* this client struct is set */
2055 #if _FFR_XCNCT
2056 #define D_XCNCT	((char)0x04)	/* X-Connect was used */
2057 #define D_XCNCT_M	((char)0x05)	/* X-Connect was used + "forged" */
2058 #endif
2059 
2060 
2061 /*
2062 **  Queue related items
2063 */
2064 
2065 /* queue file names */
2066 #define ANYQFL_LETTER '?'
2067 #define QUARQF_LETTER 'h'
2068 #define DATAFL_LETTER 'd'
2069 #define XSCRPT_LETTER 'x'
2070 #define NORMQF_LETTER 'q'
2071 #define NEWQFL_LETTER 't'
2072 
2073 # define TEMPQF_LETTER 'T'
2074 # define LOSEQF_LETTER 'Q'
2075 
2076 /* queue sort order */
2077 #define QSO_BYPRIORITY	0		/* sort by message priority */
2078 #define QSO_BYHOST	1		/* sort by first host name */
2079 #define QSO_BYTIME	2		/* sort by submission time */
2080 #define QSO_BYFILENAME	3		/* sort by file name only */
2081 #define QSO_RANDOM	4		/* sort in random order */
2082 #define QSO_BYMODTIME	5		/* sort by modification time */
2083 #define QSO_NONE	6		/* do not sort */
2084 #if _FFR_RHS
2085 # define QSO_BYSHUFFLE	7		/* sort by shuffled host name */
2086 #endif
2087 
2088 #define NOQGRP	(-1)		/* no queue group (yet) */
2089 #define ENVQGRP	(-2)		/* use queue group of envelope */
2090 #define NOAQGRP	(-3)		/* no queue group in addr (yet) */
2091 #define ISVALIDQGRP(x)	((x) >= 0)	/* valid queue group? */
2092 #define NOQDIR	(-1)		/* no queue directory (yet) */
2093 #define ENVQDIR	(-2)		/* use queue directory of envelope */
2094 #define NOAQDIR	(-3)		/* no queue directory in addr (yet) */
2095 #define ISVALIDQDIR(x)	((x) >= 0)	/* valid queue directory? */
2096 #define RS_QUEUEGROUP	"queuegroup"	/* ruleset for queue group selection */
2097 
2098 #define NOW	((time_t) (-1))		/* queue return: now */
2099 
2100 /* SuperSafe values */
2101 #define SAFE_NO			0	/* no fsync(): don't use... */
2102 #define SAFE_INTERACTIVE	1	/* limit fsync() in -odi */
2103 #define SAFE_REALLY		2	/* always fsync() */
2104 #define SAFE_REALLY_POSTMILTER	3	/* fsync() if milter says OK */
2105 
2106 /* QueueMode bits */
2107 #define QM_NORMAL		' '
2108 #define QM_QUARANTINE		'Q'
2109 #define QM_LOST			'L'
2110 
2111 /* Queue Run Limitations */
2112 struct queue_char
2113 {
2114 	char			*queue_match;	/* string to match */
2115 	bool			queue_negate;	/* or not match, if set */
2116 	struct queue_char	*queue_next;
2117 };
2118 
2119 /* run_work_group() flags */
2120 #define RWG_NONE		0x0000
2121 #define RWG_FORK		0x0001
2122 #define RWG_VERBOSE		0x0002
2123 #define RWG_PERSISTENT		0x0004
2124 #define RWG_FORCE		0x0008
2125 #define RWG_RUNALL		0x0010
2126 
2127 typedef struct queue_char	QUEUE_CHAR;
2128 
2129 EXTERN int	volatile CurRunners;	/* current number of runner children */
2130 EXTERN int	MaxQueueRun;	/* maximum number of jobs in one queue run */
2131 EXTERN int	MaxQueueChildren;	/* max # of forked queue children */
2132 EXTERN int	MaxRunnersPerQueue;	/* max # proc's active in queue group */
2133 EXTERN int	NiceQueueRun;	/* nice queue runs to this value */
2134 EXTERN int	NumQueue;	/* number of queue groups */
2135 EXTERN int	QueueFileMode;	/* mode on files in mail queue */
2136 EXTERN int	QueueMode;	/* which queue items to act upon */
2137 EXTERN int	QueueSortOrder;	/* queue sorting order algorithm */
2138 EXTERN time_t	MinQueueAge;	/* min delivery interval */
2139 EXTERN time_t	MaxQueueAge;	/* max delivery interval */
2140 EXTERN time_t	QueueIntvl;	/* intervals between running the queue */
2141 EXTERN char	*QueueDir;	/* location of queue directory */
2142 EXTERN QUEUE_CHAR	*QueueLimitId;		/* limit queue run to id */
2143 EXTERN QUEUE_CHAR	*QueueLimitQuarantine;	/* limit queue run to quarantine reason */
2144 EXTERN QUEUE_CHAR	*QueueLimitRecipient;	/* limit queue run to rcpt */
2145 EXTERN QUEUE_CHAR	*QueueLimitSender;	/* limit queue run to sender */
2146 EXTERN QUEUEGRP	*Queue[MAXQUEUEGROUPS + 1];	/* queue groups */
2147 #if _FFR_BOUNCE_QUEUE
2148 EXTERN int	BounceQueue;
2149 #endif
2150 
2151 /* functions */
2152 extern void	assign_queueid __P((ENVELOPE *));
2153 extern ADDRESS	*copyqueue __P((ADDRESS *, SM_RPOOL_T *));
2154 extern void	cleanup_queues __P((void));
2155 extern bool	doqueuerun __P((void));
2156 extern void	initsys __P((ENVELOPE *));
2157 extern void	loseqfile __P((ENVELOPE *, char *));
2158 extern int	name2qid __P((char *));
2159 extern char	*qid_printname __P((ENVELOPE *));
2160 extern char	*qid_printqueue __P((int, int));
2161 extern void	quarantine_queue __P((char *, int));
2162 extern char	*queuename __P((ENVELOPE *, int));
2163 extern void	queueup __P((ENVELOPE *, bool, bool));
2164 extern bool	runqueue __P((bool, bool, bool, bool));
2165 extern bool	run_work_group __P((int, int));
2166 extern void	set_def_queueval __P((QUEUEGRP *, bool));
2167 extern void	setup_queues __P((bool));
2168 extern bool	setnewqueue __P((ENVELOPE *));
2169 extern bool	shouldqueue __P((long, time_t));
2170 extern void	sync_queue_time __P((void));
2171 extern void	init_qid_alg __P((void));
2172 extern int	print_single_queue __P((int, int));
2173 #if REQUIRES_DIR_FSYNC
2174 # define SYNC_DIR(path, panic) sync_dir(path, panic)
2175 extern void	sync_dir __P((char *, bool));
2176 #else
2177 # define SYNC_DIR(path, panic) ((void) 0)
2178 #endif
2179 
2180 /*
2181 **  Timeouts
2182 **
2183 **	Indicated values are the MINIMUM per RFC 1123 section 5.3.2.
2184 */
2185 
2186 EXTERN struct
2187 {
2188 			/* RFC 1123-specified timeouts [minimum value] */
2189 	time_t	to_initial;	/* initial greeting timeout [5m] */
2190 	time_t	to_mail;	/* MAIL command [5m] */
2191 	time_t	to_rcpt;	/* RCPT command [5m] */
2192 	time_t	to_datainit;	/* DATA initiation [2m] */
2193 	time_t	to_datablock;	/* DATA block [3m] */
2194 	time_t	to_datafinal;	/* DATA completion [10m] */
2195 	time_t	to_nextcommand;	/* next command [5m] */
2196 			/* following timeouts are not mentioned in RFC 1123 */
2197 	time_t	to_iconnect;	/* initial connection timeout (first try) */
2198 	time_t	to_connect;	/* initial connection timeout (later tries) */
2199 	time_t	to_aconnect;	/* all connections timeout (MX and A records) */
2200 	time_t	to_rset;	/* RSET command */
2201 	time_t	to_helo;	/* HELO command */
2202 	time_t	to_quit;	/* QUIT command */
2203 	time_t	to_miscshort;	/* misc short commands (NOOP, VERB, etc) */
2204 	time_t	to_ident;	/* IDENT protocol requests */
2205 	time_t	to_fileopen;	/* opening :include: and .forward files */
2206 	time_t	to_control;	/* process a control socket command */
2207 	time_t	to_lhlo;	/* LMTP: LHLO command */
2208 #if SASL
2209 	time_t	to_auth;	/* AUTH dialogue [10m] */
2210 #endif
2211 #if STARTTLS
2212 	time_t	to_starttls;	/* STARTTLS dialogue [10m] */
2213 #endif
2214 			/* following are per message */
2215 	time_t	to_q_return[MAXTOCLASS];	/* queue return timeouts */
2216 	time_t	to_q_warning[MAXTOCLASS];	/* queue warning timeouts */
2217 	time_t	res_retrans[MAXRESTOTYPES];	/* resolver retransmit */
2218 	int	res_retry[MAXRESTOTYPES];	/* resolver retry */
2219 } TimeOuts;
2220 
2221 /* timeout classes for return and warning timeouts */
2222 #define TOC_NORMAL	0	/* normal delivery */
2223 #define TOC_URGENT	1	/* urgent delivery */
2224 #define TOC_NONURGENT	2	/* non-urgent delivery */
2225 #define TOC_DSN		3	/* DSN delivery */
2226 
2227 /* resolver timeout specifiers */
2228 #define RES_TO_FIRST	0	/* first attempt */
2229 #define RES_TO_NORMAL	1	/* subsequent attempts */
2230 #define RES_TO_DEFAULT	2	/* default value */
2231 
2232 /* functions */
2233 extern void	inittimeouts __P((char *, bool));
2234 
2235 /*
2236 **  Interface probing
2237 */
2238 
2239 #define DPI_PROBENONE		0	/* Don't probe any interfaces */
2240 #define DPI_PROBEALL		1	/* Probe all interfaces */
2241 #define DPI_SKIPLOOPBACK	2	/* Don't probe loopback interfaces */
2242 
2243 /*
2244 **  Trace information
2245 */
2246 
2247 /* macros for debugging flags */
2248 #if NOT_SENDMAIL
2249 # define tTd(flag, level)	(tTdvect[flag] >= (unsigned char)level)
2250 #else
2251 # define tTd(flag, level)	(tTdvect[flag] >= (unsigned char)level && !IntSig)
2252 #endif
2253 #define tTdlevel(flag)		(tTdvect[flag])
2254 
2255 /* variables */
2256 extern unsigned char	tTdvect[100];	/* trace vector */
2257 
2258 /*
2259 **  Miscellaneous information.
2260 */
2261 
2262 /*
2263 **  The "no queue id" queue id for sm_syslog
2264 */
2265 
2266 #define NOQID		""
2267 
2268 #define CURHOSTNAME	(CurHostName == NULL ? "local" : CurHostName)
2269 
2270 /*
2271 **  Some in-line functions
2272 */
2273 
2274 /* set exit status */
2275 #define setstat(s)	\
2276 	do		\
2277 	{		\
2278 		if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \
2279 			ExitStat = s; \
2280 	} while (0)
2281 
2282 
2283 #define STRUCTCOPY(s, d)	d = s
2284 
2285 /*
2286 **  Update a permanent string variable with a new value.
2287 **  The old value is freed, the new value is strdup'ed.
2288 **
2289 **  We use sm_pstrdup_x to duplicate the string because it raises
2290 **  an exception on error, and because it allocates "permanent storage"
2291 **  which is not expected to be freed before process exit.
2292 **  The latter is important for memory leak analysis.
2293 **
2294 **  If an exception occurs while strdup'ing the new value,
2295 **  then the variable remains set to the old value.
2296 **  That's why the strdup must occur before we free the old value.
2297 */
2298 #define PSTRSET(var, val) \
2299 	do \
2300 	{ \
2301 		char *_newval = sm_pstrdup_x(val); \
2302 		if (var != NULL) \
2303 			sm_free(var); \
2304 		var = _newval; \
2305 	} while (0)
2306 
2307 #define _CHECK_RESTART \
2308 	do \
2309 	{ \
2310 		if (ShutdownRequest != NULL) \
2311 			shutdown_daemon(); \
2312 		else if (RestartRequest != NULL) \
2313 			restart_daemon(); \
2314 		else if (RestartWorkGroup) \
2315 			restart_marked_work_groups(); \
2316 	} while (0)
2317 
2318 # define CHECK_RESTART _CHECK_RESTART
2319 
2320 #define CHK_CUR_RUNNERS(fct, idx, count)	\
2321 	do	\
2322 	{	\
2323 		if (CurRunners < 0)	\
2324 		{	\
2325 			if (LogLevel > 3)	\
2326 				sm_syslog(LOG_ERR, NOQID,	\
2327 					"%s: CurRunners=%d, i=%d, count=%d, status=should not happen",	\
2328 					fct, CurRunners, idx, count);	\
2329 			CurRunners = 0;	\
2330 		}	\
2331 	} while (0)
2332 
2333 /* reply types (text in SmtpMsgBuffer) */
2334 #define XS_DEFAULT	0	/* other commands, e.g., RSET */
2335 #define XS_STARTTLS	1
2336 #define XS_AUTH		2
2337 #define XS_GREET	3
2338 #define XS_EHLO		4
2339 #define XS_MAIL		5
2340 #define XS_RCPT		6
2341 #define XS_DATA		7
2342 #define XS_EOM		8
2343 #define XS_DATA2	9	/* LMTP */
2344 #define XS_QUIT		10
2345 
2346 /*
2347 **  Global variables.
2348 */
2349 
2350 #if _FFR_ADD_BCC
2351 EXTERN bool AddBcc;
2352 #endif
2353 #if _FFR_ADDR_TYPE_MODES
2354 EXTERN bool	AddrTypeModes;	/* addr_type: extra "mode" information */
2355 #endif
2356 EXTERN bool	AllowBogusHELO;	/* allow syntax errors on HELO command */
2357 EXTERN bool	CheckAliases;	/* parse addresses during newaliases */
2358 #if _FFR_QUEUE_RUN_PARANOIA
2359 EXTERN int	CheckQueueRunners; /* check whether queue runners are OK */
2360 #endif
2361 EXTERN bool	ColonOkInAddr;	/* single colon legal in address */
2362 #if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_)
2363 EXTERN bool	ConfigFileRead;	/* configuration file has been read */
2364 #endif
2365 EXTERN bool	DisConnected;	/* running with OutChannel redirect to transcript file */
2366 EXTERN bool	DontExpandCnames;	/* do not $[...$] expand CNAMEs */
2367 EXTERN bool	DontInitGroups;	/* avoid initgroups() because of NIS cost */
2368 EXTERN bool	DontLockReadFiles;	/* don't read lock support files */
2369 EXTERN bool	DontPruneRoutes;	/* don't prune source routes */
2370 EXTERN bool	ForkQueueRuns;	/* fork for each job when running the queue */
2371 EXTERN bool	FromFlag;	/* if set, "From" person is explicit */
2372 EXTERN bool	FipsMode;
2373 EXTERN bool	GrabTo;		/* if set, get recipients from msg */
2374 #if _FFR_EIGHT_BIT_ADDR_OK
2375 EXTERN bool	EightBitAddrOK;	/* we'll let 8-bit addresses through */
2376 #else
2377 # define EightBitAddrOK	false
2378 #endif
2379 EXTERN bool	HasEightBits;	/* has at least one eight bit input byte */
2380 EXTERN bool	HasWildcardMX;	/* don't use MX records when canonifying */
2381 EXTERN bool	HoldErrs;	/* only output errors to transcript */
2382 EXTERN bool	IgnoreHostStatus;	/* ignore long term host status files */
2383 EXTERN bool	IgnrDot;	/* don't let dot end messages */
2384 #if _FFR_KEEPBCC
2385 EXTERN bool	KeepBcc;
2386 #else
2387 # define KeepBcc	false
2388 #endif
2389 EXTERN bool	LogUsrErrs;	/* syslog user errors (e.g., SMTP RCPT cmd) */
2390 EXTERN bool	MatchGecos;	/* look for user names in gecos field */
2391 EXTERN bool	MeToo;		/* send to the sender also */
2392 EXTERN bool	NoAlias;	/* suppress aliasing */
2393 EXTERN bool	NoConnect;	/* don't connect to non-local mailers */
2394 EXTERN bool	OnlyOneError;	/*  .... or only want to give one SMTP reply */
2395 EXTERN bool	QuickAbort;	/*  .... but only if we want a quick abort */
2396 #if _FFR_REJECT_NUL_BYTE
2397 EXTERN bool	RejectNUL;	/* reject NUL input byte? */
2398 #endif
2399 #if REQUIRES_DIR_FSYNC
2400 EXTERN bool	RequiresDirfsync;	/* requires fsync() for directory */
2401 #endif
2402 EXTERN bool	volatile RestartWorkGroup; /* daemon needs to restart some work groups */
2403 EXTERN bool	RrtImpliesDsn;	/* turn Return-Receipt-To: into DSN */
2404 EXTERN bool	SaveFrom;	/* save leading "From" lines */
2405 EXTERN bool	SendMIMEErrors;	/* send error messages in MIME format */
2406 EXTERN bool	SevenBitInput;	/* force 7-bit data on input */
2407 EXTERN bool	SingleLineFromHeader;	/* force From: header to be one line */
2408 EXTERN bool	SingleThreadDelivery;	/* single thread hosts on delivery */
2409 EXTERN bool	SoftBounce;	/* replace 5xy by 4xy (for testing) */
2410 EXTERN bool	volatile StopRequest;	/* stop sending output */
2411 EXTERN bool	SuprErrs;	/* set if we are suppressing errors */
2412 EXTERN bool	TryNullMXList;	/* if we are the best MX, try host directly */
2413 EXTERN bool	UseMSP;		/* mail submission: group writable queue ok? */
2414 EXTERN bool	WorkAroundBrokenAAAA;	/* some nameservers return SERVFAIL on AAAA queries */
2415 EXTERN bool	UseErrorsTo;	/* use Errors-To: header (back compat) */
2416 EXTERN bool	UseNameServer;	/* using DNS -- interpret h_errno & MX RRs */
2417 EXTERN bool	UseCompressedIPv6Addresses;	/* for more specific zero-subnet matches */
2418 EXTERN char	InetMode;		/* default network for daemon mode */
2419 EXTERN char	OpMode;		/* operation mode, see below */
2420 EXTERN char	SpaceSub;	/* substitution for <lwsp> */
2421 #if _FFR_BADRCPT_SHUTDOWN
2422 EXTERN int	BadRcptShutdown; /* Shutdown connection for rejected RCPTs */
2423 EXTERN int	BadRcptShutdownGood; /* above even when there are good RCPTs */
2424 #endif
2425 EXTERN int	BadRcptThrottle; /* Throttle rejected RCPTs per SMTP message */
2426 #if _FFR_RCPTTHROTDELAY
2427 EXTERN unsigned int BadRcptThrottleDelay; /* delay for BadRcptThrottle */
2428 #else
2429 # define BadRcptThrottleDelay	1
2430 #endif
2431 #if _FFR_TLS_ALTNAMES
2432 EXTERN bool	SetCertAltnames;
2433 #endif
2434 EXTERN int	CheckpointInterval;	/* queue file checkpoint interval */
2435 EXTERN int	ConfigLevel;	/* config file level */
2436 EXTERN int	ConnRateThrottle;	/* throttle for SMTP connection rate */
2437 EXTERN int	volatile CurChildren;	/* current number of daemonic children */
2438 EXTERN int	CurrentLA;	/* current load average */
2439 #if DANE
2440 EXTERN int	Dane;		/* DANE */
2441 #endif
2442 EXTERN int	DefaultNotify;	/* default DSN notification flags */
2443 EXTERN int	DelayLA;	/* load average to delay connections */
2444 EXTERN int	DontProbeInterfaces;	/* don't probe interfaces for names */
2445 EXTERN int	Errors;		/* set if errors (local to single pass) */
2446 EXTERN int	ExitStat;	/* exit status code */
2447 EXTERN int	FastSplit;	/* fast initial splitting of envelopes */
2448 EXTERN int	FileMode;	/* mode on files */
2449 EXTERN int	LineNumber;	/* line number in current input */
2450 EXTERN int	LogLevel;	/* level of logging to perform */
2451 EXTERN int	MaxAliasRecursion;	/* maximum depth of alias recursion */
2452 EXTERN int	MaxChildren;	/* maximum number of daemonic children */
2453 EXTERN int	MaxForwardEntries;	/* maximum number of forward entries */
2454 EXTERN int	MaxHeadersLength;	/* max length of headers */
2455 EXTERN int	MaxHopCount;	/* max # of hops until bounce */
2456 EXTERN int	MaxMacroRecursion;	/* maximum depth of macro recursion */
2457 EXTERN int	MaxMimeFieldLength;	/* maximum MIME field length */
2458 EXTERN int	MaxMimeHeaderLength;	/* maximum MIME header length */
2459 EXTERN int	MaxNOOPCommands; /* max "noise" commands before slowdown */
2460 
2461 EXTERN int	MaxRcptPerMsg;	/* max recipients per SMTP message */
2462 EXTERN int	MaxRuleRecursion;	/* maximum depth of ruleset recursion */
2463 #if _FFR_MSG_ACCEPT
2464 EXTERN char	*MessageAccept; /* "Message accepted for delivery" reply text */
2465 #endif
2466 
2467 EXTERN int	MimeMode;	/* MIME processing mode */
2468 EXTERN int	NoRecipientAction;
2469 
2470 #if SM_CONF_SHM
2471 EXTERN int	Numfilesys;	/* number of queue file systems */
2472 EXTERN int	*PNumFileSys;
2473 # define NumFileSys	(*PNumFileSys)
2474 #else /* SM_CONF_SHM */
2475 EXTERN int	NumFileSys;	/* number of queue file systems */
2476 #endif /* SM_CONF_SHM */
2477 
2478 EXTERN int	QueueLA;	/* load average starting forced queueing */
2479 EXTERN int	RefuseLA;	/* load average refusing connections */
2480 EXTERN time_t	RejectLogInterval;	/* time btwn log msgs while refusing */
2481 #if _FFR_MEMSTAT
2482 EXTERN long	QueueLowMem;	/* low memory starting forced queueing */
2483 EXTERN long	RefuseLowMem;	/* low memory refusing connections */
2484 EXTERN char	*MemoryResource;/* memory resource to look up */
2485 #endif /* _FFR_MEMSTAT */
2486 EXTERN int	SuperSafe;	/* be extra careful, even if expensive */
2487 EXTERN int	VendorCode;	/* vendor-specific operation enhancements */
2488 EXTERN int	Verbose;	/* set if blow-by-blow desired */
2489 EXTERN gid_t	DefGid;		/* default gid to run as */
2490 EXTERN gid_t	RealGid;	/* real gid of caller */
2491 EXTERN gid_t	RunAsGid;	/* GID to become for bulk of run */
2492 EXTERN gid_t	EffGid;		/* effective gid */
2493 #if SM_CONF_SHM
2494 EXTERN key_t	ShmKey;		/* shared memory key */
2495 EXTERN char	*ShmKeyFile;	/* shared memory key file */
2496 #endif
2497 EXTERN pid_t	CurrentPid;	/* current process id */
2498 EXTERN pid_t	DaemonPid;	/* process id of daemon */
2499 EXTERN pid_t	PidFilePid;	/* daemon/queue runner who wrote pid file */
2500 EXTERN uid_t	DefUid;		/* default uid to run as */
2501 EXTERN uid_t	RealUid;	/* real uid of caller */
2502 EXTERN uid_t	RunAsUid;	/* UID to become for bulk of run */
2503 EXTERN uid_t	TrustedUid;	/* uid of trusted user for files and startup */
2504 EXTERN size_t	DataFileBufferSize;	/* size of buf for in-core data file */
2505 EXTERN time_t	DeliverByMin;	/* deliver by minimum time */
2506 EXTERN time_t	DialDelay;	/* delay between dial-on-demand tries */
2507 EXTERN time_t	SafeAlias;	/* interval to wait until @:@ in alias file */
2508 EXTERN time_t	ServiceCacheMaxAge;	/* refresh interval for cache */
2509 EXTERN size_t	XscriptFileBufferSize;	/* size of buf for in-core transcript file */
2510 EXTERN MODE_T	OldUmask;	/* umask when sendmail starts up */
2511 EXTERN long	MaxMessageSize;	/* advertised max size we will accept */
2512 EXTERN long	MinBlocksFree;	/* min # of blocks free on queue fs */
2513 EXTERN long	QueueFactor;	/* slope of queue function */
2514 EXTERN long	WkClassFact;	/* multiplier for message class -> priority */
2515 EXTERN long	WkRecipFact;	/* multiplier for # of recipients -> priority */
2516 EXTERN long	WkTimeFact;	/* priority offset each time this job is run */
2517 EXTERN char	*ControlSocketName; /* control socket filename [control.c] */
2518 EXTERN char	*CurHostName;	/* current host we are dealing with */
2519 EXTERN char	*DeadLetterDrop;	/* path to dead letter office */
2520 EXTERN char	*DefUser;	/* default user to run as (from DefUid) */
2521 EXTERN char	*DefaultCharSet;	/* default character set for MIME */
2522 EXTERN char	*DoubleBounceAddr;	/* where to send double bounces */
2523 EXTERN char	*ErrMsgFile;	/* file to prepend to all error messages */
2524 EXTERN char	*FallbackMX;	/* fall back MX host */
2525 EXTERN char	*FallbackSmartHost;	/* fall back smart host */
2526 EXTERN char	*FileName;	/* name to print on error messages */
2527 EXTERN char	*ForwardPath;	/* path to search for .forward files */
2528 EXTERN char	*HeloName;	/* hostname to announce in HELO */
2529 EXTERN char	*HelpFile;	/* location of SMTP help file */
2530 EXTERN char	*HostStatDir;	/* location of host status information */
2531 EXTERN char	*HostsFile;	/* path to /etc/hosts file */
2532 extern char	*Mbdb;		/* mailbox database type */
2533 EXTERN char	*MustQuoteChars;	/* quote these characters in phrases */
2534 EXTERN char	*MyHostName;	/* name of this host for SMTP messages */
2535 EXTERN char	*OperatorChars;	/* operators (old $o macro) */
2536 EXTERN char	*PidFile;	/* location of proc id file [conf.c] */
2537 EXTERN char	*PostMasterCopy;	/* address to get errs cc's */
2538 EXTERN char	*ProcTitlePrefix; /* process title prefix */
2539 EXTERN char	*RealHostName;	/* name of host we are talking to */
2540 EXTERN char	*RealUserName;	/* real user name of caller */
2541 EXTERN char	*volatile RestartRequest;/* a sendmail restart has been requested */
2542 EXTERN char	*RunAsUserName;	/* user to become for bulk of run */
2543 EXTERN char	*SafeFileEnv;	/* chroot location for file delivery */
2544 EXTERN char	*ServiceSwitchFile;	/* backup service switch */
2545 EXTERN char	*volatile ShutdownRequest;/* a sendmail shutdown has been requested */
2546 EXTERN bool	volatile IntSig;
2547 EXTERN char	*SmtpGreeting;	/* SMTP greeting message (old $e macro) */
2548 EXTERN char	*SmtpPhase;	/* current phase in SMTP processing */
2549 EXTERN char	SmtpError[MAXLINE];	/* save failure error messages */
2550 EXTERN char	*StatFile;	/* location of statistics summary */
2551 EXTERN char	*TimeZoneSpec;	/* override time zone specification */
2552 EXTERN char	*UdbSpec;	/* user database source spec */
2553 EXTERN char	*UnixFromLine;	/* UNIX From_ line (old $l macro) */
2554 EXTERN char	**ExternalEnviron;	/* saved user (input) environment */
2555 EXTERN char	**SaveArgv;	/* argument vector for re-execing */
2556 EXTERN BITMAP256	DontBlameSendmail;	/* DontBlameSendmail bits */
2557 EXTERN SM_FILE_T	*InChannel;	/* input connection */
2558 EXTERN SM_FILE_T	*OutChannel;	/* output connection */
2559 EXTERN SM_FILE_T	*TrafficLogFile; /* file in which to log all traffic */
2560 #if HESIOD
2561 EXTERN void	*HesiodContext;
2562 #endif
2563 EXTERN ENVELOPE	*CurEnv;	/* envelope currently being processed */
2564 EXTERN char	*RuleSetNames[MAXRWSETS];	/* ruleset number to name */
2565 EXTERN char	*UserEnviron[MAXUSERENVIRON + 1];
2566 EXTERN struct rewrite	*RewriteRules[MAXRWSETS];
2567 EXTERN struct termescape	TermEscape;	/* terminal escape codes */
2568 EXTERN SOCKADDR	ConnectOnlyTo;	/* override connection address (for testing) */
2569 EXTERN SOCKADDR RealHostAddr;	/* address of host we are talking to */
2570 extern const SM_EXC_TYPE_T EtypeQuickAbort; /* type of a QuickAbort exception */
2571 
2572 #if _FFR_BLANKENV_MACV
2573 EXTERN int Hacks;	/* bit field of run-time enabled "hacks" */
2574 # define H_LOOKUP_MACRO_IN_BLANKENV	0x0001
2575 # define LOOKUP_MACRO_IN_BLANKENV	(Hacks & H_LOOKUP_MACRO_IN_BLANKENV)
2576 #else
2577 # define LOOKUP_MACRO_IN_BLANKENV	false
2578 #endif
2579 
2580 EXTERN int ConnectionRateWindowSize;
2581 
2582 /*
2583 **  Declarations of useful functions
2584 */
2585 
2586 /* Transcript file */
2587 extern void	closexscript __P((ENVELOPE *));
2588 extern void	openxscript __P((ENVELOPE *));
2589 
2590 #if SM_DEVELOPER
2591 #define NR_PRINTFLIKE(a, b)	PRINTFLIKE(a, b)
2592 #else
2593 #define NR_PRINTFLIKE(a, b)
2594 #endif
2595 
2596 /* error related */
2597 extern void	buffer_errors __P((void));
2598 extern void	flush_errors __P((bool));
2599 extern void NR_PRINTFLIKE(1, 2)	message __P((const char *, ...));
2600 extern void NR_PRINTFLIKE(1, 2)	nmessage __P((const char *, ...));
2601 #if _FFR_PROXY
2602 extern void NR_PRINTFLIKE(3, 4)	emessage __P((const char *, const char *, const char *, ...));
2603 extern int extsc __P((const char *, int, char *, char *));
2604 #endif
2605 extern void NR_PRINTFLIKE(1, 2)	syserr __P((const char *, ...));
2606 extern void NR_PRINTFLIKE(2, 3)	usrerrenh __P((char *, const char *, ...));
2607 extern void NR_PRINTFLIKE(1, 2)	usrerr __P((const char *, ...));
2608 extern int	isenhsc __P((const char *, int));
2609 extern int	extenhsc __P((const char *, int, char *));
2610 
2611 /* alias file */
2612 extern void	alias __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
2613 extern bool	aliaswait __P((MAP *, char *, bool));
2614 extern void	forward __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
2615 extern void	readaliases __P((MAP *, SM_FILE_T *, bool, bool));
2616 extern bool	rebuildaliases __P((MAP *, bool));
2617 extern void	setalias __P((char *));
2618 
2619 /* logging */
2620 extern void	logdelivery __P((MAILER *, MCI *, char *, const char *, ADDRESS *, time_t, ENVELOPE *, ADDRESS *, int));
2621 extern void	logsender __P((ENVELOPE *, char *));
2622 extern void PRINTFLIKE(3, 4) sm_syslog __P((int, const char *, const char *, ...));
2623 
2624 /* SMTP */
2625 extern void	giveresponse __P((int, char *, MAILER *, MCI *, ADDRESS *, time_t, ENVELOPE *, ADDRESS *));
2626 extern int	reply __P((MAILER *, MCI *, ENVELOPE *, time_t, void (*)__P((char *, bool, MAILER *, MCI *, ENVELOPE *)), char **, int));
2627 extern void	smtp __P((char *volatile, BITMAP256, ENVELOPE *volatile));
2628 #if SASL
2629 extern int	smtpauth __P((MAILER *, MCI *, ENVELOPE *));
2630 #endif
2631 extern int	smtpdata __P((MAILER *, MCI *, ENVELOPE *, ADDRESS *, time_t));
2632 extern int	smtpgetstat __P((MAILER *, MCI *, ENVELOPE *));
2633 extern int	smtpmailfrom __P((MAILER *, MCI *, ENVELOPE *));
2634 extern void	smtpmessage __P((char *, MAILER *, MCI *, ...));
2635 extern void	smtpinit __P((MAILER *, MCI *, ENVELOPE *, bool));
2636 extern char	*smtptodsn __P((int));
2637 extern int	smtpprobe __P((MCI *));
2638 extern void	smtpquit __P((MAILER *, MCI *, ENVELOPE *));
2639 extern int	smtprcpt __P((ADDRESS *, MAILER *, MCI *, ENVELOPE *, ADDRESS *, time_t));
2640 extern void	smtprset __P((MAILER *, MCI *, ENVELOPE *));
2641 
2642 #define REPLYTYPE(r)	((r) / 100)		/* first digit of reply code */
2643 #define REPLYCLASS(r)	(((r) / 10) % 10)	/* second digit of reply code */
2644 #define REPLYMINOR(r)	((r) % 10)	/* last digit of reply code */
2645 #define ISSMTPCODE(c)	(isascii(c[0]) && isdigit(c[0]) && \
2646 			isascii(c[1]) && isdigit(c[1]) && \
2647 			isascii(c[2]) && isdigit(c[2]))
2648 #define ISSMTPREPLY(c)	(ISSMTPCODE(c) && \
2649 			(c[3] == ' ' || c[3] == '-' || c[3] == '\0'))
2650 #define SM_ISSPACE(c)	(isascii(c) && isspace(c))
2651 
2652 /* delivery */
2653 extern pid_t	dowork __P((int, int, char *, bool, bool, ENVELOPE *));
2654 extern pid_t	doworklist __P((ENVELOPE *, bool, bool));
2655 extern int	endmailer __P((MCI *, ENVELOPE *, char **));
2656 extern int	mailfile __P((char *volatile, MAILER *volatile, ADDRESS *, volatile long, ENVELOPE *));
2657 extern void	sendall __P((ENVELOPE *, int));
2658 
2659 /* stats */
2660 #define STATS_NORMAL		'n'
2661 #define STATS_QUARANTINE	'q'
2662 #define STATS_REJECT		'r'
2663 #define STATS_CONNECT		'c'
2664 
2665 extern void	markstats __P((ENVELOPE *, ADDRESS *, int));
2666 extern void	clearstats __P((void));
2667 extern void	poststats __P((char *));
2668 
2669 /* control socket */
2670 extern void	closecontrolsocket __P((bool));
2671 extern void	clrcontrol __P((void));
2672 extern void	control_command __P((int, ENVELOPE *));
2673 extern int	opencontrolsocket __P((void));
2674 
2675 #if MILTER
2676 /* milter functions */
2677 extern void	milter_config __P((char *, struct milter **, int));
2678 extern void	milter_setup __P((char *));
2679 extern void	milter_set_option __P((char *, char *, bool));
2680 extern bool	milter_init __P((ENVELOPE *, char *, milters_T *));
2681 extern void	milter_quit __P((ENVELOPE *));
2682 extern void	milter_abort __P((ENVELOPE *));
2683 extern char	*milter_connect __P((char *, SOCKADDR, ENVELOPE *, char *));
2684 extern char	*milter_helo __P((char *, ENVELOPE *, char *));
2685 extern char	*milter_envfrom __P((char **, ENVELOPE *, char *));
2686 extern char	*milter_data_cmd __P((ENVELOPE *, char *));
2687 extern char	*milter_envrcpt __P((char **, ENVELOPE *, char *, bool));
2688 extern char	*milter_data __P((ENVELOPE *, char *));
2689 extern char	*milter_unknown __P((char *, ENVELOPE *, char *));
2690 #endif /* MILTER */
2691 
2692 extern char	*addquotes __P((char *, SM_RPOOL_T *));
2693 extern char	*arpadate __P((char *));
2694 extern bool	atobool __P((char *));
2695 extern int	atooct __P((char *));
2696 extern void	auth_warning __P((ENVELOPE *, const char *, ...));
2697 extern int	blocksignal __P((int));
2698 extern bool	bitintersect __P((BITMAP256, BITMAP256));
2699 extern bool	bitzerop __P((BITMAP256));
2700 extern int	check_bodytype __P((char *));
2701 extern void	buildfname __P((char *, char *, char *, int));
2702 extern bool	chkclientmodifiers __P((int));
2703 extern bool	chkdaemonmodifiers __P((int));
2704 extern int	checkcompat __P((ADDRESS *, ENVELOPE *));
2705 #ifdef XDEBUG
2706 extern void	checkfd012 __P((char *));
2707 extern void	checkfdopen __P((int, char *));
2708 #endif
2709 extern void	checkfds __P((char *));
2710 extern bool	chownsafe __P((int, bool));
2711 extern void	cleanstrcpy __P((char *, char *, int));
2712 #if SM_CONF_SHM
2713 extern void	cleanup_shm __P((bool));
2714 #endif
2715 extern void	close_sendmail_pid __P((void));
2716 extern void	clrdaemon __P((void));
2717 extern void	collect __P((SM_FILE_T *, bool, HDR **, ENVELOPE *, bool));
2718 extern time_t	convtime __P((char *, int));
2719 extern char	**copyplist __P((char **, bool, SM_RPOOL_T *));
2720 extern void	copy_class __P((int, int));
2721 extern int	count_open_connections __P((SOCKADDR *));
2722 extern time_t	curtime __P((void));
2723 extern char	*defcharset __P((ENVELOPE *));
2724 extern char	*denlstring __P((char *, bool, bool));
2725 extern void	dferror __P((SM_FILE_T *volatile, char *, ENVELOPE *));
2726 extern void	disconnect __P((int, ENVELOPE *));
2727 extern void	disk_status __P((SM_FILE_T *, char *));
2728 extern int	dns_getcanonname __P((char *, int, bool, int *, int *));
2729 extern pid_t	dofork __P((void));
2730 extern int	drop_privileges __P((bool));
2731 extern int	dsntoexitstat __P((char *));
2732 extern void	dumpfd __P((int, bool, bool));
2733 #if SM_HEAP_CHECK
2734 extern void	dumpstab __P((void));
2735 #endif
2736 extern void	dumpstate __P((char *));
2737 extern bool	enoughdiskspace __P((long, ENVELOPE *));
2738 extern char	*exitstat __P((char *));
2739 extern void	fatal_error __P((SM_EXC_T *));
2740 extern char	*fgetfolded __P((char *, int *, SM_FILE_T *));
2741 extern void	fill_fd __P((int, char *));
2742 extern char	*find_character __P((char *, int));
2743 extern int	finduser __P((char *, bool *, SM_MBDB_T *));
2744 extern void	finis __P((bool, bool, volatile int));
2745 extern void	fixcrlf __P((char *, bool));
2746 extern long	freediskspace __P((const char *, long *));
2747 #if NETINET6 && NEEDSGETIPNODE
2748 extern void	freehostent __P((struct hostent *));
2749 #endif
2750 extern char	*get_column __P((char *, int, int, char *, int));
2751 extern char	*getauthinfo __P((int, bool *));
2752 extern int	getdtsize __P((void));
2753 extern int	getla __P((void));
2754 extern char	*getmodifiers __P((char *, BITMAP256));
2755 extern BITMAP256	*getrequests __P((ENVELOPE *));
2756 extern char	*getvendor __P((int));
2757 extern void	help __P((char *, ENVELOPE *));
2758 extern void	init_md __P((int, char **));
2759 extern void	initdaemon __P((void));
2760 extern void	inithostmaps __P((void));
2761 extern void	initmacros __P((ENVELOPE *));
2762 extern void	initsetproctitle __P((int, char **, char **));
2763 extern void	init_vendor_macros __P((ENVELOPE *));
2764 extern SIGFUNC_DECL	intsig __P((int));
2765 extern bool	isatom __P((const char *));
2766 extern bool	isloopback __P((SOCKADDR sa));
2767 extern void	load_if_names __P((void));
2768 extern bool	lockfile __P((int, char *, char *, int));
2769 extern void	log_sendmail_pid __P((ENVELOPE *));
2770 extern void	logundelrcpts __P((ENVELOPE *, char *, int, bool));
2771 extern char	lower __P((int));
2772 extern void	makelower __P((char *));
2773 extern int	makeconnection_ds __P((char *, MCI *));
2774 #if DANE
2775 extern int	makeconnection __P((char *, volatile unsigned int, MCI *, ENVELOPE *, time_t, unsigned long *));
2776 #else
2777 extern int	makeconnection __P((char *, volatile unsigned int, MCI *, ENVELOPE *, time_t));
2778 #endif
2779 extern void	makeworkgroups __P((void));
2780 extern void	markfailure __P((ENVELOPE *, ADDRESS *, MCI *, int, bool));
2781 extern void	mark_work_group_restart __P((int, int));
2782 extern MCI	*mci_new __P((SM_RPOOL_T *));
2783 extern char	*munchstring __P((char *, char **, int));
2784 extern struct hostent	*myhostname __P((char *, int));
2785 extern char	*newstr __P((const char *));
2786 #if NISPLUS
2787 extern char	*nisplus_default_domain __P((void));	/* extern for Sun */
2788 #endif
2789 extern bool	path_is_dir __P((char *, bool));
2790 extern int	pickqdir __P((QUEUEGRP *qg, long fsize, ENVELOPE *e));
2791 extern char	*pintvl __P((time_t, bool));
2792 extern void	printav __P((SM_FILE_T *, char **));
2793 extern void	printmailer __P((SM_FILE_T *, MAILER *));
2794 extern void	printnqe __P((SM_FILE_T *, char *));
2795 extern void	printopenfds __P((bool));
2796 extern void	printqueue __P((void));
2797 extern void	printrules __P((void));
2798 extern pid_t	prog_open __P((char **, int *, ENVELOPE *));
2799 extern bool	putline __P((char *, MCI *));
2800 extern bool	putxline __P((char *, size_t, MCI *, int));
2801 extern void	queueup_macros __P((int, SM_FILE_T *, ENVELOPE *));
2802 extern void	readcf __P((char *, bool, ENVELOPE *));
2803 extern SIGFUNC_DECL	reapchild __P((int));
2804 extern int	releasesignal __P((int));
2805 extern void	resetlimits __P((void));
2806 extern void	restart_daemon __P((void));
2807 extern void	restart_marked_work_groups __P((void));
2808 extern bool	rfc822_string __P((char *));
2809 extern void	rmexpstab __P((void));
2810 extern bool	savemail __P((ENVELOPE *, bool));
2811 extern void	seed_random __P((void));
2812 extern void	sendtoargv __P((char **, ENVELOPE *));
2813 extern void	setclientoptions __P((char *));
2814 extern bool	setdaemonoptions __P((char *));
2815 extern void	setdefaults __P((ENVELOPE *));
2816 extern void	setdefuser __P((void));
2817 extern bool	setvendor __P((char *));
2818 extern void	set_op_mode __P((int));
2819 extern void	setoption __P((int, char *, bool, bool, ENVELOPE *));
2820 extern sigfunc_t	setsignal __P((int, sigfunc_t));
2821 extern void	sm_setuserenv __P((const char *, const char *));
2822 extern void	settime __P((ENVELOPE *));
2823 #if STARTTLS
2824 extern int	set_tls_rd_tmo __P((int));
2825 #else
2826 # define set_tls_rd_tmo(rd_tmo)	0
2827 #endif
2828 extern char	*sfgets __P((char *, int, SM_FILE_T *, time_t, char *));
2829 extern char	*shortenstring __P((const char *, size_t));
2830 extern char	*shorten_hostname __P((char []));
2831 extern bool	shorten_rfc822_string __P((char *, size_t));
2832 extern void	shutdown_daemon __P((void));
2833 extern void	sm_closefrom __P((int lowest, int highest));
2834 extern void	sm_close_on_exec __P((int lowest, int highest));
2835 extern struct hostent	*sm_gethostbyname __P((char *, int));
2836 extern struct hostent	*sm_gethostbyaddr __P((char *, int, int));
2837 extern void	sm_getla __P((void));
2838 extern struct passwd	*sm_getpwnam __P((char *));
2839 extern struct passwd	*sm_getpwuid __P((UID_T));
2840 extern void	sm_setproctitle __P((bool, ENVELOPE *, const char *, ...));
2841 extern pid_t	sm_wait __P((int *));
2842 extern bool	split_by_recipient __P((ENVELOPE *e));
2843 extern void	stop_sendmail __P((void));
2844 extern void	stripbackslash __P((char *));
2845 extern bool	strreplnonprt __P((char *, int));
2846 extern bool	strcontainedin __P((bool, char *, char *));
2847 extern int	switch_map_find __P((char *, char *[], short []));
2848 #if STARTTLS
2849 extern void	tls_set_verify __P((SSL_CTX *, SSL *, bool));
2850 #endif
2851 extern bool	transienterror __P((int));
2852 extern void	truncate_at_delim __P((char *, size_t, int));
2853 extern void	tTflag __P((char *));
2854 extern void	tTsetup __P((unsigned char *, unsigned int, char *));
2855 extern SIGFUNC_DECL	tick __P((int));
2856 extern char	*ttypath __P((void));
2857 extern void	unlockqueue __P((ENVELOPE *));
2858 #if !HASUNSETENV
2859 extern void	unsetenv __P((char *));
2860 #endif
2861 
2862 /* update file system information: +/- some blocks */
2863 #if SM_CONF_SHM
2864 extern void	upd_qs __P((ENVELOPE *, int, int, char *));
2865 # define updfs(e, count, space, where) upd_qs(e, count, space, where)
2866 #else /* SM_CONF_SHM */
2867 # define updfs(e, count, space, where)
2868 # define upd_qs(e, count, space, where)
2869 #endif /* SM_CONF_SHM */
2870 
2871 extern char	*username __P((void));
2872 extern bool	usershellok __P((char *, char *));
2873 extern void	vendor_post_defaults __P((ENVELOPE *));
2874 extern void	vendor_pre_defaults __P((ENVELOPE *));
2875 extern int	waitfor __P((pid_t));
2876 extern bool	writable __P((char *, ADDRESS *, long));
2877 #if SM_HEAP_CHECK
2878 # define xalloc(size)	xalloc_tagged(size, __FILE__, __LINE__)
2879 extern char *xalloc_tagged __P((int, char *, int));
2880 #else
2881 extern char *xalloc __P((int));
2882 #endif /* SM_HEAP_CHECK */
2883 #if _FFR_XCNCT
2884 extern int xconnect __P((SM_FILE_T *));
2885 #endif
2886 extern void	xputs __P((SM_FILE_T *, const char *));
2887 extern char	*xtextify __P((char *, char *));
2888 extern bool	xtextok __P((char *));
2889 extern int	xunlink __P((char *));
2890 extern char	*xuntextify __P((char *));
2891 
2892 #if _FFR_EAI
2893 extern bool	addr_is_ascii __P((const char *));
2894 #endif
2895 
2896 #if _FFR_RCPTFLAGS
2897 extern bool	newmodmailer __P((ADDRESS *, int));
2898 #endif
2899 
2900 #undef EXTERN
2901 #endif /* ! _SENDMAIL_H */
2902