138032Speter/* 2261363Sgshapiro * Copyright (c) 1998-2013 Proofpoint, Inc. and its suppliers. 364562Sgshapiro * All rights reserved. 438032Speter * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. 538032Speter * Copyright (c) 1988, 1993 638032Speter * The Regents of the University of California. All rights reserved. 738032Speter * 838032Speter * By using this file, you agree to the terms and conditions set 938032Speter * forth in the LICENSE file which can be found at the top level of 1038032Speter * the sendmail distribution. 1138032Speter */ 1238032Speter 1338032Speter/* 1464562Sgshapiro** SENDMAIL.H -- MTA-specific definitions for sendmail. 1538032Speter*/ 1638032Speter 1764562Sgshapiro#ifndef _SENDMAIL_H 1890792Sgshapiro# define _SENDMAIL_H 1 1964562Sgshapiro 20132943Sgshapiro#ifndef MILTER 21132943Sgshapiro# define MILTER 1 /* turn on MILTER by default */ 22132943Sgshapiro#endif /* MILTER */ 23132943Sgshapiro 2464562Sgshapiro#ifdef _DEFINE 2538032Speter# define EXTERN 2664562Sgshapiro#else /* _DEFINE */ 2738032Speter# define EXTERN extern 2864562Sgshapiro#endif /* _DEFINE */ 2938032Speter 3064562Sgshapiro 3164562Sgshapiro#include <unistd.h> 3264562Sgshapiro 3364562Sgshapiro#include <stddef.h> 3464562Sgshapiro#include <stdlib.h> 3590792Sgshapiro#include <stdio.h> 3664562Sgshapiro#include <ctype.h> 3764562Sgshapiro#include <setjmp.h> 3864562Sgshapiro#include <string.h> 3964562Sgshapiro#include <time.h> 4038032Speter# ifdef EX_OK 4138032Speter# undef EX_OK /* for SVr4.2 SMP */ 4264562Sgshapiro# endif /* EX_OK */ 4338032Speter 4464562Sgshapiro#include "sendmail/sendmail.h" 4590792Sgshapiro 4690792Sgshapiro/* profiling? */ 4790792Sgshapiro#if MONCONTROL 4890792Sgshapiro# define SM_PROF(x) moncontrol(x) 4990792Sgshapiro#else /* MONCONTROL */ 5090792Sgshapiro# define SM_PROF(x) 5190792Sgshapiro#endif /* MONCONTROL */ 5290792Sgshapiro 5390792Sgshapiro#ifdef _DEFINE 5490792Sgshapiro# ifndef lint 55266692SgshapiroSM_UNUSED(static char SmailId[]) = "@(#)$Id: sendmail.h,v 8.1104 2013-11-22 20:51:56 ca Exp $"; 5690792Sgshapiro# endif /* ! lint */ 5790792Sgshapiro#endif /* _DEFINE */ 5890792Sgshapiro 5964562Sgshapiro#include "bf.h" 6064562Sgshapiro#include "timers.h" 6190792Sgshapiro#include <sm/exc.h> 6290792Sgshapiro#include <sm/heap.h> 6390792Sgshapiro#include <sm/debug.h> 6490792Sgshapiro#include <sm/rpool.h> 6590792Sgshapiro#include <sm/io.h> 6690792Sgshapiro#include <sm/path.h> 6790792Sgshapiro#include <sm/signal.h> 6890792Sgshapiro#include <sm/clock.h> 6990792Sgshapiro#include <sm/mbdb.h> 7090792Sgshapiro#include <sm/errstring.h> 7190792Sgshapiro#include <sm/sysexits.h> 7290792Sgshapiro#include <sm/shm.h> 73168515Sgshapiro#include <sm/misc.h> 7438032Speter 7564562Sgshapiro#ifdef LOG 7638032Speter# include <syslog.h> 7764562Sgshapiro#endif /* LOG */ 7838032Speter 7964562Sgshapiro 8064562Sgshapiro 8164562Sgshapiro# if NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25 8264562Sgshapiro# include <sys/socket.h> 8364562Sgshapiro# endif /* NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25 */ 8438032Speter# if NETUNIX 8564562Sgshapiro# include <sys/un.h> 8664562Sgshapiro# endif /* NETUNIX */ 8764562Sgshapiro# if NETINET || NETINET6 8864562Sgshapiro# include <netinet/in.h> 8964562Sgshapiro# endif /* NETINET || NETINET6 */ 9064562Sgshapiro# if NETINET6 9164562Sgshapiro/* 9264562Sgshapiro** There is no standard yet for IPv6 includes. 9364562Sgshapiro** Specify OS specific implementation in conf.h 9464562Sgshapiro*/ 9564562Sgshapiro# endif /* NETINET6 */ 9638032Speter# if NETISO 9764562Sgshapiro# include <netiso/iso.h> 9864562Sgshapiro# endif /* NETISO */ 9938032Speter# if NETNS 10064562Sgshapiro# include <netns/ns.h> 10164562Sgshapiro# endif /* NETNS */ 10238032Speter# if NETX25 10364562Sgshapiro# include <netccitt/x25.h> 10464562Sgshapiro# endif /* NETX25 */ 10538032Speter 10664562Sgshapiro# if NAMED_BIND 10764562Sgshapiro# include <arpa/nameser.h> 10864562Sgshapiro# ifdef NOERROR 10964562Sgshapiro# undef NOERROR /* avoid <sys/streams.h> conflict */ 11064562Sgshapiro# endif /* NOERROR */ 11164562Sgshapiro# include <resolv.h> 11290792Sgshapiro# else /* NAMED_BIND */ 11390792Sgshapiro# undef SM_SET_H_ERRNO 11490792Sgshapiro# define SM_SET_H_ERRNO(err) 11564562Sgshapiro# endif /* NAMED_BIND */ 11638032Speter 11790792Sgshapiro# if HESIOD 11864562Sgshapiro# include <hesiod.h> 11964562Sgshapiro# if !defined(HES_ER_OK) || defined(HESIOD_INTERFACES) 12064562Sgshapiro# define HESIOD_INIT /* support for the new interface */ 12164562Sgshapiro# endif /* !defined(HES_ER_OK) || defined(HESIOD_INTERFACES) */ 12264562Sgshapiro# endif /* HESIOD */ 12338032Speter 12464562Sgshapiro#if STARTTLS 12564562Sgshapiro# include <openssl/ssl.h> 12690792Sgshapiro# if !TLS_NO_RSA 127249729Sgshapiro# if _FFR_FIPSMODE 128249729Sgshapiro# define RSA_KEYLENGTH 1024 129249729Sgshapiro# else /* _FFR_FIPSMODE */ 130249729Sgshapiro# define RSA_KEYLENGTH 512 131249729Sgshapiro# endif /* _FFR_FIPSMODE */ 13290792Sgshapiro# endif /* !TLS_NO_RSA */ 13364562Sgshapiro#endif /* STARTTLS */ 13464562Sgshapiro 13564562Sgshapiro#if SASL /* include the sasl include files if we have them */ 13698121Sgshapiro 13798121Sgshapiro 13898121Sgshapiro# if SASL == 2 || SASL >= 20000 13998121Sgshapiro# include <sasl/sasl.h> 140225906Sume# include <sasl/saslplug.h> 14198121Sgshapiro# include <sasl/saslutil.h> 142225906Sume# if SASL_VERSION_FULL < 0x020119 143225906Sumetypedef int (*sasl_callback_ft)(void); 144261363Sgshapiro# endif /* SASL_VERSION_FULL < 0x020119 */ 14598121Sgshapiro# else /* SASL == 2 || SASL >= 20000 */ 14698121Sgshapiro# include <sasl.h> 14798121Sgshapiro# include <saslutil.h> 148225906Sumetypedef int (*sasl_callback_ft)(void); 14998121Sgshapiro# endif /* SASL == 2 || SASL >= 20000 */ 15064562Sgshapiro# if defined(SASL_VERSION_MAJOR) && defined(SASL_VERSION_MINOR) && defined(SASL_VERSION_STEP) 15164562Sgshapiro# define SASL_VERSION (SASL_VERSION_MAJOR * 10000) + (SASL_VERSION_MINOR * 100) + SASL_VERSION_STEP 15298121Sgshapiro# if SASL == 1 || SASL == 2 15364562Sgshapiro# undef SASL 15464562Sgshapiro# define SASL SASL_VERSION 15598121Sgshapiro# else /* SASL == 1 || SASL == 2 */ 15664562Sgshapiro# if SASL != SASL_VERSION 15764562Sgshapiro ERROR README: -DSASL (SASL) does not agree with the version of the CYRUS_SASL library (SASL_VERSION) 15864562Sgshapiro ERROR README: see README! 15964562Sgshapiro# endif /* SASL != SASL_VERSION */ 16098121Sgshapiro# endif /* SASL == 1 || SASL == 2 */ 16164562Sgshapiro# else /* defined(SASL_VERSION_MAJOR) && defined(SASL_VERSION_MINOR) && defined(SASL_VERSION_STEP) */ 16264562Sgshapiro# if SASL == 1 16364562Sgshapiro ERROR README: please set -DSASL to the version of the CYRUS_SASL library 16464562Sgshapiro ERROR README: see README! 16564562Sgshapiro# endif /* SASL == 1 */ 16664562Sgshapiro# endif /* defined(SASL_VERSION_MAJOR) && defined(SASL_VERSION_MINOR) && defined(SASL_VERSION_STEP) */ 16764562Sgshapiro#endif /* SASL */ 16864562Sgshapiro 16938032Speter/* 17038032Speter** Following are "sort of" configuration constants, but they should 17138032Speter** be pretty solid on most architectures today. They have to be 17238032Speter** defined after <arpa/nameser.h> because some versions of that 17338032Speter** file also define them. In all cases, we can't use sizeof because 17438032Speter** some systems (e.g., Crays) always treat everything as being at 17538032Speter** least 64 bits. 17638032Speter*/ 17738032Speter 17838032Speter#ifndef INADDRSZ 17938032Speter# define INADDRSZ 4 /* size of an IPv4 address in bytes */ 18064562Sgshapiro#endif /* ! INADDRSZ */ 18164562Sgshapiro#ifndef IN6ADDRSZ 18264562Sgshapiro# define IN6ADDRSZ 16 /* size of an IPv6 address in bytes */ 18364562Sgshapiro#endif /* ! IN6ADDRSZ */ 18438032Speter#ifndef INT16SZ 18538032Speter# define INT16SZ 2 /* size of a 16 bit integer in bytes */ 18664562Sgshapiro#endif /* ! INT16SZ */ 18738032Speter#ifndef INT32SZ 18838032Speter# define INT32SZ 4 /* size of a 32 bit integer in bytes */ 18964562Sgshapiro#endif /* ! INT32SZ */ 19073188Sgshapiro#ifndef INADDR_LOOPBACK 19173188Sgshapiro# define INADDR_LOOPBACK 0x7f000001 /* loopback address */ 19273188Sgshapiro#endif /* ! INADDR_LOOPBACK */ 19338032Speter 19464562Sgshapiro/* 19564562Sgshapiro** Error return from inet_addr(3), in case not defined in /usr/include. 19664562Sgshapiro*/ 19738032Speter 19864562Sgshapiro#ifndef INADDR_NONE 19964562Sgshapiro# define INADDR_NONE 0xffffffff 20064562Sgshapiro#endif /* ! INADDR_NONE */ 20138032Speter 20264562Sgshapiro 203120256Sgshapiro/* (f)open() modes for queue files */ 204120256Sgshapiro# define QF_O_EXTRA 0 205120256Sgshapiro 206120256Sgshapiro 20790792Sgshapiro/* 20890792Sgshapiro** An 'argument class' describes the storage allocation status 20990792Sgshapiro** of an object pointed to by an argument to a function. 21090792Sgshapiro*/ 21190792Sgshapiro 21290792Sgshapirotypedef enum 21390792Sgshapiro{ 21490792Sgshapiro A_HEAP, /* the storage was allocated by malloc, and the 21590792Sgshapiro * ownership of the storage is ceded by the caller 21690792Sgshapiro * to the called function. */ 21790792Sgshapiro A_TEMP, /* The storage is temporary, and is only guaranteed 21890792Sgshapiro * to be valid for the duration of the function call. */ 21990792Sgshapiro A_PERM /* The storage is 'permanent': this might mean static 22090792Sgshapiro * storage, or rpool storage. */ 22190792Sgshapiro} ARGCLASS_T; 22290792Sgshapiro 22338032Speter/* forward references for prototypes */ 22438032Spetertypedef struct envelope ENVELOPE; 22538032Spetertypedef struct mailer MAILER; 22690792Sgshapirotypedef struct queuegrp QUEUEGRP; 22738032Speter 22890792Sgshapiro/* 22938032Speter** Address structure. 23038032Speter** Addresses are stored internally in this structure. 23138032Speter*/ 23238032Speter 23338032Speterstruct address 23438032Speter{ 23538032Speter char *q_paddr; /* the printname for the address */ 23638032Speter char *q_user; /* user name */ 23738032Speter char *q_ruser; /* real user name, or NULL if q_user */ 23838032Speter char *q_host; /* host name */ 23938032Speter struct mailer *q_mailer; /* mailer to use */ 24090792Sgshapiro unsigned long q_flags; /* status flags, see below */ 24138032Speter uid_t q_uid; /* user-id of receiver (if known) */ 24238032Speter gid_t q_gid; /* group-id of receiver (if known) */ 24338032Speter char *q_home; /* home dir (local mailer only) */ 24438032Speter char *q_fullname; /* full name if known */ 24538032Speter struct address *q_next; /* chain */ 24638032Speter struct address *q_alias; /* address this results from */ 24738032Speter char *q_owner; /* owner of q_alias */ 24838032Speter struct address *q_tchain; /* temporary use chain */ 24990792Sgshapiro#if PIPELINING 25090792Sgshapiro struct address *q_pchain; /* chain for pipelining */ 25190792Sgshapiro#endif /* PIPELINING */ 25290792Sgshapiro char *q_finalrcpt; /* Final-Recipient: DSN header */ 25338032Speter char *q_orcpt; /* ORCPT parameter from RCPT TO: line */ 25438032Speter char *q_status; /* status code for DSNs */ 25538032Speter char *q_rstatus; /* remote status message for DSNs */ 25638032Speter time_t q_statdate; /* date of status messages */ 25738032Speter char *q_statmta; /* MTA generating q_rstatus */ 25864562Sgshapiro short q_state; /* address state, see below */ 25990792Sgshapiro char *q_signature; /* MX-based sorting value */ 26090792Sgshapiro int q_qgrp; /* index into queue groups */ 26190792Sgshapiro int q_qdir; /* queue directory inside group */ 26290792Sgshapiro char *q_message; /* error message */ 26338032Speter}; 26438032Speter 26538032Spetertypedef struct address ADDRESS; 26638032Speter 26764562Sgshapiro/* bit values for q_flags */ 26864562Sgshapiro#define QGOODUID 0x00000001 /* the q_uid q_gid fields are good */ 26964562Sgshapiro#define QPRIMARY 0x00000002 /* set from RCPT or argv */ 27064562Sgshapiro#define QNOTREMOTE 0x00000004 /* address not for remote forwarding */ 27164562Sgshapiro#define QSELFREF 0x00000008 /* this address references itself */ 27264562Sgshapiro#define QBOGUSSHELL 0x00000010 /* user has no valid shell listed */ 27364562Sgshapiro#define QUNSAFEADDR 0x00000020 /* address acquired via unsafe path */ 27464562Sgshapiro#define QPINGONSUCCESS 0x00000040 /* give return on successful delivery */ 27564562Sgshapiro#define QPINGONFAILURE 0x00000080 /* give return on failure */ 27664562Sgshapiro#define QPINGONDELAY 0x00000100 /* give return on message delay */ 27790792Sgshapiro#define QHASNOTIFY 0x00000200 /* propagate notify parameter */ 27864562Sgshapiro#define QRELAYED 0x00000400 /* DSN: relayed to non-DSN aware sys */ 27964562Sgshapiro#define QEXPANDED 0x00000800 /* DSN: undergone list expansion */ 28064562Sgshapiro#define QDELIVERED 0x00001000 /* DSN: successful final delivery */ 28164562Sgshapiro#define QDELAYED 0x00002000 /* DSN: message delayed */ 28264562Sgshapiro#define QALIAS 0x00004000 /* expanded alias */ 28390792Sgshapiro#define QBYTRACE 0x00008000 /* DeliverBy: trace */ 28490792Sgshapiro#define QBYNDELAY 0x00010000 /* DeliverBy: notify, delay */ 28590792Sgshapiro#define QBYNRELAY 0x00020000 /* DeliverBy: notify, relayed */ 28664562Sgshapiro#define QTHISPASS 0x40000000 /* temp: address set this pass */ 28764562Sgshapiro#define QRCPTOK 0x80000000 /* recipient() processed address */ 28838032Speter 28964562Sgshapiro#define Q_PINGFLAGS (QPINGONSUCCESS|QPINGONFAILURE|QPINGONDELAY) 29038032Speter 29164562Sgshapiro/* values for q_state */ 29264562Sgshapiro#define QS_OK 0 /* address ok (for now)/not yet tried */ 29364562Sgshapiro#define QS_SENT 1 /* good address, delivery complete */ 29464562Sgshapiro#define QS_BADADDR 2 /* illegal address */ 29564562Sgshapiro#define QS_QUEUEUP 3 /* save address in queue */ 29690792Sgshapiro#define QS_RETRY 4 /* retry delivery for next MX */ 29790792Sgshapiro#define QS_VERIFIED 5 /* verified, but not expanded */ 29838032Speter 29990792Sgshapiro/* 30090792Sgshapiro** Notice: all of the following values are variations of QS_DONTSEND. 30190792Sgshapiro** If new states are added, they must be inserted in the proper place! 30290792Sgshapiro** See the macro definition of QS_IS_DEAD() down below. 30390792Sgshapiro*/ 30490792Sgshapiro 30590792Sgshapiro#define QS_DONTSEND 6 /* don't send to this address */ 30690792Sgshapiro#define QS_EXPANDED 7 /* expanded */ 30790792Sgshapiro#define QS_SENDER 8 /* message sender (MeToo) */ 30890792Sgshapiro#define QS_CLONED 9 /* addr cloned to split envelope */ 30990792Sgshapiro#define QS_DISCARDED 10 /* rcpt discarded (EF_DISCARD) */ 31090792Sgshapiro#define QS_REPLACED 11 /* maplocaluser()/UserDB replaced */ 31190792Sgshapiro#define QS_REMOVED 12 /* removed (removefromlist()) */ 31290792Sgshapiro#define QS_DUPLICATE 13 /* duplicate suppressed */ 31390792Sgshapiro#define QS_INCLUDED 14 /* :include: delivery */ 314102528Sgshapiro#define QS_FATALERR 15 /* fatal error, don't deliver */ 31590792Sgshapiro 31664562Sgshapiro/* address state testing primitives */ 31764562Sgshapiro#define QS_IS_OK(s) ((s) == QS_OK) 31864562Sgshapiro#define QS_IS_SENT(s) ((s) == QS_SENT) 31964562Sgshapiro#define QS_IS_BADADDR(s) ((s) == QS_BADADDR) 32064562Sgshapiro#define QS_IS_QUEUEUP(s) ((s) == QS_QUEUEUP) 32190792Sgshapiro#define QS_IS_RETRY(s) ((s) == QS_RETRY) 32264562Sgshapiro#define QS_IS_VERIFIED(s) ((s) == QS_VERIFIED) 32364562Sgshapiro#define QS_IS_EXPANDED(s) ((s) == QS_EXPANDED) 32464562Sgshapiro#define QS_IS_REMOVED(s) ((s) == QS_REMOVED) 32564562Sgshapiro#define QS_IS_UNDELIVERED(s) ((s) == QS_OK || \ 32664562Sgshapiro (s) == QS_QUEUEUP || \ 32790792Sgshapiro (s) == QS_RETRY || \ 32864562Sgshapiro (s) == QS_VERIFIED) 32990792Sgshapiro#define QS_IS_UNMARKED(s) ((s) == QS_OK || \ 33090792Sgshapiro (s) == QS_RETRY) 33164562Sgshapiro#define QS_IS_SENDABLE(s) ((s) == QS_OK || \ 33290792Sgshapiro (s) == QS_QUEUEUP || \ 33390792Sgshapiro (s) == QS_RETRY) 33464562Sgshapiro#define QS_IS_ATTEMPTED(s) ((s) == QS_QUEUEUP || \ 33590792Sgshapiro (s) == QS_RETRY || \ 336173340Sgshapiro (s) == QS_SENT || \ 337173340Sgshapiro (s) == QS_DISCARDED) 33890792Sgshapiro#define QS_IS_DEAD(s) ((s) >= QS_DONTSEND) 339223067Sgshapiro#define QS_IS_TEMPFAIL(s) ((s) == QS_QUEUEUP || (s) == QS_RETRY) 34064562Sgshapiro 34164562Sgshapiro#define NULLADDR ((ADDRESS *) NULL) 34264562Sgshapiro 34364562Sgshapiroextern ADDRESS NullAddress; /* a null (template) address [main.c] */ 34464562Sgshapiro 34538032Speter/* functions */ 346168515Sgshapiroextern void cataddr __P((char **, char **, char *, int, int, bool)); 347111823Sgshapiroextern char *crackaddr __P((char *, ENVELOPE *)); 34864562Sgshapiroextern bool emptyaddr __P((ADDRESS *)); 34964562Sgshapiroextern ADDRESS *getctladdr __P((ADDRESS *)); 35064562Sgshapiroextern int include __P((char *, bool, ADDRESS *, ADDRESS **, int, ENVELOPE *)); 35190792Sgshapiroextern bool invalidaddr __P((char *, char *, bool)); 35290792Sgshapiroextern ADDRESS *parseaddr __P((char *, ADDRESS *, int, int, char **, 35390792Sgshapiro ENVELOPE *, bool)); 354132943Sgshapiroextern char **prescan __P((char *, int, char[], int, char **, unsigned char *, bool)); 355132943Sgshapiroextern void printaddr __P((SM_FILE_T *, ADDRESS *, bool)); 35638032Speterextern ADDRESS *recipient __P((ADDRESS *, ADDRESS **, int, ENVELOPE *)); 35764562Sgshapiroextern char *remotename __P((char *, MAILER *, int, int *, ENVELOPE *)); 35890792Sgshapiroextern int rewrite __P((char **, int, int, ENVELOPE *, int)); 35938032Speterextern bool sameaddr __P((ADDRESS *, ADDRESS *)); 36038032Speterextern int sendtolist __P((char *, ADDRESS *, ADDRESS **, int, ENVELOPE *)); 36190792Sgshapiro#if MILTER 36264562Sgshapiroextern int removefromlist __P((char *, ADDRESS **, ENVELOPE *)); 36390792Sgshapiro#endif /* MILTER */ 36464562Sgshapiroextern void setsender __P((char *, ENVELOPE *, char **, int, bool)); 365168515Sgshapirotypedef void esmtp_args_F __P((ADDRESS *, char *, char *, ENVELOPE *)); 366168515Sgshapiroextern void parse_esmtp_args __P((ENVELOPE *, ADDRESS *, char *, char *, 367168515Sgshapiro char *, char *args[], esmtp_args_F)); 368168515Sgshapiroextern esmtp_args_F mail_esmtp_args; 369168515Sgshapiroextern esmtp_args_F rcpt_esmtp_args; 370168515Sgshapiroextern void reset_mail_esmtp_args __P((ENVELOPE *)); 37164562Sgshapiro 37290792Sgshapiro/* macro to simplify the common call to rewrite() */ 37390792Sgshapiro#define REWRITE(pvp, rs, env) rewrite(pvp, rs, 0, env, MAXATOM) 37490792Sgshapiro 37590792Sgshapiro/* 376168515Sgshapiro** Token Tables for prescan 377168515Sgshapiro*/ 378168515Sgshapiro 379168515Sgshapiroextern unsigned char ExtTokenTab[256]; /* external strings */ 380168515Sgshapiroextern unsigned char IntTokenTab[256]; /* internal strings */ 381168515Sgshapiro 382168515Sgshapiro 383168515Sgshapiro/* 38438032Speter** Mailer definition structure. 38538032Speter** Every mailer known to the system is declared in this 38638032Speter** structure. It defines the pathname of the mailer, some 38738032Speter** flags associated with it, and the argument vector to 38838032Speter** pass to it. The flags are defined in conf.c 38938032Speter** 39038032Speter** The argument vector is expanded before actual use. All 39138032Speter** words except the first are passed through the macro 39238032Speter** processor. 39338032Speter*/ 39438032Speter 39538032Speterstruct mailer 39638032Speter{ 39738032Speter char *m_name; /* symbolic name of this mailer */ 39838032Speter char *m_mailer; /* pathname of the mailer to use */ 39938032Speter char *m_mtatype; /* type of this MTA */ 40038032Speter char *m_addrtype; /* type for addresses */ 40138032Speter char *m_diagtype; /* type for diagnostics */ 40264562Sgshapiro BITMAP256 m_flags; /* status flags, see below */ 40338032Speter short m_mno; /* mailer number internally */ 40438032Speter short m_nice; /* niceness to run at (mostly for prog) */ 40538032Speter char **m_argv; /* template argument vector */ 40638032Speter short m_sh_rwset; /* rewrite set: sender header addresses */ 40738032Speter short m_se_rwset; /* rewrite set: sender envelope addresses */ 40838032Speter short m_rh_rwset; /* rewrite set: recipient header addresses */ 40938032Speter short m_re_rwset; /* rewrite set: recipient envelope addresses */ 41038032Speter char *m_eol; /* end of line string */ 41138032Speter long m_maxsize; /* size limit on message to this mailer */ 41238032Speter int m_linelimit; /* max # characters per line */ 41364562Sgshapiro int m_maxdeliveries; /* max deliveries per mailer connection */ 41438032Speter char *m_execdir; /* directory to chdir to before execv */ 41564562Sgshapiro char *m_rootdir; /* directory to chroot to before execv */ 41638032Speter uid_t m_uid; /* UID to run as */ 41738032Speter gid_t m_gid; /* GID to run as */ 41838032Speter char *m_defcharset; /* default character set */ 41964562Sgshapiro time_t m_wait; /* timeout to wait for end */ 42064562Sgshapiro int m_maxrcpt; /* max recipients per envelope client-side */ 42190792Sgshapiro short m_qgrp; /* queue group for this mailer */ 42238032Speter}; 42338032Speter 42438032Speter/* bits for m_flags */ 42590792Sgshapiro#define M_ESMTP 'a' /* run Extended SMTP */ 42664562Sgshapiro#define M_ALIASABLE 'A' /* user can be LHS of an alias */ 42764562Sgshapiro#define M_BLANKEND 'b' /* ensure blank line at end of message */ 428141858Sgshapiro#define M_STRIPBACKSL 'B' /* strip all leading backslashes from user */ 42964562Sgshapiro#define M_NOCOMMENT 'c' /* don't include comment part of address */ 43064562Sgshapiro#define M_CANONICAL 'C' /* make addresses canonical "u@dom" */ 43164562Sgshapiro#define M_NOBRACKET 'd' /* never angle bracket envelope route-addrs */ 43238032Speter /* 'D' CF: include Date: */ 43364562Sgshapiro#define M_EXPENSIVE 'e' /* it costs to use this mailer.... */ 43464562Sgshapiro#define M_ESCFROM 'E' /* escape From lines to >From */ 43564562Sgshapiro#define M_FOPT 'f' /* mailer takes picky -f flag */ 43638032Speter /* 'F' CF: include From: or Resent-From: */ 43764562Sgshapiro#define M_NO_NULL_FROM 'g' /* sender of errors should be $g */ 43864562Sgshapiro#define M_HST_UPPER 'h' /* preserve host case distinction */ 43964562Sgshapiro#define M_PREHEAD 'H' /* MAIL11V3: preview headers */ 44064562Sgshapiro#define M_UDBENVELOPE 'i' /* do udbsender rewriting on envelope */ 44164562Sgshapiro#define M_INTERNAL 'I' /* SMTP to another sendmail site */ 44264562Sgshapiro#define M_UDBRECIPIENT 'j' /* do udbsender rewriting on recipient lines */ 44364562Sgshapiro#define M_NOLOOPCHECK 'k' /* don't check for loops in HELO command */ 44464562Sgshapiro#define M_CHUNKING 'K' /* CHUNKING: reserved for future use */ 44564562Sgshapiro#define M_LOCALMAILER 'l' /* delivery is to this host */ 44664562Sgshapiro#define M_LIMITS 'L' /* must enforce SMTP line limits */ 44764562Sgshapiro#define M_MUSER 'm' /* can handle multiple users at once */ 44838032Speter /* 'M' CF: include Message-Id: */ 44964562Sgshapiro#define M_NHDR 'n' /* don't insert From line */ 45064562Sgshapiro#define M_MANYSTATUS 'N' /* MAIL11V3: DATA returns multi-status */ 45164562Sgshapiro#define M_RUNASRCPT 'o' /* always run mailer as recipient */ 45264562Sgshapiro#define M_FROMPATH 'p' /* use reverse-path in MAIL FROM: */ 45338032Speter /* 'P' CF: include Return-Path: */ 45464562Sgshapiro#define M_VRFY250 'q' /* VRFY command returns 250 instead of 252 */ 45564562Sgshapiro#define M_ROPT 'r' /* mailer takes picky -r flag */ 45664562Sgshapiro#define M_SECURE_PORT 'R' /* try to send on a reserved TCP port */ 45764562Sgshapiro#define M_STRIPQ 's' /* strip quote chars from user/host */ 45864562Sgshapiro#define M_SPECIFIC_UID 'S' /* run as specific uid/gid */ 45964562Sgshapiro#define M_USR_UPPER 'u' /* preserve user case distinction */ 46064562Sgshapiro#define M_UGLYUUCP 'U' /* this wants an ugly UUCP from line */ 46164562Sgshapiro#define M_CONTENT_LEN 'v' /* add Content-Length: header (SVr4) */ 46238032Speter /* 'V' UIUC: !-relativize all addresses */ 46364562Sgshapiro#define M_HASPWENT 'w' /* check for /etc/passwd entry */ 464132943Sgshapiro#define M_NOHOSTSTAT 'W' /* ignore long term host status information */ 46538032Speter /* 'x' CF: include Full-Name: */ 46664562Sgshapiro#define M_XDOT 'X' /* use hidden-dot algorithm */ 46764562Sgshapiro#define M_LMTP 'z' /* run Local Mail Transport Protocol */ 46890792Sgshapiro#define M_DIALDELAY 'Z' /* apply dial delay sleeptime */ 46964562Sgshapiro#define M_NOMX '0' /* turn off MX lookups */ 47064562Sgshapiro#define M_NONULLS '1' /* don't send null bytes */ 47190792Sgshapiro#define M_FSMTP '2' /* force SMTP (no ESMTP even if offered) */ 47264562Sgshapiro#define M_EBCDIC '3' /* extend Q-P encoding for EBCDIC */ 47364562Sgshapiro#define M_TRYRULESET5 '5' /* use ruleset 5 after local aliasing */ 47464562Sgshapiro#define M_7BITHDRS '6' /* strip headers to 7 bits even in 8 bit path */ 47564562Sgshapiro#define M_7BITS '7' /* use 7-bit path */ 47664562Sgshapiro#define M_8BITS '8' /* force "just send 8" behaviour */ 47764562Sgshapiro#define M_MAKE8BIT '9' /* convert 7 -> 8 bit if appropriate */ 47864562Sgshapiro#define M_CHECKINCLUDE ':' /* check for :include: files */ 47964562Sgshapiro#define M_CHECKPROG '|' /* check for |program addresses */ 48064562Sgshapiro#define M_CHECKFILE '/' /* check for /file addresses */ 48164562Sgshapiro#define M_CHECKUDB '@' /* user can be user database key */ 48264562Sgshapiro#define M_CHECKHDIR '~' /* SGI: check for valid home directory */ 48364562Sgshapiro#define M_HOLD '%' /* Hold delivery until ETRN/-qI/-qR/-qS */ 48464562Sgshapiro#define M_PLUS '+' /* Reserved: Used in mc for adding new flags */ 48564562Sgshapiro#define M_MINUS '-' /* Reserved: Used in mc for removing flags */ 486261363Sgshapiro#define M_NOMHHACK '!' /* Don't perform HM hack dropping explicit from */ 48738032Speter 48864562Sgshapiro/* functions */ 48964562Sgshapiroextern void initerrmailers __P((void)); 49064562Sgshapiroextern void makemailer __P((char *)); 49190792Sgshapiroextern void makequeue __P((char *, bool)); 492141858Sgshapiroextern void runqueueevent __P((int)); 49394334Sgshapiro#if _FFR_QUEUE_RUN_PARANOIA 49494334Sgshapiroextern bool checkqueuerunner __P((void)); 49594334Sgshapiro#endif /* _FFR_QUEUE_RUN_PARANOIA */ 49638032Speter 49790792SgshapiroEXTERN MAILER *FileMailer; /* ptr to *file* mailer */ 49890792SgshapiroEXTERN MAILER *InclMailer; /* ptr to *include* mailer */ 49990792SgshapiroEXTERN MAILER *LocalMailer; /* ptr to local mailer */ 50090792SgshapiroEXTERN MAILER *ProgMailer; /* ptr to program mailer */ 50190792SgshapiroEXTERN MAILER *Mailer[MAXMAILERS + 1]; 50290792Sgshapiro 50390792Sgshapiro/* 50490792Sgshapiro** Queue group definition structure. 50590792Sgshapiro** Every queue group known to the system is declared in this structure. 50690792Sgshapiro** It defines the basic pathname of the queue group, some flags 50790792Sgshapiro** associated with it, and the argument vector to pass to it. 50890792Sgshapiro*/ 50990792Sgshapiro 51090792Sgshapirostruct qpaths_s 51190792Sgshapiro{ 51290792Sgshapiro char *qp_name; /* name of queue dir, relative path */ 51390792Sgshapiro short qp_subdirs; /* use subdirs? */ 51490792Sgshapiro short qp_fsysidx; /* file system index of this directory */ 51590792Sgshapiro# if SM_CONF_SHM 51690792Sgshapiro int qp_idx; /* index into array for queue information */ 51790792Sgshapiro# endif /* SM_CONF_SHM */ 51890792Sgshapiro}; 51990792Sgshapiro 52090792Sgshapirotypedef struct qpaths_s QPATHS; 52190792Sgshapiro 52290792Sgshapirostruct queuegrp 52390792Sgshapiro{ 52490792Sgshapiro char *qg_name; /* symbolic name of this queue group */ 52590792Sgshapiro 52690792Sgshapiro /* 52790792Sgshapiro ** For now this is the same across all queue groups. 52890792Sgshapiro ** Otherwise we have to play around with chdir(). 52990792Sgshapiro */ 53090792Sgshapiro 53190792Sgshapiro char *qg_qdir; /* common component of queue directory */ 53290792Sgshapiro short qg_index; /* queue number internally, index in Queue[] */ 53390792Sgshapiro int qg_maxqrun; /* max # of jobs in 1 queuerun */ 53490792Sgshapiro int qg_numqueues; /* number of queues in this queue */ 53590792Sgshapiro 53690792Sgshapiro /* 53790792Sgshapiro ** qg_queueintvl == 0 denotes that no individual value is used. 53890792Sgshapiro ** Whatever accesses this must deal with "<= 0" as 53990792Sgshapiro ** "not set, use appropriate default". 54090792Sgshapiro */ 54190792Sgshapiro 54290792Sgshapiro time_t qg_queueintvl; /* interval for queue runs */ 54390792Sgshapiro QPATHS *qg_qpaths; /* list of queue directories */ 54490792Sgshapiro BITMAP256 qg_flags; /* status flags, see below */ 54590792Sgshapiro short qg_nice; /* niceness for queue run */ 54690792Sgshapiro int qg_wgrp; /* Assigned to this work group */ 54790792Sgshapiro int qg_maxlist; /* max items in work queue for this group */ 54890792Sgshapiro int qg_curnum; /* current number of queue for queue runs */ 54990792Sgshapiro int qg_maxrcpt; /* max recipients per envelope, 0==no limit */ 55090792Sgshapiro 55194334Sgshapiro time_t qg_nextrun; /* time for next queue runs */ 55294334Sgshapiro#if _FFR_QUEUE_GROUP_SORTORDER 55394334Sgshapiro short qg_sortorder; /* how do we sort this queuerun */ 55494334Sgshapiro#endif /* _FFR_QUEUE_GROUP_SORTORDER */ 55590792Sgshapiro#if 0 55690792Sgshapiro long qg_wkrcptfact; /* multiplier for # recipients -> priority */ 55790792Sgshapiro long qg_qfactor; /* slope of queue function */ 55890792Sgshapiro bool qg_doqueuerun; /* XXX flag is it time to do a queuerun */ 55990792Sgshapiro#endif /* 0 */ 56090792Sgshapiro}; 56190792Sgshapiro 56290792Sgshapiro/* bits for qg_flags (XXX: unused as of now) */ 56390792Sgshapiro#define QD_DEFINED ((char) 1) /* queue group has been defined */ 56490792Sgshapiro#define QD_FORK 'f' /* fork queue runs */ 56590792Sgshapiro 56690792Sgshapiroextern void filesys_update __P((void)); 56790792Sgshapiro#if _FFR_ANY_FREE_FS 56890792Sgshapiroextern bool filesys_free __P((long)); 56990792Sgshapiro#endif /* _FFR_ANY_FREE_FS */ 57090792Sgshapiro 57190792Sgshapiro#if SASL 57290792Sgshapiro/* 57390792Sgshapiro** SASL 57490792Sgshapiro*/ 57590792Sgshapiro 57690792Sgshapiro/* lines in authinfo file or index into SASL_AI_T */ 57790792Sgshapiro# define SASL_WRONG (-1) 57890792Sgshapiro# define SASL_USER 0 /* authorization id (user) */ 57990792Sgshapiro# define SASL_AUTHID 1 /* authentication id */ 58090792Sgshapiro# define SASL_PASSWORD 2 /* password fuer authid */ 58190792Sgshapiro# define SASL_DEFREALM 3 /* realm to use */ 58290792Sgshapiro# define SASL_MECHLIST 4 /* list of mechanisms to try */ 58390792Sgshapiro# define SASL_ID_REALM 5 /* authid@defrealm */ 58490792Sgshapiro 58590792Sgshapiro/* 58690792Sgshapiro** Current mechanism; this is just used to convey information between 58790792Sgshapiro** invocation of SASL callback functions. 58890792Sgshapiro** It must be last in the list, because it's not allocated by us 58990792Sgshapiro** and hence we don't free() it. 59090792Sgshapiro*/ 59190792Sgshapiro# define SASL_MECH 6 59290792Sgshapiro# define SASL_ENTRIES 7 /* number of entries in array */ 59390792Sgshapiro 59490792Sgshapiro# define SASL_USER_BIT (1 << SASL_USER) 59590792Sgshapiro# define SASL_AUTHID_BIT (1 << SASL_AUTHID) 59690792Sgshapiro# define SASL_PASSWORD_BIT (1 << SASL_PASSWORD) 59790792Sgshapiro# define SASL_DEFREALM_BIT (1 << SASL_DEFREALM) 59890792Sgshapiro# define SASL_MECHLIST_BIT (1 << SASL_MECHLIST) 59990792Sgshapiro 60090792Sgshapiro/* authenticated? */ 60190792Sgshapiro# define SASL_NOT_AUTH 0 /* not authenticated */ 60290792Sgshapiro# define SASL_PROC_AUTH 1 /* in process of authenticating */ 60390792Sgshapiro# define SASL_IS_AUTH 2 /* authenticated */ 60490792Sgshapiro 60590792Sgshapiro/* SASL options */ 60690792Sgshapiro# define SASL_AUTH_AUTH 0x1000 /* use auth= only if authenticated */ 60798121Sgshapiro# if SASL >= 20101 60898121Sgshapiro# define SASL_SEC_MASK SASL_SEC_MAXIMUM /* mask for SASL_SEC_* values: sasl.h */ 60998121Sgshapiro# else /* SASL >= 20101 */ 61098121Sgshapiro# define SASL_SEC_MASK 0x0fff /* mask for SASL_SEC_* values: sasl.h */ 61198121Sgshapiro# if (SASL_SEC_NOPLAINTEXT & SASL_SEC_MASK) == 0 || \ 61290792Sgshapiro (SASL_SEC_NOACTIVE & SASL_SEC_MASK) == 0 || \ 61390792Sgshapiro (SASL_SEC_NODICTIONARY & SASL_SEC_MASK) == 0 || \ 61490792Sgshapiro (SASL_SEC_FORWARD_SECRECY & SASL_SEC_MASK) == 0 || \ 61590792Sgshapiro (SASL_SEC_NOANONYMOUS & SASL_SEC_MASK) == 0 || \ 61690792Sgshapiro (SASL_SEC_PASS_CREDENTIALS & SASL_SEC_MASK) == 0 61790792SgshapiroERROR: change SASL_SEC_MASK_ notify sendmail.org! 61890792Sgshapiro# endif /* SASL_SEC_NOPLAINTEXT & SASL_SEC_MASK) == 0 ... */ 61998121Sgshapiro# endif /* SASL >= 20101 */ 620203004Sgshapiro# define MAXOUTLEN 8192 /* length of output buffer, should be 2^n */ 62190792Sgshapiro 62290792Sgshapiro/* functions */ 62390792Sgshapiroextern char *intersect __P((char *, char *, SM_RPOOL_T *)); 62490792Sgshapiroextern char *iteminlist __P((char *, char *, char *)); 62598121Sgshapiro# if SASL >= 20000 62698121Sgshapiroextern int proxy_policy __P((sasl_conn_t *, void *, const char *, unsigned, const char *, unsigned, const char *, unsigned, struct propctx *)); 62798121Sgshapiroextern int safesaslfile __P((void *, const char *, sasl_verify_type_t)); 62898121Sgshapiro# else /* SASL >= 20000 */ 62990792Sgshapiroextern int proxy_policy __P((void *, const char *, const char *, const char **, const char **)); 63098121Sgshapiro# if SASL > 10515 63190792Sgshapiroextern int safesaslfile __P((void *, char *, int)); 63298121Sgshapiro# else /* SASL > 10515 */ 63390792Sgshapiroextern int safesaslfile __P((void *, char *)); 63498121Sgshapiro# endif /* SASL > 10515 */ 63598121Sgshapiro# endif /* SASL >= 20000 */ 63690792Sgshapiroextern void stop_sasl_client __P((void)); 63790792Sgshapiro 63890792Sgshapiro/* structure to store authinfo */ 63990792Sgshapirotypedef char *SASL_AI_T[SASL_ENTRIES]; 64090792Sgshapiro 64190792SgshapiroEXTERN char *AuthMechanisms; /* AUTH mechanisms */ 642132943SgshapiroEXTERN char *AuthRealm; /* AUTH realm */ 64390792SgshapiroEXTERN char *SASLInfo; /* file with AUTH info */ 64490792SgshapiroEXTERN int SASLOpts; /* options for SASL */ 64590792SgshapiroEXTERN int MaxSLBits; /* max. encryption bits for SASL */ 64690792Sgshapiro#endif /* SASL */ 64790792Sgshapiro 64890792Sgshapiro/* 64990792Sgshapiro** Structure to store macros. 65090792Sgshapiro*/ 65190792Sgshapirotypedef struct 65290792Sgshapiro{ 65390792Sgshapiro SM_RPOOL_T *mac_rpool; /* resource pool */ 65490792Sgshapiro BITMAP256 mac_allocated; /* storage has been alloc()? */ 65590792Sgshapiro char *mac_table[MAXMACROID + 1]; /* macros */ 65690792Sgshapiro} MACROS_T; 65790792Sgshapiro 65890792SgshapiroEXTERN MACROS_T GlobalMacros; 65990792Sgshapiro 66090792Sgshapiro/* 66138032Speter** Information about currently open connections to mailers, or to 66238032Speter** hosts that we have looked up recently. 66338032Speter*/ 66438032Speter 66564562Sgshapiro#define MCI struct mailer_con_info 66638032Speter 66738032SpeterMCI 66838032Speter{ 66990792Sgshapiro unsigned long mci_flags; /* flag bits, see below */ 67038032Speter short mci_errno; /* error number on last connection */ 67138032Speter short mci_herrno; /* h_errno from last DNS lookup */ 67238032Speter short mci_exitstat; /* exit status from last connection */ 67338032Speter short mci_state; /* SMTP state */ 67464562Sgshapiro int mci_deliveries; /* delivery attempts for connection */ 67538032Speter long mci_maxsize; /* max size this server will accept */ 67690792Sgshapiro SM_FILE_T *mci_in; /* input side of connection */ 67790792Sgshapiro SM_FILE_T *mci_out; /* output side of connection */ 67838032Speter pid_t mci_pid; /* process id of subordinate proc */ 67938032Speter char *mci_phase; /* SMTP phase string */ 68038032Speter struct mailer *mci_mailer; /* ptr to the mailer for this conn */ 68138032Speter char *mci_host; /* host name */ 68238032Speter char *mci_status; /* DSN status to be copied to addrs */ 68338032Speter char *mci_rstatus; /* SMTP status to be copied to addrs */ 68438032Speter time_t mci_lastuse; /* last usage time */ 68590792Sgshapiro SM_FILE_T *mci_statfile; /* long term status file */ 68664562Sgshapiro char *mci_heloname; /* name to use as HELO arg */ 68790792Sgshapiro long mci_min_by; /* minimum DELIVERBY */ 68890792Sgshapiro bool mci_retryrcpt; /* tempfail for at least one rcpt */ 68990792Sgshapiro char *mci_tolist; /* list of valid recipients */ 69090792Sgshapiro SM_RPOOL_T *mci_rpool; /* resource pool */ 69190792Sgshapiro#if PIPELINING 69290792Sgshapiro int mci_okrcpts; /* number of valid recipients */ 69390792Sgshapiro ADDRESS *mci_nextaddr; /* next address for pipelined status */ 69490792Sgshapiro#endif /* PIPELINING */ 69564562Sgshapiro#if SASL 69690792Sgshapiro SASL_AI_T mci_sai; /* authentication info */ 69764562Sgshapiro bool mci_sasl_auth; /* authenticated? */ 69864562Sgshapiro int mci_sasl_string_len; 69964562Sgshapiro char *mci_sasl_string; /* sasl reply string */ 70064562Sgshapiro char *mci_saslcap; /* SASL list of mechanisms */ 70164562Sgshapiro sasl_conn_t *mci_conn; /* SASL connection */ 70264562Sgshapiro#endif /* SASL */ 70364562Sgshapiro#if STARTTLS 70464562Sgshapiro SSL *mci_ssl; /* SSL connection */ 70564562Sgshapiro#endif /* STARTTLS */ 70690792Sgshapiro MACROS_T mci_macro; /* macro definitions */ 70738032Speter}; 70838032Speter 70938032Speter 71038032Speter/* flag bits */ 71164562Sgshapiro#define MCIF_VALID 0x00000001 /* this entry is valid */ 71290792Sgshapiro/* 0x00000002 unused, was MCIF_TEMP */ 71364562Sgshapiro#define MCIF_CACHED 0x00000004 /* currently in open cache */ 71464562Sgshapiro#define MCIF_ESMTP 0x00000008 /* this host speaks ESMTP */ 71564562Sgshapiro#define MCIF_EXPN 0x00000010 /* EXPN command supported */ 71664562Sgshapiro#define MCIF_SIZE 0x00000020 /* SIZE option supported */ 71764562Sgshapiro#define MCIF_8BITMIME 0x00000040 /* BODY=8BITMIME supported */ 71864562Sgshapiro#define MCIF_7BIT 0x00000080 /* strip this message to 7 bits */ 71994334Sgshapiro/* 0x00000100 unused, was MCIF_MULTSTAT: MAIL11V3: handles MULT status */ 72064562Sgshapiro#define MCIF_INHEADER 0x00000200 /* currently outputing header */ 72164562Sgshapiro#define MCIF_CVT8TO7 0x00000400 /* convert from 8 to 7 bits */ 72264562Sgshapiro#define MCIF_DSN 0x00000800 /* DSN extension supported */ 72364562Sgshapiro#define MCIF_8BITOK 0x00001000 /* OK to send 8 bit characters */ 72464562Sgshapiro#define MCIF_CVT7TO8 0x00002000 /* convert from 7 to 8 bits */ 72564562Sgshapiro#define MCIF_INMIME 0x00004000 /* currently reading MIME header */ 72664562Sgshapiro#define MCIF_AUTH 0x00008000 /* AUTH= supported */ 72764562Sgshapiro#define MCIF_AUTHACT 0x00010000 /* SASL (AUTH) active */ 72864562Sgshapiro#define MCIF_ENHSTAT 0x00020000 /* ENHANCEDSTATUSCODES supported */ 72990792Sgshapiro#define MCIF_PIPELINED 0x00040000 /* PIPELINING supported */ 730110560Sgshapiro#define MCIF_VERB 0x00080000 /* VERB supported */ 73164562Sgshapiro#if STARTTLS 73264562Sgshapiro#define MCIF_TLS 0x00100000 /* STARTTLS supported */ 73364562Sgshapiro#define MCIF_TLSACT 0x00200000 /* STARTTLS active */ 73464562Sgshapiro#else /* STARTTLS */ 735223067Sgshapiro#define MCIF_TLS 0 736223067Sgshapiro#define MCIF_TLSACT 0 73764562Sgshapiro#endif /* STARTTLS */ 73890792Sgshapiro#define MCIF_DLVR_BY 0x00400000 /* DELIVERBY */ 73990792Sgshapiro#if _FFR_IGNORE_EXT_ON_HELO 74090792Sgshapiro# define MCIF_HELO 0x00800000 /* we used HELO: ignore extensions */ 74190792Sgshapiro#endif /* _FFR_IGNORE_EXT_ON_HELO */ 742173340Sgshapiro#define MCIF_INLONGLINE 0x01000000 /* in the middle of a long line */ 743223067Sgshapiro#define MCIF_AUTH2 0x02000000 /* got 2 AUTH lines */ 74471345Sgshapiro#define MCIF_ONLY_EHLO 0x10000000 /* use only EHLO in smtpinit */ 74538032Speter 746223067Sgshapiro#define MCIF_EXTENS (MCIF_EXPN | MCIF_SIZE | MCIF_8BITMIME | MCIF_DSN | MCIF_8BITOK | MCIF_AUTH | MCIF_ENHSTAT | MCIF_TLS | MCIF_AUTH2) 747223067Sgshapiro 74838032Speter/* states */ 74938032Speter#define MCIS_CLOSED 0 /* no traffic on this connection */ 75038032Speter#define MCIS_OPENING 1 /* sending initial protocol */ 75138032Speter#define MCIS_OPEN 2 /* open, initial protocol sent */ 75290792Sgshapiro#define MCIS_MAIL 3 /* MAIL command sent */ 75390792Sgshapiro#define MCIS_RCPT 4 /* RCPT commands being sent */ 75490792Sgshapiro#define MCIS_DATA 5 /* DATA command sent */ 75590792Sgshapiro#define MCIS_QUITING 6 /* running quit protocol */ 75690792Sgshapiro#define MCIS_SSD 7 /* service shutting down */ 75790792Sgshapiro#define MCIS_ERROR 8 /* I/O error on connection */ 75838032Speter 75938032Speter/* functions */ 76038032Speterextern void mci_cache __P((MCI *)); 761141867Sgshapiroextern void mci_close __P((MCI *, char *where)); 762132943Sgshapiroextern void mci_dump __P((SM_FILE_T *, MCI *, bool)); 763132943Sgshapiroextern void mci_dump_all __P((SM_FILE_T *, bool)); 76464562Sgshapiroextern void mci_flush __P((bool, MCI *)); 765223067Sgshapiroextern void mci_clr_extensions __P((MCI *)); 76664562Sgshapiroextern MCI *mci_get __P((char *, MAILER *)); 76764562Sgshapiroextern int mci_lock_host __P((MCI *)); 76864562Sgshapiroextern bool mci_match __P((char *, MAILER *)); 76938032Speterextern int mci_print_persistent __P((char *, char *)); 77038032Speterextern int mci_purge_persistent __P((char *, char *)); 77164562Sgshapiroextern MCI **mci_scan __P((MCI *)); 77264562Sgshapiroextern void mci_setstat __P((MCI *, int, char *, char *)); 77364562Sgshapiroextern void mci_store_persistent __P((MCI *)); 774168515Sgshapiroextern int mci_traverse_persistent __P((int (*)(char *, char *), char *)); 77538032Speterextern void mci_unlock_host __P((MCI *)); 77664562Sgshapiro 77790792SgshapiroEXTERN int MaxMciCache; /* maximum entries in MCI cache */ 77890792SgshapiroEXTERN time_t MciCacheTimeout; /* maximum idle time on connections */ 77990792SgshapiroEXTERN time_t MciInfoTimeout; /* how long 'til we retry down hosts */ 78090792Sgshapiro 78190792Sgshapiro/* 78238032Speter** Header structure. 78338032Speter** This structure is used internally to store header items. 78438032Speter*/ 78538032Speter 78638032Speterstruct header 78738032Speter{ 78838032Speter char *h_field; /* the name of the field */ 78938032Speter char *h_value; /* the value of that field */ 79038032Speter struct header *h_link; /* the next header */ 79190792Sgshapiro unsigned char h_macro; /* include header if macro defined */ 79290792Sgshapiro unsigned long h_flags; /* status bits, see below */ 79364562Sgshapiro BITMAP256 h_mflags; /* m_flags bits needed */ 79438032Speter}; 79538032Speter 79638032Spetertypedef struct header HDR; 79738032Speter 79838032Speter/* 79938032Speter** Header information structure. 80038032Speter** Defined in conf.c, this struct declares the header fields 80138032Speter** that have some magic meaning. 80238032Speter*/ 80338032Speter 80438032Speterstruct hdrinfo 80538032Speter{ 80690792Sgshapiro char *hi_field; /* the name of the field */ 80790792Sgshapiro unsigned long hi_flags; /* status bits, see below */ 80890792Sgshapiro char *hi_ruleset; /* validity check ruleset */ 80938032Speter}; 81038032Speter 81138032Speterextern struct hdrinfo HdrInfo[]; 81238032Speter 81338032Speter/* bits for h_flags and hi_flags */ 81464562Sgshapiro#define H_EOH 0x00000001 /* field terminates header */ 81564562Sgshapiro#define H_RCPT 0x00000002 /* contains recipient addresses */ 81664562Sgshapiro#define H_DEFAULT 0x00000004 /* if another value is found, drop this */ 81764562Sgshapiro#define H_RESENT 0x00000008 /* this address is a "Resent-..." address */ 81864562Sgshapiro#define H_CHECK 0x00000010 /* check h_mflags against m_flags */ 81964562Sgshapiro#define H_ACHECK 0x00000020 /* ditto, but always (not just default) */ 82064562Sgshapiro#define H_FORCE 0x00000040 /* force this field, even if default */ 82164562Sgshapiro#define H_TRACE 0x00000080 /* this field contains trace information */ 82264562Sgshapiro#define H_FROM 0x00000100 /* this is a from-type field */ 82364562Sgshapiro#define H_VALID 0x00000200 /* this field has a validated value */ 82464562Sgshapiro#define H_RECEIPTTO 0x00000400 /* field has return receipt info */ 82564562Sgshapiro#define H_ERRORSTO 0x00000800 /* field has error address info */ 82664562Sgshapiro#define H_CTE 0x00001000 /* field is a content-transfer-encoding */ 82764562Sgshapiro#define H_CTYPE 0x00002000 /* this is a content-type field */ 82864562Sgshapiro#define H_BCC 0x00004000 /* Bcc: header: strip value or delete */ 82964562Sgshapiro#define H_ENCODABLE 0x00008000 /* field can be RFC 1522 encoded */ 83064562Sgshapiro#define H_STRIPCOMM 0x00010000 /* header check: strip comments */ 83164562Sgshapiro#define H_BINDLATE 0x00020000 /* only expand macros at deliver */ 83264562Sgshapiro#define H_USER 0x00040000 /* header came from the user/SMTP */ 83338032Speter 83464562Sgshapiro/* bits for chompheader() */ 83564562Sgshapiro#define CHHDR_DEF 0x0001 /* default header */ 83664562Sgshapiro#define CHHDR_CHECK 0x0002 /* call ruleset for header */ 83764562Sgshapiro#define CHHDR_USER 0x0004 /* header from user */ 83890792Sgshapiro#define CHHDR_QUEUE 0x0008 /* header from queue file */ 83964562Sgshapiro 84038032Speter/* functions */ 841168515Sgshapiroextern void addheader __P((char *, char *, int, ENVELOPE *, bool)); 84290792Sgshapiroextern unsigned long chompheader __P((char *, int, HDR **, ENVELOPE *)); 843173340Sgshapiroextern bool commaize __P((HDR *, char *, bool, MCI *, ENVELOPE *, int)); 84490792Sgshapiroextern HDR *copyheader __P((HDR *, SM_RPOOL_T *)); 84590792Sgshapiroextern void eatheader __P((ENVELOPE *, bool, bool)); 84664562Sgshapiroextern char *hvalue __P((char *, HDR *)); 847168515Sgshapiroextern void insheader __P((int, char *, char *, int, ENVELOPE *, bool)); 84864562Sgshapiroextern bool isheader __P((char *)); 849157001Sgshapiroextern bool putfromline __P((MCI *, ENVELOPE *)); 85064562Sgshapiroextern void setupheaders __P((void)); 85164562Sgshapiro 85290792Sgshapiro/* 85364562Sgshapiro** Performance monitoring 85464562Sgshapiro*/ 85564562Sgshapiro 85664562Sgshapiro#define TIMERS struct sm_timers 85764562Sgshapiro 85864562SgshapiroTIMERS 85964562Sgshapiro{ 86064562Sgshapiro TIMER ti_overall; /* the whole process */ 86164562Sgshapiro}; 86264562Sgshapiro 86364562Sgshapiro 86464562Sgshapiro#define PUSHTIMER(l, t) { if (tTd(98, l)) pushtimer(&t); } 86564562Sgshapiro#define POPTIMER(l, t) { if (tTd(98, l)) poptimer(&t); } 86664562Sgshapiro 86790792Sgshapiro/* 86838032Speter** Envelope structure. 86938032Speter** This structure defines the message itself. There is usually 87038032Speter** only one of these -- for the message that we originally read 87138032Speter** and which is our primary interest -- but other envelopes can 87238032Speter** be generated during processing. For example, error messages 87338032Speter** will have their own envelope. 87438032Speter*/ 87538032Speter 87638032Speterstruct envelope 87738032Speter{ 87838032Speter HDR *e_header; /* head of header list */ 87938032Speter long e_msgpriority; /* adjusted priority of this message */ 88038032Speter time_t e_ctime; /* time message appeared in the queue */ 88190792Sgshapiro char *e_to; /* (list of) target person(s) */ 88238032Speter ADDRESS e_from; /* the person it is from */ 88338032Speter char *e_sender; /* e_from.q_paddr w comments stripped */ 88438032Speter char **e_fromdomain; /* the domain part of the sender */ 88538032Speter ADDRESS *e_sendqueue; /* list of message recipients */ 88638032Speter ADDRESS *e_errorqueue; /* the queue for error responses */ 88766494Sgshapiro 88866494Sgshapiro /* 88966494Sgshapiro ** Overflow detection is based on < 0, so don't change this 89066494Sgshapiro ** to unsigned. We don't use unsigned and == ULONG_MAX because 89166494Sgshapiro ** some libc's don't have strtoul(), see mail_esmtp_args(). 89266494Sgshapiro */ 89390792Sgshapiro 89438032Speter long e_msgsize; /* size of the message in bytes */ 89590792Sgshapiro char *e_msgid; /* message id (for logging) */ 89690792Sgshapiro unsigned long e_flags; /* flags, see below */ 89738032Speter int e_nrcpts; /* number of recipients */ 89838032Speter short e_class; /* msg class (priority, junk, etc.) */ 89938032Speter short e_hopcount; /* number of times processed */ 90038032Speter short e_nsent; /* number of sends since checkpoint */ 90138032Speter short e_sendmode; /* message send mode */ 90238032Speter short e_errormode; /* error return mode */ 90338032Speter short e_timeoutclass; /* message timeout class */ 904157001Sgshapiro bool (*e_puthdr)__P((MCI *, HDR *, ENVELOPE *, int)); 90538032Speter /* function to put header of message */ 906157001Sgshapiro bool (*e_putbody)__P((MCI *, ENVELOPE *, char *)); 90738032Speter /* function to put body of message */ 90864562Sgshapiro ENVELOPE *e_parent; /* the message this one encloses */ 90964562Sgshapiro ENVELOPE *e_sibling; /* the next envelope of interest */ 91038032Speter char *e_bodytype; /* type of message body */ 91190792Sgshapiro SM_FILE_T *e_dfp; /* data file */ 91238032Speter char *e_id; /* code for this entry in queue */ 913173340Sgshapiro#if _FFR_SESSID 914173340Sgshapiro char *e_sessid; /* session ID for this envelope */ 915173340Sgshapiro#endif /* _FFR_SESSID */ 91690792Sgshapiro int e_qgrp; /* queue group (index into queues) */ 91790792Sgshapiro int e_qdir; /* index into queue directories */ 91890792Sgshapiro int e_dfqgrp; /* data file queue group index */ 91990792Sgshapiro int e_dfqdir; /* data file queue directory index */ 92090792Sgshapiro int e_xfqgrp; /* queue group (index into queues) */ 92190792Sgshapiro int e_xfqdir; /* index into queue directories (xf) */ 92290792Sgshapiro SM_FILE_T *e_xfp; /* transcript file */ 92390792Sgshapiro SM_FILE_T *e_lockfp; /* the lock file for this message */ 924168515Sgshapiro char *e_message; /* error message; readonly; NULL, 925168515Sgshapiro * or allocated from e_rpool */ 92690792Sgshapiro char *e_statmsg; /* stat msg (changes per delivery). 92790792Sgshapiro * readonly. NULL or allocated from 92890792Sgshapiro * e_rpool. */ 92990792Sgshapiro char *e_quarmsg; /* why envelope is quarantined */ 93090792Sgshapiro char e_qfletter; /* queue file letter on disk */ 93138032Speter char *e_msgboundary; /* MIME-style message part boundary */ 93238032Speter char *e_origrcpt; /* original recipient (one only) */ 93338032Speter char *e_envid; /* envelope id from MAIL FROM: line */ 93438032Speter char *e_status; /* DSN status for this message */ 93538032Speter time_t e_dtime; /* time of last delivery attempt */ 93638032Speter int e_ntries; /* number of delivery attempts */ 93790792Sgshapiro dev_t e_dfdev; /* data file device (crash recovery) */ 93890792Sgshapiro ino_t e_dfino; /* data file inode (crash recovery) */ 93990792Sgshapiro MACROS_T e_macro; /* macro definitions */ 94090792Sgshapiro MCI *e_mci; /* connection info */ 94190792Sgshapiro char *e_auth_param; /* readonly; NULL or static storage or 94290792Sgshapiro * allocated from e_rpool */ 94364562Sgshapiro TIMERS e_timers; /* per job timers */ 94490792Sgshapiro long e_deliver_by; /* deliver by */ 94590792Sgshapiro int e_dlvr_flag; /* deliver by flag */ 94690792Sgshapiro SM_RPOOL_T *e_rpool; /* resource pool for this envelope */ 947168515Sgshapiro unsigned int e_features; /* server features */ 948203004Sgshapiro#if _FFR_MILTER_ENHSC 949203004Sgshapiro#define ENHSC_LEN 11 950203004Sgshapiro char e_enhsc[ENHSC_LEN]; /* enhanced status code */ 951203004Sgshapiro#endif /* _FFR_MILTER_ENHSC */ 95238032Speter}; 95338032Speter 954244833Sgshapiro#define PRT_NONNEGL(v) ((v) < 0 ? LONG_MAX : (v)) 955244833Sgshapiro 95638032Speter/* values for e_flags */ 957102528Sgshapiro#define EF_OLDSTYLE 0x00000001L /* use spaces (not commas) in hdrs */ 958102528Sgshapiro#define EF_INQUEUE 0x00000002L /* this message is fully queued */ 959102528Sgshapiro#define EF_NO_BODY_RETN 0x00000004L /* omit message body on error */ 960102528Sgshapiro#define EF_CLRQUEUE 0x00000008L /* disk copy is no longer needed */ 961102528Sgshapiro#define EF_SENDRECEIPT 0x00000010L /* send a return receipt */ 962102528Sgshapiro#define EF_FATALERRS 0x00000020L /* fatal errors occurred */ 963102528Sgshapiro#define EF_DELETE_BCC 0x00000040L /* delete Bcc: headers entirely */ 964102528Sgshapiro#define EF_RESPONSE 0x00000080L /* this is an error or return receipt */ 965102528Sgshapiro#define EF_RESENT 0x00000100L /* this message is being forwarded */ 966102528Sgshapiro#define EF_VRFYONLY 0x00000200L /* verify only (don't expand aliases) */ 967102528Sgshapiro#define EF_WARNING 0x00000400L /* warning message has been sent */ 968102528Sgshapiro#define EF_QUEUERUN 0x00000800L /* this envelope is from queue */ 969102528Sgshapiro#define EF_GLOBALERRS 0x00001000L /* treat errors as global */ 970102528Sgshapiro#define EF_PM_NOTIFY 0x00002000L /* send return mail to postmaster */ 971102528Sgshapiro#define EF_METOO 0x00004000L /* send to me too */ 972102528Sgshapiro#define EF_LOGSENDER 0x00008000L /* need to log the sender */ 973102528Sgshapiro#define EF_NORECEIPT 0x00010000L /* suppress all return-receipts */ 974102528Sgshapiro#define EF_HAS8BIT 0x00020000L /* at least one 8-bit char in body */ 975102528Sgshapiro#define EF_NL_NOT_EOL 0x00040000L /* don't accept raw NL as EOLine */ 976102528Sgshapiro#define EF_CRLF_NOT_EOL 0x00080000L /* don't accept CR-LF as EOLine */ 977102528Sgshapiro#define EF_RET_PARAM 0x00100000L /* RCPT command had RET argument */ 978102528Sgshapiro#define EF_HAS_DF 0x00200000L /* set when data file is instantiated */ 979102528Sgshapiro#define EF_IS_MIME 0x00400000L /* really is a MIME message */ 980102528Sgshapiro#define EF_DONT_MIME 0x00800000L /* never MIME this message */ 981102528Sgshapiro#define EF_DISCARD 0x01000000L /* discard the message */ 982102528Sgshapiro#define EF_TOOBIG 0x02000000L /* message is too big */ 983102528Sgshapiro#define EF_SPLIT 0x04000000L /* envelope has been split */ 984102528Sgshapiro#define EF_UNSAFE 0x08000000L /* unsafe: read from untrusted source */ 985159609Sgshapiro#define EF_TOODEEP 0x10000000L /* message is nested too deep */ 98638032Speter 98790792Sgshapiro#define DLVR_NOTIFY 0x01 98890792Sgshapiro#define DLVR_RETURN 0x02 98990792Sgshapiro#define DLVR_TRACE 0x10 99090792Sgshapiro#define IS_DLVR_NOTIFY(e) (((e)->e_dlvr_flag & DLVR_NOTIFY) != 0) 99190792Sgshapiro#define IS_DLVR_RETURN(e) (((e)->e_dlvr_flag & DLVR_RETURN) != 0) 99290792Sgshapiro#define IS_DLVR_TRACE(e) (((e)->e_dlvr_flag & DLVR_TRACE) != 0) 99390792Sgshapiro#define IS_DLVR_BY(e) ((e)->e_dlvr_flag != 0) 99438032Speter 99590792Sgshapiro#define BODYTYPE_NONE (0) 99690792Sgshapiro#define BODYTYPE_7BIT (1) 99790792Sgshapiro#define BODYTYPE_8BITMIME (2) 99890792Sgshapiro#define BODYTYPE_ILLEGAL (-1) 99990792Sgshapiro#define BODYTYPE_VALID(b) ((b) == BODYTYPE_7BIT || (b) == BODYTYPE_8BITMIME) 100090792Sgshapiro 100190792Sgshapiroextern ENVELOPE BlankEnvelope; 100290792Sgshapiro 100338032Speter/* functions */ 100490792Sgshapiroextern void clearenvelope __P((ENVELOPE *, bool, SM_RPOOL_T *)); 1005203004Sgshapiroextern int dropenvelope __P((ENVELOPE *, bool, bool)); 100690792Sgshapiroextern ENVELOPE *newenvelope __P((ENVELOPE *, ENVELOPE *, SM_RPOOL_T *)); 1007110560Sgshapiroextern void clrsessenvelope __P((ENVELOPE *)); 100864562Sgshapiroextern void printenvflags __P((ENVELOPE *)); 1009157001Sgshapiroextern bool putbody __P((MCI *, ENVELOPE *, char *)); 1010157001Sgshapiroextern bool putheader __P((MCI *, HDR *, ENVELOPE *, int)); 101138032Speter 101290792Sgshapiro/* 101338032Speter** Message priority classes. 101438032Speter** 101538032Speter** The message class is read directly from the Priority: header 101638032Speter** field in the message. 101738032Speter** 101838032Speter** CurEnv->e_msgpriority is the number of bytes in the message plus 101938032Speter** the creation time (so that jobs ``tend'' to be ordered correctly), 102038032Speter** adjusted by the message class, the number of recipients, and the 102138032Speter** amount of time the message has been sitting around. This number 102238032Speter** is used to order the queue. Higher values mean LOWER priority. 102338032Speter** 102438032Speter** Each priority class point is worth WkClassFact priority points; 102538032Speter** each recipient is worth WkRecipFact priority points. Each time 102638032Speter** we reprocess a message the priority is adjusted by WkTimeFact. 102738032Speter** WkTimeFact should normally decrease the priority so that jobs 102838032Speter** that have historically failed will be run later; thanks go to 102938032Speter** Jay Lepreau at Utah for pointing out the error in my thinking. 103038032Speter** 103138032Speter** The "class" is this number, unadjusted by the age or size of 103238032Speter** this message. Classes with negative representations will have 103338032Speter** error messages thrown away if they are not local. 103438032Speter*/ 103538032Speter 103638032Speterstruct priority 103738032Speter{ 103838032Speter char *pri_name; /* external name of priority */ 103938032Speter int pri_val; /* internal value for same */ 104038032Speter}; 104138032Speter 104290792SgshapiroEXTERN int NumPriorities; /* pointer into Priorities */ 104390792SgshapiroEXTERN struct priority Priorities[MAXPRIORITIES]; 104490792Sgshapiro 104590792Sgshapiro/* 104638032Speter** Rewrite rules. 104738032Speter*/ 104838032Speter 104938032Speterstruct rewrite 105038032Speter{ 105138032Speter char **r_lhs; /* pattern match */ 105238032Speter char **r_rhs; /* substitution value */ 105338032Speter struct rewrite *r_next;/* next in chain */ 105464562Sgshapiro int r_line; /* rule line in sendmail.cf */ 105538032Speter}; 105638032Speter 105738032Speter/* 105838032Speter** Special characters in rewriting rules. 105938032Speter** These are used internally only. 106038032Speter** The COND* rules are actually used in macros rather than in 106138032Speter** rewriting rules, but are given here because they 106238032Speter** cannot conflict. 106338032Speter*/ 106438032Speter 1065168515Sgshapiro/* "out of band" indicator */ 1066168515Sgshapiro/* sm/sendmail.h #define METAQUOTE ((unsigned char)0377) quotes the next octet */ 1067168515Sgshapiro 106838032Speter/* left hand side items */ 106990792Sgshapiro#define MATCHZANY ((unsigned char)0220) /* match zero or more tokens */ 107090792Sgshapiro#define MATCHANY ((unsigned char)0221) /* match one or more tokens */ 107190792Sgshapiro#define MATCHONE ((unsigned char)0222) /* match exactly one token */ 107290792Sgshapiro#define MATCHCLASS ((unsigned char)0223) /* match one token in a class */ 1073168515Sgshapiro#define MATCHNCLASS ((unsigned char)0224) /* match tokens not in class */ 107438032Speter 107538032Speter/* right hand side items */ 1076168515Sgshapiro#define MATCHREPL ((unsigned char)0225) /* RHS replacement for above */ 107790792Sgshapiro#define CANONNET ((unsigned char)0226) /* canonical net, next token */ 107890792Sgshapiro#define CANONHOST ((unsigned char)0227) /* canonical host, next token */ 107990792Sgshapiro#define CANONUSER ((unsigned char)0230) /* canonical user, next N tokens */ 108090792Sgshapiro#define CALLSUBR ((unsigned char)0231) /* call another rewriting set */ 108138032Speter 1082168515Sgshapiro/* conditionals in macros (anywhere) */ 108390792Sgshapiro#define CONDIF ((unsigned char)0232) /* conditional if-then */ 108490792Sgshapiro#define CONDELSE ((unsigned char)0233) /* conditional else */ 108590792Sgshapiro#define CONDFI ((unsigned char)0234) /* conditional fi */ 108638032Speter 1087168515Sgshapiro/* bracket characters for RHS host name lookup */ 108890792Sgshapiro#define HOSTBEGIN ((unsigned char)0235) /* hostname lookup begin */ 1089168515Sgshapiro#define HOSTEND ((unsigned char)0236) /* hostname lookup end */ 109038032Speter 1091168515Sgshapiro/* bracket characters for RHS generalized lookup */ 109290792Sgshapiro#define LOOKUPBEGIN ((unsigned char)0205) /* generalized lookup begin */ 109390792Sgshapiro#define LOOKUPEND ((unsigned char)0206) /* generalized lookup end */ 109438032Speter 1095168515Sgshapiro/* macro substitution characters (anywhere) */ 109690792Sgshapiro#define MACROEXPAND ((unsigned char)0201) /* macro expansion */ 109790792Sgshapiro#define MACRODEXPAND ((unsigned char)0202) /* deferred macro expansion */ 109838032Speter 109938032Speter/* to make the code clearer */ 110064562Sgshapiro#define MATCHZERO CANONHOST 110138032Speter 110282017Sgshapiro#define MAXMATCH 9 /* max params per rewrite */ 1103120256Sgshapiro#define MAX_MAP_ARGS 10 /* max arguments for map */ 110482017Sgshapiro 110538032Speter/* external <==> internal mapping table */ 110638032Speterstruct metamac 110738032Speter{ 110890792Sgshapiro char metaname; /* external code (after $) */ 110990792Sgshapiro unsigned char metaval; /* internal code (as above) */ 111038032Speter}; 111138032Speter 111238032Speter/* values for macros with external names only */ 111364562Sgshapiro#define MID_OPMODE 0202 /* operation mode */ 111438032Speter 111538032Speter/* functions */ 111690792Sgshapiro#if SM_HEAP_CHECK 111790792Sgshapiroextern void 111890792Sgshapiromacdefine_tagged __P(( 111990792Sgshapiro MACROS_T *_mac, 112090792Sgshapiro ARGCLASS_T _vclass, 112190792Sgshapiro int _id, 112290792Sgshapiro char *_value, 112390792Sgshapiro char *_file, 112490792Sgshapiro int _line, 112590792Sgshapiro int _group)); 112690792Sgshapiro# define macdefine(mac,c,id,v) \ 112790792Sgshapiro macdefine_tagged(mac,c,id,v,__FILE__,__LINE__,sm_heap_group()) 112890792Sgshapiro#else /* SM_HEAP_CHECK */ 112990792Sgshapiroextern void 113090792Sgshapiromacdefine __P(( 113190792Sgshapiro MACROS_T *_mac, 113290792Sgshapiro ARGCLASS_T _vclass, 113390792Sgshapiro int _id, 113490792Sgshapiro char *_value)); 113590792Sgshapiro# define macdefine_tagged(mac,c,id,v,file,line,grp) macdefine(mac,c,id,v) 113690792Sgshapiro#endif /* SM_HEAP_CHECK */ 113790792Sgshapiroextern void macset __P((MACROS_T *, int, char *)); 113890792Sgshapiro#define macget(mac, i) (mac)->mac_table[i] 113938032Speterextern void expand __P((char *, char *, size_t, ENVELOPE *)); 114090792Sgshapiroextern int macid_parse __P((char *, char **)); 114190792Sgshapiro#define macid(name) macid_parse(name, NULL) 114264562Sgshapiroextern char *macname __P((int)); 114338032Speterextern char *macvalue __P((int, ENVELOPE *)); 1144168515Sgshapiroextern int rscheck __P((char *, char *, char *, ENVELOPE *, int, int, char *, char *, ADDRESS *)); 114590792Sgshapiroextern int rscap __P((char *, char *, char *, ENVELOPE *, char ***, char *, int)); 114664562Sgshapiroextern void setclass __P((int, char *)); 114764562Sgshapiroextern int strtorwset __P((char *, char **, int)); 1148168515Sgshapiroextern char *translate_dollars __P((char *, char *, int *)); 114964562Sgshapiroextern bool wordinclass __P((char *, int)); 115064562Sgshapiro 115190792Sgshapiro/* 115238032Speter** Name canonification short circuit. 115338032Speter** 115438032Speter** If the name server for a host is down, the process of trying to 115538032Speter** canonify the name can hang. This is similar to (but alas, not 115638032Speter** identical to) looking up the name for delivery. This stab type 115738032Speter** caches the result of the name server lookup so we don't hang 115838032Speter** multiple times. 115938032Speter*/ 116038032Speter 116138032Speter#define NAMECANON struct _namecanon 116238032Speter 116338032SpeterNAMECANON 116438032Speter{ 116538032Speter short nc_errno; /* cached errno */ 116638032Speter short nc_herrno; /* cached h_errno */ 116738032Speter short nc_stat; /* cached exit status code */ 116838032Speter short nc_flags; /* flag bits */ 116938032Speter char *nc_cname; /* the canonical name */ 117090792Sgshapiro time_t nc_exp; /* entry expires at */ 117138032Speter}; 117238032Speter 117338032Speter/* values for nc_flags */ 117438032Speter#define NCF_VALID 0x0001 /* entry valid */ 117564562Sgshapiro 117690792Sgshapiro/* hostsignature structure */ 117790792Sgshapiro 117890792Sgshapirostruct hostsig_t 117990792Sgshapiro{ 118090792Sgshapiro char *hs_sig; /* hostsignature */ 118190792Sgshapiro time_t hs_exp; /* entry expires at */ 118290792Sgshapiro}; 118390792Sgshapiro 118490792Sgshapirotypedef struct hostsig_t HOSTSIG_T; 118590792Sgshapiro 1186223067Sgshapiro/* 1187223067Sgshapiro** The standard udp packet size PACKETSZ (512) is not sufficient for some 1188223067Sgshapiro** nameserver answers containing very many resource records. The resolver 1189223067Sgshapiro** may switch to tcp and retry if it detects udp packet overflow. 1190223067Sgshapiro** Also note that the resolver routines res_query and res_search return 1191223067Sgshapiro** the size of the *un*truncated answer in case the supplied answer buffer 1192223067Sgshapiro** it not big enough to accommodate the entire answer. 1193223067Sgshapiro*/ 1194223067Sgshapiro 1195223067Sgshapiro# ifndef MAXPACKET 1196223067Sgshapiro# define MAXPACKET 8192 /* max packet size used internally by BIND */ 1197223067Sgshapiro# endif /* ! MAXPACKET */ 1198223067Sgshapiro 1199223067Sgshapiro/* 1200223067Sgshapiro** The resolver functions res_{send,query,querydomain} expect the 1201223067Sgshapiro** answer buffer to be aligned, but some versions of gcc4 reverse 1202223067Sgshapiro** 25 years of history and no longer align char buffers on the 1203223067Sgshapiro** stack, resulting in crashes on strict-alignment platforms. Use 1204223067Sgshapiro** this union when putting the buffer on the stack to force the 1205223067Sgshapiro** alignment, then cast to (HEADER *) or (unsigned char *) as needed. 1206223067Sgshapiro*/ 1207223067Sgshapirotypedef union 1208223067Sgshapiro{ 1209223067Sgshapiro HEADER qb1; 1210223067Sgshapiro unsigned char qb2[MAXPACKET]; 1211223067Sgshapiro} querybuf; 1212223067Sgshapiro 121364562Sgshapiro/* functions */ 121490792Sgshapiroextern bool getcanonname __P((char *, int, bool, int *)); 121590792Sgshapiroextern int getmxrr __P((char *, char **, unsigned short *, bool, int *, bool, int *)); 121690792Sgshapiroextern char *hostsignature __P((MAILER *, char *)); 121790792Sgshapiroextern int getfallbackmxrr __P((char *)); 121864562Sgshapiro 121990792Sgshapiro/* 122038032Speter** Mapping functions 122138032Speter** 122238032Speter** These allow arbitrary mappings in the config file. The idea 122338032Speter** (albeit not the implementation) comes from IDA sendmail. 122438032Speter*/ 122538032Speter 122664562Sgshapiro#define MAPCLASS struct _mapclass 122764562Sgshapiro#define MAP struct _map 122864562Sgshapiro#define MAXMAPACTIONS 5 /* size of map_actions array */ 122938032Speter 123038032Speter 123138032Speter/* 123238032Speter** An actual map. 123338032Speter*/ 123438032Speter 123538032SpeterMAP 123638032Speter{ 123738032Speter MAPCLASS *map_class; /* the class of this map */ 123890792Sgshapiro MAPCLASS *map_orgclass; /* the original class of this map */ 123938032Speter char *map_mname; /* name of this map */ 124038032Speter long map_mflags; /* flags, see below */ 124138032Speter char *map_file; /* the (nominal) filename */ 124238032Speter ARBPTR_T map_db1; /* the open database ptr */ 124338032Speter ARBPTR_T map_db2; /* an "extra" database pointer */ 124438032Speter char *map_keycolnm; /* key column name */ 124538032Speter char *map_valcolnm; /* value column name */ 124690792Sgshapiro unsigned char map_keycolno; /* key column number */ 124790792Sgshapiro unsigned char map_valcolno; /* value column number */ 124838032Speter char map_coldelim; /* column delimiter */ 124964562Sgshapiro char map_spacesub; /* spacesub */ 125038032Speter char *map_app; /* to append to successful matches */ 125138032Speter char *map_tapp; /* to append to "tempfail" matches */ 125238032Speter char *map_domain; /* the (nominal) NIS domain */ 125338032Speter char *map_rebuild; /* program to run to do auto-rebuild */ 125438032Speter time_t map_mtime; /* last database modification time */ 125590792Sgshapiro time_t map_timeout; /* timeout for map accesses */ 125690792Sgshapiro int map_retry; /* # of retries for map accesses */ 125742575Speter pid_t map_pid; /* PID of process which opened map */ 125838032Speter int map_lockfd; /* auxiliary lock file descriptor */ 125938032Speter short map_specificity; /* specificity of aliases */ 126038032Speter MAP *map_stack[MAXMAPSTACK]; /* list for stacked maps */ 126138032Speter short map_return[MAXMAPACTIONS]; /* return bitmaps for stacked maps */ 126238032Speter}; 126338032Speter 126464562Sgshapiro 126538032Speter/* bit values for map_mflags */ 126664562Sgshapiro#define MF_VALID 0x00000001 /* this entry is valid */ 126764562Sgshapiro#define MF_INCLNULL 0x00000002 /* include null byte in key */ 126864562Sgshapiro#define MF_OPTIONAL 0x00000004 /* don't complain if map not found */ 126964562Sgshapiro#define MF_NOFOLDCASE 0x00000008 /* don't fold case in keys */ 127064562Sgshapiro#define MF_MATCHONLY 0x00000010 /* don't use the map value */ 127164562Sgshapiro#define MF_OPEN 0x00000020 /* this entry is open */ 127264562Sgshapiro#define MF_WRITABLE 0x00000040 /* open for writing */ 127364562Sgshapiro#define MF_ALIAS 0x00000080 /* this is an alias file */ 127464562Sgshapiro#define MF_TRY0NULL 0x00000100 /* try with no null byte */ 127564562Sgshapiro#define MF_TRY1NULL 0x00000200 /* try with the null byte */ 127664562Sgshapiro#define MF_LOCKED 0x00000400 /* this map is currently locked */ 127764562Sgshapiro#define MF_ALIASWAIT 0x00000800 /* alias map in aliaswait state */ 127864562Sgshapiro#define MF_IMPL_HASH 0x00001000 /* implicit: underlying hash database */ 127964562Sgshapiro#define MF_IMPL_NDBM 0x00002000 /* implicit: underlying NDBM database */ 128090792Sgshapiro/* 0x00004000 */ 128164562Sgshapiro#define MF_APPEND 0x00008000 /* append new entry on rebuild */ 128264562Sgshapiro#define MF_KEEPQUOTES 0x00010000 /* don't dequote key before lookup */ 128364562Sgshapiro#define MF_NODEFER 0x00020000 /* don't defer if map lookup fails */ 128464562Sgshapiro#define MF_REGEX_NOT 0x00040000 /* regular expression negation */ 128564562Sgshapiro#define MF_DEFER 0x00080000 /* don't lookup map in defer mode */ 128664562Sgshapiro#define MF_SINGLEMATCH 0x00100000 /* successful only if match one key */ 1287157001Sgshapiro#define MF_SINGLEDN 0x00200000 /* only one match, but multi values */ 128890792Sgshapiro#define MF_FILECLASS 0x00400000 /* this is a file class map */ 128990792Sgshapiro#define MF_OPENBOGUS 0x00800000 /* open failed, don't call map_close */ 129090792Sgshapiro#define MF_CLOSING 0x01000000 /* map is being closed */ 129138032Speter 1292223067Sgshapiro#define DYNOPENMAP(map) \ 1293223067Sgshapiro do \ 1294223067Sgshapiro { \ 1295223067Sgshapiro if (!bitset(MF_OPEN, (map)->map_mflags)) \ 1296223067Sgshapiro { \ 1297223067Sgshapiro if (!openmap(map)) \ 1298223067Sgshapiro return NULL; \ 1299223067Sgshapiro } \ 1300223067Sgshapiro } while (0) 130164562Sgshapiro 130264562Sgshapiro 130338032Speter/* indices for map_actions */ 130464562Sgshapiro#define MA_NOTFOUND 0 /* member map returned "not found" */ 130564562Sgshapiro#define MA_UNAVAIL 1 /* member map is not available */ 130664562Sgshapiro#define MA_TRYAGAIN 2 /* member map returns temp failure */ 130738032Speter 130890792Sgshapiro/* macros to handle MapTempFail */ 130990792Sgshapiro#define BIT_IS_MTP 0x01 /* temp.failure occurred */ 131090792Sgshapiro#define BIT_ASK_MTP 0x02 /* do we care about MapTempFail? */ 131190792Sgshapiro#define RESET_MAPTEMPFAIL MapTempFail = 0 131290792Sgshapiro#define INIT_MAPTEMPFAIL MapTempFail = BIT_ASK_MTP 131390792Sgshapiro#define SET_MAPTEMPFAIL MapTempFail |= BIT_IS_MTP 131490792Sgshapiro#define IS_MAPTEMPFAIL bitset(BIT_IS_MTP, MapTempFail) 131590792Sgshapiro#define ASK_MAPTEMPFAIL bitset(BIT_ASK_MTP, MapTempFail) 131690792Sgshapiro 131738032Speter/* 131838032Speter** The class of a map -- essentially the functions to call 131938032Speter*/ 132038032Speter 132138032SpeterMAPCLASS 132238032Speter{ 132338032Speter char *map_cname; /* name of this map class */ 132438032Speter char *map_ext; /* extension for database file */ 132538032Speter short map_cflags; /* flag bits, see below */ 132638032Speter bool (*map_parse)__P((MAP *, char *)); 132738032Speter /* argument parsing function */ 132838032Speter char *(*map_lookup)__P((MAP *, char *, char **, int *)); 132938032Speter /* lookup function */ 133038032Speter void (*map_store)__P((MAP *, char *, char *)); 133138032Speter /* store function */ 133238032Speter bool (*map_open)__P((MAP *, int)); 133338032Speter /* open function */ 133438032Speter void (*map_close)__P((MAP *)); 133538032Speter /* close function */ 133638032Speter}; 133738032Speter 133838032Speter/* bit values for map_cflags */ 133938032Speter#define MCF_ALIASOK 0x0001 /* can be used for aliases */ 134038032Speter#define MCF_ALIASONLY 0x0002 /* usable only for aliases */ 134138032Speter#define MCF_REBUILDABLE 0x0004 /* can rebuild alias files */ 134238032Speter#define MCF_OPTFILE 0x0008 /* file name is optional */ 134390792Sgshapiro#define MCF_NOTPERSIST 0x0010 /* don't keep map open all the time */ 134438032Speter 134538032Speter/* functions */ 134690792Sgshapiroextern void closemaps __P((bool)); 134764562Sgshapiroextern bool impl_map_open __P((MAP *, int)); 134864562Sgshapiroextern void initmaps __P((void)); 134964562Sgshapiroextern MAP *makemapentry __P((char *)); 135064562Sgshapiroextern void maplocaluser __P((ADDRESS *, ADDRESS **, int, ENVELOPE *)); 135138032Speterextern char *map_rewrite __P((MAP *, const char *, size_t, char **)); 135264562Sgshapiro#if NETINFO 135364562Sgshapiroextern char *ni_propval __P((char *, char *, char *, char *, int)); 135464562Sgshapiro#endif /* NETINFO */ 135564562Sgshapiroextern bool openmap __P((MAP *)); 1356168515Sgshapiroextern int udbexpand __P((ADDRESS *, ADDRESS **, int, ENVELOPE *)); 135764562Sgshapiro#if USERDB 135864562Sgshapiroextern void _udbx_close __P((void)); 135990792Sgshapiroextern char *udbsender __P((char *, SM_RPOOL_T *)); 136064562Sgshapiro#endif /* USERDB */ 136190792Sgshapiro 136290792Sgshapiro/* 136364562Sgshapiro** LDAP related items 136464562Sgshapiro*/ 136590792Sgshapiro#if LDAPMAP 136664562Sgshapiro/* struct defining LDAP Auth Methods */ 136764562Sgshapirostruct lamvalues 136864562Sgshapiro{ 136964562Sgshapiro char *lam_name; /* name of LDAP auth method */ 137064562Sgshapiro int lam_code; /* numeric code */ 137164562Sgshapiro}; 137264562Sgshapiro 137364562Sgshapiro/* struct defining LDAP Alias Dereferencing */ 137464562Sgshapirostruct ladvalues 137564562Sgshapiro{ 137664562Sgshapiro char *lad_name; /* name of LDAP alias dereferencing method */ 137764562Sgshapiro int lad_code; /* numeric code */ 137864562Sgshapiro}; 137964562Sgshapiro 138064562Sgshapiro/* struct defining LDAP Search Scope */ 138164562Sgshapirostruct lssvalues 138264562Sgshapiro{ 138364562Sgshapiro char *lss_name; /* name of LDAP search scope */ 138464562Sgshapiro int lss_code; /* numeric code */ 138564562Sgshapiro}; 138664562Sgshapiro 138764562Sgshapiro/* functions */ 138864562Sgshapiroextern bool ldapmap_parseargs __P((MAP *, char *)); 138964562Sgshapiroextern void ldapmap_set_defaults __P((char *)); 139064562Sgshapiro#endif /* LDAPMAP */ 139164562Sgshapiro 139290792Sgshapiro/* 139364562Sgshapiro** PH related items 139464562Sgshapiro*/ 139564562Sgshapiro 139690792Sgshapiro#if PH_MAP 139790792Sgshapiro 139890792Sgshapiro# include <phclient.h> 139990792Sgshapiro 140064562Sgshapirostruct ph_map_struct 140164562Sgshapiro{ 140290792Sgshapiro char *ph_servers; /* list of ph servers */ 140390792Sgshapiro char *ph_field_list; /* list of fields to search for match */ 140490792Sgshapiro PH *ph; /* PH server handle */ 140590792Sgshapiro int ph_fastclose; /* send "quit" command on close */ 140690792Sgshapiro time_t ph_timeout; /* timeout interval */ 140764562Sgshapiro}; 140864562Sgshapirotypedef struct ph_map_struct PH_MAP_STRUCT; 140964562Sgshapiro 141064562Sgshapiro#endif /* PH_MAP */ 1411132943Sgshapiro 141290792Sgshapiro/* 1413132943Sgshapiro** Regular UNIX sockaddrs are too small to handle ISO addresses, so 1414132943Sgshapiro** we are forced to declare a supertype here. 1415132943Sgshapiro*/ 1416132943Sgshapiro 1417132943Sgshapiro#if NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25 1418132943Sgshapirounion bigsockaddr 1419132943Sgshapiro{ 1420132943Sgshapiro struct sockaddr sa; /* general version */ 1421132943Sgshapiro# if NETUNIX 1422132943Sgshapiro struct sockaddr_un sunix; /* UNIX family */ 1423132943Sgshapiro# endif /* NETUNIX */ 1424132943Sgshapiro# if NETINET 1425132943Sgshapiro struct sockaddr_in sin; /* INET family */ 1426132943Sgshapiro# endif /* NETINET */ 1427132943Sgshapiro# if NETINET6 1428132943Sgshapiro struct sockaddr_in6 sin6; /* INET/IPv6 */ 1429132943Sgshapiro# endif /* NETINET6 */ 1430132943Sgshapiro# if NETISO 1431132943Sgshapiro struct sockaddr_iso siso; /* ISO family */ 1432132943Sgshapiro# endif /* NETISO */ 1433132943Sgshapiro# if NETNS 1434132943Sgshapiro struct sockaddr_ns sns; /* XNS family */ 1435132943Sgshapiro# endif /* NETNS */ 1436132943Sgshapiro# if NETX25 1437132943Sgshapiro struct sockaddr_x25 sx25; /* X.25 family */ 1438132943Sgshapiro# endif /* NETX25 */ 1439132943Sgshapiro}; 1440132943Sgshapiro 1441132943Sgshapiro# define SOCKADDR union bigsockaddr 1442132943Sgshapiro 1443132943Sgshapiro/* functions */ 1444132943Sgshapiroextern char *anynet_ntoa __P((SOCKADDR *)); 1445132943Sgshapiro# if NETINET6 1446132943Sgshapiroextern char *anynet_ntop __P((struct in6_addr *, char *, size_t)); 1447132943Sgshapiroextern int anynet_pton __P((int, const char *, void *)); 1448132943Sgshapiro# endif /* NETINET6 */ 1449132943Sgshapiroextern char *hostnamebyanyaddr __P((SOCKADDR *)); 1450132943Sgshapiroextern char *validate_connection __P((SOCKADDR *, char *, ENVELOPE *)); 1451132943Sgshapiro# if SASL >= 20000 1452132943Sgshapiroextern bool iptostring __P((SOCKADDR *, SOCKADDR_LEN_T, char *, unsigned)); 1453132943Sgshapiro# endif /* SASL >= 20000 */ 1454132943Sgshapiro 1455132943Sgshapiro#endif /* NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25 */ 1456132943Sgshapiro 1457132943Sgshapiro/* 145864562Sgshapiro** Process List (proclist) 145964562Sgshapiro*/ 146064562Sgshapiro 146164562Sgshapiro#define NO_PID ((pid_t) 0) 146264562Sgshapiro#ifndef PROC_LIST_SEG 146364562Sgshapiro# define PROC_LIST_SEG 32 /* number of pids to alloc at a time */ 146464562Sgshapiro#endif /* ! PROC_LIST_SEG */ 146564562Sgshapiro 146664562Sgshapiro/* process types */ 146764562Sgshapiro#define PROC_NONE 0 146864562Sgshapiro#define PROC_DAEMON 1 146964562Sgshapiro#define PROC_DAEMON_CHILD 2 147064562Sgshapiro#define PROC_QUEUE 3 147164562Sgshapiro#define PROC_QUEUE_CHILD 3 147264562Sgshapiro#define PROC_CONTROL 4 147364562Sgshapiro#define PROC_CONTROL_CHILD 5 147464562Sgshapiro 147564562Sgshapiro/* functions */ 1476132943Sgshapiroextern void proc_list_add __P((pid_t, char *, int, int, int, SOCKADDR *)); 147764562Sgshapiroextern void proc_list_clear __P((void)); 147890792Sgshapiroextern void proc_list_display __P((SM_FILE_T *, char *)); 147990792Sgshapiroextern void proc_list_drop __P((pid_t, int, int *)); 148064562Sgshapiroextern void proc_list_probe __P((void)); 148164562Sgshapiroextern void proc_list_set __P((pid_t, char *)); 148290792Sgshapiroextern void proc_list_signal __P((int, int)); 148364562Sgshapiro 148490792Sgshapiro/* 148538032Speter** Symbol table definitions 148638032Speter*/ 148738032Speter 148838032Speterstruct symtab 148938032Speter{ 149038032Speter char *s_name; /* name to be entered */ 149190792Sgshapiro short s_symtype; /* general type (see below) */ 149238032Speter struct symtab *s_next; /* pointer to next in chain */ 149338032Speter union 149438032Speter { 149564562Sgshapiro BITMAP256 sv_class; /* bit-map of word classes */ 149638032Speter MAILER *sv_mailer; /* pointer to mailer */ 149738032Speter char *sv_alias; /* alias */ 149838032Speter MAPCLASS sv_mapclass; /* mapping function class */ 149938032Speter MAP sv_map; /* mapping function */ 150090792Sgshapiro HOSTSIG_T sv_hostsig; /* host signature */ 150138032Speter MCI sv_mci; /* mailer connection info */ 150238032Speter NAMECANON sv_namecanon; /* canonical name cache */ 150338032Speter int sv_macro; /* macro name => id mapping */ 150438032Speter int sv_ruleset; /* ruleset index */ 150538032Speter struct hdrinfo sv_header; /* header metainfo */ 150638032Speter char *sv_service[MAXMAPSTACK]; /* service switch */ 150790792Sgshapiro#if LDAPMAP 150877349Sgshapiro MAP *sv_lmap; /* Maps for LDAP connection */ 150964562Sgshapiro#endif /* LDAPMAP */ 1510132943Sgshapiro#if SOCKETMAP 1511132943Sgshapiro MAP *sv_socketmap; /* Maps for SOCKET connection */ 1512132943Sgshapiro#endif /* SOCKETMAP */ 151390792Sgshapiro#if MILTER 151464562Sgshapiro struct milter *sv_milter; /* milter filter name */ 151590792Sgshapiro#endif /* MILTER */ 151690792Sgshapiro QUEUEGRP *sv_queue; /* pointer to queue */ 151738032Speter } s_value; 151838032Speter}; 151938032Speter 152038032Spetertypedef struct symtab STAB; 152138032Speter 152238032Speter/* symbol types */ 152364562Sgshapiro#define ST_UNDEF 0 /* undefined type */ 152464562Sgshapiro#define ST_CLASS 1 /* class map */ 1525244833Sgshapiro/* #define ST_unused 2 UNUSED */ 152664562Sgshapiro#define ST_MAILER 3 /* a mailer header */ 152764562Sgshapiro#define ST_ALIAS 4 /* an alias */ 152864562Sgshapiro#define ST_MAPCLASS 5 /* mapping function class */ 152964562Sgshapiro#define ST_MAP 6 /* mapping function */ 153064562Sgshapiro#define ST_HOSTSIG 7 /* host signature */ 153164562Sgshapiro#define ST_NAMECANON 8 /* cached canonical name */ 153264562Sgshapiro#define ST_MACRO 9 /* macro name to id mapping */ 153364562Sgshapiro#define ST_RULESET 10 /* ruleset index */ 153464562Sgshapiro#define ST_SERVICE 11 /* service switch entry */ 153564562Sgshapiro#define ST_HEADER 12 /* special header flags */ 153690792Sgshapiro#if LDAPMAP 153777349Sgshapiro# define ST_LMAP 13 /* List head of maps for LDAP connection */ 153864562Sgshapiro#endif /* LDAPMAP */ 153990792Sgshapiro#if MILTER 154064562Sgshapiro# define ST_MILTER 14 /* milter filter */ 154190792Sgshapiro#endif /* MILTER */ 154290792Sgshapiro#define ST_QUEUE 15 /* a queue entry */ 154390792Sgshapiro 1544132943Sgshapiro#if SOCKETMAP 1545132943Sgshapiro# define ST_SOCKETMAP 16 /* List head of maps for SOCKET connection */ 1546132943Sgshapiro#endif /* SOCKETMAP */ 1547132943Sgshapiro 154890792Sgshapiro/* This entry must be last */ 1549132943Sgshapiro#define ST_MCI 17 /* mailer connection info (offset) */ 155038032Speter 155164562Sgshapiro#define s_class s_value.sv_class 155264562Sgshapiro#define s_mailer s_value.sv_mailer 155364562Sgshapiro#define s_alias s_value.sv_alias 155464562Sgshapiro#define s_mci s_value.sv_mci 155564562Sgshapiro#define s_mapclass s_value.sv_mapclass 155664562Sgshapiro#define s_hostsig s_value.sv_hostsig 155764562Sgshapiro#define s_map s_value.sv_map 155864562Sgshapiro#define s_namecanon s_value.sv_namecanon 155964562Sgshapiro#define s_macro s_value.sv_macro 156064562Sgshapiro#define s_ruleset s_value.sv_ruleset 156164562Sgshapiro#define s_service s_value.sv_service 156264562Sgshapiro#define s_header s_value.sv_header 156390792Sgshapiro#if LDAPMAP 156477349Sgshapiro# define s_lmap s_value.sv_lmap 156564562Sgshapiro#endif /* LDAPMAP */ 1566132943Sgshapiro#if SOCKETMAP 1567132943Sgshapiro# define s_socketmap s_value.sv_socketmap 1568132943Sgshapiro#endif /* SOCKETMAP */ 156990792Sgshapiro#if MILTER 157064562Sgshapiro# define s_milter s_value.sv_milter 157190792Sgshapiro#endif /* MILTER */ 157290792Sgshapiro#define s_quegrp s_value.sv_queue 157338032Speter 157464562Sgshapiro/* opcodes to stab */ 157564562Sgshapiro#define ST_FIND 0 /* find entry */ 157664562Sgshapiro#define ST_ENTER 1 /* enter if not there */ 157738032Speter 157864562Sgshapiro/* functions */ 157964562Sgshapiroextern STAB *stab __P((char *, int, int)); 158064562Sgshapiroextern void stabapply __P((void (*)(STAB *, int), int)); 158164562Sgshapiro 158290792Sgshapiro/* 158338032Speter** Operation, send, error, and MIME modes 158438032Speter** 158538032Speter** The operation mode describes the basic operation of sendmail. 158638032Speter** This can be set from the command line, and is "send mail" by 158738032Speter** default. 158838032Speter** 158938032Speter** The send mode tells how to send mail. It can be set in the 159090792Sgshapiro** configuration file. Its setting determines how quickly the 159138032Speter** mail will be delivered versus the load on your system. If the 159238032Speter** -v (verbose) flag is given, it will be forced to SM_DELIVER 159338032Speter** mode. 159438032Speter** 159538032Speter** The error mode tells how to return errors. 159638032Speter*/ 159738032Speter 159838032Speter#define MD_DELIVER 'm' /* be a mail sender */ 159938032Speter#define MD_SMTP 's' /* run SMTP on standard input */ 160038032Speter#define MD_ARPAFTP 'a' /* obsolete ARPANET mode (Grey Book) */ 160138032Speter#define MD_DAEMON 'd' /* run as a daemon */ 160238032Speter#define MD_FGDAEMON 'D' /* run daemon in foreground */ 1603182352Sgshapiro#define MD_LOCAL 'l' /* like daemon, but localhost only */ 160438032Speter#define MD_VERIFY 'v' /* verify: don't collect or deliver */ 160538032Speter#define MD_TEST 't' /* test mode: resolve addrs only */ 160638032Speter#define MD_INITALIAS 'i' /* initialize alias database */ 160738032Speter#define MD_PRINT 'p' /* print the queue */ 160890792Sgshapiro#define MD_PRINTNQE 'P' /* print number of entries in queue */ 160938032Speter#define MD_FREEZE 'z' /* freeze the configuration file */ 161038032Speter#define MD_HOSTSTAT 'h' /* print persistent host stat info */ 161138032Speter#define MD_PURGESTAT 'H' /* purge persistent host stat info */ 161264562Sgshapiro#define MD_QUEUERUN 'q' /* queue run */ 1613203004Sgshapiro#define MD_CHECKCONFIG 'C' /* check configuration file */ 161438032Speter 1615182352Sgshapiro#if _FFR_LOCAL_DAEMON 1616182352SgshapiroEXTERN bool LocalDaemon; 1617223067Sgshapiro# if NETINET6 1618223067SgshapiroEXTERN bool V6LoopbackAddrFound; /* found an IPv6 loopback address */ 1619223067Sgshapiro# define SETV6LOOPBACKADDRFOUND(sa) \ 1620223067Sgshapiro do \ 1621223067Sgshapiro { \ 1622223067Sgshapiro if (isloopback(sa)) \ 1623223067Sgshapiro V6LoopbackAddrFound = true; \ 1624223067Sgshapiro } while (0) 1625223067Sgshapiro# endif /* NETINET6 */ 1626182352Sgshapiro#else /* _FFR_LOCAL_DAEMON */ 1627182352Sgshapiro# define LocalDaemon false 1628223067Sgshapiro# define V6LoopbackAddrFound false 1629223067Sgshapiro# define SETV6LOOPBACKADDRFOUND(sa) 1630182352Sgshapiro#endif /* _FFR_LOCAL_DAEMON */ 1631182352Sgshapiro 163290792Sgshapiro/* Note: see also include/sendmail/pathnames.h: GET_CLIENT_CF */ 163390792Sgshapiro 163438032Speter/* values for e_sendmode -- send modes */ 163538032Speter#define SM_DELIVER 'i' /* interactive delivery */ 163638032Speter#define SM_FORK 'b' /* deliver in background */ 1637157001Sgshapiro#if _FFR_DM_ONE 1638157001Sgshapiro#define SM_DM_ONE 'o' /* deliver first TA in background, then queue */ 1639157001Sgshapiro#endif /* _FFR_DM_ONE */ 164038032Speter#define SM_QUEUE 'q' /* queue, don't deliver */ 164138032Speter#define SM_DEFER 'd' /* defer map lookups as well as queue */ 164238032Speter#define SM_VERIFY 'v' /* verify only (used internally) */ 1643157001Sgshapiro#define DM_NOTSET (-1) /* DeliveryMode (per daemon) option not set */ 1644223067Sgshapiro# define SM_IS_INTERACTIVE(m) ((m) == SM_DELIVER) 164538032Speter 164690792Sgshapiro#define WILL_BE_QUEUED(m) ((m) == SM_QUEUE || (m) == SM_DEFER) 164764562Sgshapiro 164838032Speter/* used only as a parameter to sendall */ 164938032Speter#define SM_DEFAULT '\0' /* unspecified, use SendMode */ 165038032Speter 165164562Sgshapiro/* functions */ 165264562Sgshapiroextern void set_delivery_mode __P((int, ENVELOPE *)); 165338032Speter 165438032Speter/* values for e_errormode -- error handling modes */ 165538032Speter#define EM_PRINT 'p' /* print errors */ 165638032Speter#define EM_MAIL 'm' /* mail back errors */ 165738032Speter#define EM_WRITE 'w' /* write back errors */ 165838032Speter#define EM_BERKNET 'e' /* special berknet processing */ 165938032Speter#define EM_QUIET 'q' /* don't print messages (stat only) */ 166038032Speter 166138032Speter 166238032Speter/* bit values for MimeMode */ 166338032Speter#define MM_CVTMIME 0x0001 /* convert 8 to 7 bit MIME */ 166438032Speter#define MM_PASS8BIT 0x0002 /* just send 8 bit data blind */ 166538032Speter#define MM_MIME8BIT 0x0004 /* convert 8-bit data to MIME */ 166638032Speter 166738032Speter 166838032Speter/* how to handle messages without any recipient addresses */ 166938032Speter#define NRA_NO_ACTION 0 /* just leave it as is */ 167038032Speter#define NRA_ADD_TO 1 /* add To: header */ 167138032Speter#define NRA_ADD_APPARENTLY_TO 2 /* add Apparently-To: header */ 167238032Speter#define NRA_ADD_BCC 3 /* add empty Bcc: header */ 167338032Speter#define NRA_ADD_TO_UNDISCLOSED 4 /* add To: undisclosed:; header */ 167438032Speter 167538032Speter 167638032Speter/* flags to putxline */ 167738032Speter#define PXLF_NOTHINGSPECIAL 0 /* no special mapping */ 167838032Speter#define PXLF_MAPFROM 0x0001 /* map From_ to >From_ */ 167938032Speter#define PXLF_STRIP8BIT 0x0002 /* strip 8th bit */ 168038032Speter#define PXLF_HEADER 0x0004 /* map newlines in headers */ 168194334Sgshapiro#define PXLF_NOADDEOL 0x0008 /* if EOL not present, don't add one */ 1682168515Sgshapiro#define PXLF_STRIPMQUOTE 0x0010 /* strip METAQUOTEs */ 168338032Speter 168438032Speter/* 168538032Speter** Privacy flags 168638032Speter** These are bit values for the PrivacyFlags word. 168738032Speter*/ 168838032Speter 168990792Sgshapiro#define PRIV_PUBLIC 0 /* what have I got to hide? */ 169090792Sgshapiro#define PRIV_NEEDMAILHELO 0x00000001 /* insist on HELO for MAIL */ 169190792Sgshapiro#define PRIV_NEEDEXPNHELO 0x00000002 /* insist on HELO for EXPN */ 169290792Sgshapiro#define PRIV_NEEDVRFYHELO 0x00000004 /* insist on HELO for VRFY */ 169390792Sgshapiro#define PRIV_NOEXPN 0x00000008 /* disallow EXPN command */ 169490792Sgshapiro#define PRIV_NOVRFY 0x00000010 /* disallow VRFY command */ 169590792Sgshapiro#define PRIV_AUTHWARNINGS 0x00000020 /* flag possible auth probs */ 169690792Sgshapiro#define PRIV_NOVERB 0x00000040 /* disallow VERB command */ 169790792Sgshapiro#define PRIV_RESTRICTMAILQ 0x00010000 /* restrict mailq command */ 169890792Sgshapiro#define PRIV_RESTRICTQRUN 0x00020000 /* restrict queue run */ 169990792Sgshapiro#define PRIV_RESTRICTEXPAND 0x00040000 /* restrict alias/forward expansion */ 170090792Sgshapiro#define PRIV_NOETRN 0x00080000 /* disallow ETRN command */ 170190792Sgshapiro#define PRIV_NOBODYRETN 0x00100000 /* do not return bodies on bounces */ 170290792Sgshapiro#define PRIV_NORECEIPTS 0x00200000 /* disallow return receipts */ 1703168515Sgshapiro#define PRIV_NOACTUALRECIPIENT 0x00400000 /* no X-Actual-Recipient in DSNs */ 170438032Speter 1705168515Sgshapiro/* don't give no info, anyway, anyhow (in the main SMTP transaction) */ 170690792Sgshapiro#define PRIV_GOAWAY 0x0000ffff 170764562Sgshapiro 170838032Speter/* struct defining such things */ 170938032Speterstruct prival 171038032Speter{ 171190792Sgshapiro char *pv_name; /* name of privacy flag */ 171290792Sgshapiro unsigned long pv_flag; /* numeric level */ 171338032Speter}; 171438032Speter 171590792SgshapiroEXTERN unsigned long PrivacyFlags; /* privacy flags */ 171638032Speter 171790792Sgshapiro 171838032Speter/* 171938032Speter** Flags passed to remotename, parseaddr, allocaddr, and buildaddr. 172038032Speter*/ 172138032Speter 172238032Speter#define RF_SENDERADDR 0x001 /* this is a sender address */ 172338032Speter#define RF_HEADERADDR 0x002 /* this is a header address */ 172438032Speter#define RF_CANONICAL 0x004 /* strip comment information */ 172538032Speter#define RF_ADDDOMAIN 0x008 /* OK to do domain extension */ 172638032Speter#define RF_COPYPARSE 0x010 /* copy parsed user & host */ 172738032Speter#define RF_COPYPADDR 0x020 /* copy print address */ 172838032Speter#define RF_COPYALL (RF_COPYPARSE|RF_COPYPADDR) 172938032Speter#define RF_COPYNONE 0 1730168515Sgshapiro#define RF_RM_ADDR 0x040 /* address to be removed */ 173138032Speter 1732102528Sgshapiro/* 1733102528Sgshapiro** Flags passed to rscheck 1734102528Sgshapiro*/ 173538032Speter 1736110560Sgshapiro#define RSF_RMCOMM 0x0001 /* strip comments */ 1737102528Sgshapiro#define RSF_UNSTRUCTURED 0x0002 /* unstructured, ignore syntax errors */ 1738102528Sgshapiro#define RSF_COUNT 0x0004 /* count rejections (statistics)? */ 1739102528Sgshapiro 174038032Speter/* 174164562Sgshapiro** Flags passed to mime8to7 and putheader. 174238032Speter*/ 174338032Speter 174438032Speter#define M87F_OUTER 0 /* outer context */ 174538032Speter#define M87F_NO8BIT 0x0001 /* can't have 8-bit in this section */ 174638032Speter#define M87F_DIGEST 0x0002 /* processing multipart/digest */ 174742575Speter#define M87F_NO8TO7 0x0004 /* don't do 8->7 bit conversions */ 174838032Speter 174964562Sgshapiro/* functions */ 1750157001Sgshapiroextern bool mime7to8 __P((MCI *, HDR *, ENVELOPE *)); 1751159609Sgshapiroextern int mime8to7 __P((MCI *, HDR *, ENVELOPE *, char **, int, int)); 175238032Speter 175338032Speter/* 175438032Speter** Flags passed to returntosender. 175538032Speter*/ 175638032Speter 175738032Speter#define RTSF_NO_BODY 0 /* send headers only */ 175838032Speter#define RTSF_SEND_BODY 0x0001 /* include body of message in return */ 175938032Speter#define RTSF_PM_BOUNCE 0x0002 /* this is a postmaster bounce */ 176038032Speter 176164562Sgshapiro/* functions */ 176264562Sgshapiroextern int returntosender __P((char *, ADDRESS *, int, ENVELOPE *)); 176338032Speter 176438032Speter/* 176564562Sgshapiro** Mail Filters (milter) 176664562Sgshapiro*/ 176738032Speter 176894334Sgshapiro/* 176994334Sgshapiro** 32-bit type used by milter 177094334Sgshapiro** (needed by libmilter even if MILTER isn't defined) 177194334Sgshapiro*/ 177294334Sgshapiro 177394334Sgshapirotypedef SM_INT32 mi_int32; 177494334Sgshapiro 177594334Sgshapiro#if MILTER 177690792Sgshapiro# define SMFTO_WRITE 0 /* Timeout for sending information */ 177790792Sgshapiro# define SMFTO_READ 1 /* Timeout waiting for a response */ 177890792Sgshapiro# define SMFTO_EOM 2 /* Timeout for ACK/NAK to EOM */ 177990792Sgshapiro# define SMFTO_CONNECT 3 /* Timeout for connect() */ 178064562Sgshapiro 178190792Sgshapiro# define SMFTO_NUM_TO 4 /* Total number of timeouts */ 178264562Sgshapiro 178364562Sgshapirostruct milter 178464562Sgshapiro{ 178564562Sgshapiro char *mf_name; /* filter name */ 178664562Sgshapiro BITMAP256 mf_flags; /* MTA flags */ 178794334Sgshapiro mi_int32 mf_fvers; /* filter version */ 178894334Sgshapiro mi_int32 mf_fflags; /* filter flags */ 178994334Sgshapiro mi_int32 mf_pflags; /* protocol flags */ 179064562Sgshapiro char *mf_conn; /* connection info */ 179164562Sgshapiro int mf_sock; /* connected socket */ 179264562Sgshapiro char mf_state; /* state of filter */ 1793244833Sgshapiro char mf_lflags; /* "local" flags */ 1794244833Sgshapiro int mf_idx; /* milter number (index) */ 179564562Sgshapiro time_t mf_timeout[SMFTO_NUM_TO]; /* timeouts */ 1796168515Sgshapiro#if _FFR_MILTER_CHECK 1797168515Sgshapiro /* for testing only */ 1798168515Sgshapiro mi_int32 mf_mta_prot_version; 1799168515Sgshapiro mi_int32 mf_mta_prot_flags; 1800168515Sgshapiro mi_int32 mf_mta_actions; 1801168515Sgshapiro#endif /* _FFR_MILTER_CHECK */ 180264562Sgshapiro}; 180364562Sgshapiro 1804244833Sgshapiro#define MI_LFL_NONE 0x00000000 1805244833Sgshapiro#define MI_LFLAGS_SYM(st) (1 << (st)) /* has its own symlist for stage st */ 1806244833Sgshapiro 1807173340Sgshapirostruct milters 1808173340Sgshapiro{ 1809173340Sgshapiro mi_int32 mis_flags; /* filter flags */ 1810173340Sgshapiro}; 1811173340Sgshapirotypedef struct milters milters_T; 1812173340Sgshapiro 1813173340Sgshapiro#define MIS_FL_NONE 0x00000000 /* no requirements... */ 1814173340Sgshapiro#define MIS_FL_DEL_RCPT 0x00000001 /* can delete rcpt */ 1815173340Sgshapiro#define MIS_FL_REJ_RCPT 0x00000002 /* can reject rcpt */ 1816173340Sgshapiro 1817173340Sgshapiro 181864562Sgshapiro/* MTA flags */ 181964562Sgshapiro# define SMF_REJECT 'R' /* Reject connection on filter fail */ 182064562Sgshapiro# define SMF_TEMPFAIL 'T' /* tempfail connection on failure */ 1821141858Sgshapiro# define SMF_TEMPDROP '4' /* 421 connection on failure */ 182264562Sgshapiro 182364562SgshapiroEXTERN struct milter *InputFilters[MAXFILTERS]; 182464562SgshapiroEXTERN char *InputFilterList; 182590792SgshapiroEXTERN int MilterLogLevel; 182664562Sgshapiro 182790792Sgshapiro/* functions */ 1828120256Sgshapiroextern void setup_daemon_milters __P((void)); 182990792Sgshapiro#endif /* MILTER */ 183090792Sgshapiro 183138032Speter/* 183238032Speter** Vendor codes 183338032Speter** 183438032Speter** Vendors can customize sendmail to add special behaviour, 183538032Speter** generally for back compatibility. Ideally, this should 183638032Speter** be set up in the .cf file using the "V" command. However, 183738032Speter** it's quite reasonable for some vendors to want the default 183838032Speter** be their old version; this can be set using 183938032Speter** -DVENDOR_DEFAULT=VENDOR_xxx 184038032Speter** in the Makefile. 184138032Speter** 184264562Sgshapiro** Vendors should apply to sendmail@sendmail.org for 184338032Speter** unique vendor codes. 184438032Speter*/ 184538032Speter 184638032Speter#define VENDOR_BERKELEY 1 /* Berkeley-native configuration file */ 184738032Speter#define VENDOR_SUN 2 /* Sun-native configuration file */ 184838032Speter#define VENDOR_HP 3 /* Hewlett-Packard specific config syntax */ 184938032Speter#define VENDOR_IBM 4 /* IBM specific config syntax */ 1850261363Sgshapiro#define VENDOR_SENDMAIL 5 /* Proofpoint, Inc. specific config syntax */ 185190792Sgshapiro#define VENDOR_DEC 6 /* Compaq, DEC, Digital */ 185238032Speter 185338032Speter/* prototypes for vendor-specific hook routines */ 185464562Sgshapiroextern void vendor_daemon_setup __P((ENVELOPE *)); 185538032Speterextern void vendor_set_uid __P((UID_T)); 185638032Speter 185738032Speter 185838032Speter/* 185938032Speter** Terminal escape codes. 186038032Speter** 186138032Speter** To make debugging output clearer. 186238032Speter*/ 186338032Speter 186438032Speterstruct termescape 186538032Speter{ 186638032Speter char *te_rv_on; /* turn reverse-video on */ 1867168515Sgshapiro char *te_under_on; /* turn underlining on */ 1868168515Sgshapiro char *te_normal; /* revert to normal output */ 186938032Speter}; 187038032Speter 187190792Sgshapiro/* 187264562Sgshapiro** Additional definitions 187364562Sgshapiro*/ 187438032Speter 187590792Sgshapiro/* 187690792Sgshapiro** d_flags, see daemon.c 187790792Sgshapiro** general rule: lower case: required, upper case: No 187890792Sgshapiro*/ 187990792Sgshapiro 188064562Sgshapiro#define D_AUTHREQ 'a' /* authentication required */ 188164562Sgshapiro#define D_BINDIF 'b' /* use if_addr for outgoing connection */ 188264562Sgshapiro#define D_CANONREQ 'c' /* canonification required (cf) */ 188364562Sgshapiro#define D_IFNHELO 'h' /* use if name for HELO */ 188464562Sgshapiro#define D_FQMAIL 'f' /* fq sender address required (cf) */ 188564562Sgshapiro#define D_FQRCPT 'r' /* fq recipient address required (cf) */ 1886132943Sgshapiro#define D_SMTPS 's' /* SMTP over SSL (smtps) */ 188764562Sgshapiro#define D_UNQUALOK 'u' /* unqualified address is ok (cf) */ 188890792Sgshapiro#define D_NOAUTH 'A' /* no AUTH */ 188964562Sgshapiro#define D_NOCANON 'C' /* no canonification (cf) */ 189064562Sgshapiro#define D_NOETRN 'E' /* no ETRN (MSA) */ 189190792Sgshapiro#define D_NOTLS 'S' /* don't use STARTTLS */ 189264562Sgshapiro#define D_ETRNONLY ((char)0x01) /* allow only ETRN (disk low) */ 189390792Sgshapiro#define D_OPTIONAL 'O' /* optional socket */ 189490792Sgshapiro#define D_DISABLE ((char)0x02) /* optional socket disabled */ 189590792Sgshapiro#define D_ISSET ((char)0x03) /* this client struct is set */ 189638032Speter 189764562Sgshapiro#if STARTTLS 189890792Sgshapiro/* 189964562Sgshapiro** TLS 190038032Speter*/ 190138032Speter 190264562Sgshapiro/* what to do in the TLS initialization */ 190364562Sgshapiro#define TLS_I_NONE 0x00000000 /* no requirements... */ 1904110560Sgshapiro#define TLS_I_CERT_EX 0x00000001 /* cert must exist */ 1905110560Sgshapiro#define TLS_I_CERT_UNR 0x00000002 /* cert must be g/o unreadable */ 1906110560Sgshapiro#define TLS_I_KEY_EX 0x00000004 /* key must exist */ 1907110560Sgshapiro#define TLS_I_KEY_UNR 0x00000008 /* key must be g/o unreadable */ 1908110560Sgshapiro#define TLS_I_CERTP_EX 0x00000010 /* CA cert path must exist */ 1909110560Sgshapiro#define TLS_I_CERTP_UNR 0x00000020 /* CA cert path must be g/o unreadable */ 1910110560Sgshapiro#define TLS_I_CERTF_EX 0x00000040 /* CA cert file must exist */ 1911110560Sgshapiro#define TLS_I_CERTF_UNR 0x00000080 /* CA cert file must be g/o unreadable */ 191264562Sgshapiro#define TLS_I_RSA_TMP 0x00000100 /* RSA TMP must be generated */ 191364562Sgshapiro#define TLS_I_USE_KEY 0x00000200 /* private key must usable */ 191464562Sgshapiro#define TLS_I_USE_CERT 0x00000400 /* certificate must be usable */ 191564562Sgshapiro#define TLS_I_VRFY_PATH 0x00000800 /* load verify path must succeed */ 191664562Sgshapiro#define TLS_I_VRFY_LOC 0x00001000 /* load verify default must succeed */ 191764562Sgshapiro#define TLS_I_CACHE 0x00002000 /* require cache */ 191864562Sgshapiro#define TLS_I_TRY_DH 0x00004000 /* try DH certificate */ 191964562Sgshapiro#define TLS_I_REQ_DH 0x00008000 /* require DH certificate */ 192064562Sgshapiro#define TLS_I_DHPAR_EX 0x00010000 /* require DH parameters */ 192164562Sgshapiro#define TLS_I_DHPAR_UNR 0x00020000 /* DH param. must be g/o unreadable */ 192264562Sgshapiro#define TLS_I_DH512 0x00040000 /* generate 512bit DH param */ 192364562Sgshapiro#define TLS_I_DH1024 0x00080000 /* generate 1024bit DH param */ 192464562Sgshapiro#define TLS_I_DH2048 0x00100000 /* generate 2048bit DH param */ 192590792Sgshapiro#define TLS_I_NO_VRFY 0x00200000 /* do not require authentication */ 1926110560Sgshapiro#define TLS_I_KEY_OUNR 0x00400000 /* Key must be other unreadable */ 1927132943Sgshapiro#define TLS_I_CRLF_EX 0x00800000 /* CRL file must exist */ 1928132943Sgshapiro#define TLS_I_CRLF_UNR 0x01000000 /* CRL file must be g/o unreadable */ 192942575Speter 193090792Sgshapiro/* require server cert */ 193190792Sgshapiro#define TLS_I_SRV_CERT (TLS_I_CERT_EX | TLS_I_KEY_EX | \ 193290792Sgshapiro TLS_I_KEY_UNR | TLS_I_KEY_OUNR | \ 193390792Sgshapiro TLS_I_CERTP_EX | TLS_I_CERTF_EX | \ 1934157001Sgshapiro TLS_I_USE_KEY | TLS_I_USE_CERT | TLS_I_CACHE) 193590792Sgshapiro 193664562Sgshapiro/* server requirements */ 193790792Sgshapiro#define TLS_I_SRV (TLS_I_SRV_CERT | TLS_I_RSA_TMP | TLS_I_VRFY_PATH | \ 1938284985Sdelphij TLS_I_VRFY_LOC | TLS_I_TRY_DH | TLS_I_DH1024 | \ 1939157001Sgshapiro TLS_I_CACHE) 194038032Speter 194164562Sgshapiro/* client requirements */ 194290792Sgshapiro#define TLS_I_CLT (TLS_I_KEY_UNR | TLS_I_KEY_OUNR) 194364562Sgshapiro 194464562Sgshapiro#define TLS_AUTH_OK 0 194564562Sgshapiro#define TLS_AUTH_NO 1 194664562Sgshapiro#define TLS_AUTH_FAIL (-1) 194790792Sgshapiro 194890792Sgshapiro/* functions */ 1949249729Sgshapiroextern bool init_tls_library __P((bool _fipsmode)); 1950203004Sgshapiroextern bool inittls __P((SSL_CTX **, unsigned long, long, bool, char *, char *, char *, char *, char *)); 195190792Sgshapiroextern bool initclttls __P((bool)); 195290792Sgshapiroextern void setclttls __P((bool)); 195390792Sgshapiroextern bool initsrvtls __P((bool)); 195490792Sgshapiroextern int tls_get_info __P((SSL *, bool, char *, MACROS_T *, bool)); 195590792Sgshapiroextern int endtls __P((SSL *, char *)); 1956249729Sgshapiroextern void tlslogerr __P((int, const char *)); 195790792Sgshapiro 195890792Sgshapiro 1959110560SgshapiroEXTERN char *CACertPath; /* path to CA certificates (dir. with hashes) */ 1960110560SgshapiroEXTERN char *CACertFile; /* file with CA certificate */ 1961110560SgshapiroEXTERN char *CltCertFile; /* file with client certificate */ 1962110560SgshapiroEXTERN char *CltKeyFile; /* file with client private key */ 196390792Sgshapiro# if _FFR_TLS_1 196490792SgshapiroEXTERN char *CipherList; /* list of ciphers */ 196590792SgshapiroEXTERN char *DHParams5; /* file with DH parameters (512) */ 196690792Sgshapiro# endif /* _FFR_TLS_1 */ 196790792SgshapiroEXTERN char *DHParams; /* file with DH parameters */ 196890792SgshapiroEXTERN char *RandFile; /* source of random data */ 1969110560SgshapiroEXTERN char *SrvCertFile; /* file with server certificate */ 1970110560SgshapiroEXTERN char *SrvKeyFile; /* file with server private key */ 1971132943SgshapiroEXTERN char *CRLFile; /* file CRLs */ 1972132943Sgshapiro#if _FFR_CRLPATH 1973132943SgshapiroEXTERN char *CRLPath; /* path to CRLs (dir. with hashes) */ 1974132943Sgshapiro#endif /* _FFR_CRLPATH */ 197590792SgshapiroEXTERN unsigned long TLS_Srv_Opts; /* TLS server options */ 1976203004SgshapiroEXTERN long Srv_SSL_Options, Clt_SSL_Options; /* SSL options */ 197764562Sgshapiro#endif /* STARTTLS */ 197864562Sgshapiro 197990792Sgshapiro/* 198064562Sgshapiro** Queue related items 198138032Speter*/ 198264562Sgshapiro 198390792Sgshapiro/* queue file names */ 1984132943Sgshapiro#define ANYQFL_LETTER '?' 1985132943Sgshapiro#define QUARQF_LETTER 'h' 198690792Sgshapiro#define DATAFL_LETTER 'd' 198790792Sgshapiro#define XSCRPT_LETTER 'x' 198890792Sgshapiro#define NORMQF_LETTER 'q' 198990792Sgshapiro#define NEWQFL_LETTER 't' 199090792Sgshapiro 199190792Sgshapiro# define TEMPQF_LETTER 'T' 199290792Sgshapiro# define LOSEQF_LETTER 'Q' 199390792Sgshapiro 199464562Sgshapiro/* queue sort order */ 199564562Sgshapiro#define QSO_BYPRIORITY 0 /* sort by message priority */ 199664562Sgshapiro#define QSO_BYHOST 1 /* sort by first host name */ 199764562Sgshapiro#define QSO_BYTIME 2 /* sort by submission time */ 199864562Sgshapiro#define QSO_BYFILENAME 3 /* sort by file name only */ 199990792Sgshapiro#define QSO_RANDOM 4 /* sort in random order */ 200090792Sgshapiro#define QSO_BYMODTIME 5 /* sort by modification time */ 2001132943Sgshapiro#define QSO_NONE 6 /* do not sort */ 200290792Sgshapiro#if _FFR_RHS 2003132943Sgshapiro# define QSO_BYSHUFFLE 7 /* sort by shuffled host name */ 200490792Sgshapiro#endif /* _FFR_RHS */ 200564562Sgshapiro 200690792Sgshapiro#define NOQGRP (-1) /* no queue group (yet) */ 200790792Sgshapiro#define ENVQGRP (-2) /* use queue group of envelope */ 200890792Sgshapiro#define NOAQGRP (-3) /* no queue group in addr (yet) */ 200990792Sgshapiro#define ISVALIDQGRP(x) ((x) >= 0) /* valid queue group? */ 201090792Sgshapiro#define NOQDIR (-1) /* no queue directory (yet) */ 201190792Sgshapiro#define ENVQDIR (-2) /* use queue directory of envelope */ 201290792Sgshapiro#define NOAQDIR (-3) /* no queue directory in addr (yet) */ 201390792Sgshapiro#define ISVALIDQDIR(x) ((x) >= 0) /* valid queue directory? */ 201490792Sgshapiro#define RS_QUEUEGROUP "queuegroup" /* ruleset for queue group selection */ 201564562Sgshapiro 201690792Sgshapiro#define NOW ((time_t) (-1)) /* queue return: now */ 201764562Sgshapiro 201890792Sgshapiro/* SuperSafe values */ 201990792Sgshapiro#define SAFE_NO 0 /* no fsync(): don't use... */ 202090792Sgshapiro#define SAFE_INTERACTIVE 1 /* limit fsync() in -odi */ 202190792Sgshapiro#define SAFE_REALLY 2 /* always fsync() */ 2022132943Sgshapiro#define SAFE_REALLY_POSTMILTER 3 /* fsync() if milter says OK */ 202390792Sgshapiro 202490792Sgshapiro/* QueueMode bits */ 2025132943Sgshapiro#define QM_NORMAL ' ' 2026132943Sgshapiro#define QM_QUARANTINE 'Q' 2027132943Sgshapiro#define QM_LOST 'L' 202890792Sgshapiro 202964562Sgshapiro/* Queue Run Limitations */ 203038032Speterstruct queue_char 203138032Speter{ 203290792Sgshapiro char *queue_match; /* string to match */ 203390792Sgshapiro bool queue_negate; /* or not match, if set */ 203490792Sgshapiro struct queue_char *queue_next; 203538032Speter}; 203638032Speter 2037110560Sgshapiro/* run_work_group() flags */ 2038110560Sgshapiro#define RWG_NONE 0x0000 2039110560Sgshapiro#define RWG_FORK 0x0001 2040110560Sgshapiro#define RWG_VERBOSE 0x0002 2041110560Sgshapiro#define RWG_PERSISTENT 0x0004 2042110560Sgshapiro#define RWG_FORCE 0x0008 2043110560Sgshapiro#define RWG_RUNALL 0x0010 2044110560Sgshapiro 204590792Sgshapirotypedef struct queue_char QUEUE_CHAR; 204638032Speter 204790792SgshapiroEXTERN int volatile CurRunners; /* current number of runner children */ 204890792SgshapiroEXTERN int MaxQueueRun; /* maximum number of jobs in one queue run */ 204990792SgshapiroEXTERN int MaxQueueChildren; /* max # of forked queue children */ 205090792SgshapiroEXTERN int MaxRunnersPerQueue; /* max # proc's active in queue group */ 205190792SgshapiroEXTERN int NiceQueueRun; /* nice queue runs to this value */ 205290792SgshapiroEXTERN int NumQueue; /* number of queue groups */ 205390792SgshapiroEXTERN int QueueFileMode; /* mode on files in mail queue */ 205490792SgshapiroEXTERN int QueueMode; /* which queue items to act upon */ 205590792SgshapiroEXTERN int QueueSortOrder; /* queue sorting order algorithm */ 205690792SgshapiroEXTERN time_t MinQueueAge; /* min delivery interval */ 2057203004Sgshapiro#if _FFR_EXPDELAY 2058203004SgshapiroEXTERN time_t MaxQueueAge; /* max delivery interval */ 2059203004Sgshapiro#endif /* _FFR_EXPDELAY */ 206090792SgshapiroEXTERN time_t QueueIntvl; /* intervals between running the queue */ 206190792SgshapiroEXTERN char *QueueDir; /* location of queue directory */ 206290792SgshapiroEXTERN QUEUE_CHAR *QueueLimitId; /* limit queue run to id */ 206390792SgshapiroEXTERN QUEUE_CHAR *QueueLimitQuarantine; /* limit queue run to quarantine reason */ 206490792SgshapiroEXTERN QUEUE_CHAR *QueueLimitRecipient; /* limit queue run to rcpt */ 206590792SgshapiroEXTERN QUEUE_CHAR *QueueLimitSender; /* limit queue run to sender */ 206690792SgshapiroEXTERN QUEUEGRP *Queue[MAXQUEUEGROUPS + 1]; /* queue groups */ 206790792Sgshapiro 206864562Sgshapiro/* functions */ 206964562Sgshapiroextern void assign_queueid __P((ENVELOPE *)); 207090792Sgshapiroextern ADDRESS *copyqueue __P((ADDRESS *, SM_RPOOL_T *)); 207190792Sgshapiroextern void cleanup_queues __P((void)); 207290792Sgshapiroextern bool doqueuerun __P((void)); 207364562Sgshapiroextern void initsys __P((ENVELOPE *)); 207464562Sgshapiroextern void loseqfile __P((ENVELOPE *, char *)); 207590792Sgshapiroextern int name2qid __P((char *)); 207664562Sgshapiroextern char *qid_printname __P((ENVELOPE *)); 207790792Sgshapiroextern char *qid_printqueue __P((int, int)); 207890792Sgshapiroextern void quarantine_queue __P((char *, int)); 207964562Sgshapiroextern char *queuename __P((ENVELOPE *, int)); 208090792Sgshapiroextern void queueup __P((ENVELOPE *, bool, bool)); 208190792Sgshapiroextern bool runqueue __P((bool, bool, bool, bool)); 2082120256Sgshapiroextern bool run_work_group __P((int, int)); 208390792Sgshapiroextern void set_def_queueval __P((QUEUEGRP *, bool)); 208490792Sgshapiroextern void setup_queues __P((bool)); 208590792Sgshapiroextern bool setnewqueue __P((ENVELOPE *)); 208664562Sgshapiroextern bool shouldqueue __P((long, time_t)); 208764562Sgshapiroextern void sync_queue_time __P((void)); 2088125820Sgshapiroextern void init_qid_alg __P((void)); 208990792Sgshapiroextern int print_single_queue __P((int, int)); 209090792Sgshapiro#if REQUIRES_DIR_FSYNC 209190792Sgshapiro# define SYNC_DIR(path, panic) sync_dir(path, panic) 209290792Sgshapiroextern void sync_dir __P((char *, bool)); 209390792Sgshapiro#else /* REQUIRES_DIR_FSYNC */ 209490792Sgshapiro# define SYNC_DIR(path, panic) ((void) 0) 209590792Sgshapiro#endif /* REQUIRES_DIR_FSYNC */ 209638032Speter 209738032Speter/* 209838032Speter** Timeouts 209938032Speter** 210038032Speter** Indicated values are the MINIMUM per RFC 1123 section 5.3.2. 210138032Speter*/ 210238032Speter 210338032SpeterEXTERN struct 210438032Speter{ 210538032Speter /* RFC 1123-specified timeouts [minimum value] */ 210638032Speter time_t to_initial; /* initial greeting timeout [5m] */ 210738032Speter time_t to_mail; /* MAIL command [5m] */ 210838032Speter time_t to_rcpt; /* RCPT command [5m] */ 210938032Speter time_t to_datainit; /* DATA initiation [2m] */ 211038032Speter time_t to_datablock; /* DATA block [3m] */ 211138032Speter time_t to_datafinal; /* DATA completion [10m] */ 211238032Speter time_t to_nextcommand; /* next command [5m] */ 211338032Speter /* following timeouts are not mentioned in RFC 1123 */ 211438032Speter time_t to_iconnect; /* initial connection timeout (first try) */ 211538032Speter time_t to_connect; /* initial connection timeout (later tries) */ 211690792Sgshapiro time_t to_aconnect; /* all connections timeout (MX and A records) */ 211738032Speter time_t to_rset; /* RSET command */ 211838032Speter time_t to_helo; /* HELO command */ 211938032Speter time_t to_quit; /* QUIT command */ 212038032Speter time_t to_miscshort; /* misc short commands (NOOP, VERB, etc) */ 212138032Speter time_t to_ident; /* IDENT protocol requests */ 212238032Speter time_t to_fileopen; /* opening :include: and .forward files */ 212364562Sgshapiro time_t to_control; /* process a control socket command */ 212490792Sgshapiro time_t to_lhlo; /* LMTP: LHLO command */ 212590792Sgshapiro#if SASL 212690792Sgshapiro time_t to_auth; /* AUTH dialogue [10m] */ 212790792Sgshapiro#endif /* SASL */ 212890792Sgshapiro#if STARTTLS 212990792Sgshapiro time_t to_starttls; /* STARTTLS dialogue [10m] */ 213090792Sgshapiro#endif /* STARTTLS */ 213138032Speter /* following are per message */ 213238032Speter time_t to_q_return[MAXTOCLASS]; /* queue return timeouts */ 213338032Speter time_t to_q_warning[MAXTOCLASS]; /* queue warning timeouts */ 213464562Sgshapiro time_t res_retrans[MAXRESTOTYPES]; /* resolver retransmit */ 213564562Sgshapiro int res_retry[MAXRESTOTYPES]; /* resolver retry */ 213638032Speter} TimeOuts; 213738032Speter 213838032Speter/* timeout classes for return and warning timeouts */ 213964562Sgshapiro#define TOC_NORMAL 0 /* normal delivery */ 214064562Sgshapiro#define TOC_URGENT 1 /* urgent delivery */ 214164562Sgshapiro#define TOC_NONURGENT 2 /* non-urgent delivery */ 2142132943Sgshapiro#define TOC_DSN 3 /* DSN delivery */ 214338032Speter 214464562Sgshapiro/* resolver timeout specifiers */ 214564562Sgshapiro#define RES_TO_FIRST 0 /* first attempt */ 214664562Sgshapiro#define RES_TO_NORMAL 1 /* subsequent attempts */ 214764562Sgshapiro#define RES_TO_DEFAULT 2 /* default value */ 214838032Speter 214964562Sgshapiro/* functions */ 215064562Sgshapiroextern void inittimeouts __P((char *, bool)); 215164562Sgshapiro 215238032Speter/* 215390792Sgshapiro** Interface probing 215490792Sgshapiro*/ 215590792Sgshapiro 215690792Sgshapiro#define DPI_PROBENONE 0 /* Don't probe any interfaces */ 215790792Sgshapiro#define DPI_PROBEALL 1 /* Probe all interfaces */ 215890792Sgshapiro#define DPI_SKIPLOOPBACK 2 /* Don't probe loopback interfaces */ 215990792Sgshapiro 216090792Sgshapiro/* 216138032Speter** Trace information 216238032Speter*/ 216338032Speter 216464562Sgshapiro/* macros for debugging flags */ 2165223067Sgshapiro#if NOT_SENDMAIL 2166223067Sgshapiro# define tTd(flag, level) (tTdvect[flag] >= (unsigned char)level) 2167223067Sgshapiro#else 2168223067Sgshapiro# define tTd(flag, level) (tTdvect[flag] >= (unsigned char)level && !IntSig) 2169223067Sgshapiro#endif 217064562Sgshapiro#define tTdlevel(flag) (tTdvect[flag]) 217164562Sgshapiro 217264562Sgshapiro/* variables */ 217390792Sgshapiroextern unsigned char tTdvect[100]; /* trace vector */ 217477349Sgshapiro 217590792Sgshapiro/* 217638032Speter** Miscellaneous information. 217738032Speter*/ 217838032Speter 217938032Speter/* 218038032Speter** The "no queue id" queue id for sm_syslog 218138032Speter*/ 218238032Speter 2183173340Sgshapiro#define NOQID "" 218438032Speter 218590792Sgshapiro#define CURHOSTNAME (CurHostName == NULL ? "local" : CurHostName) 218690792Sgshapiro 218738032Speter/* 218838032Speter** Some in-line functions 218938032Speter*/ 219038032Speter 219138032Speter/* set exit status */ 2192223067Sgshapiro#define setstat(s) \ 2193223067Sgshapiro do \ 2194223067Sgshapiro { \ 2195223067Sgshapiro if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \ 2196223067Sgshapiro ExitStat = s; \ 2197223067Sgshapiro } while (0) 219838032Speter 219938032Speter 220038032Speter#define STRUCTCOPY(s, d) d = s 220190792Sgshapiro 220290792Sgshapiro/* free a pointer if it isn't NULL and set it to NULL */ 220390792Sgshapiro#define SM_FREE_CLR(p) \ 2204223067Sgshapiro do \ 2205223067Sgshapiro { \ 2206223067Sgshapiro if ((p) != NULL) \ 2207223067Sgshapiro { \ 2208223067Sgshapiro sm_free(p); \ 2209223067Sgshapiro (p) = NULL; \ 2210223067Sgshapiro } \ 2211223067Sgshapiro } while (0) 221290792Sgshapiro 221390792Sgshapiro/* 221490792Sgshapiro** Update a permanent string variable with a new value. 221590792Sgshapiro** The old value is freed, the new value is strdup'ed. 221690792Sgshapiro** 221790792Sgshapiro** We use sm_pstrdup_x to duplicate the string because it raises 221890792Sgshapiro** an exception on error, and because it allocates "permanent storage" 221990792Sgshapiro** which is not expected to be freed before process exit. 222090792Sgshapiro** The latter is important for memory leak analysis. 222190792Sgshapiro** 222290792Sgshapiro** If an exception occurs while strdup'ing the new value, 222390792Sgshapiro** then the variable remains set to the old value. 222490792Sgshapiro** That's why the strdup must occur before we free the old value. 222590792Sgshapiro** 222690792Sgshapiro** The macro uses a do loop so that this idiom will work: 222790792Sgshapiro** if (...) 222890792Sgshapiro** PSTRSET(var, val1); 222990792Sgshapiro** else 223090792Sgshapiro** PSTRSET(var, val2); 223190792Sgshapiro*/ 223290792Sgshapiro#define PSTRSET(var, val) \ 223390792Sgshapiro do \ 223490792Sgshapiro { \ 223590792Sgshapiro char *_newval = sm_pstrdup_x(val); \ 223690792Sgshapiro if (var != NULL) \ 223790792Sgshapiro sm_free(var); \ 223890792Sgshapiro var = _newval; \ 223990792Sgshapiro } while (0) 224090792Sgshapiro 2241120256Sgshapiro#define _CHECK_RESTART \ 2242120256Sgshapiro do \ 2243120256Sgshapiro { \ 2244120256Sgshapiro if (ShutdownRequest != NULL) \ 2245120256Sgshapiro shutdown_daemon(); \ 2246120256Sgshapiro else if (RestartRequest != NULL) \ 2247120256Sgshapiro restart_daemon(); \ 2248120256Sgshapiro else if (RestartWorkGroup) \ 2249120256Sgshapiro restart_marked_work_groups(); \ 2250120256Sgshapiro } while (0) 2251120256Sgshapiro 2252120256Sgshapiro# define CHECK_RESTART _CHECK_RESTART 2253120256Sgshapiro 2254244833Sgshapiro#define CHK_CUR_RUNNERS(fct, idx, count) \ 2255244833Sgshapiro do \ 2256244833Sgshapiro { \ 2257244833Sgshapiro if (CurRunners < 0) \ 2258244833Sgshapiro { \ 2259244833Sgshapiro if (LogLevel > 3) \ 2260244833Sgshapiro sm_syslog(LOG_ERR, NOQID, \ 2261244833Sgshapiro "%s: CurRunners=%d, i=%d, count=%d, status=should not happen", \ 2262244833Sgshapiro fct, CurRunners, idx, count); \ 2263244833Sgshapiro CurRunners = 0; \ 2264244833Sgshapiro } \ 2265244833Sgshapiro } while (0) 2266244833Sgshapiro 2267132943Sgshapiro/* reply types (text in SmtpMsgBuffer) */ 2268132943Sgshapiro#define XS_DEFAULT 0 2269132943Sgshapiro#define XS_STARTTLS 1 2270132943Sgshapiro#define XS_AUTH 2 2271223067Sgshapiro#define XS_GREET 3 2272223067Sgshapiro#define XS_EHLO 4 2273223067Sgshapiro#define XS_MAIL 5 2274223067Sgshapiro#define XS_RCPT 6 2275223067Sgshapiro#define XS_DATA 7 2276223067Sgshapiro#define XS_EOM 8 2277223067Sgshapiro#define XS_DATA2 9 2278223067Sgshapiro#define XS_RCPT2 10 2279223067Sgshapiro#define XS_QUIT 15 2280132943Sgshapiro 228190792Sgshapiro/* 228264562Sgshapiro** Global variables. 228364562Sgshapiro*/ 228438032Speter 2285173340Sgshapiro#if _FFR_ADDR_TYPE_MODES 2286173340SgshapiroEXTERN bool AddrTypeModes; /* addr_type: extra "mode" information */ 2287173340Sgshapiro#endif /* _FFR_ADDR_TYPE_MODES */ 228864562SgshapiroEXTERN bool AllowBogusHELO; /* allow syntax errors on HELO command */ 228964562SgshapiroEXTERN bool CheckAliases; /* parse addresses during newaliases */ 2290157001Sgshapiro#if _FFR_QUEUE_RUN_PARANOIA 2291157001SgshapiroEXTERN int CheckQueueRunners; /* check whether queue runners are OK */ 2292157001Sgshapiro#endif /* _FFR_QUEUE_RUN_PARANOIA */ 229364562SgshapiroEXTERN bool ColonOkInAddr; /* single colon legal in address */ 229490792Sgshapiro#if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) 229564562SgshapiroEXTERN bool ConfigFileRead; /* configuration file has been read */ 229690792Sgshapiro#endif /* !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) */ 229790792SgshapiroEXTERN bool DisConnected; /* running with OutChannel redirect to transcript file */ 229864562SgshapiroEXTERN bool DontExpandCnames; /* do not $[...$] expand CNAMEs */ 229964562SgshapiroEXTERN bool DontInitGroups; /* avoid initgroups() because of NIS cost */ 230064562SgshapiroEXTERN bool DontLockReadFiles; /* don't read lock support files */ 230164562SgshapiroEXTERN bool DontPruneRoutes; /* don't prune source routes */ 230264562SgshapiroEXTERN bool ForkQueueRuns; /* fork for each job when running the queue */ 230364562SgshapiroEXTERN bool FromFlag; /* if set, "From" person is explicit */ 2304249729SgshapiroEXTERN bool FipsMode; 230564562SgshapiroEXTERN bool GrabTo; /* if set, get recipients from msg */ 2306168515SgshapiroEXTERN bool EightBitAddrOK; /* we'll let 8-bit addresses through */ 230764562SgshapiroEXTERN bool HasEightBits; /* has at least one eight bit input byte */ 230864562SgshapiroEXTERN bool HasWildcardMX; /* don't use MX records when canonifying */ 230964562SgshapiroEXTERN bool HoldErrs; /* only output errors to transcript */ 231064562SgshapiroEXTERN bool IgnoreHostStatus; /* ignore long term host status files */ 231164562SgshapiroEXTERN bool IgnrDot; /* don't let dot end messages */ 231264562SgshapiroEXTERN bool LogUsrErrs; /* syslog user errors (e.g., SMTP RCPT cmd) */ 231364562SgshapiroEXTERN bool MatchGecos; /* look for user names in gecos field */ 231464562SgshapiroEXTERN bool MeToo; /* send to the sender also */ 231564562SgshapiroEXTERN bool NoAlias; /* suppress aliasing */ 231664562SgshapiroEXTERN bool NoConnect; /* don't connect to non-local mailers */ 231764562SgshapiroEXTERN bool OnlyOneError; /* .... or only want to give one SMTP reply */ 231864562SgshapiroEXTERN bool QuickAbort; /* .... but only if we want a quick abort */ 2319249729Sgshapiro#if _FFR_REJECT_NUL_BYTE 2320249729SgshapiroEXTERN bool RejectNUL; /* reject NUL input byte? */ 2321249729Sgshapiro#endif /* _FFR_REJECT_NUL_BYTE */ 2322132943Sgshapiro#if REQUIRES_DIR_FSYNC 2323110560SgshapiroEXTERN bool RequiresDirfsync; /* requires fsync() for directory */ 2324132943Sgshapiro#endif /* REQUIRES_DIR_FSYNC */ 232590792SgshapiroEXTERN bool volatile RestartWorkGroup; /* daemon needs to restart some work groups */ 232664562SgshapiroEXTERN bool RrtImpliesDsn; /* turn Return-Receipt-To: into DSN */ 232764562SgshapiroEXTERN bool SaveFrom; /* save leading "From" lines */ 232864562SgshapiroEXTERN bool SendMIMEErrors; /* send error messages in MIME format */ 232964562SgshapiroEXTERN bool SevenBitInput; /* force 7-bit data on input */ 233064562SgshapiroEXTERN bool SingleLineFromHeader; /* force From: header to be one line */ 233164562SgshapiroEXTERN bool SingleThreadDelivery; /* single thread hosts on delivery */ 233290792SgshapiroEXTERN bool SoftBounce; /* replace 5xy by 4xy (for testing) */ 233377349SgshapiroEXTERN bool volatile StopRequest; /* stop sending output */ 233464562SgshapiroEXTERN bool SuprErrs; /* set if we are suppressing errors */ 233564562SgshapiroEXTERN bool TryNullMXList; /* if we are the best MX, try host directly */ 233690792SgshapiroEXTERN bool UseMSP; /* mail submission: group writable queue ok? */ 233773188SgshapiroEXTERN bool WorkAroundBrokenAAAA; /* some nameservers return SERVFAIL on AAAA queries */ 233864562SgshapiroEXTERN bool UseErrorsTo; /* use Errors-To: header (back compat) */ 233964562SgshapiroEXTERN bool UseNameServer; /* using DNS -- interpret h_errno & MX RRs */ 234064562SgshapiroEXTERN char InetMode; /* default network for daemon mode */ 234164562SgshapiroEXTERN char OpMode; /* operation mode, see below */ 234264562SgshapiroEXTERN char SpaceSub; /* substitution for <lwsp> */ 2343182352Sgshapiro#if _FFR_BADRCPT_SHUTDOWN 2344182352SgshapiroEXTERN int BadRcptShutdown; /* Shutdown connection for rejected RCPTs */ 2345182352SgshapiroEXTERN int BadRcptShutdownGood; /* above even when there are good RCPTs */ 2346182352Sgshapiro#endif /* _FFR_BADRCPT_SHUTDOWN */ 2347203004SgshapiroEXTERN int BadRcptThrottle; /* Throttle rejected RCPTs per SMTP message */ 2348203004Sgshapiro#if _FFR_RCPTTHROTDELAY 2349203004SgshapiroEXTERN unsigned int BadRcptThrottleDelay; /* delay for BadRcptThrottle */ 2350203004Sgshapiro#else 2351203004Sgshapiro# define BadRcptThrottleDelay 1 2352203004Sgshapiro#endif /* _FFR_RCPTTHROTDELAY */ 235364562SgshapiroEXTERN int CheckpointInterval; /* queue file checkpoint interval */ 235464562SgshapiroEXTERN int ConfigLevel; /* config file level */ 235564562SgshapiroEXTERN int ConnRateThrottle; /* throttle for SMTP connection rate */ 235677349SgshapiroEXTERN int volatile CurChildren; /* current number of daemonic children */ 235764562SgshapiroEXTERN int CurrentLA; /* current load average */ 235864562SgshapiroEXTERN int DefaultNotify; /* default DSN notification flags */ 235990792SgshapiroEXTERN int DelayLA; /* load average to delay connections */ 236090792SgshapiroEXTERN int DontProbeInterfaces; /* don't probe interfaces for names */ 236164562SgshapiroEXTERN int Errors; /* set if errors (local to single pass) */ 236264562SgshapiroEXTERN int ExitStat; /* exit status code */ 236390792SgshapiroEXTERN int FastSplit; /* fast initial splitting of envelopes */ 236464562SgshapiroEXTERN int FileMode; /* mode on files */ 236564562SgshapiroEXTERN int LineNumber; /* line number in current input */ 236664562SgshapiroEXTERN int LogLevel; /* level of logging to perform */ 236764562SgshapiroEXTERN int MaxAliasRecursion; /* maximum depth of alias recursion */ 236864562SgshapiroEXTERN int MaxChildren; /* maximum number of daemonic children */ 236964562SgshapiroEXTERN int MaxForwardEntries; /* maximum number of forward entries */ 237064562SgshapiroEXTERN int MaxHeadersLength; /* max length of headers */ 237164562SgshapiroEXTERN int MaxHopCount; /* max # of hops until bounce */ 237264562SgshapiroEXTERN int MaxMacroRecursion; /* maximum depth of macro recursion */ 237364562SgshapiroEXTERN int MaxMimeFieldLength; /* maximum MIME field length */ 237464562SgshapiroEXTERN int MaxMimeHeaderLength; /* maximum MIME header length */ 2375157001SgshapiroEXTERN int MaxNOOPCommands; /* max "noise" commands before slowdown */ 237638032Speter 237764562SgshapiroEXTERN int MaxRcptPerMsg; /* max recipients per SMTP message */ 237864562SgshapiroEXTERN int MaxRuleRecursion; /* maximum depth of ruleset recursion */ 2379157001Sgshapiro#if _FFR_MSG_ACCEPT 2380159609SgshapiroEXTERN char *MessageAccept; /* "Message accepted for delivery" reply text */ 2381157001Sgshapiro#endif /* _FFR_MSG_ACCEPT */ 2382157001Sgshapiro 238364562SgshapiroEXTERN int MimeMode; /* MIME processing mode */ 238464562SgshapiroEXTERN int NoRecipientAction; 238590792Sgshapiro 238690792Sgshapiro#if SM_CONF_SHM 238790792SgshapiroEXTERN int Numfilesys; /* number of queue file systems */ 238890792SgshapiroEXTERN int *PNumFileSys; 238990792Sgshapiro# define NumFileSys (*PNumFileSys) 239090792Sgshapiro# else /* SM_CONF_SHM */ 239190792SgshapiroEXTERN int NumFileSys; /* number of queue file systems */ 239290792Sgshapiro# endif /* SM_CONF_SHM */ 239390792Sgshapiro 239464562SgshapiroEXTERN int QueueLA; /* load average starting forced queueing */ 239590792SgshapiroEXTERN int RefuseLA; /* load average refusing connections */ 2396110560SgshapiroEXTERN time_t RejectLogInterval; /* time btwn log msgs while refusing */ 2397157001Sgshapiro#if _FFR_MEMSTAT 2398157001SgshapiroEXTERN long QueueLowMem; /* low memory starting forced queueing */ 2399157001SgshapiroEXTERN long RefuseLowMem; /* low memory refusing connections */ 2400157001SgshapiroEXTERN char *MemoryResource;/* memory resource to look up */ 2401157001Sgshapiro#endif /* _FFR_MEMSTAT */ 240290792SgshapiroEXTERN int SuperSafe; /* be extra careful, even if expensive */ 240364562SgshapiroEXTERN int VendorCode; /* vendor-specific operation enhancements */ 240464562SgshapiroEXTERN int Verbose; /* set if blow-by-blow desired */ 240564562SgshapiroEXTERN gid_t DefGid; /* default gid to run as */ 240664562SgshapiroEXTERN gid_t RealGid; /* real gid of caller */ 240764562SgshapiroEXTERN gid_t RunAsGid; /* GID to become for bulk of run */ 240890792SgshapiroEXTERN gid_t EffGid; /* effective gid */ 240990792Sgshapiro#if SM_CONF_SHM 241090792SgshapiroEXTERN key_t ShmKey; /* shared memory key */ 241194334SgshapiroEXTERN char *ShmKeyFile; /* shared memory key file */ 241290792Sgshapiro#endif /* SM_CONF_SHM */ 241390792SgshapiroEXTERN pid_t CurrentPid; /* current process id */ 241490792SgshapiroEXTERN pid_t DaemonPid; /* process id of daemon */ 2415132943SgshapiroEXTERN pid_t PidFilePid; /* daemon/queue runner who wrote pid file */ 241664562SgshapiroEXTERN uid_t DefUid; /* default uid to run as */ 241764562SgshapiroEXTERN uid_t RealUid; /* real uid of caller */ 241864562SgshapiroEXTERN uid_t RunAsUid; /* UID to become for bulk of run */ 241964562SgshapiroEXTERN uid_t TrustedUid; /* uid of trusted user for files and startup */ 242090792SgshapiroEXTERN size_t DataFileBufferSize; /* size of buf for in-core data file */ 242190792SgshapiroEXTERN time_t DeliverByMin; /* deliver by minimum time */ 242264562SgshapiroEXTERN time_t DialDelay; /* delay between dial-on-demand tries */ 242364562SgshapiroEXTERN time_t SafeAlias; /* interval to wait until @:@ in alias file */ 242464562SgshapiroEXTERN time_t ServiceCacheMaxAge; /* refresh interval for cache */ 242590792SgshapiroEXTERN size_t XscriptFileBufferSize; /* size of buf for in-core transcript file */ 242664562SgshapiroEXTERN MODE_T OldUmask; /* umask when sendmail starts up */ 242764562SgshapiroEXTERN long MaxMessageSize; /* advertised max size we will accept */ 242864562SgshapiroEXTERN long MinBlocksFree; /* min # of blocks free on queue fs */ 242964562SgshapiroEXTERN long QueueFactor; /* slope of queue function */ 243064562SgshapiroEXTERN long WkClassFact; /* multiplier for message class -> priority */ 243164562SgshapiroEXTERN long WkRecipFact; /* multiplier for # of recipients -> priority */ 243264562SgshapiroEXTERN long WkTimeFact; /* priority offset each time this job is run */ 243364562SgshapiroEXTERN char *ControlSocketName; /* control socket filename [control.c] */ 243464562SgshapiroEXTERN char *CurHostName; /* current host we are dealing with */ 243564562SgshapiroEXTERN char *DeadLetterDrop; /* path to dead letter office */ 243664562SgshapiroEXTERN char *DefUser; /* default user to run as (from DefUid) */ 243764562SgshapiroEXTERN char *DefaultCharSet; /* default character set for MIME */ 243864562SgshapiroEXTERN char *DoubleBounceAddr; /* where to send double bounces */ 243964562SgshapiroEXTERN char *ErrMsgFile; /* file to prepend to all error messages */ 2440132943SgshapiroEXTERN char *FallbackMX; /* fall back MX host */ 2441132943SgshapiroEXTERN char *FallbackSmartHost; /* fall back smart host */ 244264562SgshapiroEXTERN char *FileName; /* name to print on error messages */ 244364562SgshapiroEXTERN char *ForwardPath; /* path to search for .forward files */ 2444132943SgshapiroEXTERN char *HeloName; /* hostname to announce in HELO */ 244564562SgshapiroEXTERN char *HelpFile; /* location of SMTP help file */ 244664562SgshapiroEXTERN char *HostStatDir; /* location of host status information */ 244764562SgshapiroEXTERN char *HostsFile; /* path to /etc/hosts file */ 244890792Sgshapiroextern char *Mbdb; /* mailbox database type */ 244964562SgshapiroEXTERN char *MustQuoteChars; /* quote these characters in phrases */ 245064562SgshapiroEXTERN char *MyHostName; /* name of this host for SMTP messages */ 245164562SgshapiroEXTERN char *OperatorChars; /* operators (old $o macro) */ 245264562SgshapiroEXTERN char *PidFile; /* location of proc id file [conf.c] */ 245364562SgshapiroEXTERN char *PostMasterCopy; /* address to get errs cc's */ 245464562SgshapiroEXTERN char *ProcTitlePrefix; /* process title prefix */ 245564562SgshapiroEXTERN char *RealHostName; /* name of host we are talking to */ 245664562SgshapiroEXTERN char *RealUserName; /* real user name of caller */ 245777349SgshapiroEXTERN char *volatile RestartRequest;/* a sendmail restart has been requested */ 245864562SgshapiroEXTERN char *RunAsUserName; /* user to become for bulk of run */ 245964562SgshapiroEXTERN char *SafeFileEnv; /* chroot location for file delivery */ 246064562SgshapiroEXTERN char *ServiceSwitchFile; /* backup service switch */ 246177349SgshapiroEXTERN char *volatile ShutdownRequest;/* a sendmail shutdown has been requested */ 2462223067SgshapiroEXTERN bool volatile IntSig; 246364562SgshapiroEXTERN char *SmtpGreeting; /* SMTP greeting message (old $e macro) */ 246464562SgshapiroEXTERN char *SmtpPhase; /* current phase in SMTP processing */ 246564562SgshapiroEXTERN char SmtpError[MAXLINE]; /* save failure error messages */ 246664562SgshapiroEXTERN char *StatFile; /* location of statistics summary */ 246764562SgshapiroEXTERN char *TimeZoneSpec; /* override time zone specification */ 246864562SgshapiroEXTERN char *UdbSpec; /* user database source spec */ 246964562SgshapiroEXTERN char *UnixFromLine; /* UNIX From_ line (old $l macro) */ 247090792SgshapiroEXTERN char **ExternalEnviron; /* saved user (input) environment */ 247177349SgshapiroEXTERN char **SaveArgv; /* argument vector for re-execing */ 247264562SgshapiroEXTERN BITMAP256 DontBlameSendmail; /* DontBlameSendmail bits */ 247390792SgshapiroEXTERN SM_FILE_T *InChannel; /* input connection */ 247490792SgshapiroEXTERN SM_FILE_T *OutChannel; /* output connection */ 247590792SgshapiroEXTERN SM_FILE_T *TrafficLogFile; /* file in which to log all traffic */ 247690792Sgshapiro#if HESIOD 247764562SgshapiroEXTERN void *HesiodContext; 247864562Sgshapiro#endif /* HESIOD */ 247964562SgshapiroEXTERN ENVELOPE *CurEnv; /* envelope currently being processed */ 248064562SgshapiroEXTERN char *RuleSetNames[MAXRWSETS]; /* ruleset number to name */ 248164562SgshapiroEXTERN char *UserEnviron[MAXUSERENVIRON + 1]; 248290792SgshapiroEXTERN struct rewrite *RewriteRules[MAXRWSETS]; 248364562SgshapiroEXTERN struct termescape TermEscape; /* terminal escape codes */ 248464562SgshapiroEXTERN SOCKADDR ConnectOnlyTo; /* override connection address (for testing) */ 248564562SgshapiroEXTERN SOCKADDR RealHostAddr; /* address of host we are talking to */ 248690792Sgshapiroextern const SM_EXC_TYPE_T EtypeQuickAbort; /* type of a QuickAbort exception */ 248764562Sgshapiro 248890792Sgshapiro 2489132943SgshapiroEXTERN int ConnectionRateWindowSize; 2490223067Sgshapiro#if STARTTLS && USE_OPENSSL_ENGINE 2491223067SgshapiroEXTERN bool SSLEngineInitialized; 2492223067Sgshapiro#endif /* STARTTLS && USE_OPENSSL_ENGINE */ 249390792Sgshapiro 249438032Speter/* 249538032Speter** Declarations of useful functions 249638032Speter*/ 249738032Speter 249864562Sgshapiro/* Transcript file */ 249964562Sgshapiroextern void closexscript __P((ENVELOPE *)); 250038032Speterextern void openxscript __P((ENVELOPE *)); 250164562Sgshapiro 250264562Sgshapiro/* error related */ 250364562Sgshapiroextern void buffer_errors __P((void)); 250464562Sgshapiroextern void flush_errors __P((bool)); 250590792Sgshapiroextern void PRINTFLIKE(1, 2) message __P((const char *, ...)); 250690792Sgshapiroextern void PRINTFLIKE(1, 2) nmessage __P((const char *, ...)); 250790792Sgshapiroextern void PRINTFLIKE(1, 2) syserr __P((const char *, ...)); 250890792Sgshapiroextern void PRINTFLIKE(2, 3) usrerrenh __P((char *, const char *, ...)); 250990792Sgshapiroextern void PRINTFLIKE(1, 2) usrerr __P((const char *, ...)); 251064562Sgshapiroextern int isenhsc __P((const char *, int)); 251164562Sgshapiroextern int extenhsc __P((const char *, int, char *)); 251264562Sgshapiro 251364562Sgshapiro/* alias file */ 251464562Sgshapiroextern void alias __P((ADDRESS *, ADDRESS **, int, ENVELOPE *)); 251564562Sgshapiroextern bool aliaswait __P((MAP *, char *, bool)); 251664562Sgshapiroextern void forward __P((ADDRESS *, ADDRESS **, int, ENVELOPE *)); 251790792Sgshapiroextern void readaliases __P((MAP *, SM_FILE_T *, bool, bool)); 251838032Speterextern bool rebuildaliases __P((MAP *, bool)); 251964562Sgshapiroextern void setalias __P((char *)); 252064562Sgshapiro 252164562Sgshapiro/* logging */ 252264562Sgshapiroextern void logdelivery __P((MAILER *, MCI *, char *, const char *, ADDRESS *, time_t, ENVELOPE *)); 252338032Speterextern void logsender __P((ENVELOPE *, char *)); 252490792Sgshapiroextern void PRINTFLIKE(3, 4) sm_syslog __P((int, const char *, const char *, ...)); 252564562Sgshapiro 252664562Sgshapiro/* SMTP */ 252790792Sgshapiroextern void giveresponse __P((int, char *, MAILER *, MCI *, ADDRESS *, time_t, ENVELOPE *, ADDRESS *)); 2528141858Sgshapiroextern int reply __P((MAILER *, MCI *, ENVELOPE *, time_t, void (*)__P((char *, bool, MAILER *, MCI *, ENVELOPE *)), char **, int)); 252964562Sgshapiroextern void smtp __P((char *volatile, BITMAP256, ENVELOPE *volatile)); 253064562Sgshapiro#if SASL 253164562Sgshapiroextern int smtpauth __P((MAILER *, MCI *, ENVELOPE *)); 253264562Sgshapiro#endif /* SASL */ 253390792Sgshapiroextern int smtpdata __P((MAILER *, MCI *, ENVELOPE *, ADDRESS *, time_t)); 253464562Sgshapiroextern int smtpgetstat __P((MAILER *, MCI *, ENVELOPE *)); 253564562Sgshapiroextern int smtpmailfrom __P((MAILER *, MCI *, ENVELOPE *)); 253664562Sgshapiroextern void smtpmessage __P((char *, MAILER *, MCI *, ...)); 253764562Sgshapiroextern void smtpinit __P((MAILER *, MCI *, ENVELOPE *, bool)); 253864562Sgshapiroextern char *smtptodsn __P((int)); 253964562Sgshapiroextern int smtpprobe __P((MCI *)); 254064562Sgshapiroextern void smtpquit __P((MAILER *, MCI *, ENVELOPE *)); 254190792Sgshapiroextern int smtprcpt __P((ADDRESS *, MAILER *, MCI *, ENVELOPE *, ADDRESS *, time_t)); 254238032Speterextern void smtprset __P((MAILER *, MCI *, ENVELOPE *)); 254364562Sgshapiro 2544157001Sgshapiro#define REPLYTYPE(r) ((r) / 100) /* first digit of reply code */ 2545223067Sgshapiro#define REPLYCLASS(r) (((r) / 10) % 10) /* second digit of reply code */ 2546223067Sgshapiro#define REPLYMINOR(r) ((r) % 10) /* last digit of reply code */ 254764562Sgshapiro#define ISSMTPCODE(c) (isascii(c[0]) && isdigit(c[0]) && \ 254864562Sgshapiro isascii(c[1]) && isdigit(c[1]) && \ 254964562Sgshapiro isascii(c[2]) && isdigit(c[2])) 255064562Sgshapiro#define ISSMTPREPLY(c) (ISSMTPCODE(c) && \ 255164562Sgshapiro (c[3] == ' ' || c[3] == '-' || c[3] == '\0')) 255264562Sgshapiro 255364562Sgshapiro/* delivery */ 255490792Sgshapiroextern pid_t dowork __P((int, int, char *, bool, bool, ENVELOPE *)); 255590792Sgshapiroextern pid_t doworklist __P((ENVELOPE *, bool, bool)); 255638032Speterextern int endmailer __P((MCI *, ENVELOPE *, char **)); 255764562Sgshapiroextern int mailfile __P((char *volatile, MAILER *volatile, ADDRESS *, volatile long, ENVELOPE *)); 255838032Speterextern void sendall __P((ENVELOPE *, int)); 255964562Sgshapiro 256064562Sgshapiro/* stats */ 256190792Sgshapiro#define STATS_NORMAL 'n' 2562132943Sgshapiro#define STATS_QUARANTINE 'q' 256390792Sgshapiro#define STATS_REJECT 'r' 256494334Sgshapiro#define STATS_CONNECT 'c' 256590792Sgshapiro 256690792Sgshapiroextern void markstats __P((ENVELOPE *, ADDRESS *, int)); 256764562Sgshapiroextern void clearstats __P((void)); 256838032Speterextern void poststats __P((char *)); 256964562Sgshapiro 257064562Sgshapiro/* control socket */ 257164562Sgshapiroextern void closecontrolsocket __P((bool)); 257264562Sgshapiroextern void clrcontrol __P((void)); 257364562Sgshapiroextern void control_command __P((int, ENVELOPE *)); 257464562Sgshapiroextern int opencontrolsocket __P((void)); 257564562Sgshapiro 257690792Sgshapiro#if MILTER 257764562Sgshapiro/* milter functions */ 257890792Sgshapiroextern void milter_config __P((char *, struct milter **, int)); 257964562Sgshapiroextern void milter_setup __P((char *)); 258064562Sgshapiroextern void milter_set_option __P((char *, char *, bool)); 2581173340Sgshapiroextern bool milter_init __P((ENVELOPE *, char *, milters_T *)); 258264562Sgshapiroextern void milter_quit __P((ENVELOPE *)); 258364562Sgshapiroextern void milter_abort __P((ENVELOPE *)); 258464562Sgshapiroextern char *milter_connect __P((char *, SOCKADDR, ENVELOPE *, char *)); 258564562Sgshapiroextern char *milter_helo __P((char *, ENVELOPE *, char *)); 258664562Sgshapiroextern char *milter_envfrom __P((char **, ENVELOPE *, char *)); 2587132943Sgshapiroextern char *milter_data_cmd __P((ENVELOPE *, char *)); 2588168515Sgshapiroextern char *milter_envrcpt __P((char **, ENVELOPE *, char *, bool)); 258964562Sgshapiroextern char *milter_data __P((ENVELOPE *, char *)); 2590132943Sgshapiroextern char *milter_unknown __P((char *, ENVELOPE *, char *)); 259190792Sgshapiro#endif /* MILTER */ 259264562Sgshapiro 259390792Sgshapiroextern char *addquotes __P((char *, SM_RPOOL_T *)); 259438032Speterextern char *arpadate __P((char *)); 259564562Sgshapiroextern bool atobool __P((char *)); 259664562Sgshapiroextern int atooct __P((char *)); 259764562Sgshapiroextern void auth_warning __P((ENVELOPE *, const char *, ...)); 259864562Sgshapiroextern int blocksignal __P((int)); 259964562Sgshapiroextern bool bitintersect __P((BITMAP256, BITMAP256)); 260064562Sgshapiroextern bool bitzerop __P((BITMAP256)); 260190792Sgshapiroextern int check_bodytype __P((char *)); 260264562Sgshapiroextern void buildfname __P((char *, char *, char *, int)); 260390792Sgshapiroextern bool chkclientmodifiers __P((int)); 260490792Sgshapiroextern bool chkdaemonmodifiers __P((int)); 260564562Sgshapiroextern int checkcompat __P((ADDRESS *, ENVELOPE *)); 260664562Sgshapiro#ifdef XDEBUG 260764562Sgshapiroextern void checkfd012 __P((char *)); 260864562Sgshapiroextern void checkfdopen __P((int, char *)); 260964562Sgshapiro#endif /* XDEBUG */ 261064562Sgshapiroextern void checkfds __P((char *)); 261164562Sgshapiroextern bool chownsafe __P((int, bool)); 261264562Sgshapiroextern void cleanstrcpy __P((char *, char *, int)); 261390792Sgshapiro#if SM_CONF_SHM 261490792Sgshapiroextern void cleanup_shm __P((bool)); 261590792Sgshapiro#endif /* SM_CONF_SHM */ 2616132943Sgshapiroextern void close_sendmail_pid __P((void)); 261764562Sgshapiroextern void clrdaemon __P((void)); 2618120256Sgshapiroextern void collect __P((SM_FILE_T *, bool, HDR **, ENVELOPE *, bool)); 2619132943Sgshapiroextern bool connection_rate_check __P((SOCKADDR *, ENVELOPE *)); 262064562Sgshapiroextern time_t convtime __P((char *, int)); 262190792Sgshapiroextern char **copyplist __P((char **, bool, SM_RPOOL_T *)); 262264562Sgshapiroextern void copy_class __P((int, int)); 2623132943Sgshapiroextern int count_open_connections __P((SOCKADDR *)); 262464562Sgshapiroextern time_t curtime __P((void)); 262564562Sgshapiroextern char *defcharset __P((ENVELOPE *)); 262664562Sgshapiroextern char *denlstring __P((char *, bool, bool)); 2627132943Sgshapiroextern void dferror __P((SM_FILE_T *volatile, char *, ENVELOPE *)); 262864562Sgshapiroextern void disconnect __P((int, ENVELOPE *)); 262990792Sgshapiroextern void disk_status __P((SM_FILE_T *, char *)); 263090792Sgshapiroextern bool dns_getcanonname __P((char *, int, bool, int *, int *)); 263177349Sgshapiroextern pid_t dofork __P((void)); 263238032Speterextern int drop_privileges __P((bool)); 263364562Sgshapiroextern int dsntoexitstat __P((char *)); 263464562Sgshapiroextern void dumpfd __P((int, bool, bool)); 2635168515Sgshapiro#if SM_HEAP_CHECK 2636168515Sgshapiroextern void dumpstab __P((void)); 2637168515Sgshapiro#endif /* SM_HEAP_CHECK */ 263864562Sgshapiroextern void dumpstate __P((char *)); 263990792Sgshapiroextern bool enoughdiskspace __P((long, ENVELOPE *)); 264064562Sgshapiroextern char *exitstat __P((char *)); 264190792Sgshapiroextern void fatal_error __P((SM_EXC_T *)); 2642168515Sgshapiroextern char *fgetfolded __P((char *, int *, SM_FILE_T *)); 264338032Speterextern void fill_fd __P((int, char *)); 264464562Sgshapiroextern char *find_character __P((char *, int)); 264590792Sgshapiroextern int finduser __P((char *, bool *, SM_MBDB_T *)); 264690792Sgshapiroextern void finis __P((bool, bool, volatile int)); 264764562Sgshapiroextern void fixcrlf __P((char *, bool)); 2648168515Sgshapiroextern long freediskspace __P((const char *, long *)); 264977349Sgshapiro#if NETINET6 && NEEDSGETIPNODE 265077349Sgshapiroextern void freehostent __P((struct hostent *)); 265190792Sgshapiro#endif /* NETINET6 && NEEDSGETIPNODE */ 265264562Sgshapiroextern char *get_column __P((char *, int, int, char *, int)); 265364562Sgshapiroextern char *getauthinfo __P((int, bool *)); 265464562Sgshapiroextern int getdtsize __P((void)); 265590792Sgshapiroextern int getla __P((void)); 265690792Sgshapiroextern char *getmodifiers __P((char *, BITMAP256)); 265764562Sgshapiroextern BITMAP256 *getrequests __P((ENVELOPE *)); 265864562Sgshapiroextern char *getvendor __P((int)); 265964562Sgshapiroextern void help __P((char *, ENVELOPE *)); 266064562Sgshapiroextern void init_md __P((int, char **)); 266164562Sgshapiroextern void initdaemon __P((void)); 266264562Sgshapiroextern void inithostmaps __P((void)); 266364562Sgshapiroextern void initmacros __P((ENVELOPE *)); 266464562Sgshapiroextern void initsetproctitle __P((int, char **, char **)); 266564562Sgshapiroextern void init_vendor_macros __P((ENVELOPE *)); 266664562Sgshapiroextern SIGFUNC_DECL intsig __P((int)); 2667249729Sgshapiroextern bool isatom __P((const char *)); 266864562Sgshapiroextern bool isloopback __P((SOCKADDR sa)); 266964562Sgshapiroextern void load_if_names __P((void)); 267064562Sgshapiroextern bool lockfile __P((int, char *, char *, int)); 267164562Sgshapiroextern void log_sendmail_pid __P((ENVELOPE *)); 267290792Sgshapiroextern void logundelrcpts __P((ENVELOPE *, char *, int, bool)); 267364562Sgshapiroextern char lower __P((int)); 267464562Sgshapiroextern void makelower __P((char *)); 267564562Sgshapiroextern int makeconnection_ds __P((char *, MCI *)); 267690792Sgshapiroextern int makeconnection __P((char *, volatile unsigned int, MCI *, ENVELOPE *, time_t)); 267790792Sgshapiroextern void makeworkgroups __P((void)); 2678141858Sgshapiroextern void markfailure __P((ENVELOPE *, ADDRESS *, MCI *, int, bool)); 267990792Sgshapiroextern void mark_work_group_restart __P((int, int)); 2680168515Sgshapiroextern MCI *mci_new __P((SM_RPOOL_T *)); 2681168515Sgshapiroextern char *munchstring __P((char *, char **, int)); 268264562Sgshapiroextern struct hostent *myhostname __P((char *, int)); 2683132943Sgshapiroextern char *newstr __P((const char *)); 2684110560Sgshapiro#if NISPLUS 268564562Sgshapiroextern char *nisplus_default_domain __P((void)); /* extern for Sun */ 2686110560Sgshapiro#endif /* NISPLUS */ 268764562Sgshapiroextern bool path_is_dir __P((char *, bool)); 268890792Sgshapiroextern int pickqdir __P((QUEUEGRP *qg, long fsize, ENVELOPE *e)); 268964562Sgshapiroextern char *pintvl __P((time_t, bool)); 2690132943Sgshapiroextern void printav __P((SM_FILE_T *, char **)); 2691132943Sgshapiroextern void printmailer __P((SM_FILE_T *, MAILER *)); 269290792Sgshapiroextern void printnqe __P((SM_FILE_T *, char *)); 269364562Sgshapiroextern void printopenfds __P((bool)); 269464562Sgshapiroextern void printqueue __P((void)); 269564562Sgshapiroextern void printrules __P((void)); 269677349Sgshapiroextern pid_t prog_open __P((char **, int *, ENVELOPE *)); 2697157001Sgshapiroextern bool putline __P((char *, MCI *)); 2698157001Sgshapiroextern bool putxline __P((char *, size_t, MCI *, int)); 269990792Sgshapiroextern void queueup_macros __P((int, SM_FILE_T *, ENVELOPE *)); 270064562Sgshapiroextern void readcf __P((char *, bool, ENVELOPE *)); 270164562Sgshapiroextern SIGFUNC_DECL reapchild __P((int)); 270264562Sgshapiroextern int releasesignal __P((int)); 270364562Sgshapiroextern void resetlimits __P((void)); 270490792Sgshapiroextern void restart_daemon __P((void)); 2705120256Sgshapiroextern void restart_marked_work_groups __P((void)); 270664562Sgshapiroextern bool rfc822_string __P((char *)); 2707168515Sgshapiroextern void rmexpstab __P((void)); 270890792Sgshapiroextern bool savemail __P((ENVELOPE *, bool)); 270964562Sgshapiroextern void seed_random __P((void)); 271064562Sgshapiroextern void sendtoargv __P((char **, ENVELOPE *)); 271164562Sgshapiroextern void setclientoptions __P((char *)); 271264562Sgshapiroextern bool setdaemonoptions __P((char *)); 271364562Sgshapiroextern void setdefaults __P((ENVELOPE *)); 271464562Sgshapiroextern void setdefuser __P((void)); 271564562Sgshapiroextern bool setvendor __P((char *)); 271690792Sgshapiroextern void set_op_mode __P((int)); 271764562Sgshapiroextern void setoption __P((int, char *, bool, bool, ENVELOPE *)); 271838032Speterextern sigfunc_t setsignal __P((int, sigfunc_t)); 2719157001Sgshapiroextern void sm_setuserenv __P((const char *, const char *)); 272064562Sgshapiroextern void settime __P((ENVELOPE *)); 2721182352Sgshapiro#if STARTTLS 2722182352Sgshapiroextern void set_tls_rd_tmo __P((int)); 2723182352Sgshapiro#else /* STARTTLS */ 2724182352Sgshapiro#define set_tls_rd_tmo(rd_tmo) 2725182352Sgshapiro#endif /* STARTTLS */ 272690792Sgshapiroextern char *sfgets __P((char *, int, SM_FILE_T *, time_t, char *)); 272790792Sgshapiroextern char *shortenstring __P((const char *, size_t)); 272873188Sgshapiroextern char *shorten_hostname __P((char [])); 272964562Sgshapiroextern bool shorten_rfc822_string __P((char *, size_t)); 273077349Sgshapiroextern void shutdown_daemon __P((void)); 2731132943Sgshapiroextern void sm_closefrom __P((int lowest, int highest)); 2732132943Sgshapiroextern void sm_close_on_exec __P((int lowest, int highest)); 273364562Sgshapiroextern struct hostent *sm_gethostbyname __P((char *, int)); 273438032Speterextern struct hostent *sm_gethostbyaddr __P((char *, int, int)); 273590792Sgshapiroextern void sm_getla __P((void)); 273638032Speterextern struct passwd *sm_getpwnam __P((char *)); 273738032Speterextern struct passwd *sm_getpwuid __P((UID_T)); 273864562Sgshapiroextern void sm_setproctitle __P((bool, ENVELOPE *, const char *, ...)); 273990792Sgshapiroextern pid_t sm_wait __P((int *)); 274090792Sgshapiroextern bool split_by_recipient __P((ENVELOPE *e)); 274177349Sgshapiroextern void stop_sendmail __P((void)); 2742110560Sgshapiroextern void stripbackslash __P((char *)); 274398841Sgshapiroextern bool strreplnonprt __P((char *, int)); 274490792Sgshapiroextern bool strcontainedin __P((bool, char *, char *)); 274564562Sgshapiroextern int switch_map_find __P((char *, char *[], short [])); 2746168515Sgshapiro#if STARTTLS 2747168515Sgshapiroextern void tls_set_verify __P((SSL_CTX *, SSL *, bool)); 2748168515Sgshapiro#endif /* STARTTLS */ 274964562Sgshapiroextern bool transienterror __P((int)); 275090792Sgshapiroextern void truncate_at_delim __P((char *, size_t, int)); 275164562Sgshapiroextern void tTflag __P((char *)); 275290792Sgshapiroextern void tTsetup __P((unsigned char *, unsigned int, char *)); 275390792Sgshapiroextern SIGFUNC_DECL tick __P((int)); 275464562Sgshapiroextern char *ttypath __P((void)); 275564562Sgshapiroextern void unlockqueue __P((ENVELOPE *)); 275664562Sgshapiro#if !HASUNSETENV 275764562Sgshapiroextern void unsetenv __P((char *)); 275864562Sgshapiro#endif /* !HASUNSETENV */ 275990792Sgshapiro 276090792Sgshapiro/* update file system information: +/- some blocks */ 276190792Sgshapiro#if SM_CONF_SHM 2762184980Sgshapiroextern void upd_qs __P((ENVELOPE *, int, int, char *)); 2763147078Sgshapiro# define updfs(e, count, space, where) upd_qs(e, count, space, where) 276490792Sgshapiro#else /* SM_CONF_SHM */ 2765147078Sgshapiro# define updfs(e, count, space, where) 2766147078Sgshapiro# define upd_qs(e, count, space, where) 276790792Sgshapiro#endif /* SM_CONF_SHM */ 276890792Sgshapiro 276964562Sgshapiroextern char *username __P((void)); 277064562Sgshapiroextern bool usershellok __P((char *, char *)); 277164562Sgshapiroextern void vendor_post_defaults __P((ENVELOPE *)); 277264562Sgshapiroextern void vendor_pre_defaults __P((ENVELOPE *)); 277364562Sgshapiroextern int waitfor __P((pid_t)); 277464562Sgshapiroextern bool writable __P((char *, ADDRESS *, long)); 277590792Sgshapiro#if SM_HEAP_CHECK 277690792Sgshapiro# define xalloc(size) xalloc_tagged(size, __FILE__, __LINE__) 277790792Sgshapiroextern char *xalloc_tagged __P((int, char*, int)); 277890792Sgshapiro#else /* SM_HEAP_CHECK */ 277990792Sgshapiroextern char *xalloc __P((int)); 278090792Sgshapiro#endif /* SM_HEAP_CHECK */ 2781132943Sgshapiroextern void xputs __P((SM_FILE_T *, const char *)); 278264562Sgshapiroextern char *xtextify __P((char *, char *)); 278364562Sgshapiroextern bool xtextok __P((char *)); 278490792Sgshapiroextern int xunlink __P((char *)); 278564562Sgshapiroextern char *xuntextify __P((char *)); 278690792Sgshapiro 278790792Sgshapiro 2788168515Sgshapiro#undef EXTERN 278990792Sgshapiro#endif /* ! _SENDMAIL_H */ 2790