138032Speter/*
2249729Sgshapiro * Copyright (c) 1998-2013 Sendmail, Inc. and its suppliers.
364562Sgshapiro *	All rights reserved.
438032Speter * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
538032Speter * Copyright (c) 1988, 1993
638032Speter *	The Regents of the University of California.  All rights reserved.
738032Speter *
838032Speter * By using this file, you agree to the terms and conditions set
938032Speter * forth in the LICENSE file which can be found at the top level of
1038032Speter * the sendmail distribution.
1138032Speter */
1238032Speter
1338032Speter/*
1464562Sgshapiro**  SENDMAIL.H -- MTA-specific definitions for sendmail.
1538032Speter*/
1638032Speter
1764562Sgshapiro#ifndef _SENDMAIL_H
1890792Sgshapiro# define _SENDMAIL_H 1
1964562Sgshapiro
20132943Sgshapiro#ifndef MILTER
21132943Sgshapiro# define MILTER	1	/* turn on MILTER by default */
22132943Sgshapiro#endif /* MILTER */
23132943Sgshapiro
2464562Sgshapiro#ifdef _DEFINE
2538032Speter# define EXTERN
2664562Sgshapiro#else /* _DEFINE */
2738032Speter# define EXTERN extern
2864562Sgshapiro#endif /* _DEFINE */
2938032Speter
3064562Sgshapiro
3164562Sgshapiro#include <unistd.h>
3264562Sgshapiro
3364562Sgshapiro#include <stddef.h>
3464562Sgshapiro#include <stdlib.h>
3590792Sgshapiro#include <stdio.h>
3664562Sgshapiro#include <ctype.h>
3764562Sgshapiro#include <setjmp.h>
3864562Sgshapiro#include <string.h>
3964562Sgshapiro#include <time.h>
4038032Speter# ifdef EX_OK
4138032Speter#  undef EX_OK			/* for SVr4.2 SMP */
4264562Sgshapiro# endif /* EX_OK */
4338032Speter
4464562Sgshapiro#include "sendmail/sendmail.h"
4590792Sgshapiro
4690792Sgshapiro/* profiling? */
4790792Sgshapiro#if MONCONTROL
4890792Sgshapiro# define SM_PROF(x)	moncontrol(x)
4990792Sgshapiro#else /* MONCONTROL */
5090792Sgshapiro# define SM_PROF(x)
5190792Sgshapiro#endif /* MONCONTROL */
5290792Sgshapiro
5390792Sgshapiro#ifdef _DEFINE
5490792Sgshapiro# ifndef lint
55249729SgshapiroSM_UNUSED(static char SmailId[]) = "@(#)$Id: sendmail.h,v 8.1101 2013/03/15 17:54:12 ca Exp $";
5690792Sgshapiro# endif /* ! lint */
5790792Sgshapiro#endif /* _DEFINE */
5890792Sgshapiro
5964562Sgshapiro#include "bf.h"
6064562Sgshapiro#include "timers.h"
6190792Sgshapiro#include <sm/exc.h>
6290792Sgshapiro#include <sm/heap.h>
6390792Sgshapiro#include <sm/debug.h>
6490792Sgshapiro#include <sm/rpool.h>
6590792Sgshapiro#include <sm/io.h>
6690792Sgshapiro#include <sm/path.h>
6790792Sgshapiro#include <sm/signal.h>
6890792Sgshapiro#include <sm/clock.h>
6990792Sgshapiro#include <sm/mbdb.h>
7090792Sgshapiro#include <sm/errstring.h>
7190792Sgshapiro#include <sm/sysexits.h>
7290792Sgshapiro#include <sm/shm.h>
73168515Sgshapiro#include <sm/misc.h>
7438032Speter
7564562Sgshapiro#ifdef LOG
7638032Speter# include <syslog.h>
7764562Sgshapiro#endif /* LOG */
7838032Speter
7964562Sgshapiro
8064562Sgshapiro
8164562Sgshapiro# if NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25
8264562Sgshapiro#  include <sys/socket.h>
8364562Sgshapiro# endif /* NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25 */
8438032Speter# if NETUNIX
8564562Sgshapiro#  include <sys/un.h>
8664562Sgshapiro# endif /* NETUNIX */
8764562Sgshapiro# if NETINET || NETINET6
8864562Sgshapiro#  include <netinet/in.h>
8964562Sgshapiro# endif /* NETINET || NETINET6 */
9064562Sgshapiro# if NETINET6
9164562Sgshapiro/*
9264562Sgshapiro**  There is no standard yet for IPv6 includes.
9364562Sgshapiro**  Specify OS specific implementation in conf.h
9464562Sgshapiro*/
9564562Sgshapiro# endif /* NETINET6 */
9638032Speter# if NETISO
9764562Sgshapiro#  include <netiso/iso.h>
9864562Sgshapiro# endif /* NETISO */
9938032Speter# if NETNS
10064562Sgshapiro#  include <netns/ns.h>
10164562Sgshapiro# endif /* NETNS */
10238032Speter# if NETX25
10364562Sgshapiro#  include <netccitt/x25.h>
10464562Sgshapiro# endif /* NETX25 */
10538032Speter
10664562Sgshapiro# if NAMED_BIND
10764562Sgshapiro#  include <arpa/nameser.h>
10864562Sgshapiro#  ifdef NOERROR
10964562Sgshapiro#   undef NOERROR		/* avoid <sys/streams.h> conflict */
11064562Sgshapiro#  endif /* NOERROR */
11164562Sgshapiro#  include <resolv.h>
11290792Sgshapiro# else /* NAMED_BIND */
11390792Sgshapiro#   undef SM_SET_H_ERRNO
11490792Sgshapiro#   define SM_SET_H_ERRNO(err)
11564562Sgshapiro# endif /* NAMED_BIND */
11638032Speter
11790792Sgshapiro# if HESIOD
11864562Sgshapiro#  include <hesiod.h>
11964562Sgshapiro#  if !defined(HES_ER_OK) || defined(HESIOD_INTERFACES)
12064562Sgshapiro#   define HESIOD_INIT		/* support for the new interface */
12164562Sgshapiro#  endif /* !defined(HES_ER_OK) || defined(HESIOD_INTERFACES) */
12264562Sgshapiro# endif /* HESIOD */
12338032Speter
12464562Sgshapiro#if STARTTLS
12564562Sgshapiro#  include <openssl/ssl.h>
12690792Sgshapiro# if !TLS_NO_RSA
127249729Sgshapiro#  if _FFR_FIPSMODE
128249729Sgshapiro#   define RSA_KEYLENGTH	1024
129249729Sgshapiro#  else /* _FFR_FIPSMODE  */
130249729Sgshapiro#   define RSA_KEYLENGTH	512
131249729Sgshapiro#  endif /* _FFR_FIPSMODE  */
13290792Sgshapiro# endif /* !TLS_NO_RSA */
13364562Sgshapiro#endif /* STARTTLS */
13464562Sgshapiro
13564562Sgshapiro#if SASL  /* include the sasl include files if we have them */
13698121Sgshapiro
13798121Sgshapiro
13898121Sgshapiro# if SASL == 2 || SASL >= 20000
13998121Sgshapiro#  include <sasl/sasl.h>
140225906Sume#  include <sasl/saslplug.h>
14198121Sgshapiro#  include <sasl/saslutil.h>
142225906Sume#  if SASL_VERSION_FULL < 0x020119
143225906Sumetypedef int (*sasl_callback_ft)(void);
144225906Sume#  endif
14598121Sgshapiro# else /* SASL == 2 || SASL >= 20000 */
14698121Sgshapiro#  include <sasl.h>
14798121Sgshapiro#  include <saslutil.h>
148225906Sumetypedef int (*sasl_callback_ft)(void);
14998121Sgshapiro# endif /* SASL == 2 || SASL >= 20000 */
15064562Sgshapiro# if defined(SASL_VERSION_MAJOR) && defined(SASL_VERSION_MINOR) && defined(SASL_VERSION_STEP)
15164562Sgshapiro#  define SASL_VERSION (SASL_VERSION_MAJOR * 10000)  + (SASL_VERSION_MINOR * 100) + SASL_VERSION_STEP
15298121Sgshapiro#  if SASL == 1 || SASL == 2
15364562Sgshapiro#   undef SASL
15464562Sgshapiro#   define SASL SASL_VERSION
15598121Sgshapiro#  else /* SASL == 1 || SASL == 2 */
15664562Sgshapiro#   if SASL != SASL_VERSION
15764562Sgshapiro  ERROR README: -DSASL (SASL) does not agree with the version of the CYRUS_SASL library (SASL_VERSION)
15864562Sgshapiro  ERROR README: see README!
15964562Sgshapiro#   endif /* SASL != SASL_VERSION */
16098121Sgshapiro#  endif /* SASL == 1 || SASL == 2 */
16164562Sgshapiro# else /* defined(SASL_VERSION_MAJOR) && defined(SASL_VERSION_MINOR) && defined(SASL_VERSION_STEP) */
16264562Sgshapiro#  if SASL == 1
16364562Sgshapiro  ERROR README: please set -DSASL to the version of the CYRUS_SASL library
16464562Sgshapiro  ERROR README: see README!
16564562Sgshapiro#  endif /* SASL == 1 */
16664562Sgshapiro# endif /* defined(SASL_VERSION_MAJOR) && defined(SASL_VERSION_MINOR) && defined(SASL_VERSION_STEP) */
16764562Sgshapiro#endif /* SASL */
16864562Sgshapiro
16938032Speter/*
17038032Speter**  Following are "sort of" configuration constants, but they should
17138032Speter**  be pretty solid on most architectures today.  They have to be
17238032Speter**  defined after <arpa/nameser.h> because some versions of that
17338032Speter**  file also define them.  In all cases, we can't use sizeof because
17438032Speter**  some systems (e.g., Crays) always treat everything as being at
17538032Speter**  least 64 bits.
17638032Speter*/
17738032Speter
17838032Speter#ifndef INADDRSZ
17938032Speter# define INADDRSZ	4		/* size of an IPv4 address in bytes */
18064562Sgshapiro#endif /* ! INADDRSZ */
18164562Sgshapiro#ifndef IN6ADDRSZ
18264562Sgshapiro# define IN6ADDRSZ	16		/* size of an IPv6 address in bytes */
18364562Sgshapiro#endif /* ! IN6ADDRSZ */
18438032Speter#ifndef INT16SZ
18538032Speter# define INT16SZ	2		/* size of a 16 bit integer in bytes */
18664562Sgshapiro#endif /* ! INT16SZ */
18738032Speter#ifndef INT32SZ
18838032Speter# define INT32SZ	4		/* size of a 32 bit integer in bytes */
18964562Sgshapiro#endif /* ! INT32SZ */
19073188Sgshapiro#ifndef INADDR_LOOPBACK
19173188Sgshapiro# define INADDR_LOOPBACK	0x7f000001	/* loopback address */
19273188Sgshapiro#endif /* ! INADDR_LOOPBACK */
19338032Speter
19464562Sgshapiro/*
19564562Sgshapiro**  Error return from inet_addr(3), in case not defined in /usr/include.
19664562Sgshapiro*/
19738032Speter
19864562Sgshapiro#ifndef INADDR_NONE
19964562Sgshapiro# define INADDR_NONE	0xffffffff
20064562Sgshapiro#endif /* ! INADDR_NONE */
20138032Speter
20264562Sgshapiro
203120256Sgshapiro/* (f)open() modes for queue files */
204120256Sgshapiro# define QF_O_EXTRA	0
205120256Sgshapiro
206120256Sgshapiro
20790792Sgshapiro/*
20890792Sgshapiro**  An 'argument class' describes the storage allocation status
20990792Sgshapiro**  of an object pointed to by an argument to a function.
21090792Sgshapiro*/
21190792Sgshapiro
21290792Sgshapirotypedef enum
21390792Sgshapiro{
21490792Sgshapiro	A_HEAP,	/* the storage was allocated by malloc, and the
21590792Sgshapiro		 * ownership of the storage is ceded by the caller
21690792Sgshapiro		 * to the called function. */
21790792Sgshapiro	A_TEMP, /* The storage is temporary, and is only guaranteed
21890792Sgshapiro		 * to be valid for the duration of the function call. */
21990792Sgshapiro	A_PERM	/* The storage is 'permanent': this might mean static
22090792Sgshapiro		 * storage, or rpool storage. */
22190792Sgshapiro} ARGCLASS_T;
22290792Sgshapiro
22338032Speter/* forward references for prototypes */
22438032Spetertypedef struct envelope	ENVELOPE;
22538032Spetertypedef struct mailer	MAILER;
22690792Sgshapirotypedef struct queuegrp	QUEUEGRP;
22738032Speter
22890792Sgshapiro/*
22938032Speter**  Address structure.
23038032Speter**	Addresses are stored internally in this structure.
23138032Speter*/
23238032Speter
23338032Speterstruct address
23438032Speter{
23538032Speter	char		*q_paddr;	/* the printname for the address */
23638032Speter	char		*q_user;	/* user name */
23738032Speter	char		*q_ruser;	/* real user name, or NULL if q_user */
23838032Speter	char		*q_host;	/* host name */
23938032Speter	struct mailer	*q_mailer;	/* mailer to use */
24090792Sgshapiro	unsigned long	q_flags;	/* status flags, see below */
24138032Speter	uid_t		q_uid;		/* user-id of receiver (if known) */
24238032Speter	gid_t		q_gid;		/* group-id of receiver (if known) */
24338032Speter	char		*q_home;	/* home dir (local mailer only) */
24438032Speter	char		*q_fullname;	/* full name if known */
24538032Speter	struct address	*q_next;	/* chain */
24638032Speter	struct address	*q_alias;	/* address this results from */
24738032Speter	char		*q_owner;	/* owner of q_alias */
24838032Speter	struct address	*q_tchain;	/* temporary use chain */
24990792Sgshapiro#if PIPELINING
25090792Sgshapiro	struct address	*q_pchain;	/* chain for pipelining */
25190792Sgshapiro#endif /* PIPELINING */
25290792Sgshapiro	char		*q_finalrcpt;	/* Final-Recipient: DSN header */
25338032Speter	char		*q_orcpt;	/* ORCPT parameter from RCPT TO: line */
25438032Speter	char		*q_status;	/* status code for DSNs */
25538032Speter	char		*q_rstatus;	/* remote status message for DSNs */
25638032Speter	time_t		q_statdate;	/* date of status messages */
25738032Speter	char		*q_statmta;	/* MTA generating q_rstatus */
25864562Sgshapiro	short		q_state;	/* address state, see below */
25990792Sgshapiro	char		*q_signature;	/* MX-based sorting value */
26090792Sgshapiro	int		q_qgrp;		/* index into queue groups */
26190792Sgshapiro	int		q_qdir;		/* queue directory inside group */
26290792Sgshapiro	char		*q_message;	/* error message */
26338032Speter};
26438032Speter
26538032Spetertypedef struct address ADDRESS;
26638032Speter
26764562Sgshapiro/* bit values for q_flags */
26864562Sgshapiro#define QGOODUID	0x00000001	/* the q_uid q_gid fields are good */
26964562Sgshapiro#define QPRIMARY	0x00000002	/* set from RCPT or argv */
27064562Sgshapiro#define QNOTREMOTE	0x00000004	/* address not for remote forwarding */
27164562Sgshapiro#define QSELFREF	0x00000008	/* this address references itself */
27264562Sgshapiro#define QBOGUSSHELL	0x00000010	/* user has no valid shell listed */
27364562Sgshapiro#define QUNSAFEADDR	0x00000020	/* address acquired via unsafe path */
27464562Sgshapiro#define QPINGONSUCCESS	0x00000040	/* give return on successful delivery */
27564562Sgshapiro#define QPINGONFAILURE	0x00000080	/* give return on failure */
27664562Sgshapiro#define QPINGONDELAY	0x00000100	/* give return on message delay */
27790792Sgshapiro#define QHASNOTIFY	0x00000200	/* propagate notify parameter */
27864562Sgshapiro#define QRELAYED	0x00000400	/* DSN: relayed to non-DSN aware sys */
27964562Sgshapiro#define QEXPANDED	0x00000800	/* DSN: undergone list expansion */
28064562Sgshapiro#define QDELIVERED	0x00001000	/* DSN: successful final delivery */
28164562Sgshapiro#define QDELAYED	0x00002000	/* DSN: message delayed */
28264562Sgshapiro#define QALIAS		0x00004000	/* expanded alias */
28390792Sgshapiro#define QBYTRACE	0x00008000	/* DeliverBy: trace */
28490792Sgshapiro#define QBYNDELAY	0x00010000	/* DeliverBy: notify, delay */
28590792Sgshapiro#define QBYNRELAY	0x00020000	/* DeliverBy: notify, relayed */
28664562Sgshapiro#define QTHISPASS	0x40000000	/* temp: address set this pass */
28764562Sgshapiro#define QRCPTOK		0x80000000	/* recipient() processed address */
28838032Speter
28964562Sgshapiro#define Q_PINGFLAGS	(QPINGONSUCCESS|QPINGONFAILURE|QPINGONDELAY)
29038032Speter
29164562Sgshapiro/* values for q_state */
29264562Sgshapiro#define QS_OK		0		/* address ok (for now)/not yet tried */
29364562Sgshapiro#define QS_SENT		1		/* good address, delivery complete */
29464562Sgshapiro#define QS_BADADDR	2		/* illegal address */
29564562Sgshapiro#define QS_QUEUEUP	3		/* save address in queue */
29690792Sgshapiro#define QS_RETRY	4		/* retry delivery for next MX */
29790792Sgshapiro#define QS_VERIFIED	5		/* verified, but not expanded */
29838032Speter
29990792Sgshapiro/*
30090792Sgshapiro**  Notice: all of the following values are variations of QS_DONTSEND.
30190792Sgshapiro**	If new states are added, they must be inserted in the proper place!
30290792Sgshapiro**	See the macro definition of QS_IS_DEAD() down below.
30390792Sgshapiro*/
30490792Sgshapiro
30590792Sgshapiro#define QS_DONTSEND	6		/* don't send to this address */
30690792Sgshapiro#define QS_EXPANDED	7		/* expanded */
30790792Sgshapiro#define QS_SENDER	8		/* message sender (MeToo) */
30890792Sgshapiro#define QS_CLONED	9		/* addr cloned to split envelope */
30990792Sgshapiro#define QS_DISCARDED	10		/* rcpt discarded (EF_DISCARD) */
31090792Sgshapiro#define QS_REPLACED	11		/* maplocaluser()/UserDB replaced */
31190792Sgshapiro#define QS_REMOVED	12		/* removed (removefromlist()) */
31290792Sgshapiro#define QS_DUPLICATE	13		/* duplicate suppressed */
31390792Sgshapiro#define QS_INCLUDED	14		/* :include: delivery */
314102528Sgshapiro#define QS_FATALERR	15		/* fatal error, don't deliver */
31590792Sgshapiro
31664562Sgshapiro/* address state testing primitives */
31764562Sgshapiro#define QS_IS_OK(s)		((s) == QS_OK)
31864562Sgshapiro#define QS_IS_SENT(s)		((s) == QS_SENT)
31964562Sgshapiro#define QS_IS_BADADDR(s)	((s) == QS_BADADDR)
32064562Sgshapiro#define QS_IS_QUEUEUP(s)	((s) == QS_QUEUEUP)
32190792Sgshapiro#define QS_IS_RETRY(s)		((s) == QS_RETRY)
32264562Sgshapiro#define QS_IS_VERIFIED(s)	((s) == QS_VERIFIED)
32364562Sgshapiro#define QS_IS_EXPANDED(s)	((s) == QS_EXPANDED)
32464562Sgshapiro#define QS_IS_REMOVED(s)	((s) == QS_REMOVED)
32564562Sgshapiro#define QS_IS_UNDELIVERED(s)	((s) == QS_OK || \
32664562Sgshapiro				 (s) == QS_QUEUEUP || \
32790792Sgshapiro				 (s) == QS_RETRY || \
32864562Sgshapiro				 (s) == QS_VERIFIED)
32990792Sgshapiro#define QS_IS_UNMARKED(s)	((s) == QS_OK || \
33090792Sgshapiro				 (s) == QS_RETRY)
33164562Sgshapiro#define QS_IS_SENDABLE(s)	((s) == QS_OK || \
33290792Sgshapiro				 (s) == QS_QUEUEUP || \
33390792Sgshapiro				 (s) == QS_RETRY)
33464562Sgshapiro#define QS_IS_ATTEMPTED(s)	((s) == QS_QUEUEUP || \
33590792Sgshapiro				 (s) == QS_RETRY || \
336173340Sgshapiro				 (s) == QS_SENT || \
337173340Sgshapiro				 (s) == QS_DISCARDED)
33890792Sgshapiro#define QS_IS_DEAD(s)		((s) >= QS_DONTSEND)
339223067Sgshapiro#define QS_IS_TEMPFAIL(s)	((s) == QS_QUEUEUP || (s) == QS_RETRY)
34064562Sgshapiro
34164562Sgshapiro#define NULLADDR	((ADDRESS *) NULL)
34264562Sgshapiro
34364562Sgshapiroextern ADDRESS	NullAddress;	/* a null (template) address [main.c] */
34464562Sgshapiro
34538032Speter/* functions */
346168515Sgshapiroextern void	cataddr __P((char **, char **, char *, int, int, bool));
347111823Sgshapiroextern char	*crackaddr __P((char *, ENVELOPE *));
34864562Sgshapiroextern bool	emptyaddr __P((ADDRESS *));
34964562Sgshapiroextern ADDRESS	*getctladdr __P((ADDRESS *));
35064562Sgshapiroextern int	include __P((char *, bool, ADDRESS *, ADDRESS **, int, ENVELOPE *));
35190792Sgshapiroextern bool	invalidaddr __P((char *, char *, bool));
35290792Sgshapiroextern ADDRESS	*parseaddr __P((char *, ADDRESS *, int, int, char **,
35390792Sgshapiro				ENVELOPE *, bool));
354132943Sgshapiroextern char	**prescan __P((char *, int, char[], int, char **, unsigned char *, bool));
355132943Sgshapiroextern void	printaddr __P((SM_FILE_T *, ADDRESS *, bool));
35638032Speterextern ADDRESS	*recipient __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
35764562Sgshapiroextern char	*remotename __P((char *, MAILER *, int, int *, ENVELOPE *));
35890792Sgshapiroextern int	rewrite __P((char **, int, int, ENVELOPE *, int));
35938032Speterextern bool	sameaddr __P((ADDRESS *, ADDRESS *));
36038032Speterextern int	sendtolist __P((char *, ADDRESS *, ADDRESS **, int, ENVELOPE *));
36190792Sgshapiro#if MILTER
36264562Sgshapiroextern int	removefromlist __P((char *, ADDRESS **, ENVELOPE *));
36390792Sgshapiro#endif /* MILTER */
36464562Sgshapiroextern void	setsender __P((char *, ENVELOPE *, char **, int, bool));
365168515Sgshapirotypedef void esmtp_args_F __P((ADDRESS *, char *, char *, ENVELOPE *));
366168515Sgshapiroextern void	parse_esmtp_args __P((ENVELOPE *, ADDRESS *, char *, char *,
367168515Sgshapiro			char *, char *args[], esmtp_args_F));
368168515Sgshapiroextern esmtp_args_F mail_esmtp_args;
369168515Sgshapiroextern esmtp_args_F rcpt_esmtp_args;
370168515Sgshapiroextern void	reset_mail_esmtp_args __P((ENVELOPE *));
37164562Sgshapiro
37290792Sgshapiro/* macro to simplify the common call to rewrite() */
37390792Sgshapiro#define REWRITE(pvp, rs, env)	rewrite(pvp, rs, 0, env, MAXATOM)
37490792Sgshapiro
37590792Sgshapiro/*
376168515Sgshapiro**  Token Tables for prescan
377168515Sgshapiro*/
378168515Sgshapiro
379168515Sgshapiroextern unsigned char	ExtTokenTab[256];	/* external strings */
380168515Sgshapiroextern unsigned char	IntTokenTab[256];	/* internal strings */
381168515Sgshapiro
382168515Sgshapiro
383168515Sgshapiro/*
38438032Speter**  Mailer definition structure.
38538032Speter**	Every mailer known to the system is declared in this
38638032Speter**	structure.  It defines the pathname of the mailer, some
38738032Speter**	flags associated with it, and the argument vector to
38838032Speter**	pass to it.  The flags are defined in conf.c
38938032Speter**
39038032Speter**	The argument vector is expanded before actual use.  All
39138032Speter**	words except the first are passed through the macro
39238032Speter**	processor.
39338032Speter*/
39438032Speter
39538032Speterstruct mailer
39638032Speter{
39738032Speter	char	*m_name;	/* symbolic name of this mailer */
39838032Speter	char	*m_mailer;	/* pathname of the mailer to use */
39938032Speter	char	*m_mtatype;	/* type of this MTA */
40038032Speter	char	*m_addrtype;	/* type for addresses */
40138032Speter	char	*m_diagtype;	/* type for diagnostics */
40264562Sgshapiro	BITMAP256 m_flags;	/* status flags, see below */
40338032Speter	short	m_mno;		/* mailer number internally */
40438032Speter	short	m_nice;		/* niceness to run at (mostly for prog) */
40538032Speter	char	**m_argv;	/* template argument vector */
40638032Speter	short	m_sh_rwset;	/* rewrite set: sender header addresses */
40738032Speter	short	m_se_rwset;	/* rewrite set: sender envelope addresses */
40838032Speter	short	m_rh_rwset;	/* rewrite set: recipient header addresses */
40938032Speter	short	m_re_rwset;	/* rewrite set: recipient envelope addresses */
41038032Speter	char	*m_eol;		/* end of line string */
41138032Speter	long	m_maxsize;	/* size limit on message to this mailer */
41238032Speter	int	m_linelimit;	/* max # characters per line */
41364562Sgshapiro	int	m_maxdeliveries; /* max deliveries per mailer connection */
41438032Speter	char	*m_execdir;	/* directory to chdir to before execv */
41564562Sgshapiro	char	*m_rootdir;	/* directory to chroot to before execv */
41638032Speter	uid_t	m_uid;		/* UID to run as */
41738032Speter	gid_t	m_gid;		/* GID to run as */
41838032Speter	char	*m_defcharset;	/* default character set */
41964562Sgshapiro	time_t	m_wait;		/* timeout to wait for end */
42064562Sgshapiro	int	m_maxrcpt;	/* max recipients per envelope client-side */
42190792Sgshapiro	short	m_qgrp;		/* queue group for this mailer */
42238032Speter};
42338032Speter
42438032Speter/* bits for m_flags */
42590792Sgshapiro#define M_ESMTP		'a'	/* run Extended SMTP */
42664562Sgshapiro#define M_ALIASABLE	'A'	/* user can be LHS of an alias */
42764562Sgshapiro#define M_BLANKEND	'b'	/* ensure blank line at end of message */
428141858Sgshapiro#define M_STRIPBACKSL	'B'	/* strip all leading backslashes from user */
42964562Sgshapiro#define M_NOCOMMENT	'c'	/* don't include comment part of address */
43064562Sgshapiro#define M_CANONICAL	'C'	/* make addresses canonical "u@dom" */
43164562Sgshapiro#define M_NOBRACKET	'd'	/* never angle bracket envelope route-addrs */
43238032Speter		/*	'D'	   CF: include Date: */
43364562Sgshapiro#define M_EXPENSIVE	'e'	/* it costs to use this mailer.... */
43464562Sgshapiro#define M_ESCFROM	'E'	/* escape From lines to >From */
43564562Sgshapiro#define M_FOPT		'f'	/* mailer takes picky -f flag */
43638032Speter		/*	'F'	   CF: include From: or Resent-From: */
43764562Sgshapiro#define M_NO_NULL_FROM	'g'	/* sender of errors should be $g */
43864562Sgshapiro#define M_HST_UPPER	'h'	/* preserve host case distinction */
43964562Sgshapiro#define M_PREHEAD	'H'	/* MAIL11V3: preview headers */
44064562Sgshapiro#define M_UDBENVELOPE	'i'	/* do udbsender rewriting on envelope */
44164562Sgshapiro#define M_INTERNAL	'I'	/* SMTP to another sendmail site */
44264562Sgshapiro#define M_UDBRECIPIENT	'j'	/* do udbsender rewriting on recipient lines */
44364562Sgshapiro#define M_NOLOOPCHECK	'k'	/* don't check for loops in HELO command */
44464562Sgshapiro#define M_CHUNKING	'K'	/* CHUNKING: reserved for future use */
44564562Sgshapiro#define M_LOCALMAILER	'l'	/* delivery is to this host */
44664562Sgshapiro#define M_LIMITS	'L'	/* must enforce SMTP line limits */
44764562Sgshapiro#define M_MUSER		'm'	/* can handle multiple users at once */
44838032Speter		/*	'M'	   CF: include Message-Id: */
44964562Sgshapiro#define M_NHDR		'n'	/* don't insert From line */
45064562Sgshapiro#define M_MANYSTATUS	'N'	/* MAIL11V3: DATA returns multi-status */
45164562Sgshapiro#define M_RUNASRCPT	'o'	/* always run mailer as recipient */
45264562Sgshapiro#define M_FROMPATH	'p'	/* use reverse-path in MAIL FROM: */
45338032Speter		/*	'P'	   CF: include Return-Path: */
45464562Sgshapiro#define M_VRFY250	'q'	/* VRFY command returns 250 instead of 252 */
45564562Sgshapiro#define M_ROPT		'r'	/* mailer takes picky -r flag */
45664562Sgshapiro#define M_SECURE_PORT	'R'	/* try to send on a reserved TCP port */
45764562Sgshapiro#define M_STRIPQ	's'	/* strip quote chars from user/host */
45864562Sgshapiro#define M_SPECIFIC_UID	'S'	/* run as specific uid/gid */
45964562Sgshapiro#define M_USR_UPPER	'u'	/* preserve user case distinction */
46064562Sgshapiro#define M_UGLYUUCP	'U'	/* this wants an ugly UUCP from line */
46164562Sgshapiro#define M_CONTENT_LEN	'v'	/* add Content-Length: header (SVr4) */
46238032Speter		/*	'V'	   UIUC: !-relativize all addresses */
46364562Sgshapiro#define M_HASPWENT	'w'	/* check for /etc/passwd entry */
464132943Sgshapiro#define M_NOHOSTSTAT	'W'	/* ignore long term host status information */
46538032Speter		/*	'x'	   CF: include Full-Name: */
46664562Sgshapiro#define M_XDOT		'X'	/* use hidden-dot algorithm */
46764562Sgshapiro#define M_LMTP		'z'	/* run Local Mail Transport Protocol */
46890792Sgshapiro#define M_DIALDELAY	'Z'	/* apply dial delay sleeptime */
46964562Sgshapiro#define M_NOMX		'0'	/* turn off MX lookups */
47064562Sgshapiro#define M_NONULLS	'1'	/* don't send null bytes */
47190792Sgshapiro#define M_FSMTP		'2'	/* force SMTP (no ESMTP even if offered) */
47264562Sgshapiro#define M_EBCDIC	'3'	/* extend Q-P encoding for EBCDIC */
47364562Sgshapiro#define M_TRYRULESET5	'5'	/* use ruleset 5 after local aliasing */
47464562Sgshapiro#define M_7BITHDRS	'6'	/* strip headers to 7 bits even in 8 bit path */
47564562Sgshapiro#define M_7BITS		'7'	/* use 7-bit path */
47664562Sgshapiro#define M_8BITS		'8'	/* force "just send 8" behaviour */
47764562Sgshapiro#define M_MAKE8BIT	'9'	/* convert 7 -> 8 bit if appropriate */
47864562Sgshapiro#define M_CHECKINCLUDE	':'	/* check for :include: files */
47964562Sgshapiro#define M_CHECKPROG	'|'	/* check for |program addresses */
48064562Sgshapiro#define M_CHECKFILE	'/'	/* check for /file addresses */
48164562Sgshapiro#define M_CHECKUDB	'@'	/* user can be user database key */
48264562Sgshapiro#define M_CHECKHDIR	'~'	/* SGI: check for valid home directory */
48364562Sgshapiro#define M_HOLD		'%'	/* Hold delivery until ETRN/-qI/-qR/-qS */
48464562Sgshapiro#define M_PLUS		'+'	/* Reserved: Used in mc for adding new flags */
48564562Sgshapiro#define M_MINUS		'-'	/* Reserved: Used in mc for removing flags */
48638032Speter
48764562Sgshapiro/* functions */
48864562Sgshapiroextern void	initerrmailers __P((void));
48964562Sgshapiroextern void	makemailer __P((char *));
49090792Sgshapiroextern void	makequeue __P((char *, bool));
491141858Sgshapiroextern void	runqueueevent __P((int));
49294334Sgshapiro#if _FFR_QUEUE_RUN_PARANOIA
49394334Sgshapiroextern bool	checkqueuerunner __P((void));
49494334Sgshapiro#endif /* _FFR_QUEUE_RUN_PARANOIA */
49538032Speter
49690792SgshapiroEXTERN MAILER	*FileMailer;	/* ptr to *file* mailer */
49790792SgshapiroEXTERN MAILER	*InclMailer;	/* ptr to *include* mailer */
49890792SgshapiroEXTERN MAILER	*LocalMailer;	/* ptr to local mailer */
49990792SgshapiroEXTERN MAILER	*ProgMailer;	/* ptr to program mailer */
50090792SgshapiroEXTERN MAILER	*Mailer[MAXMAILERS + 1];
50190792Sgshapiro
50290792Sgshapiro/*
50390792Sgshapiro**  Queue group definition structure.
50490792Sgshapiro**	Every queue group known to the system is declared in this structure.
50590792Sgshapiro**	It defines the basic pathname of the queue group, some flags
50690792Sgshapiro**	associated with it, and the argument vector to pass to it.
50790792Sgshapiro*/
50890792Sgshapiro
50990792Sgshapirostruct qpaths_s
51090792Sgshapiro{
51190792Sgshapiro	char	*qp_name;	/* name of queue dir, relative path */
51290792Sgshapiro	short	qp_subdirs;	/* use subdirs? */
51390792Sgshapiro	short	qp_fsysidx;	/* file system index of this directory */
51490792Sgshapiro# if SM_CONF_SHM
51590792Sgshapiro	int	qp_idx;		/* index into array for queue information */
51690792Sgshapiro# endif /* SM_CONF_SHM */
51790792Sgshapiro};
51890792Sgshapiro
51990792Sgshapirotypedef struct qpaths_s QPATHS;
52090792Sgshapiro
52190792Sgshapirostruct queuegrp
52290792Sgshapiro{
52390792Sgshapiro	char	*qg_name;	/* symbolic name of this queue group */
52490792Sgshapiro
52590792Sgshapiro	/*
52690792Sgshapiro	**  For now this is the same across all queue groups.
52790792Sgshapiro	**  Otherwise we have to play around with chdir().
52890792Sgshapiro	*/
52990792Sgshapiro
53090792Sgshapiro	char	*qg_qdir;	/* common component of queue directory */
53190792Sgshapiro	short	qg_index;	/* queue number internally, index in Queue[] */
53290792Sgshapiro	int	qg_maxqrun;	/* max # of jobs in 1 queuerun */
53390792Sgshapiro	int	qg_numqueues;	/* number of queues in this queue */
53490792Sgshapiro
53590792Sgshapiro	/*
53690792Sgshapiro	**  qg_queueintvl == 0 denotes that no individual value is used.
53790792Sgshapiro	**  Whatever accesses this must deal with "<= 0" as
53890792Sgshapiro	**  "not set, use appropriate default".
53990792Sgshapiro	*/
54090792Sgshapiro
54190792Sgshapiro	time_t	qg_queueintvl;	/* interval for queue runs */
54290792Sgshapiro	QPATHS	*qg_qpaths;	/* list of queue directories */
54390792Sgshapiro	BITMAP256 qg_flags;	/* status flags, see below */
54490792Sgshapiro	short	qg_nice;	/* niceness for queue run */
54590792Sgshapiro	int	qg_wgrp;	/* Assigned to this work group */
54690792Sgshapiro	int     qg_maxlist;	/* max items in work queue for this group */
54790792Sgshapiro	int     qg_curnum;	/* current number of queue for queue runs */
54890792Sgshapiro	int	qg_maxrcpt;	/* max recipients per envelope, 0==no limit */
54990792Sgshapiro
55094334Sgshapiro	time_t	qg_nextrun;	/* time for next queue runs */
55194334Sgshapiro#if _FFR_QUEUE_GROUP_SORTORDER
55294334Sgshapiro	short	qg_sortorder;	/* how do we sort this queuerun */
55394334Sgshapiro#endif /* _FFR_QUEUE_GROUP_SORTORDER */
55490792Sgshapiro#if 0
55590792Sgshapiro	long	qg_wkrcptfact;	/* multiplier for # recipients -> priority */
55690792Sgshapiro	long	qg_qfactor;	/* slope of queue function */
55790792Sgshapiro	bool	qg_doqueuerun;	/* XXX flag is it time to do a queuerun */
55890792Sgshapiro#endif /* 0 */
55990792Sgshapiro};
56090792Sgshapiro
56190792Sgshapiro/* bits for qg_flags (XXX: unused as of now) */
56290792Sgshapiro#define QD_DEFINED	((char) 1)	/* queue group has been defined */
56390792Sgshapiro#define QD_FORK		'f'	/* fork queue runs */
56490792Sgshapiro
56590792Sgshapiroextern void	filesys_update __P((void));
56690792Sgshapiro#if _FFR_ANY_FREE_FS
56790792Sgshapiroextern bool	filesys_free __P((long));
56890792Sgshapiro#endif /* _FFR_ANY_FREE_FS */
56990792Sgshapiro
57090792Sgshapiro#if SASL
57190792Sgshapiro/*
57290792Sgshapiro**  SASL
57390792Sgshapiro*/
57490792Sgshapiro
57590792Sgshapiro/* lines in authinfo file or index into SASL_AI_T */
57690792Sgshapiro# define SASL_WRONG	(-1)
57790792Sgshapiro# define SASL_USER	0	/* authorization id (user) */
57890792Sgshapiro# define SASL_AUTHID	1	/* authentication id */
57990792Sgshapiro# define SASL_PASSWORD	2	/* password fuer authid */
58090792Sgshapiro# define SASL_DEFREALM	3	/* realm to use */
58190792Sgshapiro# define SASL_MECHLIST	4	/* list of mechanisms to try */
58290792Sgshapiro# define SASL_ID_REALM	5	/* authid@defrealm */
58390792Sgshapiro
58490792Sgshapiro/*
58590792Sgshapiro**  Current mechanism; this is just used to convey information between
58690792Sgshapiro**  invocation of SASL callback functions.
58790792Sgshapiro**  It must be last in the list, because it's not allocated by us
58890792Sgshapiro**  and hence we don't free() it.
58990792Sgshapiro*/
59090792Sgshapiro# define SASL_MECH	6
59190792Sgshapiro# define SASL_ENTRIES	7	/* number of entries in array */
59290792Sgshapiro
59390792Sgshapiro# define SASL_USER_BIT		(1 << SASL_USER)
59490792Sgshapiro# define SASL_AUTHID_BIT	(1 << SASL_AUTHID)
59590792Sgshapiro# define SASL_PASSWORD_BIT	(1 << SASL_PASSWORD)
59690792Sgshapiro# define SASL_DEFREALM_BIT	(1 << SASL_DEFREALM)
59790792Sgshapiro# define SASL_MECHLIST_BIT	(1 << SASL_MECHLIST)
59890792Sgshapiro
59990792Sgshapiro/* authenticated? */
60090792Sgshapiro# define SASL_NOT_AUTH	0		/* not authenticated */
60190792Sgshapiro# define SASL_PROC_AUTH	1		/* in process of authenticating */
60290792Sgshapiro# define SASL_IS_AUTH	2		/* authenticated */
60390792Sgshapiro
60490792Sgshapiro/* SASL options */
60590792Sgshapiro# define SASL_AUTH_AUTH	0x1000		/* use auth= only if authenticated */
60698121Sgshapiro# if SASL >= 20101
60798121Sgshapiro#  define SASL_SEC_MASK	SASL_SEC_MAXIMUM /* mask for SASL_SEC_* values: sasl.h */
60898121Sgshapiro# else /* SASL >= 20101 */
60998121Sgshapiro#  define SASL_SEC_MASK	0x0fff		/* mask for SASL_SEC_* values: sasl.h */
61098121Sgshapiro#  if (SASL_SEC_NOPLAINTEXT & SASL_SEC_MASK) == 0 || \
61190792Sgshapiro	(SASL_SEC_NOACTIVE & SASL_SEC_MASK) == 0 || \
61290792Sgshapiro	(SASL_SEC_NODICTIONARY & SASL_SEC_MASK) == 0 || \
61390792Sgshapiro	(SASL_SEC_FORWARD_SECRECY & SASL_SEC_MASK) == 0 || \
61490792Sgshapiro	(SASL_SEC_NOANONYMOUS & SASL_SEC_MASK) == 0 || \
61590792Sgshapiro	(SASL_SEC_PASS_CREDENTIALS & SASL_SEC_MASK) == 0
61690792SgshapiroERROR: change SASL_SEC_MASK_ notify sendmail.org!
61790792Sgshapiro#  endif /* SASL_SEC_NOPLAINTEXT & SASL_SEC_MASK) == 0 ... */
61898121Sgshapiro# endif /* SASL >= 20101 */
619203004Sgshapiro# define MAXOUTLEN 8192	/* length of output buffer, should be 2^n */
62090792Sgshapiro
62190792Sgshapiro/* functions */
62290792Sgshapiroextern char	*intersect __P((char *, char *, SM_RPOOL_T *));
62390792Sgshapiroextern char	*iteminlist __P((char *, char *, char *));
62498121Sgshapiro# if SASL >= 20000
62598121Sgshapiroextern int	proxy_policy __P((sasl_conn_t *, void *, const char *, unsigned, const char *, unsigned, const char *, unsigned, struct propctx *));
62698121Sgshapiroextern int	safesaslfile __P((void *, const char *, sasl_verify_type_t));
62798121Sgshapiro# else /* SASL >= 20000 */
62890792Sgshapiroextern int	proxy_policy __P((void *, const char *, const char *, const char **, const char **));
62998121Sgshapiro#  if SASL > 10515
63090792Sgshapiroextern int	safesaslfile __P((void *, char *, int));
63198121Sgshapiro#  else /* SASL > 10515 */
63290792Sgshapiroextern int	safesaslfile __P((void *, char *));
63398121Sgshapiro#  endif /* SASL > 10515 */
63498121Sgshapiro# endif /* SASL >= 20000 */
63590792Sgshapiroextern void	stop_sasl_client __P((void));
63690792Sgshapiro
63790792Sgshapiro/* structure to store authinfo */
63890792Sgshapirotypedef char *SASL_AI_T[SASL_ENTRIES];
63990792Sgshapiro
64090792SgshapiroEXTERN char	*AuthMechanisms;	/* AUTH mechanisms */
641132943SgshapiroEXTERN char	*AuthRealm;	/* AUTH realm */
64290792SgshapiroEXTERN char	*SASLInfo;	/* file with AUTH info */
64390792SgshapiroEXTERN int	SASLOpts;	/* options for SASL */
64490792SgshapiroEXTERN int	MaxSLBits;	/* max. encryption bits for SASL */
64590792Sgshapiro#endif /* SASL */
64690792Sgshapiro
64790792Sgshapiro/*
64890792Sgshapiro**  Structure to store macros.
64990792Sgshapiro*/
65090792Sgshapirotypedef struct
65190792Sgshapiro{
65290792Sgshapiro	SM_RPOOL_T	*mac_rpool;		/* resource pool */
65390792Sgshapiro	BITMAP256	mac_allocated;		/* storage has been alloc()? */
65490792Sgshapiro	char		*mac_table[MAXMACROID + 1];	/* macros */
65590792Sgshapiro} MACROS_T;
65690792Sgshapiro
65790792SgshapiroEXTERN MACROS_T		GlobalMacros;
65890792Sgshapiro
65990792Sgshapiro/*
66038032Speter**  Information about currently open connections to mailers, or to
66138032Speter**  hosts that we have looked up recently.
66238032Speter*/
66338032Speter
66464562Sgshapiro#define MCI		struct mailer_con_info
66538032Speter
66638032SpeterMCI
66738032Speter{
66890792Sgshapiro	unsigned long	mci_flags;	/* flag bits, see below */
66938032Speter	short		mci_errno;	/* error number on last connection */
67038032Speter	short		mci_herrno;	/* h_errno from last DNS lookup */
67138032Speter	short		mci_exitstat;	/* exit status from last connection */
67238032Speter	short		mci_state;	/* SMTP state */
67364562Sgshapiro	int		mci_deliveries;	/* delivery attempts for connection */
67438032Speter	long		mci_maxsize;	/* max size this server will accept */
67590792Sgshapiro	SM_FILE_T	*mci_in;	/* input side of connection */
67690792Sgshapiro	SM_FILE_T	*mci_out;	/* output side of connection */
67738032Speter	pid_t		mci_pid;	/* process id of subordinate proc */
67838032Speter	char		*mci_phase;	/* SMTP phase string */
67938032Speter	struct mailer	*mci_mailer;	/* ptr to the mailer for this conn */
68038032Speter	char		*mci_host;	/* host name */
68138032Speter	char		*mci_status;	/* DSN status to be copied to addrs */
68238032Speter	char		*mci_rstatus;	/* SMTP status to be copied to addrs */
68338032Speter	time_t		mci_lastuse;	/* last usage time */
68490792Sgshapiro	SM_FILE_T	*mci_statfile;	/* long term status file */
68564562Sgshapiro	char		*mci_heloname;	/* name to use as HELO arg */
68690792Sgshapiro	long		mci_min_by;	/* minimum DELIVERBY */
68790792Sgshapiro	bool		mci_retryrcpt;	/* tempfail for at least one rcpt */
68890792Sgshapiro	char		*mci_tolist;	/* list of valid recipients */
68990792Sgshapiro	SM_RPOOL_T	*mci_rpool;	/* resource pool */
69090792Sgshapiro#if PIPELINING
69190792Sgshapiro	int		mci_okrcpts;	/* number of valid recipients */
69290792Sgshapiro	ADDRESS		*mci_nextaddr;	/* next address for pipelined status */
69390792Sgshapiro#endif /* PIPELINING */
69464562Sgshapiro#if SASL
69590792Sgshapiro	SASL_AI_T	mci_sai;	/* authentication info */
69664562Sgshapiro	bool		mci_sasl_auth;	/* authenticated? */
69764562Sgshapiro	int		mci_sasl_string_len;
69864562Sgshapiro	char		*mci_sasl_string;	/* sasl reply string */
69964562Sgshapiro	char		*mci_saslcap;	/* SASL list of mechanisms */
70064562Sgshapiro	sasl_conn_t	*mci_conn;	/* SASL connection */
70164562Sgshapiro#endif /* SASL */
70264562Sgshapiro#if STARTTLS
70364562Sgshapiro	SSL		*mci_ssl;	/* SSL connection */
70464562Sgshapiro#endif /* STARTTLS */
70590792Sgshapiro	MACROS_T	mci_macro;	/* macro definitions */
70638032Speter};
70738032Speter
70838032Speter
70938032Speter/* flag bits */
71064562Sgshapiro#define MCIF_VALID	0x00000001	/* this entry is valid */
71190792Sgshapiro/* 0x00000002 unused, was MCIF_TEMP */
71264562Sgshapiro#define MCIF_CACHED	0x00000004	/* currently in open cache */
71364562Sgshapiro#define MCIF_ESMTP	0x00000008	/* this host speaks ESMTP */
71464562Sgshapiro#define MCIF_EXPN	0x00000010	/* EXPN command supported */
71564562Sgshapiro#define MCIF_SIZE	0x00000020	/* SIZE option supported */
71664562Sgshapiro#define MCIF_8BITMIME	0x00000040	/* BODY=8BITMIME supported */
71764562Sgshapiro#define MCIF_7BIT	0x00000080	/* strip this message to 7 bits */
71894334Sgshapiro/* 0x00000100 unused, was MCIF_MULTSTAT: MAIL11V3: handles MULT status */
71964562Sgshapiro#define MCIF_INHEADER	0x00000200	/* currently outputing header */
72064562Sgshapiro#define MCIF_CVT8TO7	0x00000400	/* convert from 8 to 7 bits */
72164562Sgshapiro#define MCIF_DSN	0x00000800	/* DSN extension supported */
72264562Sgshapiro#define MCIF_8BITOK	0x00001000	/* OK to send 8 bit characters */
72364562Sgshapiro#define MCIF_CVT7TO8	0x00002000	/* convert from 7 to 8 bits */
72464562Sgshapiro#define MCIF_INMIME	0x00004000	/* currently reading MIME header */
72564562Sgshapiro#define MCIF_AUTH	0x00008000	/* AUTH= supported */
72664562Sgshapiro#define MCIF_AUTHACT	0x00010000	/* SASL (AUTH) active */
72764562Sgshapiro#define MCIF_ENHSTAT	0x00020000	/* ENHANCEDSTATUSCODES supported */
72890792Sgshapiro#define MCIF_PIPELINED	0x00040000	/* PIPELINING supported */
729110560Sgshapiro#define MCIF_VERB	0x00080000	/* VERB supported */
73064562Sgshapiro#if STARTTLS
73164562Sgshapiro#define MCIF_TLS	0x00100000	/* STARTTLS supported */
73264562Sgshapiro#define MCIF_TLSACT	0x00200000	/* STARTTLS active */
73364562Sgshapiro#else /* STARTTLS */
734223067Sgshapiro#define MCIF_TLS	0
735223067Sgshapiro#define MCIF_TLSACT	0
73664562Sgshapiro#endif /* STARTTLS */
73790792Sgshapiro#define MCIF_DLVR_BY	0x00400000	/* DELIVERBY */
73890792Sgshapiro#if _FFR_IGNORE_EXT_ON_HELO
73990792Sgshapiro# define MCIF_HELO	0x00800000	/* we used HELO: ignore extensions */
74090792Sgshapiro#endif /* _FFR_IGNORE_EXT_ON_HELO */
741173340Sgshapiro#define MCIF_INLONGLINE 0x01000000	/* in the middle of a long line */
742223067Sgshapiro#define MCIF_AUTH2	0x02000000	/* got 2 AUTH lines */
74371345Sgshapiro#define MCIF_ONLY_EHLO	0x10000000	/* use only EHLO in smtpinit */
74438032Speter
745223067Sgshapiro#define MCIF_EXTENS	(MCIF_EXPN | MCIF_SIZE | MCIF_8BITMIME | MCIF_DSN | MCIF_8BITOK | MCIF_AUTH | MCIF_ENHSTAT | MCIF_TLS | MCIF_AUTH2)
746223067Sgshapiro
74738032Speter/* states */
74838032Speter#define MCIS_CLOSED	0		/* no traffic on this connection */
74938032Speter#define MCIS_OPENING	1		/* sending initial protocol */
75038032Speter#define MCIS_OPEN	2		/* open, initial protocol sent */
75190792Sgshapiro#define MCIS_MAIL	3		/* MAIL command sent */
75290792Sgshapiro#define MCIS_RCPT	4		/* RCPT commands being sent */
75390792Sgshapiro#define MCIS_DATA	5		/* DATA command sent */
75490792Sgshapiro#define MCIS_QUITING	6		/* running quit protocol */
75590792Sgshapiro#define MCIS_SSD	7		/* service shutting down */
75690792Sgshapiro#define MCIS_ERROR	8		/* I/O error on connection */
75738032Speter
75838032Speter/* functions */
75938032Speterextern void	mci_cache __P((MCI *));
760141867Sgshapiroextern void	mci_close __P((MCI *, char *where));
761132943Sgshapiroextern void	mci_dump __P((SM_FILE_T *, MCI *, bool));
762132943Sgshapiroextern void	mci_dump_all __P((SM_FILE_T *, bool));
76364562Sgshapiroextern void	mci_flush __P((bool, MCI *));
764223067Sgshapiroextern void	mci_clr_extensions __P((MCI *));
76564562Sgshapiroextern MCI	*mci_get __P((char *, MAILER *));
76664562Sgshapiroextern int	mci_lock_host __P((MCI *));
76764562Sgshapiroextern bool	mci_match __P((char *, MAILER *));
76838032Speterextern int	mci_print_persistent __P((char *, char *));
76938032Speterextern int	mci_purge_persistent __P((char *, char *));
77064562Sgshapiroextern MCI	**mci_scan __P((MCI *));
77164562Sgshapiroextern void	mci_setstat __P((MCI *, int, char *, char *));
77264562Sgshapiroextern void	mci_store_persistent __P((MCI *));
773168515Sgshapiroextern int	mci_traverse_persistent __P((int (*)(char *, char *), char *));
77438032Speterextern void	mci_unlock_host __P((MCI *));
77564562Sgshapiro
77690792SgshapiroEXTERN int	MaxMciCache;		/* maximum entries in MCI cache */
77790792SgshapiroEXTERN time_t	MciCacheTimeout;	/* maximum idle time on connections */
77890792SgshapiroEXTERN time_t	MciInfoTimeout;		/* how long 'til we retry down hosts */
77990792Sgshapiro
78090792Sgshapiro/*
78138032Speter**  Header structure.
78238032Speter**	This structure is used internally to store header items.
78338032Speter*/
78438032Speter
78538032Speterstruct header
78638032Speter{
78738032Speter	char		*h_field;	/* the name of the field */
78838032Speter	char		*h_value;	/* the value of that field */
78938032Speter	struct header	*h_link;	/* the next header */
79090792Sgshapiro	unsigned char	h_macro;	/* include header if macro defined */
79190792Sgshapiro	unsigned long	h_flags;	/* status bits, see below */
79264562Sgshapiro	BITMAP256	h_mflags;	/* m_flags bits needed */
79338032Speter};
79438032Speter
79538032Spetertypedef struct header	HDR;
79638032Speter
79738032Speter/*
79838032Speter**  Header information structure.
79938032Speter**	Defined in conf.c, this struct declares the header fields
80038032Speter**	that have some magic meaning.
80138032Speter*/
80238032Speter
80338032Speterstruct hdrinfo
80438032Speter{
80590792Sgshapiro	char		*hi_field;	/* the name of the field */
80690792Sgshapiro	unsigned long	hi_flags;	/* status bits, see below */
80790792Sgshapiro	char		*hi_ruleset;	/* validity check ruleset */
80838032Speter};
80938032Speter
81038032Speterextern struct hdrinfo	HdrInfo[];
81138032Speter
81238032Speter/* bits for h_flags and hi_flags */
81364562Sgshapiro#define H_EOH		0x00000001	/* field terminates header */
81464562Sgshapiro#define H_RCPT		0x00000002	/* contains recipient addresses */
81564562Sgshapiro#define H_DEFAULT	0x00000004	/* if another value is found, drop this */
81664562Sgshapiro#define H_RESENT	0x00000008	/* this address is a "Resent-..." address */
81764562Sgshapiro#define H_CHECK		0x00000010	/* check h_mflags against m_flags */
81864562Sgshapiro#define H_ACHECK	0x00000020	/* ditto, but always (not just default) */
81964562Sgshapiro#define H_FORCE		0x00000040	/* force this field, even if default */
82064562Sgshapiro#define H_TRACE		0x00000080	/* this field contains trace information */
82164562Sgshapiro#define H_FROM		0x00000100	/* this is a from-type field */
82264562Sgshapiro#define H_VALID		0x00000200	/* this field has a validated value */
82364562Sgshapiro#define H_RECEIPTTO	0x00000400	/* field has return receipt info */
82464562Sgshapiro#define H_ERRORSTO	0x00000800	/* field has error address info */
82564562Sgshapiro#define H_CTE		0x00001000	/* field is a content-transfer-encoding */
82664562Sgshapiro#define H_CTYPE		0x00002000	/* this is a content-type field */
82764562Sgshapiro#define H_BCC		0x00004000	/* Bcc: header: strip value or delete */
82864562Sgshapiro#define H_ENCODABLE	0x00008000	/* field can be RFC 1522 encoded */
82964562Sgshapiro#define H_STRIPCOMM	0x00010000	/* header check: strip comments */
83064562Sgshapiro#define H_BINDLATE	0x00020000	/* only expand macros at deliver */
83164562Sgshapiro#define H_USER		0x00040000	/* header came from the user/SMTP */
83238032Speter
83364562Sgshapiro/* bits for chompheader() */
83464562Sgshapiro#define CHHDR_DEF	0x0001	/* default header */
83564562Sgshapiro#define CHHDR_CHECK	0x0002	/* call ruleset for header */
83664562Sgshapiro#define CHHDR_USER	0x0004	/* header from user */
83790792Sgshapiro#define CHHDR_QUEUE	0x0008	/* header from queue file */
83864562Sgshapiro
83938032Speter/* functions */
840168515Sgshapiroextern void	addheader __P((char *, char *, int, ENVELOPE *, bool));
84190792Sgshapiroextern unsigned long	chompheader __P((char *, int, HDR **, ENVELOPE *));
842173340Sgshapiroextern bool	commaize __P((HDR *, char *, bool, MCI *, ENVELOPE *, int));
84390792Sgshapiroextern HDR	*copyheader __P((HDR *, SM_RPOOL_T *));
84490792Sgshapiroextern void	eatheader __P((ENVELOPE *, bool, bool));
84564562Sgshapiroextern char	*hvalue __P((char *, HDR *));
846168515Sgshapiroextern void	insheader __P((int, char *, char *, int, ENVELOPE *, bool));
84764562Sgshapiroextern bool	isheader __P((char *));
848157001Sgshapiroextern bool	putfromline __P((MCI *, ENVELOPE *));
84964562Sgshapiroextern void	setupheaders __P((void));
85064562Sgshapiro
85190792Sgshapiro/*
85264562Sgshapiro**  Performance monitoring
85364562Sgshapiro*/
85464562Sgshapiro
85564562Sgshapiro#define TIMERS		struct sm_timers
85664562Sgshapiro
85764562SgshapiroTIMERS
85864562Sgshapiro{
85964562Sgshapiro	TIMER	ti_overall;	/* the whole process */
86064562Sgshapiro};
86164562Sgshapiro
86264562Sgshapiro
86364562Sgshapiro#define PUSHTIMER(l, t)	{ if (tTd(98, l)) pushtimer(&t); }
86464562Sgshapiro#define POPTIMER(l, t)	{ if (tTd(98, l)) poptimer(&t); }
86564562Sgshapiro
86690792Sgshapiro/*
86738032Speter**  Envelope structure.
86838032Speter**	This structure defines the message itself.  There is usually
86938032Speter**	only one of these -- for the message that we originally read
87038032Speter**	and which is our primary interest -- but other envelopes can
87138032Speter**	be generated during processing.  For example, error messages
87238032Speter**	will have their own envelope.
87338032Speter*/
87438032Speter
87538032Speterstruct envelope
87638032Speter{
87738032Speter	HDR		*e_header;	/* head of header list */
87838032Speter	long		e_msgpriority;	/* adjusted priority of this message */
87938032Speter	time_t		e_ctime;	/* time message appeared in the queue */
88090792Sgshapiro	char		*e_to;		/* (list of) target person(s) */
88138032Speter	ADDRESS		e_from;		/* the person it is from */
88238032Speter	char		*e_sender;	/* e_from.q_paddr w comments stripped */
88338032Speter	char		**e_fromdomain;	/* the domain part of the sender */
88438032Speter	ADDRESS		*e_sendqueue;	/* list of message recipients */
88538032Speter	ADDRESS		*e_errorqueue;	/* the queue for error responses */
88666494Sgshapiro
88766494Sgshapiro	/*
88866494Sgshapiro	**  Overflow detection is based on < 0, so don't change this
88966494Sgshapiro	**  to unsigned.  We don't use unsigned and == ULONG_MAX because
89066494Sgshapiro	**  some libc's don't have strtoul(), see mail_esmtp_args().
89166494Sgshapiro	*/
89290792Sgshapiro
89338032Speter	long		e_msgsize;	/* size of the message in bytes */
89490792Sgshapiro	char		*e_msgid;	/* message id (for logging) */
89590792Sgshapiro	unsigned long	e_flags;	/* flags, see below */
89638032Speter	int		e_nrcpts;	/* number of recipients */
89738032Speter	short		e_class;	/* msg class (priority, junk, etc.) */
89838032Speter	short		e_hopcount;	/* number of times processed */
89938032Speter	short		e_nsent;	/* number of sends since checkpoint */
90038032Speter	short		e_sendmode;	/* message send mode */
90138032Speter	short		e_errormode;	/* error return mode */
90238032Speter	short		e_timeoutclass;	/* message timeout class */
903157001Sgshapiro	bool		(*e_puthdr)__P((MCI *, HDR *, ENVELOPE *, int));
90438032Speter					/* function to put header of message */
905157001Sgshapiro	bool		(*e_putbody)__P((MCI *, ENVELOPE *, char *));
90638032Speter					/* function to put body of message */
90764562Sgshapiro	ENVELOPE	*e_parent;	/* the message this one encloses */
90864562Sgshapiro	ENVELOPE	*e_sibling;	/* the next envelope of interest */
90938032Speter	char		*e_bodytype;	/* type of message body */
91090792Sgshapiro	SM_FILE_T	*e_dfp;		/* data file */
91138032Speter	char		*e_id;		/* code for this entry in queue */
912173340Sgshapiro#if _FFR_SESSID
913173340Sgshapiro	char		*e_sessid;	/* session ID for this envelope */
914173340Sgshapiro#endif /* _FFR_SESSID */
91590792Sgshapiro	int		e_qgrp;		/* queue group (index into queues) */
91690792Sgshapiro	int		e_qdir;		/* index into queue directories */
91790792Sgshapiro	int		e_dfqgrp;	/* data file queue group index */
91890792Sgshapiro	int		e_dfqdir;	/* data file queue directory index */
91990792Sgshapiro	int		e_xfqgrp;	/* queue group (index into queues) */
92090792Sgshapiro	int		e_xfqdir;	/* index into queue directories (xf) */
92190792Sgshapiro	SM_FILE_T	*e_xfp;		/* transcript file */
92290792Sgshapiro	SM_FILE_T	*e_lockfp;	/* the lock file for this message */
923168515Sgshapiro	char		*e_message;	/* error message; readonly; NULL,
924168515Sgshapiro					 * or allocated from e_rpool */
92590792Sgshapiro	char		*e_statmsg;	/* stat msg (changes per delivery).
92690792Sgshapiro					 * readonly. NULL or allocated from
92790792Sgshapiro					 * e_rpool. */
92890792Sgshapiro	char		*e_quarmsg;	/* why envelope is quarantined */
92990792Sgshapiro	char		e_qfletter;	/* queue file letter on disk */
93038032Speter	char		*e_msgboundary;	/* MIME-style message part boundary */
93138032Speter	char		*e_origrcpt;	/* original recipient (one only) */
93238032Speter	char		*e_envid;	/* envelope id from MAIL FROM: line */
93338032Speter	char		*e_status;	/* DSN status for this message */
93438032Speter	time_t		e_dtime;	/* time of last delivery attempt */
93538032Speter	int		e_ntries;	/* number of delivery attempts */
93690792Sgshapiro	dev_t		e_dfdev;	/* data file device (crash recovery) */
93790792Sgshapiro	ino_t		e_dfino;	/* data file inode (crash recovery) */
93890792Sgshapiro	MACROS_T	e_macro;	/* macro definitions */
93990792Sgshapiro	MCI		*e_mci;		/* connection info */
94090792Sgshapiro	char		*e_auth_param;	/* readonly; NULL or static storage or
94190792Sgshapiro					 * allocated from e_rpool */
94264562Sgshapiro	TIMERS		e_timers;	/* per job timers */
94390792Sgshapiro	long		e_deliver_by;	/* deliver by */
94490792Sgshapiro	int		e_dlvr_flag;	/* deliver by flag */
94590792Sgshapiro	SM_RPOOL_T	*e_rpool;	/* resource pool for this envelope */
946168515Sgshapiro	unsigned int	e_features;	/* server features */
947203004Sgshapiro#if _FFR_MILTER_ENHSC
948203004Sgshapiro#define ENHSC_LEN	11
949203004Sgshapiro	char		e_enhsc[ENHSC_LEN];	/* enhanced status code */
950203004Sgshapiro#endif /* _FFR_MILTER_ENHSC */
95138032Speter};
95238032Speter
953244833Sgshapiro#define PRT_NONNEGL(v)	((v) < 0 ? LONG_MAX : (v))
954244833Sgshapiro
95538032Speter/* values for e_flags */
956102528Sgshapiro#define EF_OLDSTYLE	0x00000001L	/* use spaces (not commas) in hdrs */
957102528Sgshapiro#define EF_INQUEUE	0x00000002L	/* this message is fully queued */
958102528Sgshapiro#define EF_NO_BODY_RETN	0x00000004L	/* omit message body on error */
959102528Sgshapiro#define EF_CLRQUEUE	0x00000008L	/* disk copy is no longer needed */
960102528Sgshapiro#define EF_SENDRECEIPT	0x00000010L	/* send a return receipt */
961102528Sgshapiro#define EF_FATALERRS	0x00000020L	/* fatal errors occurred */
962102528Sgshapiro#define EF_DELETE_BCC	0x00000040L	/* delete Bcc: headers entirely */
963102528Sgshapiro#define EF_RESPONSE	0x00000080L	/* this is an error or return receipt */
964102528Sgshapiro#define EF_RESENT	0x00000100L	/* this message is being forwarded */
965102528Sgshapiro#define EF_VRFYONLY	0x00000200L	/* verify only (don't expand aliases) */
966102528Sgshapiro#define EF_WARNING	0x00000400L	/* warning message has been sent */
967102528Sgshapiro#define EF_QUEUERUN	0x00000800L	/* this envelope is from queue */
968102528Sgshapiro#define EF_GLOBALERRS	0x00001000L	/* treat errors as global */
969102528Sgshapiro#define EF_PM_NOTIFY	0x00002000L	/* send return mail to postmaster */
970102528Sgshapiro#define EF_METOO	0x00004000L	/* send to me too */
971102528Sgshapiro#define EF_LOGSENDER	0x00008000L	/* need to log the sender */
972102528Sgshapiro#define EF_NORECEIPT	0x00010000L	/* suppress all return-receipts */
973102528Sgshapiro#define EF_HAS8BIT	0x00020000L	/* at least one 8-bit char in body */
974102528Sgshapiro#define EF_NL_NOT_EOL	0x00040000L	/* don't accept raw NL as EOLine */
975102528Sgshapiro#define EF_CRLF_NOT_EOL	0x00080000L	/* don't accept CR-LF as EOLine */
976102528Sgshapiro#define EF_RET_PARAM	0x00100000L	/* RCPT command had RET argument */
977102528Sgshapiro#define EF_HAS_DF	0x00200000L	/* set when data file is instantiated */
978102528Sgshapiro#define EF_IS_MIME	0x00400000L	/* really is a MIME message */
979102528Sgshapiro#define EF_DONT_MIME	0x00800000L	/* never MIME this message */
980102528Sgshapiro#define EF_DISCARD	0x01000000L	/* discard the message */
981102528Sgshapiro#define EF_TOOBIG	0x02000000L	/* message is too big */
982102528Sgshapiro#define EF_SPLIT	0x04000000L	/* envelope has been split */
983102528Sgshapiro#define EF_UNSAFE	0x08000000L	/* unsafe: read from untrusted source */
984159609Sgshapiro#define EF_TOODEEP	0x10000000L	/* message is nested too deep */
98538032Speter
98690792Sgshapiro#define DLVR_NOTIFY	0x01
98790792Sgshapiro#define DLVR_RETURN	0x02
98890792Sgshapiro#define DLVR_TRACE	0x10
98990792Sgshapiro#define IS_DLVR_NOTIFY(e)	(((e)->e_dlvr_flag & DLVR_NOTIFY) != 0)
99090792Sgshapiro#define IS_DLVR_RETURN(e)	(((e)->e_dlvr_flag & DLVR_RETURN) != 0)
99190792Sgshapiro#define IS_DLVR_TRACE(e)	(((e)->e_dlvr_flag & DLVR_TRACE) != 0)
99290792Sgshapiro#define IS_DLVR_BY(e)		((e)->e_dlvr_flag != 0)
99338032Speter
99490792Sgshapiro#define BODYTYPE_NONE	(0)
99590792Sgshapiro#define BODYTYPE_7BIT	(1)
99690792Sgshapiro#define BODYTYPE_8BITMIME	(2)
99790792Sgshapiro#define BODYTYPE_ILLEGAL	(-1)
99890792Sgshapiro#define BODYTYPE_VALID(b) ((b) == BODYTYPE_7BIT || (b) == BODYTYPE_8BITMIME)
99990792Sgshapiro
100090792Sgshapiroextern ENVELOPE	BlankEnvelope;
100190792Sgshapiro
100238032Speter/* functions */
100390792Sgshapiroextern void	clearenvelope __P((ENVELOPE *, bool, SM_RPOOL_T *));
1004203004Sgshapiroextern int	dropenvelope __P((ENVELOPE *, bool, bool));
100590792Sgshapiroextern ENVELOPE	*newenvelope __P((ENVELOPE *, ENVELOPE *, SM_RPOOL_T *));
1006110560Sgshapiroextern void	clrsessenvelope __P((ENVELOPE *));
100764562Sgshapiroextern void	printenvflags __P((ENVELOPE *));
1008157001Sgshapiroextern bool	putbody __P((MCI *, ENVELOPE *, char *));
1009157001Sgshapiroextern bool	putheader __P((MCI *, HDR *, ENVELOPE *, int));
101038032Speter
101190792Sgshapiro/*
101238032Speter**  Message priority classes.
101338032Speter**
101438032Speter**	The message class is read directly from the Priority: header
101538032Speter**	field in the message.
101638032Speter**
101738032Speter**	CurEnv->e_msgpriority is the number of bytes in the message plus
101838032Speter**	the creation time (so that jobs ``tend'' to be ordered correctly),
101938032Speter**	adjusted by the message class, the number of recipients, and the
102038032Speter**	amount of time the message has been sitting around.  This number
102138032Speter**	is used to order the queue.  Higher values mean LOWER priority.
102238032Speter**
102338032Speter**	Each priority class point is worth WkClassFact priority points;
102438032Speter**	each recipient is worth WkRecipFact priority points.  Each time
102538032Speter**	we reprocess a message the priority is adjusted by WkTimeFact.
102638032Speter**	WkTimeFact should normally decrease the priority so that jobs
102738032Speter**	that have historically failed will be run later; thanks go to
102838032Speter**	Jay Lepreau at Utah for pointing out the error in my thinking.
102938032Speter**
103038032Speter**	The "class" is this number, unadjusted by the age or size of
103138032Speter**	this message.  Classes with negative representations will have
103238032Speter**	error messages thrown away if they are not local.
103338032Speter*/
103438032Speter
103538032Speterstruct priority
103638032Speter{
103738032Speter	char	*pri_name;	/* external name of priority */
103838032Speter	int	pri_val;	/* internal value for same */
103938032Speter};
104038032Speter
104190792SgshapiroEXTERN int	NumPriorities;	/* pointer into Priorities */
104290792SgshapiroEXTERN struct priority	Priorities[MAXPRIORITIES];
104390792Sgshapiro
104490792Sgshapiro/*
104538032Speter**  Rewrite rules.
104638032Speter*/
104738032Speter
104838032Speterstruct rewrite
104938032Speter{
105038032Speter	char	**r_lhs;	/* pattern match */
105138032Speter	char	**r_rhs;	/* substitution value */
105238032Speter	struct rewrite	*r_next;/* next in chain */
105364562Sgshapiro	int	r_line;		/* rule line in sendmail.cf */
105438032Speter};
105538032Speter
105638032Speter/*
105738032Speter**  Special characters in rewriting rules.
105838032Speter**	These are used internally only.
105938032Speter**	The COND* rules are actually used in macros rather than in
106038032Speter**		rewriting rules, but are given here because they
106138032Speter**		cannot conflict.
106238032Speter*/
106338032Speter
1064168515Sgshapiro/* "out of band" indicator */
1065168515Sgshapiro/* sm/sendmail.h #define METAQUOTE ((unsigned char)0377) quotes the next octet */
1066168515Sgshapiro
106738032Speter/* left hand side items */
106890792Sgshapiro#define MATCHZANY	((unsigned char)0220)	/* match zero or more tokens */
106990792Sgshapiro#define MATCHANY	((unsigned char)0221)	/* match one or more tokens */
107090792Sgshapiro#define MATCHONE	((unsigned char)0222)	/* match exactly one token */
107190792Sgshapiro#define MATCHCLASS	((unsigned char)0223)	/* match one token in a class */
1072168515Sgshapiro#define MATCHNCLASS	((unsigned char)0224)	/* match tokens not in class */
107338032Speter
107438032Speter/* right hand side items */
1075168515Sgshapiro#define MATCHREPL	((unsigned char)0225)	/* RHS replacement for above */
107690792Sgshapiro#define CANONNET	((unsigned char)0226)	/* canonical net, next token */
107790792Sgshapiro#define CANONHOST	((unsigned char)0227)	/* canonical host, next token */
107890792Sgshapiro#define CANONUSER	((unsigned char)0230)	/* canonical user, next N tokens */
107990792Sgshapiro#define CALLSUBR	((unsigned char)0231)	/* call another rewriting set */
108038032Speter
1081168515Sgshapiro/* conditionals in macros (anywhere) */
108290792Sgshapiro#define CONDIF		((unsigned char)0232)	/* conditional if-then */
108390792Sgshapiro#define CONDELSE	((unsigned char)0233)	/* conditional else */
108490792Sgshapiro#define CONDFI		((unsigned char)0234)	/* conditional fi */
108538032Speter
1086168515Sgshapiro/* bracket characters for RHS host name lookup */
108790792Sgshapiro#define HOSTBEGIN	((unsigned char)0235)	/* hostname lookup begin */
1088168515Sgshapiro#define HOSTEND		((unsigned char)0236)	/* hostname lookup end */
108938032Speter
1090168515Sgshapiro/* bracket characters for RHS generalized lookup */
109190792Sgshapiro#define LOOKUPBEGIN	((unsigned char)0205)	/* generalized lookup begin */
109290792Sgshapiro#define LOOKUPEND	((unsigned char)0206)	/* generalized lookup end */
109338032Speter
1094168515Sgshapiro/* macro substitution characters (anywhere) */
109590792Sgshapiro#define MACROEXPAND	((unsigned char)0201)	/* macro expansion */
109690792Sgshapiro#define MACRODEXPAND	((unsigned char)0202)	/* deferred macro expansion */
109738032Speter
109838032Speter/* to make the code clearer */
109964562Sgshapiro#define MATCHZERO	CANONHOST
110038032Speter
110182017Sgshapiro#define MAXMATCH	9	/* max params per rewrite */
1102120256Sgshapiro#define MAX_MAP_ARGS	10	/* max arguments for map */
110382017Sgshapiro
110438032Speter/* external <==> internal mapping table */
110538032Speterstruct metamac
110638032Speter{
110790792Sgshapiro	char		metaname;	/* external code (after $) */
110890792Sgshapiro	unsigned char	metaval;	/* internal code (as above) */
110938032Speter};
111038032Speter
111138032Speter/* values for macros with external names only */
111264562Sgshapiro#define MID_OPMODE	0202	/* operation mode */
111338032Speter
111438032Speter/* functions */
111590792Sgshapiro#if SM_HEAP_CHECK
111690792Sgshapiroextern void
111790792Sgshapiromacdefine_tagged __P((
111890792Sgshapiro	MACROS_T *_mac,
111990792Sgshapiro	ARGCLASS_T _vclass,
112090792Sgshapiro	int _id,
112190792Sgshapiro	char *_value,
112290792Sgshapiro	char *_file,
112390792Sgshapiro	int _line,
112490792Sgshapiro	int _group));
112590792Sgshapiro# define macdefine(mac,c,id,v) \
112690792Sgshapiro	macdefine_tagged(mac,c,id,v,__FILE__,__LINE__,sm_heap_group())
112790792Sgshapiro#else /* SM_HEAP_CHECK */
112890792Sgshapiroextern void
112990792Sgshapiromacdefine __P((
113090792Sgshapiro	MACROS_T *_mac,
113190792Sgshapiro	ARGCLASS_T _vclass,
113290792Sgshapiro	int _id,
113390792Sgshapiro	char *_value));
113490792Sgshapiro# define macdefine_tagged(mac,c,id,v,file,line,grp) macdefine(mac,c,id,v)
113590792Sgshapiro#endif /* SM_HEAP_CHECK */
113690792Sgshapiroextern void	macset __P((MACROS_T *, int, char *));
113790792Sgshapiro#define macget(mac, i) (mac)->mac_table[i]
113838032Speterextern void	expand __P((char *, char *, size_t, ENVELOPE *));
113990792Sgshapiroextern int	macid_parse __P((char *, char **));
114090792Sgshapiro#define macid(name)  macid_parse(name, NULL)
114164562Sgshapiroextern char	*macname __P((int));
114238032Speterextern char	*macvalue __P((int, ENVELOPE *));
1143168515Sgshapiroextern int	rscheck __P((char *, char *, char *, ENVELOPE *, int, int, char *, char *, ADDRESS *));
114490792Sgshapiroextern int	rscap __P((char *, char *, char *, ENVELOPE *, char ***, char *, int));
114564562Sgshapiroextern void	setclass __P((int, char *));
114664562Sgshapiroextern int	strtorwset __P((char *, char **, int));
1147168515Sgshapiroextern char	*translate_dollars __P((char *, char *, int *));
114864562Sgshapiroextern bool	wordinclass __P((char *, int));
114964562Sgshapiro
115090792Sgshapiro/*
115138032Speter**  Name canonification short circuit.
115238032Speter**
115338032Speter**	If the name server for a host is down, the process of trying to
115438032Speter**	canonify the name can hang.  This is similar to (but alas, not
115538032Speter**	identical to) looking up the name for delivery.  This stab type
115638032Speter**	caches the result of the name server lookup so we don't hang
115738032Speter**	multiple times.
115838032Speter*/
115938032Speter
116038032Speter#define NAMECANON	struct _namecanon
116138032Speter
116238032SpeterNAMECANON
116338032Speter{
116438032Speter	short		nc_errno;	/* cached errno */
116538032Speter	short		nc_herrno;	/* cached h_errno */
116638032Speter	short		nc_stat;	/* cached exit status code */
116738032Speter	short		nc_flags;	/* flag bits */
116838032Speter	char		*nc_cname;	/* the canonical name */
116990792Sgshapiro	time_t		nc_exp;		/* entry expires at */
117038032Speter};
117138032Speter
117238032Speter/* values for nc_flags */
117338032Speter#define NCF_VALID	0x0001	/* entry valid */
117464562Sgshapiro
117590792Sgshapiro/* hostsignature structure */
117690792Sgshapiro
117790792Sgshapirostruct hostsig_t
117890792Sgshapiro{
117990792Sgshapiro	char		*hs_sig;	/* hostsignature */
118090792Sgshapiro	time_t		hs_exp;		/* entry expires at */
118190792Sgshapiro};
118290792Sgshapiro
118390792Sgshapirotypedef struct hostsig_t HOSTSIG_T;
118490792Sgshapiro
1185223067Sgshapiro/*
1186223067Sgshapiro**  The standard udp packet size PACKETSZ (512) is not sufficient for some
1187223067Sgshapiro**  nameserver answers containing very many resource records. The resolver
1188223067Sgshapiro**  may switch to tcp and retry if it detects udp packet overflow.
1189223067Sgshapiro**  Also note that the resolver routines res_query and res_search return
1190223067Sgshapiro**  the size of the *un*truncated answer in case the supplied answer buffer
1191223067Sgshapiro**  it not big enough to accommodate the entire answer.
1192223067Sgshapiro*/
1193223067Sgshapiro
1194223067Sgshapiro# ifndef MAXPACKET
1195223067Sgshapiro#  define MAXPACKET 8192	/* max packet size used internally by BIND */
1196223067Sgshapiro# endif /* ! MAXPACKET */
1197223067Sgshapiro
1198223067Sgshapiro/*
1199223067Sgshapiro**  The resolver functions res_{send,query,querydomain} expect the
1200223067Sgshapiro**  answer buffer to be aligned, but some versions of gcc4 reverse
1201223067Sgshapiro**  25 years of history and no longer align char buffers on the
1202223067Sgshapiro**  stack, resulting in crashes on strict-alignment platforms.  Use
1203223067Sgshapiro**  this union when putting the buffer on the stack to force the
1204223067Sgshapiro**  alignment, then cast to (HEADER *) or (unsigned char *) as needed.
1205223067Sgshapiro*/
1206223067Sgshapirotypedef union
1207223067Sgshapiro{
1208223067Sgshapiro	HEADER		qb1;
1209223067Sgshapiro	unsigned char	qb2[MAXPACKET];
1210223067Sgshapiro} querybuf;
1211223067Sgshapiro
121264562Sgshapiro/* functions */
121390792Sgshapiroextern bool	getcanonname __P((char *, int, bool, int *));
121490792Sgshapiroextern int	getmxrr __P((char *, char **, unsigned short *, bool, int *, bool, int *));
121590792Sgshapiroextern char	*hostsignature __P((MAILER *, char *));
121690792Sgshapiroextern int	getfallbackmxrr __P((char *));
121764562Sgshapiro
121890792Sgshapiro/*
121938032Speter**  Mapping functions
122038032Speter**
122138032Speter**	These allow arbitrary mappings in the config file.  The idea
122238032Speter**	(albeit not the implementation) comes from IDA sendmail.
122338032Speter*/
122438032Speter
122564562Sgshapiro#define MAPCLASS	struct _mapclass
122664562Sgshapiro#define MAP		struct _map
122764562Sgshapiro#define MAXMAPACTIONS	5		/* size of map_actions array */
122838032Speter
122938032Speter
123038032Speter/*
123138032Speter**  An actual map.
123238032Speter*/
123338032Speter
123438032SpeterMAP
123538032Speter{
123638032Speter	MAPCLASS	*map_class;	/* the class of this map */
123790792Sgshapiro	MAPCLASS	*map_orgclass;	/* the original class of this map */
123838032Speter	char		*map_mname;	/* name of this map */
123938032Speter	long		map_mflags;	/* flags, see below */
124038032Speter	char		*map_file;	/* the (nominal) filename */
124138032Speter	ARBPTR_T	map_db1;	/* the open database ptr */
124238032Speter	ARBPTR_T	map_db2;	/* an "extra" database pointer */
124338032Speter	char		*map_keycolnm;	/* key column name */
124438032Speter	char		*map_valcolnm;	/* value column name */
124590792Sgshapiro	unsigned char	map_keycolno;	/* key column number */
124690792Sgshapiro	unsigned char	map_valcolno;	/* value column number */
124738032Speter	char		map_coldelim;	/* column delimiter */
124864562Sgshapiro	char		map_spacesub;	/* spacesub */
124938032Speter	char		*map_app;	/* to append to successful matches */
125038032Speter	char		*map_tapp;	/* to append to "tempfail" matches */
125138032Speter	char		*map_domain;	/* the (nominal) NIS domain */
125238032Speter	char		*map_rebuild;	/* program to run to do auto-rebuild */
125338032Speter	time_t		map_mtime;	/* last database modification time */
125490792Sgshapiro	time_t		map_timeout;	/* timeout for map accesses */
125590792Sgshapiro	int		map_retry;	/* # of retries for map accesses */
125642575Speter	pid_t		map_pid;	/* PID of process which opened map */
125738032Speter	int		map_lockfd;	/* auxiliary lock file descriptor */
125838032Speter	short		map_specificity;	/* specificity of aliases */
125938032Speter	MAP		*map_stack[MAXMAPSTACK];   /* list for stacked maps */
126038032Speter	short		map_return[MAXMAPACTIONS]; /* return bitmaps for stacked maps */
126138032Speter};
126238032Speter
126364562Sgshapiro
126438032Speter/* bit values for map_mflags */
126564562Sgshapiro#define MF_VALID	0x00000001	/* this entry is valid */
126664562Sgshapiro#define MF_INCLNULL	0x00000002	/* include null byte in key */
126764562Sgshapiro#define MF_OPTIONAL	0x00000004	/* don't complain if map not found */
126864562Sgshapiro#define MF_NOFOLDCASE	0x00000008	/* don't fold case in keys */
126964562Sgshapiro#define MF_MATCHONLY	0x00000010	/* don't use the map value */
127064562Sgshapiro#define MF_OPEN		0x00000020	/* this entry is open */
127164562Sgshapiro#define MF_WRITABLE	0x00000040	/* open for writing */
127264562Sgshapiro#define MF_ALIAS	0x00000080	/* this is an alias file */
127364562Sgshapiro#define MF_TRY0NULL	0x00000100	/* try with no null byte */
127464562Sgshapiro#define MF_TRY1NULL	0x00000200	/* try with the null byte */
127564562Sgshapiro#define MF_LOCKED	0x00000400	/* this map is currently locked */
127664562Sgshapiro#define MF_ALIASWAIT	0x00000800	/* alias map in aliaswait state */
127764562Sgshapiro#define MF_IMPL_HASH	0x00001000	/* implicit: underlying hash database */
127864562Sgshapiro#define MF_IMPL_NDBM	0x00002000	/* implicit: underlying NDBM database */
127990792Sgshapiro/* 0x00004000	*/
128064562Sgshapiro#define MF_APPEND	0x00008000	/* append new entry on rebuild */
128164562Sgshapiro#define MF_KEEPQUOTES	0x00010000	/* don't dequote key before lookup */
128264562Sgshapiro#define MF_NODEFER	0x00020000	/* don't defer if map lookup fails */
128364562Sgshapiro#define MF_REGEX_NOT	0x00040000	/* regular expression negation */
128464562Sgshapiro#define MF_DEFER	0x00080000	/* don't lookup map in defer mode */
128564562Sgshapiro#define MF_SINGLEMATCH	0x00100000	/* successful only if match one key */
1286157001Sgshapiro#define MF_SINGLEDN	0x00200000	/* only one match, but multi values */
128790792Sgshapiro#define MF_FILECLASS	0x00400000	/* this is a file class map */
128890792Sgshapiro#define MF_OPENBOGUS	0x00800000	/* open failed, don't call map_close */
128990792Sgshapiro#define MF_CLOSING	0x01000000	/* map is being closed */
129038032Speter
1291223067Sgshapiro#define DYNOPENMAP(map) \
1292223067Sgshapiro	do		\
1293223067Sgshapiro	{		\
1294223067Sgshapiro		if (!bitset(MF_OPEN, (map)->map_mflags)) \
1295223067Sgshapiro		{	\
1296223067Sgshapiro			if (!openmap(map))	\
1297223067Sgshapiro				return NULL;	\
1298223067Sgshapiro		}	\
1299223067Sgshapiro	} while (0)
130064562Sgshapiro
130164562Sgshapiro
130238032Speter/* indices for map_actions */
130364562Sgshapiro#define MA_NOTFOUND	0		/* member map returned "not found" */
130464562Sgshapiro#define MA_UNAVAIL	1		/* member map is not available */
130564562Sgshapiro#define MA_TRYAGAIN	2		/* member map returns temp failure */
130638032Speter
130790792Sgshapiro/* macros to handle MapTempFail */
130890792Sgshapiro#define BIT_IS_MTP	0x01	/* temp.failure occurred */
130990792Sgshapiro#define BIT_ASK_MTP	0x02	/* do we care about MapTempFail? */
131090792Sgshapiro#define RESET_MAPTEMPFAIL	MapTempFail = 0
131190792Sgshapiro#define INIT_MAPTEMPFAIL	MapTempFail = BIT_ASK_MTP
131290792Sgshapiro#define SET_MAPTEMPFAIL		MapTempFail |= BIT_IS_MTP
131390792Sgshapiro#define IS_MAPTEMPFAIL		bitset(BIT_IS_MTP, MapTempFail)
131490792Sgshapiro#define ASK_MAPTEMPFAIL		bitset(BIT_ASK_MTP, MapTempFail)
131590792Sgshapiro
131638032Speter/*
131738032Speter**  The class of a map -- essentially the functions to call
131838032Speter*/
131938032Speter
132038032SpeterMAPCLASS
132138032Speter{
132238032Speter	char	*map_cname;		/* name of this map class */
132338032Speter	char	*map_ext;		/* extension for database file */
132438032Speter	short	map_cflags;		/* flag bits, see below */
132538032Speter	bool	(*map_parse)__P((MAP *, char *));
132638032Speter					/* argument parsing function */
132738032Speter	char	*(*map_lookup)__P((MAP *, char *, char **, int *));
132838032Speter					/* lookup function */
132938032Speter	void	(*map_store)__P((MAP *, char *, char *));
133038032Speter					/* store function */
133138032Speter	bool	(*map_open)__P((MAP *, int));
133238032Speter					/* open function */
133338032Speter	void	(*map_close)__P((MAP *));
133438032Speter					/* close function */
133538032Speter};
133638032Speter
133738032Speter/* bit values for map_cflags */
133838032Speter#define MCF_ALIASOK	0x0001		/* can be used for aliases */
133938032Speter#define MCF_ALIASONLY	0x0002		/* usable only for aliases */
134038032Speter#define MCF_REBUILDABLE	0x0004		/* can rebuild alias files */
134138032Speter#define MCF_OPTFILE	0x0008		/* file name is optional */
134290792Sgshapiro#define MCF_NOTPERSIST	0x0010		/* don't keep map open all the time */
134338032Speter
134438032Speter/* functions */
134590792Sgshapiroextern void	closemaps __P((bool));
134664562Sgshapiroextern bool	impl_map_open __P((MAP *, int));
134764562Sgshapiroextern void	initmaps __P((void));
134864562Sgshapiroextern MAP	*makemapentry __P((char *));
134964562Sgshapiroextern void	maplocaluser __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
135038032Speterextern char	*map_rewrite __P((MAP *, const char *, size_t, char **));
135164562Sgshapiro#if NETINFO
135264562Sgshapiroextern char	*ni_propval __P((char *, char *, char *, char *, int));
135364562Sgshapiro#endif /* NETINFO */
135464562Sgshapiroextern bool	openmap __P((MAP *));
1355168515Sgshapiroextern int	udbexpand __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
135664562Sgshapiro#if USERDB
135764562Sgshapiroextern void	_udbx_close __P((void));
135890792Sgshapiroextern char	*udbsender __P((char *, SM_RPOOL_T *));
135964562Sgshapiro#endif /* USERDB */
136090792Sgshapiro
136190792Sgshapiro/*
136264562Sgshapiro**  LDAP related items
136364562Sgshapiro*/
136490792Sgshapiro#if LDAPMAP
136564562Sgshapiro/* struct defining LDAP Auth Methods */
136664562Sgshapirostruct lamvalues
136764562Sgshapiro{
136864562Sgshapiro	char	*lam_name;	/* name of LDAP auth method */
136964562Sgshapiro	int	lam_code;	/* numeric code */
137064562Sgshapiro};
137164562Sgshapiro
137264562Sgshapiro/* struct defining LDAP Alias Dereferencing */
137364562Sgshapirostruct ladvalues
137464562Sgshapiro{
137564562Sgshapiro	char	*lad_name;	/* name of LDAP alias dereferencing method */
137664562Sgshapiro	int	lad_code;	/* numeric code */
137764562Sgshapiro};
137864562Sgshapiro
137964562Sgshapiro/* struct defining LDAP Search Scope */
138064562Sgshapirostruct lssvalues
138164562Sgshapiro{
138264562Sgshapiro	char	*lss_name;	/* name of LDAP search scope */
138364562Sgshapiro	int	lss_code;	/* numeric code */
138464562Sgshapiro};
138564562Sgshapiro
138664562Sgshapiro/* functions */
138764562Sgshapiroextern bool	ldapmap_parseargs __P((MAP *, char *));
138864562Sgshapiroextern void	ldapmap_set_defaults __P((char *));
138964562Sgshapiro#endif /* LDAPMAP */
139064562Sgshapiro
139190792Sgshapiro/*
139264562Sgshapiro**  PH related items
139364562Sgshapiro*/
139464562Sgshapiro
139590792Sgshapiro#if PH_MAP
139690792Sgshapiro
139790792Sgshapiro# include <phclient.h>
139890792Sgshapiro
139964562Sgshapirostruct ph_map_struct
140064562Sgshapiro{
140190792Sgshapiro	char	*ph_servers;	 /* list of ph servers */
140290792Sgshapiro	char	*ph_field_list;	 /* list of fields to search for match */
140390792Sgshapiro	PH	*ph;		 /* PH server handle */
140490792Sgshapiro	int	ph_fastclose;	 /* send "quit" command on close */
140590792Sgshapiro	time_t	ph_timeout;	 /* timeout interval */
140664562Sgshapiro};
140764562Sgshapirotypedef struct ph_map_struct	PH_MAP_STRUCT;
140864562Sgshapiro
140964562Sgshapiro#endif /* PH_MAP */
1410132943Sgshapiro
141190792Sgshapiro/*
1412132943Sgshapiro**  Regular UNIX sockaddrs are too small to handle ISO addresses, so
1413132943Sgshapiro**  we are forced to declare a supertype here.
1414132943Sgshapiro*/
1415132943Sgshapiro
1416132943Sgshapiro#if NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25
1417132943Sgshapirounion bigsockaddr
1418132943Sgshapiro{
1419132943Sgshapiro	struct sockaddr		sa;	/* general version */
1420132943Sgshapiro# if NETUNIX
1421132943Sgshapiro	struct sockaddr_un	sunix;	/* UNIX family */
1422132943Sgshapiro# endif /* NETUNIX */
1423132943Sgshapiro# if NETINET
1424132943Sgshapiro	struct sockaddr_in	sin;	/* INET family */
1425132943Sgshapiro# endif /* NETINET */
1426132943Sgshapiro# if NETINET6
1427132943Sgshapiro	struct sockaddr_in6	sin6;	/* INET/IPv6 */
1428132943Sgshapiro# endif /* NETINET6 */
1429132943Sgshapiro# if NETISO
1430132943Sgshapiro	struct sockaddr_iso	siso;	/* ISO family */
1431132943Sgshapiro# endif /* NETISO */
1432132943Sgshapiro# if NETNS
1433132943Sgshapiro	struct sockaddr_ns	sns;	/* XNS family */
1434132943Sgshapiro# endif /* NETNS */
1435132943Sgshapiro# if NETX25
1436132943Sgshapiro	struct sockaddr_x25	sx25;	/* X.25 family */
1437132943Sgshapiro# endif /* NETX25 */
1438132943Sgshapiro};
1439132943Sgshapiro
1440132943Sgshapiro# define SOCKADDR	union bigsockaddr
1441132943Sgshapiro
1442132943Sgshapiro/* functions */
1443132943Sgshapiroextern char	*anynet_ntoa __P((SOCKADDR *));
1444132943Sgshapiro# if NETINET6
1445132943Sgshapiroextern char	*anynet_ntop __P((struct in6_addr *, char *, size_t));
1446132943Sgshapiroextern int	anynet_pton __P((int, const char *, void *));
1447132943Sgshapiro# endif /* NETINET6 */
1448132943Sgshapiroextern char	*hostnamebyanyaddr __P((SOCKADDR *));
1449132943Sgshapiroextern char	*validate_connection __P((SOCKADDR *, char *, ENVELOPE *));
1450132943Sgshapiro# if SASL >= 20000
1451132943Sgshapiroextern bool	iptostring __P((SOCKADDR *, SOCKADDR_LEN_T, char *, unsigned));
1452132943Sgshapiro# endif /* SASL >= 20000 */
1453132943Sgshapiro
1454132943Sgshapiro#endif /* NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25 */
1455132943Sgshapiro
1456132943Sgshapiro/*
145764562Sgshapiro**  Process List (proclist)
145864562Sgshapiro*/
145964562Sgshapiro
146064562Sgshapiro#define NO_PID		((pid_t) 0)
146164562Sgshapiro#ifndef PROC_LIST_SEG
146264562Sgshapiro# define PROC_LIST_SEG	32		/* number of pids to alloc at a time */
146364562Sgshapiro#endif /* ! PROC_LIST_SEG */
146464562Sgshapiro
146564562Sgshapiro/* process types */
146664562Sgshapiro#define PROC_NONE		0
146764562Sgshapiro#define PROC_DAEMON		1
146864562Sgshapiro#define PROC_DAEMON_CHILD	2
146964562Sgshapiro#define PROC_QUEUE		3
147064562Sgshapiro#define PROC_QUEUE_CHILD	3
147164562Sgshapiro#define PROC_CONTROL		4
147264562Sgshapiro#define PROC_CONTROL_CHILD	5
147364562Sgshapiro
147464562Sgshapiro/* functions */
1475132943Sgshapiroextern void	proc_list_add __P((pid_t, char *, int, int, int, SOCKADDR *));
147664562Sgshapiroextern void	proc_list_clear __P((void));
147790792Sgshapiroextern void	proc_list_display __P((SM_FILE_T *, char *));
147890792Sgshapiroextern void	proc_list_drop __P((pid_t, int, int *));
147964562Sgshapiroextern void	proc_list_probe __P((void));
148064562Sgshapiroextern void	proc_list_set __P((pid_t, char *));
148190792Sgshapiroextern void	proc_list_signal __P((int, int));
148264562Sgshapiro
148390792Sgshapiro/*
148438032Speter**  Symbol table definitions
148538032Speter*/
148638032Speter
148738032Speterstruct symtab
148838032Speter{
148938032Speter	char		*s_name;	/* name to be entered */
149090792Sgshapiro	short		s_symtype;	/* general type (see below) */
149138032Speter	struct symtab	*s_next;	/* pointer to next in chain */
149238032Speter	union
149338032Speter	{
149464562Sgshapiro		BITMAP256	sv_class;	/* bit-map of word classes */
149538032Speter		MAILER		*sv_mailer;	/* pointer to mailer */
149638032Speter		char		*sv_alias;	/* alias */
149738032Speter		MAPCLASS	sv_mapclass;	/* mapping function class */
149838032Speter		MAP		sv_map;		/* mapping function */
149990792Sgshapiro		HOSTSIG_T	sv_hostsig;	/* host signature */
150038032Speter		MCI		sv_mci;		/* mailer connection info */
150138032Speter		NAMECANON	sv_namecanon;	/* canonical name cache */
150238032Speter		int		sv_macro;	/* macro name => id mapping */
150338032Speter		int		sv_ruleset;	/* ruleset index */
150438032Speter		struct hdrinfo	sv_header;	/* header metainfo */
150538032Speter		char		*sv_service[MAXMAPSTACK]; /* service switch */
150690792Sgshapiro#if LDAPMAP
150777349Sgshapiro		MAP		*sv_lmap;	/* Maps for LDAP connection */
150864562Sgshapiro#endif /* LDAPMAP */
1509132943Sgshapiro#if SOCKETMAP
1510132943Sgshapiro		MAP		*sv_socketmap;	/* Maps for SOCKET connection */
1511132943Sgshapiro#endif /* SOCKETMAP */
151290792Sgshapiro#if MILTER
151364562Sgshapiro		struct milter	*sv_milter;	/* milter filter name */
151490792Sgshapiro#endif /* MILTER */
151590792Sgshapiro		QUEUEGRP	*sv_queue;	/* pointer to queue */
151638032Speter	}	s_value;
151738032Speter};
151838032Speter
151938032Spetertypedef struct symtab	STAB;
152038032Speter
152138032Speter/* symbol types */
152264562Sgshapiro#define ST_UNDEF	0	/* undefined type */
152364562Sgshapiro#define ST_CLASS	1	/* class map */
1524244833Sgshapiro/* #define ST_unused	2	UNUSED */
152564562Sgshapiro#define ST_MAILER	3	/* a mailer header */
152664562Sgshapiro#define ST_ALIAS	4	/* an alias */
152764562Sgshapiro#define ST_MAPCLASS	5	/* mapping function class */
152864562Sgshapiro#define ST_MAP		6	/* mapping function */
152964562Sgshapiro#define ST_HOSTSIG	7	/* host signature */
153064562Sgshapiro#define ST_NAMECANON	8	/* cached canonical name */
153164562Sgshapiro#define ST_MACRO	9	/* macro name to id mapping */
153264562Sgshapiro#define ST_RULESET	10	/* ruleset index */
153364562Sgshapiro#define ST_SERVICE	11	/* service switch entry */
153464562Sgshapiro#define ST_HEADER	12	/* special header flags */
153590792Sgshapiro#if LDAPMAP
153677349Sgshapiro# define ST_LMAP	13	/* List head of maps for LDAP connection */
153764562Sgshapiro#endif /* LDAPMAP */
153890792Sgshapiro#if MILTER
153964562Sgshapiro# define ST_MILTER	14	/* milter filter */
154090792Sgshapiro#endif /* MILTER */
154190792Sgshapiro#define ST_QUEUE	15	/* a queue entry */
154290792Sgshapiro
1543132943Sgshapiro#if SOCKETMAP
1544132943Sgshapiro# define ST_SOCKETMAP   16      /* List head of maps for SOCKET connection */
1545132943Sgshapiro#endif /* SOCKETMAP */
1546132943Sgshapiro
154790792Sgshapiro/* This entry must be last */
1548132943Sgshapiro#define ST_MCI		17	/* mailer connection info (offset) */
154938032Speter
155064562Sgshapiro#define s_class		s_value.sv_class
155164562Sgshapiro#define s_mailer	s_value.sv_mailer
155264562Sgshapiro#define s_alias		s_value.sv_alias
155364562Sgshapiro#define s_mci		s_value.sv_mci
155464562Sgshapiro#define s_mapclass	s_value.sv_mapclass
155564562Sgshapiro#define s_hostsig	s_value.sv_hostsig
155664562Sgshapiro#define s_map		s_value.sv_map
155764562Sgshapiro#define s_namecanon	s_value.sv_namecanon
155864562Sgshapiro#define s_macro		s_value.sv_macro
155964562Sgshapiro#define s_ruleset	s_value.sv_ruleset
156064562Sgshapiro#define s_service	s_value.sv_service
156164562Sgshapiro#define s_header	s_value.sv_header
156290792Sgshapiro#if LDAPMAP
156377349Sgshapiro# define s_lmap		s_value.sv_lmap
156464562Sgshapiro#endif /* LDAPMAP */
1565132943Sgshapiro#if SOCKETMAP
1566132943Sgshapiro# define s_socketmap    s_value.sv_socketmap
1567132943Sgshapiro#endif /* SOCKETMAP */
156890792Sgshapiro#if MILTER
156964562Sgshapiro# define s_milter	s_value.sv_milter
157090792Sgshapiro#endif /* MILTER */
157190792Sgshapiro#define s_quegrp	s_value.sv_queue
157238032Speter
157364562Sgshapiro/* opcodes to stab */
157464562Sgshapiro#define ST_FIND		0	/* find entry */
157564562Sgshapiro#define ST_ENTER	1	/* enter if not there */
157638032Speter
157764562Sgshapiro/* functions */
157864562Sgshapiroextern STAB	*stab __P((char *, int, int));
157964562Sgshapiroextern void	stabapply __P((void (*)(STAB *, int), int));
158064562Sgshapiro
158190792Sgshapiro/*
158238032Speter**  Operation, send, error, and MIME modes
158338032Speter**
158438032Speter**	The operation mode describes the basic operation of sendmail.
158538032Speter**	This can be set from the command line, and is "send mail" by
158638032Speter**	default.
158738032Speter**
158838032Speter**	The send mode tells how to send mail.  It can be set in the
158990792Sgshapiro**	configuration file.  Its setting determines how quickly the
159038032Speter**	mail will be delivered versus the load on your system.  If the
159138032Speter**	-v (verbose) flag is given, it will be forced to SM_DELIVER
159238032Speter**	mode.
159338032Speter**
159438032Speter**	The error mode tells how to return errors.
159538032Speter*/
159638032Speter
159738032Speter#define MD_DELIVER	'm'		/* be a mail sender */
159838032Speter#define MD_SMTP		's'		/* run SMTP on standard input */
159938032Speter#define MD_ARPAFTP	'a'		/* obsolete ARPANET mode (Grey Book) */
160038032Speter#define MD_DAEMON	'd'		/* run as a daemon */
160138032Speter#define MD_FGDAEMON	'D'		/* run daemon in foreground */
1602182352Sgshapiro#define MD_LOCAL	'l'		/* like daemon, but localhost only */
160338032Speter#define MD_VERIFY	'v'		/* verify: don't collect or deliver */
160438032Speter#define MD_TEST		't'		/* test mode: resolve addrs only */
160538032Speter#define MD_INITALIAS	'i'		/* initialize alias database */
160638032Speter#define MD_PRINT	'p'		/* print the queue */
160790792Sgshapiro#define MD_PRINTNQE	'P'		/* print number of entries in queue */
160838032Speter#define MD_FREEZE	'z'		/* freeze the configuration file */
160938032Speter#define MD_HOSTSTAT	'h'		/* print persistent host stat info */
161038032Speter#define MD_PURGESTAT	'H'		/* purge persistent host stat info */
161164562Sgshapiro#define MD_QUEUERUN	'q'		/* queue run */
1612203004Sgshapiro#define MD_CHECKCONFIG	'C'		/* check configuration file */
161338032Speter
1614182352Sgshapiro#if _FFR_LOCAL_DAEMON
1615182352SgshapiroEXTERN bool	LocalDaemon;
1616223067Sgshapiro# if NETINET6
1617223067SgshapiroEXTERN bool	V6LoopbackAddrFound;	/* found an IPv6 loopback address */
1618223067Sgshapiro#  define SETV6LOOPBACKADDRFOUND(sa)	\
1619223067Sgshapiro	do	\
1620223067Sgshapiro	{	\
1621223067Sgshapiro		if (isloopback(sa))	\
1622223067Sgshapiro			V6LoopbackAddrFound = true;	\
1623223067Sgshapiro	} while (0)
1624223067Sgshapiro# endif /* NETINET6 */
1625182352Sgshapiro#else /* _FFR_LOCAL_DAEMON */
1626182352Sgshapiro# define LocalDaemon	false
1627223067Sgshapiro# define V6LoopbackAddrFound	false
1628223067Sgshapiro# define SETV6LOOPBACKADDRFOUND(sa)
1629182352Sgshapiro#endif /* _FFR_LOCAL_DAEMON */
1630182352Sgshapiro
163190792Sgshapiro/* Note: see also include/sendmail/pathnames.h: GET_CLIENT_CF */
163290792Sgshapiro
163338032Speter/* values for e_sendmode -- send modes */
163438032Speter#define SM_DELIVER	'i'		/* interactive delivery */
163538032Speter#define SM_FORK		'b'		/* deliver in background */
1636157001Sgshapiro#if _FFR_DM_ONE
1637157001Sgshapiro#define SM_DM_ONE	'o' /* deliver first TA in background, then queue */
1638157001Sgshapiro#endif /* _FFR_DM_ONE */
163938032Speter#define SM_QUEUE	'q'		/* queue, don't deliver */
164038032Speter#define SM_DEFER	'd'		/* defer map lookups as well as queue */
164138032Speter#define SM_VERIFY	'v'		/* verify only (used internally) */
1642157001Sgshapiro#define DM_NOTSET	(-1)	/* DeliveryMode (per daemon) option not set */
1643223067Sgshapiro# define SM_IS_INTERACTIVE(m)	((m) == SM_DELIVER)
164438032Speter
164590792Sgshapiro#define WILL_BE_QUEUED(m)	((m) == SM_QUEUE || (m) == SM_DEFER)
164664562Sgshapiro
164738032Speter/* used only as a parameter to sendall */
164838032Speter#define SM_DEFAULT	'\0'		/* unspecified, use SendMode */
164938032Speter
165064562Sgshapiro/* functions */
165164562Sgshapiroextern void	set_delivery_mode __P((int, ENVELOPE *));
165238032Speter
165338032Speter/* values for e_errormode -- error handling modes */
165438032Speter#define EM_PRINT	'p'		/* print errors */
165538032Speter#define EM_MAIL		'm'		/* mail back errors */
165638032Speter#define EM_WRITE	'w'		/* write back errors */
165738032Speter#define EM_BERKNET	'e'		/* special berknet processing */
165838032Speter#define EM_QUIET	'q'		/* don't print messages (stat only) */
165938032Speter
166038032Speter
166138032Speter/* bit values for MimeMode */
166238032Speter#define MM_CVTMIME	0x0001		/* convert 8 to 7 bit MIME */
166338032Speter#define MM_PASS8BIT	0x0002		/* just send 8 bit data blind */
166438032Speter#define MM_MIME8BIT	0x0004		/* convert 8-bit data to MIME */
166538032Speter
166638032Speter
166738032Speter/* how to handle messages without any recipient addresses */
166838032Speter#define NRA_NO_ACTION		0	/* just leave it as is */
166938032Speter#define NRA_ADD_TO		1	/* add To: header */
167038032Speter#define NRA_ADD_APPARENTLY_TO	2	/* add Apparently-To: header */
167138032Speter#define NRA_ADD_BCC		3	/* add empty Bcc: header */
167238032Speter#define NRA_ADD_TO_UNDISCLOSED	4	/* add To: undisclosed:; header */
167338032Speter
167438032Speter
167538032Speter/* flags to putxline */
167638032Speter#define PXLF_NOTHINGSPECIAL	0	/* no special mapping */
167738032Speter#define PXLF_MAPFROM		0x0001	/* map From_ to >From_ */
167838032Speter#define PXLF_STRIP8BIT		0x0002	/* strip 8th bit */
167938032Speter#define PXLF_HEADER		0x0004	/* map newlines in headers */
168094334Sgshapiro#define PXLF_NOADDEOL		0x0008	/* if EOL not present, don't add one */
1681168515Sgshapiro#define PXLF_STRIPMQUOTE	0x0010	/* strip METAQUOTEs */
168238032Speter
168338032Speter/*
168438032Speter**  Privacy flags
168538032Speter**	These are bit values for the PrivacyFlags word.
168638032Speter*/
168738032Speter
168890792Sgshapiro#define PRIV_PUBLIC		0		/* what have I got to hide? */
168990792Sgshapiro#define PRIV_NEEDMAILHELO	0x00000001	/* insist on HELO for MAIL */
169090792Sgshapiro#define PRIV_NEEDEXPNHELO	0x00000002	/* insist on HELO for EXPN */
169190792Sgshapiro#define PRIV_NEEDVRFYHELO	0x00000004	/* insist on HELO for VRFY */
169290792Sgshapiro#define PRIV_NOEXPN		0x00000008	/* disallow EXPN command */
169390792Sgshapiro#define PRIV_NOVRFY		0x00000010	/* disallow VRFY command */
169490792Sgshapiro#define PRIV_AUTHWARNINGS	0x00000020	/* flag possible auth probs */
169590792Sgshapiro#define PRIV_NOVERB		0x00000040	/* disallow VERB command */
169690792Sgshapiro#define PRIV_RESTRICTMAILQ	0x00010000	/* restrict mailq command */
169790792Sgshapiro#define PRIV_RESTRICTQRUN	0x00020000	/* restrict queue run */
169890792Sgshapiro#define PRIV_RESTRICTEXPAND	0x00040000	/* restrict alias/forward expansion */
169990792Sgshapiro#define PRIV_NOETRN		0x00080000	/* disallow ETRN command */
170090792Sgshapiro#define PRIV_NOBODYRETN		0x00100000	/* do not return bodies on bounces */
170190792Sgshapiro#define PRIV_NORECEIPTS		0x00200000	/* disallow return receipts */
1702168515Sgshapiro#define PRIV_NOACTUALRECIPIENT	0x00400000 /* no X-Actual-Recipient in DSNs */
170338032Speter
1704168515Sgshapiro/* don't give no info, anyway, anyhow (in the main SMTP transaction) */
170590792Sgshapiro#define PRIV_GOAWAY		0x0000ffff
170664562Sgshapiro
170738032Speter/* struct defining such things */
170838032Speterstruct prival
170938032Speter{
171090792Sgshapiro	char		*pv_name;	/* name of privacy flag */
171190792Sgshapiro	unsigned long	pv_flag;	/* numeric level */
171238032Speter};
171338032Speter
171490792SgshapiroEXTERN unsigned long	PrivacyFlags;	/* privacy flags */
171538032Speter
171690792Sgshapiro
171738032Speter/*
171838032Speter**  Flags passed to remotename, parseaddr, allocaddr, and buildaddr.
171938032Speter*/
172038032Speter
172138032Speter#define RF_SENDERADDR		0x001	/* this is a sender address */
172238032Speter#define RF_HEADERADDR		0x002	/* this is a header address */
172338032Speter#define RF_CANONICAL		0x004	/* strip comment information */
172438032Speter#define RF_ADDDOMAIN		0x008	/* OK to do domain extension */
172538032Speter#define RF_COPYPARSE		0x010	/* copy parsed user & host */
172638032Speter#define RF_COPYPADDR		0x020	/* copy print address */
172738032Speter#define RF_COPYALL		(RF_COPYPARSE|RF_COPYPADDR)
172838032Speter#define RF_COPYNONE		0
1729168515Sgshapiro#define RF_RM_ADDR		0x040	/* address to be removed */
173038032Speter
1731102528Sgshapiro/*
1732102528Sgshapiro**  Flags passed to rscheck
1733102528Sgshapiro*/
173438032Speter
1735110560Sgshapiro#define RSF_RMCOMM		0x0001	/* strip comments */
1736102528Sgshapiro#define RSF_UNSTRUCTURED	0x0002	/* unstructured, ignore syntax errors */
1737102528Sgshapiro#define RSF_COUNT		0x0004	/* count rejections (statistics)? */
1738102528Sgshapiro
173938032Speter/*
174064562Sgshapiro**  Flags passed to mime8to7 and putheader.
174138032Speter*/
174238032Speter
174338032Speter#define M87F_OUTER		0	/* outer context */
174438032Speter#define M87F_NO8BIT		0x0001	/* can't have 8-bit in this section */
174538032Speter#define M87F_DIGEST		0x0002	/* processing multipart/digest */
174642575Speter#define M87F_NO8TO7		0x0004	/* don't do 8->7 bit conversions */
174738032Speter
174864562Sgshapiro/* functions */
1749157001Sgshapiroextern bool	mime7to8 __P((MCI *, HDR *, ENVELOPE *));
1750159609Sgshapiroextern int	mime8to7 __P((MCI *, HDR *, ENVELOPE *, char **, int, int));
175138032Speter
175238032Speter/*
175338032Speter**  Flags passed to returntosender.
175438032Speter*/
175538032Speter
175638032Speter#define RTSF_NO_BODY		0	/* send headers only */
175738032Speter#define RTSF_SEND_BODY		0x0001	/* include body of message in return */
175838032Speter#define RTSF_PM_BOUNCE		0x0002	/* this is a postmaster bounce */
175938032Speter
176064562Sgshapiro/* functions */
176164562Sgshapiroextern int	returntosender __P((char *, ADDRESS *, int, ENVELOPE *));
176238032Speter
176338032Speter/*
176464562Sgshapiro**  Mail Filters (milter)
176564562Sgshapiro*/
176638032Speter
176794334Sgshapiro/*
176894334Sgshapiro**  32-bit type used by milter
176994334Sgshapiro**  (needed by libmilter even if MILTER isn't defined)
177094334Sgshapiro*/
177194334Sgshapiro
177294334Sgshapirotypedef SM_INT32	mi_int32;
177394334Sgshapiro
177494334Sgshapiro#if MILTER
177590792Sgshapiro# define SMFTO_WRITE	0		/* Timeout for sending information */
177690792Sgshapiro# define SMFTO_READ	1		/* Timeout waiting for a response */
177790792Sgshapiro# define SMFTO_EOM	2		/* Timeout for ACK/NAK to EOM */
177890792Sgshapiro# define SMFTO_CONNECT	3		/* Timeout for connect() */
177964562Sgshapiro
178090792Sgshapiro# define SMFTO_NUM_TO	4		/* Total number of timeouts */
178164562Sgshapiro
178264562Sgshapirostruct milter
178364562Sgshapiro{
178464562Sgshapiro	char		*mf_name;	/* filter name */
178564562Sgshapiro	BITMAP256	mf_flags;	/* MTA flags */
178694334Sgshapiro	mi_int32	mf_fvers;	/* filter version */
178794334Sgshapiro	mi_int32	mf_fflags;	/* filter flags */
178894334Sgshapiro	mi_int32	mf_pflags;	/* protocol flags */
178964562Sgshapiro	char		*mf_conn;	/* connection info */
179064562Sgshapiro	int		mf_sock;	/* connected socket */
179164562Sgshapiro	char		mf_state;	/* state of filter */
1792244833Sgshapiro	char		mf_lflags;	/* "local" flags */
1793244833Sgshapiro	int		mf_idx;		/* milter number (index) */
179464562Sgshapiro	time_t		mf_timeout[SMFTO_NUM_TO]; /* timeouts */
1795168515Sgshapiro#if _FFR_MILTER_CHECK
1796168515Sgshapiro	/* for testing only */
1797168515Sgshapiro	mi_int32	mf_mta_prot_version;
1798168515Sgshapiro	mi_int32	mf_mta_prot_flags;
1799168515Sgshapiro	mi_int32	mf_mta_actions;
1800168515Sgshapiro#endif /* _FFR_MILTER_CHECK */
180164562Sgshapiro};
180264562Sgshapiro
1803244833Sgshapiro#define MI_LFL_NONE	0x00000000
1804244833Sgshapiro#define MI_LFLAGS_SYM(st) (1 << (st))	/* has its own symlist for stage st */
1805244833Sgshapiro
1806173340Sgshapirostruct milters
1807173340Sgshapiro{
1808173340Sgshapiro	mi_int32	mis_flags;	/* filter flags */
1809173340Sgshapiro};
1810173340Sgshapirotypedef struct milters	milters_T;
1811173340Sgshapiro
1812173340Sgshapiro#define MIS_FL_NONE	0x00000000	/* no requirements... */
1813173340Sgshapiro#define MIS_FL_DEL_RCPT	0x00000001	/* can delete rcpt */
1814173340Sgshapiro#define MIS_FL_REJ_RCPT	0x00000002	/* can reject rcpt */
1815173340Sgshapiro
1816173340Sgshapiro
181764562Sgshapiro/* MTA flags */
181864562Sgshapiro# define SMF_REJECT		'R'	/* Reject connection on filter fail */
181964562Sgshapiro# define SMF_TEMPFAIL		'T'	/* tempfail connection on failure */
1820141858Sgshapiro# define SMF_TEMPDROP		'4'	/* 421 connection on failure */
182164562Sgshapiro
182264562SgshapiroEXTERN struct milter	*InputFilters[MAXFILTERS];
182364562SgshapiroEXTERN char		*InputFilterList;
182490792SgshapiroEXTERN int		MilterLogLevel;
182564562Sgshapiro
182690792Sgshapiro/* functions */
1827120256Sgshapiroextern void	setup_daemon_milters __P((void));
182890792Sgshapiro#endif /* MILTER */
182990792Sgshapiro
183038032Speter/*
183138032Speter**  Vendor codes
183238032Speter**
183338032Speter**	Vendors can customize sendmail to add special behaviour,
183438032Speter**	generally for back compatibility.  Ideally, this should
183538032Speter**	be set up in the .cf file using the "V" command.  However,
183638032Speter**	it's quite reasonable for some vendors to want the default
183738032Speter**	be their old version; this can be set using
183838032Speter**		-DVENDOR_DEFAULT=VENDOR_xxx
183938032Speter**	in the Makefile.
184038032Speter**
184164562Sgshapiro**	Vendors should apply to sendmail@sendmail.org for
184238032Speter**	unique vendor codes.
184338032Speter*/
184438032Speter
184538032Speter#define VENDOR_BERKELEY	1	/* Berkeley-native configuration file */
184638032Speter#define VENDOR_SUN	2	/* Sun-native configuration file */
184738032Speter#define VENDOR_HP	3	/* Hewlett-Packard specific config syntax */
184838032Speter#define VENDOR_IBM	4	/* IBM specific config syntax */
184942575Speter#define VENDOR_SENDMAIL	5	/* Sendmail, Inc. specific config syntax */
185090792Sgshapiro#define VENDOR_DEC	6	/* Compaq, DEC, Digital */
185138032Speter
185238032Speter/* prototypes for vendor-specific hook routines */
185364562Sgshapiroextern void	vendor_daemon_setup __P((ENVELOPE *));
185438032Speterextern void	vendor_set_uid __P((UID_T));
185538032Speter
185638032Speter
185738032Speter/*
185838032Speter**  Terminal escape codes.
185938032Speter**
186038032Speter**	To make debugging output clearer.
186138032Speter*/
186238032Speter
186338032Speterstruct termescape
186438032Speter{
186538032Speter	char	*te_rv_on;	/* turn reverse-video on */
1866168515Sgshapiro	char	*te_under_on;	/* turn underlining on */
1867168515Sgshapiro	char	*te_normal;	/* revert to normal output */
186838032Speter};
186938032Speter
187090792Sgshapiro/*
187164562Sgshapiro**  Additional definitions
187264562Sgshapiro*/
187338032Speter
187490792Sgshapiro/*
187590792Sgshapiro**  d_flags, see daemon.c
187690792Sgshapiro**  general rule: lower case: required, upper case: No
187790792Sgshapiro*/
187890792Sgshapiro
187964562Sgshapiro#define D_AUTHREQ	'a'	/* authentication required */
188064562Sgshapiro#define D_BINDIF	'b'	/* use if_addr for outgoing connection */
188164562Sgshapiro#define D_CANONREQ	'c'	/* canonification required (cf) */
188264562Sgshapiro#define D_IFNHELO	'h'	/* use if name for HELO */
188364562Sgshapiro#define D_FQMAIL	'f'	/* fq sender address required (cf) */
188464562Sgshapiro#define D_FQRCPT	'r'	/* fq recipient address required (cf) */
1885132943Sgshapiro#define D_SMTPS		's'	/* SMTP over SSL (smtps) */
188664562Sgshapiro#define D_UNQUALOK	'u'	/* unqualified address is ok (cf) */
188790792Sgshapiro#define D_NOAUTH	'A'	/* no AUTH */
188864562Sgshapiro#define D_NOCANON	'C'	/* no canonification (cf) */
188964562Sgshapiro#define D_NOETRN	'E'	/* no ETRN (MSA) */
189090792Sgshapiro#define D_NOTLS		'S'	/* don't use STARTTLS */
189164562Sgshapiro#define D_ETRNONLY	((char)0x01)	/* allow only ETRN (disk low) */
189290792Sgshapiro#define D_OPTIONAL	'O'	/* optional socket */
189390792Sgshapiro#define D_DISABLE	((char)0x02)	/* optional socket disabled */
189490792Sgshapiro#define D_ISSET		((char)0x03)	/* this client struct is set */
189538032Speter
189664562Sgshapiro#if STARTTLS
189790792Sgshapiro/*
189864562Sgshapiro**  TLS
189938032Speter*/
190038032Speter
190164562Sgshapiro/* what to do in the TLS initialization */
190264562Sgshapiro#define TLS_I_NONE	0x00000000	/* no requirements... */
1903110560Sgshapiro#define TLS_I_CERT_EX	0x00000001	/* cert must exist */
1904110560Sgshapiro#define TLS_I_CERT_UNR	0x00000002	/* cert must be g/o unreadable */
1905110560Sgshapiro#define TLS_I_KEY_EX	0x00000004	/* key must exist */
1906110560Sgshapiro#define TLS_I_KEY_UNR	0x00000008	/* key must be g/o unreadable */
1907110560Sgshapiro#define TLS_I_CERTP_EX	0x00000010	/* CA cert path must exist */
1908110560Sgshapiro#define TLS_I_CERTP_UNR	0x00000020	/* CA cert path must be g/o unreadable */
1909110560Sgshapiro#define TLS_I_CERTF_EX	0x00000040	/* CA cert file must exist */
1910110560Sgshapiro#define TLS_I_CERTF_UNR	0x00000080	/* CA cert file must be g/o unreadable */
191164562Sgshapiro#define TLS_I_RSA_TMP	0x00000100	/* RSA TMP must be generated */
191264562Sgshapiro#define TLS_I_USE_KEY	0x00000200	/* private key must usable */
191364562Sgshapiro#define TLS_I_USE_CERT	0x00000400	/* certificate must be usable */
191464562Sgshapiro#define TLS_I_VRFY_PATH	0x00000800	/* load verify path must succeed */
191564562Sgshapiro#define TLS_I_VRFY_LOC	0x00001000	/* load verify default must succeed */
191664562Sgshapiro#define TLS_I_CACHE	0x00002000	/* require cache */
191764562Sgshapiro#define TLS_I_TRY_DH	0x00004000	/* try DH certificate */
191864562Sgshapiro#define TLS_I_REQ_DH	0x00008000	/* require DH certificate */
191964562Sgshapiro#define TLS_I_DHPAR_EX	0x00010000	/* require DH parameters */
192064562Sgshapiro#define TLS_I_DHPAR_UNR	0x00020000	/* DH param. must be g/o unreadable */
192164562Sgshapiro#define TLS_I_DH512	0x00040000	/* generate 512bit DH param */
192264562Sgshapiro#define TLS_I_DH1024	0x00080000	/* generate 1024bit DH param */
192364562Sgshapiro#define TLS_I_DH2048	0x00100000	/* generate 2048bit DH param */
192490792Sgshapiro#define TLS_I_NO_VRFY	0x00200000	/* do not require authentication */
1925110560Sgshapiro#define TLS_I_KEY_OUNR	0x00400000	/* Key must be other unreadable */
1926132943Sgshapiro#define TLS_I_CRLF_EX	0x00800000	/* CRL file must exist */
1927132943Sgshapiro#define TLS_I_CRLF_UNR	0x01000000	/* CRL file must be g/o unreadable */
192842575Speter
192990792Sgshapiro/* require server cert */
193090792Sgshapiro#define TLS_I_SRV_CERT	 (TLS_I_CERT_EX | TLS_I_KEY_EX | \
193190792Sgshapiro			  TLS_I_KEY_UNR | TLS_I_KEY_OUNR | \
193290792Sgshapiro			  TLS_I_CERTP_EX | TLS_I_CERTF_EX | \
1933157001Sgshapiro			  TLS_I_USE_KEY | TLS_I_USE_CERT | TLS_I_CACHE)
193490792Sgshapiro
193564562Sgshapiro/* server requirements */
193690792Sgshapiro#define TLS_I_SRV	(TLS_I_SRV_CERT | TLS_I_RSA_TMP | TLS_I_VRFY_PATH | \
1937157001Sgshapiro			 TLS_I_VRFY_LOC | TLS_I_TRY_DH | TLS_I_DH512 | \
1938157001Sgshapiro			 TLS_I_CACHE)
193938032Speter
194064562Sgshapiro/* client requirements */
194190792Sgshapiro#define TLS_I_CLT	(TLS_I_KEY_UNR | TLS_I_KEY_OUNR)
194264562Sgshapiro
194364562Sgshapiro#define TLS_AUTH_OK	0
194464562Sgshapiro#define TLS_AUTH_NO	1
194564562Sgshapiro#define TLS_AUTH_FAIL	(-1)
194690792Sgshapiro
194790792Sgshapiro/* functions */
1948249729Sgshapiroextern bool	init_tls_library __P((bool _fipsmode));
1949203004Sgshapiroextern bool	inittls __P((SSL_CTX **, unsigned long, long, bool, char *, char *, char *, char *, char *));
195090792Sgshapiroextern bool	initclttls __P((bool));
195190792Sgshapiroextern void	setclttls __P((bool));
195290792Sgshapiroextern bool	initsrvtls __P((bool));
195390792Sgshapiroextern int	tls_get_info __P((SSL *, bool, char *, MACROS_T *, bool));
195490792Sgshapiroextern int	endtls __P((SSL *, char *));
1955249729Sgshapiroextern void	tlslogerr __P((int, const char *));
195690792Sgshapiro
195790792Sgshapiro
1958110560SgshapiroEXTERN char	*CACertPath;	/* path to CA certificates (dir. with hashes) */
1959110560SgshapiroEXTERN char	*CACertFile;	/* file with CA certificate */
1960110560SgshapiroEXTERN char	*CltCertFile;	/* file with client certificate */
1961110560SgshapiroEXTERN char	*CltKeyFile;	/* file with client private key */
196290792Sgshapiro# if _FFR_TLS_1
196390792SgshapiroEXTERN char	*CipherList;	/* list of ciphers */
196490792SgshapiroEXTERN char	*DHParams5;	/* file with DH parameters (512) */
196590792Sgshapiro# endif /* _FFR_TLS_1 */
196690792SgshapiroEXTERN char	*DHParams;	/* file with DH parameters */
196790792SgshapiroEXTERN char	*RandFile;	/* source of random data */
1968110560SgshapiroEXTERN char	*SrvCertFile;	/* file with server certificate */
1969110560SgshapiroEXTERN char	*SrvKeyFile;	/* file with server private key */
1970132943SgshapiroEXTERN char	*CRLFile;	/* file CRLs */
1971132943Sgshapiro#if _FFR_CRLPATH
1972132943SgshapiroEXTERN char	*CRLPath;	/* path to CRLs (dir. with hashes) */
1973132943Sgshapiro#endif /* _FFR_CRLPATH */
197490792SgshapiroEXTERN unsigned long	TLS_Srv_Opts;	/* TLS server options */
1975203004SgshapiroEXTERN long	Srv_SSL_Options, Clt_SSL_Options; /* SSL options */
197664562Sgshapiro#endif /* STARTTLS */
197764562Sgshapiro
197890792Sgshapiro/*
197964562Sgshapiro**  Queue related items
198038032Speter*/
198164562Sgshapiro
198290792Sgshapiro/* queue file names */
1983132943Sgshapiro#define ANYQFL_LETTER '?'
1984132943Sgshapiro#define QUARQF_LETTER 'h'
198590792Sgshapiro#define DATAFL_LETTER 'd'
198690792Sgshapiro#define XSCRPT_LETTER 'x'
198790792Sgshapiro#define NORMQF_LETTER 'q'
198890792Sgshapiro#define NEWQFL_LETTER 't'
198990792Sgshapiro
199090792Sgshapiro# define TEMPQF_LETTER 'T'
199190792Sgshapiro# define LOSEQF_LETTER 'Q'
199290792Sgshapiro
199364562Sgshapiro/* queue sort order */
199464562Sgshapiro#define QSO_BYPRIORITY	0		/* sort by message priority */
199564562Sgshapiro#define QSO_BYHOST	1		/* sort by first host name */
199664562Sgshapiro#define QSO_BYTIME	2		/* sort by submission time */
199764562Sgshapiro#define QSO_BYFILENAME	3		/* sort by file name only */
199890792Sgshapiro#define QSO_RANDOM	4		/* sort in random order */
199990792Sgshapiro#define QSO_BYMODTIME	5		/* sort by modification time */
2000132943Sgshapiro#define QSO_NONE	6		/* do not sort */
200190792Sgshapiro#if _FFR_RHS
2002132943Sgshapiro# define QSO_BYSHUFFLE	7		/* sort by shuffled host name */
200390792Sgshapiro#endif /* _FFR_RHS */
200464562Sgshapiro
200590792Sgshapiro#define NOQGRP	(-1)		/* no queue group (yet) */
200690792Sgshapiro#define ENVQGRP	(-2)		/* use queue group of envelope */
200790792Sgshapiro#define NOAQGRP	(-3)		/* no queue group in addr (yet) */
200890792Sgshapiro#define ISVALIDQGRP(x)	((x) >= 0)	/* valid queue group? */
200990792Sgshapiro#define NOQDIR	(-1)		/* no queue directory (yet) */
201090792Sgshapiro#define ENVQDIR	(-2)		/* use queue directory of envelope */
201190792Sgshapiro#define NOAQDIR	(-3)		/* no queue directory in addr (yet) */
201290792Sgshapiro#define ISVALIDQDIR(x)	((x) >= 0)	/* valid queue directory? */
201390792Sgshapiro#define RS_QUEUEGROUP	"queuegroup"	/* ruleset for queue group selection */
201464562Sgshapiro
201590792Sgshapiro#define NOW	((time_t) (-1))		/* queue return: now */
201664562Sgshapiro
201790792Sgshapiro/* SuperSafe values */
201890792Sgshapiro#define SAFE_NO			0	/* no fsync(): don't use... */
201990792Sgshapiro#define SAFE_INTERACTIVE	1	/* limit fsync() in -odi */
202090792Sgshapiro#define SAFE_REALLY		2	/* always fsync() */
2021132943Sgshapiro#define SAFE_REALLY_POSTMILTER	3	/* fsync() if milter says OK */
202290792Sgshapiro
202390792Sgshapiro/* QueueMode bits */
2024132943Sgshapiro#define QM_NORMAL		' '
2025132943Sgshapiro#define QM_QUARANTINE		'Q'
2026132943Sgshapiro#define QM_LOST			'L'
202790792Sgshapiro
202864562Sgshapiro/* Queue Run Limitations */
202938032Speterstruct queue_char
203038032Speter{
203190792Sgshapiro	char			*queue_match;	/* string to match */
203290792Sgshapiro	bool			queue_negate;	/* or not match, if set */
203390792Sgshapiro	struct queue_char	*queue_next;
203438032Speter};
203538032Speter
2036110560Sgshapiro/* run_work_group() flags */
2037110560Sgshapiro#define RWG_NONE		0x0000
2038110560Sgshapiro#define RWG_FORK		0x0001
2039110560Sgshapiro#define RWG_VERBOSE		0x0002
2040110560Sgshapiro#define RWG_PERSISTENT		0x0004
2041110560Sgshapiro#define RWG_FORCE		0x0008
2042110560Sgshapiro#define RWG_RUNALL		0x0010
2043110560Sgshapiro
204490792Sgshapirotypedef struct queue_char	QUEUE_CHAR;
204538032Speter
204690792SgshapiroEXTERN int	volatile CurRunners;	/* current number of runner children */
204790792SgshapiroEXTERN int	MaxQueueRun;	/* maximum number of jobs in one queue run */
204890792SgshapiroEXTERN int	MaxQueueChildren;	/* max # of forked queue children */
204990792SgshapiroEXTERN int	MaxRunnersPerQueue;	/* max # proc's active in queue group */
205090792SgshapiroEXTERN int	NiceQueueRun;	/* nice queue runs to this value */
205190792SgshapiroEXTERN int	NumQueue;	/* number of queue groups */
205290792SgshapiroEXTERN int	QueueFileMode;	/* mode on files in mail queue */
205390792SgshapiroEXTERN int	QueueMode;	/* which queue items to act upon */
205490792SgshapiroEXTERN int	QueueSortOrder;	/* queue sorting order algorithm */
205590792SgshapiroEXTERN time_t	MinQueueAge;	/* min delivery interval */
2056203004Sgshapiro#if _FFR_EXPDELAY
2057203004SgshapiroEXTERN time_t	MaxQueueAge;	/* max delivery interval */
2058203004Sgshapiro#endif /* _FFR_EXPDELAY */
205990792SgshapiroEXTERN time_t	QueueIntvl;	/* intervals between running the queue */
206090792SgshapiroEXTERN char	*QueueDir;	/* location of queue directory */
206190792SgshapiroEXTERN QUEUE_CHAR	*QueueLimitId;		/* limit queue run to id */
206290792SgshapiroEXTERN QUEUE_CHAR	*QueueLimitQuarantine;	/* limit queue run to quarantine reason */
206390792SgshapiroEXTERN QUEUE_CHAR	*QueueLimitRecipient;	/* limit queue run to rcpt */
206490792SgshapiroEXTERN QUEUE_CHAR	*QueueLimitSender;	/* limit queue run to sender */
206590792SgshapiroEXTERN QUEUEGRP	*Queue[MAXQUEUEGROUPS + 1];	/* queue groups */
206690792Sgshapiro
206764562Sgshapiro/* functions */
206864562Sgshapiroextern void	assign_queueid __P((ENVELOPE *));
206990792Sgshapiroextern ADDRESS	*copyqueue __P((ADDRESS *, SM_RPOOL_T *));
207090792Sgshapiroextern void	cleanup_queues __P((void));
207190792Sgshapiroextern bool	doqueuerun __P((void));
207264562Sgshapiroextern void	initsys __P((ENVELOPE *));
207364562Sgshapiroextern void	loseqfile __P((ENVELOPE *, char *));
207490792Sgshapiroextern int	name2qid __P((char *));
207564562Sgshapiroextern char	*qid_printname __P((ENVELOPE *));
207690792Sgshapiroextern char	*qid_printqueue __P((int, int));
207790792Sgshapiroextern void	quarantine_queue __P((char *, int));
207864562Sgshapiroextern char	*queuename __P((ENVELOPE *, int));
207990792Sgshapiroextern void	queueup __P((ENVELOPE *, bool, bool));
208090792Sgshapiroextern bool	runqueue __P((bool, bool, bool, bool));
2081120256Sgshapiroextern bool	run_work_group __P((int, int));
208290792Sgshapiroextern void	set_def_queueval __P((QUEUEGRP *, bool));
208390792Sgshapiroextern void	setup_queues __P((bool));
208490792Sgshapiroextern bool	setnewqueue __P((ENVELOPE *));
208564562Sgshapiroextern bool	shouldqueue __P((long, time_t));
208664562Sgshapiroextern void	sync_queue_time __P((void));
2087125820Sgshapiroextern void	init_qid_alg __P((void));
208890792Sgshapiroextern int	print_single_queue __P((int, int));
208990792Sgshapiro#if REQUIRES_DIR_FSYNC
209090792Sgshapiro# define SYNC_DIR(path, panic) sync_dir(path, panic)
209190792Sgshapiroextern void	sync_dir __P((char *, bool));
209290792Sgshapiro#else /* REQUIRES_DIR_FSYNC */
209390792Sgshapiro# define SYNC_DIR(path, panic) ((void) 0)
209490792Sgshapiro#endif /* REQUIRES_DIR_FSYNC */
209538032Speter
209638032Speter/*
209738032Speter**  Timeouts
209838032Speter**
209938032Speter**	Indicated values are the MINIMUM per RFC 1123 section 5.3.2.
210038032Speter*/
210138032Speter
210238032SpeterEXTERN struct
210338032Speter{
210438032Speter			/* RFC 1123-specified timeouts [minimum value] */
210538032Speter	time_t	to_initial;	/* initial greeting timeout [5m] */
210638032Speter	time_t	to_mail;	/* MAIL command [5m] */
210738032Speter	time_t	to_rcpt;	/* RCPT command [5m] */
210838032Speter	time_t	to_datainit;	/* DATA initiation [2m] */
210938032Speter	time_t	to_datablock;	/* DATA block [3m] */
211038032Speter	time_t	to_datafinal;	/* DATA completion [10m] */
211138032Speter	time_t	to_nextcommand;	/* next command [5m] */
211238032Speter			/* following timeouts are not mentioned in RFC 1123 */
211338032Speter	time_t	to_iconnect;	/* initial connection timeout (first try) */
211438032Speter	time_t	to_connect;	/* initial connection timeout (later tries) */
211590792Sgshapiro	time_t	to_aconnect;	/* all connections timeout (MX and A records) */
211638032Speter	time_t	to_rset;	/* RSET command */
211738032Speter	time_t	to_helo;	/* HELO command */
211838032Speter	time_t	to_quit;	/* QUIT command */
211938032Speter	time_t	to_miscshort;	/* misc short commands (NOOP, VERB, etc) */
212038032Speter	time_t	to_ident;	/* IDENT protocol requests */
212138032Speter	time_t	to_fileopen;	/* opening :include: and .forward files */
212264562Sgshapiro	time_t	to_control;	/* process a control socket command */
212390792Sgshapiro	time_t	to_lhlo;	/* LMTP: LHLO command */
212490792Sgshapiro#if SASL
212590792Sgshapiro	time_t	to_auth;	/* AUTH dialogue [10m] */
212690792Sgshapiro#endif /* SASL */
212790792Sgshapiro#if STARTTLS
212890792Sgshapiro	time_t	to_starttls;	/* STARTTLS dialogue [10m] */
212990792Sgshapiro#endif /* STARTTLS */
213038032Speter			/* following are per message */
213138032Speter	time_t	to_q_return[MAXTOCLASS];	/* queue return timeouts */
213238032Speter	time_t	to_q_warning[MAXTOCLASS];	/* queue warning timeouts */
213364562Sgshapiro	time_t	res_retrans[MAXRESTOTYPES];	/* resolver retransmit */
213464562Sgshapiro	int	res_retry[MAXRESTOTYPES];	/* resolver retry */
213538032Speter} TimeOuts;
213638032Speter
213738032Speter/* timeout classes for return and warning timeouts */
213864562Sgshapiro#define TOC_NORMAL	0	/* normal delivery */
213964562Sgshapiro#define TOC_URGENT	1	/* urgent delivery */
214064562Sgshapiro#define TOC_NONURGENT	2	/* non-urgent delivery */
2141132943Sgshapiro#define TOC_DSN		3	/* DSN delivery */
214238032Speter
214364562Sgshapiro/* resolver timeout specifiers */
214464562Sgshapiro#define RES_TO_FIRST	0	/* first attempt */
214564562Sgshapiro#define RES_TO_NORMAL	1	/* subsequent attempts */
214664562Sgshapiro#define RES_TO_DEFAULT	2	/* default value */
214738032Speter
214864562Sgshapiro/* functions */
214964562Sgshapiroextern void	inittimeouts __P((char *, bool));
215064562Sgshapiro
215138032Speter/*
215290792Sgshapiro**  Interface probing
215390792Sgshapiro*/
215490792Sgshapiro
215590792Sgshapiro#define DPI_PROBENONE		0	/* Don't probe any interfaces */
215690792Sgshapiro#define DPI_PROBEALL		1	/* Probe all interfaces */
215790792Sgshapiro#define DPI_SKIPLOOPBACK	2	/* Don't probe loopback interfaces */
215890792Sgshapiro
215990792Sgshapiro/*
216038032Speter**  Trace information
216138032Speter*/
216238032Speter
216364562Sgshapiro/* macros for debugging flags */
2164223067Sgshapiro#if NOT_SENDMAIL
2165223067Sgshapiro# define tTd(flag, level)	(tTdvect[flag] >= (unsigned char)level)
2166223067Sgshapiro#else
2167223067Sgshapiro# define tTd(flag, level)	(tTdvect[flag] >= (unsigned char)level && !IntSig)
2168223067Sgshapiro#endif
216964562Sgshapiro#define tTdlevel(flag)		(tTdvect[flag])
217064562Sgshapiro
217164562Sgshapiro/* variables */
217290792Sgshapiroextern unsigned char	tTdvect[100];	/* trace vector */
217377349Sgshapiro
217490792Sgshapiro/*
217538032Speter**  Miscellaneous information.
217638032Speter*/
217738032Speter
217838032Speter/*
217938032Speter**  The "no queue id" queue id for sm_syslog
218038032Speter*/
218138032Speter
2182173340Sgshapiro#define NOQID		""
218338032Speter
218490792Sgshapiro#define CURHOSTNAME	(CurHostName == NULL ? "local" : CurHostName)
218590792Sgshapiro
218638032Speter/*
218738032Speter**  Some in-line functions
218838032Speter*/
218938032Speter
219038032Speter/* set exit status */
2191223067Sgshapiro#define setstat(s)	\
2192223067Sgshapiro	do		\
2193223067Sgshapiro	{		\
2194223067Sgshapiro		if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \
2195223067Sgshapiro			ExitStat = s; \
2196223067Sgshapiro	} while (0)
219738032Speter
219838032Speter
219938032Speter#define STRUCTCOPY(s, d)	d = s
220090792Sgshapiro
220190792Sgshapiro/* free a pointer if it isn't NULL and set it to NULL */
220290792Sgshapiro#define SM_FREE_CLR(p)	\
2203223067Sgshapiro	do		\
2204223067Sgshapiro	{		\
2205223067Sgshapiro		if ((p) != NULL) \
2206223067Sgshapiro		{ \
2207223067Sgshapiro			sm_free(p); \
2208223067Sgshapiro			(p) = NULL; \
2209223067Sgshapiro		} \
2210223067Sgshapiro	} while (0)
221190792Sgshapiro
221290792Sgshapiro/*
221390792Sgshapiro**  Update a permanent string variable with a new value.
221490792Sgshapiro**  The old value is freed, the new value is strdup'ed.
221590792Sgshapiro**
221690792Sgshapiro**  We use sm_pstrdup_x to duplicate the string because it raises
221790792Sgshapiro**  an exception on error, and because it allocates "permanent storage"
221890792Sgshapiro**  which is not expected to be freed before process exit.
221990792Sgshapiro**  The latter is important for memory leak analysis.
222090792Sgshapiro**
222190792Sgshapiro**  If an exception occurs while strdup'ing the new value,
222290792Sgshapiro**  then the variable remains set to the old value.
222390792Sgshapiro**  That's why the strdup must occur before we free the old value.
222490792Sgshapiro**
222590792Sgshapiro**  The macro uses a do loop so that this idiom will work:
222690792Sgshapiro**	if (...)
222790792Sgshapiro**		PSTRSET(var, val1);
222890792Sgshapiro**	else
222990792Sgshapiro**		PSTRSET(var, val2);
223090792Sgshapiro*/
223190792Sgshapiro#define PSTRSET(var, val) \
223290792Sgshapiro	do \
223390792Sgshapiro	{ \
223490792Sgshapiro		char *_newval = sm_pstrdup_x(val); \
223590792Sgshapiro		if (var != NULL) \
223690792Sgshapiro			sm_free(var); \
223790792Sgshapiro		var = _newval; \
223890792Sgshapiro	} while (0)
223990792Sgshapiro
2240120256Sgshapiro#define _CHECK_RESTART \
2241120256Sgshapiro	do \
2242120256Sgshapiro	{ \
2243120256Sgshapiro		if (ShutdownRequest != NULL) \
2244120256Sgshapiro			shutdown_daemon(); \
2245120256Sgshapiro		else if (RestartRequest != NULL) \
2246120256Sgshapiro			restart_daemon(); \
2247120256Sgshapiro		else if (RestartWorkGroup) \
2248120256Sgshapiro			restart_marked_work_groups(); \
2249120256Sgshapiro	} while (0)
2250120256Sgshapiro
2251120256Sgshapiro# define CHECK_RESTART _CHECK_RESTART
2252120256Sgshapiro
2253244833Sgshapiro#define CHK_CUR_RUNNERS(fct, idx, count)	\
2254244833Sgshapiro	do	\
2255244833Sgshapiro	{	\
2256244833Sgshapiro		if (CurRunners < 0)	\
2257244833Sgshapiro		{	\
2258244833Sgshapiro			if (LogLevel > 3)	\
2259244833Sgshapiro				sm_syslog(LOG_ERR, NOQID,	\
2260244833Sgshapiro					"%s: CurRunners=%d, i=%d, count=%d, status=should not happen",	\
2261244833Sgshapiro					fct, CurRunners, idx, count);	\
2262244833Sgshapiro			CurRunners = 0;	\
2263244833Sgshapiro		}	\
2264244833Sgshapiro	} while (0)
2265244833Sgshapiro
2266132943Sgshapiro/* reply types (text in SmtpMsgBuffer) */
2267132943Sgshapiro#define XS_DEFAULT	0
2268132943Sgshapiro#define XS_STARTTLS	1
2269132943Sgshapiro#define XS_AUTH		2
2270223067Sgshapiro#define XS_GREET	3
2271223067Sgshapiro#define XS_EHLO		4
2272223067Sgshapiro#define XS_MAIL		5
2273223067Sgshapiro#define XS_RCPT		6
2274223067Sgshapiro#define XS_DATA		7
2275223067Sgshapiro#define XS_EOM		8
2276223067Sgshapiro#define XS_DATA2	9
2277223067Sgshapiro#define XS_RCPT2	10
2278223067Sgshapiro#define XS_QUIT		15
2279132943Sgshapiro
228090792Sgshapiro/*
228164562Sgshapiro**  Global variables.
228264562Sgshapiro*/
228338032Speter
2284173340Sgshapiro#if _FFR_ADDR_TYPE_MODES
2285173340SgshapiroEXTERN bool	AddrTypeModes;	/* addr_type: extra "mode" information */
2286173340Sgshapiro#endif /* _FFR_ADDR_TYPE_MODES */
228764562SgshapiroEXTERN bool	AllowBogusHELO;	/* allow syntax errors on HELO command */
228864562SgshapiroEXTERN bool	CheckAliases;	/* parse addresses during newaliases */
2289157001Sgshapiro#if _FFR_QUEUE_RUN_PARANOIA
2290157001SgshapiroEXTERN int	CheckQueueRunners; /* check whether queue runners are OK */
2291157001Sgshapiro#endif /* _FFR_QUEUE_RUN_PARANOIA */
229264562SgshapiroEXTERN bool	ColonOkInAddr;	/* single colon legal in address */
229390792Sgshapiro#if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_)
229464562SgshapiroEXTERN bool	ConfigFileRead;	/* configuration file has been read */
229590792Sgshapiro#endif /* !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) */
229690792SgshapiroEXTERN bool	DisConnected;	/* running with OutChannel redirect to transcript file */
229764562SgshapiroEXTERN bool	DontExpandCnames;	/* do not $[...$] expand CNAMEs */
229864562SgshapiroEXTERN bool	DontInitGroups;	/* avoid initgroups() because of NIS cost */
229964562SgshapiroEXTERN bool	DontLockReadFiles;	/* don't read lock support files */
230064562SgshapiroEXTERN bool	DontPruneRoutes;	/* don't prune source routes */
230164562SgshapiroEXTERN bool	ForkQueueRuns;	/* fork for each job when running the queue */
230264562SgshapiroEXTERN bool	FromFlag;	/* if set, "From" person is explicit */
2303249729SgshapiroEXTERN bool	FipsMode;
230464562SgshapiroEXTERN bool	GrabTo;		/* if set, get recipients from msg */
2305168515SgshapiroEXTERN bool	EightBitAddrOK;	/* we'll let 8-bit addresses through */
230664562SgshapiroEXTERN bool	HasEightBits;	/* has at least one eight bit input byte */
230764562SgshapiroEXTERN bool	HasWildcardMX;	/* don't use MX records when canonifying */
230864562SgshapiroEXTERN bool	HoldErrs;	/* only output errors to transcript */
230964562SgshapiroEXTERN bool	IgnoreHostStatus;	/* ignore long term host status files */
231064562SgshapiroEXTERN bool	IgnrDot;	/* don't let dot end messages */
231164562SgshapiroEXTERN bool	LogUsrErrs;	/* syslog user errors (e.g., SMTP RCPT cmd) */
231264562SgshapiroEXTERN bool	MatchGecos;	/* look for user names in gecos field */
231364562SgshapiroEXTERN bool	MeToo;		/* send to the sender also */
231464562SgshapiroEXTERN bool	NoAlias;	/* suppress aliasing */
231564562SgshapiroEXTERN bool	NoConnect;	/* don't connect to non-local mailers */
231664562SgshapiroEXTERN bool	OnlyOneError;	/*  .... or only want to give one SMTP reply */
231764562SgshapiroEXTERN bool	QuickAbort;	/*  .... but only if we want a quick abort */
2318249729Sgshapiro#if _FFR_REJECT_NUL_BYTE
2319249729SgshapiroEXTERN bool	RejectNUL;	/* reject NUL input byte? */
2320249729Sgshapiro#endif /* _FFR_REJECT_NUL_BYTE */
2321132943Sgshapiro#if REQUIRES_DIR_FSYNC
2322110560SgshapiroEXTERN bool	RequiresDirfsync;	/* requires fsync() for directory */
2323132943Sgshapiro#endif /* REQUIRES_DIR_FSYNC */
232490792SgshapiroEXTERN bool	volatile RestartWorkGroup; /* daemon needs to restart some work groups */
232564562SgshapiroEXTERN bool	RrtImpliesDsn;	/* turn Return-Receipt-To: into DSN */
232664562SgshapiroEXTERN bool	SaveFrom;	/* save leading "From" lines */
232764562SgshapiroEXTERN bool	SendMIMEErrors;	/* send error messages in MIME format */
232864562SgshapiroEXTERN bool	SevenBitInput;	/* force 7-bit data on input */
232964562SgshapiroEXTERN bool	SingleLineFromHeader;	/* force From: header to be one line */
233064562SgshapiroEXTERN bool	SingleThreadDelivery;	/* single thread hosts on delivery */
233190792SgshapiroEXTERN bool	SoftBounce;	/* replace 5xy by 4xy (for testing) */
233277349SgshapiroEXTERN bool	volatile StopRequest;	/* stop sending output */
233364562SgshapiroEXTERN bool	SuprErrs;	/* set if we are suppressing errors */
233464562SgshapiroEXTERN bool	TryNullMXList;	/* if we are the best MX, try host directly */
233590792SgshapiroEXTERN bool	UseMSP;		/* mail submission: group writable queue ok? */
233673188SgshapiroEXTERN bool	WorkAroundBrokenAAAA;	/* some nameservers return SERVFAIL on AAAA queries */
233764562SgshapiroEXTERN bool	UseErrorsTo;	/* use Errors-To: header (back compat) */
233864562SgshapiroEXTERN bool	UseNameServer;	/* using DNS -- interpret h_errno & MX RRs */
233964562SgshapiroEXTERN char	InetMode;		/* default network for daemon mode */
234064562SgshapiroEXTERN char	OpMode;		/* operation mode, see below */
234164562SgshapiroEXTERN char	SpaceSub;	/* substitution for <lwsp> */
2342182352Sgshapiro#if _FFR_BADRCPT_SHUTDOWN
2343182352SgshapiroEXTERN int	BadRcptShutdown; /* Shutdown connection for rejected RCPTs */
2344182352SgshapiroEXTERN int	BadRcptShutdownGood; /* above even when there are good RCPTs */
2345182352Sgshapiro#endif /* _FFR_BADRCPT_SHUTDOWN */
2346203004SgshapiroEXTERN int	BadRcptThrottle; /* Throttle rejected RCPTs per SMTP message */
2347203004Sgshapiro#if _FFR_RCPTTHROTDELAY
2348203004SgshapiroEXTERN unsigned int BadRcptThrottleDelay; /* delay for BadRcptThrottle */
2349203004Sgshapiro#else
2350203004Sgshapiro# define BadRcptThrottleDelay	1
2351203004Sgshapiro#endif /* _FFR_RCPTTHROTDELAY */
235264562SgshapiroEXTERN int	CheckpointInterval;	/* queue file checkpoint interval */
235364562SgshapiroEXTERN int	ConfigLevel;	/* config file level */
235464562SgshapiroEXTERN int	ConnRateThrottle;	/* throttle for SMTP connection rate */
235577349SgshapiroEXTERN int	volatile CurChildren;	/* current number of daemonic children */
235664562SgshapiroEXTERN int	CurrentLA;	/* current load average */
235764562SgshapiroEXTERN int	DefaultNotify;	/* default DSN notification flags */
235890792SgshapiroEXTERN int	DelayLA;	/* load average to delay connections */
235990792SgshapiroEXTERN int	DontProbeInterfaces;	/* don't probe interfaces for names */
236064562SgshapiroEXTERN int	Errors;		/* set if errors (local to single pass) */
236164562SgshapiroEXTERN int	ExitStat;	/* exit status code */
236290792SgshapiroEXTERN int	FastSplit;	/* fast initial splitting of envelopes */
236364562SgshapiroEXTERN int	FileMode;	/* mode on files */
236464562SgshapiroEXTERN int	LineNumber;	/* line number in current input */
236564562SgshapiroEXTERN int	LogLevel;	/* level of logging to perform */
236664562SgshapiroEXTERN int	MaxAliasRecursion;	/* maximum depth of alias recursion */
236764562SgshapiroEXTERN int	MaxChildren;	/* maximum number of daemonic children */
236864562SgshapiroEXTERN int	MaxForwardEntries;	/* maximum number of forward entries */
236964562SgshapiroEXTERN int	MaxHeadersLength;	/* max length of headers */
237064562SgshapiroEXTERN int	MaxHopCount;	/* max # of hops until bounce */
237164562SgshapiroEXTERN int	MaxMacroRecursion;	/* maximum depth of macro recursion */
237264562SgshapiroEXTERN int	MaxMimeFieldLength;	/* maximum MIME field length */
237364562SgshapiroEXTERN int	MaxMimeHeaderLength;	/* maximum MIME header length */
2374157001SgshapiroEXTERN int	MaxNOOPCommands; /* max "noise" commands before slowdown */
237538032Speter
237664562SgshapiroEXTERN int	MaxRcptPerMsg;	/* max recipients per SMTP message */
237764562SgshapiroEXTERN int	MaxRuleRecursion;	/* maximum depth of ruleset recursion */
2378157001Sgshapiro#if _FFR_MSG_ACCEPT
2379159609SgshapiroEXTERN char	*MessageAccept; /* "Message accepted for delivery" reply text */
2380157001Sgshapiro#endif /* _FFR_MSG_ACCEPT */
2381157001Sgshapiro
238264562SgshapiroEXTERN int	MimeMode;	/* MIME processing mode */
238364562SgshapiroEXTERN int	NoRecipientAction;
238490792Sgshapiro
238590792Sgshapiro#if SM_CONF_SHM
238690792SgshapiroEXTERN int	Numfilesys;	/* number of queue file systems */
238790792SgshapiroEXTERN int	*PNumFileSys;
238890792Sgshapiro# define NumFileSys	(*PNumFileSys)
238990792Sgshapiro# else /* SM_CONF_SHM */
239090792SgshapiroEXTERN int	NumFileSys;	/* number of queue file systems */
239190792Sgshapiro# endif /* SM_CONF_SHM */
239290792Sgshapiro
239364562SgshapiroEXTERN int	QueueLA;	/* load average starting forced queueing */
239490792SgshapiroEXTERN int	RefuseLA;	/* load average refusing connections */
2395110560SgshapiroEXTERN time_t	RejectLogInterval;	/* time btwn log msgs while refusing */
2396157001Sgshapiro#if _FFR_MEMSTAT
2397157001SgshapiroEXTERN long	QueueLowMem;	/* low memory starting forced queueing */
2398157001SgshapiroEXTERN long	RefuseLowMem;	/* low memory refusing connections */
2399157001SgshapiroEXTERN char	*MemoryResource;/* memory resource to look up */
2400157001Sgshapiro#endif /* _FFR_MEMSTAT */
240190792SgshapiroEXTERN int	SuperSafe;	/* be extra careful, even if expensive */
240264562SgshapiroEXTERN int	VendorCode;	/* vendor-specific operation enhancements */
240364562SgshapiroEXTERN int	Verbose;	/* set if blow-by-blow desired */
240464562SgshapiroEXTERN gid_t	DefGid;		/* default gid to run as */
240564562SgshapiroEXTERN gid_t	RealGid;	/* real gid of caller */
240664562SgshapiroEXTERN gid_t	RunAsGid;	/* GID to become for bulk of run */
240790792SgshapiroEXTERN gid_t	EffGid;		/* effective gid */
240890792Sgshapiro#if SM_CONF_SHM
240990792SgshapiroEXTERN key_t	ShmKey;		/* shared memory key */
241094334SgshapiroEXTERN char	*ShmKeyFile;	/* shared memory key file */
241190792Sgshapiro#endif /* SM_CONF_SHM */
241290792SgshapiroEXTERN pid_t	CurrentPid;	/* current process id */
241390792SgshapiroEXTERN pid_t	DaemonPid;	/* process id of daemon */
2414132943SgshapiroEXTERN pid_t	PidFilePid;	/* daemon/queue runner who wrote pid file */
241564562SgshapiroEXTERN uid_t	DefUid;		/* default uid to run as */
241664562SgshapiroEXTERN uid_t	RealUid;	/* real uid of caller */
241764562SgshapiroEXTERN uid_t	RunAsUid;	/* UID to become for bulk of run */
241864562SgshapiroEXTERN uid_t	TrustedUid;	/* uid of trusted user for files and startup */
241990792SgshapiroEXTERN size_t	DataFileBufferSize;	/* size of buf for in-core data file */
242090792SgshapiroEXTERN time_t	DeliverByMin;	/* deliver by minimum time */
242164562SgshapiroEXTERN time_t	DialDelay;	/* delay between dial-on-demand tries */
242264562SgshapiroEXTERN time_t	SafeAlias;	/* interval to wait until @:@ in alias file */
242364562SgshapiroEXTERN time_t	ServiceCacheMaxAge;	/* refresh interval for cache */
242490792SgshapiroEXTERN size_t	XscriptFileBufferSize;	/* size of buf for in-core transcript file */
242564562SgshapiroEXTERN MODE_T	OldUmask;	/* umask when sendmail starts up */
242664562SgshapiroEXTERN long	MaxMessageSize;	/* advertised max size we will accept */
242764562SgshapiroEXTERN long	MinBlocksFree;	/* min # of blocks free on queue fs */
242864562SgshapiroEXTERN long	QueueFactor;	/* slope of queue function */
242964562SgshapiroEXTERN long	WkClassFact;	/* multiplier for message class -> priority */
243064562SgshapiroEXTERN long	WkRecipFact;	/* multiplier for # of recipients -> priority */
243164562SgshapiroEXTERN long	WkTimeFact;	/* priority offset each time this job is run */
243264562SgshapiroEXTERN char	*ControlSocketName; /* control socket filename [control.c] */
243364562SgshapiroEXTERN char	*CurHostName;	/* current host we are dealing with */
243464562SgshapiroEXTERN char	*DeadLetterDrop;	/* path to dead letter office */
243564562SgshapiroEXTERN char	*DefUser;	/* default user to run as (from DefUid) */
243664562SgshapiroEXTERN char	*DefaultCharSet;	/* default character set for MIME */
243764562SgshapiroEXTERN char	*DoubleBounceAddr;	/* where to send double bounces */
243864562SgshapiroEXTERN char	*ErrMsgFile;	/* file to prepend to all error messages */
2439132943SgshapiroEXTERN char	*FallbackMX;	/* fall back MX host */
2440132943SgshapiroEXTERN char	*FallbackSmartHost;	/* fall back smart host */
244164562SgshapiroEXTERN char	*FileName;	/* name to print on error messages */
244264562SgshapiroEXTERN char	*ForwardPath;	/* path to search for .forward files */
2443132943SgshapiroEXTERN char	*HeloName;	/* hostname to announce in HELO */
244464562SgshapiroEXTERN char	*HelpFile;	/* location of SMTP help file */
244564562SgshapiroEXTERN char	*HostStatDir;	/* location of host status information */
244664562SgshapiroEXTERN char	*HostsFile;	/* path to /etc/hosts file */
244790792Sgshapiroextern char	*Mbdb;		/* mailbox database type */
244864562SgshapiroEXTERN char	*MustQuoteChars;	/* quote these characters in phrases */
244964562SgshapiroEXTERN char	*MyHostName;	/* name of this host for SMTP messages */
245064562SgshapiroEXTERN char	*OperatorChars;	/* operators (old $o macro) */
245164562SgshapiroEXTERN char	*PidFile;	/* location of proc id file [conf.c] */
245264562SgshapiroEXTERN char	*PostMasterCopy;	/* address to get errs cc's */
245364562SgshapiroEXTERN char	*ProcTitlePrefix; /* process title prefix */
245464562SgshapiroEXTERN char	*RealHostName;	/* name of host we are talking to */
245564562SgshapiroEXTERN char	*RealUserName;	/* real user name of caller */
245677349SgshapiroEXTERN char	*volatile RestartRequest;/* a sendmail restart has been requested */
245764562SgshapiroEXTERN char	*RunAsUserName;	/* user to become for bulk of run */
245864562SgshapiroEXTERN char	*SafeFileEnv;	/* chroot location for file delivery */
245964562SgshapiroEXTERN char	*ServiceSwitchFile;	/* backup service switch */
246077349SgshapiroEXTERN char	*volatile ShutdownRequest;/* a sendmail shutdown has been requested */
2461223067SgshapiroEXTERN bool	volatile IntSig;
246264562SgshapiroEXTERN char	*SmtpGreeting;	/* SMTP greeting message (old $e macro) */
246364562SgshapiroEXTERN char	*SmtpPhase;	/* current phase in SMTP processing */
246464562SgshapiroEXTERN char	SmtpError[MAXLINE];	/* save failure error messages */
246564562SgshapiroEXTERN char	*StatFile;	/* location of statistics summary */
246664562SgshapiroEXTERN char	*TimeZoneSpec;	/* override time zone specification */
246764562SgshapiroEXTERN char	*UdbSpec;	/* user database source spec */
246864562SgshapiroEXTERN char	*UnixFromLine;	/* UNIX From_ line (old $l macro) */
246990792SgshapiroEXTERN char	**ExternalEnviron;	/* saved user (input) environment */
247077349SgshapiroEXTERN char	**SaveArgv;	/* argument vector for re-execing */
247164562SgshapiroEXTERN BITMAP256	DontBlameSendmail;	/* DontBlameSendmail bits */
247290792SgshapiroEXTERN SM_FILE_T	*InChannel;	/* input connection */
247390792SgshapiroEXTERN SM_FILE_T	*OutChannel;	/* output connection */
247490792SgshapiroEXTERN SM_FILE_T	*TrafficLogFile; /* file in which to log all traffic */
247590792Sgshapiro#if HESIOD
247664562SgshapiroEXTERN void	*HesiodContext;
247764562Sgshapiro#endif /* HESIOD */
247864562SgshapiroEXTERN ENVELOPE	*CurEnv;	/* envelope currently being processed */
247964562SgshapiroEXTERN char	*RuleSetNames[MAXRWSETS];	/* ruleset number to name */
248064562SgshapiroEXTERN char	*UserEnviron[MAXUSERENVIRON + 1];
248190792SgshapiroEXTERN struct rewrite	*RewriteRules[MAXRWSETS];
248264562SgshapiroEXTERN struct termescape	TermEscape;	/* terminal escape codes */
248364562SgshapiroEXTERN SOCKADDR	ConnectOnlyTo;	/* override connection address (for testing) */
248464562SgshapiroEXTERN SOCKADDR RealHostAddr;	/* address of host we are talking to */
248590792Sgshapiroextern const SM_EXC_TYPE_T EtypeQuickAbort; /* type of a QuickAbort exception */
248664562Sgshapiro
248790792Sgshapiro
2488132943SgshapiroEXTERN int ConnectionRateWindowSize;
2489223067Sgshapiro#if STARTTLS && USE_OPENSSL_ENGINE
2490223067SgshapiroEXTERN bool	SSLEngineInitialized;
2491223067Sgshapiro#endif /* STARTTLS && USE_OPENSSL_ENGINE */
249290792Sgshapiro
249338032Speter/*
249438032Speter**  Declarations of useful functions
249538032Speter*/
249638032Speter
249764562Sgshapiro/* Transcript file */
249864562Sgshapiroextern void	closexscript __P((ENVELOPE *));
249938032Speterextern void	openxscript __P((ENVELOPE *));
250064562Sgshapiro
250164562Sgshapiro/* error related */
250264562Sgshapiroextern void	buffer_errors __P((void));
250364562Sgshapiroextern void	flush_errors __P((bool));
250490792Sgshapiroextern void PRINTFLIKE(1, 2)	message __P((const char *, ...));
250590792Sgshapiroextern void PRINTFLIKE(1, 2)	nmessage __P((const char *, ...));
250690792Sgshapiroextern void PRINTFLIKE(1, 2)	syserr __P((const char *, ...));
250790792Sgshapiroextern void PRINTFLIKE(2, 3)	usrerrenh __P((char *, const char *, ...));
250890792Sgshapiroextern void PRINTFLIKE(1, 2)	usrerr __P((const char *, ...));
250964562Sgshapiroextern int	isenhsc __P((const char *, int));
251064562Sgshapiroextern int	extenhsc __P((const char *, int, char *));
251164562Sgshapiro
251264562Sgshapiro/* alias file */
251364562Sgshapiroextern void	alias __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
251464562Sgshapiroextern bool	aliaswait __P((MAP *, char *, bool));
251564562Sgshapiroextern void	forward __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
251690792Sgshapiroextern void	readaliases __P((MAP *, SM_FILE_T *, bool, bool));
251738032Speterextern bool	rebuildaliases __P((MAP *, bool));
251864562Sgshapiroextern void	setalias __P((char *));
251964562Sgshapiro
252064562Sgshapiro/* logging */
252164562Sgshapiroextern void	logdelivery __P((MAILER *, MCI *, char *, const char *, ADDRESS *, time_t, ENVELOPE *));
252238032Speterextern void	logsender __P((ENVELOPE *, char *));
252390792Sgshapiroextern void PRINTFLIKE(3, 4) sm_syslog __P((int, const char *, const char *, ...));
252464562Sgshapiro
252564562Sgshapiro/* SMTP */
252690792Sgshapiroextern void	giveresponse __P((int, char *, MAILER *, MCI *, ADDRESS *, time_t, ENVELOPE *, ADDRESS *));
2527141858Sgshapiroextern int	reply __P((MAILER *, MCI *, ENVELOPE *, time_t, void (*)__P((char *, bool, MAILER *, MCI *, ENVELOPE *)), char **, int));
252864562Sgshapiroextern void	smtp __P((char *volatile, BITMAP256, ENVELOPE *volatile));
252964562Sgshapiro#if SASL
253064562Sgshapiroextern int	smtpauth __P((MAILER *, MCI *, ENVELOPE *));
253164562Sgshapiro#endif /* SASL */
253290792Sgshapiroextern int	smtpdata __P((MAILER *, MCI *, ENVELOPE *, ADDRESS *, time_t));
253364562Sgshapiroextern int	smtpgetstat __P((MAILER *, MCI *, ENVELOPE *));
253464562Sgshapiroextern int	smtpmailfrom __P((MAILER *, MCI *, ENVELOPE *));
253564562Sgshapiroextern void	smtpmessage __P((char *, MAILER *, MCI *, ...));
253664562Sgshapiroextern void	smtpinit __P((MAILER *, MCI *, ENVELOPE *, bool));
253764562Sgshapiroextern char	*smtptodsn __P((int));
253864562Sgshapiroextern int	smtpprobe __P((MCI *));
253964562Sgshapiroextern void	smtpquit __P((MAILER *, MCI *, ENVELOPE *));
254090792Sgshapiroextern int	smtprcpt __P((ADDRESS *, MAILER *, MCI *, ENVELOPE *, ADDRESS *, time_t));
254138032Speterextern void	smtprset __P((MAILER *, MCI *, ENVELOPE *));
254264562Sgshapiro
2543157001Sgshapiro#define REPLYTYPE(r)	((r) / 100)		/* first digit of reply code */
2544223067Sgshapiro#define REPLYCLASS(r)	(((r) / 10) % 10)	/* second digit of reply code */
2545223067Sgshapiro#define REPLYMINOR(r)	((r) % 10)	/* last digit of reply code */
254664562Sgshapiro#define ISSMTPCODE(c)	(isascii(c[0]) && isdigit(c[0]) && \
254764562Sgshapiro		    isascii(c[1]) && isdigit(c[1]) && \
254864562Sgshapiro		    isascii(c[2]) && isdigit(c[2]))
254964562Sgshapiro#define ISSMTPREPLY(c)	(ISSMTPCODE(c) && \
255064562Sgshapiro		    (c[3] == ' ' || c[3] == '-' || c[3] == '\0'))
255164562Sgshapiro
255264562Sgshapiro/* delivery */
255390792Sgshapiroextern pid_t	dowork __P((int, int, char *, bool, bool, ENVELOPE *));
255490792Sgshapiroextern pid_t	doworklist __P((ENVELOPE *, bool, bool));
255538032Speterextern int	endmailer __P((MCI *, ENVELOPE *, char **));
255664562Sgshapiroextern int	mailfile __P((char *volatile, MAILER *volatile, ADDRESS *, volatile long, ENVELOPE *));
255738032Speterextern void	sendall __P((ENVELOPE *, int));
255864562Sgshapiro
255964562Sgshapiro/* stats */
256090792Sgshapiro#define STATS_NORMAL		'n'
2561132943Sgshapiro#define STATS_QUARANTINE	'q'
256290792Sgshapiro#define STATS_REJECT		'r'
256394334Sgshapiro#define STATS_CONNECT		'c'
256490792Sgshapiro
256590792Sgshapiroextern void	markstats __P((ENVELOPE *, ADDRESS *, int));
256664562Sgshapiroextern void	clearstats __P((void));
256738032Speterextern void	poststats __P((char *));
256864562Sgshapiro
256964562Sgshapiro/* control socket */
257064562Sgshapiroextern void	closecontrolsocket  __P((bool));
257164562Sgshapiroextern void	clrcontrol  __P((void));
257264562Sgshapiroextern void	control_command __P((int, ENVELOPE *));
257364562Sgshapiroextern int	opencontrolsocket __P((void));
257464562Sgshapiro
257590792Sgshapiro#if MILTER
257664562Sgshapiro/* milter functions */
257790792Sgshapiroextern void	milter_config __P((char *, struct milter **, int));
257864562Sgshapiroextern void	milter_setup __P((char *));
257964562Sgshapiroextern void	milter_set_option __P((char *, char *, bool));
2580173340Sgshapiroextern bool	milter_init __P((ENVELOPE *, char *, milters_T *));
258164562Sgshapiroextern void	milter_quit __P((ENVELOPE *));
258264562Sgshapiroextern void	milter_abort __P((ENVELOPE *));
258364562Sgshapiroextern char	*milter_connect __P((char *, SOCKADDR, ENVELOPE *, char *));
258464562Sgshapiroextern char	*milter_helo __P((char *, ENVELOPE *, char *));
258564562Sgshapiroextern char	*milter_envfrom __P((char **, ENVELOPE *, char *));
2586132943Sgshapiroextern char	*milter_data_cmd __P((ENVELOPE *, char *));
2587168515Sgshapiroextern char	*milter_envrcpt __P((char **, ENVELOPE *, char *, bool));
258864562Sgshapiroextern char	*milter_data __P((ENVELOPE *, char *));
2589132943Sgshapiroextern char	*milter_unknown __P((char *, ENVELOPE *, char *));
259090792Sgshapiro#endif /* MILTER */
259164562Sgshapiro
259290792Sgshapiroextern char	*addquotes __P((char *, SM_RPOOL_T *));
259338032Speterextern char	*arpadate __P((char *));
259464562Sgshapiroextern bool	atobool __P((char *));
259564562Sgshapiroextern int	atooct __P((char *));
259664562Sgshapiroextern void	auth_warning __P((ENVELOPE *, const char *, ...));
259764562Sgshapiroextern int	blocksignal __P((int));
259864562Sgshapiroextern bool	bitintersect __P((BITMAP256, BITMAP256));
259964562Sgshapiroextern bool	bitzerop __P((BITMAP256));
260090792Sgshapiroextern int	check_bodytype __P((char *));
260164562Sgshapiroextern void	buildfname __P((char *, char *, char *, int));
260290792Sgshapiroextern bool	chkclientmodifiers __P((int));
260390792Sgshapiroextern bool	chkdaemonmodifiers __P((int));
260464562Sgshapiroextern int	checkcompat __P((ADDRESS *, ENVELOPE *));
260564562Sgshapiro#ifdef XDEBUG
260664562Sgshapiroextern void	checkfd012 __P((char *));
260764562Sgshapiroextern void	checkfdopen __P((int, char *));
260864562Sgshapiro#endif /* XDEBUG */
260964562Sgshapiroextern void	checkfds __P((char *));
261064562Sgshapiroextern bool	chownsafe __P((int, bool));
261164562Sgshapiroextern void	cleanstrcpy __P((char *, char *, int));
261290792Sgshapiro#if SM_CONF_SHM
261390792Sgshapiroextern void	cleanup_shm __P((bool));
261490792Sgshapiro#endif /* SM_CONF_SHM */
2615132943Sgshapiroextern void	close_sendmail_pid __P((void));
261664562Sgshapiroextern void	clrdaemon __P((void));
2617120256Sgshapiroextern void	collect __P((SM_FILE_T *, bool, HDR **, ENVELOPE *, bool));
2618132943Sgshapiroextern bool	connection_rate_check __P((SOCKADDR *, ENVELOPE *));
261964562Sgshapiroextern time_t	convtime __P((char *, int));
262090792Sgshapiroextern char	**copyplist __P((char **, bool, SM_RPOOL_T *));
262164562Sgshapiroextern void	copy_class __P((int, int));
2622132943Sgshapiroextern int	count_open_connections __P((SOCKADDR *));
262364562Sgshapiroextern time_t	curtime __P((void));
262464562Sgshapiroextern char	*defcharset __P((ENVELOPE *));
262564562Sgshapiroextern char	*denlstring __P((char *, bool, bool));
2626132943Sgshapiroextern void	dferror __P((SM_FILE_T *volatile, char *, ENVELOPE *));
262764562Sgshapiroextern void	disconnect __P((int, ENVELOPE *));
262890792Sgshapiroextern void	disk_status __P((SM_FILE_T *, char *));
262990792Sgshapiroextern bool	dns_getcanonname __P((char *, int, bool, int *, int *));
263077349Sgshapiroextern pid_t	dofork __P((void));
263138032Speterextern int	drop_privileges __P((bool));
263264562Sgshapiroextern int	dsntoexitstat __P((char *));
263364562Sgshapiroextern void	dumpfd __P((int, bool, bool));
2634168515Sgshapiro#if SM_HEAP_CHECK
2635168515Sgshapiroextern void	dumpstab __P((void));
2636168515Sgshapiro#endif /* SM_HEAP_CHECK */
263764562Sgshapiroextern void	dumpstate __P((char *));
263890792Sgshapiroextern bool	enoughdiskspace __P((long, ENVELOPE *));
263964562Sgshapiroextern char	*exitstat __P((char *));
264090792Sgshapiroextern void	fatal_error __P((SM_EXC_T *));
2641168515Sgshapiroextern char	*fgetfolded __P((char *, int *, SM_FILE_T *));
264238032Speterextern void	fill_fd __P((int, char *));
264364562Sgshapiroextern char	*find_character __P((char *, int));
264490792Sgshapiroextern int	finduser __P((char *, bool *, SM_MBDB_T *));
264590792Sgshapiroextern void	finis __P((bool, bool, volatile int));
264664562Sgshapiroextern void	fixcrlf __P((char *, bool));
2647168515Sgshapiroextern long	freediskspace __P((const char *, long *));
264877349Sgshapiro#if NETINET6 && NEEDSGETIPNODE
264977349Sgshapiroextern void	freehostent __P((struct hostent *));
265090792Sgshapiro#endif /* NETINET6 && NEEDSGETIPNODE */
265164562Sgshapiroextern char	*get_column __P((char *, int, int, char *, int));
265264562Sgshapiroextern char	*getauthinfo __P((int, bool *));
265364562Sgshapiroextern int	getdtsize __P((void));
265490792Sgshapiroextern int	getla __P((void));
265590792Sgshapiroextern char	*getmodifiers __P((char *, BITMAP256));
265664562Sgshapiroextern BITMAP256	*getrequests __P((ENVELOPE *));
265764562Sgshapiroextern char	*getvendor __P((int));
265864562Sgshapiroextern void	help __P((char *, ENVELOPE *));
265964562Sgshapiroextern void	init_md __P((int, char **));
266064562Sgshapiroextern void	initdaemon __P((void));
266164562Sgshapiroextern void	inithostmaps __P((void));
266264562Sgshapiroextern void	initmacros __P((ENVELOPE *));
266364562Sgshapiroextern void	initsetproctitle __P((int, char **, char **));
266464562Sgshapiroextern void	init_vendor_macros __P((ENVELOPE *));
266564562Sgshapiroextern SIGFUNC_DECL	intsig __P((int));
2666249729Sgshapiroextern bool	isatom __P((const char *));
266764562Sgshapiroextern bool	isloopback __P((SOCKADDR sa));
266864562Sgshapiroextern void	load_if_names __P((void));
266964562Sgshapiroextern bool	lockfile __P((int, char *, char *, int));
267064562Sgshapiroextern void	log_sendmail_pid __P((ENVELOPE *));
267190792Sgshapiroextern void	logundelrcpts __P((ENVELOPE *, char *, int, bool));
267264562Sgshapiroextern char	lower __P((int));
267364562Sgshapiroextern void	makelower __P((char *));
267464562Sgshapiroextern int	makeconnection_ds __P((char *, MCI *));
267590792Sgshapiroextern int	makeconnection __P((char *, volatile unsigned int, MCI *, ENVELOPE *, time_t));
267690792Sgshapiroextern void	makeworkgroups __P((void));
2677141858Sgshapiroextern void	markfailure __P((ENVELOPE *, ADDRESS *, MCI *, int, bool));
267890792Sgshapiroextern void	mark_work_group_restart __P((int, int));
2679168515Sgshapiroextern MCI	*mci_new __P((SM_RPOOL_T *));
2680168515Sgshapiroextern char	*munchstring __P((char *, char **, int));
268164562Sgshapiroextern struct hostent	*myhostname __P((char *, int));
2682132943Sgshapiroextern char	*newstr __P((const char *));
2683110560Sgshapiro#if NISPLUS
268464562Sgshapiroextern char	*nisplus_default_domain __P((void));	/* extern for Sun */
2685110560Sgshapiro#endif /* NISPLUS */
268664562Sgshapiroextern bool	path_is_dir __P((char *, bool));
268790792Sgshapiroextern int	pickqdir __P((QUEUEGRP *qg, long fsize, ENVELOPE *e));
268864562Sgshapiroextern char	*pintvl __P((time_t, bool));
2689132943Sgshapiroextern void	printav __P((SM_FILE_T *, char **));
2690132943Sgshapiroextern void	printmailer __P((SM_FILE_T *, MAILER *));
269190792Sgshapiroextern void	printnqe __P((SM_FILE_T *, char *));
269264562Sgshapiroextern void	printopenfds __P((bool));
269364562Sgshapiroextern void	printqueue __P((void));
269464562Sgshapiroextern void	printrules __P((void));
269577349Sgshapiroextern pid_t	prog_open __P((char **, int *, ENVELOPE *));
2696157001Sgshapiroextern bool	putline __P((char *, MCI *));
2697157001Sgshapiroextern bool	putxline __P((char *, size_t, MCI *, int));
269890792Sgshapiroextern void	queueup_macros __P((int, SM_FILE_T *, ENVELOPE *));
269964562Sgshapiroextern void	readcf __P((char *, bool, ENVELOPE *));
270064562Sgshapiroextern SIGFUNC_DECL	reapchild __P((int));
270164562Sgshapiroextern int	releasesignal __P((int));
270264562Sgshapiroextern void	resetlimits __P((void));
270390792Sgshapiroextern void	restart_daemon __P((void));
2704120256Sgshapiroextern void	restart_marked_work_groups __P((void));
270564562Sgshapiroextern bool	rfc822_string __P((char *));
2706168515Sgshapiroextern void	rmexpstab __P((void));
270790792Sgshapiroextern bool	savemail __P((ENVELOPE *, bool));
270864562Sgshapiroextern void	seed_random __P((void));
270964562Sgshapiroextern void	sendtoargv __P((char **, ENVELOPE *));
271064562Sgshapiroextern void	setclientoptions __P((char *));
271164562Sgshapiroextern bool	setdaemonoptions __P((char *));
271264562Sgshapiroextern void	setdefaults __P((ENVELOPE *));
271364562Sgshapiroextern void	setdefuser __P((void));
271464562Sgshapiroextern bool	setvendor __P((char *));
271590792Sgshapiroextern void	set_op_mode __P((int));
271664562Sgshapiroextern void	setoption __P((int, char *, bool, bool, ENVELOPE *));
271738032Speterextern sigfunc_t	setsignal __P((int, sigfunc_t));
2718157001Sgshapiroextern void	sm_setuserenv __P((const char *, const char *));
271964562Sgshapiroextern void	settime __P((ENVELOPE *));
2720182352Sgshapiro#if STARTTLS
2721182352Sgshapiroextern void	set_tls_rd_tmo __P((int));
2722182352Sgshapiro#else /* STARTTLS */
2723182352Sgshapiro#define set_tls_rd_tmo(rd_tmo)
2724182352Sgshapiro#endif /* STARTTLS */
272590792Sgshapiroextern char	*sfgets __P((char *, int, SM_FILE_T *, time_t, char *));
272690792Sgshapiroextern char	*shortenstring __P((const char *, size_t));
272773188Sgshapiroextern char	*shorten_hostname __P((char []));
272864562Sgshapiroextern bool	shorten_rfc822_string __P((char *, size_t));
272977349Sgshapiroextern void	shutdown_daemon __P((void));
2730132943Sgshapiroextern void	sm_closefrom __P((int lowest, int highest));
2731132943Sgshapiroextern void	sm_close_on_exec __P((int lowest, int highest));
273264562Sgshapiroextern struct hostent	*sm_gethostbyname __P((char *, int));
273338032Speterextern struct hostent	*sm_gethostbyaddr __P((char *, int, int));
273490792Sgshapiroextern void	sm_getla __P((void));
273538032Speterextern struct passwd	*sm_getpwnam __P((char *));
273638032Speterextern struct passwd	*sm_getpwuid __P((UID_T));
273764562Sgshapiroextern void	sm_setproctitle __P((bool, ENVELOPE *, const char *, ...));
273890792Sgshapiroextern pid_t	sm_wait __P((int *));
273990792Sgshapiroextern bool	split_by_recipient __P((ENVELOPE *e));
274077349Sgshapiroextern void	stop_sendmail __P((void));
2741110560Sgshapiroextern void	stripbackslash __P((char *));
274298841Sgshapiroextern bool	strreplnonprt __P((char *, int));
274390792Sgshapiroextern bool	strcontainedin __P((bool, char *, char *));
274464562Sgshapiroextern int	switch_map_find __P((char *, char *[], short []));
2745168515Sgshapiro#if STARTTLS
2746168515Sgshapiroextern void	tls_set_verify __P((SSL_CTX *, SSL *, bool));
2747168515Sgshapiro#endif /* STARTTLS */
274864562Sgshapiroextern bool	transienterror __P((int));
274990792Sgshapiroextern void	truncate_at_delim __P((char *, size_t, int));
275064562Sgshapiroextern void	tTflag __P((char *));
275190792Sgshapiroextern void	tTsetup __P((unsigned char *, unsigned int, char *));
275290792Sgshapiroextern SIGFUNC_DECL	tick __P((int));
275364562Sgshapiroextern char	*ttypath __P((void));
275464562Sgshapiroextern void	unlockqueue __P((ENVELOPE *));
275564562Sgshapiro#if !HASUNSETENV
275664562Sgshapiroextern void	unsetenv __P((char *));
275764562Sgshapiro#endif /* !HASUNSETENV */
275890792Sgshapiro
275990792Sgshapiro/* update file system information: +/- some blocks */
276090792Sgshapiro#if SM_CONF_SHM
2761184980Sgshapiroextern void	upd_qs __P((ENVELOPE *, int, int, char *));
2762147078Sgshapiro# define updfs(e, count, space, where) upd_qs(e, count, space, where)
276390792Sgshapiro#else /* SM_CONF_SHM */
2764147078Sgshapiro# define updfs(e, count, space, where)
2765147078Sgshapiro# define upd_qs(e, count, space, where)
276690792Sgshapiro#endif /* SM_CONF_SHM */
276790792Sgshapiro
276864562Sgshapiroextern char	*username __P((void));
276964562Sgshapiroextern bool	usershellok __P((char *, char *));
277064562Sgshapiroextern void	vendor_post_defaults __P((ENVELOPE *));
277164562Sgshapiroextern void	vendor_pre_defaults __P((ENVELOPE *));
277264562Sgshapiroextern int	waitfor __P((pid_t));
277364562Sgshapiroextern bool	writable __P((char *, ADDRESS *, long));
277490792Sgshapiro#if SM_HEAP_CHECK
277590792Sgshapiro# define xalloc(size)	xalloc_tagged(size, __FILE__, __LINE__)
277690792Sgshapiroextern char *xalloc_tagged __P((int, char*, int));
277790792Sgshapiro#else /* SM_HEAP_CHECK */
277890792Sgshapiroextern char *xalloc __P((int));
277990792Sgshapiro#endif /* SM_HEAP_CHECK */
2780132943Sgshapiroextern void	xputs __P((SM_FILE_T *, const char *));
278164562Sgshapiroextern char	*xtextify __P((char *, char *));
278264562Sgshapiroextern bool	xtextok __P((char *));
278390792Sgshapiroextern int	xunlink __P((char *));
278464562Sgshapiroextern char	*xuntextify __P((char *));
278590792Sgshapiro
278690792Sgshapiro
2787168515Sgshapiro#undef EXTERN
278890792Sgshapiro#endif /* ! _SENDMAIL_H */
2789