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