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