1295Seric /*
23313Seric **  SENDMAIL.H -- Global definitions for sendmail.
3295Seric */
4295Seric 
5295Seric 
6295Seric 
74371Seric # ifdef _DEFINE
84371Seric # define EXTERN
9*4537Seric static char SmailSccsId[] =	"@(#)sendmail.h	3.47	10/17/81";
104371Seric # else  _DEFINE
114371Seric # define EXTERN extern
124371Seric # endif _DEFINE
13295Seric 
144183Seric # include <stdio.h>
154183Seric # include <ctype.h>
161390Seric # include "useful.h"
171390Seric 
18295Seric /*
194284Seric **  Configuration constants.
204284Seric **	There shouldn't be much need to change these....
21295Seric */
22295Seric 
234374Seric # define MAXLINE	256		/* max line length */
244374Seric # define MAXNAME	128		/* max length of a name */
254374Seric # define MAXFIELD	2500		/* max total length of a hdr field */
264374Seric # define MAXPV		40		/* max # of parms to mailers */
274374Seric # define MAXHOP		30		/* max value of HopCount */
284384Seric # define MAXATOM	30		/* max atoms per address */
294374Seric # define MAXMAILERS	10		/* maximum mailers known to system */
304374Seric # define SPACESUB	('.'|0200)	/* substitution for <lwsp> */
31295Seric 
324162Seric /* values for ArpaMode -- these are ordered!! */
334162Seric # define ARPA_NONE	0	/* not in arpanet mode */
344162Seric # define ARPA_OLD	1	/* in old arpanet mode */
354162Seric # define ARPA_MAIL	2	/* in regular arpanet mail */
364162Seric # define ARPA_FILE	3	/* reading over data connection */
37295Seric 
384167Seric extern char	Arpa_Info[];	/* the message number for Arpanet info */
39295Seric 
40295Seric 
41295Seric 
423190Seric 
434162Seric 
444167Seric 
45295Seric /*
463190Seric **  Address structure.
473190Seric **	Addresses are stored internally in this structure.
483190Seric */
493190Seric 
503190Seric struct address
513190Seric {
523190Seric 	char		*q_paddr;	/* the printname for the address */
533190Seric 	char		*q_user;	/* user name */
543190Seric 	char		*q_host;	/* host name */
553190Seric 	short		q_mailer;	/* mailer to use */
563190Seric 	short		q_rmailer;	/* real mailer (before mapping) */
574149Seric 	u_short		q_flags;	/* status flags, see below */
584213Seric 	short		q_uid;		/* user-id of receiver (if known) */
594398Seric 	short		q_gid;		/* group-id of receiver (if known) */
604079Seric 	char		*q_home;	/* home dir (local mailer only) */
613190Seric 	struct address	*q_next;	/* chain */
624398Seric 	struct address	*q_alias;	/* address this results from */
633190Seric };
643190Seric 
653190Seric typedef struct address ADDRESS;
663190Seric 
673190Seric # define QDONTSEND	000001	/* don't send to this address */
684068Seric # define QBADADDR	000002	/* this address is verified bad */
694403Seric # define QGOODUID	000004	/* the q_uid q_gid fields are good */
704422Seric # define QPRIMARY	000010	/* set from argv */
713190Seric 
723190Seric 
733190Seric 
743190Seric 
753190Seric 
763190Seric /*
77295Seric **  Mailer definition structure.
78295Seric **	Every mailer known to the system is declared in this
79295Seric **	structure.  It defines the pathname of the mailer, some
80295Seric **	flags associated with it, and the argument vector to
811390Seric **	pass to it.  The flags are defined in conf.c
82295Seric **
832899Seric **	The host map is a list of lists of strings.  Within each
842899Seric **	list, any host is mapped to the last host in the list.
852899Seric **	This allows multiple names, as well as doing clever
862899Seric **	mail grouping in point-to-point networks.  Note: this
872899Seric **	is only used internally, so the apparent host is still
882899Seric **	kept around.
892899Seric **
904171Seric **	The argument vector is expanded before actual use.  All
914171Seric **	words except the first are passed through the macro
924171Seric **	processor.
93295Seric */
94295Seric 
95295Seric struct mailer
96295Seric {
973190Seric 	char	*m_name;	/* symbolic name of this mailer */
98295Seric 	char	*m_mailer;	/* pathname of the mailer to use */
994149Seric 	u_long	m_flags;	/* status flags, see below */
100295Seric 	short	m_badstat;	/* the status code to use on unknown error */
1014438Seric 	short	m_mno;		/* mailer number internally */
1022899Seric 	char	*m_from;	/* pattern for From: header */
1033049Seric 	char	**m_argv;	/* template argument vector */
1043190Seric 	ADDRESS	*m_sendq;	/* list of addresses to send to */
105295Seric };
106295Seric 
1074100Seric typedef struct mailer	MAILER;
1084100Seric 
1092899Seric # define M_FOPT		000001	/* mailer takes picky -f flag */
1102899Seric # define M_ROPT		000002	/* mailer takes picky -r flag */
1112899Seric # define M_QUIET	000004	/* don't print error on bad status */
1122899Seric # define M_RESTR	000010	/* must be daemon to execute */
1133190Seric # define M_NHDR		000020	/* don't insert From line */
1144192Seric # define M_LOCAL	000040	/* delivery is to this host */
1152899Seric # define M_STRIPQ	000100	/* strip quote characters from user/host */
1163190Seric # define M_MUSER	000200	/* mailer can handle multiple users at once */
1172899Seric # define M_NEEDFROM	000400	/* need arpa-style From: line */
1182899Seric # define M_NEEDDATE	001000	/* need arpa-style Date: line */
1192899Seric # define M_MSGID	002000	/* need Message-Id: field */
1203153Seric # define M_USR_UPPER	010000	/* preserve user case distinction */
1213153Seric # define M_HST_UPPER	020000	/* preserve host case distinction */
1223390Seric # define M_FULLNAME	040000	/* want Full-Name field */
123295Seric 
1244317Seric # define M_ARPAFMT	(M_NEEDDATE|M_NEEDFROM|M_MSGID)
1252899Seric 
1264371Seric EXTERN MAILER *Mailer[MAXMAILERS+1];
127295Seric 
1284079Seric /* special mailer numbers */
1294192Seric # define MN_LOCAL	0	/* local mailer */
1304192Seric # define MN_PROG	1	/* program mailer */
1314100Seric /* mailers from 2 on are arbitrary */
132295Seric 
133295Seric 
1344079Seric 
1352899Seric /*
1362899Seric **  Header structure.
1372899Seric **	This structure is used internally to store header items.
1382899Seric */
139295Seric 
1402899Seric struct header
1412899Seric {
1422899Seric 	char		*h_field;	/* the name of the field */
1432899Seric 	char		*h_value;	/* the value of that field */
1442899Seric 	struct header	*h_link;	/* the next header */
1454149Seric 	u_short		h_flags;	/* status bits, see below */
1464149Seric 	u_long		h_mflags;	/* m_flags bits needed */
1472899Seric };
148295Seric 
1492899Seric typedef struct header	HDR;
1502899Seric 
1514371Seric EXTERN HDR	*Header;	/* head of header list */
1522899Seric 
153295Seric /*
1542899Seric **  Header information structure.
1552899Seric **	Defined in conf.c, this struct declares the header fields
1562899Seric **	that have some magic meaning.
1572899Seric */
1582899Seric 
1592899Seric struct hdrinfo
1602899Seric {
1612899Seric 	char	*hi_field;	/* the name of the field */
1624149Seric 	u_short	hi_flags;	/* status bits, see below */
1634149Seric 	u_short	hi_mflags;	/* m_flags needed for this field */
1642899Seric };
1652899Seric 
1662899Seric extern struct hdrinfo	HdrInfo[];
1672899Seric 
1682899Seric /* bits for h_flags and hi_flags */
1693060Seric # define H_EOH		00001	/* this field terminates header */
1702899Seric # define H_DEFAULT	00004	/* if another value is found, drop this */
1712899Seric # define H_USED		00010	/* indicates that this has been output */
1723386Seric # define H_CHECK	00020	/* check h_mflags against m_flags */
1733390Seric # define H_ACHECK	00040	/* ditto, but always (not just default) */
1744149Seric # define H_FORCE	00100	/* force this field, even if default */
1754222Seric # define H_ADDR		00200	/* this field contains addresses */
1762899Seric 
1772899Seric 
1783153Seric /*
1793153Seric **  Rewrite rules.
1803153Seric */
1812899Seric 
1823153Seric struct rewrite
1833153Seric {
1843153Seric 	char	**r_lhs;	/* pattern match */
1853153Seric 	char	**r_rhs;	/* substitution value */
1863153Seric 	struct rewrite	*r_next;/* next in chain */
1873153Seric };
1882899Seric 
1894090Seric extern struct rewrite	*RewriteRules[];
1903153Seric 
1914060Seric # define MATCHANY	'\020'	/* match one or more tokens */
1924060Seric # define MATCHONE	'\021'	/* match exactly one token */
1934060Seric # define MATCHCLASS	'\022'	/* match one token in a class */
1944467Seric # define MATCHREPL	'\023'	/* replacement on RHS for above */
1953153Seric 
1963153Seric # define CANONNET	'\025'	/* canonical net, next token */
1973153Seric # define CANONHOST	'\026'	/* canonical host, next token */
1983153Seric # define CANONUSER	'\027'	/* canonical user, next N tokens */
1993153Seric 
2003153Seric 
2013153Seric 
2024056Seric /*
2034056Seric **  Symbol table definitions
2044056Seric */
2053153Seric 
2064056Seric struct symtab
2074056Seric {
2084056Seric 	char		*s_name;	/* name to be entered */
2094100Seric 	char		s_type;		/* general type (see below) */
2104056Seric 	struct symtab	*s_next;	/* pointer to next in chain */
2114100Seric 	union
2124100Seric 	{
2134100Seric 		long	sv_class;	/* bit-map of word classes */
2144100Seric 		ADDRESS	*sv_addr;	/* pointer to address header */
2154100Seric 		MAILER	*sv_mailer;	/* pointer to mailer */
2164100Seric 		char	*sv_alias;	/* alias */
2174100Seric 	}	s_value;
2184056Seric };
2194056Seric 
2204056Seric typedef struct symtab	STAB;
2214056Seric 
2224100Seric /* symbol types */
2234100Seric # define ST_UNDEF	0	/* undefined type */
2244100Seric # define ST_CLASS	1	/* class map */
2254100Seric # define ST_ADDRESS	2	/* an address in parsed format */
2264100Seric # define ST_MAILER	3	/* a mailer header */
2274100Seric # define ST_ALIAS	4	/* an alias */
2284100Seric 
2294100Seric # define s_class	s_value.sv_class
2304100Seric # define s_addr		s_value.sv_addr
2314100Seric # define s_mailer	s_value.sv_mailer
2324100Seric # define s_alias	s_value.sv_alias
2334100Seric 
2344056Seric extern STAB	*stab();
2354056Seric 
2364056Seric /* opcodes to stab */
2374056Seric # define ST_FIND	0	/* find entry */
2384056Seric # define ST_ENTER	1	/* enter if not there */
2394056Seric 
2404056Seric 
2414056Seric 
2424056Seric 
2432899Seric /*
2444284Seric **  Statistics structure.
2454284Seric */
2464284Seric 
2474284Seric struct statistics
2484284Seric {
2494284Seric 	time_t	stat_itime;		/* file initialization time */
2504284Seric 	short	stat_size;		/* size of this structure */
2514284Seric 	long	stat_nf[MAXMAILERS];	/* # msgs from each mailer */
2524284Seric 	long	stat_bf[MAXMAILERS];	/* kbytes from each mailer */
2534284Seric 	long	stat_nt[MAXMAILERS];	/* # msgs to each mailer */
2544284Seric 	long	stat_bt[MAXMAILERS];	/* kbytes to each mailer */
2554284Seric };
2564284Seric 
2574371Seric EXTERN struct statistics	Stat;
2584284Seric extern long			kbytes();	/* for _bf, _bt */
2594284Seric 
2604284Seric 
2614284Seric 
2624284Seric 
2634284Seric /*
264295Seric **  Global variables.
265295Seric */
266295Seric 
2674371Seric EXTERN bool	FromFlag;	/* if set, "From" person is explicit */
2684371Seric EXTERN bool	MailBack;	/* mail back response on error */
2694371Seric EXTERN bool	BerkNet;	/* called from BerkNet */
2704371Seric EXTERN bool	WriteBack;	/* write back response on error */
2714371Seric EXTERN bool	NoAlias;	/* if set, don't do any aliasing */
2724371Seric EXTERN bool	ForceMail;	/* if set, mail even if already got a copy */
2734371Seric EXTERN bool	MeToo;		/* send to the sender also */
2744371Seric EXTERN bool	IgnrDot;	/* don't let dot end messages */
2754371Seric EXTERN bool	SaveFrom;	/* save leading "From" lines */
2764371Seric EXTERN bool	Verbose;	/* set if blow-by-blow desired */
2774371Seric EXTERN bool	GrabTo;		/* if set, get recipients from msg */
2784371Seric EXTERN bool	DontSend;	/* mark recipients as QDONTSEND */
2794371Seric EXTERN bool	NoReturn;	/* don't return letter to sender */
280*4537Seric EXTERN bool	Daemon;		/* running as a daemon */
281*4537Seric EXTERN int	RealUid;	/* when Daemon, real uid of caller */
282*4537Seric EXTERN int	RealGid;	/* when Daemon, real gid of caller */
2834371Seric EXTERN int	OldUmask;	/* umask when sendmail starts up */
2844371Seric EXTERN int	Debug;		/* debugging level */
2854371Seric EXTERN int	Errors;		/* set if errors */
2864371Seric EXTERN int	ExitStat;	/* exit status code */
2874371Seric EXTERN int	ArpaMode;	/* ARPANET handling mode */
2884371Seric EXTERN long	MsgSize;	/* size of the message in bytes */
289295Seric extern char	InFileName[];	/* input file name */
290295Seric extern char	Transcript[];	/* the transcript file name */
2914371Seric EXTERN FILE	*TempFile;	/* mail temp file */
2924371Seric EXTERN ADDRESS	From;		/* the person it is from */
2934371Seric EXTERN char	*To;		/* the target person */
2944371Seric EXTERN int	HopCount;	/* hop count */
2954371Seric EXTERN long	CurTime;	/* time of this message */
2964371Seric EXTERN int	AliasLevel;	/* depth of aliasing */
2974371Seric EXTERN char	*OrigFrom;	/* the From: line read from the message */
2984371Seric EXTERN bool	SuprErrs;	/* set if we are suppressing errors */
2994371Seric EXTERN bool	HasXscrpt;	/* set if we have a transcript */
300295Seric 
301295Seric 
302295Seric # include	<sysexits.h>
303295Seric 
304295Seric # define setstat(s)		{ if (ExitStat == EX_OK) ExitStat = s; }
3054085Seric 
3064085Seric 
3074085Seric /* useful functions */
3084085Seric 
3094085Seric extern char	*newstr();
3104085Seric extern ADDRESS	*parse();
3114085Seric extern char	*xalloc();
3124085Seric extern char	*expand();
3134085Seric extern bool	sameaddr();
314