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