1295Seric /*
23313Seric **  SENDMAIL.H -- Global definitions for sendmail.
3295Seric */
4295Seric 
5295Seric 
6295Seric 
74371Seric # ifdef _DEFINE
84371Seric # define EXTERN
9*4624Seric static char SmailSccsId[] =	"@(#)sendmail.h	3.50	10/26/81";
104371Seric # else  _DEFINE
114371Seric # define EXTERN extern
124371Seric # endif _DEFINE
13295Seric 
14*4624Seric # ifndef major
15*4624Seric # include <sys/types.h>
16*4624Seric # 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 
354162Seric /* values for ArpaMode -- these are ordered!! */
364162Seric # define ARPA_NONE	0	/* not in arpanet mode */
374162Seric # define ARPA_OLD	1	/* in old arpanet mode */
384162Seric # define ARPA_MAIL	2	/* in regular arpanet mail */
394162Seric # define ARPA_FILE	3	/* reading over data connection */
404553Seric # define ARPA_SMTP	4	/* running SMTP protocol */
41295Seric 
424167Seric extern char	Arpa_Info[];	/* the message number for Arpanet info */
43295Seric 
44295Seric 
45295Seric 
463190Seric 
474162Seric 
484167Seric 
49295Seric /*
503190Seric **  Address structure.
513190Seric **	Addresses are stored internally in this structure.
523190Seric */
533190Seric 
543190Seric struct address
553190Seric {
563190Seric 	char		*q_paddr;	/* the printname for the address */
573190Seric 	char		*q_user;	/* user name */
583190Seric 	char		*q_host;	/* host name */
594597Seric 	struct mailer	*q_mailer;	/* mailer to use */
603190Seric 	short		q_rmailer;	/* real mailer (before mapping) */
614149Seric 	u_short		q_flags;	/* status flags, see below */
624213Seric 	short		q_uid;		/* user-id of receiver (if known) */
634398Seric 	short		q_gid;		/* group-id of receiver (if known) */
644079Seric 	char		*q_home;	/* home dir (local mailer only) */
653190Seric 	struct address	*q_next;	/* chain */
664398Seric 	struct address	*q_alias;	/* address this results from */
67*4624Seric 	time_t		q_timeout;	/* timeout for this address */
683190Seric };
693190Seric 
703190Seric typedef struct address ADDRESS;
713190Seric 
723190Seric # define QDONTSEND	000001	/* don't send to this address */
734068Seric # define QBADADDR	000002	/* this address is verified bad */
744403Seric # define QGOODUID	000004	/* the q_uid q_gid fields are good */
754422Seric # define QPRIMARY	000010	/* set from argv */
76*4624Seric # define QQUEUEUP	000020	/* queue for later transmission */
773190Seric 
783190Seric 
793190Seric 
803190Seric 
813190Seric 
823190Seric /*
83295Seric **  Mailer definition structure.
84295Seric **	Every mailer known to the system is declared in this
85295Seric **	structure.  It defines the pathname of the mailer, some
86295Seric **	flags associated with it, and the argument vector to
871390Seric **	pass to it.  The flags are defined in conf.c
88295Seric **
892899Seric **	The host map is a list of lists of strings.  Within each
902899Seric **	list, any host is mapped to the last host in the list.
912899Seric **	This allows multiple names, as well as doing clever
922899Seric **	mail grouping in point-to-point networks.  Note: this
932899Seric **	is only used internally, so the apparent host is still
942899Seric **	kept around.
952899Seric **
964171Seric **	The argument vector is expanded before actual use.  All
974171Seric **	words except the first are passed through the macro
984171Seric **	processor.
99295Seric */
100295Seric 
101295Seric struct mailer
102295Seric {
1033190Seric 	char	*m_name;	/* symbolic name of this mailer */
104295Seric 	char	*m_mailer;	/* pathname of the mailer to use */
1054149Seric 	u_long	m_flags;	/* status flags, see below */
106295Seric 	short	m_badstat;	/* the status code to use on unknown error */
1074438Seric 	short	m_mno;		/* mailer number internally */
1082899Seric 	char	*m_from;	/* pattern for From: header */
1093049Seric 	char	**m_argv;	/* template argument vector */
1103190Seric 	ADDRESS	*m_sendq;	/* list of addresses to send to */
111295Seric };
112295Seric 
1134100Seric typedef struct mailer	MAILER;
1144100Seric 
1152899Seric # define M_FOPT		000001	/* mailer takes picky -f flag */
1162899Seric # define M_ROPT		000002	/* mailer takes picky -r flag */
1172899Seric # define M_QUIET	000004	/* don't print error on bad status */
1182899Seric # define M_RESTR	000010	/* must be daemon to execute */
1193190Seric # define M_NHDR		000020	/* don't insert From line */
1204192Seric # define M_LOCAL	000040	/* delivery is to this host */
1212899Seric # define M_STRIPQ	000100	/* strip quote characters from user/host */
1223190Seric # define M_MUSER	000200	/* mailer can handle multiple users at once */
1232899Seric # define M_NEEDFROM	000400	/* need arpa-style From: line */
1242899Seric # define M_NEEDDATE	001000	/* need arpa-style Date: line */
1252899Seric # define M_MSGID	002000	/* need Message-Id: field */
1263153Seric # define M_USR_UPPER	010000	/* preserve user case distinction */
1273153Seric # define M_HST_UPPER	020000	/* preserve host case distinction */
1283390Seric # define M_FULLNAME	040000	/* want Full-Name field */
129295Seric 
1304317Seric # define M_ARPAFMT	(M_NEEDDATE|M_NEEDFROM|M_MSGID)
1312899Seric 
1324597Seric EXTERN MAILER	*Mailer[MAXMAILERS+1];
133295Seric 
1344597Seric EXTERN MAILER	*LocalMailer;		/* ptr to local mailer */
1354597Seric EXTERN MAILER	*ProgMailer;		/* ptr to program mailer */
136295Seric 
137295Seric 
1382899Seric /*
1392899Seric **  Header structure.
1402899Seric **	This structure is used internally to store header items.
1412899Seric */
142295Seric 
1432899Seric struct header
1442899Seric {
1452899Seric 	char		*h_field;	/* the name of the field */
1462899Seric 	char		*h_value;	/* the value of that field */
1472899Seric 	struct header	*h_link;	/* the next header */
1484149Seric 	u_short		h_flags;	/* status bits, see below */
1494149Seric 	u_long		h_mflags;	/* m_flags bits needed */
1502899Seric };
151295Seric 
1522899Seric typedef struct header	HDR;
1532899Seric 
1544371Seric EXTERN HDR	*Header;	/* head of header list */
1552899Seric 
156295Seric /*
1572899Seric **  Header information structure.
1582899Seric **	Defined in conf.c, this struct declares the header fields
1592899Seric **	that have some magic meaning.
1602899Seric */
1612899Seric 
1622899Seric struct hdrinfo
1632899Seric {
1642899Seric 	char	*hi_field;	/* the name of the field */
1654149Seric 	u_short	hi_flags;	/* status bits, see below */
1664149Seric 	u_short	hi_mflags;	/* m_flags needed for this field */
1672899Seric };
1682899Seric 
1692899Seric extern struct hdrinfo	HdrInfo[];
1702899Seric 
1712899Seric /* bits for h_flags and hi_flags */
1723060Seric # define H_EOH		00001	/* this field terminates header */
1732899Seric # define H_DEFAULT	00004	/* if another value is found, drop this */
1742899Seric # define H_USED		00010	/* indicates that this has been output */
1753386Seric # define H_CHECK	00020	/* check h_mflags against m_flags */
1763390Seric # define H_ACHECK	00040	/* ditto, but always (not just default) */
1774149Seric # define H_FORCE	00100	/* force this field, even if default */
1784222Seric # define H_ADDR		00200	/* this field contains addresses */
1792899Seric 
1802899Seric 
181*4624Seric 
1823153Seric /*
183*4624Seric **  Work queue.
184*4624Seric */
185*4624Seric 
186*4624Seric struct work
187*4624Seric {
188*4624Seric 	char		*w_name;	/* name of control file */
189*4624Seric 	short		w_pri;		/* priority of message, see below */
190*4624Seric 	long		w_size;		/* length of data file */
191*4624Seric 	struct work	*w_next;	/* next in queue */
192*4624Seric };
193*4624Seric 
194*4624Seric typedef struct work	WORK;
195*4624Seric 
196*4624Seric EXTERN WORK	*WorkQ;			/* queue of things to be done */
197*4624Seric 
198*4624Seric 
199*4624Seric /*
200*4624Seric **  Message priorities.
201*4624Seric */
202*4624Seric 
203*4624Seric # define PRI_NORMAL	20
204*4624Seric # define PRI_SECONDCL	10
205*4624Seric # define PRI_THIRDCL	7
206*4624Seric # define PRI_QUICK	24
207*4624Seric # define PRI_PRIORITY	40
208*4624Seric 
209*4624Seric EXTERN int	MsgPriority;		/* priority of this message */
210*4624Seric 
211*4624Seric 
212*4624Seric 
213*4624Seric /*
2143153Seric **  Rewrite rules.
2153153Seric */
2162899Seric 
2173153Seric struct rewrite
2183153Seric {
2193153Seric 	char	**r_lhs;	/* pattern match */
2203153Seric 	char	**r_rhs;	/* substitution value */
2213153Seric 	struct rewrite	*r_next;/* next in chain */
2223153Seric };
2232899Seric 
2244090Seric extern struct rewrite	*RewriteRules[];
2253153Seric 
2264060Seric # define MATCHANY	'\020'	/* match one or more tokens */
2274060Seric # define MATCHONE	'\021'	/* match exactly one token */
2284060Seric # define MATCHCLASS	'\022'	/* match one token in a class */
2294467Seric # define MATCHREPL	'\023'	/* replacement on RHS for above */
2303153Seric 
2313153Seric # define CANONNET	'\025'	/* canonical net, next token */
2323153Seric # define CANONHOST	'\026'	/* canonical host, next token */
2333153Seric # define CANONUSER	'\027'	/* canonical user, next N tokens */
2343153Seric 
2353153Seric 
2363153Seric 
2374056Seric /*
2384056Seric **  Symbol table definitions
2394056Seric */
2403153Seric 
2414056Seric struct symtab
2424056Seric {
2434056Seric 	char		*s_name;	/* name to be entered */
2444100Seric 	char		s_type;		/* general type (see below) */
2454056Seric 	struct symtab	*s_next;	/* pointer to next in chain */
2464100Seric 	union
2474100Seric 	{
2484100Seric 		long	sv_class;	/* bit-map of word classes */
2494100Seric 		ADDRESS	*sv_addr;	/* pointer to address header */
2504100Seric 		MAILER	*sv_mailer;	/* pointer to mailer */
2514100Seric 		char	*sv_alias;	/* alias */
2524100Seric 	}	s_value;
2534056Seric };
2544056Seric 
2554056Seric typedef struct symtab	STAB;
2564056Seric 
2574100Seric /* symbol types */
2584100Seric # define ST_UNDEF	0	/* undefined type */
2594100Seric # define ST_CLASS	1	/* class map */
2604100Seric # define ST_ADDRESS	2	/* an address in parsed format */
2614100Seric # define ST_MAILER	3	/* a mailer header */
2624100Seric # define ST_ALIAS	4	/* an alias */
2634100Seric 
2644100Seric # define s_class	s_value.sv_class
2654100Seric # define s_addr		s_value.sv_addr
2664100Seric # define s_mailer	s_value.sv_mailer
2674100Seric # define s_alias	s_value.sv_alias
2684100Seric 
2694056Seric extern STAB	*stab();
2704056Seric 
2714056Seric /* opcodes to stab */
2724056Seric # define ST_FIND	0	/* find entry */
2734056Seric # define ST_ENTER	1	/* enter if not there */
2744056Seric 
2754056Seric 
2764056Seric 
2774056Seric 
2782899Seric /*
2794284Seric **  Statistics structure.
2804284Seric */
2814284Seric 
2824284Seric struct statistics
2834284Seric {
2844284Seric 	time_t	stat_itime;		/* file initialization time */
2854284Seric 	short	stat_size;		/* size of this structure */
2864284Seric 	long	stat_nf[MAXMAILERS];	/* # msgs from each mailer */
2874284Seric 	long	stat_bf[MAXMAILERS];	/* kbytes from each mailer */
2884284Seric 	long	stat_nt[MAXMAILERS];	/* # msgs to each mailer */
2894284Seric 	long	stat_bt[MAXMAILERS];	/* kbytes to each mailer */
2904284Seric };
2914284Seric 
2924371Seric EXTERN struct statistics	Stat;
2934284Seric extern long			kbytes();	/* for _bf, _bt */
2944284Seric 
2954284Seric 
2964284Seric 
2974284Seric 
2984284Seric /*
299295Seric **  Global variables.
300295Seric */
301295Seric 
3024371Seric EXTERN bool	FromFlag;	/* if set, "From" person is explicit */
3034371Seric EXTERN bool	MailBack;	/* mail back response on error */
3044371Seric EXTERN bool	BerkNet;	/* called from BerkNet */
3054371Seric EXTERN bool	WriteBack;	/* write back response on error */
3064371Seric EXTERN bool	NoAlias;	/* if set, don't do any aliasing */
3074371Seric EXTERN bool	ForceMail;	/* if set, mail even if already got a copy */
3084371Seric EXTERN bool	MeToo;		/* send to the sender also */
3094371Seric EXTERN bool	IgnrDot;	/* don't let dot end messages */
3104371Seric EXTERN bool	SaveFrom;	/* save leading "From" lines */
3114371Seric EXTERN bool	Verbose;	/* set if blow-by-blow desired */
3124371Seric EXTERN bool	GrabTo;		/* if set, get recipients from msg */
3134371Seric EXTERN bool	DontSend;	/* mark recipients as QDONTSEND */
3144371Seric EXTERN bool	NoReturn;	/* don't return letter to sender */
3154537Seric EXTERN bool	Daemon;		/* running as a daemon */
3164553Seric EXTERN bool	Smtp;		/* using SMTP over connection */
3174553Seric EXTERN bool	SuprErrs;	/* set if we are suppressing errors */
318*4624Seric EXTERN bool	QueueUp;	/* queue this message for future xmission */
319*4624Seric EXTERN bool	QueueRun;	/* currently running something from the queue */
320*4624Seric extern time_t	TimeOut;	/* time until timeout */
3214553Seric EXTERN FILE	*InChannel;	/* input connection */
3224553Seric EXTERN FILE	*OutChannel;	/* output connection */
3234553Seric EXTERN FILE	*TempFile;	/* mail temp file */
3244537Seric EXTERN int	RealUid;	/* when Daemon, real uid of caller */
3254537Seric EXTERN int	RealGid;	/* when Daemon, real gid of caller */
3264371Seric EXTERN int	OldUmask;	/* umask when sendmail starts up */
3274371Seric EXTERN int	Debug;		/* debugging level */
3284371Seric EXTERN int	Errors;		/* set if errors */
3294371Seric EXTERN int	ExitStat;	/* exit status code */
3304371Seric EXTERN int	ArpaMode;	/* ARPANET handling mode */
3314553Seric EXTERN int	HopCount;	/* hop count */
3324553Seric EXTERN int	AliasLevel;	/* depth of aliasing */
333*4624Seric EXTERN time_t	QueueIntvl;	/* intervals between running the queue */
3344553Seric EXTERN char	*OrigFrom;	/* the From: line read from the message */
3354553Seric EXTERN char	*To;		/* the target person */
3364553Seric EXTERN char	*HostName;	/* name of this host for SMTP messages */
337*4624Seric EXTERN char	*InFileName;	/* input file name */
338*4624Seric EXTERN char	*Transcript;	/* the transcript file name */
339*4624Seric extern char	*XcriptFile;	/* template for Transcript */
340*4624Seric extern char	*AliasFile;	/* location of alias file */
341*4624Seric extern char	*ConfFile;	/* location of configuration file */
342*4624Seric extern char	*StatFile;	/* location of statistics summary */
343*4624Seric extern char	*QueueDir;	/* location of queue directory */
3444371Seric EXTERN ADDRESS	From;		/* the person it is from */
3454553Seric EXTERN long	MsgSize;	/* size of the message in bytes */
346*4624Seric EXTERN time_t	CurTime;	/* time of this message */
347295Seric 
348295Seric 
349295Seric # include	<sysexits.h>
350295Seric 
351295Seric # define setstat(s)		{ if (ExitStat == EX_OK) ExitStat = s; }
3524085Seric 
3534085Seric 
3544085Seric /* useful functions */
3554085Seric 
3564085Seric extern char	*newstr();
3574085Seric extern ADDRESS	*parse();
3584085Seric extern char	*xalloc();
3594085Seric extern char	*expand();
3604085Seric extern bool	sameaddr();
361