Deleted Added
full compact
sendmail.h (80785) sendmail.h (82017)
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
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
23static char SmailId[] = "@(#)$Id: sendmail.h,v 8.517.4.69 2001/07/20 18:46:01 gshapiro Exp $";
23static 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 */
169typedef struct envelope ENVELOPE;
170typedef struct mailer MAILER;
171
172 /*
173** Address structure.
174** Addresses are stored internally in this structure.
175*/
176
177struct 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
202typedef 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
269extern ADDRESS NullAddress; /* a null (template) address [main.c] */
270
271/* functions */
272extern void cataddr __P((char **, char **, char *, int, int));
273extern char *crackaddr __P((char *));
274extern bool emptyaddr __P((ADDRESS *));
275extern ADDRESS *getctladdr __P((ADDRESS *));
276extern int include __P((char *, bool, ADDRESS *, ADDRESS **, int, ENVELOPE *));
277extern bool invalidaddr __P((char *, char *));
278extern ADDRESS *parseaddr __P((char *, ADDRESS *, int, int, char **, ENVELOPE *));
279extern char **prescan __P((char *, int, char[], int, char **, u_char *));
280extern void printaddr __P((ADDRESS *, bool));
281extern ADDRESS *recipient __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
282extern char *remotename __P((char *, MAILER *, int, int *, ENVELOPE *));
283extern int rewrite __P((char **, int, int, ENVELOPE *));
284extern bool sameaddr __P((ADDRESS *, ADDRESS *));
285extern int sendtolist __P((char *, ADDRESS *, ADDRESS **, int, ENVELOPE *));
286extern int removefromlist __P((char *, ADDRESS **, ENVELOPE *));
287extern 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
301struct 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 */
391extern void initerrmailers __P((void));
392extern 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
401MCI
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 */
478extern void mci_cache __P((MCI *));
479extern void mci_dump __P((MCI *, bool));
480extern void mci_dump_all __P((bool));
481extern void mci_flush __P((bool, MCI *));
482extern MCI *mci_get __P((char *, MAILER *));
483extern int mci_lock_host __P((MCI *));
484extern bool mci_match __P((char *, MAILER *));
485extern int mci_print_persistent __P((char *, char *));
486extern int mci_purge_persistent __P((char *, char *));
487extern MCI **mci_scan __P((MCI *));
488extern void mci_setstat __P((MCI *, int, char *, char *));
489extern void mci_store_persistent __P((MCI *));
490extern int mci_traverse_persistent __P((int (*)(), char *));
491extern void mci_unlock_host __P((MCI *));
492
493 /*
494** Header structure.
495** This structure is used internally to store header items.
496*/
497
498struct 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
508typedef 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
516struct 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
523extern 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 */
553extern void addheader __P((char *, char *, int, HDR **));
554extern u_long chompheader __P((char *, int, HDR **, ENVELOPE *));
555extern void commaize __P((HDR *, char *, bool, MCI *, ENVELOPE *));
556extern HDR *copyheader __P((HDR *));
557extern void eatheader __P((ENVELOPE *, bool));
558extern char *hvalue __P((char *, HDR *));
559extern bool isheader __P((char *));
560extern void putfromline __P((MCI *, ENVELOPE *));
561extern void setupheaders __P((void));
562
563 /*
564** Performance monitoring
565*/
566
567#define TIMERS struct sm_timers
568
569TIMERS
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
587struct 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 */
677extern void clearenvelope __P((ENVELOPE *, bool));
678extern void dropenvelope __P((ENVELOPE *, bool));
679extern ENVELOPE *newenvelope __P((ENVELOPE *, ENVELOPE *));
680extern void printenvflags __P((ENVELOPE *));
681extern void putbody __P((MCI *, ENVELOPE *, char *));
682extern 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
708struct 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
718struct 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
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 */
169typedef struct envelope ENVELOPE;
170typedef struct mailer MAILER;
171
172 /*
173** Address structure.
174** Addresses are stored internally in this structure.
175*/
176
177struct 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
202typedef 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
269extern ADDRESS NullAddress; /* a null (template) address [main.c] */
270
271/* functions */
272extern void cataddr __P((char **, char **, char *, int, int));
273extern char *crackaddr __P((char *));
274extern bool emptyaddr __P((ADDRESS *));
275extern ADDRESS *getctladdr __P((ADDRESS *));
276extern int include __P((char *, bool, ADDRESS *, ADDRESS **, int, ENVELOPE *));
277extern bool invalidaddr __P((char *, char *));
278extern ADDRESS *parseaddr __P((char *, ADDRESS *, int, int, char **, ENVELOPE *));
279extern char **prescan __P((char *, int, char[], int, char **, u_char *));
280extern void printaddr __P((ADDRESS *, bool));
281extern ADDRESS *recipient __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
282extern char *remotename __P((char *, MAILER *, int, int *, ENVELOPE *));
283extern int rewrite __P((char **, int, int, ENVELOPE *));
284extern bool sameaddr __P((ADDRESS *, ADDRESS *));
285extern int sendtolist __P((char *, ADDRESS *, ADDRESS **, int, ENVELOPE *));
286extern int removefromlist __P((char *, ADDRESS **, ENVELOPE *));
287extern 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
301struct 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 */
391extern void initerrmailers __P((void));
392extern 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
401MCI
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 */
478extern void mci_cache __P((MCI *));
479extern void mci_dump __P((MCI *, bool));
480extern void mci_dump_all __P((bool));
481extern void mci_flush __P((bool, MCI *));
482extern MCI *mci_get __P((char *, MAILER *));
483extern int mci_lock_host __P((MCI *));
484extern bool mci_match __P((char *, MAILER *));
485extern int mci_print_persistent __P((char *, char *));
486extern int mci_purge_persistent __P((char *, char *));
487extern MCI **mci_scan __P((MCI *));
488extern void mci_setstat __P((MCI *, int, char *, char *));
489extern void mci_store_persistent __P((MCI *));
490extern int mci_traverse_persistent __P((int (*)(), char *));
491extern void mci_unlock_host __P((MCI *));
492
493 /*
494** Header structure.
495** This structure is used internally to store header items.
496*/
497
498struct 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
508typedef 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
516struct 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
523extern 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 */
553extern void addheader __P((char *, char *, int, HDR **));
554extern u_long chompheader __P((char *, int, HDR **, ENVELOPE *));
555extern void commaize __P((HDR *, char *, bool, MCI *, ENVELOPE *));
556extern HDR *copyheader __P((HDR *));
557extern void eatheader __P((ENVELOPE *, bool));
558extern char *hvalue __P((char *, HDR *));
559extern bool isheader __P((char *));
560extern void putfromline __P((MCI *, ENVELOPE *));
561extern void setupheaders __P((void));
562
563 /*
564** Performance monitoring
565*/
566
567#define TIMERS struct sm_timers
568
569TIMERS
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
587struct 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 */
677extern void clearenvelope __P((ENVELOPE *, bool));
678extern void dropenvelope __P((ENVELOPE *, bool));
679extern ENVELOPE *newenvelope __P((ENVELOPE *, ENVELOPE *));
680extern void printenvflags __P((ENVELOPE *));
681extern void putbody __P((MCI *, ENVELOPE *, char *));
682extern 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
708struct 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
718struct 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
768/* external <==> internal mapping table */
769struct metamac
770{
771 char metaname; /* external code (after $) */
772 u_char metaval; /* internal code (as above) */
773};
774
775/* values for macros with external names only */
776#define MID_OPMODE 0202 /* operation mode */
777
778/* functions */
779extern void define __P((int, char *, ENVELOPE *));
780extern void expand __P((char *, char *, size_t, ENVELOPE *));
781extern int macid __P((char *, char **));
782extern char *macname __P((int));
783extern char *macvalue __P((int, ENVELOPE *));
784extern int rscheck __P((char *, char *, char *, ENVELOPE *, bool, bool, int, char *));
785extern void setclass __P((int, char *));
786extern int strtorwset __P((char *, char **, int));
787extern void translate_dollars __P((char *));
788extern bool wordinclass __P((char *, int));
789
790 /*
791** Name canonification short circuit.
792**
793** If the name server for a host is down, the process of trying to
794** canonify the name can hang. This is similar to (but alas, not
795** identical to) looking up the name for delivery. This stab type
796** caches the result of the name server lookup so we don't hang
797** multiple times.
798*/
799
800#define NAMECANON struct _namecanon
801
802NAMECANON
803{
804 short nc_errno; /* cached errno */
805 short nc_herrno; /* cached h_errno */
806 short nc_stat; /* cached exit status code */
807 short nc_flags; /* flag bits */
808 char *nc_cname; /* the canonical name */
809};
810
811/* values for nc_flags */
812#define NCF_VALID 0x0001 /* entry valid */
813
814/* functions */
815extern bool getcanonname __P((char *, int, bool));
816extern int getmxrr __P((char *, char **, u_short *, bool, int *));
817
818 /*
819** Mapping functions
820**
821** These allow arbitrary mappings in the config file. The idea
822** (albeit not the implementation) comes from IDA sendmail.
823*/
824
825#define MAPCLASS struct _mapclass
826#define MAP struct _map
827#define MAXMAPACTIONS 5 /* size of map_actions array */
828
829
830/*
831** An actual map.
832*/
833
834MAP
835{
836 MAPCLASS *map_class; /* the class of this map */
837 char *map_mname; /* name of this map */
838 long map_mflags; /* flags, see below */
839 char *map_file; /* the (nominal) filename */
840 ARBPTR_T map_db1; /* the open database ptr */
841 ARBPTR_T map_db2; /* an "extra" database pointer */
842 char *map_keycolnm; /* key column name */
843 char *map_valcolnm; /* value column name */
844 u_char map_keycolno; /* key column number */
845 u_char map_valcolno; /* value column number */
846 char map_coldelim; /* column delimiter */
847 char map_spacesub; /* spacesub */
848 char *map_app; /* to append to successful matches */
849 char *map_tapp; /* to append to "tempfail" matches */
850 char *map_domain; /* the (nominal) NIS domain */
851 char *map_rebuild; /* program to run to do auto-rebuild */
852 time_t map_mtime; /* last database modification time */
853 pid_t map_pid; /* PID of process which opened map */
854 int map_lockfd; /* auxiliary lock file descriptor */
855 short map_specificity; /* specificity of aliases */
856 MAP *map_stack[MAXMAPSTACK]; /* list for stacked maps */
857 short map_return[MAXMAPACTIONS]; /* return bitmaps for stacked maps */
858};
859
860
861/* bit values for map_mflags */
862#define MF_VALID 0x00000001 /* this entry is valid */
863#define MF_INCLNULL 0x00000002 /* include null byte in key */
864#define MF_OPTIONAL 0x00000004 /* don't complain if map not found */
865#define MF_NOFOLDCASE 0x00000008 /* don't fold case in keys */
866#define MF_MATCHONLY 0x00000010 /* don't use the map value */
867#define MF_OPEN 0x00000020 /* this entry is open */
868#define MF_WRITABLE 0x00000040 /* open for writing */
869#define MF_ALIAS 0x00000080 /* this is an alias file */
870#define MF_TRY0NULL 0x00000100 /* try with no null byte */
871#define MF_TRY1NULL 0x00000200 /* try with the null byte */
872#define MF_LOCKED 0x00000400 /* this map is currently locked */
873#define MF_ALIASWAIT 0x00000800 /* alias map in aliaswait state */
874#define MF_IMPL_HASH 0x00001000 /* implicit: underlying hash database */
875#define MF_IMPL_NDBM 0x00002000 /* implicit: underlying NDBM database */
876#define MF_UNSAFEDB 0x00004000 /* this map is world writable */
877#define MF_APPEND 0x00008000 /* append new entry on rebuild */
878#define MF_KEEPQUOTES 0x00010000 /* don't dequote key before lookup */
879#define MF_NODEFER 0x00020000 /* don't defer if map lookup fails */
880#define MF_REGEX_NOT 0x00040000 /* regular expression negation */
881#define MF_DEFER 0x00080000 /* don't lookup map in defer mode */
882#define MF_SINGLEMATCH 0x00100000 /* successful only if match one key */
883#define MF_NOREWRITE 0x00200000 /* don't rewrite result, return as-is */
884#define MF_CLOSING 0x00400000 /* map is being closed */
885
886#define DYNOPENMAP(map) if (!bitset(MF_OPEN, (map)->map_mflags)) \
887 { \
888 if (!openmap(map)) \
889 return NULL; \
890 }
891
892
893/* indices for map_actions */
894#define MA_NOTFOUND 0 /* member map returned "not found" */
895#define MA_UNAVAIL 1 /* member map is not available */
896#define MA_TRYAGAIN 2 /* member map returns temp failure */
897
898/*
899** The class of a map -- essentially the functions to call
900*/
901
902MAPCLASS
903{
904 char *map_cname; /* name of this map class */
905 char *map_ext; /* extension for database file */
906 short map_cflags; /* flag bits, see below */
907 bool (*map_parse)__P((MAP *, char *));
908 /* argument parsing function */
909 char *(*map_lookup)__P((MAP *, char *, char **, int *));
910 /* lookup function */
911 void (*map_store)__P((MAP *, char *, char *));
912 /* store function */
913 bool (*map_open)__P((MAP *, int));
914 /* open function */
915 void (*map_close)__P((MAP *));
916 /* close function */
917};
918
919/* bit values for map_cflags */
920#define MCF_ALIASOK 0x0001 /* can be used for aliases */
921#define MCF_ALIASONLY 0x0002 /* usable only for aliases */
922#define MCF_REBUILDABLE 0x0004 /* can rebuild alias files */
923#define MCF_OPTFILE 0x0008 /* file name is optional */
924
925/* functions */
926extern void closemaps __P((void));
927extern bool impl_map_open __P((MAP *, int));
928extern void initmaps __P((void));
929extern MAP *makemapentry __P((char *));
930extern void maplocaluser __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
931extern char *map_rewrite __P((MAP *, const char *, size_t, char **));
932#if NETINFO
933extern char *ni_propval __P((char *, char *, char *, char *, int));
934#endif /* NETINFO */
935extern bool openmap __P((MAP *));
936#if USERDB
937extern void _udbx_close __P((void));
938extern int udbexpand __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
939extern char *udbsender __P((char *));
940#endif /* USERDB */
941 /*
942** LDAP related items
943*/
944#ifdef LDAPMAP
945struct ldapmap_struct
946{
947 /* needed for ldap_open or ldap_init */
948 char *ldap_host;
949 int ldap_port;
950
951 /* options set in ld struct before ldap_bind_s */
952 int ldap_deref;
953 time_t ldap_timelimit;
954 int ldap_sizelimit;
955 int ldap_options;
956
957 /* args for ldap_bind_s */
958 LDAP *ldap_ld;
959 char *ldap_binddn;
960 char *ldap_secret;
961 int ldap_method;
962
963 /* args for ldap_search */
964 char *ldap_base;
965 int ldap_scope;
966 char *ldap_filter;
967 char *ldap_attr[LDAPMAP_MAX_ATTR + 1];
968 bool ldap_attrsonly;
969
970 /* args for ldap_result */
971 struct timeval ldap_timeout;
972 LDAPMessage *ldap_res;
973
974 /* Linked list of maps sharing the same LDAP binding */
975 MAP *ldap_next;
976};
977
978typedef struct ldapmap_struct LDAPMAP_STRUCT;
979
980/* struct defining LDAP Auth Methods */
981struct lamvalues
982{
983 char *lam_name; /* name of LDAP auth method */
984 int lam_code; /* numeric code */
985};
986
987/* struct defining LDAP Alias Dereferencing */
988struct ladvalues
989{
990 char *lad_name; /* name of LDAP alias dereferencing method */
991 int lad_code; /* numeric code */
992};
993
994/* struct defining LDAP Search Scope */
995struct lssvalues
996{
997 char *lss_name; /* name of LDAP search scope */
998 int lss_code; /* numeric code */
999};
1000
1001/* functions */
1002extern bool ldapmap_parseargs __P((MAP *, char *));
1003extern void ldapmap_set_defaults __P((char *));
1004#endif /* LDAPMAP */
1005
1006 /*
1007** PH related items
1008*/
1009
1010#ifdef PH_MAP
1011struct ph_map_struct
1012{
1013 char *ph_servers; /* list of ph servers */
1014 char *ph_field_list; /* list of fields to search for match */
1015 FILE *ph_to_server;
1016 FILE *ph_from_server;
1017 int ph_sockfd;
1018 time_t ph_timeout;
1019};
1020typedef struct ph_map_struct PH_MAP_STRUCT;
1021
1022# define DEFAULT_PH_MAP_FIELDS "alias callsign name spacedname"
1023#endif /* PH_MAP */
1024 /*
1025** Process List (proclist)
1026*/
1027
1028struct procs
1029{
1030 pid_t proc_pid;
1031 char *proc_task;
1032 int proc_type;
1033};
1034
1035#define NO_PID ((pid_t) 0)
1036#ifndef PROC_LIST_SEG
1037# define PROC_LIST_SEG 32 /* number of pids to alloc at a time */
1038#endif /* ! PROC_LIST_SEG */
1039
1040/* process types */
1041#define PROC_NONE 0
1042#define PROC_DAEMON 1
1043#define PROC_DAEMON_CHILD 2
1044#define PROC_QUEUE 3
1045#define PROC_QUEUE_CHILD 3
1046#define PROC_CONTROL 4
1047#define PROC_CONTROL_CHILD 5
1048
1049/* functions */
1050extern void proc_list_add __P((pid_t, char *, int));
1051extern void proc_list_clear __P((void));
1052extern void proc_list_display __P((FILE *));
1053extern int proc_list_drop __P((pid_t));
1054extern void proc_list_probe __P((void));
1055extern void proc_list_set __P((pid_t, char *));
1056
1057 /*
1058** Symbol table definitions
1059*/
1060
1061struct symtab
1062{
1063 char *s_name; /* name to be entered */
1064 short s_type; /* general type (see below) */
1065 short s_len; /* length of this entry */
1066 struct symtab *s_next; /* pointer to next in chain */
1067 union
1068 {
1069 BITMAP256 sv_class; /* bit-map of word classes */
1070 ADDRESS *sv_addr; /* pointer to address header */
1071 MAILER *sv_mailer; /* pointer to mailer */
1072 char *sv_alias; /* alias */
1073 MAPCLASS sv_mapclass; /* mapping function class */
1074 MAP sv_map; /* mapping function */
1075 char *sv_hostsig; /* host signature */
1076 MCI sv_mci; /* mailer connection info */
1077 NAMECANON sv_namecanon; /* canonical name cache */
1078 int sv_macro; /* macro name => id mapping */
1079 int sv_ruleset; /* ruleset index */
1080 struct hdrinfo sv_header; /* header metainfo */
1081 char *sv_service[MAXMAPSTACK]; /* service switch */
1082#ifdef LDAPMAP
1083 MAP *sv_lmap; /* Maps for LDAP connection */
1084#endif /* LDAPMAP */
1085#if _FFR_MILTER
1086 struct milter *sv_milter; /* milter filter name */
1087#endif /* _FFR_MILTER */
1088 } s_value;
1089};
1090
1091typedef struct symtab STAB;
1092
1093/* symbol types */
1094#define ST_UNDEF 0 /* undefined type */
1095#define ST_CLASS 1 /* class map */
1096#define ST_ADDRESS 2 /* an address in parsed format */
1097#define ST_MAILER 3 /* a mailer header */
1098#define ST_ALIAS 4 /* an alias */
1099#define ST_MAPCLASS 5 /* mapping function class */
1100#define ST_MAP 6 /* mapping function */
1101#define ST_HOSTSIG 7 /* host signature */
1102#define ST_NAMECANON 8 /* cached canonical name */
1103#define ST_MACRO 9 /* macro name to id mapping */
1104#define ST_RULESET 10 /* ruleset index */
1105#define ST_SERVICE 11 /* service switch entry */
1106#define ST_HEADER 12 /* special header flags */
1107#ifdef LDAPMAP
1108# define ST_LMAP 13 /* List head of maps for LDAP connection */
1109#endif /* LDAPMAP */
1110#if _FFR_MILTER
1111# define ST_MILTER 14 /* milter filter */
1112#endif /* _FFR_MILTER */
1113#define ST_MCI 16 /* mailer connection info (offset) */
1114
1115#define s_class s_value.sv_class
1116#define s_address s_value.sv_addr
1117#define s_mailer s_value.sv_mailer
1118#define s_alias s_value.sv_alias
1119#define s_mci s_value.sv_mci
1120#define s_mapclass s_value.sv_mapclass
1121#define s_hostsig s_value.sv_hostsig
1122#define s_map s_value.sv_map
1123#define s_namecanon s_value.sv_namecanon
1124#define s_macro s_value.sv_macro
1125#define s_ruleset s_value.sv_ruleset
1126#define s_service s_value.sv_service
1127#define s_header s_value.sv_header
1128#ifdef LDAPMAP
1129# define s_lmap s_value.sv_lmap
1130#endif /* LDAPMAP */
1131#if _FFR_MILTER
1132# define s_milter s_value.sv_milter
1133#endif /* _FFR_MILTER */
1134
1135/* opcodes to stab */
1136#define ST_FIND 0 /* find entry */
1137#define ST_ENTER 1 /* enter if not there */
1138
1139/* functions */
1140extern STAB *stab __P((char *, int, int));
1141extern void stabapply __P((void (*)(STAB *, int), int));
1142
1143 /*
1144** STRUCT EVENT -- event queue.
1145**
1146** Maintained in sorted order.
1147**
1148** We store the pid of the process that set this event to insure
1149** that when we fork we will not take events intended for the parent.
1150*/
1151
1152struct event
1153{
1154 time_t ev_time; /* time of the function call */
1155 void (*ev_func)__P((int));
1156 /* function to call */
1157 int ev_arg; /* argument to ev_func */
1158 pid_t ev_pid; /* pid that set this event */
1159 struct event *ev_link; /* link to next item */
1160};
1161
1162typedef struct event EVENT;
1163
1164/* functions */
1165extern void clrevent __P((EVENT *));
1166extern void clear_events __P((void));
1167extern EVENT *setevent __P((time_t, void(*)(), int));
1168extern EVENT *sigsafe_setevent __P((time_t, void(*)(), int));
1169
1170 /*
1171** Operation, send, error, and MIME modes
1172**
1173** The operation mode describes the basic operation of sendmail.
1174** This can be set from the command line, and is "send mail" by
1175** default.
1176**
1177** The send mode tells how to send mail. It can be set in the
1178** configuration file. It's setting determines how quickly the
1179** mail will be delivered versus the load on your system. If the
1180** -v (verbose) flag is given, it will be forced to SM_DELIVER
1181** mode.
1182**
1183** The error mode tells how to return errors.
1184*/
1185
1186#define MD_DELIVER 'm' /* be a mail sender */
1187#define MD_SMTP 's' /* run SMTP on standard input */
1188#define MD_ARPAFTP 'a' /* obsolete ARPANET mode (Grey Book) */
1189#define MD_DAEMON 'd' /* run as a daemon */
1190#define MD_FGDAEMON 'D' /* run daemon in foreground */
1191#define MD_VERIFY 'v' /* verify: don't collect or deliver */
1192#define MD_TEST 't' /* test mode: resolve addrs only */
1193#define MD_INITALIAS 'i' /* initialize alias database */
1194#define MD_PRINT 'p' /* print the queue */
1195#define MD_FREEZE 'z' /* freeze the configuration file */
1196#define MD_HOSTSTAT 'h' /* print persistent host stat info */
1197#define MD_PURGESTAT 'H' /* purge persistent host stat info */
1198#define MD_QUEUERUN 'q' /* queue run */
1199
1200/* values for e_sendmode -- send modes */
1201#define SM_DELIVER 'i' /* interactive delivery */
1202#define SM_FORK 'b' /* deliver in background */
1203#define SM_QUEUE 'q' /* queue, don't deliver */
1204#define SM_DEFER 'd' /* defer map lookups as well as queue */
1205#define SM_VERIFY 'v' /* verify only (used internally) */
1206
1207
1208/* used only as a parameter to sendall */
1209#define SM_DEFAULT '\0' /* unspecified, use SendMode */
1210
1211/* functions */
1212extern void set_delivery_mode __P((int, ENVELOPE *));
1213
1214/* values for e_errormode -- error handling modes */
1215#define EM_PRINT 'p' /* print errors */
1216#define EM_MAIL 'm' /* mail back errors */
1217#define EM_WRITE 'w' /* write back errors */
1218#define EM_BERKNET 'e' /* special berknet processing */
1219#define EM_QUIET 'q' /* don't print messages (stat only) */
1220
1221
1222/* bit values for MimeMode */
1223#define MM_CVTMIME 0x0001 /* convert 8 to 7 bit MIME */
1224#define MM_PASS8BIT 0x0002 /* just send 8 bit data blind */
1225#define MM_MIME8BIT 0x0004 /* convert 8-bit data to MIME */
1226
1227
1228/* how to handle messages without any recipient addresses */
1229#define NRA_NO_ACTION 0 /* just leave it as is */
1230#define NRA_ADD_TO 1 /* add To: header */
1231#define NRA_ADD_APPARENTLY_TO 2 /* add Apparently-To: header */
1232#define NRA_ADD_BCC 3 /* add empty Bcc: header */
1233#define NRA_ADD_TO_UNDISCLOSED 4 /* add To: undisclosed:; header */
1234
1235
1236/* flags to putxline */
1237#define PXLF_NOTHINGSPECIAL 0 /* no special mapping */
1238#define PXLF_MAPFROM 0x0001 /* map From_ to >From_ */
1239#define PXLF_STRIP8BIT 0x0002 /* strip 8th bit */
1240#define PXLF_HEADER 0x0004 /* map newlines in headers */
1241
1242/*
1243** Privacy flags
1244** These are bit values for the PrivacyFlags word.
1245*/
1246
1247#define PRIV_PUBLIC 0 /* what have I got to hide? */
1248#define PRIV_NEEDMAILHELO 0x0001 /* insist on HELO for MAIL, at least */
1249#define PRIV_NEEDEXPNHELO 0x0002 /* insist on HELO for EXPN */
1250#define PRIV_NEEDVRFYHELO 0x0004 /* insist on HELO for VRFY */
1251#define PRIV_NOEXPN 0x0008 /* disallow EXPN command entirely */
1252#define PRIV_NOVRFY 0x0010 /* disallow VRFY command entirely */
1253#define PRIV_AUTHWARNINGS 0x0020 /* flag possible authorization probs */
1254#define PRIV_NORECEIPTS 0x0040 /* disallow return receipts */
1255#define PRIV_NOVERB 0x0100 /* disallow VERB command entirely */
1256#define PRIV_RESTRICTMAILQ 0x1000 /* restrict mailq command */
1257#define PRIV_RESTRICTQRUN 0x2000 /* restrict queue run */
1258#define PRIV_NOETRN 0x4000 /* disallow ETRN command entirely */
1259#define PRIV_NOBODYRETN 0x8000 /* do not return bodies on bounces */
1260
1261/* don't give no info, anyway, anyhow */
1262#define PRIV_GOAWAY (0x0fff & ~PRIV_NORECEIPTS)
1263
1264/* struct defining such things */
1265struct prival
1266{
1267 char *pv_name; /* name of privacy flag */
1268 u_short pv_flag; /* numeric level */
1269};
1270
1271
1272/*
1273** Flags passed to remotename, parseaddr, allocaddr, and buildaddr.
1274*/
1275
1276#define RF_SENDERADDR 0x001 /* this is a sender address */
1277#define RF_HEADERADDR 0x002 /* this is a header address */
1278#define RF_CANONICAL 0x004 /* strip comment information */
1279#define RF_ADDDOMAIN 0x008 /* OK to do domain extension */
1280#define RF_COPYPARSE 0x010 /* copy parsed user & host */
1281#define RF_COPYPADDR 0x020 /* copy print address */
1282#define RF_COPYALL (RF_COPYPARSE|RF_COPYPADDR)
1283#define RF_COPYNONE 0
1284
1285
1286/*
1287** Flags passed to mime8to7 and putheader.
1288*/
1289
1290#define M87F_OUTER 0 /* outer context */
1291#define M87F_NO8BIT 0x0001 /* can't have 8-bit in this section */
1292#define M87F_DIGEST 0x0002 /* processing multipart/digest */
1293#define M87F_NO8TO7 0x0004 /* don't do 8->7 bit conversions */
1294
1295/* functions */
1296extern void mime7to8 __P((MCI *, HDR *, ENVELOPE *));
1297extern int mime8to7 __P((MCI *, HDR *, ENVELOPE *, char **, int));
1298
1299/*
1300** Flags passed to returntosender.
1301*/
1302
1303#define RTSF_NO_BODY 0 /* send headers only */
1304#define RTSF_SEND_BODY 0x0001 /* include body of message in return */
1305#define RTSF_PM_BOUNCE 0x0002 /* this is a postmaster bounce */
1306
1307/* functions */
1308extern int returntosender __P((char *, ADDRESS *, int, ENVELOPE *));
1309
1310/*
1311** Regular UNIX sockaddrs are too small to handle ISO addresses, so
1312** we are forced to declare a supertype here.
1313*/
1314
1315#if NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25
1316union bigsockaddr
1317{
1318 struct sockaddr sa; /* general version */
1319# if NETUNIX
1320 struct sockaddr_un sunix; /* UNIX family */
1321# endif /* NETUNIX */
1322# if NETINET
1323 struct sockaddr_in sin; /* INET family */
1324# endif /* NETINET */
1325# if NETINET6
1326 struct sockaddr_in6 sin6; /* INET/IPv6 */
1327# endif /* NETINET6 */
1328# if NETISO
1329 struct sockaddr_iso siso; /* ISO family */
1330# endif /* NETISO */
1331# if NETNS
1332 struct sockaddr_ns sns; /* XNS family */
1333# endif /* NETNS */
1334# if NETX25
1335 struct sockaddr_x25 sx25; /* X.25 family */
1336# endif /* NETX25 */
1337};
1338
1339# define SOCKADDR union bigsockaddr
1340
1341/* functions */
1342extern char *anynet_ntoa __P((SOCKADDR *));
1343# if NETINET6
1344extern char *anynet_ntop __P((struct in6_addr *, char *, size_t));
1345# endif /* NETINET6 */
1346extern char *hostnamebyanyaddr __P((SOCKADDR *));
1347# if DAEMON
1348extern char *validate_connection __P((SOCKADDR *, char *, ENVELOPE *));
1349# endif /* DAEMON */
1350
1351#endif /* NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25 */
1352
1353#if _FFR_MILTER
1354 /*
1355** Mail Filters (milter)
1356*/
1357
1358#include <libmilter/milter.h>
1359
1360#define SMFTO_WRITE 0 /* Timeout for sending information */
1361#define SMFTO_READ 1 /* Timeout waiting for a response */
1362#define SMFTO_EOM 2 /* Timeout for ACK/NAK to EOM */
1363#define SMFTO_CONNECT 3 /* Timeout for connect() */
1364
1365#define SMFTO_NUM_TO 4 /* Total number of timeouts */
1366
1367struct milter
1368{
1369 char *mf_name; /* filter name */
1370 BITMAP256 mf_flags; /* MTA flags */
1371 u_long mf_fvers; /* filter version */
1372 u_long mf_fflags; /* filter flags */
1373 u_long mf_pflags; /* protocol flags */
1374 char *mf_conn; /* connection info */
1375 int mf_sock; /* connected socket */
1376 char mf_state; /* state of filter */
1377 time_t mf_timeout[SMFTO_NUM_TO]; /* timeouts */
1378};
1379
1380/* MTA flags */
1381# define SMF_REJECT 'R' /* Reject connection on filter fail */
1382# define SMF_TEMPFAIL 'T' /* tempfail connection on failure */
1383
1384/* states */
1385# define SMFS_CLOSED 'C' /* closed for all further actions */
1386# define SMFS_OPEN 'O' /* connected to remote milter filter */
1387# define SMFS_INMSG 'M' /* currently servicing a message */
1388# define SMFS_DONE 'D' /* done with current message */
1389# define SMFS_CLOSABLE 'Q' /* done with current connection */
1390# define SMFS_ERROR 'E' /* error state */
1391# define SMFS_READY 'R' /* ready for action */
1392
1393/* 32-bit type used by milter */
1394typedef SM_INT32 mi_int32;
1395
1396EXTERN struct milter *InputFilters[MAXFILTERS];
1397EXTERN char *InputFilterList;
1398#endif /* _FFR_MILTER */
1399
1400/*
1401** Vendor codes
1402**
1403** Vendors can customize sendmail to add special behaviour,
1404** generally for back compatibility. Ideally, this should
1405** be set up in the .cf file using the "V" command. However,
1406** it's quite reasonable for some vendors to want the default
1407** be their old version; this can be set using
1408** -DVENDOR_DEFAULT=VENDOR_xxx
1409** in the Makefile.
1410**
1411** Vendors should apply to sendmail@sendmail.org for
1412** unique vendor codes.
1413*/
1414
1415#define VENDOR_BERKELEY 1 /* Berkeley-native configuration file */
1416#define VENDOR_SUN 2 /* Sun-native configuration file */
1417#define VENDOR_HP 3 /* Hewlett-Packard specific config syntax */
1418#define VENDOR_IBM 4 /* IBM specific config syntax */
1419#define VENDOR_SENDMAIL 5 /* Sendmail, Inc. specific config syntax */
1420
1421/* prototypes for vendor-specific hook routines */
1422extern void vendor_daemon_setup __P((ENVELOPE *));
1423extern void vendor_set_uid __P((UID_T));
1424
1425
1426/*
1427** Terminal escape codes.
1428**
1429** To make debugging output clearer.
1430*/
1431
1432struct termescape
1433{
1434 char *te_rv_on; /* turn reverse-video on */
1435 char *te_rv_off; /* turn reverse-video off */
1436};
1437
1438 /*
1439** Additional definitions
1440*/
1441
1442/* d_flags, see daemon.c */
1443/* general rule: lower case: required, upper case: No */
1444#define D_AUTHREQ 'a' /* authentication required */
1445#define D_BINDIF 'b' /* use if_addr for outgoing connection */
1446#define D_CANONREQ 'c' /* canonification required (cf) */
1447#define D_IFNHELO 'h' /* use if name for HELO */
1448#define D_FQMAIL 'f' /* fq sender address required (cf) */
1449#if _FFR_TLS_CLT1
1450#define D_CLTNOTLS 'S' /* don't use STARTTLS in client */
1451#endif /* _FFR_TLS_CLT1 */
1452#define D_FQRCPT 'r' /* fq recipient address required (cf) */
1453#define D_UNQUALOK 'u' /* unqualified address is ok (cf) */
1454#define D_NOCANON 'C' /* no canonification (cf) */
1455#define D_NOETRN 'E' /* no ETRN (MSA) */
1456#define D_ETRNONLY ((char)0x01) /* allow only ETRN (disk low) */
1457
1458/* Flags for submitmode */
1459#define SUBMIT_UNKNOWN 0x0000 /* unknown agent type */
1460#define SUBMIT_MTA 0x0001 /* act like a message transfer agent */
1461#define SUBMIT_MSA 0x0002 /* act like a message submission agent */
1462
1463#if SASL
1464 /*
1465** SASL
1466*/
1467
1468/* authenticated? */
1469# define SASL_NOT_AUTH 0 /* not authenticated */
1470# define SASL_PROC_AUTH 1 /* in process of authenticating */
1471# define SASL_IS_AUTH 2 /* authenticated */
1472
1473/* SASL options */
1474# define SASL_AUTH_AUTH 0x1000 /* use auth= only if authenticated */
1475# if _FFR_SASL_OPTS
1476# define SASL_SEC_MASK 0x0fff /* mask for SASL_SEC_* values: sasl.h */
1477# if (SASL_SEC_NOPLAINTEXT & SASL_SEC_MASK) == 0 || \
1478 (SASL_SEC_NOACTIVE & SASL_SEC_MASK) == 0 || \
1479 (SASL_SEC_NODICTIONARY & SASL_SEC_MASK) == 0 || \
1480 (SASL_SEC_FORWARD_SECRECY & SASL_SEC_MASK) == 0 || \
1481 (SASL_SEC_NOANONYMOUS & SASL_SEC_MASK) == 0 || \
1482 (SASL_SEC_PASS_CREDENTIALS & SASL_SEC_MASK) == 0
1483ERROR: change SASL_SEC_MASK_ notify sendmail.org!
1484# endif
1485# endif /* _FFR_SASL_OPTS */
1486
1487# define MAXOUTLEN 1024 /* length of output buffer */
1488#endif /* SASL */
1489
1490#if STARTTLS
1491 /*
1492** TLS
1493*/
1494
1495/* what to do in the TLS initialization */
1496#define TLS_I_NONE 0x00000000 /* no requirements... */
1497#define TLS_I_CERT_EX 0x00000001 /* CERT must exist */
1498#define TLS_I_CERT_UNR 0x00000002 /* CERT must be g/o unreadable */
1499#define TLS_I_KEY_EX 0x00000004 /* KEY must exist */
1500#define TLS_I_KEY_UNR 0x00000008 /* KEY must be g/o unreadable */
1501#define TLS_I_CERTP_EX 0x00000010 /* CA CERT PATH must exist */
1502#define TLS_I_CERTP_UNR 0x00000020 /* CA CERT PATH must be g/o unreadable */
1503#define TLS_I_CERTF_EX 0x00000040 /* CA CERT FILE must exist */
1504#define TLS_I_CERTF_UNR 0x00000080 /* CA CERT FILE must be g/o unreadable */
1505#define TLS_I_RSA_TMP 0x00000100 /* RSA TMP must be generated */
1506#define TLS_I_USE_KEY 0x00000200 /* private key must usable */
1507#define TLS_I_USE_CERT 0x00000400 /* certificate must be usable */
1508#define TLS_I_VRFY_PATH 0x00000800 /* load verify path must succeed */
1509#define TLS_I_VRFY_LOC 0x00001000 /* load verify default must succeed */
1510#define TLS_I_CACHE 0x00002000 /* require cache */
1511#define TLS_I_TRY_DH 0x00004000 /* try DH certificate */
1512#define TLS_I_REQ_DH 0x00008000 /* require DH certificate */
1513#define TLS_I_DHPAR_EX 0x00010000 /* require DH parameters */
1514#define TLS_I_DHPAR_UNR 0x00020000 /* DH param. must be g/o unreadable */
1515#define TLS_I_DH512 0x00040000 /* generate 512bit DH param */
1516#define TLS_I_DH1024 0x00080000 /* generate 1024bit DH param */
1517#define TLS_I_DH2048 0x00100000 /* generate 2048bit DH param */
1518
1519/* server requirements */
1520#define TLS_I_SRV (TLS_I_CERT_EX | TLS_I_KEY_EX | TLS_I_KEY_UNR | \
1521 TLS_I_CERTP_EX | TLS_I_CERTF_EX | TLS_I_RSA_TMP | \
1522 TLS_I_USE_KEY | TLS_I_USE_CERT | TLS_I_VRFY_PATH | \
1523 TLS_I_VRFY_LOC | TLS_I_TRY_DH | \
1524 TLS_I_DH512)
1525
1526/* client requirements */
1527#define TLS_I_CLT (TLS_I_KEY_UNR)
1528
1529#define TLS_AUTH_OK 0
1530#define TLS_AUTH_NO 1
1531#define TLS_AUTH_FAIL (-1)
1532#endif /* STARTTLS */
1533
1534
1535 /*
1536** Queue related items
1537*/
1538
1539/* queue sort order */
1540#define QSO_BYPRIORITY 0 /* sort by message priority */
1541#define QSO_BYHOST 1 /* sort by first host name */
1542#define QSO_BYTIME 2 /* sort by submission time */
1543#define QSO_BYFILENAME 3 /* sort by file name only */
1544
1545#if _FFR_QUEUEDELAY
1546#define QD_LINEAR 0 /* linear (old) delay alg */
1547#define QD_EXP 1 /* exponential delay alg */
1548#endif /* _FFR_QUEUEDELAY */
1549
1550#define NOQDIR (-1) /* no queue directory (yet) */
1551
1552#define NOW ((time_t) (-1)) /* queue return: now */
1553
1554/* Queue Run Limitations */
1555struct queue_char
1556{
1557 char *queue_match; /* string to match */
1558 struct queue_char *queue_next;
1559};
1560
1561typedef struct queue_char QUEUE_CHAR;
1562
1563/* functions */
1564extern void assign_queueid __P((ENVELOPE *));
1565extern ADDRESS *copyqueue __P((ADDRESS *));
1566extern void initsys __P((ENVELOPE *));
1567extern void loseqfile __P((ENVELOPE *, char *));
1568extern void multiqueue_cache __P((void));
1569extern char *qid_printname __P((ENVELOPE *));
1570extern char *qid_printqueue __P((int));
1571extern char *queuename __P((ENVELOPE *, int));
1572extern void queueup __P((ENVELOPE *, bool));
1573extern bool runqueue __P((bool, bool));
1574extern void setnewqueue __P((ENVELOPE *));
1575extern bool shouldqueue __P((long, time_t));
1576extern void sync_queue_time __P((void));
1577
1578/*
1579** Timeouts
1580**
1581** Indicated values are the MINIMUM per RFC 1123 section 5.3.2.
1582*/
1583
1584EXTERN struct
1585{
1586 /* RFC 1123-specified timeouts [minimum value] */
1587 time_t to_initial; /* initial greeting timeout [5m] */
1588 time_t to_mail; /* MAIL command [5m] */
1589 time_t to_rcpt; /* RCPT command [5m] */
1590 time_t to_datainit; /* DATA initiation [2m] */
1591 time_t to_datablock; /* DATA block [3m] */
1592 time_t to_datafinal; /* DATA completion [10m] */
1593 time_t to_nextcommand; /* next command [5m] */
1594 /* following timeouts are not mentioned in RFC 1123 */
1595 time_t to_iconnect; /* initial connection timeout (first try) */
1596 time_t to_connect; /* initial connection timeout (later tries) */
1597 time_t to_rset; /* RSET command */
1598 time_t to_helo; /* HELO command */
1599 time_t to_quit; /* QUIT command */
1600 time_t to_miscshort; /* misc short commands (NOOP, VERB, etc) */
1601 time_t to_ident; /* IDENT protocol requests */
1602 time_t to_fileopen; /* opening :include: and .forward files */
1603 time_t to_control; /* process a control socket command */
1604 /* following are per message */
1605 time_t to_q_return[MAXTOCLASS]; /* queue return timeouts */
1606 time_t to_q_warning[MAXTOCLASS]; /* queue warning timeouts */
1607 time_t res_retrans[MAXRESTOTYPES]; /* resolver retransmit */
1608 int res_retry[MAXRESTOTYPES]; /* resolver retry */
1609} TimeOuts;
1610
1611/* timeout classes for return and warning timeouts */
1612#define TOC_NORMAL 0 /* normal delivery */
1613#define TOC_URGENT 1 /* urgent delivery */
1614#define TOC_NONURGENT 2 /* non-urgent delivery */
1615
1616/* resolver timeout specifiers */
1617#define RES_TO_FIRST 0 /* first attempt */
1618#define RES_TO_NORMAL 1 /* subsequent attempts */
1619#define RES_TO_DEFAULT 2 /* default value */
1620
1621/* functions */
1622extern void inittimeouts __P((char *, bool));
1623
1624/*
1625** Trace information
1626*/
1627
1628/* macros for debugging flags */
1629#define tTd(flag, level) (tTdvect[flag] >= (u_char)level)
1630#define tTdlevel(flag) (tTdvect[flag])
1631
1632/* variables */
1633extern u_char tTdvect[100]; /* trace vector */
1634 /*
1635** Critical signal sections
1636*/
1637
1638#define PEND_SIGHUP 0x0001
1639#define PEND_SIGINT 0x0002
1640#define PEND_SIGTERM 0x0004
1641#define PEND_SIGUSR1 0x0008
1642
1643#define ENTER_CRITICAL() InCriticalSection++
1644
1645#define LEAVE_CRITICAL() \
1646do \
1647{ \
1648 if (InCriticalSection > 0) \
1649 InCriticalSection--; \
1650} while (0)
1651
1652#define CHECK_CRITICAL(sig) \
1653do \
1654{ \
1655 if (InCriticalSection > 0 && (sig) != 0) \
1656 { \
1657 pend_signal((sig)); \
1658 return SIGFUNC_RETURN; \
1659 } \
1660} while (0)
1661
1662/* reset signal in case System V semantics */
1663#ifdef SYS5SIGNALS
1664# define FIX_SYSV_SIGNAL(sig, handler) \
1665{ \
1666 if ((sig) != 0) \
1667 (void) setsignal((sig), (handler)); \
1668}
1669#else /* SYS5SIGNALS */
1670# define FIX_SYSV_SIGNAL(sig, handler) { /* EMPTY */ }
1671#endif /* SYS5SIGNALS */
1672
1673/* variables */
1674EXTERN u_int volatile InCriticalSection; /* >0 if in a critical section */
1675EXTERN int volatile PendingSignal; /* pending signal to resend */
1676
1677/* functions */
1678extern void pend_signal __P((int));
1679
1680 /*
1681** Miscellaneous information.
1682*/
1683
1684/*
1685** The "no queue id" queue id for sm_syslog
1686*/
1687
1688#define NOQID "*~*"
1689
1690
1691/*
1692** Some in-line functions
1693*/
1694
1695/* set exit status */
1696#define setstat(s) { \
1697 if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \
1698 ExitStat = s; \
1699 }
1700
1701/* make a copy of a string */
1702#define newstr(s) strcpy(xalloc(strlen(s) + 1), s)
1703
1704#define STRUCTCOPY(s, d) d = s
1705 /*
1706** Global variables.
1707*/
1708
1709EXTERN bool AllowBogusHELO; /* allow syntax errors on HELO command */
1710#if !_FFR_REMOVE_AUTOREBUILD
1711EXTERN bool AutoRebuild; /* auto-rebuild the alias database as needed */
1712#endif /* !_FFR_REMOVE_AUTOREBUILD */
1713EXTERN bool CheckAliases; /* parse addresses during newaliases */
1714EXTERN bool ChownAlwaysSafe; /* treat chown(2) as safe */
1715EXTERN bool ColonOkInAddr; /* single colon legal in address */
1716EXTERN bool ConfigFileRead; /* configuration file has been read */
1717EXTERN bool volatile DataProgress; /* have we sent anything since last check */
1718EXTERN bool DisConnected; /* running with OutChannel redirected to xf */
1719EXTERN bool volatile DoQueueRun; /* non-interrupt time queue run needed */
1720EXTERN bool DontExpandCnames; /* do not $[...$] expand CNAMEs */
1721EXTERN bool DontInitGroups; /* avoid initgroups() because of NIS cost */
1722EXTERN bool DontLockReadFiles; /* don't read lock support files */
1723EXTERN bool DontProbeInterfaces; /* don't probe interfaces for names */
1724EXTERN bool DontPruneRoutes; /* don't prune source routes */
1725EXTERN bool ForkQueueRuns; /* fork for each job when running the queue */
1726EXTERN bool FromFlag; /* if set, "From" person is explicit */
1727EXTERN bool GrabTo; /* if set, get recipients from msg */
1728EXTERN bool HasEightBits; /* has at least one eight bit input byte */
1729EXTERN bool HasWildcardMX; /* don't use MX records when canonifying */
1730EXTERN bool HoldErrs; /* only output errors to transcript */
1731EXTERN bool IgnoreHostStatus; /* ignore long term host status files */
1732EXTERN bool IgnrDot; /* don't let dot end messages */
1733EXTERN bool InChild; /* true if running in an SMTP subprocess */
1734EXTERN bool LogUsrErrs; /* syslog user errors (e.g., SMTP RCPT cmd) */
1735EXTERN bool MapOpenErr; /* error opening a non-optional map */
1736EXTERN bool MatchGecos; /* look for user names in gecos field */
1737EXTERN bool MeToo; /* send to the sender also */
1738EXTERN bool NoAlias; /* suppress aliasing */
1739EXTERN bool NoConnect; /* don't connect to non-local mailers */
1740EXTERN bool OnlyOneError; /* .... or only want to give one SMTP reply */
1741EXTERN bool QuickAbort; /* .... but only if we want a quick abort */
1742EXTERN bool RrtImpliesDsn; /* turn Return-Receipt-To: into DSN */
1743EXTERN bool SaveFrom; /* save leading "From" lines */
1744EXTERN bool SendMIMEErrors; /* send error messages in MIME format */
1745EXTERN bool SevenBitInput; /* force 7-bit data on input */
1746EXTERN bool SingleLineFromHeader; /* force From: header to be one line */
1747EXTERN bool SingleThreadDelivery; /* single thread hosts on delivery */
1748EXTERN bool volatile StopRequest; /* stop sending output */
1749EXTERN bool SuperSafe; /* be extra careful, even if expensive */
1750EXTERN bool SuprErrs; /* set if we are suppressing errors */
1751EXTERN bool TryNullMXList; /* if we are the best MX, try host directly */
1752#if _FFR_WORKAROUND_BROKEN_NAMESERVERS
1753EXTERN bool WorkAroundBrokenAAAA; /* some nameservers return SERVFAIL on AAAA queries */
1754#endif /* _FFR_WORKAROUND_BROKEN_NAMESERVERS */
1755EXTERN bool UseErrorsTo; /* use Errors-To: header (back compat) */
1756EXTERN bool UseHesiod; /* using Hesiod -- interpret Hesiod errors */
1757EXTERN bool UseNameServer; /* using DNS -- interpret h_errno & MX RRs */
1758EXTERN char InetMode; /* default network for daemon mode */
1759EXTERN char OpMode; /* operation mode, see below */
1760EXTERN char SpaceSub; /* substitution for <lwsp> */
1761EXTERN int CheckpointInterval; /* queue file checkpoint interval */
1762EXTERN int ConfigLevel; /* config file level */
1763EXTERN int ConnRateThrottle; /* throttle for SMTP connection rate */
1764EXTERN int volatile CurChildren; /* current number of daemonic children */
1765EXTERN int CurrentLA; /* current load average */
1766EXTERN int DefaultNotify; /* default DSN notification flags */
1767EXTERN int Errors; /* set if errors (local to single pass) */
1768EXTERN int ExitStat; /* exit status code */
1769EXTERN int FileMode; /* mode on files */
1770EXTERN int LineNumber; /* line number in current input */
1771EXTERN int LogLevel; /* level of logging to perform */
1772EXTERN int MaxAliasRecursion; /* maximum depth of alias recursion */
1773EXTERN int MaxChildren; /* maximum number of daemonic children */
1774EXTERN int MaxForwardEntries; /* maximum number of forward entries */
1775EXTERN int MaxHeadersLength; /* max length of headers */
1776EXTERN int MaxHopCount; /* max # of hops until bounce */
1777EXTERN int MaxMacroRecursion; /* maximum depth of macro recursion */
1778EXTERN int MaxMciCache; /* maximum entries in MCI cache */
1779EXTERN int MaxMimeFieldLength; /* maximum MIME field length */
1780EXTERN int MaxMimeHeaderLength; /* maximum MIME header length */
1781
1782
1783EXTERN int MaxQueueRun; /* maximum number of jobs in one queue run */
1784EXTERN int MaxRcptPerMsg; /* max recipients per SMTP message */
1785EXTERN int MaxRuleRecursion; /* maximum depth of ruleset recursion */
1786EXTERN int MimeMode; /* MIME processing mode */
1787EXTERN int NoRecipientAction;
1788EXTERN int NumPriorities; /* pointer into Priorities */
1789EXTERN u_short PrivacyFlags; /* privacy flags */
1790#if _FFR_QUEUE_FILE_MODE
1791EXTERN int QueueFileMode; /* mode on qf/tf/df files */
1792#endif /* _FFR_QUEUE_FILE_MODE */
1793EXTERN int QueueLA; /* load average starting forced queueing */
1794EXTERN int QueueSortOrder; /* queue sorting order algorithm */
1795EXTERN int RefuseLA; /* load average refusing connections are */
1796EXTERN int VendorCode; /* vendor-specific operation enhancements */
1797EXTERN int Verbose; /* set if blow-by-blow desired */
1798EXTERN gid_t DefGid; /* default gid to run as */
1799EXTERN gid_t RealGid; /* real gid of caller */
1800EXTERN gid_t RunAsGid; /* GID to become for bulk of run */
1801EXTERN uid_t DefUid; /* default uid to run as */
1802EXTERN uid_t RealUid; /* real uid of caller */
1803EXTERN uid_t RunAsUid; /* UID to become for bulk of run */
1804EXTERN uid_t TrustedUid; /* uid of trusted user for files and startup */
1805EXTERN size_t DataFileBufferSize; /* size of buffer for in-core df */
1806EXTERN size_t XscriptFileBufferSize; /* size of buffer for in-core xf */
1807EXTERN time_t DialDelay; /* delay between dial-on-demand tries */
1808EXTERN time_t MciCacheTimeout; /* maximum idle time on connections */
1809EXTERN time_t MciInfoTimeout; /* how long 'til we retry down hosts */
1810EXTERN time_t MinQueueAge; /* min delivery interval */
1811EXTERN time_t QueueIntvl; /* intervals between running the queue */
1812EXTERN time_t SafeAlias; /* interval to wait until @:@ in alias file */
1813EXTERN time_t ServiceCacheMaxAge; /* refresh interval for cache */
1814EXTERN time_t ServiceCacheTime; /* time service switch was cached */
1815EXTERN MODE_T OldUmask; /* umask when sendmail starts up */
1816EXTERN long MaxMessageSize; /* advertised max size we will accept */
1817EXTERN long MinBlocksFree; /* min # of blocks free on queue fs */
1818EXTERN long QueueFactor; /* slope of queue function */
1819EXTERN long WkClassFact; /* multiplier for message class -> priority */
1820EXTERN long WkRecipFact; /* multiplier for # of recipients -> priority */
1821EXTERN long WkTimeFact; /* priority offset each time this job is run */
1822#if SASL
1823EXTERN char *AuthMechanisms; /* AUTH mechanisms */
1824EXTERN char *SASLInfo; /* file with AUTH info */
1825#endif /* SASL */
1826EXTERN int SASLOpts; /* options for SASL */
1827#if STARTTLS
1828EXTERN char *CACERTpath; /* path to CA certificates (dir. with hashes) */
1829EXTERN char *CACERTfile; /* file with CA certificate */
1830EXTERN char *SrvCERTfile; /* file with server certificate */
1831EXTERN char *Srvkeyfile; /* file with server private key */
1832EXTERN char *CltCERTfile; /* file with client certificate */
1833EXTERN char *Cltkeyfile; /* file with client private key */
1834EXTERN char *DHParams; /* file with DH parameters */
1835EXTERN char *RandFile; /* source of random data */
1836# if _FFR_TLS_1
1837EXTERN char *DHParams5; /* file with DH parameters (512) */
1838EXTERN char *CipherList; /* list of ciphers */
1839# endif /* _FFR_TLS_1 */
1840#endif /* STARTTLS */
1841EXTERN char *ConfFile; /* location of configuration file [conf.c] */
1842EXTERN char *ControlSocketName; /* control socket filename [control.c] */
1843EXTERN char *CurHostName; /* current host we are dealing with */
1844EXTERN char *DeadLetterDrop; /* path to dead letter office */
1845EXTERN char *DefUser; /* default user to run as (from DefUid) */
1846EXTERN char *DefaultCharSet; /* default character set for MIME */
1847EXTERN char *DoubleBounceAddr; /* where to send double bounces */
1848EXTERN char *ErrMsgFile; /* file to prepend to all error messages */
1849EXTERN char *FallBackMX; /* fall back MX host */
1850EXTERN char *FileName; /* name to print on error messages */
1851EXTERN char *ForwardPath; /* path to search for .forward files */
1852EXTERN char *HelpFile; /* location of SMTP help file */
1853EXTERN char *HostStatDir; /* location of host status information */
1854EXTERN char *HostsFile; /* path to /etc/hosts file */
1855EXTERN char *MustQuoteChars; /* quote these characters in phrases */
1856EXTERN char *MyHostName; /* name of this host for SMTP messages */
1857EXTERN char *OperatorChars; /* operators (old $o macro) */
1858EXTERN char *PidFile; /* location of proc id file [conf.c] */
1859EXTERN char *PostMasterCopy; /* address to get errs cc's */
1860EXTERN char *ProcTitlePrefix; /* process title prefix */
1861EXTERN char *QueueDir; /* location of queue directory */
1862#if _FFR_QUEUEDELAY
1863EXTERN int QueueAlg; /* algorithm for queue delays */
1864EXTERN time_t QueueInitDelay; /* initial queue delay */
1865EXTERN time_t QueueMaxDelay; /* maximum queue delay */
1866#endif /* _FFR_QUEUEDELAY */
1867EXTERN char *RealHostName; /* name of host we are talking to */
1868EXTERN char *RealUserName; /* real user name of caller */
1869EXTERN char *volatile RestartRequest;/* a sendmail restart has been requested */
1870EXTERN char *RunAsUserName; /* user to become for bulk of run */
1871EXTERN char *SafeFileEnv; /* chroot location for file delivery */
1872EXTERN char *ServiceSwitchFile; /* backup service switch */
1873EXTERN char *volatile ShutdownRequest;/* a sendmail shutdown has been requested */
1874EXTERN char *SmtpGreeting; /* SMTP greeting message (old $e macro) */
1875EXTERN char *SmtpPhase; /* current phase in SMTP processing */
1876EXTERN char SmtpError[MAXLINE]; /* save failure error messages */
1877EXTERN char *StatFile; /* location of statistics summary */
1878EXTERN char *TimeZoneSpec; /* override time zone specification */
1879EXTERN char *UdbSpec; /* user database source spec */
1880EXTERN char *UnixFromLine; /* UNIX From_ line (old $l macro) */
1881EXTERN char **ExternalEnviron; /* input environment */
1882 /* saved user environment */
1883EXTERN char **SaveArgv; /* argument vector for re-execing */
1884EXTERN BITMAP256 DontBlameSendmail; /* DontBlameSendmail bits */
1885#if SFIO
1886EXTERN Sfio_t *InChannel; /* input connection */
1887EXTERN Sfio_t *OutChannel; /* output connection */
1888#else /* SFIO */
1889EXTERN FILE *InChannel; /* input connection */
1890EXTERN FILE *OutChannel; /* output connection */
1891#endif /* SFIO */
1892EXTERN FILE *TrafficLogFile; /* file in which to log all traffic */
1893#ifdef HESIOD
1894EXTERN void *HesiodContext;
1895#endif /* HESIOD */
1896EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */
1897EXTERN MAILER *LocalMailer; /* ptr to local mailer */
1898EXTERN MAILER *ProgMailer; /* ptr to program mailer */
1899EXTERN MAILER *FileMailer; /* ptr to *file* mailer */
1900EXTERN MAILER *InclMailer; /* ptr to *include* mailer */
1901EXTERN QUEUE_CHAR *QueueLimitRecipient; /* limit queue run to rcpt */
1902EXTERN QUEUE_CHAR *QueueLimitSender; /* limit queue run to sender */
1903EXTERN QUEUE_CHAR *QueueLimitId; /* limit queue run to id */
1904EXTERN MAILER *Mailer[MAXMAILERS + 1];
1905EXTERN struct rewrite *RewriteRules[MAXRWSETS];
1906EXTERN char *RuleSetNames[MAXRWSETS]; /* ruleset number to name */
1907EXTERN char *UserEnviron[MAXUSERENVIRON + 1];
1908EXTERN struct priority Priorities[MAXPRIORITIES];
1909EXTERN struct termescape TermEscape; /* terminal escape codes */
1910EXTERN SOCKADDR ConnectOnlyTo; /* override connection address (for testing) */
1911EXTERN SOCKADDR RealHostAddr; /* address of host we are talking to */
1912EXTERN jmp_buf TopFrame; /* branch-to-top-of-loop-on-error frame */
1913EXTERN TIMERS Timers;
1914
1915/*
1916** Declarations of useful functions
1917*/
1918
1919#if SASL
1920extern char *intersect __P((char *, char *));
1921extern char *iteminlist __P((char *, char *, char *));
1922extern int proxy_policy __P((void *, const char *, const char *, const char **, const char **));
1923# if SASL > 10515
1924extern int safesaslfile __P((void *, char *, int));
1925# else /* SASL > 10515 */
1926extern int safesaslfile __P((void *, char *));
1927# endif /* SASL > 10515 */
1928extern int sasl_decode64 __P((const char *, unsigned, char *, unsigned *));
1929extern int sasl_encode64 __P((const char *, unsigned, char *, unsigned, unsigned *));
1930#endif /* SASL */
1931
1932#if STARTTLS
1933extern void apps_ssl_info_cb __P((SSL *, int , int));
1934extern bool init_tls_library __P((void));
1935extern bool inittls __P((SSL_CTX **, u_long, bool, char *, char *, char *, char *, char *));
1936extern bool initclttls __P((void));
1937extern bool initsrvtls __P((void));
1938extern int tls_get_info __P((SSL *, ENVELOPE *, bool, char *, bool));
1939extern int endtls __P((SSL *, char *));
1940extern int endtlsclt __P((MCI *));
1941extern void tlslogerr __P((void));
1942extern bool tls_rand_init __P((char *, int));
1943#endif /* STARTTLS */
1944
1945/* Transcript file */
1946extern void closexscript __P((ENVELOPE *));
1947extern void openxscript __P((ENVELOPE *));
1948
1949/* error related */
1950extern void buffer_errors __P((void));
1951extern void flush_errors __P((bool));
1952extern void message __P((const char *, ...));
1953extern void nmessage __P((const char *, ...));
1954extern void syserr __P((const char *, ...));
1955extern void usrerrenh __P((char *, const char *, ...));
1956extern void usrerr __P((const char *, ...));
1957extern int isenhsc __P((const char *, int));
1958extern int extenhsc __P((const char *, int, char *));
1959
1960/* alias file */
1961extern void alias __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
1962extern bool aliaswait __P((MAP *, char *, bool));
1963extern void forward __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
1964extern void readaliases __P((MAP *, FILE *, bool, bool));
1965extern bool rebuildaliases __P((MAP *, bool));
1966extern void setalias __P((char *));
1967
1968/* logging */
1969extern void logdelivery __P((MAILER *, MCI *, char *, const char *, ADDRESS *, time_t, ENVELOPE *));
1970extern void logsender __P((ENVELOPE *, char *));
1971extern void sm_syslog __P((int, const char *, const char *, ...));
1972
1973/* SMTP */
1974extern void giveresponse __P((int, char *, MAILER *, MCI *, ADDRESS *, time_t, ENVELOPE *));
1975extern int reply __P((MAILER *, MCI *, ENVELOPE *, time_t, void (*)(), char **));
1976extern void smtp __P((char *volatile, BITMAP256, ENVELOPE *volatile));
1977#if SASL
1978extern int smtpauth __P((MAILER *, MCI *, ENVELOPE *));
1979#endif /* SASL */
1980extern int smtpdata __P((MAILER *, MCI *, ENVELOPE *));
1981extern int smtpgetstat __P((MAILER *, MCI *, ENVELOPE *));
1982extern int smtpmailfrom __P((MAILER *, MCI *, ENVELOPE *));
1983extern void smtpmessage __P((char *, MAILER *, MCI *, ...));
1984extern void smtpinit __P((MAILER *, MCI *, ENVELOPE *, bool));
1985extern char *smtptodsn __P((int));
1986extern int smtpprobe __P((MCI *));
1987extern void smtpquit __P((MAILER *, MCI *, ENVELOPE *));
1988extern int smtprcpt __P((ADDRESS *, MAILER *, MCI *, ENVELOPE *));
1989extern void smtprset __P((MAILER *, MCI *, ENVELOPE *));
1990
1991#define ISSMTPCODE(c) (isascii(c[0]) && isdigit(c[0]) && \
1992 isascii(c[1]) && isdigit(c[1]) && \
1993 isascii(c[2]) && isdigit(c[2]))
1994#define ISSMTPREPLY(c) (ISSMTPCODE(c) && \
1995 (c[3] == ' ' || c[3] == '-' || c[3] == '\0'))
1996
1997/* delivery */
1998extern pid_t dowork __P((int, char *, bool, bool, ENVELOPE *));
1999extern int endmailer __P((MCI *, ENVELOPE *, char **));
2000extern int mailfile __P((char *volatile, MAILER *volatile, ADDRESS *, volatile long, ENVELOPE *));
2001extern void sendall __P((ENVELOPE *, int));
2002
2003/* stats */
2004extern void markstats __P((ENVELOPE *, ADDRESS *, bool));
2005extern void clearstats __P((void));
2006extern void poststats __P((char *));
2007
2008/* control socket */
2009extern void closecontrolsocket __P((bool));
2010extern void clrcontrol __P((void));
2011extern void control_command __P((int, ENVELOPE *));
2012extern int opencontrolsocket __P((void));
2013
2014#if _FFR_MILTER
2015/* milter functions */
2016extern void milter_parse_list __P((char *, struct milter **, int));
2017extern void milter_setup __P((char *));
2018extern void milter_set_option __P((char *, char *, bool));
2019extern bool milter_can_delrcpts __P((void));
2020extern void milter_init __P((ENVELOPE *, char *));
2021extern void milter_quit __P((ENVELOPE *));
2022extern void milter_abort __P((ENVELOPE *));
2023extern char *milter_connect __P((char *, SOCKADDR, ENVELOPE *, char *));
2024extern char *milter_helo __P((char *, ENVELOPE *, char *));
2025extern char *milter_envfrom __P((char **, ENVELOPE *, char *));
2026extern char *milter_envrcpt __P((char **, ENVELOPE *, char *));
2027extern char *milter_data __P((ENVELOPE *, char *));
2028#endif /* _FFR_MILTER */
2029
2030extern char *addquotes __P((char *));
2031extern void allsignals __P((bool));
2032extern char *arpadate __P((char *));
2033extern bool atobool __P((char *));
2034extern int atooct __P((char *));
2035extern void auth_warning __P((ENVELOPE *, const char *, ...));
2036extern int blocksignal __P((int));
2037extern bool bitintersect __P((BITMAP256, BITMAP256));
2038extern bool bitzerop __P((BITMAP256));
2039extern void buildfname __P((char *, char *, char *, int));
2040extern int checkcompat __P((ADDRESS *, ENVELOPE *));
2041#ifdef XDEBUG
2042extern void checkfd012 __P((char *));
2043extern void checkfdopen __P((int, char *));
2044#endif /* XDEBUG */
2045extern void checkfds __P((char *));
2046extern bool chownsafe __P((int, bool));
2047extern void cleanstrcpy __P((char *, char *, int));
2048extern void clrdaemon __P((void));
2049extern void collect __P((FILE *, bool, HDR **, ENVELOPE *));
2050extern time_t convtime __P((char *, int));
2051extern char **copyplist __P((char **, bool));
2052extern void copy_class __P((int, int));
2053extern time_t curtime __P((void));
2054extern char *defcharset __P((ENVELOPE *));
2055extern char *denlstring __P((char *, bool, bool));
2056extern void disconnect __P((int, ENVELOPE *));
2057extern bool dns_getcanonname __P((char *, int, bool, int *));
2058extern pid_t dofork __P((void));
2059extern int drop_privileges __P((bool));
2060extern int dsntoexitstat __P((char *));
2061extern void dumpfd __P((int, bool, bool));
2062extern void dumpstate __P((char *));
2063extern bool enoughdiskspace __P((long, bool));
2064extern char *exitstat __P((char *));
2065extern char *fgetfolded __P((char *, int, FILE *));
2066extern void fill_fd __P((int, char *));
2067extern char *find_character __P((char *, int));
2068extern struct passwd *finduser __P((char *, bool *));
2069extern void finis __P((bool, volatile int));
2070extern void fixcrlf __P((char *, bool));
2071extern long freediskspace __P((char *, long *));
2072#if NETINET6 && NEEDSGETIPNODE
2073# if _FFR_FREEHOSTENT
2074extern void freehostent __P((struct hostent *));
2075# endif /* _FFR_FREEHOSTENT */
2076#endif /* NEEDSGETIPNODE && NETINET6 */
2077extern char *get_column __P((char *, int, int, char *, int));
2078extern char *getauthinfo __P((int, bool *));
2079extern char *getcfname __P((void));
2080extern char *getextenv __P((const char *));
2081extern int getdtsize __P((void));
2082extern BITMAP256 *getrequests __P((ENVELOPE *));
2083extern char *getvendor __P((int));
2084extern void help __P((char *, ENVELOPE *));
2085extern void init_md __P((int, char **));
2086extern void initdaemon __P((void));
2087extern void inithostmaps __P((void));
2088extern void initmacros __P((ENVELOPE *));
2089extern void initsetproctitle __P((int, char **, char **));
2090extern void init_vendor_macros __P((ENVELOPE *));
2091extern SIGFUNC_DECL intsig __P((int));
2092extern bool isloopback __P((SOCKADDR sa));
2093extern void load_if_names __P((void));
2094extern bool lockfile __P((int, char *, char *, int));
2095extern void log_sendmail_pid __P((ENVELOPE *));
2096extern char lower __P((int));
2097extern void makelower __P((char *));
2098extern int makeconnection_ds __P((char *, MCI *));
2099extern int makeconnection __P((char *, volatile u_int, MCI *, ENVELOPE *));
2100extern char * munchstring __P((char *, char **, int));
2101extern struct hostent *myhostname __P((char *, int));
2102extern char *nisplus_default_domain __P((void)); /* extern for Sun */
2103extern bool path_is_dir __P((char *, bool));
2104extern char *pintvl __P((time_t, bool));
2105extern void printav __P((char **));
2106extern void printmailer __P((MAILER *));
2107extern void printopenfds __P((bool));
2108extern void printqueue __P((void));
2109extern void printrules __P((void));
2110extern pid_t prog_open __P((char **, int *, ENVELOPE *));
2111extern void putline __P((char *, MCI *));
2112extern void putxline __P((char *, size_t, MCI *, int));
2113extern void queueup_macros __P((int, FILE *, ENVELOPE *));
2114extern void readcf __P((char *, bool, ENVELOPE *));
2115extern SIGFUNC_DECL reapchild __P((int));
2116extern int releasesignal __P((int));
2117extern void resetlimits __P((void));
2118extern bool rfc822_string __P((char *));
2119extern FILE *safefopen __P((char *, int, int, long));
2120extern void savemail __P((ENVELOPE *, bool));
2121extern void seed_random __P((void));
2122extern void sendtoargv __P((char **, ENVELOPE *));
2123extern void setclientoptions __P((char *));
2124extern bool setdaemonoptions __P((char *));
2125extern void setdefaults __P((ENVELOPE *));
2126extern void setdefuser __P((void));
2127extern bool setvendor __P((char *));
2128extern void setoption __P((int, char *, bool, bool, ENVELOPE *));
2129extern sigfunc_t setsignal __P((int, sigfunc_t));
2130extern void setuserenv __P((const char *, const char *));
2131extern void settime __P((ENVELOPE *));
2132extern char *sfgets __P((char *, int, FILE *, time_t, char *));
2133extern char *shortenstring __P((const char *, int));
2134extern char *shorten_hostname __P((char []));
2135extern bool shorten_rfc822_string __P((char *, size_t));
2136extern void shutdown_daemon __P((void));
2137extern void sm_dopr __P((char *, const char *, va_list));
2138extern void sm_free __P((void *));
2139extern struct hostent *sm_gethostbyname __P((char *, int));
2140extern struct hostent *sm_gethostbyaddr __P((char *, int, int));
2141extern int sm_getla __P((ENVELOPE *));
2142extern struct passwd *sm_getpwnam __P((char *));
2143extern struct passwd *sm_getpwuid __P((UID_T));
2144extern void sm_setproctitle __P((bool, ENVELOPE *, const char *, ...));
2145extern SIGFUNC_DECL sm_signal_noop __P((int));
2146extern int sm_strcasecmp __P((const char *, const char *));
2147extern void stop_sendmail __P((void));
2148extern bool strcontainedin __P((char *, char *));
2149extern void stripquotes __P((char *));
2150extern int switch_map_find __P((char *, char *[], short []));
2151extern bool transienterror __P((int));
2152extern void tTflag __P((char *));
2153extern void tTsetup __P((u_char *, int, char *));
2154extern char *ttypath __P((void));
2155extern void unlockqueue __P((ENVELOPE *));
2156#if !HASUNSETENV
2157extern void unsetenv __P((char *));
2158#endif /* !HASUNSETENV */
2159extern char *username __P((void));
2160extern bool usershellok __P((char *, char *));
2161extern void vendor_post_defaults __P((ENVELOPE *));
2162extern void vendor_pre_defaults __P((ENVELOPE *));
2163extern int waitfor __P((pid_t));
2164extern bool writable __P((char *, ADDRESS *, long));
2165extern char *xalloc __P((int));
2166extern char *xcalloc __P((size_t, size_t));
2167extern char *xrealloc __P((void *, size_t));
2168extern void xputs __P((const char *));
2169extern char *xtextify __P((char *, char *));
2170extern bool xtextok __P((char *));
2171extern void xunlink __P((char *));
2172extern char *xuntextify __P((char *));
2173#endif /* _SENDMAIL_H */
770/* external <==> internal mapping table */
771struct 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 */
781extern void define __P((int, char *, ENVELOPE *));
782extern void expand __P((char *, char *, size_t, ENVELOPE *));
783extern int macid __P((char *, char **));
784extern char *macname __P((int));
785extern char *macvalue __P((int, ENVELOPE *));
786extern int rscheck __P((char *, char *, char *, ENVELOPE *, bool, bool, int, char *));
787extern void setclass __P((int, char *));
788extern int strtorwset __P((char *, char **, int));
789extern void translate_dollars __P((char *));
790extern 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
804NAMECANON
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 */
817extern bool getcanonname __P((char *, int, bool));
818extern 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
836MAP
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
904MAPCLASS
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 */
928extern void closemaps __P((void));
929extern bool impl_map_open __P((MAP *, int));
930extern void initmaps __P((void));
931extern MAP *makemapentry __P((char *));
932extern void maplocaluser __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
933extern char *map_rewrite __P((MAP *, const char *, size_t, char **));
934#if NETINFO
935extern char *ni_propval __P((char *, char *, char *, char *, int));
936#endif /* NETINFO */
937extern bool openmap __P((MAP *));
938#if USERDB
939extern void _udbx_close __P((void));
940extern int udbexpand __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
941extern char *udbsender __P((char *));
942#endif /* USERDB */
943 /*
944** LDAP related items
945*/
946#ifdef LDAPMAP
947struct 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
980typedef struct ldapmap_struct LDAPMAP_STRUCT;
981
982/* struct defining LDAP Auth Methods */
983struct 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 */
990struct 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 */
997struct lssvalues
998{
999 char *lss_name; /* name of LDAP search scope */
1000 int lss_code; /* numeric code */
1001};
1002
1003/* functions */
1004extern bool ldapmap_parseargs __P((MAP *, char *));
1005extern void ldapmap_set_defaults __P((char *));
1006#endif /* LDAPMAP */
1007
1008 /*
1009** PH related items
1010*/
1011
1012#ifdef PH_MAP
1013struct 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};
1022typedef 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
1030struct 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 */
1052extern void proc_list_add __P((pid_t, char *, int));
1053extern void proc_list_clear __P((void));
1054extern void proc_list_display __P((FILE *));
1055extern int proc_list_drop __P((pid_t));
1056extern void proc_list_probe __P((void));
1057extern void proc_list_set __P((pid_t, char *));
1058
1059 /*
1060** Symbol table definitions
1061*/
1062
1063struct 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
1093typedef 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 */
1142extern STAB *stab __P((char *, int, int));
1143extern 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
1154struct 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
1164typedef struct event EVENT;
1165
1166/* functions */
1167extern void clrevent __P((EVENT *));
1168extern void clear_events __P((void));
1169extern EVENT *setevent __P((time_t, void(*)(), int));
1170extern 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 */
1214extern 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 */
1267struct 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 */
1298extern void mime7to8 __P((MCI *, HDR *, ENVELOPE *));
1299extern 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 */
1310extern 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
1318union 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 */
1344extern char *anynet_ntoa __P((SOCKADDR *));
1345# if NETINET6
1346extern char *anynet_ntop __P((struct in6_addr *, char *, size_t));
1347# endif /* NETINET6 */
1348extern char *hostnamebyanyaddr __P((SOCKADDR *));
1349# if DAEMON
1350extern 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
1369struct 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 */
1396typedef SM_INT32 mi_int32;
1397
1398EXTERN struct milter *InputFilters[MAXFILTERS];
1399EXTERN 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 */
1424extern void vendor_daemon_setup __P((ENVELOPE *));
1425extern void vendor_set_uid __P((UID_T));
1426
1427
1428/*
1429** Terminal escape codes.
1430**
1431** To make debugging output clearer.
1432*/
1433
1434struct 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
1485ERROR: 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 */
1557struct queue_char
1558{
1559 char *queue_match; /* string to match */
1560 struct queue_char *queue_next;
1561};
1562
1563typedef struct queue_char QUEUE_CHAR;
1564
1565/* functions */
1566extern void assign_queueid __P((ENVELOPE *));
1567extern ADDRESS *copyqueue __P((ADDRESS *));
1568extern void initsys __P((ENVELOPE *));
1569extern void loseqfile __P((ENVELOPE *, char *));
1570extern void multiqueue_cache __P((void));
1571extern char *qid_printname __P((ENVELOPE *));
1572extern char *qid_printqueue __P((int));
1573extern char *queuename __P((ENVELOPE *, int));
1574extern void queueup __P((ENVELOPE *, bool));
1575extern bool runqueue __P((bool, bool));
1576extern void setnewqueue __P((ENVELOPE *));
1577extern bool shouldqueue __P((long, time_t));
1578extern 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
1586EXTERN 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 */
1624extern 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 */
1635extern 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() \
1648do \
1649{ \
1650 if (InCriticalSection > 0) \
1651 InCriticalSection--; \
1652} while (0)
1653
1654#define CHECK_CRITICAL(sig) \
1655do \
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 */
1676EXTERN u_int volatile InCriticalSection; /* >0 if in a critical section */
1677EXTERN int volatile PendingSignal; /* pending signal to resend */
1678
1679/* functions */
1680extern 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
1711EXTERN bool AllowBogusHELO; /* allow syntax errors on HELO command */
1712#if !_FFR_REMOVE_AUTOREBUILD
1713EXTERN bool AutoRebuild; /* auto-rebuild the alias database as needed */
1714#endif /* !_FFR_REMOVE_AUTOREBUILD */
1715EXTERN bool CheckAliases; /* parse addresses during newaliases */
1716EXTERN bool ChownAlwaysSafe; /* treat chown(2) as safe */
1717EXTERN bool ColonOkInAddr; /* single colon legal in address */
1718EXTERN bool ConfigFileRead; /* configuration file has been read */
1719EXTERN bool volatile DataProgress; /* have we sent anything since last check */
1720EXTERN bool DisConnected; /* running with OutChannel redirected to xf */
1721EXTERN bool volatile DoQueueRun; /* non-interrupt time queue run needed */
1722EXTERN bool DontExpandCnames; /* do not $[...$] expand CNAMEs */
1723EXTERN bool DontInitGroups; /* avoid initgroups() because of NIS cost */
1724EXTERN bool DontLockReadFiles; /* don't read lock support files */
1725EXTERN bool DontProbeInterfaces; /* don't probe interfaces for names */
1726EXTERN bool DontPruneRoutes; /* don't prune source routes */
1727EXTERN bool ForkQueueRuns; /* fork for each job when running the queue */
1728EXTERN bool FromFlag; /* if set, "From" person is explicit */
1729EXTERN bool GrabTo; /* if set, get recipients from msg */
1730EXTERN bool HasEightBits; /* has at least one eight bit input byte */
1731EXTERN bool HasWildcardMX; /* don't use MX records when canonifying */
1732EXTERN bool HoldErrs; /* only output errors to transcript */
1733EXTERN bool IgnoreHostStatus; /* ignore long term host status files */
1734EXTERN bool IgnrDot; /* don't let dot end messages */
1735EXTERN bool InChild; /* true if running in an SMTP subprocess */
1736EXTERN bool LogUsrErrs; /* syslog user errors (e.g., SMTP RCPT cmd) */
1737EXTERN bool MapOpenErr; /* error opening a non-optional map */
1738EXTERN bool MatchGecos; /* look for user names in gecos field */
1739EXTERN bool MeToo; /* send to the sender also */
1740EXTERN bool NoAlias; /* suppress aliasing */
1741EXTERN bool NoConnect; /* don't connect to non-local mailers */
1742EXTERN bool OnlyOneError; /* .... or only want to give one SMTP reply */
1743EXTERN bool QuickAbort; /* .... but only if we want a quick abort */
1744EXTERN bool RrtImpliesDsn; /* turn Return-Receipt-To: into DSN */
1745EXTERN bool SaveFrom; /* save leading "From" lines */
1746EXTERN bool SendMIMEErrors; /* send error messages in MIME format */
1747EXTERN bool SevenBitInput; /* force 7-bit data on input */
1748EXTERN bool SingleLineFromHeader; /* force From: header to be one line */
1749EXTERN bool SingleThreadDelivery; /* single thread hosts on delivery */
1750EXTERN bool volatile StopRequest; /* stop sending output */
1751EXTERN bool SuperSafe; /* be extra careful, even if expensive */
1752EXTERN bool SuprErrs; /* set if we are suppressing errors */
1753EXTERN bool TryNullMXList; /* if we are the best MX, try host directly */
1754#if _FFR_WORKAROUND_BROKEN_NAMESERVERS
1755EXTERN bool WorkAroundBrokenAAAA; /* some nameservers return SERVFAIL on AAAA queries */
1756#endif /* _FFR_WORKAROUND_BROKEN_NAMESERVERS */
1757EXTERN bool UseErrorsTo; /* use Errors-To: header (back compat) */
1758EXTERN bool UseHesiod; /* using Hesiod -- interpret Hesiod errors */
1759EXTERN bool UseNameServer; /* using DNS -- interpret h_errno & MX RRs */
1760EXTERN char InetMode; /* default network for daemon mode */
1761EXTERN char OpMode; /* operation mode, see below */
1762EXTERN char SpaceSub; /* substitution for <lwsp> */
1763EXTERN int CheckpointInterval; /* queue file checkpoint interval */
1764EXTERN int ConfigLevel; /* config file level */
1765EXTERN int ConnRateThrottle; /* throttle for SMTP connection rate */
1766EXTERN int volatile CurChildren; /* current number of daemonic children */
1767EXTERN int CurrentLA; /* current load average */
1768EXTERN int DefaultNotify; /* default DSN notification flags */
1769EXTERN int Errors; /* set if errors (local to single pass) */
1770EXTERN int ExitStat; /* exit status code */
1771EXTERN int FileMode; /* mode on files */
1772EXTERN int LineNumber; /* line number in current input */
1773EXTERN int LogLevel; /* level of logging to perform */
1774EXTERN int MaxAliasRecursion; /* maximum depth of alias recursion */
1775EXTERN int MaxChildren; /* maximum number of daemonic children */
1776EXTERN int MaxForwardEntries; /* maximum number of forward entries */
1777EXTERN int MaxHeadersLength; /* max length of headers */
1778EXTERN int MaxHopCount; /* max # of hops until bounce */
1779EXTERN int MaxMacroRecursion; /* maximum depth of macro recursion */
1780EXTERN int MaxMciCache; /* maximum entries in MCI cache */
1781EXTERN int MaxMimeFieldLength; /* maximum MIME field length */
1782EXTERN int MaxMimeHeaderLength; /* maximum MIME header length */
1783
1784
1785EXTERN int MaxQueueRun; /* maximum number of jobs in one queue run */
1786EXTERN int MaxRcptPerMsg; /* max recipients per SMTP message */
1787EXTERN int MaxRuleRecursion; /* maximum depth of ruleset recursion */
1788EXTERN int MimeMode; /* MIME processing mode */
1789EXTERN int NoRecipientAction;
1790EXTERN int NumPriorities; /* pointer into Priorities */
1791EXTERN u_short PrivacyFlags; /* privacy flags */
1792#if _FFR_QUEUE_FILE_MODE
1793EXTERN int QueueFileMode; /* mode on qf/tf/df files */
1794#endif /* _FFR_QUEUE_FILE_MODE */
1795EXTERN int QueueLA; /* load average starting forced queueing */
1796EXTERN int QueueSortOrder; /* queue sorting order algorithm */
1797EXTERN int RefuseLA; /* load average refusing connections are */
1798EXTERN int VendorCode; /* vendor-specific operation enhancements */
1799EXTERN int Verbose; /* set if blow-by-blow desired */
1800EXTERN gid_t DefGid; /* default gid to run as */
1801EXTERN gid_t RealGid; /* real gid of caller */
1802EXTERN gid_t RunAsGid; /* GID to become for bulk of run */
1803EXTERN uid_t DefUid; /* default uid to run as */
1804EXTERN uid_t RealUid; /* real uid of caller */
1805EXTERN uid_t RunAsUid; /* UID to become for bulk of run */
1806EXTERN uid_t TrustedUid; /* uid of trusted user for files and startup */
1807EXTERN size_t DataFileBufferSize; /* size of buffer for in-core df */
1808EXTERN size_t XscriptFileBufferSize; /* size of buffer for in-core xf */
1809EXTERN time_t DialDelay; /* delay between dial-on-demand tries */
1810EXTERN time_t MciCacheTimeout; /* maximum idle time on connections */
1811EXTERN time_t MciInfoTimeout; /* how long 'til we retry down hosts */
1812EXTERN time_t MinQueueAge; /* min delivery interval */
1813EXTERN time_t QueueIntvl; /* intervals between running the queue */
1814EXTERN time_t SafeAlias; /* interval to wait until @:@ in alias file */
1815EXTERN time_t ServiceCacheMaxAge; /* refresh interval for cache */
1816EXTERN time_t ServiceCacheTime; /* time service switch was cached */
1817EXTERN MODE_T OldUmask; /* umask when sendmail starts up */
1818EXTERN long MaxMessageSize; /* advertised max size we will accept */
1819EXTERN long MinBlocksFree; /* min # of blocks free on queue fs */
1820EXTERN long QueueFactor; /* slope of queue function */
1821EXTERN long WkClassFact; /* multiplier for message class -> priority */
1822EXTERN long WkRecipFact; /* multiplier for # of recipients -> priority */
1823EXTERN long WkTimeFact; /* priority offset each time this job is run */
1824#if SASL
1825EXTERN char *AuthMechanisms; /* AUTH mechanisms */
1826EXTERN char *SASLInfo; /* file with AUTH info */
1827#endif /* SASL */
1828EXTERN int SASLOpts; /* options for SASL */
1829#if STARTTLS
1830EXTERN char *CACERTpath; /* path to CA certificates (dir. with hashes) */
1831EXTERN char *CACERTfile; /* file with CA certificate */
1832EXTERN char *SrvCERTfile; /* file with server certificate */
1833EXTERN char *Srvkeyfile; /* file with server private key */
1834EXTERN char *CltCERTfile; /* file with client certificate */
1835EXTERN char *Cltkeyfile; /* file with client private key */
1836EXTERN char *DHParams; /* file with DH parameters */
1837EXTERN char *RandFile; /* source of random data */
1838# if _FFR_TLS_1
1839EXTERN char *DHParams5; /* file with DH parameters (512) */
1840EXTERN char *CipherList; /* list of ciphers */
1841# endif /* _FFR_TLS_1 */
1842#endif /* STARTTLS */
1843EXTERN char *ConfFile; /* location of configuration file [conf.c] */
1844EXTERN char *ControlSocketName; /* control socket filename [control.c] */
1845EXTERN char *CurHostName; /* current host we are dealing with */
1846EXTERN char *DeadLetterDrop; /* path to dead letter office */
1847EXTERN char *DefUser; /* default user to run as (from DefUid) */
1848EXTERN char *DefaultCharSet; /* default character set for MIME */
1849EXTERN char *DoubleBounceAddr; /* where to send double bounces */
1850EXTERN char *ErrMsgFile; /* file to prepend to all error messages */
1851EXTERN char *FallBackMX; /* fall back MX host */
1852EXTERN char *FileName; /* name to print on error messages */
1853EXTERN char *ForwardPath; /* path to search for .forward files */
1854EXTERN char *HelpFile; /* location of SMTP help file */
1855EXTERN char *HostStatDir; /* location of host status information */
1856EXTERN char *HostsFile; /* path to /etc/hosts file */
1857EXTERN char *MustQuoteChars; /* quote these characters in phrases */
1858EXTERN char *MyHostName; /* name of this host for SMTP messages */
1859EXTERN char *OperatorChars; /* operators (old $o macro) */
1860EXTERN char *PidFile; /* location of proc id file [conf.c] */
1861EXTERN char *PostMasterCopy; /* address to get errs cc's */
1862EXTERN char *ProcTitlePrefix; /* process title prefix */
1863EXTERN char *QueueDir; /* location of queue directory */
1864#if _FFR_QUEUEDELAY
1865EXTERN int QueueAlg; /* algorithm for queue delays */
1866EXTERN time_t QueueInitDelay; /* initial queue delay */
1867EXTERN time_t QueueMaxDelay; /* maximum queue delay */
1868#endif /* _FFR_QUEUEDELAY */
1869EXTERN char *RealHostName; /* name of host we are talking to */
1870EXTERN char *RealUserName; /* real user name of caller */
1871EXTERN char *volatile RestartRequest;/* a sendmail restart has been requested */
1872EXTERN char *RunAsUserName; /* user to become for bulk of run */
1873EXTERN char *SafeFileEnv; /* chroot location for file delivery */
1874EXTERN char *ServiceSwitchFile; /* backup service switch */
1875EXTERN char *volatile ShutdownRequest;/* a sendmail shutdown has been requested */
1876EXTERN char *SmtpGreeting; /* SMTP greeting message (old $e macro) */
1877EXTERN char *SmtpPhase; /* current phase in SMTP processing */
1878EXTERN char SmtpError[MAXLINE]; /* save failure error messages */
1879EXTERN char *StatFile; /* location of statistics summary */
1880EXTERN char *TimeZoneSpec; /* override time zone specification */
1881EXTERN char *UdbSpec; /* user database source spec */
1882EXTERN char *UnixFromLine; /* UNIX From_ line (old $l macro) */
1883EXTERN char **ExternalEnviron; /* input environment */
1884 /* saved user environment */
1885EXTERN char **SaveArgv; /* argument vector for re-execing */
1886EXTERN BITMAP256 DontBlameSendmail; /* DontBlameSendmail bits */
1887#if SFIO
1888EXTERN Sfio_t *InChannel; /* input connection */
1889EXTERN Sfio_t *OutChannel; /* output connection */
1890#else /* SFIO */
1891EXTERN FILE *InChannel; /* input connection */
1892EXTERN FILE *OutChannel; /* output connection */
1893#endif /* SFIO */
1894EXTERN FILE *TrafficLogFile; /* file in which to log all traffic */
1895#ifdef HESIOD
1896EXTERN void *HesiodContext;
1897#endif /* HESIOD */
1898EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */
1899EXTERN MAILER *LocalMailer; /* ptr to local mailer */
1900EXTERN MAILER *ProgMailer; /* ptr to program mailer */
1901EXTERN MAILER *FileMailer; /* ptr to *file* mailer */
1902EXTERN MAILER *InclMailer; /* ptr to *include* mailer */
1903EXTERN QUEUE_CHAR *QueueLimitRecipient; /* limit queue run to rcpt */
1904EXTERN QUEUE_CHAR *QueueLimitSender; /* limit queue run to sender */
1905EXTERN QUEUE_CHAR *QueueLimitId; /* limit queue run to id */
1906EXTERN MAILER *Mailer[MAXMAILERS + 1];
1907EXTERN struct rewrite *RewriteRules[MAXRWSETS];
1908EXTERN char *RuleSetNames[MAXRWSETS]; /* ruleset number to name */
1909EXTERN char *UserEnviron[MAXUSERENVIRON + 1];
1910EXTERN struct priority Priorities[MAXPRIORITIES];
1911EXTERN struct termescape TermEscape; /* terminal escape codes */
1912EXTERN SOCKADDR ConnectOnlyTo; /* override connection address (for testing) */
1913EXTERN SOCKADDR RealHostAddr; /* address of host we are talking to */
1914EXTERN jmp_buf TopFrame; /* branch-to-top-of-loop-on-error frame */
1915EXTERN TIMERS Timers;
1916
1917/*
1918** Declarations of useful functions
1919*/
1920
1921#if SASL
1922extern char *intersect __P((char *, char *));
1923extern char *iteminlist __P((char *, char *, char *));
1924extern int proxy_policy __P((void *, const char *, const char *, const char **, const char **));
1925# if SASL > 10515
1926extern int safesaslfile __P((void *, char *, int));
1927# else /* SASL > 10515 */
1928extern int safesaslfile __P((void *, char *));
1929# endif /* SASL > 10515 */
1930extern int sasl_decode64 __P((const char *, unsigned, char *, unsigned *));
1931extern int sasl_encode64 __P((const char *, unsigned, char *, unsigned, unsigned *));
1932#endif /* SASL */
1933
1934#if STARTTLS
1935extern void apps_ssl_info_cb __P((SSL *, int , int));
1936extern bool init_tls_library __P((void));
1937extern bool inittls __P((SSL_CTX **, u_long, bool, char *, char *, char *, char *, char *));
1938extern bool initclttls __P((void));
1939extern bool initsrvtls __P((void));
1940extern int tls_get_info __P((SSL *, ENVELOPE *, bool, char *, bool));
1941extern int endtls __P((SSL *, char *));
1942extern int endtlsclt __P((MCI *));
1943extern void tlslogerr __P((void));
1944extern bool tls_rand_init __P((char *, int));
1945#endif /* STARTTLS */
1946
1947/* Transcript file */
1948extern void closexscript __P((ENVELOPE *));
1949extern void openxscript __P((ENVELOPE *));
1950
1951/* error related */
1952extern void buffer_errors __P((void));
1953extern void flush_errors __P((bool));
1954extern void message __P((const char *, ...));
1955extern void nmessage __P((const char *, ...));
1956extern void syserr __P((const char *, ...));
1957extern void usrerrenh __P((char *, const char *, ...));
1958extern void usrerr __P((const char *, ...));
1959extern int isenhsc __P((const char *, int));
1960extern int extenhsc __P((const char *, int, char *));
1961
1962/* alias file */
1963extern void alias __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
1964extern bool aliaswait __P((MAP *, char *, bool));
1965extern void forward __P((ADDRESS *, ADDRESS **, int, ENVELOPE *));
1966extern void readaliases __P((MAP *, FILE *, bool, bool));
1967extern bool rebuildaliases __P((MAP *, bool));
1968extern void setalias __P((char *));
1969
1970/* logging */
1971extern void logdelivery __P((MAILER *, MCI *, char *, const char *, ADDRESS *, time_t, ENVELOPE *));
1972extern void logsender __P((ENVELOPE *, char *));
1973extern void sm_syslog __P((int, const char *, const char *, ...));
1974
1975/* SMTP */
1976extern void giveresponse __P((int, char *, MAILER *, MCI *, ADDRESS *, time_t, ENVELOPE *));
1977extern int reply __P((MAILER *, MCI *, ENVELOPE *, time_t, void (*)(), char **));
1978extern void smtp __P((char *volatile, BITMAP256, ENVELOPE *volatile));
1979#if SASL
1980extern int smtpauth __P((MAILER *, MCI *, ENVELOPE *));
1981#endif /* SASL */
1982extern int smtpdata __P((MAILER *, MCI *, ENVELOPE *));
1983extern int smtpgetstat __P((MAILER *, MCI *, ENVELOPE *));
1984extern int smtpmailfrom __P((MAILER *, MCI *, ENVELOPE *));
1985extern void smtpmessage __P((char *, MAILER *, MCI *, ...));
1986extern void smtpinit __P((MAILER *, MCI *, ENVELOPE *, bool));
1987extern char *smtptodsn __P((int));
1988extern int smtpprobe __P((MCI *));
1989extern void smtpquit __P((MAILER *, MCI *, ENVELOPE *));
1990extern int smtprcpt __P((ADDRESS *, MAILER *, MCI *, ENVELOPE *));
1991extern 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 */
2000extern pid_t dowork __P((int, char *, bool, bool, ENVELOPE *));
2001extern int endmailer __P((MCI *, ENVELOPE *, char **));
2002extern int mailfile __P((char *volatile, MAILER *volatile, ADDRESS *, volatile long, ENVELOPE *));
2003extern void sendall __P((ENVELOPE *, int));
2004
2005/* stats */
2006extern void markstats __P((ENVELOPE *, ADDRESS *, bool));
2007extern void clearstats __P((void));
2008extern void poststats __P((char *));
2009
2010/* control socket */
2011extern void closecontrolsocket __P((bool));
2012extern void clrcontrol __P((void));
2013extern void control_command __P((int, ENVELOPE *));
2014extern int opencontrolsocket __P((void));
2015
2016#if _FFR_MILTER
2017/* milter functions */
2018extern void milter_parse_list __P((char *, struct milter **, int));
2019extern void milter_setup __P((char *));
2020extern void milter_set_option __P((char *, char *, bool));
2021extern bool milter_can_delrcpts __P((void));
2022extern void milter_init __P((ENVELOPE *, char *));
2023extern void milter_quit __P((ENVELOPE *));
2024extern void milter_abort __P((ENVELOPE *));
2025extern char *milter_connect __P((char *, SOCKADDR, ENVELOPE *, char *));
2026extern char *milter_helo __P((char *, ENVELOPE *, char *));
2027extern char *milter_envfrom __P((char **, ENVELOPE *, char *));
2028extern char *milter_envrcpt __P((char **, ENVELOPE *, char *));
2029extern char *milter_data __P((ENVELOPE *, char *));
2030#endif /* _FFR_MILTER */
2031
2032extern char *addquotes __P((char *));
2033extern void allsignals __P((bool));
2034extern char *arpadate __P((char *));
2035extern bool atobool __P((char *));
2036extern int atooct __P((char *));
2037extern void auth_warning __P((ENVELOPE *, const char *, ...));
2038extern int blocksignal __P((int));
2039extern bool bitintersect __P((BITMAP256, BITMAP256));
2040extern bool bitzerop __P((BITMAP256));
2041extern void buildfname __P((char *, char *, char *, int));
2042extern int checkcompat __P((ADDRESS *, ENVELOPE *));
2043#ifdef XDEBUG
2044extern void checkfd012 __P((char *));
2045extern void checkfdopen __P((int, char *));
2046#endif /* XDEBUG */
2047extern void checkfds __P((char *));
2048extern bool chownsafe __P((int, bool));
2049extern void cleanstrcpy __P((char *, char *, int));
2050extern void clrdaemon __P((void));
2051extern void collect __P((FILE *, bool, HDR **, ENVELOPE *));
2052extern time_t convtime __P((char *, int));
2053extern char **copyplist __P((char **, bool));
2054extern void copy_class __P((int, int));
2055extern time_t curtime __P((void));
2056extern char *defcharset __P((ENVELOPE *));
2057extern char *denlstring __P((char *, bool, bool));
2058extern void disconnect __P((int, ENVELOPE *));
2059extern bool dns_getcanonname __P((char *, int, bool, int *));
2060extern pid_t dofork __P((void));
2061extern int drop_privileges __P((bool));
2062extern int dsntoexitstat __P((char *));
2063extern void dumpfd __P((int, bool, bool));
2064extern void dumpstate __P((char *));
2065extern bool enoughdiskspace __P((long, bool));
2066extern char *exitstat __P((char *));
2067extern char *fgetfolded __P((char *, int, FILE *));
2068extern void fill_fd __P((int, char *));
2069extern char *find_character __P((char *, int));
2070extern struct passwd *finduser __P((char *, bool *));
2071extern void finis __P((bool, volatile int));
2072extern void fixcrlf __P((char *, bool));
2073extern long freediskspace __P((char *, long *));
2074#if NETINET6 && NEEDSGETIPNODE
2075# if _FFR_FREEHOSTENT
2076extern void freehostent __P((struct hostent *));
2077# endif /* _FFR_FREEHOSTENT */
2078#endif /* NEEDSGETIPNODE && NETINET6 */
2079extern char *get_column __P((char *, int, int, char *, int));
2080extern char *getauthinfo __P((int, bool *));
2081extern char *getcfname __P((void));
2082extern char *getextenv __P((const char *));
2083extern int getdtsize __P((void));
2084extern BITMAP256 *getrequests __P((ENVELOPE *));
2085extern char *getvendor __P((int));
2086extern void help __P((char *, ENVELOPE *));
2087extern void init_md __P((int, char **));
2088extern void initdaemon __P((void));
2089extern void inithostmaps __P((void));
2090extern void initmacros __P((ENVELOPE *));
2091extern void initsetproctitle __P((int, char **, char **));
2092extern void init_vendor_macros __P((ENVELOPE *));
2093extern SIGFUNC_DECL intsig __P((int));
2094extern bool isloopback __P((SOCKADDR sa));
2095extern void load_if_names __P((void));
2096extern bool lockfile __P((int, char *, char *, int));
2097extern void log_sendmail_pid __P((ENVELOPE *));
2098extern char lower __P((int));
2099extern void makelower __P((char *));
2100extern int makeconnection_ds __P((char *, MCI *));
2101extern int makeconnection __P((char *, volatile u_int, MCI *, ENVELOPE *));
2102extern char * munchstring __P((char *, char **, int));
2103extern struct hostent *myhostname __P((char *, int));
2104extern char *nisplus_default_domain __P((void)); /* extern for Sun */
2105extern bool path_is_dir __P((char *, bool));
2106extern char *pintvl __P((time_t, bool));
2107extern void printav __P((char **));
2108extern void printmailer __P((MAILER *));
2109extern void printopenfds __P((bool));
2110extern void printqueue __P((void));
2111extern void printrules __P((void));
2112extern pid_t prog_open __P((char **, int *, ENVELOPE *));
2113extern void putline __P((char *, MCI *));
2114extern void putxline __P((char *, size_t, MCI *, int));
2115extern void queueup_macros __P((int, FILE *, ENVELOPE *));
2116extern void readcf __P((char *, bool, ENVELOPE *));
2117extern SIGFUNC_DECL reapchild __P((int));
2118extern int releasesignal __P((int));
2119extern void resetlimits __P((void));
2120extern bool rfc822_string __P((char *));
2121extern FILE *safefopen __P((char *, int, int, long));
2122extern void savemail __P((ENVELOPE *, bool));
2123extern void seed_random __P((void));
2124extern void sendtoargv __P((char **, ENVELOPE *));
2125extern void setclientoptions __P((char *));
2126extern bool setdaemonoptions __P((char *));
2127extern void setdefaults __P((ENVELOPE *));
2128extern void setdefuser __P((void));
2129extern bool setvendor __P((char *));
2130extern void setoption __P((int, char *, bool, bool, ENVELOPE *));
2131extern sigfunc_t setsignal __P((int, sigfunc_t));
2132extern void setuserenv __P((const char *, const char *));
2133extern void settime __P((ENVELOPE *));
2134extern char *sfgets __P((char *, int, FILE *, time_t, char *));
2135extern char *shortenstring __P((const char *, int));
2136extern char *shorten_hostname __P((char []));
2137extern bool shorten_rfc822_string __P((char *, size_t));
2138extern void shutdown_daemon __P((void));
2139extern void sm_dopr __P((char *, const char *, va_list));
2140extern void sm_free __P((void *));
2141extern struct hostent *sm_gethostbyname __P((char *, int));
2142extern struct hostent *sm_gethostbyaddr __P((char *, int, int));
2143extern int sm_getla __P((ENVELOPE *));
2144extern struct passwd *sm_getpwnam __P((char *));
2145extern struct passwd *sm_getpwuid __P((UID_T));
2146extern void sm_setproctitle __P((bool, ENVELOPE *, const char *, ...));
2147extern SIGFUNC_DECL sm_signal_noop __P((int));
2148extern int sm_strcasecmp __P((const char *, const char *));
2149extern void stop_sendmail __P((void));
2150extern bool strcontainedin __P((char *, char *));
2151extern void stripquotes __P((char *));
2152extern int switch_map_find __P((char *, char *[], short []));
2153extern bool transienterror __P((int));
2154extern void tTflag __P((char *));
2155extern void tTsetup __P((u_char *, int, char *));
2156extern char *ttypath __P((void));
2157extern void unlockqueue __P((ENVELOPE *));
2158#if !HASUNSETENV
2159extern void unsetenv __P((char *));
2160#endif /* !HASUNSETENV */
2161extern char *username __P((void));
2162extern bool usershellok __P((char *, char *));
2163extern void vendor_post_defaults __P((ENVELOPE *));
2164extern void vendor_pre_defaults __P((ENVELOPE *));
2165extern int waitfor __P((pid_t));
2166extern bool writable __P((char *, ADDRESS *, long));
2167extern char *xalloc __P((int));
2168extern char *xcalloc __P((size_t, size_t));
2169extern char *xrealloc __P((void *, size_t));
2170extern void xputs __P((const char *));
2171extern char *xtextify __P((char *, char *));
2172extern bool xtextok __P((char *));
2173extern void xunlink __P((char *));
2174extern char *xuntextify __P((char *));
2175#endif /* _SENDMAIL_H */