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