1295Seric /*
23313Seric **  SENDMAIL.H -- Global definitions for sendmail.
3295Seric */
4295Seric 
5295Seric 
6295Seric 
74371Seric # ifdef _DEFINE
84371Seric # define EXTERN
95194Seric # ifndef lint
10*8268Seric static char SmailSccsId[] =	"@(#)sendmail.h	3.91		09/26/82";
115194Seric # endif lint
124371Seric # else  _DEFINE
134371Seric # define EXTERN extern
144371Seric # endif _DEFINE
15295Seric 
164183Seric # include <stdio.h>
174183Seric # include <ctype.h>
187355Seric # include <setjmp.h>
191390Seric # include "useful.h"
201390Seric 
217674Seric # ifdef LOG
227674Seric # include <syslog.h>
237674Seric # endif LOG
247799Seric /*
254284Seric **  Configuration constants.
264284Seric **	There shouldn't be much need to change these....
27295Seric */
28295Seric 
294374Seric # define MAXLINE	256		/* max line length */
304374Seric # define MAXNAME	128		/* max length of a name */
314374Seric # define MAXFIELD	2500		/* max total length of a hdr field */
324374Seric # define MAXPV		40		/* max # of parms to mailers */
334374Seric # define MAXHOP		30		/* max value of HopCount */
347799Seric # define MAXATOM	100		/* max atoms per address */
358006Seric # define MAXMAILERS	25		/* maximum mailers known to system */
368057Seric # define MAXRWSETS	30		/* max # of sets of rewriting rules */
378249Seric # define MAXPRIORITIES	25		/* max values for Precedence: field */
384374Seric # define SPACESUB	('.'|0200)	/* substitution for <lwsp> */
396902Seric /*
403190Seric **  Address structure.
413190Seric **	Addresses are stored internally in this structure.
423190Seric */
433190Seric 
443190Seric struct address
453190Seric {
463190Seric 	char		*q_paddr;	/* the printname for the address */
473190Seric 	char		*q_user;	/* user name */
483190Seric 	char		*q_host;	/* host name */
494597Seric 	struct mailer	*q_mailer;	/* mailer to use */
504149Seric 	u_short		q_flags;	/* status flags, see below */
514213Seric 	short		q_uid;		/* user-id of receiver (if known) */
524398Seric 	short		q_gid;		/* group-id of receiver (if known) */
534079Seric 	char		*q_home;	/* home dir (local mailer only) */
544995Seric 	char		*q_fullname;	/* full name if known */
554995Seric 	struct address	*q_next;	/* chain */
564995Seric 	struct address	*q_alias;	/* address this results from */
575034Seric 	struct address	*q_tchain;	/* temporary use chain */
584987Seric 	time_t		q_timeout;	/* timeout for this address */
593190Seric };
603190Seric 
613190Seric typedef struct address ADDRESS;
623190Seric 
633190Seric # define QDONTSEND	000001	/* don't send to this address */
644068Seric # define QBADADDR	000002	/* this address is verified bad */
654403Seric # define QGOODUID	000004	/* the q_uid q_gid fields are good */
664422Seric # define QPRIMARY	000010	/* set from argv */
674624Seric # define QQUEUEUP	000020	/* queue for later transmission */
686902Seric /*
69295Seric **  Mailer definition structure.
70295Seric **	Every mailer known to the system is declared in this
71295Seric **	structure.  It defines the pathname of the mailer, some
72295Seric **	flags associated with it, and the argument vector to
731390Seric **	pass to it.  The flags are defined in conf.c
74295Seric **
754171Seric **	The argument vector is expanded before actual use.  All
764171Seric **	words except the first are passed through the macro
774171Seric **	processor.
78295Seric */
79295Seric 
80295Seric struct mailer
81295Seric {
823190Seric 	char	*m_name;	/* symbolic name of this mailer */
83295Seric 	char	*m_mailer;	/* pathname of the mailer to use */
844149Seric 	u_long	m_flags;	/* status flags, see below */
85295Seric 	short	m_badstat;	/* the status code to use on unknown error */
864438Seric 	short	m_mno;		/* mailer number internally */
873049Seric 	char	**m_argv;	/* template argument vector */
888061Seric 	short	m_s_rwset;	/* rewriting set for sender addresses */
898061Seric 	short	m_r_rwset;	/* rewriting set for recipient addresses */
90295Seric };
91295Seric 
924100Seric typedef struct mailer	MAILER;
934100Seric 
945601Seric /* bits for m_flags */
956819Seric # define M_FOPT		000000001L	/* mailer takes picky -f flag */
966819Seric # define M_ROPT		000000002L	/* mailer takes picky -r flag */
976819Seric # define M_QUIET	000000004L	/* don't print error on bad status */
986819Seric # define M_RESTR	000000010L	/* must be daemon to execute */
996819Seric # define M_NHDR		000000020L	/* don't insert From line */
1006819Seric # define M_LOCAL	000000040L	/* delivery is to this host */
1016819Seric # define M_STRIPQ	000000100L	/* strip quote chars from user/host */
1026819Seric # define M_MUSER	000000200L	/* can handle multiple users at once */
1036819Seric # define M_NEEDFROM	000000400L	/* need arpa-style From: line */
1046819Seric # define M_NEEDDATE	000001000L	/* need arpa-style Date: line */
1056819Seric # define M_MSGID	000002000L	/* need Message-Id: field */
1068180Seric # define M_CANONICAL	000004000L	/* make addresses canonical "u@dom" */
1076819Seric # define M_USR_UPPER	000010000L	/* preserve user case distinction */
1086819Seric # define M_HST_UPPER	000020000L	/* preserve host case distinction */
1096819Seric # define M_FULLNAME	000040000L	/* want Full-Name field */
1106819Seric # define M_UGLYUUCP	000100000L	/* this wants an ugly UUCP from line */
1116819Seric # define M_EXPENSIVE	000200000L	/* it costs to use this mailer.... */
1126982Seric # define M_FULLSMTP	000400000L	/* must run full SMTP, inc. limits */
113295Seric 
1144317Seric # define M_ARPAFMT	(M_NEEDDATE|M_NEEDFROM|M_MSGID)
1152899Seric 
1164597Seric EXTERN MAILER	*Mailer[MAXMAILERS+1];
117295Seric 
1184597Seric EXTERN MAILER	*LocalMailer;		/* ptr to local mailer */
1194597Seric EXTERN MAILER	*ProgMailer;		/* ptr to program mailer */
1206902Seric /*
1212899Seric **  Header structure.
1222899Seric **	This structure is used internally to store header items.
1232899Seric */
124295Seric 
1252899Seric struct header
1262899Seric {
1272899Seric 	char		*h_field;	/* the name of the field */
1282899Seric 	char		*h_value;	/* the value of that field */
1292899Seric 	struct header	*h_link;	/* the next header */
1304149Seric 	u_short		h_flags;	/* status bits, see below */
1314149Seric 	u_long		h_mflags;	/* m_flags bits needed */
1322899Seric };
133295Seric 
1342899Seric typedef struct header	HDR;
1352899Seric 
136295Seric /*
1372899Seric **  Header information structure.
1382899Seric **	Defined in conf.c, this struct declares the header fields
1392899Seric **	that have some magic meaning.
1402899Seric */
1412899Seric 
1422899Seric struct hdrinfo
1432899Seric {
1442899Seric 	char	*hi_field;	/* the name of the field */
1454149Seric 	u_short	hi_flags;	/* status bits, see below */
1464149Seric 	u_short	hi_mflags;	/* m_flags needed for this field */
1472899Seric };
1482899Seric 
1492899Seric extern struct hdrinfo	HdrInfo[];
1502899Seric 
1512899Seric /* bits for h_flags and hi_flags */
1523060Seric # define H_EOH		00001	/* this field terminates header */
1535918Seric # define H_RCPT		00002	/* contains recipient addresses */
1542899Seric # define H_DEFAULT	00004	/* if another value is found, drop this */
1552899Seric # define H_USED		00010	/* indicates that this has been output */
1563386Seric # define H_CHECK	00020	/* check h_mflags against m_flags */
1573390Seric # define H_ACHECK	00040	/* ditto, but always (not just default) */
1584149Seric # define H_FORCE	00100	/* force this field, even if default */
1598061Seric # define H_TRACE	00200	/* this field contains trace information */
1607761Seric # define H_FROM		00400	/* this is a from-type field */
1616902Seric /*
1626902Seric **  Envelope structure.
1636902Seric **	This structure defines the message itself.  There is usually
1646902Seric **	only one of these -- for the message that we originally read
1656902Seric **	and which is our primary interest -- but other envelopes can
1666902Seric **	be generated during processing.  For example, error messages
1676902Seric **	will have their own envelope.
1686902Seric */
1692899Seric 
1706902Seric struct envelope
1716902Seric {
1726987Seric 	HDR		*e_header;	/* head of header list */
1736987Seric 	long		e_msgpriority;	/* adjusted priority of this message */
1747859Seric 	time_t		e_ctime;	/* time message appeared in the queue */
1756987Seric 	bool		e_queueup;	/* queue this message */
1767859Seric 	bool		e_dontqueue;	/* override queueing */
1776987Seric 	bool		e_oldstyle;	/* use spaces (not commas) in hdrs */
1786987Seric 	bool		e_sendreceipt;	/* actually send a receipt back */
1796987Seric 	char		*e_to;		/* the target person */
1808061Seric 	char		*e_receiptto;	/* return receipt address */
1816987Seric 	ADDRESS		e_from;		/* the person it is from */
1828180Seric 	char		**e_fromdomain;	/* the domain part of the sender */
1836987Seric 	ADDRESS		*e_sendqueue;	/* list of message recipients */
1847044Seric 	ADDRESS		*e_errorqueue;	/* the queue for error responses */
1856987Seric 	long		e_msgsize;	/* size of the message in bytes */
1866987Seric 	short		e_class;	/* msg class (priority, junk, etc.) */
1876987Seric 	int		(*e_puthdr)();	/* function to put header of message */
1886987Seric 	int		(*e_putbody)();	/* function to put body of message */
1896987Seric 	struct envelope	*e_parent;	/* the message this one encloses */
1906987Seric 	char		*e_df;		/* location of temp file */
1917810Seric 	char		*e_qf;		/* queue control file */
1927810Seric 	char		*e_id;		/* code for this entry in queue */
1936987Seric 	char		*e_macro[128];	/* macro definitions */
1946902Seric };
1952899Seric 
1966902Seric typedef struct envelope	ENVELOPE;
1974624Seric 
1986902Seric EXTERN ENVELOPE	*CurEnv;	/* envelope currently being processed */
1996902Seric /*
2004624Seric **  Work queue.
2014624Seric */
2024624Seric 
2034624Seric struct work
2044624Seric {
2054624Seric 	char		*w_name;	/* name of control file */
2065034Seric 	long		w_pri;		/* priority of message, see below */
2074624Seric 	struct work	*w_next;	/* next in queue */
2084624Seric };
2094624Seric 
2104624Seric typedef struct work	WORK;
2114624Seric 
2124624Seric EXTERN WORK	*WorkQ;			/* queue of things to be done */
2134624Seric 
2144624Seric 
2154624Seric /*
2164624Seric **  Message priorities.
2174633Seric **	Priorities > 0 should be preemptive.
2185034Seric **
2196902Seric **	CurEnv->e_msgpriority is the number of bytes in the message adjusted
2205034Seric **	by the message priority and the amount of time the message
2215034Seric **	has been sitting around.  Each priority point is worth
2225034Seric **	WKPRIFACT bytes of message, and each time we reprocess a
2235034Seric **	message the size gets reduced by WKTIMEFACT.
2246910Seric **
2256910Seric **	The "class" is this number, unadjusted by the age or size of
2266910Seric **	this message.  Classes with negative representations will have
2276910Seric **	error messages thrown away if they are not local.
2284624Seric */
2294624Seric 
2308249Seric struct priority
2318249Seric {
2328249Seric 	char	*pri_name;	/* external name of priority */
2338249Seric 	int	pri_val;	/* internal value for same */
2348249Seric };
2354624Seric 
2368249Seric EXTERN struct priority	Priorities[MAXPRIORITIES];
2378249Seric EXTERN int		NumPriorities;	/* pointer into Priorities */
2388249Seric 
2395034Seric # define WKPRIFACT	1800		/* bytes each pri point is worth */
2405034Seric # define WKTIMEFACT	400		/* bytes each time unit is worth */
2416902Seric /*
2423153Seric **  Rewrite rules.
2433153Seric */
2442899Seric 
2453153Seric struct rewrite
2463153Seric {
2473153Seric 	char	**r_lhs;	/* pattern match */
2483153Seric 	char	**r_rhs;	/* substitution value */
2493153Seric 	struct rewrite	*r_next;/* next in chain */
2503153Seric };
2512899Seric 
2528057Seric EXTERN struct rewrite	*RewriteRules[MAXRWSETS];
2533153Seric 
2548057Seric /*
2558057Seric **  Special characters in rewriting rules.
2568057Seric **	These are used internally only.
2578057Seric **	The COND* rules are actually used in macros rather than in
2588057Seric **		rewriting rules, but are given here because they
2598057Seric **		cannot conflict.
2608057Seric */
2613153Seric 
2628057Seric /* left hand side items */
2638057Seric # define MATCHZANY	'\020'	/* match zero or more tokens */
2648057Seric # define MATCHANY	'\021'	/* match one or more tokens */
2658057Seric # define MATCHONE	'\022'	/* match exactly one token */
2668057Seric # define MATCHCLASS	'\023'	/* match one token in a class */
2678057Seric # define MATCHREPL	'\024'	/* replacement on RHS for above */
2688057Seric 
2698057Seric /* right hand side items */
2703153Seric # define CANONNET	'\025'	/* canonical net, next token */
2713153Seric # define CANONHOST	'\026'	/* canonical host, next token */
2723153Seric # define CANONUSER	'\027'	/* canonical user, next N tokens */
2738057Seric # define CALLSUBR	'\030'	/* call another rewriting set */
2743153Seric 
2758057Seric /* conditionals in macros */
2768057Seric # define CONDIF		'\031'	/* conditional if-then */
2778057Seric # define CONDELSE	'\032'	/* conditional else */
2788057Seric # define CONDFI		'\033'	/* conditional fi */
2796902Seric /*
2804056Seric **  Symbol table definitions
2814056Seric */
2823153Seric 
2834056Seric struct symtab
2844056Seric {
2854056Seric 	char		*s_name;	/* name to be entered */
2864100Seric 	char		s_type;		/* general type (see below) */
2874056Seric 	struct symtab	*s_next;	/* pointer to next in chain */
2884100Seric 	union
2894100Seric 	{
2904100Seric 		long	sv_class;	/* bit-map of word classes */
2914100Seric 		ADDRESS	*sv_addr;	/* pointer to address header */
2924100Seric 		MAILER	*sv_mailer;	/* pointer to mailer */
2934100Seric 		char	*sv_alias;	/* alias */
2944100Seric 	}	s_value;
2954056Seric };
2964056Seric 
2974056Seric typedef struct symtab	STAB;
2984056Seric 
2994100Seric /* symbol types */
3004100Seric # define ST_UNDEF	0	/* undefined type */
3014100Seric # define ST_CLASS	1	/* class map */
3024100Seric # define ST_ADDRESS	2	/* an address in parsed format */
3034100Seric # define ST_MAILER	3	/* a mailer header */
3044100Seric # define ST_ALIAS	4	/* an alias */
3054100Seric 
3064100Seric # define s_class	s_value.sv_class
3075976Seric # define s_address	s_value.sv_addr
3084100Seric # define s_mailer	s_value.sv_mailer
3094100Seric # define s_alias	s_value.sv_alias
3104100Seric 
3114056Seric extern STAB	*stab();
3124056Seric 
3134056Seric /* opcodes to stab */
3144056Seric # define ST_FIND	0	/* find entry */
3154056Seric # define ST_ENTER	1	/* enter if not there */
3166902Seric /*
3177684Seric **  STRUCT EVENT -- event queue.
3187684Seric **
3197684Seric **	Maintained in sorted order.
3207931Seric **
3217931Seric **	We store the pid of the process that set this event to insure
3227931Seric **	that when we fork we will not take events intended for the parent.
3237684Seric */
3247684Seric 
3257684Seric struct event
3267684Seric {
3277684Seric 	time_t		ev_time;	/* time of the function call */
3287684Seric 	int		(*ev_func)();	/* function to call */
3297684Seric 	int		ev_arg;		/* argument to ev_func */
3307931Seric 	int		ev_pid;		/* pid that set this event */
3317684Seric 	struct event	*ev_link;	/* link to next item */
3327684Seric };
3337684Seric 
3347684Seric typedef struct event	EVENT;
3357684Seric 
3367684Seric EXTERN EVENT	*EventQueue;		/* head of event queue */
3377684Seric /*
3384284Seric **  Statistics structure.
3394284Seric */
3404284Seric 
3414284Seric struct statistics
3424284Seric {
3434284Seric 	time_t	stat_itime;		/* file initialization time */
3444284Seric 	short	stat_size;		/* size of this structure */
3454284Seric 	long	stat_nf[MAXMAILERS];	/* # msgs from each mailer */
3464284Seric 	long	stat_bf[MAXMAILERS];	/* kbytes from each mailer */
3474284Seric 	long	stat_nt[MAXMAILERS];	/* # msgs to each mailer */
3484284Seric 	long	stat_bt[MAXMAILERS];	/* kbytes to each mailer */
3494284Seric };
3504284Seric 
3514371Seric EXTERN struct statistics	Stat;
3524284Seric extern long			kbytes();	/* for _bf, _bt */
3536902Seric /*
3546997Seric **  Operation modes
3556997Seric **	The default operation mode can be safely changed (except
3566997Seric **	that the default cannot be MD_DAEMON).
3576997Seric */
3586997Seric 
3596997Seric EXTERN char	Mode;		/* operation mode, see below */
3606997Seric 
3616997Seric #define MD_DELIVER	'a'		/* collect and deliver */
3626997Seric #define MD_FORK		'f'		/* verify & fork before delivery */
3636997Seric #define MD_QUEUE	'q'		/* collect & queue, don't deliver */
3646997Seric #define MD_DAEMON	'd'		/* run as a daemon */
3656997Seric #define MD_VERIFY	'v'		/* verify: don't collect or deliver */
3666997Seric 
3676997Seric #define MD_DEFAULT	MD_DELIVER	/* default operation mode */
3686997Seric /*
369295Seric **  Global variables.
370295Seric */
371295Seric 
3724371Seric EXTERN bool	FromFlag;	/* if set, "From" person is explicit */
3734371Seric EXTERN bool	MailBack;	/* mail back response on error */
3744371Seric EXTERN bool	BerkNet;	/* called from BerkNet */
3754371Seric EXTERN bool	WriteBack;	/* write back response on error */
3764371Seric EXTERN bool	NoAlias;	/* if set, don't do any aliasing */
3774371Seric EXTERN bool	ForceMail;	/* if set, mail even if already got a copy */
3784371Seric EXTERN bool	MeToo;		/* send to the sender also */
3794371Seric EXTERN bool	IgnrDot;	/* don't let dot end messages */
3804371Seric EXTERN bool	SaveFrom;	/* save leading "From" lines */
3814371Seric EXTERN bool	Verbose;	/* set if blow-by-blow desired */
3824371Seric EXTERN bool	GrabTo;		/* if set, get recipients from msg */
3834371Seric EXTERN bool	DontSend;	/* mark recipients as QDONTSEND */
3844371Seric EXTERN bool	NoReturn;	/* don't return letter to sender */
3854553Seric EXTERN bool	Smtp;		/* using SMTP over connection */
3864553Seric EXTERN bool	SuprErrs;	/* set if we are suppressing errors */
3876049Seric EXTERN bool	QueueRun;	/* currently running message from the queue */
3884711Seric EXTERN bool	HoldErrs;	/* only output errors to transcript */
3894711Seric EXTERN bool	ArpaMode;	/* set if running arpanet protocol */
3905904Seric EXTERN bool	NoConnect;	/* don't connect to non-local mailers */
3916049Seric EXTERN bool	FatalErrors;	/* set if fatal errors during processing */
392*8268Seric EXTERN bool	SuperSafe;	/* be extra careful, even if expensive */
393*8268Seric EXTERN time_t	TimeOut;	/* time until timeout */
3944553Seric EXTERN FILE	*InChannel;	/* input connection */
3954553Seric EXTERN FILE	*OutChannel;	/* output connection */
3964553Seric EXTERN FILE	*TempFile;	/* mail temp file */
3974711Seric EXTERN FILE	*Xscript;	/* mail transcript file */
3984537Seric EXTERN int	RealUid;	/* when Daemon, real uid of caller */
3994537Seric EXTERN int	RealGid;	/* when Daemon, real gid of caller */
400*8268Seric EXTERN int	DefUid;		/* default uid to run as */
401*8268Seric EXTERN int	DefGid;		/* default gid to run as */
4024371Seric EXTERN int	OldUmask;	/* umask when sendmail starts up */
4036049Seric EXTERN int	Errors;		/* set if errors (local to single pass) */
4044371Seric EXTERN int	ExitStat;	/* exit status code */
4054553Seric EXTERN int	HopCount;	/* hop count */
4064553Seric EXTERN int	AliasLevel;	/* depth of aliasing */
4077282Seric EXTERN int	MotherPid;	/* proc id of parent process */
4088057Seric EXTERN int	LineNumber;	/* line number in current input */
409*8268Seric EXTERN int	ReadTimeout;	/* timeout on reads */
410*8268Seric EXTERN int	LogLevel;	/* level of logging to perform */
4114624Seric EXTERN time_t	QueueIntvl;	/* intervals between running the queue */
4124553Seric EXTERN char	*HostName;	/* name of this host for SMTP messages */
4134624Seric EXTERN char	*Transcript;	/* the transcript file name */
414*8268Seric EXTERN char	*AliasFile;	/* location of alias file */
415*8268Seric EXTERN char	*HelpFile;	/* location of SMTP help file */
416*8268Seric EXTERN char	*StatFile;	/* location of statistics summary */
417*8268Seric EXTERN char	*QueueDir;	/* location of queue directory */
418*8268Seric EXTERN jmp_buf	TopFrame;	/* branch-to-top-of-loop-on-error frame */
419*8268Seric EXTERN bool	QuickAbort;	/*  .... but only if we want a quick abort */
4207859Seric extern char	*XcriptFile;	/* template for Transcript [conf.c] */
4217859Seric extern char	*ConfFile;	/* location of configuration file [conf.c] */
4227859Seric extern char	Arpa_Info[];	/* the reply code for Arpanet info [conf.c] */
4237674Seric /*
4247674Seric **  Trace information
4257674Seric */
426295Seric 
4277674Seric /* trace vector and macros for debugging flags */
4287674Seric EXTERN u_char	tTdvect[100];
4297674Seric # define tTd(flag, level)	(tTdvect[flag] >= level)
4307674Seric # define tTdlevel(flag)		(tTdvect[flag])
4317674Seric /*
4327674Seric **  Miscellaneous information.
4337674Seric */
434295Seric 
435295Seric # include	<sysexits.h>
436295Seric 
437295Seric # define setstat(s)		{ if (ExitStat == EX_OK) ExitStat = s; }
4384085Seric 
4394085Seric 
4404085Seric /* useful functions */
4414085Seric 
4424085Seric extern char	*newstr();
4434085Seric extern ADDRESS	*parse();
4444085Seric extern char	*xalloc();
4454085Seric extern bool	sameaddr();
4466889Seric extern FILE	*dfopen();
4477684Seric extern EVENT	*setevent();
4487684Seric extern char	*sfgets();
4497810Seric extern char	*queuename();
4507884Seric extern time_t	curtime();
451