1 /*
2 **  SENDMAIL.H -- Global definitions for sendmail.
3 */
4 
5 
6 
7 # ifdef _DEFINE
8 # define EXTERN
9 static char SmailSccsId[] =	"@(#)sendmail.h	3.52.1.1	11/21/81";
10 # else  _DEFINE
11 # define EXTERN extern
12 # endif _DEFINE
13 
14 # ifndef major
15 # include <sys/types.h>
16 # endif major
17 # include <stdio.h>
18 # include <ctype.h>
19 # include "useful.h"
20 
21 /*
22 **  Configuration constants.
23 **	There shouldn't be much need to change these....
24 */
25 
26 # define MAXLINE	256		/* max line length */
27 # define MAXNAME	128		/* max length of a name */
28 # define MAXFIELD	2500		/* max total length of a hdr field */
29 # define MAXPV		40		/* max # of parms to mailers */
30 # define MAXHOP		30		/* max value of HopCount */
31 # define MAXATOM	30		/* max atoms per address */
32 # define MAXMAILERS	10		/* maximum mailers known to system */
33 # define SPACESUB	('.'|0200)	/* substitution for <lwsp> */
34 
35 extern char	Arpa_Info[];	/* the message number for Arpanet info */
36 
37 
38 
39 
40 
41 
42 /*
43 **  Address structure.
44 **	Addresses are stored internally in this structure.
45 **
46 **	Each address is on two chains and in one tree.
47 **		The q_next chain is used to link together addresses
48 **		  for one mailer (and is rooted in a mailer).
49 **		The q_chain chain is used to maintain a list of
50 **		  addresses originating from one call to sendto, and
51 **		  is used primarily for printing messages.
52 **		The q_alias, q_sibling, and q_child tree maintains
53 **		  a complete tree of the aliases.  q_alias points to
54 **		  the parent -- obviously, there can be several, and
55 **		  so this points to "one" of them.  Ditto for q_sibling.
56 */
57 
58 struct address
59 {
60 	char		*q_paddr;	/* the printname for the address */
61 	char		*q_user;	/* user name */
62 	char		*q_host;	/* host name */
63 	struct mailer	*q_mailer;	/* mailer to use */
64 	short		q_rmailer;	/* real mailer (before mapping) */
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 of this person */
70 	time_t		q_timeout;	/* timeout for this address */
71 	struct address	*q_next;	/* chain */
72 	struct address	*q_alias;	/* parent in alias tree */
73 	struct address	*q_sibling;	/* sibling in alias tree */
74 	struct address	*q_child;	/* child in alias tree */
75 };
76 
77 typedef struct address ADDRESS;
78 
79 # define QDONTSEND	000001	/* don't send to this address */
80 # define QBADADDR	000002	/* this address is verified bad */
81 # define QGOODUID	000004	/* the q_uid q_gid fields are good */
82 # define QPRIMARY	000010	/* set from argv */
83 # define QQUEUEUP	000020	/* queue for later transmission */
84 # define QPSEUDO	000040	/* only on the list for verification */
85 
86 
87 
88 
89 
90 /*
91 **  Mailer definition structure.
92 **	Every mailer known to the system is declared in this
93 **	structure.  It defines the pathname of the mailer, some
94 **	flags associated with it, and the argument vector to
95 **	pass to it.  The flags are defined in conf.c
96 **
97 **	The host map is a list of lists of strings.  Within each
98 **	list, any host is mapped to the last host in the list.
99 **	This allows multiple names, as well as doing clever
100 **	mail grouping in point-to-point networks.  Note: this
101 **	is only used internally, so the apparent host is still
102 **	kept around.
103 **
104 **	The argument vector is expanded before actual use.  All
105 **	words except the first are passed through the macro
106 **	processor.
107 */
108 
109 struct mailer
110 {
111 	char	*m_name;	/* symbolic name of this mailer */
112 	char	*m_mailer;	/* pathname of the mailer to use */
113 	u_long	m_flags;	/* status flags, see below */
114 	short	m_badstat;	/* the status code to use on unknown error */
115 	short	m_mno;		/* mailer number internally */
116 	char	*m_from;	/* pattern for From: header */
117 	char	**m_argv;	/* template argument vector */
118 	ADDRESS	*m_sendq;	/* list of addresses to send to */
119 };
120 
121 typedef struct mailer	MAILER;
122 
123 # define M_FOPT		000001	/* mailer takes picky -f flag */
124 # define M_ROPT		000002	/* mailer takes picky -r flag */
125 # define M_QUIET	000004	/* don't print error on bad status */
126 # define M_RESTR	000010	/* must be daemon to execute */
127 # define M_NHDR		000020	/* don't insert From line */
128 # define M_LOCAL	000040	/* delivery is to this host */
129 # define M_STRIPQ	000100	/* strip quote characters from user/host */
130 # define M_MUSER	000200	/* mailer can handle multiple users at once */
131 # define M_NEEDFROM	000400	/* need arpa-style From: line */
132 # define M_NEEDDATE	001000	/* need arpa-style Date: line */
133 # define M_MSGID	002000	/* need Message-Id: field */
134 # define M_USR_UPPER	010000	/* preserve user case distinction */
135 # define M_HST_UPPER	020000	/* preserve host case distinction */
136 # define M_FULLNAME	040000	/* want Full-Name field */
137 
138 # define M_ARPAFMT	(M_NEEDDATE|M_NEEDFROM|M_MSGID)
139 
140 EXTERN MAILER	*Mailer[MAXMAILERS+1];
141 
142 EXTERN MAILER	*LocalMailer;		/* ptr to local mailer */
143 EXTERN MAILER	*ProgMailer;		/* ptr to program mailer */
144 
145 
146 /*
147 **  Header structure.
148 **	This structure is used internally to store header items.
149 */
150 
151 struct header
152 {
153 	char		*h_field;	/* the name of the field */
154 	char		*h_value;	/* the value of that field */
155 	struct header	*h_link;	/* the next header */
156 	u_short		h_flags;	/* status bits, see below */
157 	u_long		h_mflags;	/* m_flags bits needed */
158 };
159 
160 typedef struct header	HDR;
161 
162 EXTERN HDR	*Header;	/* head of header list */
163 
164 /*
165 **  Header information structure.
166 **	Defined in conf.c, this struct declares the header fields
167 **	that have some magic meaning.
168 */
169 
170 struct hdrinfo
171 {
172 	char	*hi_field;	/* the name of the field */
173 	u_short	hi_flags;	/* status bits, see below */
174 	u_short	hi_mflags;	/* m_flags needed for this field */
175 };
176 
177 extern struct hdrinfo	HdrInfo[];
178 
179 /* bits for h_flags and hi_flags */
180 # define H_EOH		00001	/* this field terminates header */
181 # define H_DEFAULT	00004	/* if another value is found, drop this */
182 # define H_USED		00010	/* indicates that this has been output */
183 # define H_CHECK	00020	/* check h_mflags against m_flags */
184 # define H_ACHECK	00040	/* ditto, but always (not just default) */
185 # define H_FORCE	00100	/* force this field, even if default */
186 # define H_ADDR		00200	/* this field contains addresses */
187 
188 
189 
190 /*
191 **  Work queue.
192 */
193 
194 struct work
195 {
196 	char		*w_name;	/* name of control file */
197 	short		w_pri;		/* priority of message, see below */
198 	long		w_size;		/* length of data file */
199 	struct work	*w_next;	/* next in queue */
200 };
201 
202 typedef struct work	WORK;
203 
204 EXTERN WORK	*WorkQ;			/* queue of things to be done */
205 
206 
207 /*
208 **  Message priorities.
209 **	Priorities > 0 should be preemptive.
210 */
211 
212 # define PRI_ALERT	20
213 # define PRI_QUICK	10
214 # define PRI_FIRSTCL	0
215 # define PRI_NORMAL	-4
216 # define PRI_SECONDCL	-10
217 # define PRI_THIRDCL	-20
218 
219 EXTERN int	MsgPriority;		/* priority of this message */
220 
221 
222 
223 /*
224 **  Rewrite rules.
225 */
226 
227 struct rewrite
228 {
229 	char	**r_lhs;	/* pattern match */
230 	char	**r_rhs;	/* substitution value */
231 	struct rewrite	*r_next;/* next in chain */
232 };
233 
234 extern struct rewrite	*RewriteRules[];
235 
236 # define MATCHANY	'\020'	/* match one or more tokens */
237 # define MATCHONE	'\021'	/* match exactly one token */
238 # define MATCHCLASS	'\022'	/* match one token in a class */
239 # define MATCHREPL	'\023'	/* replacement on RHS for above */
240 
241 # define CANONNET	'\025'	/* canonical net, next token */
242 # define CANONHOST	'\026'	/* canonical host, next token */
243 # define CANONUSER	'\027'	/* canonical user, next N tokens */
244 
245 
246 
247 /*
248 **  Symbol table definitions
249 */
250 
251 struct symtab
252 {
253 	char		*s_name;	/* name to be entered */
254 	char		s_type;		/* general type (see below) */
255 	struct symtab	*s_next;	/* pointer to next in chain */
256 	union
257 	{
258 		long	sv_class;	/* bit-map of word classes */
259 		ADDRESS	*sv_addr;	/* pointer to address header */
260 		MAILER	*sv_mailer;	/* pointer to mailer */
261 		char	*sv_alias;	/* alias */
262 	}	s_value;
263 };
264 
265 typedef struct symtab	STAB;
266 
267 /* symbol types */
268 # define ST_UNDEF	0	/* undefined type */
269 # define ST_CLASS	1	/* class map */
270 # define ST_ADDRESS	2	/* an address in parsed format */
271 # define ST_MAILER	3	/* a mailer header */
272 # define ST_ALIAS	4	/* an alias */
273 
274 # define s_class	s_value.sv_class
275 # define s_addr		s_value.sv_addr
276 # define s_mailer	s_value.sv_mailer
277 # define s_alias	s_value.sv_alias
278 
279 extern STAB	*stab();
280 
281 /* opcodes to stab */
282 # define ST_FIND	0	/* find entry */
283 # define ST_ENTER	1	/* enter if not there */
284 
285 
286 
287 
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 
306 
307 
308 /*
309 **  Global variables.
310 */
311 
312 EXTERN bool	FromFlag;	/* if set, "From" person is explicit */
313 EXTERN bool	MailBack;	/* mail back response on error */
314 EXTERN bool	BerkNet;	/* called from BerkNet */
315 EXTERN bool	WriteBack;	/* write back response on error */
316 EXTERN bool	NoAlias;	/* if set, don't do any aliasing */
317 EXTERN bool	ForceMail;	/* if set, mail even if already got a copy */
318 EXTERN bool	MeToo;		/* send to the sender also */
319 EXTERN bool	IgnrDot;	/* don't let dot end messages */
320 EXTERN bool	SaveFrom;	/* save leading "From" lines */
321 EXTERN bool	Verbose;	/* set if blow-by-blow desired */
322 EXTERN bool	GrabTo;		/* if set, get recipients from msg */
323 EXTERN bool	DontSend;	/* mark recipients as QDONTSEND */
324 EXTERN bool	NoReturn;	/* don't return letter to sender */
325 EXTERN bool	Daemon;		/* running as a daemon */
326 EXTERN bool	Smtp;		/* using SMTP over connection */
327 EXTERN bool	SuprErrs;	/* set if we are suppressing errors */
328 EXTERN bool	QueueUp;	/* queue this message for future xmission */
329 EXTERN bool	QueueRun;	/* currently running something from the queue */
330 EXTERN bool	HoldErrs;	/* only output errors to transcript */
331 EXTERN bool	ArpaMode;	/* set if running arpanet protocol */
332 extern time_t	TimeOut;	/* time until timeout */
333 EXTERN FILE	*InChannel;	/* input connection */
334 EXTERN FILE	*OutChannel;	/* output connection */
335 EXTERN FILE	*TempFile;	/* mail temp file */
336 EXTERN FILE	*Xscript;	/* mail transcript file */
337 EXTERN int	RealUid;	/* when Daemon, real uid of caller */
338 EXTERN int	RealGid;	/* when Daemon, real gid of caller */
339 EXTERN int	OldUmask;	/* umask when sendmail starts up */
340 EXTERN int	Debug;		/* debugging level */
341 EXTERN int	Errors;		/* set if errors */
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	*OrigFrom;	/* the From: line read from the message */
347 EXTERN char	*To;		/* the target person */
348 EXTERN char	*HostName;	/* name of this host for SMTP messages */
349 EXTERN char	*InFileName;	/* input file name */
350 EXTERN char	*Transcript;	/* the transcript file name */
351 extern char	*XcriptFile;	/* template for Transcript */
352 extern char	*AliasFile;	/* location of alias file */
353 extern char	*ConfFile;	/* location of configuration file */
354 extern char	*StatFile;	/* location of statistics summary */
355 extern char	*QueueDir;	/* location of queue directory */
356 EXTERN ADDRESS	From;		/* the person it is from */
357 EXTERN long	MsgSize;	/* size of the message in bytes */
358 EXTERN time_t	CurTime;	/* time of this message */
359 
360 
361 # include	<sysexits.h>
362 
363 # define setstat(s)		{ if (ExitStat == EX_OK) ExitStat = s; }
364 
365 
366 /* useful functions */
367 
368 extern char	*newstr();
369 extern ADDRESS	*parse();
370 extern char	*xalloc();
371 extern char	*expand();
372 extern bool	sameaddr();
373