xref: /freebsd/contrib/sendmail/src/sendmail.h (revision 17d6c636720d00f77e5d098daf4c278f89d84f7b)
1 /*
2  * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
3  *	All rights reserved.
4  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
5  * Copyright (c) 1988, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * By using this file, you agree to the terms and conditions set
9  * forth in the LICENSE file which can be found at the top level of
10  * the sendmail distribution.
11  */
12 
13 /*
14 **  SENDMAIL.H -- MTA-specific definitions for sendmail.
15 */
16 
17 #ifndef _SENDMAIL_H
18 #define _SENDMAIL_H 1
19 
20 #ifdef _DEFINE
21 # define EXTERN
22 # ifndef lint
23 static char SmailId[] =	"@(#)$Id: sendmail.h,v 8.517.4.70 2001/08/14 23:08:12 ca Exp $";
24 # endif /* ! lint */
25 #else /* _DEFINE */
26 # define EXTERN extern
27 #endif /* _DEFINE */
28 
29 
30 #include <unistd.h>
31 
32 #if SFIO
33 # include <sfio/stdio.h>
34 # if defined(SFIO_VERSION) && SFIO_VERSION > 20000000L
35    ERROR README: SFIO 2000 does not work with sendmail, use SFIO 1999 instead.
36 # endif /* defined(SFIO_VERSION) && SFIO_VERSION > 20000000L */
37 #endif /* SFIO */
38 
39 #include <stddef.h>
40 #include <stdlib.h>
41 #if !SFIO
42 # include <stdio.h>
43 #endif /* !SFIO */
44 #include <ctype.h>
45 #include <setjmp.h>
46 #include <string.h>
47 #include <time.h>
48 # ifdef EX_OK
49 #  undef EX_OK			/* for SVr4.2 SMP */
50 # endif /* EX_OK */
51 #include <sysexits.h>
52 
53 #include "sendmail/sendmail.h"
54 #include "bf.h"
55 #include "timers.h"
56 
57 #ifdef LOG
58 # include <syslog.h>
59 #endif /* LOG */
60 
61 
62 
63 # if NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25
64 #  include <sys/socket.h>
65 # endif /* NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25 */
66 # if NETUNIX
67 #  include <sys/un.h>
68 # endif /* NETUNIX */
69 # if NETINET || NETINET6
70 #  include <netinet/in.h>
71 # endif /* NETINET || NETINET6 */
72 # if NETINET6
73 /*
74 **  There is no standard yet for IPv6 includes.
75 **  Specify OS specific implementation in conf.h
76 */
77 # endif /* NETINET6 */
78 # if NETISO
79 #  include <netiso/iso.h>
80 # endif /* NETISO */
81 # if NETNS
82 #  include <netns/ns.h>
83 # endif /* NETNS */
84 # if NETX25
85 #  include <netccitt/x25.h>
86 # endif /* NETX25 */
87 
88 # if NAMED_BIND
89 #  include <arpa/nameser.h>
90 #  ifdef NOERROR
91 #   undef NOERROR		/* avoid <sys/streams.h> conflict */
92 #  endif /* NOERROR */
93 #  include <resolv.h>
94 # endif /* NAMED_BIND */
95 
96 # ifdef HESIOD
97 #  include <hesiod.h>
98 #  if !defined(HES_ER_OK) || defined(HESIOD_INTERFACES)
99 #   define HESIOD_INIT		/* support for the new interface */
100 #  endif /* !defined(HES_ER_OK) || defined(HESIOD_INTERFACES) */
101 # endif /* HESIOD */
102 
103 #if STARTTLS
104 # if !SFIO && !_FFR_TLS_TOREK
105   ERROR README: STARTTLS requires SFIO
106 # endif /* !SFIO && !_FFR_TLS_TOREK */
107 # if SFIO && _FFR_TLS_TOREK
108   ERROR README: Can not do both SFIO and _FFR_TLS_TOREK
109 # endif /* SFIO && _FFR_TLS_TOREK */
110 #  include <openssl/ssl.h>
111 #endif /* STARTTLS */
112 
113 #if SASL  /* include the sasl include files if we have them */
114 # include <sasl.h>
115 # if defined(SASL_VERSION_MAJOR) && defined(SASL_VERSION_MINOR) && defined(SASL_VERSION_STEP)
116 #  define SASL_VERSION (SASL_VERSION_MAJOR * 10000)  + (SASL_VERSION_MINOR * 100) + SASL_VERSION_STEP
117 #  if SASL == 1
118 #   undef SASL
119 #   define SASL SASL_VERSION
120 #  else /* SASL == 1 */
121 #   if SASL != SASL_VERSION
122   ERROR README: -DSASL (SASL) does not agree with the version of the CYRUS_SASL library (SASL_VERSION)
123   ERROR README: see README!
124 #   endif /* SASL != SASL_VERSION */
125 #  endif /* SASL == 1 */
126 # else /* defined(SASL_VERSION_MAJOR) && defined(SASL_VERSION_MINOR) && defined(SASL_VERSION_STEP) */
127 #  if SASL == 1
128   ERROR README: please set -DSASL to the version of the CYRUS_SASL library
129   ERROR README: see README!
130 #  endif /* SASL == 1 */
131 # endif /* defined(SASL_VERSION_MAJOR) && defined(SASL_VERSION_MINOR) && defined(SASL_VERSION_STEP) */
132 #endif /* SASL */
133 
134 /*
135 **  Following are "sort of" configuration constants, but they should
136 **  be pretty solid on most architectures today.  They have to be
137 **  defined after <arpa/nameser.h> because some versions of that
138 **  file also define them.  In all cases, we can't use sizeof because
139 **  some systems (e.g., Crays) always treat everything as being at
140 **  least 64 bits.
141 */
142 
143 #ifndef INADDRSZ
144 # define INADDRSZ	4		/* size of an IPv4 address in bytes */
145 #endif /* ! INADDRSZ */
146 #ifndef IN6ADDRSZ
147 # define IN6ADDRSZ	16		/* size of an IPv6 address in bytes */
148 #endif /* ! IN6ADDRSZ */
149 #ifndef INT16SZ
150 # define INT16SZ	2		/* size of a 16 bit integer in bytes */
151 #endif /* ! INT16SZ */
152 #ifndef INT32SZ
153 # define INT32SZ	4		/* size of a 32 bit integer in bytes */
154 #endif /* ! INT32SZ */
155 #ifndef INADDR_LOOPBACK
156 # define INADDR_LOOPBACK	0x7f000001	/* loopback address */
157 #endif /* ! INADDR_LOOPBACK */
158 
159 /*
160 **  Error return from inet_addr(3), in case not defined in /usr/include.
161 */
162 
163 #ifndef INADDR_NONE
164 # define INADDR_NONE	0xffffffff
165 #endif /* ! INADDR_NONE */
166 
167 
168 /* forward references for prototypes */
169 typedef struct envelope	ENVELOPE;
170 typedef struct mailer	MAILER;
171 
172 /*
173 **  Address structure.
174 **	Addresses are stored internally in this structure.
175 */
176 
177 struct address
178 {
179 	char		*q_paddr;	/* the printname for the address */
180 	char		*q_user;	/* user name */
181 	char		*q_ruser;	/* real user name, or NULL if q_user */
182 	char		*q_host;	/* host name */
183 	struct mailer	*q_mailer;	/* mailer to use */
184 	u_long		q_flags;	/* status flags, see below */
185 	uid_t		q_uid;		/* user-id of receiver (if known) */
186 	gid_t		q_gid;		/* group-id of receiver (if known) */
187 	char		*q_home;	/* home dir (local mailer only) */
188 	char		*q_fullname;	/* full name if known */
189 	struct address	*q_next;	/* chain */
190 	struct address	*q_alias;	/* address this results from */
191 	char		*q_owner;	/* owner of q_alias */
192 	struct address	*q_tchain;	/* temporary use chain */
193 	char		*q_orcpt;	/* ORCPT parameter from RCPT TO: line */
194 	char		*q_status;	/* status code for DSNs */
195 	char		*q_rstatus;	/* remote status message for DSNs */
196 	time_t		q_statdate;	/* date of status messages */
197 	char		*q_statmta;	/* MTA generating q_rstatus */
198 	short		q_state;	/* address state, see below */
199 	short		q_specificity;	/* how "specific" this address is */
200 };
201 
202 typedef struct address ADDRESS;
203 
204 /* bit values for q_flags */
205 #define QGOODUID	0x00000001	/* the q_uid q_gid fields are good */
206 #define QPRIMARY	0x00000002	/* set from RCPT or argv */
207 #define QNOTREMOTE	0x00000004	/* address not for remote forwarding */
208 #define QSELFREF	0x00000008	/* this address references itself */
209 #define QBOGUSSHELL	0x00000010	/* user has no valid shell listed */
210 #define QUNSAFEADDR	0x00000020	/* address acquired via unsafe path */
211 #define QPINGONSUCCESS	0x00000040	/* give return on successful delivery */
212 #define QPINGONFAILURE	0x00000080	/* give return on failure */
213 #define QPINGONDELAY	0x00000100	/* give return on message delay */
214 #define QHASNOTIFY	0x00000200	/* propogate notify parameter */
215 #define QRELAYED	0x00000400	/* DSN: relayed to non-DSN aware sys */
216 #define QEXPANDED	0x00000800	/* DSN: undergone list expansion */
217 #define QDELIVERED	0x00001000	/* DSN: successful final delivery */
218 #define QDELAYED	0x00002000	/* DSN: message delayed */
219 #define QALIAS		0x00004000	/* expanded alias */
220 #define QTHISPASS	0x40000000	/* temp: address set this pass */
221 #define QRCPTOK		0x80000000	/* recipient() processed address */
222 
223 #define Q_PINGFLAGS	(QPINGONSUCCESS|QPINGONFAILURE|QPINGONDELAY)
224 
225 /* values for q_state */
226 #define QS_OK		0		/* address ok (for now)/not yet tried */
227 #define QS_SENT		1		/* good address, delivery complete */
228 #define QS_BADADDR	2		/* illegal address */
229 #define QS_QUEUEUP	3		/* save address in queue */
230 #define QS_VERIFIED	4		/* verified, but not expanded */
231 #define QS_DONTSEND	5		/* don't send to this address */
232 #define QS_EXPANDED	6		/* QS_DONTSEND: expanded */
233 #define QS_SENDER	7		/* QS_DONTSEND: message sender (MeToo) */
234 #define QS_CLONED	8		/* QS_DONTSEND: addr cloned to split envelope */
235 #define QS_DISCARDED	9		/* QS_DONTSEND: rcpt discarded (EF_DISCARD) */
236 #define QS_REPLACED	10		/* QS_DONTSEND: maplocaluser()/UserDB replaced */
237 #define QS_REMOVED	11		/* QS_DONTSEND: removed (removefromlist()) */
238 #define QS_DUPLICATE	12		/* QS_DONTSEND: duplicate suppressed */
239 #define QS_INCLUDED	13		/* QS_DONTSEND: :include: delivery */
240 
241 /* address state testing primitives */
242 #define QS_IS_OK(s)		((s) == QS_OK)
243 #define QS_IS_SENT(s)		((s) == QS_SENT)
244 #define QS_IS_BADADDR(s)	((s) == QS_BADADDR)
245 #define QS_IS_QUEUEUP(s)	((s) == QS_QUEUEUP)
246 #define QS_IS_VERIFIED(s)	((s) == QS_VERIFIED)
247 #define QS_IS_EXPANDED(s)	((s) == QS_EXPANDED)
248 #define QS_IS_REMOVED(s)	((s) == QS_REMOVED)
249 #define QS_IS_UNDELIVERED(s)	((s) == QS_OK || \
250 				 (s) == QS_QUEUEUP || \
251 				 (s) == QS_VERIFIED)
252 #define QS_IS_SENDABLE(s)	((s) == QS_OK || \
253 				 (s) == QS_QUEUEUP)
254 #define QS_IS_ATTEMPTED(s)	((s) == QS_QUEUEUP || \
255 				 (s) == QS_SENT)
256 #define QS_IS_DEAD(s)		((s) == QS_DONTSEND || \
257 				 (s) == QS_CLONED || \
258 				 (s) == QS_SENDER || \
259 				 (s) == QS_DISCARDED || \
260 				 (s) == QS_REPLACED || \
261 				 (s) == QS_REMOVED || \
262 				 (s) == QS_DUPLICATE || \
263 				 (s) == QS_INCLUDED || \
264 				 (s) == QS_EXPANDED)
265 
266 
267 #define NULLADDR	((ADDRESS *) NULL)
268 
269 extern ADDRESS	NullAddress;	/* a null (template) address [main.c] */
270 
271 /* functions */
272 extern void	cataddr __P((char **, char **, char *, int, int));
273 extern char	*crackaddr __P((char *));
274 extern bool	emptyaddr __P((ADDRESS *));
275 extern ADDRESS	*getctladdr __P((ADDRESS *));
276 extern int	include __P((char *, bool, ADDRESS *, ADDRESS **, int, ENVELOPE *));
277 extern bool	invalidaddr __P((char *, char *));
278 extern ADDRESS	*parseaddr __P((char *, ADDRESS *, int, int, char **, ENVELOPE *));
279 extern char	**prescan __P((char *, int, char[], int, char **, u_char *));
280 extern void	printaddr __P((ADDRESS *, bool));
281 extern ADDRESS	*recipient __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
282 extern char	*remotename __P((char *, MAILER *, int, int *, ENVELOPE *));
283 extern int	rewrite __P((char **, int, int, ENVELOPE *));
284 extern bool	sameaddr __P((ADDRESS *, ADDRESS *));
285 extern int	sendtolist __P((char *, ADDRESS *, ADDRESS **, int, ENVELOPE *));
286 extern int	removefromlist __P((char *, ADDRESS **, ENVELOPE *));
287 extern void	setsender __P((char *, ENVELOPE *, char **, int, bool));
288 
289 /*
290 **  Mailer definition structure.
291 **	Every mailer known to the system is declared in this
292 **	structure.  It defines the pathname of the mailer, some
293 **	flags associated with it, and the argument vector to
294 **	pass to it.  The flags are defined in conf.c
295 **
296 **	The argument vector is expanded before actual use.  All
297 **	words except the first are passed through the macro
298 **	processor.
299 */
300 
301 struct mailer
302 {
303 	char	*m_name;	/* symbolic name of this mailer */
304 	char	*m_mailer;	/* pathname of the mailer to use */
305 	char	*m_mtatype;	/* type of this MTA */
306 	char	*m_addrtype;	/* type for addresses */
307 	char	*m_diagtype;	/* type for diagnostics */
308 	BITMAP256 m_flags;	/* status flags, see below */
309 	short	m_mno;		/* mailer number internally */
310 	short	m_nice;		/* niceness to run at (mostly for prog) */
311 	char	**m_argv;	/* template argument vector */
312 	short	m_sh_rwset;	/* rewrite set: sender header addresses */
313 	short	m_se_rwset;	/* rewrite set: sender envelope addresses */
314 	short	m_rh_rwset;	/* rewrite set: recipient header addresses */
315 	short	m_re_rwset;	/* rewrite set: recipient envelope addresses */
316 	char	*m_eol;		/* end of line string */
317 	long	m_maxsize;	/* size limit on message to this mailer */
318 	int	m_linelimit;	/* max # characters per line */
319 	int	m_maxdeliveries; /* max deliveries per mailer connection */
320 	char	*m_execdir;	/* directory to chdir to before execv */
321 	char	*m_rootdir;	/* directory to chroot to before execv */
322 	uid_t	m_uid;		/* UID to run as */
323 	gid_t	m_gid;		/* GID to run as */
324 	char	*m_defcharset;	/* default character set */
325 	time_t	m_wait;		/* timeout to wait for end */
326 #if _FFR_DYNAMIC_TOBUF
327 	int	m_maxrcpt;	/* max recipients per envelope client-side */
328 #endif /* _FFR_DYNAMIC_TOBUF */
329 };
330 
331 /* bits for m_flags */
332 #define M_ESMTP		'a'	/* run Extended SMTP protocol */
333 #define M_ALIASABLE	'A'	/* user can be LHS of an alias */
334 #define M_BLANKEND	'b'	/* ensure blank line at end of message */
335 #define M_NOCOMMENT	'c'	/* don't include comment part of address */
336 #define M_CANONICAL	'C'	/* make addresses canonical "u@dom" */
337 #define M_NOBRACKET	'd'	/* never angle bracket envelope route-addrs */
338 		/*	'D'	   CF: include Date: */
339 #define M_EXPENSIVE	'e'	/* it costs to use this mailer.... */
340 #define M_ESCFROM	'E'	/* escape From lines to >From */
341 #define M_FOPT		'f'	/* mailer takes picky -f flag */
342 		/*	'F'	   CF: include From: or Resent-From: */
343 #define M_NO_NULL_FROM	'g'	/* sender of errors should be $g */
344 #define M_HST_UPPER	'h'	/* preserve host case distinction */
345 #define M_PREHEAD	'H'	/* MAIL11V3: preview headers */
346 #define M_UDBENVELOPE	'i'	/* do udbsender rewriting on envelope */
347 #define M_INTERNAL	'I'	/* SMTP to another sendmail site */
348 #define M_UDBRECIPIENT	'j'	/* do udbsender rewriting on recipient lines */
349 #define M_NOLOOPCHECK	'k'	/* don't check for loops in HELO command */
350 #define M_CHUNKING	'K'	/* CHUNKING: reserved for future use */
351 #define M_LOCALMAILER	'l'	/* delivery is to this host */
352 #define M_LIMITS	'L'	/* must enforce SMTP line limits */
353 #define M_MUSER		'm'	/* can handle multiple users at once */
354 		/*	'M'	   CF: include Message-Id: */
355 #define M_NHDR		'n'	/* don't insert From line */
356 #define M_MANYSTATUS	'N'	/* MAIL11V3: DATA returns multi-status */
357 #define M_RUNASRCPT	'o'	/* always run mailer as recipient */
358 #define M_FROMPATH	'p'	/* use reverse-path in MAIL FROM: */
359 		/*	'P'	   CF: include Return-Path: */
360 #define M_VRFY250	'q'	/* VRFY command returns 250 instead of 252 */
361 #define M_ROPT		'r'	/* mailer takes picky -r flag */
362 #define M_SECURE_PORT	'R'	/* try to send on a reserved TCP port */
363 #define M_STRIPQ	's'	/* strip quote chars from user/host */
364 #define M_SPECIFIC_UID	'S'	/* run as specific uid/gid */
365 #define M_USR_UPPER	'u'	/* preserve user case distinction */
366 #define M_UGLYUUCP	'U'	/* this wants an ugly UUCP from line */
367 #define M_CONTENT_LEN	'v'	/* add Content-Length: header (SVr4) */
368 		/*	'V'	   UIUC: !-relativize all addresses */
369 #define M_HASPWENT	'w'	/* check for /etc/passwd entry */
370 		/*	'x'	   CF: include Full-Name: */
371 #define M_XDOT		'X'	/* use hidden-dot algorithm */
372 #define M_LMTP		'z'	/* run Local Mail Transport Protocol */
373 #define M_NOMX		'0'	/* turn off MX lookups */
374 #define M_NONULLS	'1'	/* don't send null bytes */
375 #define M_EBCDIC	'3'	/* extend Q-P encoding for EBCDIC */
376 #define M_TRYRULESET5	'5'	/* use ruleset 5 after local aliasing */
377 #define M_7BITHDRS	'6'	/* strip headers to 7 bits even in 8 bit path */
378 #define M_7BITS		'7'	/* use 7-bit path */
379 #define M_8BITS		'8'	/* force "just send 8" behaviour */
380 #define M_MAKE8BIT	'9'	/* convert 7 -> 8 bit if appropriate */
381 #define M_CHECKINCLUDE	':'	/* check for :include: files */
382 #define M_CHECKPROG	'|'	/* check for |program addresses */
383 #define M_CHECKFILE	'/'	/* check for /file addresses */
384 #define M_CHECKUDB	'@'	/* user can be user database key */
385 #define M_CHECKHDIR	'~'	/* SGI: check for valid home directory */
386 #define M_HOLD		'%'	/* Hold delivery until ETRN/-qI/-qR/-qS */
387 #define M_PLUS		'+'	/* Reserved: Used in mc for adding new flags */
388 #define M_MINUS		'-'	/* Reserved: Used in mc for removing flags */
389 
390 /* functions */
391 extern void	initerrmailers __P((void));
392 extern void	makemailer __P((char *));
393 
394 /*
395 **  Information about currently open connections to mailers, or to
396 **  hosts that we have looked up recently.
397 */
398 
399 #define MCI		struct mailer_con_info
400 
401 MCI
402 {
403 	u_long		mci_flags;	/* flag bits, see below */
404 	short		mci_errno;	/* error number on last connection */
405 	short		mci_herrno;	/* h_errno from last DNS lookup */
406 	short		mci_exitstat;	/* exit status from last connection */
407 	short		mci_state;	/* SMTP state */
408 	int		mci_deliveries;	/* delivery attempts for connection */
409 	long		mci_maxsize;	/* max size this server will accept */
410 #if SFIO
411 	Sfio_t		*mci_in;	/* input side of connection */
412 	Sfio_t		*mci_out;	/* output side of connection */
413 #else /* SFIO */
414 	FILE		*mci_in;	/* input side of connection */
415 	FILE		*mci_out;	/* output side of connection */
416 #endif /* SFIO */
417 	pid_t		mci_pid;	/* process id of subordinate proc */
418 	char		*mci_phase;	/* SMTP phase string */
419 	struct mailer	*mci_mailer;	/* ptr to the mailer for this conn */
420 	char		*mci_host;	/* host name */
421 	char		*mci_status;	/* DSN status to be copied to addrs */
422 	char		*mci_rstatus;	/* SMTP status to be copied to addrs */
423 	time_t		mci_lastuse;	/* last usage time */
424 	FILE		*mci_statfile;	/* long term status file */
425 	char		*mci_heloname;	/* name to use as HELO arg */
426 #if SASL
427 	bool		mci_sasl_auth;	/* authenticated? */
428 	int		mci_sasl_string_len;
429 	char		*mci_sasl_string;	/* sasl reply string */
430 	char		*mci_saslcap;	/* SASL list of mechanisms */
431 	sasl_conn_t	*mci_conn;	/* SASL connection */
432 #endif /* SASL */
433 #if STARTTLS
434 	SSL		*mci_ssl;	/* SSL connection */
435 #endif /* STARTTLS */
436 };
437 
438 
439 /* flag bits */
440 #define MCIF_VALID	0x00000001	/* this entry is valid */
441 #define MCIF_TEMP	0x00000002	/* don't cache this connection */
442 #define MCIF_CACHED	0x00000004	/* currently in open cache */
443 #define MCIF_ESMTP	0x00000008	/* this host speaks ESMTP */
444 #define MCIF_EXPN	0x00000010	/* EXPN command supported */
445 #define MCIF_SIZE	0x00000020	/* SIZE option supported */
446 #define MCIF_8BITMIME	0x00000040	/* BODY=8BITMIME supported */
447 #define MCIF_7BIT	0x00000080	/* strip this message to 7 bits */
448 #define MCIF_MULTSTAT	0x00000100	/* MAIL11V3: handles MULT status */
449 #define MCIF_INHEADER	0x00000200	/* currently outputing header */
450 #define MCIF_CVT8TO7	0x00000400	/* convert from 8 to 7 bits */
451 #define MCIF_DSN	0x00000800	/* DSN extension supported */
452 #define MCIF_8BITOK	0x00001000	/* OK to send 8 bit characters */
453 #define MCIF_CVT7TO8	0x00002000	/* convert from 7 to 8 bits */
454 #define MCIF_INMIME	0x00004000	/* currently reading MIME header */
455 #define MCIF_AUTH	0x00008000	/* AUTH= supported */
456 #define MCIF_AUTHACT	0x00010000	/* SASL (AUTH) active */
457 #define MCIF_ENHSTAT	0x00020000	/* ENHANCEDSTATUSCODES supported */
458 #if STARTTLS
459 #define MCIF_TLS	0x00100000	/* STARTTLS supported */
460 #define MCIF_TLSACT	0x00200000	/* STARTTLS active */
461 #define MCIF_EXTENS	(MCIF_EXPN | MCIF_SIZE | MCIF_8BITMIME | MCIF_DSN | MCIF_8BITOK | MCIF_AUTH | MCIF_ENHSTAT | MCIF_TLS)
462 #else /* STARTTLS */
463 #define MCIF_EXTENS	(MCIF_EXPN | MCIF_SIZE | MCIF_8BITMIME | MCIF_DSN | MCIF_8BITOK | MCIF_AUTH | MCIF_ENHSTAT)
464 #endif /* STARTTLS */
465 #define MCIF_ONLY_EHLO	0x10000000	/* use only EHLO in smtpinit */
466 
467 
468 /* states */
469 #define MCIS_CLOSED	0		/* no traffic on this connection */
470 #define MCIS_OPENING	1		/* sending initial protocol */
471 #define MCIS_OPEN	2		/* open, initial protocol sent */
472 #define MCIS_ACTIVE	3		/* message being sent */
473 #define MCIS_QUITING	4		/* running quit protocol */
474 #define MCIS_SSD	5		/* service shutting down */
475 #define MCIS_ERROR	6		/* I/O error on connection */
476 
477 /* functions */
478 extern void	mci_cache __P((MCI *));
479 extern void	mci_dump __P((MCI *, bool));
480 extern void	mci_dump_all __P((bool));
481 extern void	mci_flush __P((bool, MCI *));
482 extern MCI	*mci_get __P((char *, MAILER *));
483 extern int	mci_lock_host __P((MCI *));
484 extern bool	mci_match __P((char *, MAILER *));
485 extern int	mci_print_persistent __P((char *, char *));
486 extern int	mci_purge_persistent __P((char *, char *));
487 extern MCI	**mci_scan __P((MCI *));
488 extern void	mci_setstat __P((MCI *, int, char *, char *));
489 extern void	mci_store_persistent __P((MCI *));
490 extern int	mci_traverse_persistent __P((int (*)(), char *));
491 extern void	mci_unlock_host __P((MCI *));
492 
493 /*
494 **  Header structure.
495 **	This structure is used internally to store header items.
496 */
497 
498 struct header
499 {
500 	char		*h_field;	/* the name of the field */
501 	char		*h_value;	/* the value of that field */
502 	struct header	*h_link;	/* the next header */
503 	u_char		h_macro;	/* include header if macro defined */
504 	u_long		h_flags;	/* status bits, see below */
505 	BITMAP256	h_mflags;	/* m_flags bits needed */
506 };
507 
508 typedef struct header	HDR;
509 
510 /*
511 **  Header information structure.
512 **	Defined in conf.c, this struct declares the header fields
513 **	that have some magic meaning.
514 */
515 
516 struct hdrinfo
517 {
518 	char	*hi_field;	/* the name of the field */
519 	u_long	hi_flags;	/* status bits, see below */
520 	char	*hi_ruleset;	/* validity check ruleset */
521 };
522 
523 extern struct hdrinfo	HdrInfo[];
524 
525 /* bits for h_flags and hi_flags */
526 #define H_EOH		0x00000001	/* field terminates header */
527 #define H_RCPT		0x00000002	/* contains recipient addresses */
528 #define H_DEFAULT	0x00000004	/* if another value is found, drop this */
529 #define H_RESENT	0x00000008	/* this address is a "Resent-..." address */
530 #define H_CHECK		0x00000010	/* check h_mflags against m_flags */
531 #define H_ACHECK	0x00000020	/* ditto, but always (not just default) */
532 #define H_FORCE		0x00000040	/* force this field, even if default */
533 #define H_TRACE		0x00000080	/* this field contains trace information */
534 #define H_FROM		0x00000100	/* this is a from-type field */
535 #define H_VALID		0x00000200	/* this field has a validated value */
536 #define H_RECEIPTTO	0x00000400	/* field has return receipt info */
537 #define H_ERRORSTO	0x00000800	/* field has error address info */
538 #define H_CTE		0x00001000	/* field is a content-transfer-encoding */
539 #define H_CTYPE		0x00002000	/* this is a content-type field */
540 #define H_BCC		0x00004000	/* Bcc: header: strip value or delete */
541 #define H_ENCODABLE	0x00008000	/* field can be RFC 1522 encoded */
542 #define H_STRIPCOMM	0x00010000	/* header check: strip comments */
543 #define H_BINDLATE	0x00020000	/* only expand macros at deliver */
544 #define H_USER		0x00040000	/* header came from the user/SMTP */
545 
546 /* bits for chompheader() */
547 #define CHHDR_DEF	0x0001	/* default header */
548 #define CHHDR_CHECK	0x0002	/* call ruleset for header */
549 #define CHHDR_USER	0x0004	/* header from user */
550 #define CHHDR_QUEUE	0x0008	/* header from qf file */
551 
552 /* functions */
553 extern void	addheader __P((char *, char *, int, HDR **));
554 extern u_long	chompheader __P((char *, int, HDR **, ENVELOPE *));
555 extern void	commaize __P((HDR *, char *, bool, MCI *, ENVELOPE *));
556 extern HDR	*copyheader __P((HDR *));
557 extern void	eatheader __P((ENVELOPE *, bool));
558 extern char	*hvalue __P((char *, HDR *));
559 extern bool	isheader __P((char *));
560 extern void	putfromline __P((MCI *, ENVELOPE *));
561 extern void	setupheaders __P((void));
562 
563 /*
564 **  Performance monitoring
565 */
566 
567 #define TIMERS		struct sm_timers
568 
569 TIMERS
570 {
571 	TIMER	ti_overall;	/* the whole process */
572 };
573 
574 
575 #define PUSHTIMER(l, t)	{ if (tTd(98, l)) pushtimer(&t); }
576 #define POPTIMER(l, t)	{ if (tTd(98, l)) poptimer(&t); }
577 
578 /*
579 **  Envelope structure.
580 **	This structure defines the message itself.  There is usually
581 **	only one of these -- for the message that we originally read
582 **	and which is our primary interest -- but other envelopes can
583 **	be generated during processing.  For example, error messages
584 **	will have their own envelope.
585 */
586 
587 struct envelope
588 {
589 	HDR		*e_header;	/* head of header list */
590 	long		e_msgpriority;	/* adjusted priority of this message */
591 	time_t		e_ctime;	/* time message appeared in the queue */
592 	char		*e_to;		/* the target person */
593 	ADDRESS		e_from;		/* the person it is from */
594 	char		*e_sender;	/* e_from.q_paddr w comments stripped */
595 	char		**e_fromdomain;	/* the domain part of the sender */
596 	ADDRESS		*e_sendqueue;	/* list of message recipients */
597 	ADDRESS		*e_errorqueue;	/* the queue for error responses */
598 
599 	/*
600 	**  Overflow detection is based on < 0, so don't change this
601 	**  to unsigned.  We don't use unsigned and == ULONG_MAX because
602 	**  some libc's don't have strtoul(), see mail_esmtp_args().
603 	*/
604 	long		e_msgsize;	/* size of the message in bytes */
605 	long		e_flags;	/* flags, see below */
606 	int		e_nrcpts;	/* number of recipients */
607 	short		e_class;	/* msg class (priority, junk, etc.) */
608 	short		e_hopcount;	/* number of times processed */
609 	short		e_nsent;	/* number of sends since checkpoint */
610 	short		e_sendmode;	/* message send mode */
611 	short		e_errormode;	/* error return mode */
612 	short		e_timeoutclass;	/* message timeout class */
613 	void		(*e_puthdr)__P((MCI *, HDR *, ENVELOPE *, int));
614 					/* function to put header of message */
615 	void		(*e_putbody)__P((MCI *, ENVELOPE *, char *));
616 					/* function to put body of message */
617 	ENVELOPE	*e_parent;	/* the message this one encloses */
618 	ENVELOPE	*e_sibling;	/* the next envelope of interest */
619 	char		*e_bodytype;	/* type of message body */
620 	FILE		*e_dfp;		/* data file */
621 	char		*e_id;		/* code for this entry in queue */
622 	int		e_queuedir;	/* index into queue directories */
623 	FILE		*e_xfp;		/* transcript file */
624 	FILE		*e_lockfp;	/* the lock file for this message */
625 	char		*e_message;	/* error message */
626 	char		*e_statmsg;	/* stat msg (changes per delivery) */
627 	char		*e_msgboundary;	/* MIME-style message part boundary */
628 	char		*e_origrcpt;	/* original recipient (one only) */
629 	char		*e_envid;	/* envelope id from MAIL FROM: line */
630 	char		*e_status;	/* DSN status for this message */
631 	time_t		e_dtime;	/* time of last delivery attempt */
632 	int		e_ntries;	/* number of delivery attempts */
633 	dev_t		e_dfdev;	/* df file's device, for crash recov */
634 	ino_t		e_dfino;	/* df file's ino, for crash recovery */
635 	char		*e_macro[MAXMACROID + 1]; /* macro definitions */
636 	char		*e_if_macros[2]; /* HACK: incoming interface info */
637 	char		*e_auth_param;
638 	TIMERS		e_timers;	/* per job timers */
639 #if _FFR_QUEUEDELAY
640 	int		e_queuealg;	/* algorithm for queue delay */
641 	time_t		e_queuedelay;	/* current delay */
642 #endif /* _FFR_QUEUEDELAY */
643 };
644 
645 /* values for e_flags */
646 #define EF_OLDSTYLE	0x0000001L	/* use spaces (not commas) in hdrs */
647 #define EF_INQUEUE	0x0000002L	/* this message is fully queued */
648 #define EF_NO_BODY_RETN	0x0000004L	/* omit message body on error */
649 #define EF_CLRQUEUE	0x0000008L	/* disk copy is no longer needed */
650 #define EF_SENDRECEIPT	0x0000010L	/* send a return receipt */
651 #define EF_FATALERRS	0x0000020L	/* fatal errors occurred */
652 #define EF_DELETE_BCC	0x0000040L	/* delete Bcc: headers entirely */
653 #define EF_RESPONSE	0x0000080L	/* this is an error or return receipt */
654 #define EF_RESENT	0x0000100L	/* this message is being forwarded */
655 #define EF_VRFYONLY	0x0000200L	/* verify only (don't expand aliases) */
656 #define EF_WARNING	0x0000400L	/* warning message has been sent */
657 #define EF_QUEUERUN	0x0000800L	/* this envelope is from queue */
658 #define EF_GLOBALERRS	0x0001000L	/* treat errors as global */
659 #define EF_PM_NOTIFY	0x0002000L	/* send return mail to postmaster */
660 #define EF_METOO	0x0004000L	/* send to me too */
661 #define EF_LOGSENDER	0x0008000L	/* need to log the sender */
662 #define EF_NORECEIPT	0x0010000L	/* suppress all return-receipts */
663 #define EF_HAS8BIT	0x0020000L	/* at least one 8-bit char in body */
664 #define EF_NL_NOT_EOL	0x0040000L	/* don't accept raw NL as EOLine */
665 #define EF_CRLF_NOT_EOL	0x0080000L	/* don't accept CR-LF as EOLine */
666 #define EF_RET_PARAM	0x0100000L	/* RCPT command had RET argument */
667 #define EF_HAS_DF	0x0200000L	/* set when df file is instantiated */
668 #define EF_IS_MIME	0x0400000L	/* really is a MIME message */
669 #define EF_DONT_MIME	0x0800000L	/* never MIME this message */
670 #define EF_DISCARD	0x1000000L	/* discard the message */
671 #define EF_TOOBIG	0x2000000L	/* message is too big */
672 
673 /* values for e_if_macros */
674 #define EIF_ADDR	0		/* ${if_addr} */
675 
676 /* functions */
677 extern void	clearenvelope __P((ENVELOPE *, bool));
678 extern void	dropenvelope __P((ENVELOPE *, bool));
679 extern ENVELOPE	*newenvelope __P((ENVELOPE *, ENVELOPE *));
680 extern void	printenvflags __P((ENVELOPE *));
681 extern void	putbody __P((MCI *, ENVELOPE *, char *));
682 extern void	putheader __P((MCI *, HDR *, ENVELOPE *, int));
683 
684 /*
685 **  Message priority classes.
686 **
687 **	The message class is read directly from the Priority: header
688 **	field in the message.
689 **
690 **	CurEnv->e_msgpriority is the number of bytes in the message plus
691 **	the creation time (so that jobs ``tend'' to be ordered correctly),
692 **	adjusted by the message class, the number of recipients, and the
693 **	amount of time the message has been sitting around.  This number
694 **	is used to order the queue.  Higher values mean LOWER priority.
695 **
696 **	Each priority class point is worth WkClassFact priority points;
697 **	each recipient is worth WkRecipFact priority points.  Each time
698 **	we reprocess a message the priority is adjusted by WkTimeFact.
699 **	WkTimeFact should normally decrease the priority so that jobs
700 **	that have historically failed will be run later; thanks go to
701 **	Jay Lepreau at Utah for pointing out the error in my thinking.
702 **
703 **	The "class" is this number, unadjusted by the age or size of
704 **	this message.  Classes with negative representations will have
705 **	error messages thrown away if they are not local.
706 */
707 
708 struct priority
709 {
710 	char	*pri_name;	/* external name of priority */
711 	int	pri_val;	/* internal value for same */
712 };
713 
714 /*
715 **  Rewrite rules.
716 */
717 
718 struct rewrite
719 {
720 	char	**r_lhs;	/* pattern match */
721 	char	**r_rhs;	/* substitution value */
722 	struct rewrite	*r_next;/* next in chain */
723 	int	r_line;		/* rule line in sendmail.cf */
724 };
725 
726 /*
727 **  Special characters in rewriting rules.
728 **	These are used internally only.
729 **	The COND* rules are actually used in macros rather than in
730 **		rewriting rules, but are given here because they
731 **		cannot conflict.
732 */
733 
734 /* left hand side items */
735 #define MATCHZANY	((u_char)0220)	/* match zero or more tokens */
736 #define MATCHANY	((u_char)0221)	/* match one or more tokens */
737 #define MATCHONE	((u_char)0222)	/* match exactly one token */
738 #define MATCHCLASS	((u_char)0223)	/* match one token in a class */
739 #define MATCHNCLASS	((u_char)0224)	/* match anything not in class */
740 #define MATCHREPL	((u_char)0225)	/* replacement on RHS for above */
741 
742 /* right hand side items */
743 #define CANONNET	((u_char)0226)	/* canonical net, next token */
744 #define CANONHOST	((u_char)0227)	/* canonical host, next token */
745 #define CANONUSER	((u_char)0230)	/* canonical user, next N tokens */
746 #define CALLSUBR	((u_char)0231)	/* call another rewriting set */
747 
748 /* conditionals in macros */
749 #define CONDIF		((u_char)0232)	/* conditional if-then */
750 #define CONDELSE	((u_char)0233)	/* conditional else */
751 #define CONDFI		((u_char)0234)	/* conditional fi */
752 
753 /* bracket characters for host name lookup */
754 #define HOSTBEGIN	((u_char)0235)	/* hostname lookup begin */
755 #define HOSTEND	((u_char)0236)	/* hostname lookup end */
756 
757 /* bracket characters for generalized lookup */
758 #define LOOKUPBEGIN	((u_char)0205)	/* generalized lookup begin */
759 #define LOOKUPEND	((u_char)0206)	/* generalized lookup end */
760 
761 /* macro substitution character */
762 #define MACROEXPAND	((u_char)0201)	/* macro expansion */
763 #define MACRODEXPAND	((u_char)0202)	/* deferred macro expansion */
764 
765 /* to make the code clearer */
766 #define MATCHZERO	CANONHOST
767 
768 #define MAXMATCH	9	/* max params per rewrite */
769 
770 /* external <==> internal mapping table */
771 struct metamac
772 {
773 	char	metaname;	/* external code (after $) */
774 	u_char	metaval;	/* internal code (as above) */
775 };
776 
777 /* values for macros with external names only */
778 #define MID_OPMODE	0202	/* operation mode */
779 
780 /* functions */
781 extern void	define __P((int, char *, ENVELOPE *));
782 extern void	expand __P((char *, char *, size_t, ENVELOPE *));
783 extern int	macid __P((char *, char **));
784 extern char	*macname __P((int));
785 extern char	*macvalue __P((int, ENVELOPE *));
786 extern int	rscheck __P((char *, char *, char *, ENVELOPE *, bool, bool, int, char *));
787 extern void	setclass __P((int, char *));
788 extern int	strtorwset __P((char *, char **, int));
789 extern void	translate_dollars __P((char *));
790 extern bool	wordinclass __P((char *, int));
791 
792 /*
793 **  Name canonification short circuit.
794 **
795 **	If the name server for a host is down, the process of trying to
796 **	canonify the name can hang.  This is similar to (but alas, not
797 **	identical to) looking up the name for delivery.  This stab type
798 **	caches the result of the name server lookup so we don't hang
799 **	multiple times.
800 */
801 
802 #define NAMECANON	struct _namecanon
803 
804 NAMECANON
805 {
806 	short		nc_errno;	/* cached errno */
807 	short		nc_herrno;	/* cached h_errno */
808 	short		nc_stat;	/* cached exit status code */
809 	short		nc_flags;	/* flag bits */
810 	char		*nc_cname;	/* the canonical name */
811 };
812 
813 /* values for nc_flags */
814 #define NCF_VALID	0x0001	/* entry valid */
815 
816 /* functions */
817 extern bool	getcanonname __P((char *, int, bool));
818 extern int	getmxrr __P((char *, char **, u_short *, bool, int *));
819 
820 /*
821 **  Mapping functions
822 **
823 **	These allow arbitrary mappings in the config file.  The idea
824 **	(albeit not the implementation) comes from IDA sendmail.
825 */
826 
827 #define MAPCLASS	struct _mapclass
828 #define MAP		struct _map
829 #define MAXMAPACTIONS	5		/* size of map_actions array */
830 
831 
832 /*
833 **  An actual map.
834 */
835 
836 MAP
837 {
838 	MAPCLASS	*map_class;	/* the class of this map */
839 	char		*map_mname;	/* name of this map */
840 	long		map_mflags;	/* flags, see below */
841 	char		*map_file;	/* the (nominal) filename */
842 	ARBPTR_T	map_db1;	/* the open database ptr */
843 	ARBPTR_T	map_db2;	/* an "extra" database pointer */
844 	char		*map_keycolnm;	/* key column name */
845 	char		*map_valcolnm;	/* value column name */
846 	u_char		map_keycolno;	/* key column number */
847 	u_char		map_valcolno;	/* value column number */
848 	char		map_coldelim;	/* column delimiter */
849 	char		map_spacesub;	/* spacesub */
850 	char		*map_app;	/* to append to successful matches */
851 	char		*map_tapp;	/* to append to "tempfail" matches */
852 	char		*map_domain;	/* the (nominal) NIS domain */
853 	char		*map_rebuild;	/* program to run to do auto-rebuild */
854 	time_t		map_mtime;	/* last database modification time */
855 	pid_t		map_pid;	/* PID of process which opened map */
856 	int		map_lockfd;	/* auxiliary lock file descriptor */
857 	short		map_specificity;	/* specificity of aliases */
858 	MAP		*map_stack[MAXMAPSTACK];   /* list for stacked maps */
859 	short		map_return[MAXMAPACTIONS]; /* return bitmaps for stacked maps */
860 };
861 
862 
863 /* bit values for map_mflags */
864 #define MF_VALID	0x00000001	/* this entry is valid */
865 #define MF_INCLNULL	0x00000002	/* include null byte in key */
866 #define MF_OPTIONAL	0x00000004	/* don't complain if map not found */
867 #define MF_NOFOLDCASE	0x00000008	/* don't fold case in keys */
868 #define MF_MATCHONLY	0x00000010	/* don't use the map value */
869 #define MF_OPEN		0x00000020	/* this entry is open */
870 #define MF_WRITABLE	0x00000040	/* open for writing */
871 #define MF_ALIAS	0x00000080	/* this is an alias file */
872 #define MF_TRY0NULL	0x00000100	/* try with no null byte */
873 #define MF_TRY1NULL	0x00000200	/* try with the null byte */
874 #define MF_LOCKED	0x00000400	/* this map is currently locked */
875 #define MF_ALIASWAIT	0x00000800	/* alias map in aliaswait state */
876 #define MF_IMPL_HASH	0x00001000	/* implicit: underlying hash database */
877 #define MF_IMPL_NDBM	0x00002000	/* implicit: underlying NDBM database */
878 #define MF_UNSAFEDB	0x00004000	/* this map is world writable */
879 #define MF_APPEND	0x00008000	/* append new entry on rebuild */
880 #define MF_KEEPQUOTES	0x00010000	/* don't dequote key before lookup */
881 #define MF_NODEFER	0x00020000	/* don't defer if map lookup fails */
882 #define MF_REGEX_NOT	0x00040000	/* regular expression negation */
883 #define MF_DEFER	0x00080000	/* don't lookup map in defer mode */
884 #define MF_SINGLEMATCH	0x00100000	/* successful only if match one key */
885 #define MF_NOREWRITE	0x00200000	/* don't rewrite result, return as-is */
886 #define MF_CLOSING	0x00400000	/* map is being closed */
887 
888 #define DYNOPENMAP(map) if (!bitset(MF_OPEN, (map)->map_mflags)) \
889 	{	\
890 		if (!openmap(map))	\
891 			return NULL;	\
892 	}
893 
894 
895 /* indices for map_actions */
896 #define MA_NOTFOUND	0		/* member map returned "not found" */
897 #define MA_UNAVAIL	1		/* member map is not available */
898 #define MA_TRYAGAIN	2		/* member map returns temp failure */
899 
900 /*
901 **  The class of a map -- essentially the functions to call
902 */
903 
904 MAPCLASS
905 {
906 	char	*map_cname;		/* name of this map class */
907 	char	*map_ext;		/* extension for database file */
908 	short	map_cflags;		/* flag bits, see below */
909 	bool	(*map_parse)__P((MAP *, char *));
910 					/* argument parsing function */
911 	char	*(*map_lookup)__P((MAP *, char *, char **, int *));
912 					/* lookup function */
913 	void	(*map_store)__P((MAP *, char *, char *));
914 					/* store function */
915 	bool	(*map_open)__P((MAP *, int));
916 					/* open function */
917 	void	(*map_close)__P((MAP *));
918 					/* close function */
919 };
920 
921 /* bit values for map_cflags */
922 #define MCF_ALIASOK	0x0001		/* can be used for aliases */
923 #define MCF_ALIASONLY	0x0002		/* usable only for aliases */
924 #define MCF_REBUILDABLE	0x0004		/* can rebuild alias files */
925 #define MCF_OPTFILE	0x0008		/* file name is optional */
926 
927 /* functions */
928 extern void	closemaps __P((void));
929 extern bool	impl_map_open __P((MAP *, int));
930 extern void	initmaps __P((void));
931 extern MAP	*makemapentry __P((char *));
932 extern void	maplocaluser __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
933 extern char	*map_rewrite __P((MAP *, const char *, size_t, char **));
934 #if NETINFO
935 extern char	*ni_propval __P((char *, char *, char *, char *, int));
936 #endif /* NETINFO */
937 extern bool	openmap __P((MAP *));
938 #if USERDB
939 extern void	_udbx_close __P((void));
940 extern int	udbexpand __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
941 extern char	*udbsender __P((char *));
942 #endif /* USERDB */
943 /*
944 **  LDAP related items
945 */
946 #ifdef LDAPMAP
947 struct ldapmap_struct
948 {
949 	/* needed for ldap_open or ldap_init */
950 	char		*ldap_host;
951 	int		ldap_port;
952 
953 	/* options set in ld struct before ldap_bind_s */
954 	int		ldap_deref;
955 	time_t		ldap_timelimit;
956 	int		ldap_sizelimit;
957 	int		ldap_options;
958 
959 	/* args for ldap_bind_s */
960 	LDAP		*ldap_ld;
961 	char		*ldap_binddn;
962 	char		*ldap_secret;
963 	int		ldap_method;
964 
965 	/* args for ldap_search */
966 	char		*ldap_base;
967 	int		ldap_scope;
968 	char		*ldap_filter;
969 	char		*ldap_attr[LDAPMAP_MAX_ATTR + 1];
970 	bool		ldap_attrsonly;
971 
972 	/* args for ldap_result */
973 	struct timeval	ldap_timeout;
974 	LDAPMessage	*ldap_res;
975 
976 	/* Linked list of maps sharing the same LDAP binding */
977 	MAP		*ldap_next;
978 };
979 
980 typedef struct ldapmap_struct	LDAPMAP_STRUCT;
981 
982 /* struct defining LDAP Auth Methods */
983 struct lamvalues
984 {
985 	char	*lam_name;	/* name of LDAP auth method */
986 	int	lam_code;	/* numeric code */
987 };
988 
989 /* struct defining LDAP Alias Dereferencing */
990 struct ladvalues
991 {
992 	char	*lad_name;	/* name of LDAP alias dereferencing method */
993 	int	lad_code;	/* numeric code */
994 };
995 
996 /* struct defining LDAP Search Scope */
997 struct lssvalues
998 {
999 	char	*lss_name;	/* name of LDAP search scope */
1000 	int	lss_code;	/* numeric code */
1001 };
1002 
1003 /* functions */
1004 extern bool	ldapmap_parseargs __P((MAP *, char *));
1005 extern void	ldapmap_set_defaults __P((char *));
1006 #endif /* LDAPMAP */
1007 
1008 /*
1009 **  PH related items
1010 */
1011 
1012 #ifdef PH_MAP
1013 struct ph_map_struct
1014 {
1015 	char	*ph_servers;	/* list of ph servers */
1016 	char	*ph_field_list;	/* list of fields to search for match */
1017 	FILE	*ph_to_server;
1018 	FILE	*ph_from_server;
1019 	int	ph_sockfd;
1020 	time_t	ph_timeout;
1021 };
1022 typedef struct ph_map_struct	PH_MAP_STRUCT;
1023 
1024 # define DEFAULT_PH_MAP_FIELDS		"alias callsign name spacedname"
1025 #endif /* PH_MAP */
1026 /*
1027 **  Process List (proclist)
1028 */
1029 
1030 struct procs
1031 {
1032 	pid_t	proc_pid;
1033 	char	*proc_task;
1034 	int	proc_type;
1035 };
1036 
1037 #define NO_PID		((pid_t) 0)
1038 #ifndef PROC_LIST_SEG
1039 # define PROC_LIST_SEG	32		/* number of pids to alloc at a time */
1040 #endif /* ! PROC_LIST_SEG */
1041 
1042 /* process types */
1043 #define PROC_NONE		0
1044 #define PROC_DAEMON		1
1045 #define PROC_DAEMON_CHILD	2
1046 #define PROC_QUEUE		3
1047 #define PROC_QUEUE_CHILD	3
1048 #define PROC_CONTROL		4
1049 #define PROC_CONTROL_CHILD	5
1050 
1051 /* functions */
1052 extern void	proc_list_add __P((pid_t, char *, int));
1053 extern void	proc_list_clear __P((void));
1054 extern void	proc_list_display __P((FILE *));
1055 extern int	proc_list_drop __P((pid_t));
1056 extern void	proc_list_probe __P((void));
1057 extern void	proc_list_set __P((pid_t, char *));
1058 
1059 /*
1060 **  Symbol table definitions
1061 */
1062 
1063 struct symtab
1064 {
1065 	char		*s_name;	/* name to be entered */
1066 	short		s_type;		/* general type (see below) */
1067 	short		s_len;		/* length of this entry */
1068 	struct symtab	*s_next;	/* pointer to next in chain */
1069 	union
1070 	{
1071 		BITMAP256	sv_class;	/* bit-map of word classes */
1072 		ADDRESS		*sv_addr;	/* pointer to address header */
1073 		MAILER		*sv_mailer;	/* pointer to mailer */
1074 		char		*sv_alias;	/* alias */
1075 		MAPCLASS	sv_mapclass;	/* mapping function class */
1076 		MAP		sv_map;		/* mapping function */
1077 		char		*sv_hostsig;	/* host signature */
1078 		MCI		sv_mci;		/* mailer connection info */
1079 		NAMECANON	sv_namecanon;	/* canonical name cache */
1080 		int		sv_macro;	/* macro name => id mapping */
1081 		int		sv_ruleset;	/* ruleset index */
1082 		struct hdrinfo	sv_header;	/* header metainfo */
1083 		char		*sv_service[MAXMAPSTACK]; /* service switch */
1084 #ifdef LDAPMAP
1085 		MAP		*sv_lmap;	/* Maps for LDAP connection */
1086 #endif /* LDAPMAP */
1087 #if _FFR_MILTER
1088 		struct milter	*sv_milter;	/* milter filter name */
1089 #endif /* _FFR_MILTER */
1090 	}	s_value;
1091 };
1092 
1093 typedef struct symtab	STAB;
1094 
1095 /* symbol types */
1096 #define ST_UNDEF	0	/* undefined type */
1097 #define ST_CLASS	1	/* class map */
1098 #define ST_ADDRESS	2	/* an address in parsed format */
1099 #define ST_MAILER	3	/* a mailer header */
1100 #define ST_ALIAS	4	/* an alias */
1101 #define ST_MAPCLASS	5	/* mapping function class */
1102 #define ST_MAP		6	/* mapping function */
1103 #define ST_HOSTSIG	7	/* host signature */
1104 #define ST_NAMECANON	8	/* cached canonical name */
1105 #define ST_MACRO	9	/* macro name to id mapping */
1106 #define ST_RULESET	10	/* ruleset index */
1107 #define ST_SERVICE	11	/* service switch entry */
1108 #define ST_HEADER	12	/* special header flags */
1109 #ifdef LDAPMAP
1110 # define ST_LMAP	13	/* List head of maps for LDAP connection */
1111 #endif /* LDAPMAP */
1112 #if _FFR_MILTER
1113 # define ST_MILTER	14	/* milter filter */
1114 #endif /* _FFR_MILTER */
1115 #define ST_MCI		16	/* mailer connection info (offset) */
1116 
1117 #define s_class		s_value.sv_class
1118 #define s_address	s_value.sv_addr
1119 #define s_mailer	s_value.sv_mailer
1120 #define s_alias		s_value.sv_alias
1121 #define s_mci		s_value.sv_mci
1122 #define s_mapclass	s_value.sv_mapclass
1123 #define s_hostsig	s_value.sv_hostsig
1124 #define s_map		s_value.sv_map
1125 #define s_namecanon	s_value.sv_namecanon
1126 #define s_macro		s_value.sv_macro
1127 #define s_ruleset	s_value.sv_ruleset
1128 #define s_service	s_value.sv_service
1129 #define s_header	s_value.sv_header
1130 #ifdef LDAPMAP
1131 # define s_lmap		s_value.sv_lmap
1132 #endif /* LDAPMAP */
1133 #if _FFR_MILTER
1134 # define s_milter	s_value.sv_milter
1135 #endif /* _FFR_MILTER */
1136 
1137 /* opcodes to stab */
1138 #define ST_FIND		0	/* find entry */
1139 #define ST_ENTER	1	/* enter if not there */
1140 
1141 /* functions */
1142 extern STAB	*stab __P((char *, int, int));
1143 extern void	stabapply __P((void (*)(STAB *, int), int));
1144 
1145 /*
1146 **  STRUCT EVENT -- event queue.
1147 **
1148 **	Maintained in sorted order.
1149 **
1150 **	We store the pid of the process that set this event to insure
1151 **	that when we fork we will not take events intended for the parent.
1152 */
1153 
1154 struct event
1155 {
1156 	time_t		ev_time;	/* time of the function call */
1157 	void		(*ev_func)__P((int));
1158 					/* function to call */
1159 	int		ev_arg;		/* argument to ev_func */
1160 	pid_t		ev_pid;		/* pid that set this event */
1161 	struct event	*ev_link;	/* link to next item */
1162 };
1163 
1164 typedef struct event	EVENT;
1165 
1166 /* functions */
1167 extern void	clrevent __P((EVENT *));
1168 extern void	clear_events __P((void));
1169 extern EVENT	*setevent __P((time_t, void(*)(), int));
1170 extern EVENT	*sigsafe_setevent __P((time_t, void(*)(), int));
1171 
1172 /*
1173 **  Operation, send, error, and MIME modes
1174 **
1175 **	The operation mode describes the basic operation of sendmail.
1176 **	This can be set from the command line, and is "send mail" by
1177 **	default.
1178 **
1179 **	The send mode tells how to send mail.  It can be set in the
1180 **	configuration file.  It's setting determines how quickly the
1181 **	mail will be delivered versus the load on your system.  If the
1182 **	-v (verbose) flag is given, it will be forced to SM_DELIVER
1183 **	mode.
1184 **
1185 **	The error mode tells how to return errors.
1186 */
1187 
1188 #define MD_DELIVER	'm'		/* be a mail sender */
1189 #define MD_SMTP		's'		/* run SMTP on standard input */
1190 #define MD_ARPAFTP	'a'		/* obsolete ARPANET mode (Grey Book) */
1191 #define MD_DAEMON	'd'		/* run as a daemon */
1192 #define MD_FGDAEMON	'D'		/* run daemon in foreground */
1193 #define MD_VERIFY	'v'		/* verify: don't collect or deliver */
1194 #define MD_TEST		't'		/* test mode: resolve addrs only */
1195 #define MD_INITALIAS	'i'		/* initialize alias database */
1196 #define MD_PRINT	'p'		/* print the queue */
1197 #define MD_FREEZE	'z'		/* freeze the configuration file */
1198 #define MD_HOSTSTAT	'h'		/* print persistent host stat info */
1199 #define MD_PURGESTAT	'H'		/* purge persistent host stat info */
1200 #define MD_QUEUERUN	'q'		/* queue run */
1201 
1202 /* values for e_sendmode -- send modes */
1203 #define SM_DELIVER	'i'		/* interactive delivery */
1204 #define SM_FORK		'b'		/* deliver in background */
1205 #define SM_QUEUE	'q'		/* queue, don't deliver */
1206 #define SM_DEFER	'd'		/* defer map lookups as well as queue */
1207 #define SM_VERIFY	'v'		/* verify only (used internally) */
1208 
1209 
1210 /* used only as a parameter to sendall */
1211 #define SM_DEFAULT	'\0'		/* unspecified, use SendMode */
1212 
1213 /* functions */
1214 extern void	set_delivery_mode __P((int, ENVELOPE *));
1215 
1216 /* values for e_errormode -- error handling modes */
1217 #define EM_PRINT	'p'		/* print errors */
1218 #define EM_MAIL		'm'		/* mail back errors */
1219 #define EM_WRITE	'w'		/* write back errors */
1220 #define EM_BERKNET	'e'		/* special berknet processing */
1221 #define EM_QUIET	'q'		/* don't print messages (stat only) */
1222 
1223 
1224 /* bit values for MimeMode */
1225 #define MM_CVTMIME	0x0001		/* convert 8 to 7 bit MIME */
1226 #define MM_PASS8BIT	0x0002		/* just send 8 bit data blind */
1227 #define MM_MIME8BIT	0x0004		/* convert 8-bit data to MIME */
1228 
1229 
1230 /* how to handle messages without any recipient addresses */
1231 #define NRA_NO_ACTION		0	/* just leave it as is */
1232 #define NRA_ADD_TO		1	/* add To: header */
1233 #define NRA_ADD_APPARENTLY_TO	2	/* add Apparently-To: header */
1234 #define NRA_ADD_BCC		3	/* add empty Bcc: header */
1235 #define NRA_ADD_TO_UNDISCLOSED	4	/* add To: undisclosed:; header */
1236 
1237 
1238 /* flags to putxline */
1239 #define PXLF_NOTHINGSPECIAL	0	/* no special mapping */
1240 #define PXLF_MAPFROM		0x0001	/* map From_ to >From_ */
1241 #define PXLF_STRIP8BIT		0x0002	/* strip 8th bit */
1242 #define PXLF_HEADER		0x0004	/* map newlines in headers */
1243 
1244 /*
1245 **  Privacy flags
1246 **	These are bit values for the PrivacyFlags word.
1247 */
1248 
1249 #define PRIV_PUBLIC		0	/* what have I got to hide? */
1250 #define PRIV_NEEDMAILHELO	0x0001	/* insist on HELO for MAIL, at least */
1251 #define PRIV_NEEDEXPNHELO	0x0002	/* insist on HELO for EXPN */
1252 #define PRIV_NEEDVRFYHELO	0x0004	/* insist on HELO for VRFY */
1253 #define PRIV_NOEXPN		0x0008	/* disallow EXPN command entirely */
1254 #define PRIV_NOVRFY		0x0010	/* disallow VRFY command entirely */
1255 #define PRIV_AUTHWARNINGS	0x0020	/* flag possible authorization probs */
1256 #define PRIV_NORECEIPTS		0x0040	/* disallow return receipts */
1257 #define PRIV_NOVERB		0x0100	/* disallow VERB command entirely */
1258 #define PRIV_RESTRICTMAILQ	0x1000	/* restrict mailq command */
1259 #define PRIV_RESTRICTQRUN	0x2000	/* restrict queue run */
1260 #define PRIV_NOETRN		0x4000	/* disallow ETRN command entirely */
1261 #define PRIV_NOBODYRETN		0x8000	/* do not return bodies on bounces */
1262 
1263 /* don't give no info, anyway, anyhow */
1264 #define PRIV_GOAWAY		(0x0fff & ~PRIV_NORECEIPTS)
1265 
1266 /* struct defining such things */
1267 struct prival
1268 {
1269 	char	*pv_name;	/* name of privacy flag */
1270 	u_short	pv_flag;	/* numeric level */
1271 };
1272 
1273 
1274 /*
1275 **  Flags passed to remotename, parseaddr, allocaddr, and buildaddr.
1276 */
1277 
1278 #define RF_SENDERADDR		0x001	/* this is a sender address */
1279 #define RF_HEADERADDR		0x002	/* this is a header address */
1280 #define RF_CANONICAL		0x004	/* strip comment information */
1281 #define RF_ADDDOMAIN		0x008	/* OK to do domain extension */
1282 #define RF_COPYPARSE		0x010	/* copy parsed user & host */
1283 #define RF_COPYPADDR		0x020	/* copy print address */
1284 #define RF_COPYALL		(RF_COPYPARSE|RF_COPYPADDR)
1285 #define RF_COPYNONE		0
1286 
1287 
1288 /*
1289 **  Flags passed to mime8to7 and putheader.
1290 */
1291 
1292 #define M87F_OUTER		0	/* outer context */
1293 #define M87F_NO8BIT		0x0001	/* can't have 8-bit in this section */
1294 #define M87F_DIGEST		0x0002	/* processing multipart/digest */
1295 #define M87F_NO8TO7		0x0004	/* don't do 8->7 bit conversions */
1296 
1297 /* functions */
1298 extern void	mime7to8 __P((MCI *, HDR *, ENVELOPE *));
1299 extern int	mime8to7 __P((MCI *, HDR *, ENVELOPE *, char **, int));
1300 
1301 /*
1302 **  Flags passed to returntosender.
1303 */
1304 
1305 #define RTSF_NO_BODY		0	/* send headers only */
1306 #define RTSF_SEND_BODY		0x0001	/* include body of message in return */
1307 #define RTSF_PM_BOUNCE		0x0002	/* this is a postmaster bounce */
1308 
1309 /* functions */
1310 extern int	returntosender __P((char *, ADDRESS *, int, ENVELOPE *));
1311 
1312 /*
1313 **  Regular UNIX sockaddrs are too small to handle ISO addresses, so
1314 **  we are forced to declare a supertype here.
1315 */
1316 
1317 #if NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25
1318 union bigsockaddr
1319 {
1320 	struct sockaddr		sa;	/* general version */
1321 # if NETUNIX
1322 	struct sockaddr_un	sunix;	/* UNIX family */
1323 # endif /* NETUNIX */
1324 # if NETINET
1325 	struct sockaddr_in	sin;	/* INET family */
1326 # endif /* NETINET */
1327 # if NETINET6
1328 	struct sockaddr_in6	sin6;	/* INET/IPv6 */
1329 # endif /* NETINET6 */
1330 # if NETISO
1331 	struct sockaddr_iso	siso;	/* ISO family */
1332 # endif /* NETISO */
1333 # if NETNS
1334 	struct sockaddr_ns	sns;	/* XNS family */
1335 # endif /* NETNS */
1336 # if NETX25
1337 	struct sockaddr_x25	sx25;	/* X.25 family */
1338 # endif /* NETX25 */
1339 };
1340 
1341 # define SOCKADDR	union bigsockaddr
1342 
1343 /* functions */
1344 extern char	*anynet_ntoa __P((SOCKADDR *));
1345 # if NETINET6
1346 extern char	*anynet_ntop __P((struct in6_addr *, char *, size_t));
1347 # endif /* NETINET6 */
1348 extern char	*hostnamebyanyaddr __P((SOCKADDR *));
1349 # if DAEMON
1350 extern char	*validate_connection __P((SOCKADDR *, char *, ENVELOPE *));
1351 # endif /* DAEMON */
1352 
1353 #endif /* NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25 */
1354 
1355 #if _FFR_MILTER
1356 /*
1357 **  Mail Filters (milter)
1358 */
1359 
1360 #include <libmilter/milter.h>
1361 
1362 #define SMFTO_WRITE	0		/* Timeout for sending information */
1363 #define SMFTO_READ	1		/* Timeout waiting for a response */
1364 #define SMFTO_EOM	2		/* Timeout for ACK/NAK to EOM */
1365 #define SMFTO_CONNECT	3		/* Timeout for connect() */
1366 
1367 #define SMFTO_NUM_TO	4		/* Total number of timeouts */
1368 
1369 struct milter
1370 {
1371 	char		*mf_name;	/* filter name */
1372 	BITMAP256	mf_flags;	/* MTA flags */
1373 	u_long		mf_fvers;	/* filter version */
1374 	u_long		mf_fflags;	/* filter flags */
1375 	u_long		mf_pflags;	/* protocol flags */
1376 	char		*mf_conn;	/* connection info */
1377 	int		mf_sock;	/* connected socket */
1378 	char		mf_state;	/* state of filter */
1379 	time_t		mf_timeout[SMFTO_NUM_TO]; /* timeouts */
1380 };
1381 
1382 /* MTA flags */
1383 # define SMF_REJECT		'R'	/* Reject connection on filter fail */
1384 # define SMF_TEMPFAIL		'T'	/* tempfail connection on failure */
1385 
1386 /* states */
1387 # define SMFS_CLOSED		'C'	/* closed for all further actions */
1388 # define SMFS_OPEN		'O'	/* connected to remote milter filter */
1389 # define SMFS_INMSG		'M'	/* currently servicing a message */
1390 # define SMFS_DONE		'D'	/* done with current message */
1391 # define SMFS_CLOSABLE		'Q'	/* done with current connection */
1392 # define SMFS_ERROR		'E'	/* error state */
1393 # define SMFS_READY		'R'	/* ready for action */
1394 
1395 /* 32-bit type used by milter */
1396 typedef SM_INT32	mi_int32;
1397 
1398 EXTERN struct milter	*InputFilters[MAXFILTERS];
1399 EXTERN char		*InputFilterList;
1400 #endif /* _FFR_MILTER */
1401 
1402 /*
1403 **  Vendor codes
1404 **
1405 **	Vendors can customize sendmail to add special behaviour,
1406 **	generally for back compatibility.  Ideally, this should
1407 **	be set up in the .cf file using the "V" command.  However,
1408 **	it's quite reasonable for some vendors to want the default
1409 **	be their old version; this can be set using
1410 **		-DVENDOR_DEFAULT=VENDOR_xxx
1411 **	in the Makefile.
1412 **
1413 **	Vendors should apply to sendmail@sendmail.org for
1414 **	unique vendor codes.
1415 */
1416 
1417 #define VENDOR_BERKELEY	1	/* Berkeley-native configuration file */
1418 #define VENDOR_SUN	2	/* Sun-native configuration file */
1419 #define VENDOR_HP	3	/* Hewlett-Packard specific config syntax */
1420 #define VENDOR_IBM	4	/* IBM specific config syntax */
1421 #define VENDOR_SENDMAIL	5	/* Sendmail, Inc. specific config syntax */
1422 
1423 /* prototypes for vendor-specific hook routines */
1424 extern void	vendor_daemon_setup __P((ENVELOPE *));
1425 extern void	vendor_set_uid __P((UID_T));
1426 
1427 
1428 /*
1429 **  Terminal escape codes.
1430 **
1431 **	To make debugging output clearer.
1432 */
1433 
1434 struct termescape
1435 {
1436 	char	*te_rv_on;	/* turn reverse-video on */
1437 	char	*te_rv_off;	/* turn reverse-video off */
1438 };
1439 
1440 /*
1441 **  Additional definitions
1442 */
1443 
1444 /* d_flags, see daemon.c */
1445 /* general rule: lower case: required, upper case: No */
1446 #define D_AUTHREQ	'a'	/* authentication required */
1447 #define D_BINDIF	'b'	/* use if_addr for outgoing connection */
1448 #define D_CANONREQ	'c'	/* canonification required (cf) */
1449 #define D_IFNHELO	'h'	/* use if name for HELO */
1450 #define D_FQMAIL	'f'	/* fq sender address required (cf) */
1451 #if _FFR_TLS_CLT1
1452 #define D_CLTNOTLS	'S'	/* don't use STARTTLS in client */
1453 #endif /* _FFR_TLS_CLT1 */
1454 #define D_FQRCPT	'r'	/* fq recipient address required (cf) */
1455 #define D_UNQUALOK	'u'	/* unqualified address is ok (cf) */
1456 #define D_NOCANON	'C'	/* no canonification (cf) */
1457 #define D_NOETRN	'E'	/* no ETRN (MSA) */
1458 #define D_ETRNONLY	((char)0x01)	/* allow only ETRN (disk low) */
1459 
1460 /* Flags for submitmode */
1461 #define SUBMIT_UNKNOWN	0x0000	/* unknown agent type */
1462 #define SUBMIT_MTA	0x0001	/* act like a message transfer agent */
1463 #define SUBMIT_MSA	0x0002	/* act like a message submission agent */
1464 
1465 #if SASL
1466 /*
1467 **  SASL
1468 */
1469 
1470 /* authenticated? */
1471 # define SASL_NOT_AUTH	0		/* not authenticated */
1472 # define SASL_PROC_AUTH	1		/* in process of authenticating */
1473 # define SASL_IS_AUTH	2		/* authenticated */
1474 
1475 /* SASL options */
1476 # define SASL_AUTH_AUTH	0x1000		/* use auth= only if authenticated */
1477 # if _FFR_SASL_OPTS
1478 #  define SASL_SEC_MASK	0x0fff		/* mask for SASL_SEC_* values: sasl.h */
1479 #  if (SASL_SEC_NOPLAINTEXT & SASL_SEC_MASK) == 0 || \
1480 	(SASL_SEC_NOACTIVE & SASL_SEC_MASK) == 0 || \
1481 	(SASL_SEC_NODICTIONARY & SASL_SEC_MASK) == 0 || \
1482 	(SASL_SEC_FORWARD_SECRECY & SASL_SEC_MASK) == 0 || \
1483 	(SASL_SEC_NOANONYMOUS & SASL_SEC_MASK) == 0 || \
1484 	(SASL_SEC_PASS_CREDENTIALS & SASL_SEC_MASK) == 0
1485 ERROR: change SASL_SEC_MASK_ notify sendmail.org!
1486 #  endif
1487 # endif /* _FFR_SASL_OPTS */
1488 
1489 # define MAXOUTLEN 1024			/* length of output buffer */
1490 #endif /* SASL */
1491 
1492 #if STARTTLS
1493 /*
1494 **  TLS
1495 */
1496 
1497 /* what to do in the TLS initialization */
1498 #define TLS_I_NONE	0x00000000	/* no requirements... */
1499 #define TLS_I_CERT_EX	0x00000001	/* CERT must exist */
1500 #define TLS_I_CERT_UNR	0x00000002	/* CERT must be g/o unreadable */
1501 #define TLS_I_KEY_EX	0x00000004	/* KEY must exist */
1502 #define TLS_I_KEY_UNR	0x00000008	/* KEY must be g/o unreadable */
1503 #define TLS_I_CERTP_EX	0x00000010	/* CA CERT PATH must exist */
1504 #define TLS_I_CERTP_UNR	0x00000020	/* CA CERT PATH must be g/o unreadable */
1505 #define TLS_I_CERTF_EX	0x00000040	/* CA CERT FILE must exist */
1506 #define TLS_I_CERTF_UNR	0x00000080	/* CA CERT FILE must be g/o unreadable */
1507 #define TLS_I_RSA_TMP	0x00000100	/* RSA TMP must be generated */
1508 #define TLS_I_USE_KEY	0x00000200	/* private key must usable */
1509 #define TLS_I_USE_CERT	0x00000400	/* certificate must be usable */
1510 #define TLS_I_VRFY_PATH	0x00000800	/* load verify path must succeed */
1511 #define TLS_I_VRFY_LOC	0x00001000	/* load verify default must succeed */
1512 #define TLS_I_CACHE	0x00002000	/* require cache */
1513 #define TLS_I_TRY_DH	0x00004000	/* try DH certificate */
1514 #define TLS_I_REQ_DH	0x00008000	/* require DH certificate */
1515 #define TLS_I_DHPAR_EX	0x00010000	/* require DH parameters */
1516 #define TLS_I_DHPAR_UNR	0x00020000	/* DH param. must be g/o unreadable */
1517 #define TLS_I_DH512	0x00040000	/* generate 512bit DH param */
1518 #define TLS_I_DH1024	0x00080000	/* generate 1024bit DH param */
1519 #define TLS_I_DH2048	0x00100000	/* generate 2048bit DH param */
1520 
1521 /* server requirements */
1522 #define TLS_I_SRV	(TLS_I_CERT_EX | TLS_I_KEY_EX | TLS_I_KEY_UNR | \
1523 			 TLS_I_CERTP_EX | TLS_I_CERTF_EX | TLS_I_RSA_TMP | \
1524 			 TLS_I_USE_KEY | TLS_I_USE_CERT | TLS_I_VRFY_PATH | \
1525 			 TLS_I_VRFY_LOC | TLS_I_TRY_DH | \
1526 			 TLS_I_DH512)
1527 
1528 /* client requirements */
1529 #define TLS_I_CLT	(TLS_I_KEY_UNR)
1530 
1531 #define TLS_AUTH_OK	0
1532 #define TLS_AUTH_NO	1
1533 #define TLS_AUTH_FAIL	(-1)
1534 #endif /* STARTTLS */
1535 
1536 
1537 /*
1538 **  Queue related items
1539 */
1540 
1541 /* queue sort order */
1542 #define QSO_BYPRIORITY	0		/* sort by message priority */
1543 #define QSO_BYHOST	1		/* sort by first host name */
1544 #define QSO_BYTIME	2		/* sort by submission time */
1545 #define QSO_BYFILENAME	3		/* sort by file name only */
1546 
1547 #if _FFR_QUEUEDELAY
1548 #define QD_LINEAR	0		/* linear (old) delay alg */
1549 #define QD_EXP		1		/* exponential delay alg */
1550 #endif /* _FFR_QUEUEDELAY */
1551 
1552 #define	NOQDIR	(-1)			/* no queue directory (yet) */
1553 
1554 #define	NOW	((time_t) (-1))		/* queue return: now */
1555 
1556 /* Queue Run Limitations */
1557 struct queue_char
1558 {
1559 	char *queue_match;		/* string to match */
1560 	struct queue_char *queue_next;
1561 };
1562 
1563 typedef struct queue_char QUEUE_CHAR;
1564 
1565 /* functions */
1566 extern void	assign_queueid __P((ENVELOPE *));
1567 extern ADDRESS	*copyqueue __P((ADDRESS *));
1568 extern void	initsys __P((ENVELOPE *));
1569 extern void	loseqfile __P((ENVELOPE *, char *));
1570 extern void	multiqueue_cache __P((void));
1571 extern char	*qid_printname __P((ENVELOPE *));
1572 extern char	*qid_printqueue __P((int));
1573 extern char	*queuename __P((ENVELOPE *, int));
1574 extern void	queueup __P((ENVELOPE *, bool));
1575 extern bool	runqueue __P((bool, bool));
1576 extern void	setnewqueue __P((ENVELOPE *));
1577 extern bool	shouldqueue __P((long, time_t));
1578 extern void	sync_queue_time __P((void));
1579 
1580 /*
1581 **  Timeouts
1582 **
1583 **	Indicated values are the MINIMUM per RFC 1123 section 5.3.2.
1584 */
1585 
1586 EXTERN struct
1587 {
1588 			/* RFC 1123-specified timeouts [minimum value] */
1589 	time_t	to_initial;	/* initial greeting timeout [5m] */
1590 	time_t	to_mail;	/* MAIL command [5m] */
1591 	time_t	to_rcpt;	/* RCPT command [5m] */
1592 	time_t	to_datainit;	/* DATA initiation [2m] */
1593 	time_t	to_datablock;	/* DATA block [3m] */
1594 	time_t	to_datafinal;	/* DATA completion [10m] */
1595 	time_t	to_nextcommand;	/* next command [5m] */
1596 			/* following timeouts are not mentioned in RFC 1123 */
1597 	time_t	to_iconnect;	/* initial connection timeout (first try) */
1598 	time_t	to_connect;	/* initial connection timeout (later tries) */
1599 	time_t	to_rset;	/* RSET command */
1600 	time_t	to_helo;	/* HELO command */
1601 	time_t	to_quit;	/* QUIT command */
1602 	time_t	to_miscshort;	/* misc short commands (NOOP, VERB, etc) */
1603 	time_t	to_ident;	/* IDENT protocol requests */
1604 	time_t	to_fileopen;	/* opening :include: and .forward files */
1605 	time_t	to_control;	/* process a control socket command */
1606 			/* following are per message */
1607 	time_t	to_q_return[MAXTOCLASS];	/* queue return timeouts */
1608 	time_t	to_q_warning[MAXTOCLASS];	/* queue warning timeouts */
1609 	time_t	res_retrans[MAXRESTOTYPES];	/* resolver retransmit */
1610 	int	res_retry[MAXRESTOTYPES];	/* resolver retry */
1611 } TimeOuts;
1612 
1613 /* timeout classes for return and warning timeouts */
1614 #define TOC_NORMAL	0	/* normal delivery */
1615 #define TOC_URGENT	1	/* urgent delivery */
1616 #define TOC_NONURGENT	2	/* non-urgent delivery */
1617 
1618 /* resolver timeout specifiers */
1619 #define RES_TO_FIRST	0	/* first attempt */
1620 #define RES_TO_NORMAL	1	/* subsequent attempts */
1621 #define RES_TO_DEFAULT	2	/* default value */
1622 
1623 /* functions */
1624 extern void	inittimeouts __P((char *, bool));
1625 
1626 /*
1627 **  Trace information
1628 */
1629 
1630 /* macros for debugging flags */
1631 #define tTd(flag, level)	(tTdvect[flag] >= (u_char)level)
1632 #define tTdlevel(flag)		(tTdvect[flag])
1633 
1634 /* variables */
1635 extern u_char	tTdvect[100];	/* trace vector */
1636 /*
1637 **  Critical signal sections
1638 */
1639 
1640 #define PEND_SIGHUP	0x0001
1641 #define PEND_SIGINT	0x0002
1642 #define PEND_SIGTERM	0x0004
1643 #define PEND_SIGUSR1	0x0008
1644 
1645 #define ENTER_CRITICAL()	InCriticalSection++
1646 
1647 #define LEAVE_CRITICAL()						\
1648 do									\
1649 {									\
1650 	if (InCriticalSection > 0)					\
1651 		InCriticalSection--;					\
1652 } while (0)
1653 
1654 #define CHECK_CRITICAL(sig)						\
1655 do									\
1656 {									\
1657 	if (InCriticalSection > 0 && (sig) != 0)			\
1658 	{								\
1659 		pend_signal((sig));					\
1660 		return SIGFUNC_RETURN;					\
1661 	}								\
1662 } while (0)
1663 
1664 /* reset signal in case System V semantics */
1665 #ifdef SYS5SIGNALS
1666 # define FIX_SYSV_SIGNAL(sig, handler)					\
1667 {									\
1668 	if ((sig) != 0)							\
1669 		(void) setsignal((sig), (handler));			\
1670 }
1671 #else /* SYS5SIGNALS */
1672 # define FIX_SYSV_SIGNAL(sig, handler)	{ /* EMPTY */ }
1673 #endif /* SYS5SIGNALS */
1674 
1675 /* variables */
1676 EXTERN u_int	volatile InCriticalSection;	/* >0 if in a critical section */
1677 EXTERN int	volatile PendingSignal;	/* pending signal to resend */
1678 
1679 /* functions */
1680 extern void	pend_signal __P((int));
1681 
1682 /*
1683 **  Miscellaneous information.
1684 */
1685 
1686 /*
1687 **  The "no queue id" queue id for sm_syslog
1688 */
1689 
1690 #define NOQID		"*~*"
1691 
1692 
1693 /*
1694 **  Some in-line functions
1695 */
1696 
1697 /* set exit status */
1698 #define setstat(s)	{ \
1699 				if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \
1700 					ExitStat = s; \
1701 			}
1702 
1703 /* make a copy of a string */
1704 #define newstr(s)	strcpy(xalloc(strlen(s) + 1), s)
1705 
1706 #define STRUCTCOPY(s, d)	d = s
1707 /*
1708 **  Global variables.
1709 */
1710 
1711 EXTERN bool	AllowBogusHELO;	/* allow syntax errors on HELO command */
1712 #if !_FFR_REMOVE_AUTOREBUILD
1713 EXTERN bool	AutoRebuild;	/* auto-rebuild the alias database as needed */
1714 #endif /* !_FFR_REMOVE_AUTOREBUILD */
1715 EXTERN bool	CheckAliases;	/* parse addresses during newaliases */
1716 EXTERN bool	ChownAlwaysSafe;	/* treat chown(2) as safe */
1717 EXTERN bool	ColonOkInAddr;	/* single colon legal in address */
1718 EXTERN bool	ConfigFileRead;	/* configuration file has been read */
1719 EXTERN bool	volatile DataProgress;	/* have we sent anything since last check */
1720 EXTERN bool	DisConnected;	/* running with OutChannel redirected to xf */
1721 EXTERN bool	volatile DoQueueRun;	/* non-interrupt time queue run needed */
1722 EXTERN bool	DontExpandCnames;	/* do not $[...$] expand CNAMEs */
1723 EXTERN bool	DontInitGroups;	/* avoid initgroups() because of NIS cost */
1724 EXTERN bool	DontLockReadFiles;	/* don't read lock support files */
1725 EXTERN bool	DontProbeInterfaces;	/* don't probe interfaces for names */
1726 EXTERN bool	DontPruneRoutes;	/* don't prune source routes */
1727 EXTERN bool	ForkQueueRuns;	/* fork for each job when running the queue */
1728 EXTERN bool	FromFlag;	/* if set, "From" person is explicit */
1729 EXTERN bool	GrabTo;		/* if set, get recipients from msg */
1730 EXTERN bool	HasEightBits;	/* has at least one eight bit input byte */
1731 EXTERN bool	HasWildcardMX;	/* don't use MX records when canonifying */
1732 EXTERN bool	HoldErrs;	/* only output errors to transcript */
1733 EXTERN bool	IgnoreHostStatus;	/* ignore long term host status files */
1734 EXTERN bool	IgnrDot;	/* don't let dot end messages */
1735 EXTERN bool	InChild;	/* true if running in an SMTP subprocess */
1736 EXTERN bool	LogUsrErrs;	/* syslog user errors (e.g., SMTP RCPT cmd) */
1737 EXTERN bool	MapOpenErr;	/* error opening a non-optional map */
1738 EXTERN bool	MatchGecos;	/* look for user names in gecos field */
1739 EXTERN bool	MeToo;		/* send to the sender also */
1740 EXTERN bool	NoAlias;	/* suppress aliasing */
1741 EXTERN bool	NoConnect;	/* don't connect to non-local mailers */
1742 EXTERN bool	OnlyOneError;	/*  .... or only want to give one SMTP reply */
1743 EXTERN bool	QuickAbort;	/*  .... but only if we want a quick abort */
1744 EXTERN bool	RrtImpliesDsn;	/* turn Return-Receipt-To: into DSN */
1745 EXTERN bool	SaveFrom;	/* save leading "From" lines */
1746 EXTERN bool	SendMIMEErrors;	/* send error messages in MIME format */
1747 EXTERN bool	SevenBitInput;	/* force 7-bit data on input */
1748 EXTERN bool	SingleLineFromHeader;	/* force From: header to be one line */
1749 EXTERN bool	SingleThreadDelivery;	/* single thread hosts on delivery */
1750 EXTERN bool	volatile StopRequest;	/* stop sending output */
1751 EXTERN bool	SuperSafe;	/* be extra careful, even if expensive */
1752 EXTERN bool	SuprErrs;	/* set if we are suppressing errors */
1753 EXTERN bool	TryNullMXList;	/* if we are the best MX, try host directly */
1754 #if _FFR_WORKAROUND_BROKEN_NAMESERVERS
1755 EXTERN bool	WorkAroundBrokenAAAA;	/* some nameservers return SERVFAIL on AAAA queries */
1756 #endif /* _FFR_WORKAROUND_BROKEN_NAMESERVERS */
1757 EXTERN bool	UseErrorsTo;	/* use Errors-To: header (back compat) */
1758 EXTERN bool	UseHesiod;	/* using Hesiod -- interpret Hesiod errors */
1759 EXTERN bool	UseNameServer;	/* using DNS -- interpret h_errno & MX RRs */
1760 EXTERN char	InetMode;		/* default network for daemon mode */
1761 EXTERN char	OpMode;		/* operation mode, see below */
1762 EXTERN char	SpaceSub;	/* substitution for <lwsp> */
1763 EXTERN int	CheckpointInterval;	/* queue file checkpoint interval */
1764 EXTERN int	ConfigLevel;	/* config file level */
1765 EXTERN int	ConnRateThrottle;	/* throttle for SMTP connection rate */
1766 EXTERN int	volatile CurChildren;	/* current number of daemonic children */
1767 EXTERN int	CurrentLA;	/* current load average */
1768 EXTERN int	DefaultNotify;	/* default DSN notification flags */
1769 EXTERN int	Errors;		/* set if errors (local to single pass) */
1770 EXTERN int	ExitStat;	/* exit status code */
1771 EXTERN int	FileMode;	/* mode on files */
1772 EXTERN int	LineNumber;	/* line number in current input */
1773 EXTERN int	LogLevel;	/* level of logging to perform */
1774 EXTERN int	MaxAliasRecursion;	/* maximum depth of alias recursion */
1775 EXTERN int	MaxChildren;	/* maximum number of daemonic children */
1776 EXTERN int	MaxForwardEntries;	/* maximum number of forward entries */
1777 EXTERN int	MaxHeadersLength;	/* max length of headers */
1778 EXTERN int	MaxHopCount;	/* max # of hops until bounce */
1779 EXTERN int	MaxMacroRecursion;	/* maximum depth of macro recursion */
1780 EXTERN int	MaxMciCache;		/* maximum entries in MCI cache */
1781 EXTERN int	MaxMimeFieldLength;	/* maximum MIME field length */
1782 EXTERN int	MaxMimeHeaderLength;	/* maximum MIME header length */
1783 
1784 
1785 EXTERN int	MaxQueueRun;	/* maximum number of jobs in one queue run */
1786 EXTERN int	MaxRcptPerMsg;	/* max recipients per SMTP message */
1787 EXTERN int	MaxRuleRecursion;	/* maximum depth of ruleset recursion */
1788 EXTERN int	MimeMode;	/* MIME processing mode */
1789 EXTERN int	NoRecipientAction;
1790 EXTERN int	NumPriorities;	/* pointer into Priorities */
1791 EXTERN u_short	PrivacyFlags;	/* privacy flags */
1792 #if _FFR_QUEUE_FILE_MODE
1793 EXTERN int	QueueFileMode;	/* mode on qf/tf/df files */
1794 #endif /* _FFR_QUEUE_FILE_MODE */
1795 EXTERN int	QueueLA;	/* load average starting forced queueing */
1796 EXTERN int	QueueSortOrder;	/* queue sorting order algorithm */
1797 EXTERN int	RefuseLA;	/* load average refusing connections are */
1798 EXTERN int	VendorCode;	/* vendor-specific operation enhancements */
1799 EXTERN int	Verbose;	/* set if blow-by-blow desired */
1800 EXTERN gid_t	DefGid;		/* default gid to run as */
1801 EXTERN gid_t	RealGid;	/* real gid of caller */
1802 EXTERN gid_t	RunAsGid;	/* GID to become for bulk of run */
1803 EXTERN uid_t	DefUid;		/* default uid to run as */
1804 EXTERN uid_t	RealUid;	/* real uid of caller */
1805 EXTERN uid_t	RunAsUid;	/* UID to become for bulk of run */
1806 EXTERN uid_t	TrustedUid;	/* uid of trusted user for files and startup */
1807 EXTERN size_t	DataFileBufferSize;	/* size of buffer for in-core df */
1808 EXTERN size_t	XscriptFileBufferSize;	/* size of buffer for in-core xf */
1809 EXTERN time_t	DialDelay;	/* delay between dial-on-demand tries */
1810 EXTERN time_t	MciCacheTimeout;	/* maximum idle time on connections */
1811 EXTERN time_t	MciInfoTimeout;		/* how long 'til we retry down hosts */
1812 EXTERN time_t	MinQueueAge;	/* min delivery interval */
1813 EXTERN time_t	QueueIntvl;	/* intervals between running the queue */
1814 EXTERN time_t	SafeAlias;	/* interval to wait until @:@ in alias file */
1815 EXTERN time_t	ServiceCacheMaxAge;	/* refresh interval for cache */
1816 EXTERN time_t	ServiceCacheTime;	/* time service switch was cached */
1817 EXTERN MODE_T	OldUmask;	/* umask when sendmail starts up */
1818 EXTERN long	MaxMessageSize;	/* advertised max size we will accept */
1819 EXTERN long	MinBlocksFree;	/* min # of blocks free on queue fs */
1820 EXTERN long	QueueFactor;	/* slope of queue function */
1821 EXTERN long	WkClassFact;	/* multiplier for message class -> priority */
1822 EXTERN long	WkRecipFact;	/* multiplier for # of recipients -> priority */
1823 EXTERN long	WkTimeFact;	/* priority offset each time this job is run */
1824 #if SASL
1825 EXTERN char	*AuthMechanisms;	/* AUTH mechanisms */
1826 EXTERN char	*SASLInfo;		/* file with AUTH info */
1827 #endif /* SASL */
1828 EXTERN int	SASLOpts;		/* options for SASL */
1829 #if STARTTLS
1830 EXTERN char	*CACERTpath;	/* path to CA certificates (dir. with hashes) */
1831 EXTERN char	*CACERTfile;	/* file with CA certificate */
1832 EXTERN char	*SrvCERTfile;	/* file with server certificate */
1833 EXTERN char	*Srvkeyfile;	/* file with server private key */
1834 EXTERN char	*CltCERTfile;	/* file with client certificate */
1835 EXTERN char	*Cltkeyfile;	/* file with client private key */
1836 EXTERN char	*DHParams;	/* file with DH parameters */
1837 EXTERN char	*RandFile;	/* source of random data */
1838 # if _FFR_TLS_1
1839 EXTERN char	*DHParams5;	/* file with DH parameters (512) */
1840 EXTERN char	*CipherList;	/* list of ciphers */
1841 # endif /* _FFR_TLS_1 */
1842 #endif /* STARTTLS */
1843 EXTERN char	*ConfFile;	/* location of configuration file [conf.c] */
1844 EXTERN char	*ControlSocketName; /* control socket filename [control.c] */
1845 EXTERN char	*CurHostName;	/* current host we are dealing with */
1846 EXTERN char	*DeadLetterDrop;	/* path to dead letter office */
1847 EXTERN char	*DefUser;	/* default user to run as (from DefUid) */
1848 EXTERN char	*DefaultCharSet;	/* default character set for MIME */
1849 EXTERN char	*DoubleBounceAddr;	/* where to send double bounces */
1850 EXTERN char	*ErrMsgFile;	/* file to prepend to all error messages */
1851 EXTERN char	*FallBackMX;	/* fall back MX host */
1852 EXTERN char	*FileName;	/* name to print on error messages */
1853 EXTERN char	*ForwardPath;	/* path to search for .forward files */
1854 EXTERN char	*HelpFile;	/* location of SMTP help file */
1855 EXTERN char	*HostStatDir;	/* location of host status information */
1856 EXTERN char	*HostsFile;	/* path to /etc/hosts file */
1857 EXTERN char	*MustQuoteChars;	/* quote these characters in phrases */
1858 EXTERN char	*MyHostName;	/* name of this host for SMTP messages */
1859 EXTERN char	*OperatorChars;	/* operators (old $o macro) */
1860 EXTERN char	*PidFile;	/* location of proc id file [conf.c] */
1861 EXTERN char	*PostMasterCopy;	/* address to get errs cc's */
1862 EXTERN char	*ProcTitlePrefix; /* process title prefix */
1863 EXTERN char	*QueueDir;	/* location of queue directory */
1864 #if _FFR_QUEUEDELAY
1865 EXTERN int	QueueAlg;	/* algorithm for queue delays */
1866 EXTERN time_t	QueueInitDelay;	/* initial queue delay */
1867 EXTERN time_t	QueueMaxDelay;	/* maximum queue delay */
1868 #endif /* _FFR_QUEUEDELAY */
1869 EXTERN char	*RealHostName;	/* name of host we are talking to */
1870 EXTERN char	*RealUserName;	/* real user name of caller */
1871 EXTERN char	*volatile RestartRequest;/* a sendmail restart has been requested */
1872 EXTERN char	*RunAsUserName;	/* user to become for bulk of run */
1873 EXTERN char	*SafeFileEnv;	/* chroot location for file delivery */
1874 EXTERN char	*ServiceSwitchFile;	/* backup service switch */
1875 EXTERN char	*volatile ShutdownRequest;/* a sendmail shutdown has been requested */
1876 EXTERN char	*SmtpGreeting;	/* SMTP greeting message (old $e macro) */
1877 EXTERN char	*SmtpPhase;	/* current phase in SMTP processing */
1878 EXTERN char	SmtpError[MAXLINE];	/* save failure error messages */
1879 EXTERN char	*StatFile;	/* location of statistics summary */
1880 EXTERN char	*TimeZoneSpec;	/* override time zone specification */
1881 EXTERN char	*UdbSpec;	/* user database source spec */
1882 EXTERN char	*UnixFromLine;	/* UNIX From_ line (old $l macro) */
1883 EXTERN char	**ExternalEnviron;	/* input environment */
1884 					/* saved user environment */
1885 EXTERN char	**SaveArgv;	/* argument vector for re-execing */
1886 EXTERN BITMAP256	DontBlameSendmail;	/* DontBlameSendmail bits */
1887 #if SFIO
1888 EXTERN Sfio_t	*InChannel;	/* input connection */
1889 EXTERN Sfio_t	*OutChannel;	/* output connection */
1890 #else /* SFIO */
1891 EXTERN FILE	*InChannel;	/* input connection */
1892 EXTERN FILE	*OutChannel;	/* output connection */
1893 #endif /* SFIO */
1894 EXTERN FILE	*TrafficLogFile;	/* file in which to log all traffic */
1895 #ifdef HESIOD
1896 EXTERN void	*HesiodContext;
1897 #endif /* HESIOD */
1898 EXTERN ENVELOPE	*CurEnv;	/* envelope currently being processed */
1899 EXTERN MAILER	*LocalMailer;	/* ptr to local mailer */
1900 EXTERN MAILER	*ProgMailer;	/* ptr to program mailer */
1901 EXTERN MAILER	*FileMailer;	/* ptr to *file* mailer */
1902 EXTERN MAILER	*InclMailer;	/* ptr to *include* mailer */
1903 EXTERN QUEUE_CHAR	*QueueLimitRecipient;	/* limit queue run to rcpt */
1904 EXTERN QUEUE_CHAR	*QueueLimitSender;	/* limit queue run to sender */
1905 EXTERN QUEUE_CHAR	*QueueLimitId;		/* limit queue run to id */
1906 EXTERN MAILER	*Mailer[MAXMAILERS + 1];
1907 EXTERN struct rewrite	*RewriteRules[MAXRWSETS];
1908 EXTERN char	*RuleSetNames[MAXRWSETS];	/* ruleset number to name */
1909 EXTERN char	*UserEnviron[MAXUSERENVIRON + 1];
1910 EXTERN struct priority	Priorities[MAXPRIORITIES];
1911 EXTERN struct termescape	TermEscape;	/* terminal escape codes */
1912 EXTERN SOCKADDR	ConnectOnlyTo;	/* override connection address (for testing) */
1913 EXTERN SOCKADDR RealHostAddr;	/* address of host we are talking to */
1914 EXTERN jmp_buf	TopFrame;	/* branch-to-top-of-loop-on-error frame */
1915 EXTERN TIMERS	Timers;
1916 
1917 /*
1918 **  Declarations of useful functions
1919 */
1920 
1921 #if SASL
1922 extern char	*intersect __P((char *, char *));
1923 extern char	*iteminlist __P((char *, char *, char *));
1924 extern int	proxy_policy __P((void *, const char *, const char *, const char **, const char **));
1925 # if SASL > 10515
1926 extern int	safesaslfile __P((void *, char *, int));
1927 # else /* SASL > 10515 */
1928 extern int	safesaslfile __P((void *, char *));
1929 # endif /* SASL > 10515 */
1930 extern int	sasl_decode64 __P((const char *, unsigned, char *, unsigned *));
1931 extern int	sasl_encode64 __P((const char *, unsigned, char *, unsigned, unsigned *));
1932 #endif /* SASL */
1933 
1934 #if STARTTLS
1935 extern void	apps_ssl_info_cb __P((SSL *, int , int));
1936 extern bool	init_tls_library __P((void));
1937 extern bool	inittls __P((SSL_CTX **, u_long, bool, char *, char *, char *, char *, char *));
1938 extern bool	initclttls __P((void));
1939 extern bool	initsrvtls __P((void));
1940 extern int	tls_get_info __P((SSL *, ENVELOPE *, bool, char *, bool));
1941 extern int	endtls __P((SSL *, char *));
1942 extern int	endtlsclt __P((MCI *));
1943 extern void	tlslogerr __P((void));
1944 extern bool	tls_rand_init __P((char *, int));
1945 #endif /* STARTTLS */
1946 
1947 /* Transcript file */
1948 extern void	closexscript __P((ENVELOPE *));
1949 extern void	openxscript __P((ENVELOPE *));
1950 
1951 /* error related */
1952 extern void	buffer_errors __P((void));
1953 extern void	flush_errors __P((bool));
1954 extern void	message __P((const char *, ...));
1955 extern void	nmessage __P((const char *, ...));
1956 extern void	syserr __P((const char *, ...));
1957 extern void	usrerrenh __P((char *, const char *, ...));
1958 extern void	usrerr __P((const char *, ...));
1959 extern int	isenhsc __P((const char *, int));
1960 extern int	extenhsc __P((const char *, int, char *));
1961 
1962 /* alias file */
1963 extern void	alias __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
1964 extern bool	aliaswait __P((MAP *, char *, bool));
1965 extern void	forward __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
1966 extern void	readaliases __P((MAP *, FILE *, bool, bool));
1967 extern bool	rebuildaliases __P((MAP *, bool));
1968 extern void	setalias __P((char *));
1969 
1970 /* logging */
1971 extern void	logdelivery __P((MAILER *, MCI *, char *, const char *, ADDRESS *, time_t, ENVELOPE *));
1972 extern void	logsender __P((ENVELOPE *, char *));
1973 extern void	sm_syslog __P((int, const char *, const char *, ...));
1974 
1975 /* SMTP */
1976 extern void	giveresponse __P((int, char *, MAILER *, MCI *, ADDRESS *, time_t, ENVELOPE *));
1977 extern int	reply __P((MAILER *, MCI *, ENVELOPE *, time_t, void (*)(), char **));
1978 extern void	smtp __P((char *volatile, BITMAP256, ENVELOPE *volatile));
1979 #if SASL
1980 extern int	smtpauth __P((MAILER *, MCI *, ENVELOPE *));
1981 #endif /* SASL */
1982 extern int	smtpdata __P((MAILER *, MCI *, ENVELOPE *));
1983 extern int	smtpgetstat __P((MAILER *, MCI *, ENVELOPE *));
1984 extern int	smtpmailfrom __P((MAILER *, MCI *, ENVELOPE *));
1985 extern void	smtpmessage __P((char *, MAILER *, MCI *, ...));
1986 extern void	smtpinit __P((MAILER *, MCI *, ENVELOPE *, bool));
1987 extern char	*smtptodsn __P((int));
1988 extern int	smtpprobe __P((MCI *));
1989 extern void	smtpquit __P((MAILER *, MCI *, ENVELOPE *));
1990 extern int	smtprcpt __P((ADDRESS *, MAILER *, MCI *, ENVELOPE *));
1991 extern void	smtprset __P((MAILER *, MCI *, ENVELOPE *));
1992 
1993 #define ISSMTPCODE(c)	(isascii(c[0]) && isdigit(c[0]) && \
1994 		    isascii(c[1]) && isdigit(c[1]) && \
1995 		    isascii(c[2]) && isdigit(c[2]))
1996 #define ISSMTPREPLY(c)	(ISSMTPCODE(c) && \
1997 		    (c[3] == ' ' || c[3] == '-' || c[3] == '\0'))
1998 
1999 /* delivery */
2000 extern pid_t	dowork __P((int, char *, bool, bool, ENVELOPE *));
2001 extern int	endmailer __P((MCI *, ENVELOPE *, char **));
2002 extern int	mailfile __P((char *volatile, MAILER *volatile, ADDRESS *, volatile long, ENVELOPE *));
2003 extern void	sendall __P((ENVELOPE *, int));
2004 
2005 /* stats */
2006 extern void	markstats __P((ENVELOPE *, ADDRESS *, bool));
2007 extern void	clearstats __P((void));
2008 extern void	poststats __P((char *));
2009 
2010 /* control socket */
2011 extern void	closecontrolsocket  __P((bool));
2012 extern void	clrcontrol  __P((void));
2013 extern void	control_command __P((int, ENVELOPE *));
2014 extern int	opencontrolsocket __P((void));
2015 
2016 #if _FFR_MILTER
2017 /* milter functions */
2018 extern void	milter_parse_list __P((char *, struct milter **, int));
2019 extern void	milter_setup __P((char *));
2020 extern void	milter_set_option __P((char *, char *, bool));
2021 extern bool	milter_can_delrcpts __P((void));
2022 extern void	milter_init __P((ENVELOPE *, char *));
2023 extern void	milter_quit __P((ENVELOPE *));
2024 extern void	milter_abort __P((ENVELOPE *));
2025 extern char	*milter_connect __P((char *, SOCKADDR, ENVELOPE *, char *));
2026 extern char	*milter_helo __P((char *, ENVELOPE *, char *));
2027 extern char	*milter_envfrom __P((char **, ENVELOPE *, char *));
2028 extern char	*milter_envrcpt __P((char **, ENVELOPE *, char *));
2029 extern char	*milter_data __P((ENVELOPE *, char *));
2030 #endif /* _FFR_MILTER */
2031 
2032 extern char	*addquotes __P((char *));
2033 extern void	allsignals __P((bool));
2034 extern char	*arpadate __P((char *));
2035 extern bool	atobool __P((char *));
2036 extern int	atooct __P((char *));
2037 extern void	auth_warning __P((ENVELOPE *, const char *, ...));
2038 extern int	blocksignal __P((int));
2039 extern bool	bitintersect __P((BITMAP256, BITMAP256));
2040 extern bool	bitzerop __P((BITMAP256));
2041 extern void	buildfname __P((char *, char *, char *, int));
2042 extern int	checkcompat __P((ADDRESS *, ENVELOPE *));
2043 #ifdef XDEBUG
2044 extern void	checkfd012 __P((char *));
2045 extern void	checkfdopen __P((int, char *));
2046 #endif /* XDEBUG */
2047 extern void	checkfds __P((char *));
2048 extern bool	chownsafe __P((int, bool));
2049 extern void	cleanstrcpy __P((char *, char *, int));
2050 extern void	clrdaemon __P((void));
2051 extern void	collect __P((FILE *, bool, HDR **, ENVELOPE *));
2052 extern time_t	convtime __P((char *, int));
2053 extern char	**copyplist __P((char **, bool));
2054 extern void	copy_class __P((int, int));
2055 extern time_t	curtime __P((void));
2056 extern char	*defcharset __P((ENVELOPE *));
2057 extern char	*denlstring __P((char *, bool, bool));
2058 extern void	disconnect __P((int, ENVELOPE *));
2059 extern bool	dns_getcanonname __P((char *, int, bool, int *));
2060 extern pid_t	dofork __P((void));
2061 extern int	drop_privileges __P((bool));
2062 extern int	dsntoexitstat __P((char *));
2063 extern void	dumpfd __P((int, bool, bool));
2064 extern void	dumpstate __P((char *));
2065 extern bool	enoughdiskspace __P((long, bool));
2066 extern char	*exitstat __P((char *));
2067 extern char	*fgetfolded __P((char *, int, FILE *));
2068 extern void	fill_fd __P((int, char *));
2069 extern char	*find_character __P((char *, int));
2070 extern struct passwd	*finduser __P((char *, bool *));
2071 extern void	finis __P((bool, volatile int));
2072 extern void	fixcrlf __P((char *, bool));
2073 extern long	freediskspace __P((char *, long *));
2074 #if NETINET6 && NEEDSGETIPNODE
2075 # if _FFR_FREEHOSTENT
2076 extern void	freehostent __P((struct hostent *));
2077 # endif /* _FFR_FREEHOSTENT */
2078 #endif /* NEEDSGETIPNODE && NETINET6 */
2079 extern char	*get_column __P((char *, int, int, char *, int));
2080 extern char	*getauthinfo __P((int, bool *));
2081 extern char	*getcfname __P((void));
2082 extern char	*getextenv __P((const char *));
2083 extern int	getdtsize __P((void));
2084 extern BITMAP256	*getrequests __P((ENVELOPE *));
2085 extern char	*getvendor __P((int));
2086 extern void	help __P((char *, ENVELOPE *));
2087 extern void	init_md __P((int, char **));
2088 extern void	initdaemon __P((void));
2089 extern void	inithostmaps __P((void));
2090 extern void	initmacros __P((ENVELOPE *));
2091 extern void	initsetproctitle __P((int, char **, char **));
2092 extern void	init_vendor_macros __P((ENVELOPE *));
2093 extern SIGFUNC_DECL	intsig __P((int));
2094 extern bool	isloopback __P((SOCKADDR sa));
2095 extern void	load_if_names __P((void));
2096 extern bool	lockfile __P((int, char *, char *, int));
2097 extern void	log_sendmail_pid __P((ENVELOPE *));
2098 extern char	lower __P((int));
2099 extern void	makelower __P((char *));
2100 extern int	makeconnection_ds __P((char *, MCI *));
2101 extern int	makeconnection __P((char *, volatile u_int, MCI *, ENVELOPE *));
2102 extern char *	munchstring __P((char *, char **, int));
2103 extern struct hostent	*myhostname __P((char *, int));
2104 extern char	*nisplus_default_domain __P((void));	/* extern for Sun */
2105 extern bool	path_is_dir __P((char *, bool));
2106 extern char	*pintvl __P((time_t, bool));
2107 extern void	printav __P((char **));
2108 extern void	printmailer __P((MAILER *));
2109 extern void	printopenfds __P((bool));
2110 extern void	printqueue __P((void));
2111 extern void	printrules __P((void));
2112 extern pid_t	prog_open __P((char **, int *, ENVELOPE *));
2113 extern void	putline __P((char *, MCI *));
2114 extern void	putxline __P((char *, size_t, MCI *, int));
2115 extern void	queueup_macros __P((int, FILE *, ENVELOPE *));
2116 extern void	readcf __P((char *, bool, ENVELOPE *));
2117 extern SIGFUNC_DECL	reapchild __P((int));
2118 extern int	releasesignal __P((int));
2119 extern void	resetlimits __P((void));
2120 extern bool	rfc822_string __P((char *));
2121 extern FILE	*safefopen __P((char *, int, int, long));
2122 extern void	savemail __P((ENVELOPE *, bool));
2123 extern void	seed_random __P((void));
2124 extern void	sendtoargv __P((char **, ENVELOPE *));
2125 extern void	setclientoptions __P((char *));
2126 extern bool	setdaemonoptions __P((char *));
2127 extern void	setdefaults __P((ENVELOPE *));
2128 extern void	setdefuser __P((void));
2129 extern bool	setvendor __P((char *));
2130 extern void	setoption __P((int, char *, bool, bool, ENVELOPE *));
2131 extern sigfunc_t	setsignal __P((int, sigfunc_t));
2132 extern void	setuserenv __P((const char *, const char *));
2133 extern void	settime __P((ENVELOPE *));
2134 extern char	*sfgets __P((char *, int, FILE *, time_t, char *));
2135 extern char	*shortenstring __P((const char *, int));
2136 extern char	*shorten_hostname __P((char []));
2137 extern bool	shorten_rfc822_string __P((char *, size_t));
2138 extern void	shutdown_daemon __P((void));
2139 extern void	sm_dopr __P((char *, const char *, va_list));
2140 extern void	sm_free __P((void *));
2141 extern struct hostent	*sm_gethostbyname __P((char *, int));
2142 extern struct hostent	*sm_gethostbyaddr __P((char *, int, int));
2143 extern int	sm_getla __P((ENVELOPE *));
2144 extern struct passwd	*sm_getpwnam __P((char *));
2145 extern struct passwd	*sm_getpwuid __P((UID_T));
2146 extern void	sm_setproctitle __P((bool, ENVELOPE *, const char *, ...));
2147 extern SIGFUNC_DECL	sm_signal_noop __P((int));
2148 extern int	sm_strcasecmp __P((const char *, const char *));
2149 extern void	stop_sendmail __P((void));
2150 extern bool	strcontainedin __P((char *, char *));
2151 extern void	stripquotes __P((char *));
2152 extern int	switch_map_find __P((char *, char *[], short []));
2153 extern bool	transienterror __P((int));
2154 extern void	tTflag __P((char *));
2155 extern void	tTsetup __P((u_char *, int, char *));
2156 extern char	*ttypath __P((void));
2157 extern void	unlockqueue __P((ENVELOPE *));
2158 #if !HASUNSETENV
2159 extern void	unsetenv __P((char *));
2160 #endif /* !HASUNSETENV */
2161 extern char	*username __P((void));
2162 extern bool	usershellok __P((char *, char *));
2163 extern void	vendor_post_defaults __P((ENVELOPE *));
2164 extern void	vendor_pre_defaults __P((ENVELOPE *));
2165 extern int	waitfor __P((pid_t));
2166 extern bool	writable __P((char *, ADDRESS *, long));
2167 extern char	*xalloc __P((int));
2168 extern char	*xcalloc __P((size_t, size_t));
2169 extern char	*xrealloc __P((void *, size_t));
2170 extern void	xputs __P((const char *));
2171 extern char	*xtextify __P((char *, char *));
2172 extern bool	xtextok __P((char *));
2173 extern void	xunlink __P((char *));
2174 extern char	*xuntextify __P((char *));
2175 #endif /* _SENDMAIL_H */
2176