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