prototype functions
[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 *
5a972da1 8 * @(#)sendmail.h 6.67 (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
5a972da1 18static char SmailSccsId[] = "@(#)sendmail.h 6.67 %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 */
31f1ab13 494 int map_mflags; /* flags, see below */
42fa5d67 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 */
31f1ab13 511# define MF_ALIAS 0x0080 /* this is an alias file */
713c523f
EA
512# define MF_IMPL_HASH 0x1000 /* implicit: underlying hash database */
513# define MF_IMPL_NDBM 0x2000 /* implicit: underlying NDBM database */
b543d6fa
EA
514
515
516/*
517** The class of a map -- essentially the functions to call
518*/
519
520MAPCLASS
521{
713c523f
EA
522 char *map_cname; /* name of this map class */
523 char *map_ext; /* extension for database file */
31f1ab13 524 short map_cflags; /* flag bits, see below */
713c523f
EA
525 bool (*map_parse)__P((MAP *, char *));
526 /* argument parsing function */
527 char *(*map_lookup)__P((MAP *, char *, char **, int *));
b543d6fa 528 /* lookup function */
713c523f
EA
529 void (*map_store)__P((MAP *, char *, char *));
530 /* store function */
713c523f
EA
531 bool (*map_open)__P((MAP *, int));
532 /* open function */
533 void (*map_close)__P((MAP *));
534 /* close function */
b543d6fa 535};
31f1ab13
EA
536
537/* bit values for map_cflags */
538#define MCF_ALIASOK 0x0001 /* can be used for aliases */
539#define MCF_ALIASONLY 0x0002 /* usable only for aliases */
540#define MCF_REBUILDABLE 0x0004 /* can rebuild alias files */
42fa5d67 541\f/*
4d3a97d9
EA
542** Symbol table definitions
543*/
544
545struct symtab
546{
547 char *s_name; /* name to be entered */
cdb17311 548 char s_type; /* general type (see below) */
4d3a97d9 549 struct symtab *s_next; /* pointer to next in chain */
cdb17311
EA
550 union
551 {
2e3062fe
EA
552 BITMAP sv_class; /* bit-map of word classes */
553 ADDRESS *sv_addr; /* pointer to address header */
554 MAILER *sv_mailer; /* pointer to mailer */
555 char *sv_alias; /* alias */
31f1ab13 556 MAPCLASS sv_mapclass; /* mapping function class */
42fa5d67 557 MAP sv_map; /* mapping function */
ae21f7bc 558 char *sv_hostsig; /* host signature */
f2e44ded 559 MCI sv_mci; /* mailer connection info */
c96073f7 560 NAMECANON sv_namecanon; /* canonical name cache */
cdb17311 561 } s_value;
4d3a97d9
EA
562};
563
564typedef struct symtab STAB;
565
cdb17311
EA
566/* symbol types */
567# define ST_UNDEF 0 /* undefined type */
568# define ST_CLASS 1 /* class map */
569# define ST_ADDRESS 2 /* an address in parsed format */
570# define ST_MAILER 3 /* a mailer header */
571# define ST_ALIAS 4 /* an alias */
e62e1144
EA
572# define ST_MAPCLASS 5 /* mapping function class */
573# define ST_MAP 6 /* mapping function */
ae21f7bc 574# define ST_HOSTSIG 7 /* host signature */
c96073f7 575# define ST_NAMECANON 8 /* cached canonical name */
f2e44ded 576# define ST_MCI 16 /* mailer connection info (offset) */
cdb17311
EA
577
578# define s_class s_value.sv_class
14a39063 579# define s_address s_value.sv_addr
cdb17311
EA
580# define s_mailer s_value.sv_mailer
581# define s_alias s_value.sv_alias
2ae0e0ed 582# define s_mci s_value.sv_mci
cdb17311 583
5a972da1
EA
584extern STAB *stab __P((char *, int, int));
585extern void stabapply __P((void (*)(STAB *)));
4d3a97d9
EA
586
587/* opcodes to stab */
588# define ST_FIND 0 /* find entry */
589# define ST_ENTER 1 /* enter if not there */
2654b031 590\f/*
2439b900
EA
591** STRUCT EVENT -- event queue.
592**
593** Maintained in sorted order.
f5d25d7b
EA
594**
595** We store the pid of the process that set this event to insure
596** that when we fork we will not take events intended for the parent.
2439b900
EA
597*/
598
599struct event
600{
601 time_t ev_time; /* time of the function call */
b543d6fa
EA
602 int (*ev_func)__P((int));
603 /* function to call */
2439b900 604 int ev_arg; /* argument to ev_func */
f5d25d7b 605 int ev_pid; /* pid that set this event */
2439b900
EA
606 struct event *ev_link; /* link to next item */
607};
608
609typedef struct event EVENT;
610
611EXTERN EVENT *EventQueue; /* head of event queue */
612\f/*
7338e3d4 613** Operation, send, and error modes
75f95954
EA
614**
615** The operation mode describes the basic operation of sendmail.
616** This can be set from the command line, and is "send mail" by
617** default.
618**
619** The send mode tells how to send mail. It can be set in the
620** configuration file. It's setting determines how quickly the
621** mail will be delivered versus the load on your system. If the
622** -v (verbose) flag is given, it will be forced to SM_DELIVER
623** mode.
624**
7338e3d4 625** The error mode tells how to return errors.
d0bd03ce
EA
626*/
627
75f95954 628EXTERN char OpMode; /* operation mode, see below */
d0bd03ce 629
75f95954 630#define MD_DELIVER 'm' /* be a mail sender */
75f95954 631#define MD_SMTP 's' /* run SMTP on standard input */
d0bd03ce
EA
632#define MD_DAEMON 'd' /* run as a daemon */
633#define MD_VERIFY 'v' /* verify: don't collect or deliver */
44cb7eee 634#define MD_TEST 't' /* test mode: resolve addrs only */
6bf17095
EA
635#define MD_INITALIAS 'i' /* initialize alias database */
636#define MD_PRINT 'p' /* print the queue */
637#define MD_FREEZE 'z' /* freeze the configuration file */
d0bd03ce 638
75f95954 639
8c8e8e94 640/* values for e_sendmode -- send modes */
75f95954
EA
641#define SM_DELIVER 'i' /* interactive delivery */
642#define SM_QUICKD 'j' /* deliver w/o queueing */
643#define SM_FORK 'b' /* deliver in background */
644#define SM_QUEUE 'q' /* queue, don't deliver */
645#define SM_VERIFY 'v' /* verify only (used internally) */
7338e3d4 646
eefcf91f
EA
647/* used only as a parameter to sendall */
648#define SM_DEFAULT '\0' /* unspecified, use SendMode */
649
7338e3d4 650
8c8e8e94 651/* values for e_errormode -- error handling modes */
7338e3d4
EA
652#define EM_PRINT 'p' /* print errors */
653#define EM_MAIL 'm' /* mail back errors */
654#define EM_WRITE 'w' /* write back errors */
655#define EM_BERKNET 'e' /* special berknet processing */
656#define EM_QUIET 'q' /* don't print messages (stat only) */
e3ecd56f
EA
657\f/*
658** Additional definitions
659*/
660
20951c3f 661
1c7897ef 662/* Offset used to ensure that name server error * codes are unique */
20951c3f 663#define MAX_ERRNO 100
1c7897ef 664
e3ecd56f
EA
665
666/*
667** Privacy flags
668** These are bit values for the PrivacyFlags word.
669*/
670
1c7897ef
EA
671#define PRIV_PUBLIC 0 /* what have I got to hide? */
672#define PRIV_NEEDMAILHELO 00001 /* insist on HELO for MAIL, at least */
673#define PRIV_NEEDEXPNHELO 00002 /* insist on HELO for EXPN */
674#define PRIV_NEEDVRFYHELO 00004 /* insist on HELO for VRFY */
675#define PRIV_NOEXPN 00010 /* disallow EXPN command entirely */
676#define PRIV_NOVRFY 00020 /* disallow VRFY command entirely */
94bc039a 677#define PRIV_AUTHWARNINGS 00040 /* flag possible authorization probs */
ae1498c3
EA
678#define PRIV_RESTRMAILQ 01000 /* restrict mailq command */
679#define PRIV_GOAWAY 00777 /* don't give no info, anyway, anyhow */
1c7897ef
EA
680
681/* struct defining such things */
682struct prival
683{
684 char *pv_name; /* name of privacy flag */
685 int pv_flag; /* numeric level */
686};
3341995c 687
e3ecd56f
EA
688
689/*
690** Flags passed to remotename
691*/
692
693#define RF_SENDERADDR 0001 /* this is a sender address */
694#define RF_HEADERADDR 0002 /* this is a header address */
695#define RF_CANONICAL 0004 /* strip comment information */
696#define RF_ADDDOMAIN 0010 /* OK to do domain extension */
697
698
3341995c
EA
699/*
700** Regular UNIX sockaddrs are too small to handle ISO addresses, so
701** we are forced to declare a supertype here.
702*/
703
3356c77c 704union bigsockaddr
3341995c 705{
3356c77c
EA
706 struct sockaddr sa; /* general version */
707#ifdef NETINET
708 struct sockaddr_in sin; /* INET family */
709#endif
710#ifdef NETISO
711 struct sockaddr_iso siso; /* ISO family */
712#endif
88e65f7c
EA
713#ifdef NETNS
714 struct sockaddr_ns sns; /* XNS family */
715#endif
716#ifdef NETX25
717 struct sockaddr_x25 sx25; /* X.25 family */
718#endif
3341995c
EA
719};
720
3356c77c 721#define SOCKADDR union bigsockaddr
3341995c 722
d0bd03ce 723\f/*
b3cbe40f
EA
724** Global variables.
725*/
726
327272f5 727EXTERN bool FromFlag; /* if set, "From" person is explicit */
327272f5
EA
728EXTERN bool MeToo; /* send to the sender also */
729EXTERN bool IgnrDot; /* don't let dot end messages */
730EXTERN bool SaveFrom; /* save leading "From" lines */
731EXTERN bool Verbose; /* set if blow-by-blow desired */
732EXTERN bool GrabTo; /* if set, get recipients from msg */
327272f5 733EXTERN bool NoReturn; /* don't return letter to sender */
cbdb7357 734EXTERN bool SuprErrs; /* set if we are suppressing errors */
49086753 735EXTERN bool HoldErrs; /* only output errors to transcript */
3135d20c 736EXTERN bool NoConnect; /* don't connect to non-local mailers */
c1e24818 737EXTERN bool SuperSafe; /* be extra careful, even if expensive */
2e3062fe 738EXTERN bool ForkQueueRuns; /* fork for each job when running the queue */
6bf17095 739EXTERN bool AutoRebuild; /* auto-rebuild the alias database as needed */
7355ccf5 740EXTERN bool CheckAliases; /* parse addresses during newaliases */
c420ea6b 741EXTERN bool NoAlias; /* suppress aliasing */
35af2f06 742EXTERN bool UseNameServer; /* use internet domain name server */
aaed1537 743EXTERN bool SevenBit; /* force 7-bit data */
fd399267 744EXTERN int SafeAlias; /* minutes to wait until @:@ in alias file */
cbdb7357
EA
745EXTERN FILE *InChannel; /* input connection */
746EXTERN FILE *OutChannel; /* output connection */
05c5b8b4
EA
747EXTERN uid_t RealUid; /* when Daemon, real uid of caller */
748EXTERN gid_t RealGid; /* when Daemon, real gid of caller */
749EXTERN uid_t DefUid; /* default uid to run as */
750EXTERN gid_t DefGid; /* default gid to run as */
3fbc69d6 751EXTERN char *DefUser; /* default user to run as (from DefUid) */
327272f5 752EXTERN int OldUmask; /* umask when sendmail starts up */
1ea752a1 753EXTERN int Errors; /* set if errors (local to single pass) */
327272f5 754EXTERN int ExitStat; /* exit status code */
cbdb7357 755EXTERN int AliasLevel; /* depth of aliasing */
792a6b53 756EXTERN int LineNumber; /* line number in current input */
c1e24818 757EXTERN int LogLevel; /* level of logging to perform */
d9667c04 758EXTERN int FileMode; /* mode on files */
2e3062fe
EA
759EXTERN int QueueLA; /* load average starting forced queueing */
760EXTERN int RefuseLA; /* load average refusing connections are */
3620ad97 761EXTERN int CurrentLA; /* current load average */
faad4dd5 762EXTERN long QueueFactor; /* slope of queue function */
ed45aae1 763EXTERN time_t QueueIntvl; /* intervals between running the queue */
c1e24818 764EXTERN char *HelpFile; /* location of SMTP help file */
05c5b8b4 765EXTERN char *ErrMsgFile; /* file to prepend to all error messages */
c1e24818
EA
766EXTERN char *StatFile; /* location of statistics summary */
767EXTERN char *QueueDir; /* location of queue directory */
7338e3d4 768EXTERN char *FileName; /* name to print on error messages */
2e3062fe 769EXTERN char *SmtpPhase; /* current phase in SMTP processing */
57c97d4a 770EXTERN char *MyHostName; /* name of this host for SMTP messages */
2e3062fe 771EXTERN char *RealHostName; /* name of host we are talking to */
3341995c 772EXTERN SOCKADDR RealHostAddr; /* address of host we are talking to */
57c97d4a 773EXTERN char *CurHostName; /* current host we are dealing with */
c1e24818
EA
774EXTERN jmp_buf TopFrame; /* branch-to-top-of-loop-on-error frame */
775EXTERN bool QuickAbort; /* .... but only if we want a quick abort */
f61c3c40 776EXTERN bool LogUsrErrs; /* syslog user errors (e.g., SMTP RCPT cmd) */
64409ce4
EA
777EXTERN bool SendMIMEErrors; /* send error messages in MIME format */
778EXTERN bool MatchGecos; /* look for user names in gecos field */
779EXTERN char SpaceSub; /* substitution for <lwsp> */
1c7897ef 780EXTERN int PrivacyFlags; /* privacy flags */
96476cab 781extern char *ConfFile; /* location of configuration file [conf.c] */
acae5a9d 782extern char *FreezeFile; /* location of frozen memory image [conf.c] */
1c7897ef 783extern char *PidFile; /* location of proc id file [conf.c] */
2e3062fe 784extern ADDRESS NullAddress; /* a null (template) address [main.c] */
faad4dd5
EA
785EXTERN long WkClassFact; /* multiplier for message class -> priority */
786EXTERN long WkRecipFact; /* multiplier for # of recipients -> priority */
787EXTERN long WkTimeFact; /* priority offset each time this job is run */
64409ce4
EA
788EXTERN char *UdbSpec; /* user database source spec */
789EXTERN int MaxHopCount; /* max # of hops until bounce */
790EXTERN int ConfigLevel; /* config file level */
791EXTERN char *TimeZoneSpec; /* override time zone specification */
792EXTERN char *ForwardPath; /* path to search for .forward files */
793EXTERN long MinBlocksFree; /* min # of blocks free on queue fs */
794EXTERN char *FallBackMX; /* fall back MX host */
795EXTERN long MaxMessageSize; /* advertised max size we will accept */
2e3062fe 796EXTERN char *PostMasterCopy; /* address to get errs cc's */
8dcff118 797EXTERN int CheckpointInterval; /* queue file checkpoint interval */
63d473ff 798EXTERN bool DontPruneRoutes; /* don't prune source routes */
a979db86 799EXTERN int MaxMciCache; /* maximum entries in MCI cache */
f2e44ded 800EXTERN time_t MciCacheTimeout; /* maximum idle time on connections */
d6c28d1a
EA
801EXTERN char *QueueLimitRecipient; /* limit queue runs to this recipient */
802EXTERN char *QueueLimitSender; /* limit queue runs to this sender */
803EXTERN char *QueueLimitId; /* limit queue runs to this id */
7f5e2eef
EA
804
805
806/*
807** Timeouts
808**
809** Indicated values are the MINIMUM per RFC 1123 section 5.3.2.
810*/
811
812EXTERN struct
813{
814 time_t to_initial; /* initial greeting timeout [5m] */
815 time_t to_mail; /* MAIL command [5m] */
816 time_t to_rcpt; /* RCPT command [5m] */
817 time_t to_datainit; /* DATA initiation [2m] */
818 time_t to_datablock; /* DATA block [3m] */
819 time_t to_datafinal; /* DATA completion [10m] */
820 time_t to_nextcommand; /* next command [5m] */
821 /* following timeouts are not mentioned in RFC 1123 */
822 time_t to_rset; /* RSET command */
823 time_t to_helo; /* HELO command */
824 time_t to_quit; /* QUIT command */
825 time_t to_miscshort; /* misc short commands (NOOP, VERB, etc) */
c2bdb1dd
EA
826 /* following are per message */
827 time_t to_q_return; /* queue return timeout */
828 time_t to_q_warning; /* queue warning timeout */
7f5e2eef
EA
829} TimeOuts;
830
831
832/*
9678c96d
EA
833** Trace information
834*/
b3cbe40f 835
9678c96d
EA
836/* trace vector and macros for debugging flags */
837EXTERN u_char tTdvect[100];
838# define tTd(flag, level) (tTdvect[flag] >= level)
839# define tTdlevel(flag) (tTdvect[flag])
840\f/*
841** Miscellaneous information.
842*/
b3cbe40f 843
b3cbe40f 844
15842c3c
EA
845
846/*
847** Some in-line functions
848*/
849
850/* set exit status */
c8ec8736
EA
851#define setstat(s) { \
852 if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \
853 ExitStat = s; \
854 }
29871fef 855
15842c3c 856/* make a copy of a string */
c8ec8736 857#define newstr(s) strcpy(xalloc(strlen(s) + 1), s)
15842c3c 858
2e3062fe
EA
859#define STRUCTCOPY(s, d) d = s
860
15842c3c
EA
861
862/*
863** Declarations of useful functions
864*/
29871fef 865
713c523f
EA
866extern ADDRESS *parseaddr __P((char *, ADDRESS *, int, int, char **, ENVELOPE *));
867extern char *xalloc __P((int));
868extern bool sameaddr __P((ADDRESS *, ADDRESS *));
869extern FILE *dfopen __P((char *, int, int));
870extern EVENT *setevent __P((time_t, int(*)(), int));
871extern char *sfgets __P((char *, int, FILE *, time_t));
872extern char *queuename __P((ENVELOPE *, int));
873extern time_t curtime __P(());
874extern bool transienterror __P((int));
875extern const char *errstring __P((int));
5a972da1
EA
876extern void expand __P((char *, char *, char *, ENVELOPE *));
877extern void define __P((char, char *, ENVELOPE *));
878extern char *macvalue __P((char, ENVELOPE *));
879extern char **prescan __P((char *, char, char[], char **));
880extern char *fgetfolded __P((char *, int, FILE *));
881extern ADDRESS *recipient __P((ADDRESS *, ADDRESS **, ENVELOPE *));
882extern ENVELOPE *newenvelope __P((ENVELOPE *, ENVELOPE *));
883extern void dropenvelope __P((ENVELOPE *));
884extern void clearenvelope __P((ENVELOPE *, bool));
885extern char *username __P(());
886extern MCI *mci_get __P((char *, MAILER *));
887extern char *pintvl __P((time_t, bool));
888extern char *sfgets __P((char *, int, FILE *, time_t));
889extern char *map_rewrite __P((MAP *, char *, int, char **));
890extern ADDRESS *getctladdr __P((ADDRESS *));
891extern char *anynet_ntoa __P((SOCKADDR *));
892extern char *remotename __P((char *, MAILER *, int, int *, ENVELOPE *));
893extern bool shouldqueue __P((long, time_t));
894extern bool lockfile __P((int, char *, int));
895extern char *hostsignature __P((MAILER *, char *, ENVELOPE *));
896extern void openxscript __P((ENVELOPE *));
897extern void closexscript __P((ENVELOPE *));
58633cc7
EA
898
899/* ellipsis is a different case though */
900#ifdef __STDC__
34025690
EA
901extern void auth_warning(ENVELOPE *, const char *, ...);
902extern void syserr(const char *, ...);
903extern void usrerr(const char *, ...);
904extern void message(const char *, ...);
905extern void nmessage(const char *, ...);
58633cc7 906#else
713c523f
EA
907extern void auth_warning();
908extern void syserr();
909extern void usrerr();
910extern void message();
911extern void nmessage();
58633cc7 912#endif
70aca632
EA
913
914/*
915** HACK to fix bug in C compiler on CCI
916*/
917
918#undef isascii
5eddb1af 919#define isascii(x) (((x) & ~0177) == 0)