1 /*
2  * Copyright (c) 1983 Eric P. Allman
3  * Copyright (c) 1988 Regents of the University of California.
4  * All rights reserved.
5  *
6  * %sccs.include.redist.c%
7  *
8  *	@(#)sendmail.h	6.11 (Berkeley) 02/18/93
9  */
10 
11 /*
12 **  SENDMAIL.H -- Global definitions for sendmail.
13 */
14 
15 # ifdef _DEFINE
16 # define EXTERN
17 # ifndef lint
18 static char SmailSccsId[] =	"@(#)sendmail.h	6.11		02/18/93";
19 # endif lint
20 # else /*  _DEFINE */
21 # define EXTERN extern
22 # endif /* _DEFINE */
23 
24 # include <stddef.h>
25 # include <stdlib.h>
26 # include <stdio.h>
27 # include <ctype.h>
28 # include <setjmp.h>
29 # include <sysexits.h>
30 # include <string.h>
31 # include <time.h>
32 # include <errno.h>
33 
34 # include "conf.h"
35 # include "useful.h"
36 
37 # ifdef LOG
38 # include <syslog.h>
39 # endif /* LOG */
40 
41 # ifdef DAEMON
42 # include <sys/socket.h>
43 # include <netinet/in.h>
44 # endif /* DAEMON */
45 
46 
47 
48 
49 /*
50 **  Data structure for bit maps.
51 **
52 **	Each bit in this map can be referenced by an ascii character.
53 **	This is 128 possible bits, or 12 8-bit bytes.
54 */
55 
56 #define BITMAPBYTES	16	/* number of bytes in a bit map */
57 #define BYTEBITS	8	/* number of bits in a byte */
58 
59 /* internal macros */
60 #define _BITWORD(bit)	(bit / (BYTEBITS * sizeof (int)))
61 #define _BITBIT(bit)	(1 << (bit % (BYTEBITS * sizeof (int))))
62 
63 typedef int	BITMAP[BITMAPBYTES / sizeof (int)];
64 
65 /* test bit number N */
66 #define bitnset(bit, map)	((map)[_BITWORD(bit)] & _BITBIT(bit))
67 
68 /* set bit number N */
69 #define setbitn(bit, map)	(map)[_BITWORD(bit)] |= _BITBIT(bit)
70 
71 /* clear bit number N */
72 #define clrbitn(bit, map)	(map)[_BITWORD(bit)] &= ~_BITBIT(bit)
73 
74 /* clear an entire bit map */
75 #define clrbitmap(map)		bzero((char *) map, BITMAPBYTES)
76 /*
77 **  Address structure.
78 **	Addresses are stored internally in this structure.
79 */
80 
81 struct address
82 {
83 	char		*q_paddr;	/* the printname for the address */
84 	char		*q_user;	/* user name */
85 	char		*q_ruser;	/* real user name, or NULL if q_user */
86 	char		*q_host;	/* host name */
87 	struct mailer	*q_mailer;	/* mailer to use */
88 	u_short		q_flags;	/* status flags, see below */
89 	uid_t		q_uid;		/* user-id of receiver (if known) */
90 	gid_t		q_gid;		/* group-id of receiver (if known) */
91 	char		*q_home;	/* home dir (local mailer only) */
92 	char		*q_fullname;	/* full name if known */
93 	struct address	*q_next;	/* chain */
94 	struct address	*q_alias;	/* address this results from */
95 	struct address	*q_tchain;	/* temporary use chain */
96 	time_t		q_timeout;	/* timeout for this address */
97 };
98 
99 typedef struct address ADDRESS;
100 
101 # define QDONTSEND	000001	/* don't send to this address */
102 # define QBADADDR	000002	/* this address is verified bad */
103 # define QGOODUID	000004	/* the q_uid q_gid fields are good */
104 # define QPRIMARY	000010	/* set from argv */
105 # define QQUEUEUP	000020	/* queue for later transmission */
106 # define QSENT		000040	/* has been successfully delivered */
107 # define QNOTREMOTE	000100	/* not an address for remote forwarding */
108 /*
109 **  Mailer definition structure.
110 **	Every mailer known to the system is declared in this
111 **	structure.  It defines the pathname of the mailer, some
112 **	flags associated with it, and the argument vector to
113 **	pass to it.  The flags are defined in conf.c
114 **
115 **	The argument vector is expanded before actual use.  All
116 **	words except the first are passed through the macro
117 **	processor.
118 */
119 
120 struct mailer
121 {
122 	char	*m_name;	/* symbolic name of this mailer */
123 	char	*m_mailer;	/* pathname of the mailer to use */
124 	BITMAP	m_flags;	/* status flags, see below */
125 	short	m_mno;		/* mailer number internally */
126 	char	**m_argv;	/* template argument vector */
127 	short	m_sh_rwset;	/* rewrite set: sender header addresses */
128 	short	m_se_rwset;	/* rewrite set: sender envelope addresses */
129 	short	m_rh_rwset;	/* rewrite set: recipient header addresses */
130 	short	m_re_rwset;	/* rewrite set: recipient envelope addresses */
131 	char	*m_eol;		/* end of line string */
132 	long	m_maxsize;	/* size limit on message to this mailer */
133 	int	m_linelimit;	/* max # characters per line */
134 };
135 
136 typedef struct mailer	MAILER;
137 
138 /* bits for m_flags */
139 # define M_NOCOMMENT	'c'	/* don't include comment part of address */
140 # define M_CANONICAL	'C'	/* make addresses canonical "u@dom" */
141 		/*	'D'	/* CF: include Date: */
142 # define M_EXPENSIVE	'e'	/* it costs to use this mailer.... */
143 # define M_ESCFROM	'E'	/* escape From lines to >From */
144 # define M_FOPT		'f'	/* mailer takes picky -f flag */
145 		/*	'F'	/* CF: include From: or Resent-From: */
146 # define M_HST_UPPER	'h'	/* preserve host case distinction */
147 		/*	'H'	/* UIUC: MAIL11V3: preview headers */
148 # define M_INTERNAL	'I'	/* SMTP to another sendmail site */
149 # define M_LOCAL	'l'	/* delivery is to this host */
150 # define M_LIMITS	'L'	/* must enforce SMTP line limits */
151 # define M_MUSER	'm'	/* can handle multiple users at once */
152 		/*	'M'	/* CF: include Message-Id: */
153 # define M_NHDR		'n'	/* don't insert From line */
154 		/*	'N'	/* UIUC: MAIL11V3: DATA returns multi-status */
155 # define M_FROMPATH	'p'	/* use reverse-path in MAIL FROM: */
156 		/*	'P'	/* CF: include Return-Path: */
157 # define M_ROPT		'r'	/* mailer takes picky -r flag */
158 # define M_SECURE_PORT	'R'	/* try to send on a reserved TCP port */
159 # define M_STRIPQ	's'	/* strip quote chars from user/host */
160 # define M_RESTR	'S'	/* must be daemon to execute */
161 # define M_USR_UPPER	'u'	/* preserve user case distinction */
162 # define M_UGLYUUCP	'U'	/* this wants an ugly UUCP from line */
163 		/*	'V'	/* UIUC: !-relativize all addresses */
164 # define M_XDOT		'X'	/* use hidden-dot algorithm */
165 # define M_7BITS	'7'	/* use 7-bit path */
166 
167 EXTERN MAILER	*Mailer[MAXMAILERS+1];
168 
169 EXTERN MAILER	*LocalMailer;		/* ptr to local mailer */
170 EXTERN MAILER	*ProgMailer;		/* ptr to program mailer */
171 EXTERN MAILER	*FileMailer;		/* ptr to *file* mailer */
172 EXTERN MAILER	*InclMailer;		/* ptr to *include* mailer */
173 /*
174 **  Header structure.
175 **	This structure is used internally to store header items.
176 */
177 
178 struct header
179 {
180 	char		*h_field;	/* the name of the field */
181 	char		*h_value;	/* the value of that field */
182 	struct header	*h_link;	/* the next header */
183 	u_short		h_flags;	/* status bits, see below */
184 	BITMAP		h_mflags;	/* m_flags bits needed */
185 };
186 
187 typedef struct header	HDR;
188 
189 /*
190 **  Header information structure.
191 **	Defined in conf.c, this struct declares the header fields
192 **	that have some magic meaning.
193 */
194 
195 struct hdrinfo
196 {
197 	char	*hi_field;	/* the name of the field */
198 	u_short	hi_flags;	/* status bits, see below */
199 };
200 
201 extern struct hdrinfo	HdrInfo[];
202 
203 /* bits for h_flags and hi_flags */
204 # define H_EOH		00001	/* this field terminates header */
205 # define H_RCPT		00002	/* contains recipient addresses */
206 # define H_DEFAULT	00004	/* if another value is found, drop this */
207 # define H_RESENT	00010	/* this address is a "Resent-..." address */
208 # define H_CHECK	00020	/* check h_mflags against m_flags */
209 # define H_ACHECK	00040	/* ditto, but always (not just default) */
210 # define H_FORCE	00100	/* force this field, even if default */
211 # define H_TRACE	00200	/* this field contains trace information */
212 # define H_FROM		00400	/* this is a from-type field */
213 # define H_VALID	01000	/* this field has a validated value */
214 # define H_RECEIPTTO	02000	/* this field has return receipt info */
215 # define H_ERRORSTO	04000	/* this field has error address info */
216 /*
217 **  Envelope structure.
218 **	This structure defines the message itself.  There is usually
219 **	only one of these -- for the message that we originally read
220 **	and which is our primary interest -- but other envelopes can
221 **	be generated during processing.  For example, error messages
222 **	will have their own envelope.
223 */
224 
225 struct envelope
226 {
227 	HDR		*e_header;	/* head of header list */
228 	long		e_msgpriority;	/* adjusted priority of this message */
229 	time_t		e_ctime;	/* time message appeared in the queue */
230 	char		*e_to;		/* the target person */
231 	char		*e_receiptto;	/* return receipt address */
232 	ADDRESS		e_from;		/* the person it is from */
233 	char		*e_sender;	/* string version of from person */
234 	char		*e_returnpath;	/* string version of return path */
235 	char		**e_fromdomain;	/* the domain part of the sender */
236 	ADDRESS		*e_sendqueue;	/* list of message recipients */
237 	ADDRESS		*e_errorqueue;	/* the queue for error responses */
238 	long		e_msgsize;	/* size of the message in bytes */
239 	int		e_nrcpts;	/* number of recipients */
240 	short		e_class;	/* msg class (priority, junk, etc.) */
241 	short		e_flags;	/* flags, see below */
242 	short		e_hopcount;	/* number of times processed */
243 	short		e_nsent;	/* number of sends since checkpoint */
244 	int		(*e_puthdr)();	/* function to put header of message */
245 	int		(*e_putbody)();	/* function to put body of message */
246 	struct envelope	*e_parent;	/* the message this one encloses */
247 	struct envelope *e_sibling;	/* the next envelope of interest */
248 	char		*e_df;		/* location of temp file */
249 	FILE		*e_dfp;		/* temporary file */
250 	char		*e_id;		/* code for this entry in queue */
251 	FILE		*e_xfp;		/* transcript file */
252 	FILE		*e_lockfp;	/* the lock file for this message */
253 	char		*e_message;	/* error message */
254 	char		*e_macro[128];	/* macro definitions */
255 };
256 
257 typedef struct envelope	ENVELOPE;
258 
259 /* values for e_flags */
260 #define EF_OLDSTYLE	000001		/* use spaces (not commas) in hdrs */
261 #define EF_INQUEUE	000002		/* this message is fully queued */
262 #define EF_TIMEOUT	000004		/* this message is too old */
263 #define EF_CLRQUEUE	000010		/* disk copy is no longer needed */
264 #define EF_SENDRECEIPT	000020		/* send a return receipt */
265 #define EF_FATALERRS	000040		/* fatal errors occured */
266 #define EF_KEEPQUEUE	000100		/* keep queue files always */
267 #define EF_RESPONSE	000200		/* this is an error or return receipt */
268 #define EF_RESENT	000400		/* this message is being forwarded */
269 
270 EXTERN ENVELOPE	*CurEnv;	/* envelope currently being processed */
271 /*
272 **  Message priority classes.
273 **
274 **	The message class is read directly from the Priority: header
275 **	field in the message.
276 **
277 **	CurEnv->e_msgpriority is the number of bytes in the message plus
278 **	the creation time (so that jobs ``tend'' to be ordered correctly),
279 **	adjusted by the message class, the number of recipients, and the
280 **	amount of time the message has been sitting around.  This number
281 **	is used to order the queue.  Higher values mean LOWER priority.
282 **
283 **	Each priority class point is worth WkClassFact priority points;
284 **	each recipient is worth WkRecipFact priority points.  Each time
285 **	we reprocess a message the priority is adjusted by WkTimeFact.
286 **	WkTimeFact should normally decrease the priority so that jobs
287 **	that have historically failed will be run later; thanks go to
288 **	Jay Lepreau at Utah for pointing out the error in my thinking.
289 **
290 **	The "class" is this number, unadjusted by the age or size of
291 **	this message.  Classes with negative representations will have
292 **	error messages thrown away if they are not local.
293 */
294 
295 struct priority
296 {
297 	char	*pri_name;	/* external name of priority */
298 	int	pri_val;	/* internal value for same */
299 };
300 
301 EXTERN struct priority	Priorities[MAXPRIORITIES];
302 EXTERN int		NumPriorities;	/* pointer into Priorities */
303 /*
304 **  Rewrite rules.
305 */
306 
307 struct rewrite
308 {
309 	char	**r_lhs;	/* pattern match */
310 	char	**r_rhs;	/* substitution value */
311 	struct rewrite	*r_next;/* next in chain */
312 };
313 
314 EXTERN struct rewrite	*RewriteRules[MAXRWSETS];
315 
316 /*
317 **  Special characters in rewriting rules.
318 **	These are used internally only.
319 **	The COND* rules are actually used in macros rather than in
320 **		rewriting rules, but are given here because they
321 **		cannot conflict.
322 */
323 
324 /* left hand side items */
325 # define MATCHZANY	'\020'	/* match zero or more tokens */
326 # define MATCHANY	'\021'	/* match one or more tokens */
327 # define MATCHONE	'\022'	/* match exactly one token */
328 # define MATCHCLASS	'\023'	/* match one token in a class */
329 # define MATCHNCLASS	'\024'	/* match anything not in class */
330 # define MATCHREPL	'\025'	/* replacement on RHS for above */
331 
332 /* right hand side items */
333 # define CANONNET	'\026'	/* canonical net, next token */
334 # define CANONHOST	'\027'	/* canonical host, next token */
335 # define CANONUSER	'\030'	/* canonical user, next N tokens */
336 # define CALLSUBR	'\031'	/* call another rewriting set */
337 
338 /* conditionals in macros */
339 # define CONDIF		'\032'	/* conditional if-then */
340 # define CONDELSE	'\033'	/* conditional else */
341 # define CONDFI		'\034'	/* conditional fi */
342 
343 /* bracket characters for host name lookup */
344 # define HOSTBEGIN	'\035'	/* hostname lookup begin */
345 # define HOSTEND	'\036'	/* hostname lookup end */
346 
347 /* bracket characters for generalized lookup */
348 # define LOOKUPBEGIN	'\005'	/* generalized lookup begin */
349 # define LOOKUPEND	'\006'	/* generalized lookup end */
350 
351 /* \001 is also reserved as the macro expansion character */
352 
353 /* external <==> internal mapping table */
354 struct metamac
355 {
356 	char	metaname;	/* external code (after $) */
357 	char	metaval;	/* internal code (as above) */
358 };
359 /*
360 **  Information about currently open connections to mailers, or to
361 **  hosts that we have looked up recently.
362 */
363 
364 # define MCI	struct mailer_con_info
365 
366 MCI
367 {
368 	short		mci_flags;	/* flag bits, see below */
369 	short		mci_errno;	/* error number on last connection */
370 	short		mci_exitstat;	/* exit status from last connection */
371 	short		mci_state;	/* SMTP state */
372 	FILE		*mci_in;	/* input side of connection */
373 	FILE		*mci_out;	/* output side of connection */
374 	int		mci_pid;	/* process id of subordinate proc */
375 	char		*mci_phase;	/* SMTP phase string */
376 	struct mailer	*mci_mailer;	/* ptr to the mailer for this conn */
377 	char		*mci_host;	/* host name */
378 	time_t		mci_lastuse;	/* last usage time */
379 };
380 
381 
382 /* flag bits */
383 #define MCIF_VALID	00001		/* this entry is valid */
384 #define MCIF_TEMP	00002		/* don't cache this connection */
385 #define MCIF_CACHED	00004		/* currently in open cache */
386 
387 /* states */
388 #define MCIS_CLOSED	0		/* no traffic on this connection */
389 #define MCIS_OPENING	1		/* sending initial protocol */
390 #define MCIS_OPEN	2		/* open, initial protocol sent */
391 #define MCIS_ACTIVE	3		/* message being sent */
392 #define MCIS_QUITING	4		/* running quit protocol */
393 #define MCIS_SSD	5		/* service shutting down */
394 #define MCIS_ERROR	6		/* I/O error on connection */
395 /*
396 **  Mapping functions
397 **
398 **	These allow arbitrary mappings in the config file.  The idea
399 **	(albeit not the implementation) comes from IDA sendmail.
400 */
401 
402 
403 /*
404 **  The class of a map -- essentially the functions to call
405 */
406 
407 # define MAPCLASS	struct _mapclass
408 
409 MAPCLASS
410 {
411 	bool	(*map_init)();		/* initialization function */
412 	char	*(*map_lookup)();	/* lookup function */
413 };
414 
415 
416 /*
417 **  An actual map.
418 */
419 
420 # define MAP		struct _map
421 
422 MAP
423 {
424 	MAPCLASS	*map_class;	/* the class of this map */
425 	int		map_flags;	/* flags, see below */
426 	char		*map_file;	/* the (nominal) filename */
427 	void		*map_db;	/* the open database ptr */
428 	char		*map_app;	/* to append to successful matches */
429 	char		*map_domain;	/* the (nominal) NIS domain */
430 };
431 
432 /* bit values for map_flags */
433 # define MF_VALID	00001		/* this entry is valid */
434 # define MF_INCLNULL	00002		/* include null byte in key */
435 # define MF_OPTIONAL	00004		/* don't complain if map not found */
436 # define MF_NOFOLDCASE	00010		/* don't fold case in keys */
437 # define MF_MATCHONLY	00020		/* don't use the map value */
438 /*
439 **  Symbol table definitions
440 */
441 
442 struct symtab
443 {
444 	char		*s_name;	/* name to be entered */
445 	char		s_type;		/* general type (see below) */
446 	struct symtab	*s_next;	/* pointer to next in chain */
447 	union
448 	{
449 		BITMAP		sv_class;	/* bit-map of word classes */
450 		ADDRESS		*sv_addr;	/* pointer to address header */
451 		MAILER		*sv_mailer;	/* pointer to mailer */
452 		char		*sv_alias;	/* alias */
453 		MAPCLASS	sv_mapclass;	/* mapping function class */
454 		MAP		sv_map;		/* mapping function */
455 		char		*sv_hostsig;	/* host signature */
456 		MCI		sv_mci;		/* mailer connection info */
457 	}	s_value;
458 };
459 
460 typedef struct symtab	STAB;
461 
462 /* symbol types */
463 # define ST_UNDEF	0	/* undefined type */
464 # define ST_CLASS	1	/* class map */
465 # define ST_ADDRESS	2	/* an address in parsed format */
466 # define ST_MAILER	3	/* a mailer header */
467 # define ST_ALIAS	4	/* an alias */
468 # define ST_MAPCLASS	5	/* mapping function class */
469 # define ST_MAP		6	/* mapping function */
470 # define ST_HOSTSIG	7	/* host signature */
471 # define ST_MCI		16	/* mailer connection info (offset) */
472 
473 # define s_class	s_value.sv_class
474 # define s_address	s_value.sv_addr
475 # define s_mailer	s_value.sv_mailer
476 # define s_alias	s_value.sv_alias
477 # define s_mci		s_value.sv_mci
478 # define s_mapclass	s_value.sv_mapclass
479 # define s_hostsig	s_value.sv_hostsig
480 # define s_map		s_value.sv_map
481 
482 extern STAB	*stab();
483 
484 /* opcodes to stab */
485 # define ST_FIND	0	/* find entry */
486 # define ST_ENTER	1	/* enter if not there */
487 /*
488 **  STRUCT EVENT -- event queue.
489 **
490 **	Maintained in sorted order.
491 **
492 **	We store the pid of the process that set this event to insure
493 **	that when we fork we will not take events intended for the parent.
494 */
495 
496 struct event
497 {
498 	time_t		ev_time;	/* time of the function call */
499 	int		(*ev_func)();	/* function to call */
500 	int		ev_arg;		/* argument to ev_func */
501 	int		ev_pid;		/* pid that set this event */
502 	struct event	*ev_link;	/* link to next item */
503 };
504 
505 typedef struct event	EVENT;
506 
507 EXTERN EVENT	*EventQueue;		/* head of event queue */
508 /*
509 **  Operation, send, and error modes
510 **
511 **	The operation mode describes the basic operation of sendmail.
512 **	This can be set from the command line, and is "send mail" by
513 **	default.
514 **
515 **	The send mode tells how to send mail.  It can be set in the
516 **	configuration file.  It's setting determines how quickly the
517 **	mail will be delivered versus the load on your system.  If the
518 **	-v (verbose) flag is given, it will be forced to SM_DELIVER
519 **	mode.
520 **
521 **	The error mode tells how to return errors.
522 */
523 
524 EXTERN char	OpMode;		/* operation mode, see below */
525 
526 #define MD_DELIVER	'm'		/* be a mail sender */
527 #define MD_SMTP		's'		/* run SMTP on standard input */
528 #define MD_DAEMON	'd'		/* run as a daemon */
529 #define MD_VERIFY	'v'		/* verify: don't collect or deliver */
530 #define MD_TEST		't'		/* test mode: resolve addrs only */
531 #define MD_INITALIAS	'i'		/* initialize alias database */
532 #define MD_PRINT	'p'		/* print the queue */
533 #define MD_FREEZE	'z'		/* freeze the configuration file */
534 
535 
536 EXTERN char	SendMode;	/* send mode, see below */
537 
538 #define SM_DELIVER	'i'		/* interactive delivery */
539 #define SM_QUICKD	'j'		/* deliver w/o queueing */
540 #define SM_FORK		'b'		/* deliver in background */
541 #define SM_QUEUE	'q'		/* queue, don't deliver */
542 #define SM_VERIFY	'v'		/* verify only (used internally) */
543 
544 /* used only as a parameter to sendall */
545 #define SM_DEFAULT	'\0'		/* unspecified, use SendMode */
546 
547 
548 EXTERN char	ErrorMode;	/* error mode, see below */
549 
550 #define EM_PRINT	'p'		/* print errors */
551 #define EM_MAIL		'm'		/* mail back errors */
552 #define EM_WRITE	'w'		/* write back errors */
553 #define EM_BERKNET	'e'		/* special berknet processing */
554 #define EM_QUIET	'q'		/* don't print messages (stat only) */
555 
556 /* offset used to issure that the error messages for name server error
557  * codes are unique.
558  */
559 #define	MAX_ERRNO	100
560 /*
561 **  Global variables.
562 */
563 
564 EXTERN bool	FromFlag;	/* if set, "From" person is explicit */
565 EXTERN bool	NoAlias;	/* if set, don't do any aliasing */
566 EXTERN bool	ForceMail;	/* if set, mail even if already got a copy */
567 EXTERN bool	MeToo;		/* send to the sender also */
568 EXTERN bool	IgnrDot;	/* don't let dot end messages */
569 EXTERN bool	SaveFrom;	/* save leading "From" lines */
570 EXTERN bool	Verbose;	/* set if blow-by-blow desired */
571 EXTERN bool	GrabTo;		/* if set, get recipients from msg */
572 EXTERN bool	NoReturn;	/* don't return letter to sender */
573 EXTERN bool	SuprErrs;	/* set if we are suppressing errors */
574 EXTERN bool	QueueRun;	/* currently running message from the queue */
575 EXTERN bool	HoldErrs;	/* only output errors to transcript */
576 EXTERN bool	NoConnect;	/* don't connect to non-local mailers */
577 EXTERN bool	SuperSafe;	/* be extra careful, even if expensive */
578 EXTERN bool	ForkQueueRuns;	/* fork for each job when running the queue */
579 EXTERN bool	AutoRebuild;	/* auto-rebuild the alias database as needed */
580 EXTERN bool	CheckAliases;	/* parse addresses during newaliases */
581 EXTERN bool	UseNameServer;	/* use internet domain name server */
582 EXTERN bool	EightBit;	/* try to preserve 8-bit data */
583 EXTERN int	SafeAlias;	/* minutes to wait until @:@ in alias file */
584 EXTERN time_t	TimeOut;	/* time until timeout */
585 EXTERN FILE	*InChannel;	/* input connection */
586 EXTERN FILE	*OutChannel;	/* output connection */
587 EXTERN uid_t	RealUid;	/* when Daemon, real uid of caller */
588 EXTERN gid_t	RealGid;	/* when Daemon, real gid of caller */
589 EXTERN uid_t	DefUid;		/* default uid to run as */
590 EXTERN gid_t	DefGid;		/* default gid to run as */
591 EXTERN char	*DefUser;	/* default user to run as (from DefUid) */
592 EXTERN int	OldUmask;	/* umask when sendmail starts up */
593 EXTERN int	Errors;		/* set if errors (local to single pass) */
594 EXTERN int	ExitStat;	/* exit status code */
595 EXTERN int	AliasLevel;	/* depth of aliasing */
596 EXTERN int	MotherPid;	/* proc id of parent process */
597 EXTERN int	LineNumber;	/* line number in current input */
598 EXTERN time_t	ReadTimeout;	/* timeout on reads */
599 EXTERN int	LogLevel;	/* level of logging to perform */
600 EXTERN int	FileMode;	/* mode on files */
601 EXTERN int	QueueLA;	/* load average starting forced queueing */
602 EXTERN int	RefuseLA;	/* load average refusing connections are */
603 EXTERN int	CurrentLA;	/* current load average */
604 EXTERN long	QueueFactor;	/* slope of queue function */
605 EXTERN time_t	QueueIntvl;	/* intervals between running the queue */
606 EXTERN char	*AliasFile;	/* location of alias file */
607 EXTERN char	*HelpFile;	/* location of SMTP help file */
608 EXTERN char	*ErrMsgFile;	/* file to prepend to all error messages */
609 EXTERN char	*StatFile;	/* location of statistics summary */
610 EXTERN char	*QueueDir;	/* location of queue directory */
611 EXTERN char	*FileName;	/* name to print on error messages */
612 EXTERN char	*SmtpPhase;	/* current phase in SMTP processing */
613 EXTERN char	*MyHostName;	/* name of this host for SMTP messages */
614 EXTERN char	*RealHostName;	/* name of host we are talking to */
615 EXTERN struct	sockaddr_in RealHostAddr;/* address of host we are talking to */
616 EXTERN char	*CurHostName;	/* current host we are dealing with */
617 EXTERN jmp_buf	TopFrame;	/* branch-to-top-of-loop-on-error frame */
618 EXTERN bool	QuickAbort;	/*  .... but only if we want a quick abort */
619 EXTERN bool	LogUsrErrs;	/* syslog user errors (e.g., SMTP RCPT cmd) */
620 extern char	*ConfFile;	/* location of configuration file [conf.c] */
621 extern char	*FreezeFile;	/* location of frozen memory image [conf.c] */
622 extern char	Arpa_Info[];	/* the reply code for Arpanet info [conf.c] */
623 extern ADDRESS	NullAddress;	/* a null (template) address [main.c] */
624 EXTERN char	SpaceSub;	/* substitution for <lwsp> */
625 EXTERN long	WkClassFact;	/* multiplier for message class -> priority */
626 EXTERN long	WkRecipFact;	/* multiplier for # of recipients -> priority */
627 EXTERN long	WkTimeFact;	/* priority offset each time this job is run */
628 EXTERN char	*PostMasterCopy;	/* address to get errs cc's */
629 EXTERN char	*TrustedUsers[MAXTRUST+1];	/* list of trusted users */
630 EXTERN int	CheckpointInterval;	/* queue file checkpoint interval */
631 EXTERN char	*UdbSpec;	/* user database source spec [udbexpand.c] */
632 EXTERN int	MaxHopCount;	/* number of hops until we give an error */
633 EXTERN int	ConfigLevel;	/* config file level -- what does .cf expect? */
634 EXTERN char	*TimeZoneSpec;	/* override time zone specification */
635 EXTERN bool	MatchGecos;	/* look for user names in gecos field */
636 EXTERN int	MaxMciCache;	/* maximum entries in MCI cache */
637 EXTERN time_t	MciCacheTimeout;	/* maximum idle time on connections */
638 EXTERN char	*ForwardPath;	/* path to search for .forward files */
639 /*
640 **  Trace information
641 */
642 
643 /* trace vector and macros for debugging flags */
644 EXTERN u_char	tTdvect[100];
645 # define tTd(flag, level)	(tTdvect[flag] >= level)
646 # define tTdlevel(flag)		(tTdvect[flag])
647 /*
648 **  Miscellaneous information.
649 */
650 
651 
652 
653 /*
654 **  Some in-line functions
655 */
656 
657 /* set exit status */
658 #define setstat(s)	{ \
659 				if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \
660 					ExitStat = s; \
661 			}
662 
663 /* make a copy of a string */
664 #define newstr(s)	strcpy(xalloc(strlen(s) + 1), s)
665 
666 #define STRUCTCOPY(s, d)	d = s
667 
668 
669 /*
670 **  Declarations of useful functions
671 */
672 
673 extern ADDRESS	*parseaddr();
674 extern char	*xalloc();
675 extern bool	sameaddr();
676 extern FILE	*dfopen();
677 extern EVENT	*setevent();
678 extern char	*sfgets();
679 extern char	*queuename();
680 extern time_t	curtime();
681