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