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