change inheritance for macros in envelopes; be able to canonicalize
[unix-history] / usr / src / usr.sbin / sendmail / src / sendmail.h
CommitLineData
b3cbe40f 1/*
96faada8 2** SENDMAIL.H -- Global definitions for sendmail.
b3cbe40f
EA
3*/
4
5
6
327272f5
EA
7# ifdef _DEFINE
8# define EXTERN
4e5e456f 9# ifndef lint
857afefe 10static char SmailSccsId[] = "@(#)sendmail.h 3.87 %G%";
4e5e456f 11# endif lint
327272f5
EA
12# else _DEFINE
13# define EXTERN extern
14# endif _DEFINE
b3cbe40f 15
aeb209da
EA
16# include <stdio.h>
17# include <ctype.h>
37eaaadb 18# include <setjmp.h>
b5fd168f 19# include "conf.h"
cb590f52
EA
20# include "useful.h"
21
9678c96d
EA
22# ifdef LOG
23# include <syslog.h>
24# endif LOG
281f3387 25\f/*
4e1f4d4b
EA
26** Configuration constants.
27** There shouldn't be much need to change these....
b3cbe40f
EA
28*/
29
2b5e3c25
EA
30# define MAXLINE 256 /* max line length */
31# define MAXNAME 128 /* max length of a name */
32# define MAXFIELD 2500 /* max total length of a hdr field */
33# define MAXPV 40 /* max # of parms to mailers */
34# define MAXHOP 30 /* max value of HopCount */
281f3387 35# define MAXATOM 100 /* max atoms per address */
77680bb1 36# define MAXMAILERS 25 /* maximum mailers known to system */
792a6b53 37# define MAXRWSETS 30 /* max # of sets of rewriting rules */
2b5e3c25 38# define SPACESUB ('.'|0200) /* substitution for <lwsp> */
2654b031 39\f/*
9e3c0a28
EA
40** Address structure.
41** Addresses are stored internally in this structure.
abae7b2d
EA
42**
43** Each address is on two chains and in one tree.
44** The q_next chain is used to link together addresses
45** for one mailer (and is rooted in a mailer).
46** The q_chain chain is used to maintain a list of
47** addresses originating from one call to sendto, and
48** is used primarily for printing messages.
49** The q_alias, q_sibling, and q_child tree maintains
50** a complete tree of the aliases. q_alias points to
51** the parent -- obviously, there can be several, and
52** so this points to "one" of them. Ditto for q_sibling.
9e3c0a28
EA
53*/
54
55struct address
56{
57 char *q_paddr; /* the printname for the address */
58 char *q_user; /* user name */
59 char *q_host; /* host name */
179c1218 60 struct mailer *q_mailer; /* mailer to use */
b2e9d033 61 u_short q_flags; /* status flags, see below */
9c3f729b 62 short q_uid; /* user-id of receiver (if known) */
1bf7c76b 63 short q_gid; /* group-id of receiver (if known) */
4bb4503e 64 char *q_home; /* home dir (local mailer only) */
f77d50ee 65 char *q_fullname; /* full name if known */
abae7b2d 66 char *q_fullname; /* full name of this person */
ed45aae1 67 time_t q_timeout; /* timeout for this address */
abae7b2d
EA
68 struct address *q_next; /* chain */
69 struct address *q_alias; /* parent in alias tree */
70 struct address *q_sibling; /* sibling in alias tree */
71 struct address *q_child; /* child in alias tree */
9e3c0a28
EA
72};
73
74typedef struct address ADDRESS;
75
76# define QDONTSEND 000001 /* don't send to this address */
1ef61b9f 77# define QBADADDR 000002 /* this address is verified bad */
2c1457f0 78# define QGOODUID 000004 /* the q_uid q_gid fields are good */
92f12b98 79# define QPRIMARY 000010 /* set from argv */
ed45aae1 80# define QQUEUEUP 000020 /* queue for later transmission */
abae7b2d 81# define QPSEUDO 000040 /* only on the list for verification */
2654b031 82\f/*
b3cbe40f
EA
83** Mailer definition structure.
84** Every mailer known to the system is declared in this
85** structure. It defines the pathname of the mailer, some
86** flags associated with it, and the argument vector to
cb590f52 87** pass to it. The flags are defined in conf.c
b3cbe40f 88**
b8944683
EA
89** The argument vector is expanded before actual use. All
90** words except the first are passed through the macro
91** processor.
b3cbe40f
EA
92*/
93
94struct mailer
95{
d6a28dd8 96 char *m_name; /* symbolic name of this mailer */
9e3c0a28 97 char *m_mailer; /* pathname of the mailer to use */
b2e9d033 98 u_long m_flags; /* status flags, see below */
b3cbe40f 99 short m_badstat; /* the status code to use on unknown error */
b14547d5 100 short m_mno; /* mailer number internally */
6708a5e3 101 char **m_argv; /* template argument vector */
17232873
EA
102 short m_s_rwset; /* rewriting set for sender addresses */
103 short m_r_rwset; /* rewriting set for recipient addresses */
b3cbe40f
EA
104};
105
cdb17311
EA
106typedef struct mailer MAILER;
107
5fbf3fea 108/* bits for m_flags */
fae04b89
EA
109# define M_FOPT 000000001L /* mailer takes picky -f flag */
110# define M_ROPT 000000002L /* mailer takes picky -r flag */
111# define M_QUIET 000000004L /* don't print error on bad status */
112# define M_RESTR 000000010L /* must be daemon to execute */
113# define M_NHDR 000000020L /* don't insert From line */
114# define M_LOCAL 000000040L /* delivery is to this host */
115# define M_STRIPQ 000000100L /* strip quote chars from user/host */
116# define M_MUSER 000000200L /* can handle multiple users at once */
117# define M_NEEDFROM 000000400L /* need arpa-style From: line */
118# define M_NEEDDATE 000001000L /* need arpa-style Date: line */
119# define M_MSGID 000002000L /* need Message-Id: field */
857afefe 120# define M_CANONICAL 000004000L /* make addresses canonical "u@dom" */
fae04b89
EA
121# define M_USR_UPPER 000010000L /* preserve user case distinction */
122# define M_HST_UPPER 000020000L /* preserve host case distinction */
123# define M_FULLNAME 000040000L /* want Full-Name field */
124# define M_UGLYUUCP 000100000L /* this wants an ugly UUCP from line */
125# define M_EXPENSIVE 000200000L /* it costs to use this mailer.... */
21abecca 126# define M_FULLSMTP 000400000L /* must run full SMTP, inc. limits */
1a12c7d6 127
74c5fe7c 128# define M_ARPAFMT (M_NEEDDATE|M_NEEDFROM|M_MSGID)
b3cbe40f 129
179c1218 130EXTERN MAILER *Mailer[MAXMAILERS+1];
4bb4503e 131
179c1218
EA
132EXTERN MAILER *LocalMailer; /* ptr to local mailer */
133EXTERN MAILER *ProgMailer; /* ptr to program mailer */
2654b031 134\f/*
1a12c7d6
EA
135** Header structure.
136** This structure is used internally to store header items.
137*/
138
139struct header
140{
141 char *h_field; /* the name of the field */
142 char *h_value; /* the value of that field */
143 struct header *h_link; /* the next header */
b2e9d033
EA
144 u_short h_flags; /* status bits, see below */
145 u_long h_mflags; /* m_flags bits needed */
1a12c7d6
EA
146};
147
148typedef struct header HDR;
149
1a12c7d6
EA
150/*
151** Header information structure.
152** Defined in conf.c, this struct declares the header fields
153** that have some magic meaning.
154*/
155
156struct hdrinfo
157{
158 char *hi_field; /* the name of the field */
b2e9d033
EA
159 u_short hi_flags; /* status bits, see below */
160 u_short hi_mflags; /* m_flags needed for this field */
1a12c7d6
EA
161};
162
163extern struct hdrinfo HdrInfo[];
164
165/* bits for h_flags and hi_flags */
355a2a04 166# define H_EOH 00001 /* this field terminates header */
028b97f3 167# define H_RCPT 00002 /* contains recipient addresses */
1a12c7d6
EA
168# define H_DEFAULT 00004 /* if another value is found, drop this */
169# define H_USED 00010 /* indicates that this has been output */
2f0c5bd8 170# define H_CHECK 00020 /* check h_mflags against m_flags */
a9e0e597 171# define H_ACHECK 00040 /* ditto, but always (not just default) */
b2e9d033 172# define H_FORCE 00100 /* force this field, even if default */
17232873 173# define H_TRACE 00200 /* this field contains trace information */
91f868d8 174# define H_FROM 00400 /* this is a from-type field */
2654b031
EA
175\f/*
176** Envelope structure.
177** This structure defines the message itself. There is usually
178** only one of these -- for the message that we originally read
179** and which is our primary interest -- but other envelopes can
180** be generated during processing. For example, error messages
181** will have their own envelope.
182*/
1a12c7d6 183
2654b031
EA
184struct envelope
185{
dd1fe05b
EA
186 HDR *e_header; /* head of header list */
187 long e_msgpriority; /* adjusted priority of this message */
96476cab 188 time_t e_ctime; /* time message appeared in the queue */
dd1fe05b 189 bool e_queueup; /* queue this message */
96476cab 190 bool e_dontqueue; /* override queueing */
dd1fe05b 191 bool e_oldstyle; /* use spaces (not commas) in hdrs */
dd1fe05b 192 bool e_sendreceipt; /* actually send a receipt back */
dd1fe05b 193 char *e_to; /* the target person */
17232873 194 char *e_receiptto; /* return receipt address */
dd1fe05b 195 ADDRESS e_from; /* the person it is from */
857afefe 196 char **e_fromdomain; /* the domain part of the sender */
1bcdf0a2 197 ADDRESS *e_returnto; /* place to return the message to */
dd1fe05b 198 ADDRESS *e_sendqueue; /* list of message recipients */
3c7fe765 199 ADDRESS *e_errorqueue; /* the queue for error responses */
dd1fe05b
EA
200 long e_msgsize; /* size of the message in bytes */
201 short e_class; /* msg class (priority, junk, etc.) */
202 int (*e_puthdr)(); /* function to put header of message */
203 int (*e_putbody)(); /* function to put body of message */
204 struct envelope *e_parent; /* the message this one encloses */
205 char *e_df; /* location of temp file */
2cce0c26
EA
206 char *e_qf; /* queue control file */
207 char *e_id; /* code for this entry in queue */
dd1fe05b 208 char *e_macro[128]; /* macro definitions */
2654b031 209};
1a12c7d6 210
2654b031 211typedef struct envelope ENVELOPE;
ed45aae1 212
2654b031
EA
213EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */
214\f/*
ed45aae1
EA
215** Work queue.
216*/
217
218struct work
219{
220 char *w_name; /* name of control file */
9ccf54c4 221 long w_pri; /* priority of message, see below */
ed45aae1
EA
222 struct work *w_next; /* next in queue */
223};
224
225typedef struct work WORK;
226
227EXTERN WORK *WorkQ; /* queue of things to be done */
228
229
230/*
231** Message priorities.
aba51985 232** Priorities > 0 should be preemptive.
9ccf54c4 233**
2654b031 234** CurEnv->e_msgpriority is the number of bytes in the message adjusted
9ccf54c4
EA
235** by the message priority and the amount of time the message
236** has been sitting around. Each priority point is worth
237** WKPRIFACT bytes of message, and each time we reprocess a
238** message the size gets reduced by WKTIMEFACT.
df74deb0
EA
239**
240** The "class" is this number, unadjusted by the age or size of
241** this message. Classes with negative representations will have
242** error messages thrown away if they are not local.
ed45aae1
EA
243*/
244
df74deb0
EA
245# define PRI_ALERT 50
246# define PRI_QUICK 30
247# define PRI_FIRSTCL 10
9ccf54c4 248# define PRI_NORMAL 0
aba51985 249# define PRI_SECONDCL -10
df74deb0
EA
250# define PRI_THIRDCL -40
251# define PRI_JUNK -100
ed45aae1 252
9ccf54c4
EA
253# define WKPRIFACT 1800 /* bytes each pri point is worth */
254# define WKTIMEFACT 400 /* bytes each time unit is worth */
2654b031 255\f/*
d6a28dd8
EA
256** Rewrite rules.
257*/
258
259struct rewrite
260{
261 char **r_lhs; /* pattern match */
262 char **r_rhs; /* substitution value */
263 struct rewrite *r_next;/* next in chain */
264};
265
792a6b53 266EXTERN struct rewrite *RewriteRules[MAXRWSETS];
d6a28dd8 267
792a6b53
EA
268/*
269** Special characters in rewriting rules.
270** These are used internally only.
271** The COND* rules are actually used in macros rather than in
272** rewriting rules, but are given here because they
273** cannot conflict.
274*/
275
276/* left hand side items */
277# define MATCHZANY '\020' /* match zero or more tokens */
278# define MATCHANY '\021' /* match one or more tokens */
279# define MATCHONE '\022' /* match exactly one token */
280# define MATCHCLASS '\023' /* match one token in a class */
281# define MATCHREPL '\024' /* replacement on RHS for above */
d6a28dd8 282
792a6b53 283/* right hand side items */
d6a28dd8
EA
284# define CANONNET '\025' /* canonical net, next token */
285# define CANONHOST '\026' /* canonical host, next token */
286# define CANONUSER '\027' /* canonical user, next N tokens */
792a6b53 287# define CALLSUBR '\030' /* call another rewriting set */
d6a28dd8 288
792a6b53
EA
289/* conditionals in macros */
290# define CONDIF '\031' /* conditional if-then */
291# define CONDELSE '\032' /* conditional else */
292# define CONDFI '\033' /* conditional fi */
2654b031 293\f/*
4d3a97d9
EA
294** Symbol table definitions
295*/
296
297struct symtab
298{
299 char *s_name; /* name to be entered */
cdb17311 300 char s_type; /* general type (see below) */
4d3a97d9 301 struct symtab *s_next; /* pointer to next in chain */
cdb17311
EA
302 union
303 {
304 long sv_class; /* bit-map of word classes */
305 ADDRESS *sv_addr; /* pointer to address header */
306 MAILER *sv_mailer; /* pointer to mailer */
307 char *sv_alias; /* alias */
308 } s_value;
4d3a97d9
EA
309};
310
311typedef struct symtab STAB;
312
cdb17311
EA
313/* symbol types */
314# define ST_UNDEF 0 /* undefined type */
315# define ST_CLASS 1 /* class map */
316# define ST_ADDRESS 2 /* an address in parsed format */
317# define ST_MAILER 3 /* a mailer header */
318# define ST_ALIAS 4 /* an alias */
319
320# define s_class s_value.sv_class
14a39063 321# define s_address s_value.sv_addr
cdb17311
EA
322# define s_mailer s_value.sv_mailer
323# define s_alias s_value.sv_alias
324
4d3a97d9
EA
325extern STAB *stab();
326
327/* opcodes to stab */
328# define ST_FIND 0 /* find entry */
329# define ST_ENTER 1 /* enter if not there */
2654b031 330\f/*
2439b900
EA
331** STRUCT EVENT -- event queue.
332**
333** Maintained in sorted order.
f5d25d7b
EA
334**
335** We store the pid of the process that set this event to insure
336** that when we fork we will not take events intended for the parent.
2439b900
EA
337*/
338
339struct event
340{
341 time_t ev_time; /* time of the function call */
342 int (*ev_func)(); /* function to call */
343 int ev_arg; /* argument to ev_func */
f5d25d7b 344 int ev_pid; /* pid that set this event */
2439b900
EA
345 struct event *ev_link; /* link to next item */
346};
347
348typedef struct event EVENT;
349
350EXTERN EVENT *EventQueue; /* head of event queue */
351\f/*
4e1f4d4b
EA
352** Statistics structure.
353*/
354
355struct statistics
356{
357 time_t stat_itime; /* file initialization time */
358 short stat_size; /* size of this structure */
359 long stat_nf[MAXMAILERS]; /* # msgs from each mailer */
360 long stat_bf[MAXMAILERS]; /* kbytes from each mailer */
361 long stat_nt[MAXMAILERS]; /* # msgs to each mailer */
362 long stat_bt[MAXMAILERS]; /* kbytes to each mailer */
363};
364
327272f5 365EXTERN struct statistics Stat;
4e1f4d4b 366extern long kbytes(); /* for _bf, _bt */
2654b031 367\f/*
d0bd03ce
EA
368** Operation modes
369** The default operation mode can be safely changed (except
370** that the default cannot be MD_DAEMON).
371*/
372
373EXTERN char Mode; /* operation mode, see below */
374
375#define MD_DELIVER 'a' /* collect and deliver */
376#define MD_FORK 'f' /* verify & fork before delivery */
377#define MD_QUEUE 'q' /* collect & queue, don't deliver */
378#define MD_DAEMON 'd' /* run as a daemon */
379#define MD_VERIFY 'v' /* verify: don't collect or deliver */
380
381#define MD_DEFAULT MD_DELIVER /* default operation mode */
382\f/*
b3cbe40f
EA
383** Global variables.
384*/
385
327272f5
EA
386EXTERN bool FromFlag; /* if set, "From" person is explicit */
387EXTERN bool MailBack; /* mail back response on error */
388EXTERN bool BerkNet; /* called from BerkNet */
389EXTERN bool WriteBack; /* write back response on error */
390EXTERN bool NoAlias; /* if set, don't do any aliasing */
391EXTERN bool ForceMail; /* if set, mail even if already got a copy */
392EXTERN bool MeToo; /* send to the sender also */
393EXTERN bool IgnrDot; /* don't let dot end messages */
394EXTERN bool SaveFrom; /* save leading "From" lines */
395EXTERN bool Verbose; /* set if blow-by-blow desired */
396EXTERN bool GrabTo; /* if set, get recipients from msg */
397EXTERN bool DontSend; /* mark recipients as QDONTSEND */
398EXTERN bool NoReturn; /* don't return letter to sender */
cbdb7357
EA
399EXTERN bool Smtp; /* using SMTP over connection */
400EXTERN bool SuprErrs; /* set if we are suppressing errors */
1ea752a1 401EXTERN bool QueueRun; /* currently running message from the queue */
49086753
EA
402EXTERN bool HoldErrs; /* only output errors to transcript */
403EXTERN bool ArpaMode; /* set if running arpanet protocol */
3135d20c 404EXTERN bool NoConnect; /* don't connect to non-local mailers */
1ea752a1 405EXTERN bool FatalErrors; /* set if fatal errors during processing */
96476cab 406extern time_t TimeOut; /* time until timeout [conf.c] */
cbdb7357
EA
407EXTERN FILE *InChannel; /* input connection */
408EXTERN FILE *OutChannel; /* output connection */
409EXTERN FILE *TempFile; /* mail temp file */
49086753 410EXTERN FILE *Xscript; /* mail transcript file */
f6a0cc15
EA
411EXTERN int RealUid; /* when Daemon, real uid of caller */
412EXTERN int RealGid; /* when Daemon, real gid of caller */
96476cab
EA
413extern int DefUid; /* default uid to run as [conf.c] */
414extern int DefGid; /* default gid to run as [conf.c] */
327272f5 415EXTERN int OldUmask; /* umask when sendmail starts up */
1ea752a1 416EXTERN int Errors; /* set if errors (local to single pass) */
327272f5 417EXTERN int ExitStat; /* exit status code */
cbdb7357
EA
418EXTERN int HopCount; /* hop count */
419EXTERN int AliasLevel; /* depth of aliasing */
e673aad7 420EXTERN int MotherPid; /* proc id of parent process */
792a6b53 421EXTERN int LineNumber; /* line number in current input */
ed45aae1 422EXTERN time_t QueueIntvl; /* intervals between running the queue */
cbdb7357 423EXTERN char *HostName; /* name of this host for SMTP messages */
ed45aae1 424EXTERN char *Transcript; /* the transcript file name */
96476cab
EA
425extern char *XcriptFile; /* template for Transcript [conf.c] */
426extern char *AliasFile; /* location of alias file [conf.c] */
427extern char *ConfFile; /* location of configuration file [conf.c] */
428extern char *StatFile; /* location of statistics summary [conf.c] */
429extern char *QueueDir; /* location of queue directory [conf.c] */
430extern char Arpa_Info[]; /* the reply code for Arpanet info [conf.c] */
91f868d8
EA
431EXTERN jmp_buf TopFrame; /* branch-to-top-of-loop-on-error frame */
432EXTERN bool QuickAbort; /* .... but only if we want a quick abort */
96476cab
EA
433extern int ReadTimeout; /* timeout on reads [conf.c] */
434extern int LogLevel; /* level of logging to perform [conf.c] */
9678c96d
EA
435\f/*
436** Trace information
437*/
b3cbe40f 438
9678c96d
EA
439/* trace vector and macros for debugging flags */
440EXTERN u_char tTdvect[100];
441# define tTd(flag, level) (tTdvect[flag] >= level)
442# define tTdlevel(flag) (tTdvect[flag])
443\f/*
444** Miscellaneous information.
445*/
b3cbe40f
EA
446
447# include <sysexits.h>
448
b3cbe40f 449# define setstat(s) { if (ExitStat == EX_OK) ExitStat = s; }
29871fef
EA
450
451
452/* useful functions */
453
454extern char *newstr();
455extern ADDRESS *parse();
456extern char *xalloc();
29871fef 457extern bool sameaddr();
5c373723 458extern FILE *dfopen();
2439b900
EA
459extern EVENT *setevent();
460extern char *sfgets();
2cce0c26 461extern char *queuename();
88039044 462extern time_t curtime();