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