add M_ESMTP
[unix-history] / usr / src / usr.sbin / sendmail / src / sendmail.h
CommitLineData
aeb2545d 1/*
dc45ba8c 2 * Copyright (c) 1983 Eric P. Allman
bee79b64
KB
3 * Copyright (c) 1988 Regents of the University of California.
4 * All rights reserved.
5 *
417f7a11 6 * %sccs.include.redist.c%
bee79b64 7 *
4f163ea3 8 * @(#)sendmail.h 6.51 (Berkeley) %G%
bee79b64 9 */
aeb2545d 10
b3cbe40f 11/*
96faada8 12** SENDMAIL.H -- Global definitions for sendmail.
b3cbe40f
EA
13*/
14
327272f5
EA
15# ifdef _DEFINE
16# define EXTERN
4e5e456f 17# ifndef lint
4f163ea3 18static char SmailSccsId[] = "@(#)sendmail.h 6.51 %G%";
6353954f 19# endif
f3d8f6d6 20# else /* _DEFINE */
327272f5 21# define EXTERN extern
f3d8f6d6 22# endif /* _DEFINE */
b3cbe40f 23
9dfbef75 24# include <unistd.h>
f3d8f6d6
EA
25# include <stddef.h>
26# include <stdlib.h>
aeb209da
EA
27# include <stdio.h>
28# include <ctype.h>
37eaaadb 29# include <setjmp.h>
e234fcd9 30# include <sysexits.h>
f3d8f6d6
EA
31# include <string.h>
32# include <time.h>
33# include <errno.h>
34
b5fd168f 35# include "conf.h"
6bf17095 36# include "conf.h"
cb590f52
EA
37# include "useful.h"
38
9678c96d 39# ifdef LOG
5031c0bb 40# include <syslog.h>
f3d8f6d6 41# endif /* LOG */
6e8a8adf 42
2e3062fe 43# ifdef DAEMON
2e3062fe 44# include <sys/socket.h>
3356c77c
EA
45# endif
46# ifdef NETINET
2e3062fe 47# include <netinet/in.h>
3356c77c
EA
48# endif
49# ifdef NETISO
50# include <netiso/iso.h>
51# endif
88e65f7c
EA
52# ifdef NETNS
53# include <netns/ns.h>
54# endif
55# ifdef NETX25
56# include <netccitt/x25.h>
57# endif
2e3062fe 58
6e8a8adf 59
a584db60
EA
60
61
6e8a8adf
EA
62/*
63** Data structure for bit maps.
64**
65** Each bit in this map can be referenced by an ascii character.
66** This is 128 possible bits, or 12 8-bit bytes.
67*/
68
69#define BITMAPBYTES 16 /* number of bytes in a bit map */
70#define BYTEBITS 8 /* number of bits in a byte */
71
72/* internal macros */
73#define _BITWORD(bit) (bit / (BYTEBITS * sizeof (int)))
74#define _BITBIT(bit) (1 << (bit % (BYTEBITS * sizeof (int))))
75
76typedef int BITMAP[BITMAPBYTES / sizeof (int)];
77
78/* test bit number N */
79#define bitnset(bit, map) ((map)[_BITWORD(bit)] & _BITBIT(bit))
80
81/* set bit number N */
82#define setbitn(bit, map) (map)[_BITWORD(bit)] |= _BITBIT(bit)
83
84/* clear bit number N */
85#define clrbitn(bit, map) (map)[_BITWORD(bit)] &= ~_BITBIT(bit)
86
87/* clear an entire bit map */
cca7676f 88#define clrbitmap(map) bzero((char *) map, BITMAPBYTES)
281f3387 89\f/*
9e3c0a28
EA
90** Address structure.
91** Addresses are stored internally in this structure.
abae7b2d
EA
92**
93** Each address is on two chains and in one tree.
94** The q_next chain is used to link together addresses
95** for one mailer (and is rooted in a mailer).
96** The q_chain chain is used to maintain a list of
97** addresses originating from one call to sendto, and
98** is used primarily for printing messages.
99** The q_alias, q_sibling, and q_child tree maintains
100** a complete tree of the aliases. q_alias points to
101** the parent -- obviously, there can be several, and
102** so this points to "one" of them. Ditto for q_sibling.
9e3c0a28
EA
103*/
104
105struct address
106{
107 char *q_paddr; /* the printname for the address */
108 char *q_user; /* user name */
3fbc69d6 109 char *q_ruser; /* real user name, or NULL if q_user */
9e3c0a28 110 char *q_host; /* host name */
179c1218 111 struct mailer *q_mailer; /* mailer to use */
b2e9d033 112 u_short q_flags; /* status flags, see below */
0c9a26a7
EA
113 uid_t q_uid; /* user-id of receiver (if known) */
114 gid_t q_gid; /* group-id of receiver (if known) */
4bb4503e 115 char *q_home; /* home dir (local mailer only) */
f77d50ee 116 char *q_fullname; /* full name if known */
abae7b2d 117 char *q_fullname; /* full name of this person */
ed45aae1 118 time_t q_timeout; /* timeout for this address */
abae7b2d
EA
119 struct address *q_next; /* chain */
120 struct address *q_alias; /* parent in alias tree */
121 struct address *q_sibling; /* sibling in alias tree */
122 struct address *q_child; /* child in alias tree */
9e3c0a28
EA
123};
124
125typedef struct address ADDRESS;
126
127# define QDONTSEND 000001 /* don't send to this address */
1ef61b9f 128# define QBADADDR 000002 /* this address is verified bad */
2c1457f0 129# define QGOODUID 000004 /* the q_uid q_gid fields are good */
92f12b98 130# define QPRIMARY 000010 /* set from argv */
ed45aae1 131# define QQUEUEUP 000020 /* queue for later transmission */
8dcff118 132# define QSENT 000040 /* has been successfully delivered */
51966dba 133# define QNOTREMOTE 000100 /* not an address for remote forwarding */
e47d965e 134# define QSELFREF 000200 /* this address references itself */
8bcce465 135# define QVERIFIED 000400 /* verified, but not expanded */
abae7b2d 136# define QPSEUDO 000040 /* only on the list for verification */
2654b031 137\f/*
b3cbe40f
EA
138** Mailer definition structure.
139** Every mailer known to the system is declared in this
140** structure. It defines the pathname of the mailer, some
141** flags associated with it, and the argument vector to
cb590f52 142** pass to it. The flags are defined in conf.c
b3cbe40f 143**
b8944683
EA
144** The argument vector is expanded before actual use. All
145** words except the first are passed through the macro
146** processor.
b3cbe40f
EA
147*/
148
149struct mailer
150{
d6a28dd8 151 char *m_name; /* symbolic name of this mailer */
9e3c0a28 152 char *m_mailer; /* pathname of the mailer to use */
6e8a8adf 153 BITMAP m_flags; /* status flags, see below */
b14547d5 154 short m_mno; /* mailer number internally */
6708a5e3 155 char **m_argv; /* template argument vector */
5f2e67fb
EA
156 short m_sh_rwset; /* rewrite set: sender header addresses */
157 short m_se_rwset; /* rewrite set: sender envelope addresses */
158 short m_rh_rwset; /* rewrite set: recipient header addresses */
159 short m_re_rwset; /* rewrite set: recipient envelope addresses */
b3ef02a2 160 char *m_eol; /* end of line string */
6e8a8adf 161 long m_maxsize; /* size limit on message to this mailer */
8657d05f 162 int m_linelimit; /* max # characters per line */
a9d54f84 163 char *m_execdir; /* directory to chdir to before execv */
b3cbe40f
EA
164};
165
cdb17311
EA
166typedef struct mailer MAILER;
167
5fbf3fea 168/* bits for m_flags */
4f163ea3 169# define M_ESMTP 'a' /* run Extended SMTP protocol */
e0b72c68 170# define M_NOCOMMENT 'c' /* don't include comment part of address */
55c35014 171# define M_CANONICAL 'C' /* make addresses canonical "u@dom" */
e0b72c68 172 /* 'D' /* CF: include Date: */
55c35014
EA
173# define M_EXPENSIVE 'e' /* it costs to use this mailer.... */
174# define M_ESCFROM 'E' /* escape From lines to >From */
6e8a8adf 175# define M_FOPT 'f' /* mailer takes picky -f flag */
e0b72c68 176 /* 'F' /* CF: include From: or Resent-From: */
55c35014 177# define M_HST_UPPER 'h' /* preserve host case distinction */
e0b72c68 178 /* 'H' /* UIUC: MAIL11V3: preview headers */
55c35014 179# define M_INTERNAL 'I' /* SMTP to another sendmail site */
2ebcc9e9 180# define M_LOCALMAILER 'l' /* delivery is to this host */
55c35014 181# define M_LIMITS 'L' /* must enforce SMTP line limits */
6e8a8adf 182# define M_MUSER 'm' /* can handle multiple users at once */
e0b72c68 183 /* 'M' /* CF: include Message-Id: */
55c35014 184# define M_NHDR 'n' /* don't insert From line */
e0b72c68 185 /* 'N' /* UIUC: MAIL11V3: DATA returns multi-status */
55c35014 186# define M_FROMPATH 'p' /* use reverse-path in MAIL FROM: */
e0b72c68 187 /* 'P' /* CF: include Return-Path: */
55c35014 188# define M_ROPT 'r' /* mailer takes picky -r flag */
a4f165f5 189# define M_SECURE_PORT 'R' /* try to send on a reserved TCP port */
55c35014
EA
190# define M_STRIPQ 's' /* strip quote chars from user/host */
191# define M_RESTR 'S' /* must be daemon to execute */
6e8a8adf 192# define M_USR_UPPER 'u' /* preserve user case distinction */
6e8a8adf 193# define M_UGLYUUCP 'U' /* this wants an ugly UUCP from line */
e0b72c68 194 /* 'V' /* UIUC: !-relativize all addresses */
4f163ea3 195 /* 'x' /* CF: include Full-Name: */
6e8a8adf 196# define M_XDOT 'X' /* use hidden-dot algorithm */
8657d05f 197# define M_7BITS '7' /* use 7-bit path */
1a12c7d6 198
179c1218 199EXTERN MAILER *Mailer[MAXMAILERS+1];
4bb4503e 200
179c1218
EA
201EXTERN MAILER *LocalMailer; /* ptr to local mailer */
202EXTERN MAILER *ProgMailer; /* ptr to program mailer */
38817acb
EA
203EXTERN MAILER *FileMailer; /* ptr to *file* mailer */
204EXTERN MAILER *InclMailer; /* ptr to *include* mailer */
2654b031 205\f/*
1a12c7d6
EA
206** Header structure.
207** This structure is used internally to store header items.
208*/
209
210struct header
211{
212 char *h_field; /* the name of the field */
213 char *h_value; /* the value of that field */
214 struct header *h_link; /* the next header */
b2e9d033 215 u_short h_flags; /* status bits, see below */
6e8a8adf 216 BITMAP h_mflags; /* m_flags bits needed */
1a12c7d6
EA
217};
218
219typedef struct header HDR;
220
1a12c7d6
EA
221/*
222** Header information structure.
223** Defined in conf.c, this struct declares the header fields
224** that have some magic meaning.
225*/
226
227struct hdrinfo
228{
229 char *hi_field; /* the name of the field */
b2e9d033 230 u_short hi_flags; /* status bits, see below */
1a12c7d6
EA
231};
232
233extern struct hdrinfo HdrInfo[];
234
235/* bits for h_flags and hi_flags */
355a2a04 236# define H_EOH 00001 /* this field terminates header */
028b97f3 237# define H_RCPT 00002 /* contains recipient addresses */
1a12c7d6 238# define H_DEFAULT 00004 /* if another value is found, drop this */
a90807d8 239# define H_RESENT 00010 /* this address is a "Resent-..." address */
2f0c5bd8 240# define H_CHECK 00020 /* check h_mflags against m_flags */
a9e0e597 241# define H_ACHECK 00040 /* ditto, but always (not just default) */
b2e9d033 242# define H_FORCE 00100 /* force this field, even if default */
17232873 243# define H_TRACE 00200 /* this field contains trace information */
91f868d8 244# define H_FROM 00400 /* this is a from-type field */
f5a42e44 245# define H_VALID 01000 /* this field has a validated value */
453139c0
EA
246# define H_RECEIPTTO 02000 /* this field has return receipt info */
247# define H_ERRORSTO 04000 /* this field has error address info */
2654b031
EA
248\f/*
249** Envelope structure.
250** This structure defines the message itself. There is usually
251** only one of these -- for the message that we originally read
252** and which is our primary interest -- but other envelopes can
253** be generated during processing. For example, error messages
254** will have their own envelope.
255*/
1a12c7d6 256
b543d6fa
EA
257# define ENVELOPE struct envelope
258
259ENVELOPE
2654b031 260{
dd1fe05b
EA
261 HDR *e_header; /* head of header list */
262 long e_msgpriority; /* adjusted priority of this message */
96476cab 263 time_t e_ctime; /* time message appeared in the queue */
dd1fe05b 264 char *e_to; /* the target person */
17232873 265 char *e_receiptto; /* return receipt address */
dd1fe05b 266 ADDRESS e_from; /* the person it is from */
547f2e0e 267 char *e_sender; /* e_from.q_paddr w comments stripped */
857afefe 268 char **e_fromdomain; /* the domain part of the sender */
1bcdf0a2 269 ADDRESS *e_returnto; /* place to return the message to */
dd1fe05b 270 ADDRESS *e_sendqueue; /* list of message recipients */
3c7fe765 271 ADDRESS *e_errorqueue; /* the queue for error responses */
dd1fe05b 272 long e_msgsize; /* size of the message in bytes */
2e3062fe 273 int e_nrcpts; /* number of recipients */
dd1fe05b 274 short e_class; /* msg class (priority, junk, etc.) */
e6f08ab1 275 short e_flags; /* flags, see below */
7338e3d4 276 short e_hopcount; /* number of times processed */
9f27c6a8 277 short e_nsent; /* number of sends since checkpoint */
8c8e8e94
EA
278 short e_sendmode; /* message send mode */
279 short e_errormode; /* error return mode */
b543d6fa
EA
280 int (*e_puthdr)__P((FILE *, MAILER *, ENVELOPE *));
281 /* function to put header of message */
282 int (*e_putbody)__P((FILE *, MAILER *, ENVELOPE *));
283 /* function to put body of message */
dd1fe05b 284 struct envelope *e_parent; /* the message this one encloses */
e6f08ab1 285 struct envelope *e_sibling; /* the next envelope of interest */
60eebb0d 286 char *e_bodytype; /* type of message body */
dd1fe05b 287 char *e_df; /* location of temp file */
912acb74 288 FILE *e_dfp; /* temporary file */
2cce0c26 289 char *e_id; /* code for this entry in queue */
912acb74 290 FILE *e_xfp; /* transcript file */
3620ad97 291 FILE *e_lockfp; /* the lock file for this message */
553e463f 292 FILE *e_qfp; /* queue control file */
1369934e 293 char *e_message; /* error message */
86575ebf 294 char *e_statmsg; /* stat msg (changes per delivery) */
dd1fe05b 295 char *e_macro[128]; /* macro definitions */
2654b031 296};
1a12c7d6 297
e6f08ab1
EA
298/* values for e_flags */
299#define EF_OLDSTYLE 000001 /* use spaces (not commas) in hdrs */
300#define EF_INQUEUE 000002 /* this message is fully queued */
301#define EF_TIMEOUT 000004 /* this message is too old */
302#define EF_CLRQUEUE 000010 /* disk copy is no longer needed */
303#define EF_SENDRECEIPT 000020 /* send a return receipt */
304#define EF_FATALERRS 000040 /* fatal errors occured */
305#define EF_KEEPQUEUE 000100 /* keep queue files always */
7338e3d4 306#define EF_RESPONSE 000200 /* this is an error or return receipt */
a90807d8 307#define EF_RESENT 000400 /* this message is being forwarded */
71804bbd 308#define EF_VRFYONLY 001000 /* verify only (don't expand aliases) */
c2bdb1dd
EA
309#define EF_WARNING 002000 /* warning message has been sent */
310#define EF_QUEUERUN 004000 /* this envelope is from queue */
e6f08ab1 311
2654b031
EA
312EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */
313\f/*
505aaba0 314** Message priority classes.
9ccf54c4 315**
505aaba0
EA
316** The message class is read directly from the Priority: header
317** field in the message.
df74deb0 318**
505aaba0
EA
319** CurEnv->e_msgpriority is the number of bytes in the message plus
320** the creation time (so that jobs ``tend'' to be ordered correctly),
321** adjusted by the message class, the number of recipients, and the
322** amount of time the message has been sitting around. This number
323** is used to order the queue. Higher values mean LOWER priority.
324**
325** Each priority class point is worth WkClassFact priority points;
326** each recipient is worth WkRecipFact priority points. Each time
327** we reprocess a message the priority is adjusted by WkTimeFact.
328** WkTimeFact should normally decrease the priority so that jobs
329** that have historically failed will be run later; thanks go to
330** Jay Lepreau at Utah for pointing out the error in my thinking.
ee32daaf 331**
df74deb0
EA
332** The "class" is this number, unadjusted by the age or size of
333** this message. Classes with negative representations will have
334** error messages thrown away if they are not local.
ed45aae1
EA
335*/
336
a444c81b
EA
337struct priority
338{
339 char *pri_name; /* external name of priority */
340 int pri_val; /* internal value for same */
341};
342
343EXTERN struct priority Priorities[MAXPRIORITIES];
344EXTERN int NumPriorities; /* pointer into Priorities */
2654b031 345\f/*
d6a28dd8
EA
346** Rewrite rules.
347*/
348
349struct rewrite
350{
351 char **r_lhs; /* pattern match */
352 char **r_rhs; /* substitution value */
353 struct rewrite *r_next;/* next in chain */
354};
355
792a6b53 356EXTERN struct rewrite *RewriteRules[MAXRWSETS];
d6a28dd8 357
792a6b53
EA
358/*
359** Special characters in rewriting rules.
360** These are used internally only.
361** The COND* rules are actually used in macros rather than in
362** rewriting rules, but are given here because they
363** cannot conflict.
364*/
365
366/* left hand side items */
2bee003d
EA
367# define MATCHZANY 0220 /* match zero or more tokens */
368# define MATCHANY 0221 /* match one or more tokens */
369# define MATCHONE 0222 /* match exactly one token */
370# define MATCHCLASS 0223 /* match one token in a class */
371# define MATCHNCLASS 0224 /* match anything not in class */
372# define MATCHREPL 0225 /* replacement on RHS for above */
41173b8f
EA
373# define MATCHLOOKUP '\035' /* look up and replace a sequence */
374# define MATCHELOOKUP '\036' /* end of the sequence */
d6a28dd8 375
792a6b53 376/* right hand side items */
2bee003d
EA
377# define CANONNET 0226 /* canonical net, next token */
378# define CANONHOST 0227 /* canonical host, next token */
379# define CANONUSER 0230 /* canonical user, next N tokens */
380# define CALLSUBR 0231 /* call another rewriting set */
d6a28dd8 381
792a6b53 382/* conditionals in macros */
2bee003d
EA
383# define CONDIF 0232 /* conditional if-then */
384# define CONDELSE 0233 /* conditional else */
385# define CONDFI 0234 /* conditional fi */
a73ae8ac 386
58862a24 387/* bracket characters for host name lookup */
2bee003d
EA
388# define HOSTBEGIN 0235 /* hostname lookup begin */
389# define HOSTEND 0236 /* hostname lookup end */
58862a24 390
42fa5d67 391/* bracket characters for generalized lookup */
2bee003d
EA
392# define LOOKUPBEGIN 0205 /* generalized lookup begin */
393# define LOOKUPEND 0206 /* generalized lookup end */
42fa5d67 394
2bee003d
EA
395/* macro substitution character */
396# define MACROEXPAND 0201 /* macro expansion */
34e7a9e4 397# define MACRODEXPAND 0202 /* deferred macro expansion */
e45dcea5 398
7703d47a
EA
399/* to make the code clearer */
400# define MATCHZERO CANONHOST
401
e45dcea5
EA
402/* external <==> internal mapping table */
403struct metamac
404{
405 char metaname; /* external code (after $) */
406 char metaval; /* internal code (as above) */
407};
2654b031 408\f/*
2ae0e0ed
EA
409** Information about currently open connections to mailers, or to
410** hosts that we have looked up recently.
2e3062fe
EA
411*/
412
f2e44ded 413# define MCI struct mailer_con_info
2e3062fe 414
f2e44ded 415MCI
2e3062fe 416{
2ae0e0ed
EA
417 short mci_flags; /* flag bits, see below */
418 short mci_errno; /* error number on last connection */
419 short mci_exitstat; /* exit status from last connection */
4e20c4d2 420 short mci_state; /* SMTP state */
a979db86
EA
421 short mci_options; /* ESMTP options */
422 long mci_maxsize; /* max size this server will accept */
2ae0e0ed
EA
423 FILE *mci_in; /* input side of connection */
424 FILE *mci_out; /* output side of connection */
425 int mci_pid; /* process id of subordinate proc */
e62e1144
EA
426 char *mci_phase; /* SMTP phase string */
427 struct mailer *mci_mailer; /* ptr to the mailer for this conn */
4e20c4d2 428 char *mci_host; /* host name */
e62e1144 429 time_t mci_lastuse; /* last usage time */
2e3062fe
EA
430};
431
432
433/* flag bits */
2ae0e0ed 434#define MCIF_VALID 00001 /* this entry is valid */
06771186 435#define MCIF_TEMP 00002 /* don't cache this connection */
f2e44ded 436#define MCIF_CACHED 00004 /* currently in open cache */
06771186
EA
437
438/* states */
439#define MCIS_CLOSED 0 /* no traffic on this connection */
e62e1144
EA
440#define MCIS_OPENING 1 /* sending initial protocol */
441#define MCIS_OPEN 2 /* open, initial protocol sent */
442#define MCIS_ACTIVE 3 /* message being sent */
f2e44ded
EA
443#define MCIS_QUITING 4 /* running quit protocol */
444#define MCIS_SSD 5 /* service shutting down */
445#define MCIS_ERROR 6 /* I/O error on connection */
a979db86
EA
446
447/* options bits */
4f163ea3
EA
448#define MCIO_ESMTP 0x0001 /* this host speaks ESMTP */
449#define MCIO_EXPN 0x0002 /* EXPN command supported */
450#define MCIO_SIZE 0x0004 /* SIZE option supported */
451#define MCIO_8BITMIME 0x0008 /* BODY=8BITMIME supported */
2e3062fe 452\f/*
42fa5d67
EA
453** Mapping functions
454**
455** These allow arbitrary mappings in the config file. The idea
456** (albeit not the implementation) comes from IDA sendmail.
457*/
458
42fa5d67 459# define MAPCLASS struct _mapclass
b543d6fa 460# define MAP struct _map
42fa5d67
EA
461
462
463/*
464** An actual map.
465*/
466
42fa5d67
EA
467MAP
468{
469 MAPCLASS *map_class; /* the class of this map */
470 int map_flags; /* flags, see below */
471 char *map_file; /* the (nominal) filename */
5a4c03c6 472 void *map_db; /* the open database ptr */
32fd13db 473 char *map_app; /* to append to successful matches */
33844dcf 474 char *map_domain; /* the (nominal) NIS domain */
9d3eed3f 475 char *map_rebuild; /* program to run to do auto-rebuild */
b543d6fa 476 char **map_deplist; /* dependency list */
42fa5d67
EA
477};
478
479/* bit values for map_flags */
480# define MF_VALID 00001 /* this entry is valid */
5a4c03c6 481# define MF_INCLNULL 00002 /* include null byte in key */
32fd13db 482# define MF_OPTIONAL 00004 /* don't complain if map not found */
5dac3bbf 483# define MF_NOFOLDCASE 00010 /* don't fold case in keys */
33844dcf 484# define MF_MATCHONLY 00020 /* don't use the map value */
b543d6fa
EA
485
486
487/*
488** The class of a map -- essentially the functions to call
489*/
490
491MAPCLASS
492{
493 bool (*map_init)__P((MAP *, char *, char *));
494 /* initialization function */
495 char *(*map_lookup)__P((MAP *, char *, int, char **, int *));
496 /* lookup function */
497};
42fa5d67 498\f/*
4d3a97d9
EA
499** Symbol table definitions
500*/
501
502struct symtab
503{
504 char *s_name; /* name to be entered */
cdb17311 505 char s_type; /* general type (see below) */
4d3a97d9 506 struct symtab *s_next; /* pointer to next in chain */
cdb17311
EA
507 union
508 {
2e3062fe
EA
509 BITMAP sv_class; /* bit-map of word classes */
510 ADDRESS *sv_addr; /* pointer to address header */
511 MAILER *sv_mailer; /* pointer to mailer */
512 char *sv_alias; /* alias */
42fa5d67
EA
513 MAPCLASS sv_mapclass; /* mapping function class */
514 MAP sv_map; /* mapping function */
ae21f7bc 515 char *sv_hostsig; /* host signature */
f2e44ded 516 MCI sv_mci; /* mailer connection info */
cdb17311 517 } s_value;
4d3a97d9
EA
518};
519
520typedef struct symtab STAB;
521
cdb17311
EA
522/* symbol types */
523# define ST_UNDEF 0 /* undefined type */
524# define ST_CLASS 1 /* class map */
525# define ST_ADDRESS 2 /* an address in parsed format */
526# define ST_MAILER 3 /* a mailer header */
527# define ST_ALIAS 4 /* an alias */
e62e1144
EA
528# define ST_MAPCLASS 5 /* mapping function class */
529# define ST_MAP 6 /* mapping function */
ae21f7bc 530# define ST_HOSTSIG 7 /* host signature */
f2e44ded 531# define ST_MCI 16 /* mailer connection info (offset) */
cdb17311
EA
532
533# define s_class s_value.sv_class
14a39063 534# define s_address s_value.sv_addr
cdb17311
EA
535# define s_mailer s_value.sv_mailer
536# define s_alias s_value.sv_alias
2ae0e0ed 537# define s_mci s_value.sv_mci
cdb17311 538
4d3a97d9
EA
539extern STAB *stab();
540
541/* opcodes to stab */
542# define ST_FIND 0 /* find entry */
543# define ST_ENTER 1 /* enter if not there */
2654b031 544\f/*
2439b900
EA
545** STRUCT EVENT -- event queue.
546**
547** Maintained in sorted order.
f5d25d7b
EA
548**
549** We store the pid of the process that set this event to insure
550** that when we fork we will not take events intended for the parent.
2439b900
EA
551*/
552
553struct event
554{
555 time_t ev_time; /* time of the function call */
b543d6fa
EA
556 int (*ev_func)__P((int));
557 /* function to call */
2439b900 558 int ev_arg; /* argument to ev_func */
f5d25d7b 559 int ev_pid; /* pid that set this event */
2439b900
EA
560 struct event *ev_link; /* link to next item */
561};
562
563typedef struct event EVENT;
564
565EXTERN EVENT *EventQueue; /* head of event queue */
566\f/*
7338e3d4 567** Operation, send, and error modes
75f95954
EA
568**
569** The operation mode describes the basic operation of sendmail.
570** This can be set from the command line, and is "send mail" by
571** default.
572**
573** The send mode tells how to send mail. It can be set in the
574** configuration file. It's setting determines how quickly the
575** mail will be delivered versus the load on your system. If the
576** -v (verbose) flag is given, it will be forced to SM_DELIVER
577** mode.
578**
7338e3d4 579** The error mode tells how to return errors.
d0bd03ce
EA
580*/
581
75f95954 582EXTERN char OpMode; /* operation mode, see below */
d0bd03ce 583
75f95954 584#define MD_DELIVER 'm' /* be a mail sender */
75f95954 585#define MD_SMTP 's' /* run SMTP on standard input */
d0bd03ce
EA
586#define MD_DAEMON 'd' /* run as a daemon */
587#define MD_VERIFY 'v' /* verify: don't collect or deliver */
44cb7eee 588#define MD_TEST 't' /* test mode: resolve addrs only */
6bf17095
EA
589#define MD_INITALIAS 'i' /* initialize alias database */
590#define MD_PRINT 'p' /* print the queue */
591#define MD_FREEZE 'z' /* freeze the configuration file */
d0bd03ce 592
75f95954 593
8c8e8e94 594/* values for e_sendmode -- send modes */
75f95954
EA
595#define SM_DELIVER 'i' /* interactive delivery */
596#define SM_QUICKD 'j' /* deliver w/o queueing */
597#define SM_FORK 'b' /* deliver in background */
598#define SM_QUEUE 'q' /* queue, don't deliver */
599#define SM_VERIFY 'v' /* verify only (used internally) */
7338e3d4 600
eefcf91f
EA
601/* used only as a parameter to sendall */
602#define SM_DEFAULT '\0' /* unspecified, use SendMode */
603
7338e3d4 604
8c8e8e94 605/* values for e_errormode -- error handling modes */
7338e3d4
EA
606#define EM_PRINT 'p' /* print errors */
607#define EM_MAIL 'm' /* mail back errors */
608#define EM_WRITE 'w' /* write back errors */
609#define EM_BERKNET 'e' /* special berknet processing */
610#define EM_QUIET 'q' /* don't print messages (stat only) */
e3ecd56f
EA
611\f/*
612** Additional definitions
613*/
614
20951c3f 615
1c7897ef 616/* Offset used to ensure that name server error * codes are unique */
20951c3f 617#define MAX_ERRNO 100
1c7897ef 618
e3ecd56f
EA
619
620/*
621** Privacy flags
622** These are bit values for the PrivacyFlags word.
623*/
624
1c7897ef
EA
625#define PRIV_PUBLIC 0 /* what have I got to hide? */
626#define PRIV_NEEDMAILHELO 00001 /* insist on HELO for MAIL, at least */
627#define PRIV_NEEDEXPNHELO 00002 /* insist on HELO for EXPN */
628#define PRIV_NEEDVRFYHELO 00004 /* insist on HELO for VRFY */
629#define PRIV_NOEXPN 00010 /* disallow EXPN command entirely */
630#define PRIV_NOVRFY 00020 /* disallow VRFY command entirely */
94bc039a 631#define PRIV_AUTHWARNINGS 00040 /* flag possible authorization probs */
ae1498c3
EA
632#define PRIV_RESTRMAILQ 01000 /* restrict mailq command */
633#define PRIV_GOAWAY 00777 /* don't give no info, anyway, anyhow */
1c7897ef
EA
634
635/* struct defining such things */
636struct prival
637{
638 char *pv_name; /* name of privacy flag */
639 int pv_flag; /* numeric level */
640};
3341995c 641
e3ecd56f
EA
642
643/*
644** Flags passed to remotename
645*/
646
647#define RF_SENDERADDR 0001 /* this is a sender address */
648#define RF_HEADERADDR 0002 /* this is a header address */
649#define RF_CANONICAL 0004 /* strip comment information */
650#define RF_ADDDOMAIN 0010 /* OK to do domain extension */
651
652
3341995c
EA
653/*
654** Regular UNIX sockaddrs are too small to handle ISO addresses, so
655** we are forced to declare a supertype here.
656*/
657
3356c77c 658union bigsockaddr
3341995c 659{
3356c77c
EA
660 struct sockaddr sa; /* general version */
661#ifdef NETINET
662 struct sockaddr_in sin; /* INET family */
663#endif
664#ifdef NETISO
665 struct sockaddr_iso siso; /* ISO family */
666#endif
88e65f7c
EA
667#ifdef NETNS
668 struct sockaddr_ns sns; /* XNS family */
669#endif
670#ifdef NETX25
671 struct sockaddr_x25 sx25; /* X.25 family */
672#endif
3341995c
EA
673};
674
3356c77c 675#define SOCKADDR union bigsockaddr
3341995c 676
d0bd03ce 677\f/*
b3cbe40f
EA
678** Global variables.
679*/
680
327272f5 681EXTERN bool FromFlag; /* if set, "From" person is explicit */
327272f5 682EXTERN bool NoAlias; /* if set, don't do any aliasing */
327272f5
EA
683EXTERN bool MeToo; /* send to the sender also */
684EXTERN bool IgnrDot; /* don't let dot end messages */
685EXTERN bool SaveFrom; /* save leading "From" lines */
686EXTERN bool Verbose; /* set if blow-by-blow desired */
687EXTERN bool GrabTo; /* if set, get recipients from msg */
327272f5 688EXTERN bool NoReturn; /* don't return letter to sender */
cbdb7357 689EXTERN bool SuprErrs; /* set if we are suppressing errors */
49086753 690EXTERN bool HoldErrs; /* only output errors to transcript */
3135d20c 691EXTERN bool NoConnect; /* don't connect to non-local mailers */
c1e24818 692EXTERN bool SuperSafe; /* be extra careful, even if expensive */
2e3062fe 693EXTERN bool ForkQueueRuns; /* fork for each job when running the queue */
6bf17095 694EXTERN bool AutoRebuild; /* auto-rebuild the alias database as needed */
7355ccf5 695EXTERN bool CheckAliases; /* parse addresses during newaliases */
35af2f06 696EXTERN bool UseNameServer; /* use internet domain name server */
8657d05f 697EXTERN bool EightBit; /* try to preserve 8-bit data */
fd399267 698EXTERN int SafeAlias; /* minutes to wait until @:@ in alias file */
cbdb7357
EA
699EXTERN FILE *InChannel; /* input connection */
700EXTERN FILE *OutChannel; /* output connection */
05c5b8b4
EA
701EXTERN uid_t RealUid; /* when Daemon, real uid of caller */
702EXTERN gid_t RealGid; /* when Daemon, real gid of caller */
703EXTERN uid_t DefUid; /* default uid to run as */
704EXTERN gid_t DefGid; /* default gid to run as */
3fbc69d6 705EXTERN char *DefUser; /* default user to run as (from DefUid) */
327272f5 706EXTERN int OldUmask; /* umask when sendmail starts up */
1ea752a1 707EXTERN int Errors; /* set if errors (local to single pass) */
327272f5 708EXTERN int ExitStat; /* exit status code */
cbdb7357 709EXTERN int AliasLevel; /* depth of aliasing */
792a6b53 710EXTERN int LineNumber; /* line number in current input */
c1e24818 711EXTERN int LogLevel; /* level of logging to perform */
d9667c04 712EXTERN int FileMode; /* mode on files */
2e3062fe
EA
713EXTERN int QueueLA; /* load average starting forced queueing */
714EXTERN int RefuseLA; /* load average refusing connections are */
3620ad97 715EXTERN int CurrentLA; /* current load average */
faad4dd5 716EXTERN long QueueFactor; /* slope of queue function */
ed45aae1 717EXTERN time_t QueueIntvl; /* intervals between running the queue */
c1e24818
EA
718EXTERN char *AliasFile; /* location of alias file */
719EXTERN char *HelpFile; /* location of SMTP help file */
05c5b8b4 720EXTERN char *ErrMsgFile; /* file to prepend to all error messages */
c1e24818
EA
721EXTERN char *StatFile; /* location of statistics summary */
722EXTERN char *QueueDir; /* location of queue directory */
7338e3d4 723EXTERN char *FileName; /* name to print on error messages */
2e3062fe 724EXTERN char *SmtpPhase; /* current phase in SMTP processing */
57c97d4a 725EXTERN char *MyHostName; /* name of this host for SMTP messages */
2e3062fe 726EXTERN char *RealHostName; /* name of host we are talking to */
3341995c 727EXTERN SOCKADDR RealHostAddr; /* address of host we are talking to */
57c97d4a 728EXTERN char *CurHostName; /* current host we are dealing with */
c1e24818
EA
729EXTERN jmp_buf TopFrame; /* branch-to-top-of-loop-on-error frame */
730EXTERN bool QuickAbort; /* .... but only if we want a quick abort */
f61c3c40 731EXTERN bool LogUsrErrs; /* syslog user errors (e.g., SMTP RCPT cmd) */
1c7897ef 732EXTERN int PrivacyFlags; /* privacy flags */
96476cab 733extern char *ConfFile; /* location of configuration file [conf.c] */
acae5a9d 734extern char *FreezeFile; /* location of frozen memory image [conf.c] */
1c7897ef 735extern char *PidFile; /* location of proc id file [conf.c] */
2e3062fe
EA
736extern ADDRESS NullAddress; /* a null (template) address [main.c] */
737EXTERN char SpaceSub; /* substitution for <lwsp> */
faad4dd5
EA
738EXTERN long WkClassFact; /* multiplier for message class -> priority */
739EXTERN long WkRecipFact; /* multiplier for # of recipients -> priority */
740EXTERN long WkTimeFact; /* priority offset each time this job is run */
2e3062fe 741EXTERN char *PostMasterCopy; /* address to get errs cc's */
8dcff118 742EXTERN int CheckpointInterval; /* queue file checkpoint interval */
a979db86
EA
743EXTERN char *UdbSpec; /* user database source spec */
744EXTERN int MaxHopCount; /* max # of hops until bounce */
745EXTERN int ConfigLevel; /* config file level */
746EXTERN char *TimeZoneSpec; /* override time zone specification */
747EXTERN bool MatchGecos; /* look for user names in gecos field */
63d473ff 748EXTERN bool DontPruneRoutes; /* don't prune source routes */
a979db86 749EXTERN int MaxMciCache; /* maximum entries in MCI cache */
f2e44ded 750EXTERN time_t MciCacheTimeout; /* maximum idle time on connections */
a979db86
EA
751EXTERN char *ForwardPath; /* path to search for .forward files */
752EXTERN long MinBlocksFree; /* min # of blocks free on queue fs */
d6c28d1a
EA
753EXTERN char *QueueLimitRecipient; /* limit queue runs to this recipient */
754EXTERN char *QueueLimitSender; /* limit queue runs to this sender */
755EXTERN char *QueueLimitId; /* limit queue runs to this id */
a979db86
EA
756EXTERN char *FallBackMX; /* fall back MX host */
757EXTERN long MaxMessageSize; /* advertised max size we will accept */
7f5e2eef
EA
758
759
760/*
761** Timeouts
762**
763** Indicated values are the MINIMUM per RFC 1123 section 5.3.2.
764*/
765
766EXTERN struct
767{
768 time_t to_initial; /* initial greeting timeout [5m] */
769 time_t to_mail; /* MAIL command [5m] */
770 time_t to_rcpt; /* RCPT command [5m] */
771 time_t to_datainit; /* DATA initiation [2m] */
772 time_t to_datablock; /* DATA block [3m] */
773 time_t to_datafinal; /* DATA completion [10m] */
774 time_t to_nextcommand; /* next command [5m] */
775 /* following timeouts are not mentioned in RFC 1123 */
776 time_t to_rset; /* RSET command */
777 time_t to_helo; /* HELO command */
778 time_t to_quit; /* QUIT command */
779 time_t to_miscshort; /* misc short commands (NOOP, VERB, etc) */
c2bdb1dd
EA
780 /* following are per message */
781 time_t to_q_return; /* queue return timeout */
782 time_t to_q_warning; /* queue warning timeout */
7f5e2eef
EA
783} TimeOuts;
784
785
786/*
9678c96d
EA
787** Trace information
788*/
b3cbe40f 789
9678c96d
EA
790/* trace vector and macros for debugging flags */
791EXTERN u_char tTdvect[100];
792# define tTd(flag, level) (tTdvect[flag] >= level)
793# define tTdlevel(flag) (tTdvect[flag])
794\f/*
795** Miscellaneous information.
796*/
b3cbe40f 797
b3cbe40f 798
15842c3c
EA
799
800/*
801** Some in-line functions
802*/
803
804/* set exit status */
c8ec8736
EA
805#define setstat(s) { \
806 if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \
807 ExitStat = s; \
808 }
29871fef 809
15842c3c 810/* make a copy of a string */
c8ec8736 811#define newstr(s) strcpy(xalloc(strlen(s) + 1), s)
15842c3c 812
2e3062fe
EA
813#define STRUCTCOPY(s, d) d = s
814
15842c3c
EA
815
816/*
817** Declarations of useful functions
818*/
29871fef 819
57d5319a 820extern ADDRESS *parseaddr __P((char *, ADDRESS *, int, int, char **, ENVELOPE *));
b543d6fa
EA
821extern char *xalloc __P((int));
822extern bool sameaddr __P((ADDRESS *, ADDRESS *));
823extern FILE *dfopen __P((char *, char *));
824extern EVENT *setevent __P((time_t, int(*)(), int));
825extern char *sfgets __P((char *, int, FILE *, time_t));
57d5319a 826extern char *queuename __P((ENVELOPE *, int));
b543d6fa
EA
827extern time_t curtime __P(());
828extern bool transienterror __P((int));
829extern char *errstring __P((int));
58633cc7
EA
830
831/* ellipsis is a different case though */
832#ifdef __STDC__
833extern void auth_warning(ENVELOPE *, char *, ...);
834extern void syserr(char *, ...);
835extern void usrerr(char *, ...);
836extern void message(char *, ...);
837extern void nmessage(char *, ...);
838#else
839extern void auth_warning();
840extern void syserr();
841extern void usrerr();
842extern void message();
843extern void nmessage();
844#endif
70aca632
EA
845
846/*
847** HACK to fix bug in C compiler on CCI
848*/
849
850#undef isascii
5eddb1af 851#define isascii(x) (((x) & ~0177) == 0)