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.117		03/07/83";
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 "conf.h"
20 # include "useful.h"
21 
22 # ifdef LOG
23 # include <syslog.h>
24 # endif LOG
25 
26 
27 /*
28 **  Data structure for bit maps.
29 **
30 **	Each bit in this map can be referenced by an ascii character.
31 **	This is 128 possible bits, or 12 8-bit bytes.
32 */
33 
34 #define BITMAPBYTES	16	/* number of bytes in a bit map */
35 #define BYTEBITS	8	/* number of bits in a byte */
36 
37 /* internal macros */
38 #define _BITWORD(bit)	(bit / (BYTEBITS * sizeof (int)))
39 #define _BITBIT(bit)	(1 << (bit % (BYTEBITS * sizeof (int))))
40 
41 typedef int	BITMAP[BITMAPBYTES / sizeof (int)];
42 
43 /* test bit number N */
44 #define bitnset(bit, map)	((map)[_BITWORD(bit)] & _BITBIT(bit))
45 
46 /* set bit number N */
47 #define setbitn(bit, map)	(map)[_BITWORD(bit)] |= _BITBIT(bit)
48 
49 /* clear bit number N */
50 #define clrbitn(bit, map)	(map)[_BITWORD(bit)] &= ~_BITBIT(bit)
51 
52 /* clear an entire bit map */
53 #define clrbitmap(map)		bzero((char *) map, BITMAPBYTES)
54 /*
55 **  Address structure.
56 **	Addresses are stored internally in this structure.
57 */
58 
59 struct address
60 {
61 	char		*q_paddr;	/* the printname for the address */
62 	char		*q_user;	/* user name */
63 	char		*q_host;	/* host name */
64 	struct mailer	*q_mailer;	/* mailer to use */
65 	u_short		q_flags;	/* status flags, see below */
66 	short		q_uid;		/* user-id of receiver (if known) */
67 	short		q_gid;		/* group-id of receiver (if known) */
68 	char		*q_home;	/* home dir (local mailer only) */
69 	char		*q_fullname;	/* full name if known */
70 	struct address	*q_next;	/* chain */
71 	struct address	*q_alias;	/* address this results from */
72 	struct address	*q_tchain;	/* temporary use chain */
73 	time_t		q_timeout;	/* timeout for this address */
74 };
75 
76 typedef struct address ADDRESS;
77 
78 # define QDONTSEND	000001	/* don't send to this address */
79 # define QBADADDR	000002	/* this address is verified bad */
80 # define QGOODUID	000004	/* the q_uid q_gid fields are good */
81 # define QPRIMARY	000010	/* set from argv */
82 # define QQUEUEUP	000020	/* queue for later transmission */
83 /*
84 **  Mailer definition structure.
85 **	Every mailer known to the system is declared in this
86 **	structure.  It defines the pathname of the mailer, some
87 **	flags associated with it, and the argument vector to
88 **	pass to it.  The flags are defined in conf.c
89 **
90 **	The argument vector is expanded before actual use.  All
91 **	words except the first are passed through the macro
92 **	processor.
93 */
94 
95 struct mailer
96 {
97 	char	*m_name;	/* symbolic name of this mailer */
98 	char	*m_mailer;	/* pathname of the mailer to use */
99 	BITMAP	m_flags;	/* status flags, see below */
100 	short	m_mno;		/* mailer number internally */
101 	char	**m_argv;	/* template argument vector */
102 	short	m_s_rwset;	/* rewriting set for sender addresses */
103 	short	m_r_rwset;	/* rewriting set for recipient addresses */
104 	char	*m_eol;		/* end of line string */
105 	long	m_maxsize;	/* size limit on message to this mailer */
106 };
107 
108 typedef struct mailer	MAILER;
109 
110 /* bits for m_flags */
111 # define M_FOPT		'f'	/* mailer takes picky -f flag */
112 # define M_ROPT		'r'	/* mailer takes picky -r flag */
113 # define M_RESTR	'S'	/* must be daemon to execute */
114 # define M_NHDR		'n'	/* don't insert From line */
115 # define M_LOCAL	'l'	/* delivery is to this host */
116 # define M_STRIPQ	's'	/* strip quote chars from user/host */
117 # define M_MUSER	'm'	/* can handle multiple users at once */
118 # define M_CANONICAL	'C'	/* make addresses canonical "u@dom" */
119 # define M_USR_UPPER	'u'	/* preserve user case distinction */
120 # define M_HST_UPPER	'h'	/* preserve host case distinction */
121 # define M_UGLYUUCP	'U'	/* this wants an ugly UUCP from line */
122 # define M_EXPENSIVE	'e'	/* it costs to use this mailer.... */
123 # define M_LIMITS	'L'	/* must enforce SMTP line limits */
124 # define M_INTERNAL	'I'	/* SMTP to another sendmail site */
125 # define M_FROMPATH	'p'	/* use reverse-path in MAIL FROM: */
126 # define M_XDOT		'X'	/* use hidden-dot algorithm */
127 
128 EXTERN MAILER	*Mailer[MAXMAILERS+1];
129 
130 EXTERN MAILER	*LocalMailer;		/* ptr to local mailer */
131 EXTERN MAILER	*ProgMailer;		/* ptr to program mailer */
132 /*
133 **  Header structure.
134 **	This structure is used internally to store header items.
135 */
136 
137 struct header
138 {
139 	char		*h_field;	/* the name of the field */
140 	char		*h_value;	/* the value of that field */
141 	struct header	*h_link;	/* the next header */
142 	u_short		h_flags;	/* status bits, see below */
143 	BITMAP		h_mflags;	/* m_flags bits needed */
144 };
145 
146 typedef struct header	HDR;
147 
148 /*
149 **  Header information structure.
150 **	Defined in conf.c, this struct declares the header fields
151 **	that have some magic meaning.
152 */
153 
154 struct hdrinfo
155 {
156 	char	*hi_field;	/* the name of the field */
157 	u_short	hi_flags;	/* status bits, see below */
158 };
159 
160 extern struct hdrinfo	HdrInfo[];
161 
162 /* bits for h_flags and hi_flags */
163 # define H_EOH		00001	/* this field terminates header */
164 # define H_RCPT		00002	/* contains recipient addresses */
165 # define H_DEFAULT	00004	/* if another value is found, drop this */
166 # define H_RESENT	00010	/* this address is a "Resent-..." address */
167 # define H_CHECK	00020	/* check h_mflags against m_flags */
168 # define H_ACHECK	00040	/* ditto, but always (not just default) */
169 # define H_FORCE	00100	/* force this field, even if default */
170 # define H_TRACE	00200	/* this field contains trace information */
171 # define H_FROM		00400	/* this is a from-type field */
172 /*
173 **  Envelope structure.
174 **	This structure defines the message itself.  There is usually
175 **	only one of these -- for the message that we originally read
176 **	and which is our primary interest -- but other envelopes can
177 **	be generated during processing.  For example, error messages
178 **	will have their own envelope.
179 */
180 
181 struct envelope
182 {
183 	HDR		*e_header;	/* head of header list */
184 	long		e_msgpriority;	/* adjusted priority of this message */
185 	time_t		e_ctime;	/* time message appeared in the queue */
186 	char		*e_to;		/* the target person */
187 	char		*e_receiptto;	/* return receipt address */
188 	ADDRESS		e_from;		/* the person it is from */
189 	char		**e_fromdomain;	/* the domain part of the sender */
190 	ADDRESS		*e_sendqueue;	/* list of message recipients */
191 	ADDRESS		*e_errorqueue;	/* the queue for error responses */
192 	long		e_msgsize;	/* size of the message in bytes */
193 	short		e_class;	/* msg class (priority, junk, etc.) */
194 	short		e_flags;	/* flags, see below */
195 	short		e_hopcount;	/* number of times processed */
196 	int		(*e_puthdr)();	/* function to put header of message */
197 	int		(*e_putbody)();	/* function to put body of message */
198 	struct envelope	*e_parent;	/* the message this one encloses */
199 	struct envelope *e_sibling;	/* the next envelope of interest */
200 	char		*e_df;		/* location of temp file */
201 	FILE		*e_dfp;		/* temporary file */
202 	char		*e_id;		/* code for this entry in queue */
203 	FILE		*e_xfp;		/* transcript file */
204 	char		*e_message;	/* error message */
205 	char		*e_macro[128];	/* macro definitions */
206 };
207 
208 typedef struct envelope	ENVELOPE;
209 
210 /* values for e_flags */
211 #define EF_OLDSTYLE	000001		/* use spaces (not commas) in hdrs */
212 #define EF_INQUEUE	000002		/* this message is fully queued */
213 #define EF_TIMEOUT	000004		/* this message is too old */
214 #define EF_CLRQUEUE	000010		/* disk copy is no longer needed */
215 #define EF_SENDRECEIPT	000020		/* send a return receipt */
216 #define EF_FATALERRS	000040		/* fatal errors occured */
217 #define EF_KEEPQUEUE	000100		/* keep queue files always */
218 #define EF_RESPONSE	000200		/* this is an error or return receipt */
219 #define EF_RESENT	000400		/* this message is being forwarded */
220 
221 EXTERN ENVELOPE	*CurEnv;	/* envelope currently being processed */
222 /*
223 **  Message priorities.
224 **	Priorities > 0 should be preemptive.
225 **
226 **	CurEnv->e_msgpriority is the number of bytes in the message adjusted
227 **	by the message priority and the amount of time the message
228 **	has been sitting around.  Each priority point is worth
229 **	WKPRIFACT bytes of message, and each time we reprocess a
230 **	message the size gets reduced by WKTIMEFACT.
231 **
232 **	The "class" is this number, unadjusted by the age or size of
233 **	this message.  Classes with negative representations will have
234 **	error messages thrown away if they are not local.
235 */
236 
237 struct priority
238 {
239 	char	*pri_name;	/* external name of priority */
240 	int	pri_val;	/* internal value for same */
241 };
242 
243 EXTERN struct priority	Priorities[MAXPRIORITIES];
244 EXTERN int		NumPriorities;	/* pointer into Priorities */
245 
246 # define WKPRIFACT	1800		/* bytes each pri point is worth */
247 # define WKTIMEFACT	400		/* bytes each time unit is worth */
248 /*
249 **  Rewrite rules.
250 */
251 
252 struct rewrite
253 {
254 	char	**r_lhs;	/* pattern match */
255 	char	**r_rhs;	/* substitution value */
256 	struct rewrite	*r_next;/* next in chain */
257 };
258 
259 EXTERN struct rewrite	*RewriteRules[MAXRWSETS];
260 
261 /*
262 **  Special characters in rewriting rules.
263 **	These are used internally only.
264 **	The COND* rules are actually used in macros rather than in
265 **		rewriting rules, but are given here because they
266 **		cannot conflict.
267 */
268 
269 /* left hand side items */
270 # define MATCHZANY	'\020'	/* match zero or more tokens */
271 # define MATCHANY	'\021'	/* match one or more tokens */
272 # define MATCHONE	'\022'	/* match exactly one token */
273 # define MATCHCLASS	'\023'	/* match one token in a class */
274 # define MATCHNCLASS	'\034'	/* match anything not in class */
275 # define MATCHREPL	'\024'	/* replacement on RHS for above */
276 
277 /* right hand side items */
278 # define CANONNET	'\025'	/* canonical net, next token */
279 # define CANONHOST	'\026'	/* canonical host, next token */
280 # define CANONUSER	'\027'	/* canonical user, next N tokens */
281 # define CALLSUBR	'\030'	/* call another rewriting set */
282 
283 /* conditionals in macros */
284 # define CONDIF		'\031'	/* conditional if-then */
285 # define CONDELSE	'\032'	/* conditional else */
286 # define CONDFI		'\033'	/* conditional fi */
287 /*
288 **  Symbol table definitions
289 */
290 
291 struct symtab
292 {
293 	char		*s_name;	/* name to be entered */
294 	char		s_type;		/* general type (see below) */
295 	struct symtab	*s_next;	/* pointer to next in chain */
296 	union
297 	{
298 		BITMAP	sv_class;	/* bit-map of word classes */
299 		ADDRESS	*sv_addr;	/* pointer to address header */
300 		MAILER	*sv_mailer;	/* pointer to mailer */
301 		char	*sv_alias;	/* alias */
302 	}	s_value;
303 };
304 
305 typedef struct symtab	STAB;
306 
307 /* symbol types */
308 # define ST_UNDEF	0	/* undefined type */
309 # define ST_CLASS	1	/* class map */
310 # define ST_ADDRESS	2	/* an address in parsed format */
311 # define ST_MAILER	3	/* a mailer header */
312 # define ST_ALIAS	4	/* an alias */
313 
314 # define s_class	s_value.sv_class
315 # define s_address	s_value.sv_addr
316 # define s_mailer	s_value.sv_mailer
317 # define s_alias	s_value.sv_alias
318 
319 extern STAB	*stab();
320 
321 /* opcodes to stab */
322 # define ST_FIND	0	/* find entry */
323 # define ST_ENTER	1	/* enter if not there */
324 /*
325 **  STRUCT EVENT -- event queue.
326 **
327 **	Maintained in sorted order.
328 **
329 **	We store the pid of the process that set this event to insure
330 **	that when we fork we will not take events intended for the parent.
331 */
332 
333 struct event
334 {
335 	time_t		ev_time;	/* time of the function call */
336 	int		(*ev_func)();	/* function to call */
337 	int		ev_arg;		/* argument to ev_func */
338 	int		ev_pid;		/* pid that set this event */
339 	struct event	*ev_link;	/* link to next item */
340 };
341 
342 typedef struct event	EVENT;
343 
344 EXTERN EVENT	*EventQueue;		/* head of event queue */
345 /*
346 **  Operation, send, and error modes
347 **
348 **	The operation mode describes the basic operation of sendmail.
349 **	This can be set from the command line, and is "send mail" by
350 **	default.
351 **
352 **	The send mode tells how to send mail.  It can be set in the
353 **	configuration file.  It's setting determines how quickly the
354 **	mail will be delivered versus the load on your system.  If the
355 **	-v (verbose) flag is given, it will be forced to SM_DELIVER
356 **	mode.
357 **
358 **	The error mode tells how to return errors.
359 */
360 
361 EXTERN char	OpMode;		/* operation mode, see below */
362 
363 #define MD_DELIVER	'm'		/* be a mail sender */
364 #define MD_ARPAFTP	'a'		/* old-style arpanet protocols */
365 #define MD_SMTP		's'		/* run SMTP on standard input */
366 #define MD_DAEMON	'd'		/* run as a daemon */
367 #define MD_VERIFY	'v'		/* verify: don't collect or deliver */
368 #define MD_TEST		't'		/* test mode: resolve addrs only */
369 #define MD_INITALIAS	'i'		/* initialize alias database */
370 #define MD_PRINT	'p'		/* print the queue */
371 #define MD_FREEZE	'z'		/* freeze the configuration file */
372 
373 
374 EXTERN char	SendMode;	/* send mode, see below */
375 
376 #define SM_DELIVER	'i'		/* interactive delivery */
377 #define SM_QUICKD	'j'		/* deliver w/o queueing */
378 #define SM_FORK		'b'		/* deliver in background */
379 #define SM_QUEUE	'q'		/* queue, don't deliver */
380 #define SM_VERIFY	'v'		/* verify only (used internally) */
381 
382 
383 EXTERN char	ErrorMode;	/* error mode, see below */
384 
385 #define EM_PRINT	'p'		/* print errors */
386 #define EM_MAIL		'm'		/* mail back errors */
387 #define EM_WRITE	'w'		/* write back errors */
388 #define EM_BERKNET	'e'		/* special berknet processing */
389 #define EM_QUIET	'q'		/* don't print messages (stat only) */
390 /*
391 **  Global variables.
392 */
393 
394 EXTERN bool	FromFlag;	/* if set, "From" person is explicit */
395 EXTERN bool	NoAlias;	/* if set, don't do any aliasing */
396 EXTERN bool	ForceMail;	/* if set, mail even if already got a copy */
397 EXTERN bool	MeToo;		/* send to the sender also */
398 EXTERN bool	IgnrDot;	/* don't let dot end messages */
399 EXTERN bool	SaveFrom;	/* save leading "From" lines */
400 EXTERN bool	Verbose;	/* set if blow-by-blow desired */
401 EXTERN bool	GrabTo;		/* if set, get recipients from msg */
402 EXTERN bool	NoReturn;	/* don't return letter to sender */
403 EXTERN bool	SuprErrs;	/* set if we are suppressing errors */
404 EXTERN bool	QueueRun;	/* currently running message from the queue */
405 EXTERN bool	HoldErrs;	/* only output errors to transcript */
406 EXTERN bool	NoConnect;	/* don't connect to non-local mailers */
407 EXTERN bool	SuperSafe;	/* be extra careful, even if expensive */
408 EXTERN bool	SafeAlias;	/* alias file must have "@:@" to be complete */
409 EXTERN bool	AutoRebuild;	/* auto-rebuild the alias database as needed */
410 EXTERN time_t	TimeOut;	/* time until timeout */
411 EXTERN FILE	*InChannel;	/* input connection */
412 EXTERN FILE	*OutChannel;	/* output connection */
413 EXTERN int	RealUid;	/* when Daemon, real uid of caller */
414 EXTERN int	RealGid;	/* when Daemon, real gid of caller */
415 EXTERN int	DefUid;		/* default uid to run as */
416 EXTERN int	DefGid;		/* default gid to run as */
417 EXTERN int	OldUmask;	/* umask when sendmail starts up */
418 EXTERN int	Errors;		/* set if errors (local to single pass) */
419 EXTERN int	ExitStat;	/* exit status code */
420 EXTERN int	AliasLevel;	/* depth of aliasing */
421 EXTERN int	MotherPid;	/* proc id of parent process */
422 EXTERN int	LineNumber;	/* line number in current input */
423 EXTERN int	ReadTimeout;	/* timeout on reads */
424 EXTERN int	LogLevel;	/* level of logging to perform */
425 EXTERN int	FileMode;	/* mode on files */
426 EXTERN time_t	QueueIntvl;	/* intervals between running the queue */
427 EXTERN char	*HostName;	/* name of this host for SMTP messages */
428 EXTERN char	*AliasFile;	/* location of alias file */
429 EXTERN char	*HelpFile;	/* location of SMTP help file */
430 EXTERN char	*StatFile;	/* location of statistics summary */
431 EXTERN char	*QueueDir;	/* location of queue directory */
432 EXTERN char	*FileName;	/* name to print on error messages */
433 EXTERN char	*TrustedUsers[MAXTRUST+1];	/* list of trusted users */
434 EXTERN jmp_buf	TopFrame;	/* branch-to-top-of-loop-on-error frame */
435 EXTERN bool	QuickAbort;	/*  .... but only if we want a quick abort */
436 extern char	*ConfFile;	/* location of configuration file [conf.c] */
437 extern char	*FreezeFile;	/* location of frozen memory image [conf.c] */
438 extern char	Arpa_Info[];	/* the reply code for Arpanet info [conf.c] */
439 extern char	SpaceSub;	/* substitution for <lwsp> [conf.c] */
440 /*
441 **  Trace information
442 */
443 
444 /* trace vector and macros for debugging flags */
445 EXTERN u_char	tTdvect[100];
446 # define tTd(flag, level)	(tTdvect[flag] >= level)
447 # define tTdlevel(flag)		(tTdvect[flag])
448 /*
449 **  Miscellaneous information.
450 */
451 
452 # include	<sysexits.h>
453 
454 
455 /*
456 **  Some in-line functions
457 */
458 
459 /* set exit status */
460 #define setstat(s)	{ \
461 				if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \
462 					ExitStat = s; \
463 			}
464 
465 /* make a copy of a string */
466 #define newstr(s)	strcpy(xalloc(strlen(s) + 1), s)
467 
468 
469 /*
470 **  Declarations of useful functions
471 */
472 
473 extern ADDRESS	*parseaddr();
474 extern char	*xalloc();
475 extern bool	sameaddr();
476 extern FILE	*dfopen();
477 extern EVENT	*setevent();
478 extern char	*sfgets();
479 extern char	*queuename();
480 extern time_t	curtime();
481