1 /*
2 **  SENDMAIL.H -- Global definitions for sendmail.
3 */
4 
5 
6 
7 # ifdef _DEFINE
8 # define EXTERN
9 # ifndef lint
10 static char SmailSccsId[] =	"@(#)sendmail.h	3.90		09/26/82";
11 # endif lint
12 # else  _DEFINE
13 # define EXTERN extern
14 # endif _DEFINE
15 
16 # include <stdio.h>
17 # include <ctype.h>
18 # include <setjmp.h>
19 # include "useful.h"
20 
21 # ifdef LOG
22 # include <syslog.h>
23 # endif LOG
24 /*
25 **  Configuration constants.
26 **	There shouldn't be much need to change these....
27 */
28 
29 # define MAXLINE	256		/* max line length */
30 # define MAXNAME	128		/* max length of a name */
31 # define MAXFIELD	2500		/* max total length of a hdr field */
32 # define MAXPV		40		/* max # of parms to mailers */
33 # define MAXHOP		30		/* max value of HopCount */
34 # define MAXATOM	100		/* max atoms per address */
35 # define MAXMAILERS	25		/* maximum mailers known to system */
36 # define MAXRWSETS	30		/* max # of sets of rewriting rules */
37 # define MAXPRIORITIES	25		/* max values for Precedence: field */
38 # define SPACESUB	('.'|0200)	/* substitution for <lwsp> */
39 /*
40 **  Address structure.
41 **	Addresses are stored internally in this structure.
42 */
43 
44 struct address
45 {
46 	char		*q_paddr;	/* the printname for the address */
47 	char		*q_user;	/* user name */
48 	char		*q_host;	/* host name */
49 	struct mailer	*q_mailer;	/* mailer to use */
50 	u_short		q_flags;	/* status flags, see below */
51 	short		q_uid;		/* user-id of receiver (if known) */
52 	short		q_gid;		/* group-id of receiver (if known) */
53 	char		*q_home;	/* home dir (local mailer only) */
54 	char		*q_fullname;	/* full name if known */
55 	struct address	*q_next;	/* chain */
56 	struct address	*q_alias;	/* address this results from */
57 	struct address	*q_tchain;	/* temporary use chain */
58 	time_t		q_timeout;	/* timeout for this address */
59 };
60 
61 typedef struct address ADDRESS;
62 
63 # define QDONTSEND	000001	/* don't send to this address */
64 # define QBADADDR	000002	/* this address is verified bad */
65 # define QGOODUID	000004	/* the q_uid q_gid fields are good */
66 # define QPRIMARY	000010	/* set from argv */
67 # define QQUEUEUP	000020	/* queue for later transmission */
68 /*
69 **  Mailer definition structure.
70 **	Every mailer known to the system is declared in this
71 **	structure.  It defines the pathname of the mailer, some
72 **	flags associated with it, and the argument vector to
73 **	pass to it.  The flags are defined in conf.c
74 **
75 **	The argument vector is expanded before actual use.  All
76 **	words except the first are passed through the macro
77 **	processor.
78 */
79 
80 struct mailer
81 {
82 	char	*m_name;	/* symbolic name of this mailer */
83 	char	*m_mailer;	/* pathname of the mailer to use */
84 	u_long	m_flags;	/* status flags, see below */
85 	short	m_badstat;	/* the status code to use on unknown error */
86 	short	m_mno;		/* mailer number internally */
87 	char	**m_argv;	/* template argument vector */
88 	short	m_s_rwset;	/* rewriting set for sender addresses */
89 	short	m_r_rwset;	/* rewriting set for recipient addresses */
90 };
91 
92 typedef struct mailer	MAILER;
93 
94 /* bits for m_flags */
95 # define M_FOPT		000000001L	/* mailer takes picky -f flag */
96 # define M_ROPT		000000002L	/* mailer takes picky -r flag */
97 # define M_QUIET	000000004L	/* don't print error on bad status */
98 # define M_RESTR	000000010L	/* must be daemon to execute */
99 # define M_NHDR		000000020L	/* don't insert From line */
100 # define M_LOCAL	000000040L	/* delivery is to this host */
101 # define M_STRIPQ	000000100L	/* strip quote chars from user/host */
102 # define M_MUSER	000000200L	/* can handle multiple users at once */
103 # define M_NEEDFROM	000000400L	/* need arpa-style From: line */
104 # define M_NEEDDATE	000001000L	/* need arpa-style Date: line */
105 # define M_MSGID	000002000L	/* need Message-Id: field */
106 # define M_CANONICAL	000004000L	/* make addresses canonical "u@dom" */
107 # define M_USR_UPPER	000010000L	/* preserve user case distinction */
108 # define M_HST_UPPER	000020000L	/* preserve host case distinction */
109 # define M_FULLNAME	000040000L	/* want Full-Name field */
110 # define M_UGLYUUCP	000100000L	/* this wants an ugly UUCP from line */
111 # define M_EXPENSIVE	000200000L	/* it costs to use this mailer.... */
112 # define M_FULLSMTP	000400000L	/* must run full SMTP, inc. limits */
113 
114 # define M_ARPAFMT	(M_NEEDDATE|M_NEEDFROM|M_MSGID)
115 
116 EXTERN MAILER	*Mailer[MAXMAILERS+1];
117 
118 EXTERN MAILER	*LocalMailer;		/* ptr to local mailer */
119 EXTERN MAILER	*ProgMailer;		/* ptr to program mailer */
120 /*
121 **  Header structure.
122 **	This structure is used internally to store header items.
123 */
124 
125 struct header
126 {
127 	char		*h_field;	/* the name of the field */
128 	char		*h_value;	/* the value of that field */
129 	struct header	*h_link;	/* the next header */
130 	u_short		h_flags;	/* status bits, see below */
131 	u_long		h_mflags;	/* m_flags bits needed */
132 };
133 
134 typedef struct header	HDR;
135 
136 /*
137 **  Header information structure.
138 **	Defined in conf.c, this struct declares the header fields
139 **	that have some magic meaning.
140 */
141 
142 struct hdrinfo
143 {
144 	char	*hi_field;	/* the name of the field */
145 	u_short	hi_flags;	/* status bits, see below */
146 	u_short	hi_mflags;	/* m_flags needed for this field */
147 };
148 
149 extern struct hdrinfo	HdrInfo[];
150 
151 /* bits for h_flags and hi_flags */
152 # define H_EOH		00001	/* this field terminates header */
153 # define H_RCPT		00002	/* contains recipient addresses */
154 # define H_DEFAULT	00004	/* if another value is found, drop this */
155 # define H_USED		00010	/* indicates that this has been output */
156 # define H_CHECK	00020	/* check h_mflags against m_flags */
157 # define H_ACHECK	00040	/* ditto, but always (not just default) */
158 # define H_FORCE	00100	/* force this field, even if default */
159 # define H_TRACE	00200	/* this field contains trace information */
160 # define H_FROM		00400	/* this is a from-type field */
161 /*
162 **  Envelope structure.
163 **	This structure defines the message itself.  There is usually
164 **	only one of these -- for the message that we originally read
165 **	and which is our primary interest -- but other envelopes can
166 **	be generated during processing.  For example, error messages
167 **	will have their own envelope.
168 */
169 
170 struct envelope
171 {
172 	HDR		*e_header;	/* head of header list */
173 	long		e_msgpriority;	/* adjusted priority of this message */
174 	time_t		e_ctime;	/* time message appeared in the queue */
175 	bool		e_queueup;	/* queue this message */
176 	bool		e_dontqueue;	/* override queueing */
177 	bool		e_oldstyle;	/* use spaces (not commas) in hdrs */
178 	bool		e_sendreceipt;	/* actually send a receipt back */
179 	char		*e_to;		/* the target person */
180 	char		*e_receiptto;	/* return receipt address */
181 	ADDRESS		e_from;		/* the person it is from */
182 	char		**e_fromdomain;	/* the domain part of the sender */
183 	ADDRESS		*e_sendqueue;	/* list of message recipients */
184 	ADDRESS		*e_errorqueue;	/* the queue for error responses */
185 	long		e_msgsize;	/* size of the message in bytes */
186 	short		e_class;	/* msg class (priority, junk, etc.) */
187 	int		(*e_puthdr)();	/* function to put header of message */
188 	int		(*e_putbody)();	/* function to put body of message */
189 	struct envelope	*e_parent;	/* the message this one encloses */
190 	char		*e_df;		/* location of temp file */
191 	char		*e_qf;		/* queue control file */
192 	char		*e_id;		/* code for this entry in queue */
193 	char		*e_macro[128];	/* macro definitions */
194 };
195 
196 typedef struct envelope	ENVELOPE;
197 
198 EXTERN ENVELOPE	*CurEnv;	/* envelope currently being processed */
199 /*
200 **  Work queue.
201 */
202 
203 struct work
204 {
205 	char		*w_name;	/* name of control file */
206 	long		w_pri;		/* priority of message, see below */
207 	struct work	*w_next;	/* next in queue */
208 };
209 
210 typedef struct work	WORK;
211 
212 EXTERN WORK	*WorkQ;			/* queue of things to be done */
213 
214 
215 /*
216 **  Message priorities.
217 **	Priorities > 0 should be preemptive.
218 **
219 **	CurEnv->e_msgpriority is the number of bytes in the message adjusted
220 **	by the message priority and the amount of time the message
221 **	has been sitting around.  Each priority point is worth
222 **	WKPRIFACT bytes of message, and each time we reprocess a
223 **	message the size gets reduced by WKTIMEFACT.
224 **
225 **	The "class" is this number, unadjusted by the age or size of
226 **	this message.  Classes with negative representations will have
227 **	error messages thrown away if they are not local.
228 */
229 
230 struct priority
231 {
232 	char	*pri_name;	/* external name of priority */
233 	int	pri_val;	/* internal value for same */
234 };
235 
236 EXTERN struct priority	Priorities[MAXPRIORITIES];
237 EXTERN int		NumPriorities;	/* pointer into Priorities */
238 
239 # define WKPRIFACT	1800		/* bytes each pri point is worth */
240 # define WKTIMEFACT	400		/* bytes each time unit is worth */
241 /*
242 **  Rewrite rules.
243 */
244 
245 struct rewrite
246 {
247 	char	**r_lhs;	/* pattern match */
248 	char	**r_rhs;	/* substitution value */
249 	struct rewrite	*r_next;/* next in chain */
250 };
251 
252 EXTERN struct rewrite	*RewriteRules[MAXRWSETS];
253 
254 /*
255 **  Special characters in rewriting rules.
256 **	These are used internally only.
257 **	The COND* rules are actually used in macros rather than in
258 **		rewriting rules, but are given here because they
259 **		cannot conflict.
260 */
261 
262 /* left hand side items */
263 # define MATCHZANY	'\020'	/* match zero or more tokens */
264 # define MATCHANY	'\021'	/* match one or more tokens */
265 # define MATCHONE	'\022'	/* match exactly one token */
266 # define MATCHCLASS	'\023'	/* match one token in a class */
267 # define MATCHREPL	'\024'	/* replacement on RHS for above */
268 
269 /* right hand side items */
270 # define CANONNET	'\025'	/* canonical net, next token */
271 # define CANONHOST	'\026'	/* canonical host, next token */
272 # define CANONUSER	'\027'	/* canonical user, next N tokens */
273 # define CALLSUBR	'\030'	/* call another rewriting set */
274 
275 /* conditionals in macros */
276 # define CONDIF		'\031'	/* conditional if-then */
277 # define CONDELSE	'\032'	/* conditional else */
278 # define CONDFI		'\033'	/* conditional fi */
279 /*
280 **  Symbol table definitions
281 */
282 
283 struct symtab
284 {
285 	char		*s_name;	/* name to be entered */
286 	char		s_type;		/* general type (see below) */
287 	struct symtab	*s_next;	/* pointer to next in chain */
288 	union
289 	{
290 		long	sv_class;	/* bit-map of word classes */
291 		ADDRESS	*sv_addr;	/* pointer to address header */
292 		MAILER	*sv_mailer;	/* pointer to mailer */
293 		char	*sv_alias;	/* alias */
294 	}	s_value;
295 };
296 
297 typedef struct symtab	STAB;
298 
299 /* symbol types */
300 # define ST_UNDEF	0	/* undefined type */
301 # define ST_CLASS	1	/* class map */
302 # define ST_ADDRESS	2	/* an address in parsed format */
303 # define ST_MAILER	3	/* a mailer header */
304 # define ST_ALIAS	4	/* an alias */
305 
306 # define s_class	s_value.sv_class
307 # define s_address	s_value.sv_addr
308 # define s_mailer	s_value.sv_mailer
309 # define s_alias	s_value.sv_alias
310 
311 extern STAB	*stab();
312 
313 /* opcodes to stab */
314 # define ST_FIND	0	/* find entry */
315 # define ST_ENTER	1	/* enter if not there */
316 /*
317 **  STRUCT EVENT -- event queue.
318 **
319 **	Maintained in sorted order.
320 **
321 **	We store the pid of the process that set this event to insure
322 **	that when we fork we will not take events intended for the parent.
323 */
324 
325 struct event
326 {
327 	time_t		ev_time;	/* time of the function call */
328 	int		(*ev_func)();	/* function to call */
329 	int		ev_arg;		/* argument to ev_func */
330 	int		ev_pid;		/* pid that set this event */
331 	struct event	*ev_link;	/* link to next item */
332 };
333 
334 typedef struct event	EVENT;
335 
336 EXTERN EVENT	*EventQueue;		/* head of event queue */
337 /*
338 **  Statistics structure.
339 */
340 
341 struct statistics
342 {
343 	time_t	stat_itime;		/* file initialization time */
344 	short	stat_size;		/* size of this structure */
345 	long	stat_nf[MAXMAILERS];	/* # msgs from each mailer */
346 	long	stat_bf[MAXMAILERS];	/* kbytes from each mailer */
347 	long	stat_nt[MAXMAILERS];	/* # msgs to each mailer */
348 	long	stat_bt[MAXMAILERS];	/* kbytes to each mailer */
349 };
350 
351 EXTERN struct statistics	Stat;
352 extern long			kbytes();	/* for _bf, _bt */
353 /*
354 **  Operation modes
355 **	The default operation mode can be safely changed (except
356 **	that the default cannot be MD_DAEMON).
357 */
358 
359 EXTERN char	Mode;		/* operation mode, see below */
360 
361 #define MD_DELIVER	'a'		/* collect and deliver */
362 #define MD_FORK		'f'		/* verify & fork before delivery */
363 #define MD_QUEUE	'q'		/* collect & queue, don't deliver */
364 #define MD_DAEMON	'd'		/* run as a daemon */
365 #define MD_VERIFY	'v'		/* verify: don't collect or deliver */
366 
367 #define MD_DEFAULT	MD_DELIVER	/* default operation mode */
368 /*
369 **  Global variables.
370 */
371 
372 EXTERN bool	FromFlag;	/* if set, "From" person is explicit */
373 EXTERN bool	MailBack;	/* mail back response on error */
374 EXTERN bool	BerkNet;	/* called from BerkNet */
375 EXTERN bool	WriteBack;	/* write back response on error */
376 EXTERN bool	NoAlias;	/* if set, don't do any aliasing */
377 EXTERN bool	ForceMail;	/* if set, mail even if already got a copy */
378 EXTERN bool	MeToo;		/* send to the sender also */
379 EXTERN bool	IgnrDot;	/* don't let dot end messages */
380 EXTERN bool	SaveFrom;	/* save leading "From" lines */
381 EXTERN bool	Verbose;	/* set if blow-by-blow desired */
382 EXTERN bool	GrabTo;		/* if set, get recipients from msg */
383 EXTERN bool	DontSend;	/* mark recipients as QDONTSEND */
384 EXTERN bool	NoReturn;	/* don't return letter to sender */
385 EXTERN bool	Smtp;		/* using SMTP over connection */
386 EXTERN bool	SuprErrs;	/* set if we are suppressing errors */
387 EXTERN bool	QueueRun;	/* currently running message from the queue */
388 EXTERN bool	HoldErrs;	/* only output errors to transcript */
389 EXTERN bool	ArpaMode;	/* set if running arpanet protocol */
390 EXTERN bool	NoConnect;	/* don't connect to non-local mailers */
391 EXTERN bool	FatalErrors;	/* set if fatal errors during processing */
392 extern bool	SuperSafe;	/* be extra careful, despite cost [conf.c] */
393 extern time_t	TimeOut;	/* time until timeout [conf.c] */
394 EXTERN FILE	*InChannel;	/* input connection */
395 EXTERN FILE	*OutChannel;	/* output connection */
396 EXTERN FILE	*TempFile;	/* mail temp file */
397 EXTERN FILE	*Xscript;	/* mail transcript file */
398 EXTERN int	RealUid;	/* when Daemon, real uid of caller */
399 EXTERN int	RealGid;	/* when Daemon, real gid of caller */
400 extern int	DefUid;		/* default uid to run as [conf.c] */
401 extern int	DefGid;		/* default gid to run as [conf.c] */
402 EXTERN int	OldUmask;	/* umask when sendmail starts up */
403 EXTERN int	Errors;		/* set if errors (local to single pass) */
404 EXTERN int	ExitStat;	/* exit status code */
405 EXTERN int	HopCount;	/* hop count */
406 EXTERN int	AliasLevel;	/* depth of aliasing */
407 EXTERN int	MotherPid;	/* proc id of parent process */
408 EXTERN int	LineNumber;	/* line number in current input */
409 EXTERN time_t	QueueIntvl;	/* intervals between running the queue */
410 EXTERN char	*HostName;	/* name of this host for SMTP messages */
411 EXTERN char	*Transcript;	/* the transcript file name */
412 extern char	*XcriptFile;	/* template for Transcript [conf.c] */
413 extern char	*AliasFile;	/* location of alias file [conf.c] */
414 extern char	*ConfFile;	/* location of configuration file [conf.c] */
415 extern char	*StatFile;	/* location of statistics summary [conf.c] */
416 extern char	*QueueDir;	/* location of queue directory [conf.c] */
417 extern char	Arpa_Info[];	/* the reply code for Arpanet info [conf.c] */
418 EXTERN jmp_buf	TopFrame;	/* branch-to-top-of-loop-on-error frame */
419 EXTERN bool	QuickAbort;	/*  .... but only if we want a quick abort */
420 extern int	ReadTimeout;	/* timeout on reads [conf.c] */
421 extern int	LogLevel;	/* level of logging to perform [conf.c] */
422 /*
423 **  Trace information
424 */
425 
426 /* trace vector and macros for debugging flags */
427 EXTERN u_char	tTdvect[100];
428 # define tTd(flag, level)	(tTdvect[flag] >= level)
429 # define tTdlevel(flag)		(tTdvect[flag])
430 /*
431 **  Miscellaneous information.
432 */
433 
434 # include	<sysexits.h>
435 
436 # define setstat(s)		{ if (ExitStat == EX_OK) ExitStat = s; }
437 
438 
439 /* useful functions */
440 
441 extern char	*newstr();
442 extern ADDRESS	*parse();
443 extern char	*xalloc();
444 extern bool	sameaddr();
445 extern FILE	*dfopen();
446 extern EVENT	*setevent();
447 extern char	*sfgets();
448 extern char	*queuename();
449 extern time_t	curtime();
450