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.66		05/20/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 "useful.h"
19 
20 /*
21 **  Configuration constants.
22 **	There shouldn't be much need to change these....
23 */
24 
25 # define MAXLINE	256		/* max line length */
26 # define MAXNAME	128		/* max length of a name */
27 # define MAXFIELD	2500		/* max total length of a hdr field */
28 # define MAXPV		40		/* max # of parms to mailers */
29 # define MAXHOP		30		/* max value of HopCount */
30 # define MAXATOM	30		/* max atoms per address */
31 # define MAXMAILERS	10		/* maximum mailers known to system */
32 # define SPACESUB	('.'|0200)	/* substitution for <lwsp> */
33 
34 extern char	Arpa_Info[];	/* the message number for Arpanet info */
35 
36 
37 
38 
39 
40 
41 /*
42 **  Address structure.
43 **	Addresses are stored internally in this structure.
44 */
45 
46 struct address
47 {
48 	char		*q_paddr;	/* the printname for the address */
49 	char		*q_user;	/* user name */
50 	char		*q_host;	/* host name */
51 	struct mailer	*q_mailer;	/* mailer to use */
52 	short		q_rmailer;	/* real mailer (before mapping) */
53 	u_short		q_flags;	/* status flags, see below */
54 	short		q_uid;		/* user-id of receiver (if known) */
55 	short		q_gid;		/* group-id of receiver (if known) */
56 	char		*q_home;	/* home dir (local mailer only) */
57 	char		*q_fullname;	/* full name if known */
58 	struct address	*q_next;	/* chain */
59 	struct address	*q_alias;	/* address this results from */
60 	struct address	*q_tchain;	/* temporary use chain */
61 	time_t		q_timeout;	/* timeout for this address */
62 };
63 
64 typedef struct address ADDRESS;
65 
66 # define QDONTSEND	000001	/* don't send to this address */
67 # define QBADADDR	000002	/* this address is verified bad */
68 # define QGOODUID	000004	/* the q_uid q_gid fields are good */
69 # define QPRIMARY	000010	/* set from argv */
70 # define QQUEUEUP	000020	/* queue for later transmission */
71 
72 
73 
74 
75 
76 /*
77 **  Mailer definition structure.
78 **	Every mailer known to the system is declared in this
79 **	structure.  It defines the pathname of the mailer, some
80 **	flags associated with it, and the argument vector to
81 **	pass to it.  The flags are defined in conf.c
82 **
83 **	The argument vector is expanded before actual use.  All
84 **	words except the first are passed through the macro
85 **	processor.
86 */
87 
88 struct mailer
89 {
90 	char	*m_name;	/* symbolic name of this mailer */
91 	char	*m_mailer;	/* pathname of the mailer to use */
92 	u_long	m_flags;	/* status flags, see below */
93 	short	m_badstat;	/* the status code to use on unknown error */
94 	short	m_mno;		/* mailer number internally */
95 	char	*m_from;	/* pattern for From: header */
96 	char	**m_argv;	/* template argument vector */
97 };
98 
99 typedef struct mailer	MAILER;
100 
101 /* bits for m_flags */
102 # define M_FOPT		000000001L	/* mailer takes picky -f flag */
103 # define M_ROPT		000000002L	/* mailer takes picky -r flag */
104 # define M_QUIET	000000004L	/* don't print error on bad status */
105 # define M_RESTR	000000010L	/* must be daemon to execute */
106 # define M_NHDR		000000020L	/* don't insert From line */
107 # define M_LOCAL	000000040L	/* delivery is to this host */
108 # define M_STRIPQ	000000100L	/* strip quote chars from user/host */
109 # define M_MUSER	000000200L	/* can handle multiple users at once */
110 # define M_NEEDFROM	000000400L	/* need arpa-style From: line */
111 # define M_NEEDDATE	000001000L	/* need arpa-style Date: line */
112 # define M_MSGID	000002000L	/* need Message-Id: field */
113 # define M_RELRCPT	000004000L	/* make recipient addresses relative */
114 # define M_USR_UPPER	000010000L	/* preserve user case distinction */
115 # define M_HST_UPPER	000020000L	/* preserve host case distinction */
116 # define M_FULLNAME	000040000L	/* want Full-Name field */
117 # define M_UGLYUUCP	000100000L	/* this wants an ugly UUCP from line */
118 # define M_EXPENSIVE	000200000L	/* it costs to use this mailer.... */
119 
120 # define M_ARPAFMT	(M_NEEDDATE|M_NEEDFROM|M_MSGID)
121 
122 EXTERN MAILER	*Mailer[MAXMAILERS+1];
123 
124 EXTERN MAILER	*LocalMailer;		/* ptr to local mailer */
125 EXTERN MAILER	*ProgMailer;		/* ptr to program mailer */
126 
127 
128 /*
129 **  Header structure.
130 **	This structure is used internally to store header items.
131 */
132 
133 struct header
134 {
135 	char		*h_field;	/* the name of the field */
136 	char		*h_value;	/* the value of that field */
137 	struct header	*h_link;	/* the next header */
138 	u_short		h_flags;	/* status bits, see below */
139 	u_long		h_mflags;	/* m_flags bits needed */
140 };
141 
142 typedef struct header	HDR;
143 
144 EXTERN HDR	*Header;	/* head of header list */
145 
146 /*
147 **  Header information structure.
148 **	Defined in conf.c, this struct declares the header fields
149 **	that have some magic meaning.
150 */
151 
152 struct hdrinfo
153 {
154 	char	*hi_field;	/* the name of the field */
155 	u_short	hi_flags;	/* status bits, see below */
156 	u_short	hi_mflags;	/* m_flags needed for this field */
157 };
158 
159 extern struct hdrinfo	HdrInfo[];
160 
161 /* bits for h_flags and hi_flags */
162 # define H_EOH		00001	/* this field terminates header */
163 # define H_RCPT		00002	/* contains recipient addresses */
164 # define H_DEFAULT	00004	/* if another value is found, drop this */
165 # define H_USED		00010	/* indicates that this has been output */
166 # define H_CHECK	00020	/* check h_mflags against m_flags */
167 # define H_ACHECK	00040	/* ditto, but always (not just default) */
168 # define H_FORCE	00100	/* force this field, even if default */
169 # define H_ADDR		00200	/* this field contains addresses */
170 
171 
172 
173 /*
174 **  Work queue.
175 */
176 
177 struct work
178 {
179 	char		*w_name;	/* name of control file */
180 	long		w_pri;		/* priority of message, see below */
181 	struct work	*w_next;	/* next in queue */
182 };
183 
184 typedef struct work	WORK;
185 
186 EXTERN WORK	*WorkQ;			/* queue of things to be done */
187 
188 
189 /*
190 **  Message priorities.
191 **	Priorities > 0 should be preemptive.
192 **
193 **	MsgPriority is the number of bytes in the message adjusted
194 **	by the message priority and the amount of time the message
195 **	has been sitting around.  Each priority point is worth
196 **	WKPRIFACT bytes of message, and each time we reprocess a
197 **	message the size gets reduced by WKTIMEFACT.
198 */
199 
200 # define PRI_ALERT	20
201 # define PRI_QUICK	10
202 # define PRI_FIRSTCL	3
203 # define PRI_NORMAL	0
204 # define PRI_SECONDCL	-10
205 # define PRI_THIRDCL	-20
206 
207 # define WKPRIFACT	1800		/* bytes each pri point is worth */
208 # define WKTIMEFACT	400		/* bytes each time unit is worth */
209 
210 EXTERN long	MsgPriority;		/* adjusted priority of this message */
211 
212 
213 
214 /*
215 **  Rewrite rules.
216 */
217 
218 struct rewrite
219 {
220 	char	**r_lhs;	/* pattern match */
221 	char	**r_rhs;	/* substitution value */
222 	struct rewrite	*r_next;/* next in chain */
223 };
224 
225 extern struct rewrite	*RewriteRules[];
226 
227 # define MATCHANY	'\020'	/* match one or more tokens */
228 # define MATCHONE	'\021'	/* match exactly one token */
229 # define MATCHCLASS	'\022'	/* match one token in a class */
230 # define MATCHREPL	'\023'	/* replacement on RHS for above */
231 
232 # define CANONNET	'\025'	/* canonical net, next token */
233 # define CANONHOST	'\026'	/* canonical host, next token */
234 # define CANONUSER	'\027'	/* canonical user, next N tokens */
235 
236 # define CONDIF		'\030'	/* conditional if-then */
237 # define CONDELSE	'\031'	/* conditional else */
238 # define CONDFI		'\032'	/* conditional fi */
239 
240 
241 
242 /*
243 **  Symbol table definitions
244 */
245 
246 struct symtab
247 {
248 	char		*s_name;	/* name to be entered */
249 	char		s_type;		/* general type (see below) */
250 	struct symtab	*s_next;	/* pointer to next in chain */
251 	union
252 	{
253 		long	sv_class;	/* bit-map of word classes */
254 		ADDRESS	*sv_addr;	/* pointer to address header */
255 		MAILER	*sv_mailer;	/* pointer to mailer */
256 		char	*sv_alias;	/* alias */
257 	}	s_value;
258 };
259 
260 typedef struct symtab	STAB;
261 
262 /* symbol types */
263 # define ST_UNDEF	0	/* undefined type */
264 # define ST_CLASS	1	/* class map */
265 # define ST_ADDRESS	2	/* an address in parsed format */
266 # define ST_MAILER	3	/* a mailer header */
267 # define ST_ALIAS	4	/* an alias */
268 
269 # define s_class	s_value.sv_class
270 # define s_address	s_value.sv_addr
271 # define s_mailer	s_value.sv_mailer
272 # define s_alias	s_value.sv_alias
273 
274 extern STAB	*stab();
275 
276 /* opcodes to stab */
277 # define ST_FIND	0	/* find entry */
278 # define ST_ENTER	1	/* enter if not there */
279 
280 
281 
282 
283 /*
284 **  Statistics structure.
285 */
286 
287 struct statistics
288 {
289 	time_t	stat_itime;		/* file initialization time */
290 	short	stat_size;		/* size of this structure */
291 	long	stat_nf[MAXMAILERS];	/* # msgs from each mailer */
292 	long	stat_bf[MAXMAILERS];	/* kbytes from each mailer */
293 	long	stat_nt[MAXMAILERS];	/* # msgs to each mailer */
294 	long	stat_bt[MAXMAILERS];	/* kbytes to each mailer */
295 };
296 
297 EXTERN struct statistics	Stat;
298 extern long			kbytes();	/* for _bf, _bt */
299 
300 
301 
302 
303 /*
304 **  Global variables.
305 */
306 
307 EXTERN bool	FromFlag;	/* if set, "From" person is explicit */
308 EXTERN bool	MailBack;	/* mail back response on error */
309 EXTERN bool	BerkNet;	/* called from BerkNet */
310 EXTERN bool	WriteBack;	/* write back response on error */
311 EXTERN bool	NoAlias;	/* if set, don't do any aliasing */
312 EXTERN bool	ForceMail;	/* if set, mail even if already got a copy */
313 EXTERN bool	MeToo;		/* send to the sender also */
314 EXTERN bool	IgnrDot;	/* don't let dot end messages */
315 EXTERN bool	SaveFrom;	/* save leading "From" lines */
316 EXTERN bool	Verbose;	/* set if blow-by-blow desired */
317 EXTERN bool	GrabTo;		/* if set, get recipients from msg */
318 EXTERN bool	DontSend;	/* mark recipients as QDONTSEND */
319 EXTERN bool	NoReturn;	/* don't return letter to sender */
320 EXTERN bool	Daemon;		/* running as a daemon */
321 EXTERN bool	Smtp;		/* using SMTP over connection */
322 EXTERN bool	SuprErrs;	/* set if we are suppressing errors */
323 EXTERN bool	QueueUp;	/* queue this message for future xmission */
324 EXTERN bool	QueueRun;	/* currently running message from the queue */
325 EXTERN bool	HoldErrs;	/* only output errors to transcript */
326 EXTERN bool	ArpaMode;	/* set if running arpanet protocol */
327 EXTERN bool	ForkOff;	/* fork after initial verification */
328 EXTERN bool	OldStyle;	/* spaces (not commas) delimit addresses */
329 EXTERN bool	NoConnect;	/* don't connect to non-local mailers */
330 EXTERN bool	RetReceipt;	/* give a return receipt if delivery occurs */
331 EXTERN bool	SendReceipt;	/* actually send a receipt back */
332 EXTERN bool	FatalErrors;	/* set if fatal errors during processing */
333 extern time_t	TimeOut;	/* time until timeout */
334 EXTERN FILE	*InChannel;	/* input connection */
335 EXTERN FILE	*OutChannel;	/* output connection */
336 EXTERN FILE	*TempFile;	/* mail temp file */
337 EXTERN FILE	*Xscript;	/* mail transcript file */
338 EXTERN int	RealUid;	/* when Daemon, real uid of caller */
339 EXTERN int	RealGid;	/* when Daemon, real gid of caller */
340 extern int	DefUid;		/* default uid to run as */
341 extern int	DefGid;		/* default gid to run as */
342 EXTERN int	OldUmask;	/* umask when sendmail starts up */
343 EXTERN int	Debug;		/* debugging level */
344 EXTERN int	Errors;		/* set if errors (local to single pass) */
345 EXTERN int	ExitStat;	/* exit status code */
346 EXTERN int	HopCount;	/* hop count */
347 EXTERN int	AliasLevel;	/* depth of aliasing */
348 EXTERN time_t	QueueIntvl;	/* intervals between running the queue */
349 EXTERN char	*OrigFrom;	/* the From: line read from the message */
350 EXTERN char	*To;		/* the target person */
351 EXTERN char	*HostName;	/* name of this host for SMTP messages */
352 EXTERN char	*InFileName;	/* input file name */
353 EXTERN char	*Transcript;	/* the transcript file name */
354 extern char	*XcriptFile;	/* template for Transcript */
355 extern char	*AliasFile;	/* location of alias file */
356 extern char	*ConfFile;	/* location of configuration file */
357 extern char	*StatFile;	/* location of statistics summary */
358 extern char	*QueueDir;	/* location of queue directory */
359 EXTERN ADDRESS	From;		/* the person it is from */
360 EXTERN ADDRESS	*SendQueue;	/* list of message recipients */
361 EXTERN long	MsgSize;	/* size of the message in bytes */
362 EXTERN time_t	CurTime;	/* time of this message */
363 
364 
365 # include	<sysexits.h>
366 
367 # define setstat(s)		{ if (ExitStat == EX_OK) ExitStat = s; }
368 
369 
370 /* useful functions */
371 
372 extern char	*newstr();
373 extern ADDRESS	*parse();
374 extern char	*xalloc();
375 extern char	*expand();
376 extern bool	sameaddr();
377 extern FILE	*dfopen();
378