1295Seric /*
23313Seric **  SENDMAIL.H -- Global definitions for sendmail.
3295Seric */
4295Seric 
5295Seric 
6295Seric 
74371Seric # ifdef _DEFINE
84371Seric # define EXTERN
9*4987Seric static char SmailSccsId[] =	"@(#)sendmail.h	3.52.1.1	11/21/81";
104371Seric # else  _DEFINE
114371Seric # define EXTERN extern
124371Seric # endif _DEFINE
13295Seric 
144624Seric # ifndef major
154624Seric # include <sys/types.h>
164624Seric # endif major
174183Seric # include <stdio.h>
184183Seric # include <ctype.h>
191390Seric # include "useful.h"
201390Seric 
21295Seric /*
224284Seric **  Configuration constants.
234284Seric **	There shouldn't be much need to change these....
24295Seric */
25295Seric 
264374Seric # define MAXLINE	256		/* max line length */
274374Seric # define MAXNAME	128		/* max length of a name */
284374Seric # define MAXFIELD	2500		/* max total length of a hdr field */
294374Seric # define MAXPV		40		/* max # of parms to mailers */
304374Seric # define MAXHOP		30		/* max value of HopCount */
314384Seric # define MAXATOM	30		/* max atoms per address */
324374Seric # define MAXMAILERS	10		/* maximum mailers known to system */
334374Seric # define SPACESUB	('.'|0200)	/* substitution for <lwsp> */
34295Seric 
354167Seric extern char	Arpa_Info[];	/* the message number for Arpanet info */
36295Seric 
37295Seric 
38295Seric 
393190Seric 
404162Seric 
414167Seric 
42295Seric /*
433190Seric **  Address structure.
443190Seric **	Addresses are stored internally in this structure.
45*4987Seric **
46*4987Seric **	Each address is on two chains and in one tree.
47*4987Seric **		The q_next chain is used to link together addresses
48*4987Seric **		  for one mailer (and is rooted in a mailer).
49*4987Seric **		The q_chain chain is used to maintain a list of
50*4987Seric **		  addresses originating from one call to sendto, and
51*4987Seric **		  is used primarily for printing messages.
52*4987Seric **		The q_alias, q_sibling, and q_child tree maintains
53*4987Seric **		  a complete tree of the aliases.  q_alias points to
54*4987Seric **		  the parent -- obviously, there can be several, and
55*4987Seric **		  so this points to "one" of them.  Ditto for q_sibling.
563190Seric */
573190Seric 
583190Seric struct address
593190Seric {
603190Seric 	char		*q_paddr;	/* the printname for the address */
613190Seric 	char		*q_user;	/* user name */
623190Seric 	char		*q_host;	/* host name */
634597Seric 	struct mailer	*q_mailer;	/* mailer to use */
643190Seric 	short		q_rmailer;	/* real mailer (before mapping) */
654149Seric 	u_short		q_flags;	/* status flags, see below */
664213Seric 	short		q_uid;		/* user-id of receiver (if known) */
674398Seric 	short		q_gid;		/* group-id of receiver (if known) */
684079Seric 	char		*q_home;	/* home dir (local mailer only) */
69*4987Seric 	char		*q_fullname;	/* full name of this person */
70*4987Seric 	time_t		q_timeout;	/* timeout for this address */
713190Seric 	struct address	*q_next;	/* chain */
72*4987Seric 	struct address	*q_alias;	/* parent in alias tree */
73*4987Seric 	struct address	*q_sibling;	/* sibling in alias tree */
74*4987Seric 	struct address	*q_child;	/* child in alias tree */
753190Seric };
763190Seric 
773190Seric typedef struct address ADDRESS;
783190Seric 
793190Seric # define QDONTSEND	000001	/* don't send to this address */
804068Seric # define QBADADDR	000002	/* this address is verified bad */
814403Seric # define QGOODUID	000004	/* the q_uid q_gid fields are good */
824422Seric # define QPRIMARY	000010	/* set from argv */
834624Seric # define QQUEUEUP	000020	/* queue for later transmission */
84*4987Seric # define QPSEUDO	000040	/* only on the list for verification */
853190Seric 
863190Seric 
873190Seric 
883190Seric 
893190Seric 
903190Seric /*
91295Seric **  Mailer definition structure.
92295Seric **	Every mailer known to the system is declared in this
93295Seric **	structure.  It defines the pathname of the mailer, some
94295Seric **	flags associated with it, and the argument vector to
951390Seric **	pass to it.  The flags are defined in conf.c
96295Seric **
972899Seric **	The host map is a list of lists of strings.  Within each
982899Seric **	list, any host is mapped to the last host in the list.
992899Seric **	This allows multiple names, as well as doing clever
1002899Seric **	mail grouping in point-to-point networks.  Note: this
1012899Seric **	is only used internally, so the apparent host is still
1022899Seric **	kept around.
1032899Seric **
1044171Seric **	The argument vector is expanded before actual use.  All
1054171Seric **	words except the first are passed through the macro
1064171Seric **	processor.
107295Seric */
108295Seric 
109295Seric struct mailer
110295Seric {
1113190Seric 	char	*m_name;	/* symbolic name of this mailer */
112295Seric 	char	*m_mailer;	/* pathname of the mailer to use */
1134149Seric 	u_long	m_flags;	/* status flags, see below */
114295Seric 	short	m_badstat;	/* the status code to use on unknown error */
1154438Seric 	short	m_mno;		/* mailer number internally */
1162899Seric 	char	*m_from;	/* pattern for From: header */
1173049Seric 	char	**m_argv;	/* template argument vector */
1183190Seric 	ADDRESS	*m_sendq;	/* list of addresses to send to */
119295Seric };
120295Seric 
1214100Seric typedef struct mailer	MAILER;
1224100Seric 
1232899Seric # define M_FOPT		000001	/* mailer takes picky -f flag */
1242899Seric # define M_ROPT		000002	/* mailer takes picky -r flag */
1252899Seric # define M_QUIET	000004	/* don't print error on bad status */
1262899Seric # define M_RESTR	000010	/* must be daemon to execute */
1273190Seric # define M_NHDR		000020	/* don't insert From line */
1284192Seric # define M_LOCAL	000040	/* delivery is to this host */
1292899Seric # define M_STRIPQ	000100	/* strip quote characters from user/host */
1303190Seric # define M_MUSER	000200	/* mailer can handle multiple users at once */
1312899Seric # define M_NEEDFROM	000400	/* need arpa-style From: line */
1322899Seric # define M_NEEDDATE	001000	/* need arpa-style Date: line */
1332899Seric # define M_MSGID	002000	/* need Message-Id: field */
1343153Seric # define M_USR_UPPER	010000	/* preserve user case distinction */
1353153Seric # define M_HST_UPPER	020000	/* preserve host case distinction */
1363390Seric # define M_FULLNAME	040000	/* want Full-Name field */
137295Seric 
1384317Seric # define M_ARPAFMT	(M_NEEDDATE|M_NEEDFROM|M_MSGID)
1392899Seric 
1404597Seric EXTERN MAILER	*Mailer[MAXMAILERS+1];
141295Seric 
1424597Seric EXTERN MAILER	*LocalMailer;		/* ptr to local mailer */
1434597Seric EXTERN MAILER	*ProgMailer;		/* ptr to program mailer */
144295Seric 
145295Seric 
1462899Seric /*
1472899Seric **  Header structure.
1482899Seric **	This structure is used internally to store header items.
1492899Seric */
150295Seric 
1512899Seric struct header
1522899Seric {
1532899Seric 	char		*h_field;	/* the name of the field */
1542899Seric 	char		*h_value;	/* the value of that field */
1552899Seric 	struct header	*h_link;	/* the next header */
1564149Seric 	u_short		h_flags;	/* status bits, see below */
1574149Seric 	u_long		h_mflags;	/* m_flags bits needed */
1582899Seric };
159295Seric 
1602899Seric typedef struct header	HDR;
1612899Seric 
1624371Seric EXTERN HDR	*Header;	/* head of header list */
1632899Seric 
164295Seric /*
1652899Seric **  Header information structure.
1662899Seric **	Defined in conf.c, this struct declares the header fields
1672899Seric **	that have some magic meaning.
1682899Seric */
1692899Seric 
1702899Seric struct hdrinfo
1712899Seric {
1722899Seric 	char	*hi_field;	/* the name of the field */
1734149Seric 	u_short	hi_flags;	/* status bits, see below */
1744149Seric 	u_short	hi_mflags;	/* m_flags needed for this field */
1752899Seric };
1762899Seric 
1772899Seric extern struct hdrinfo	HdrInfo[];
1782899Seric 
1792899Seric /* bits for h_flags and hi_flags */
1803060Seric # define H_EOH		00001	/* this field terminates header */
1812899Seric # define H_DEFAULT	00004	/* if another value is found, drop this */
1822899Seric # define H_USED		00010	/* indicates that this has been output */
1833386Seric # define H_CHECK	00020	/* check h_mflags against m_flags */
1843390Seric # define H_ACHECK	00040	/* ditto, but always (not just default) */
1854149Seric # define H_FORCE	00100	/* force this field, even if default */
1864222Seric # define H_ADDR		00200	/* this field contains addresses */
1872899Seric 
1882899Seric 
1894624Seric 
1903153Seric /*
1914624Seric **  Work queue.
1924624Seric */
1934624Seric 
1944624Seric struct work
1954624Seric {
1964624Seric 	char		*w_name;	/* name of control file */
1974624Seric 	short		w_pri;		/* priority of message, see below */
1984624Seric 	long		w_size;		/* length of data file */
1994624Seric 	struct work	*w_next;	/* next in queue */
2004624Seric };
2014624Seric 
2024624Seric typedef struct work	WORK;
2034624Seric 
2044624Seric EXTERN WORK	*WorkQ;			/* queue of things to be done */
2054624Seric 
2064624Seric 
2074624Seric /*
2084624Seric **  Message priorities.
2094633Seric **	Priorities > 0 should be preemptive.
2104624Seric */
2114624Seric 
2124633Seric # define PRI_ALERT	20
2134633Seric # define PRI_QUICK	10
2144633Seric # define PRI_FIRSTCL	0
2154633Seric # define PRI_NORMAL	-4
2164633Seric # define PRI_SECONDCL	-10
2174633Seric # define PRI_THIRDCL	-20
2184624Seric 
2194624Seric EXTERN int	MsgPriority;		/* priority of this message */
2204624Seric 
2214624Seric 
2224624Seric 
2234624Seric /*
2243153Seric **  Rewrite rules.
2253153Seric */
2262899Seric 
2273153Seric struct rewrite
2283153Seric {
2293153Seric 	char	**r_lhs;	/* pattern match */
2303153Seric 	char	**r_rhs;	/* substitution value */
2313153Seric 	struct rewrite	*r_next;/* next in chain */
2323153Seric };
2332899Seric 
2344090Seric extern struct rewrite	*RewriteRules[];
2353153Seric 
2364060Seric # define MATCHANY	'\020'	/* match one or more tokens */
2374060Seric # define MATCHONE	'\021'	/* match exactly one token */
2384060Seric # define MATCHCLASS	'\022'	/* match one token in a class */
2394467Seric # define MATCHREPL	'\023'	/* replacement on RHS for above */
2403153Seric 
2413153Seric # define CANONNET	'\025'	/* canonical net, next token */
2423153Seric # define CANONHOST	'\026'	/* canonical host, next token */
2433153Seric # define CANONUSER	'\027'	/* canonical user, next N tokens */
2443153Seric 
2453153Seric 
2463153Seric 
2474056Seric /*
2484056Seric **  Symbol table definitions
2494056Seric */
2503153Seric 
2514056Seric struct symtab
2524056Seric {
2534056Seric 	char		*s_name;	/* name to be entered */
2544100Seric 	char		s_type;		/* general type (see below) */
2554056Seric 	struct symtab	*s_next;	/* pointer to next in chain */
2564100Seric 	union
2574100Seric 	{
2584100Seric 		long	sv_class;	/* bit-map of word classes */
2594100Seric 		ADDRESS	*sv_addr;	/* pointer to address header */
2604100Seric 		MAILER	*sv_mailer;	/* pointer to mailer */
2614100Seric 		char	*sv_alias;	/* alias */
2624100Seric 	}	s_value;
2634056Seric };
2644056Seric 
2654056Seric typedef struct symtab	STAB;
2664056Seric 
2674100Seric /* symbol types */
2684100Seric # define ST_UNDEF	0	/* undefined type */
2694100Seric # define ST_CLASS	1	/* class map */
2704100Seric # define ST_ADDRESS	2	/* an address in parsed format */
2714100Seric # define ST_MAILER	3	/* a mailer header */
2724100Seric # define ST_ALIAS	4	/* an alias */
2734100Seric 
2744100Seric # define s_class	s_value.sv_class
2754100Seric # define s_addr		s_value.sv_addr
2764100Seric # define s_mailer	s_value.sv_mailer
2774100Seric # define s_alias	s_value.sv_alias
2784100Seric 
2794056Seric extern STAB	*stab();
2804056Seric 
2814056Seric /* opcodes to stab */
2824056Seric # define ST_FIND	0	/* find entry */
2834056Seric # define ST_ENTER	1	/* enter if not there */
2844056Seric 
2854056Seric 
2864056Seric 
2874056Seric 
2882899Seric /*
2894284Seric **  Statistics structure.
2904284Seric */
2914284Seric 
2924284Seric struct statistics
2934284Seric {
2944284Seric 	time_t	stat_itime;		/* file initialization time */
2954284Seric 	short	stat_size;		/* size of this structure */
2964284Seric 	long	stat_nf[MAXMAILERS];	/* # msgs from each mailer */
2974284Seric 	long	stat_bf[MAXMAILERS];	/* kbytes from each mailer */
2984284Seric 	long	stat_nt[MAXMAILERS];	/* # msgs to each mailer */
2994284Seric 	long	stat_bt[MAXMAILERS];	/* kbytes to each mailer */
3004284Seric };
3014284Seric 
3024371Seric EXTERN struct statistics	Stat;
3034284Seric extern long			kbytes();	/* for _bf, _bt */
3044284Seric 
3054284Seric 
3064284Seric 
3074284Seric 
3084284Seric /*
309295Seric **  Global variables.
310295Seric */
311295Seric 
3124371Seric EXTERN bool	FromFlag;	/* if set, "From" person is explicit */
3134371Seric EXTERN bool	MailBack;	/* mail back response on error */
3144371Seric EXTERN bool	BerkNet;	/* called from BerkNet */
3154371Seric EXTERN bool	WriteBack;	/* write back response on error */
3164371Seric EXTERN bool	NoAlias;	/* if set, don't do any aliasing */
3174371Seric EXTERN bool	ForceMail;	/* if set, mail even if already got a copy */
3184371Seric EXTERN bool	MeToo;		/* send to the sender also */
3194371Seric EXTERN bool	IgnrDot;	/* don't let dot end messages */
3204371Seric EXTERN bool	SaveFrom;	/* save leading "From" lines */
3214371Seric EXTERN bool	Verbose;	/* set if blow-by-blow desired */
3224371Seric EXTERN bool	GrabTo;		/* if set, get recipients from msg */
3234371Seric EXTERN bool	DontSend;	/* mark recipients as QDONTSEND */
3244371Seric EXTERN bool	NoReturn;	/* don't return letter to sender */
3254537Seric EXTERN bool	Daemon;		/* running as a daemon */
3264553Seric EXTERN bool	Smtp;		/* using SMTP over connection */
3274553Seric EXTERN bool	SuprErrs;	/* set if we are suppressing errors */
3284624Seric EXTERN bool	QueueUp;	/* queue this message for future xmission */
3294624Seric EXTERN bool	QueueRun;	/* currently running something from the queue */
3304711Seric EXTERN bool	HoldErrs;	/* only output errors to transcript */
3314711Seric EXTERN bool	ArpaMode;	/* set if running arpanet protocol */
3324624Seric extern time_t	TimeOut;	/* time until timeout */
3334553Seric EXTERN FILE	*InChannel;	/* input connection */
3344553Seric EXTERN FILE	*OutChannel;	/* output connection */
3354553Seric EXTERN FILE	*TempFile;	/* mail temp file */
3364711Seric EXTERN FILE	*Xscript;	/* mail transcript file */
3374537Seric EXTERN int	RealUid;	/* when Daemon, real uid of caller */
3384537Seric EXTERN int	RealGid;	/* when Daemon, real gid of caller */
3394371Seric EXTERN int	OldUmask;	/* umask when sendmail starts up */
3404371Seric EXTERN int	Debug;		/* debugging level */
3414371Seric EXTERN int	Errors;		/* set if errors */
3424371Seric EXTERN int	ExitStat;	/* exit status code */
3434553Seric EXTERN int	HopCount;	/* hop count */
3444553Seric EXTERN int	AliasLevel;	/* depth of aliasing */
3454624Seric EXTERN time_t	QueueIntvl;	/* intervals between running the queue */
3464553Seric EXTERN char	*OrigFrom;	/* the From: line read from the message */
3474553Seric EXTERN char	*To;		/* the target person */
3484553Seric EXTERN char	*HostName;	/* name of this host for SMTP messages */
3494624Seric EXTERN char	*InFileName;	/* input file name */
3504624Seric EXTERN char	*Transcript;	/* the transcript file name */
3514624Seric extern char	*XcriptFile;	/* template for Transcript */
3524624Seric extern char	*AliasFile;	/* location of alias file */
3534624Seric extern char	*ConfFile;	/* location of configuration file */
3544624Seric extern char	*StatFile;	/* location of statistics summary */
3554624Seric extern char	*QueueDir;	/* location of queue directory */
3564371Seric EXTERN ADDRESS	From;		/* the person it is from */
3574553Seric EXTERN long	MsgSize;	/* size of the message in bytes */
3584624Seric EXTERN time_t	CurTime;	/* time of this message */
359295Seric 
360295Seric 
361295Seric # include	<sysexits.h>
362295Seric 
363295Seric # define setstat(s)		{ if (ExitStat == EX_OK) ExitStat = s; }
3644085Seric 
3654085Seric 
3664085Seric /* useful functions */
3674085Seric 
3684085Seric extern char	*newstr();
3694085Seric extern ADDRESS	*parse();
3704085Seric extern char	*xalloc();
3714085Seric extern char	*expand();
3724085Seric extern bool	sameaddr();
373