source: trunk/third/sendmail/sendmail/sendmail.h @ 22421

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