This commit was manufactured by cvs2svn to create tag 'FreeBSD-release/1.1'.
[unix-history] / usr.sbin / sendmail / src / sendmail.h
CommitLineData
15637ed4
RG
1/*
2 * Copyright (c) 1983 Eric P. Allman
6f14531a
RG
3 * Copyright (c) 1988, 1993
4 * The Regents of the University of California. All rights reserved.
15637ed4
RG
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
c2714ef5 34 * @(#)sendmail.h 8.41 (Berkeley) 2/6/94
15637ed4
RG
35 */
36
37/*
38** SENDMAIL.H -- Global definitions for sendmail.
39*/
40
41# ifdef _DEFINE
42# define EXTERN
43# ifndef lint
c2714ef5 44static char SmailSccsId[] = "@(#)sendmail.h 8.41 2/6/94";
6f14531a
RG
45# endif
46# else /* _DEFINE */
15637ed4 47# define EXTERN extern
6f14531a 48# endif /* _DEFINE */
15637ed4 49
6f14531a
RG
50# include <unistd.h>
51# include <stddef.h>
52# include <stdlib.h>
15637ed4
RG
53# include <stdio.h>
54# include <ctype.h>
55# include <setjmp.h>
6f14531a
RG
56# include <sysexits.h>
57# include <string.h>
58# include <time.h>
59# include <errno.h>
60
15637ed4
RG
61# include "conf.h"
62# include "useful.h"
63
64# ifdef LOG
6f14531a
RG
65# include <syslog.h>
66# endif /* LOG */
15637ed4
RG
67
68# ifdef DAEMON
15637ed4 69# include <sys/socket.h>
6f14531a 70# endif
042b8fbf
AM
71# ifdef NETUNIX
72# include <sys/un.h>
73# endif
6f14531a 74# ifdef NETINET
15637ed4 75# include <netinet/in.h>
6f14531a
RG
76# endif
77# ifdef NETISO
78# include <netiso/iso.h>
79# endif
80# ifdef NETNS
81# include <netns/ns.h>
82# endif
83# ifdef NETX25
84# include <netccitt/x25.h>
85# endif
15637ed4
RG
86
87
15637ed4
RG
88
89
90/*
91** Data structure for bit maps.
92**
93** Each bit in this map can be referenced by an ascii character.
94** This is 128 possible bits, or 12 8-bit bytes.
95*/
96
97#define BITMAPBYTES 16 /* number of bytes in a bit map */
98#define BYTEBITS 8 /* number of bits in a byte */
99
100/* internal macros */
101#define _BITWORD(bit) (bit / (BYTEBITS * sizeof (int)))
102#define _BITBIT(bit) (1 << (bit % (BYTEBITS * sizeof (int))))
103
104typedef int BITMAP[BITMAPBYTES / sizeof (int)];
105
106/* test bit number N */
107#define bitnset(bit, map) ((map)[_BITWORD(bit)] & _BITBIT(bit))
108
109/* set bit number N */
110#define setbitn(bit, map) (map)[_BITWORD(bit)] |= _BITBIT(bit)
111
112/* clear bit number N */
113#define clrbitn(bit, map) (map)[_BITWORD(bit)] &= ~_BITBIT(bit)
114
115/* clear an entire bit map */
116#define clrbitmap(map) bzero((char *) map, BITMAPBYTES)
117\f/*
118** Address structure.
119** Addresses are stored internally in this structure.
120*/
121
122struct address
123{
124 char *q_paddr; /* the printname for the address */
125 char *q_user; /* user name */
126 char *q_ruser; /* real user name, or NULL if q_user */
127 char *q_host; /* host name */
128 struct mailer *q_mailer; /* mailer to use */
129 u_short q_flags; /* status flags, see below */
6f14531a
RG
130 uid_t q_uid; /* user-id of receiver (if known) */
131 gid_t q_gid; /* group-id of receiver (if known) */
15637ed4
RG
132 char *q_home; /* home dir (local mailer only) */
133 char *q_fullname; /* full name if known */
134 struct address *q_next; /* chain */
135 struct address *q_alias; /* address this results from */
6f14531a 136 char *q_owner; /* owner of q_alias */
15637ed4
RG
137 struct address *q_tchain; /* temporary use chain */
138 time_t q_timeout; /* timeout for this address */
139};
140
141typedef struct address ADDRESS;
142
143# define QDONTSEND 000001 /* don't send to this address */
144# define QBADADDR 000002 /* this address is verified bad */
145# define QGOODUID 000004 /* the q_uid q_gid fields are good */
146# define QPRIMARY 000010 /* set from argv */
147# define QQUEUEUP 000020 /* queue for later transmission */
148# define QSENT 000040 /* has been successfully delivered */
6f14531a
RG
149# define QNOTREMOTE 000100 /* not an address for remote forwarding */
150# define QSELFREF 000200 /* this address references itself */
151# define QVERIFIED 000400 /* verified, but not expanded */
3a363396 152# define QREPORT 001000 /* report this address in return message */
042b8fbf
AM
153# define QBOGUSSHELL 002000 /* this entry has an invalid shell listed */
154# define QUNSAFEADDR 004000 /* address aquired through an unsafe path */
d747e748
JH
155
156# define NULLADDR ((ADDRESS *) NULL)
15637ed4
RG
157\f/*
158** Mailer definition structure.
159** Every mailer known to the system is declared in this
160** structure. It defines the pathname of the mailer, some
161** flags associated with it, and the argument vector to
162** pass to it. The flags are defined in conf.c
163**
164** The argument vector is expanded before actual use. All
165** words except the first are passed through the macro
166** processor.
167*/
168
169struct mailer
170{
171 char *m_name; /* symbolic name of this mailer */
172 char *m_mailer; /* pathname of the mailer to use */
173 BITMAP m_flags; /* status flags, see below */
174 short m_mno; /* mailer number internally */
175 char **m_argv; /* template argument vector */
6f14531a
RG
176 short m_sh_rwset; /* rewrite set: sender header addresses */
177 short m_se_rwset; /* rewrite set: sender envelope addresses */
178 short m_rh_rwset; /* rewrite set: recipient header addresses */
179 short m_re_rwset; /* rewrite set: recipient envelope addresses */
15637ed4
RG
180 char *m_eol; /* end of line string */
181 long m_maxsize; /* size limit on message to this mailer */
6f14531a
RG
182 int m_linelimit; /* max # characters per line */
183 char *m_execdir; /* directory to chdir to before execv */
15637ed4
RG
184};
185
186typedef struct mailer MAILER;
187
188/* bits for m_flags */
6f14531a
RG
189# define M_ESMTP 'a' /* run Extended SMTP protocol */
190# define M_BLANKEND 'b' /* ensure blank line at end of message */
191# define M_NOCOMMENT 'c' /* don't include comment part of address */
15637ed4 192# define M_CANONICAL 'C' /* make addresses canonical "u@dom" */
6f14531a 193 /* 'D' /* CF: include Date: */
15637ed4
RG
194# define M_EXPENSIVE 'e' /* it costs to use this mailer.... */
195# define M_ESCFROM 'E' /* escape From lines to >From */
196# define M_FOPT 'f' /* mailer takes picky -f flag */
6f14531a
RG
197 /* 'F' /* CF: include From: or Resent-From: */
198# define M_NO_NULL_FROM 'g' /* sender of errors should be $g */
15637ed4 199# define M_HST_UPPER 'h' /* preserve host case distinction */
d747e748 200# define M_PREHEAD 'H' /* MAIL11V3: preview headers */
15637ed4 201# define M_INTERNAL 'I' /* SMTP to another sendmail site */
6f14531a 202# define M_LOCALMAILER 'l' /* delivery is to this host */
15637ed4
RG
203# define M_LIMITS 'L' /* must enforce SMTP line limits */
204# define M_MUSER 'm' /* can handle multiple users at once */
6f14531a 205 /* 'M' /* CF: include Message-Id: */
15637ed4 206# define M_NHDR 'n' /* don't insert From line */
d747e748 207# define M_MANYSTATUS 'N' /* MAIL11V3: DATA returns multi-status */
15637ed4 208# define M_FROMPATH 'p' /* use reverse-path in MAIL FROM: */
6f14531a 209 /* 'P' /* CF: include Return-Path: */
15637ed4
RG
210# define M_ROPT 'r' /* mailer takes picky -r flag */
211# define M_SECURE_PORT 'R' /* try to send on a reserved TCP port */
212# define M_STRIPQ 's' /* strip quote chars from user/host */
213# define M_RESTR 'S' /* must be daemon to execute */
214# define M_USR_UPPER 'u' /* preserve user case distinction */
215# define M_UGLYUUCP 'U' /* this wants an ugly UUCP from line */
6f14531a
RG
216 /* 'V' /* UIUC: !-relativize all addresses */
217 /* 'x' /* CF: include Full-Name: */
15637ed4 218# define M_XDOT 'X' /* use hidden-dot algorithm */
6f14531a 219# define M_7BITS '7' /* use 7-bit path */
15637ed4
RG
220
221EXTERN MAILER *Mailer[MAXMAILERS+1];
222
223EXTERN MAILER *LocalMailer; /* ptr to local mailer */
224EXTERN MAILER *ProgMailer; /* ptr to program mailer */
6f14531a
RG
225EXTERN MAILER *FileMailer; /* ptr to *file* mailer */
226EXTERN MAILER *InclMailer; /* ptr to *include* mailer */
15637ed4
RG
227\f/*
228** Header structure.
229** This structure is used internally to store header items.
230*/
231
232struct header
233{
234 char *h_field; /* the name of the field */
235 char *h_value; /* the value of that field */
236 struct header *h_link; /* the next header */
237 u_short h_flags; /* status bits, see below */
238 BITMAP h_mflags; /* m_flags bits needed */
239};
240
241typedef struct header HDR;
242
243/*
244** Header information structure.
245** Defined in conf.c, this struct declares the header fields
246** that have some magic meaning.
247*/
248
249struct hdrinfo
250{
251 char *hi_field; /* the name of the field */
252 u_short hi_flags; /* status bits, see below */
253};
254
255extern struct hdrinfo HdrInfo[];
256
257/* bits for h_flags and hi_flags */
258# define H_EOH 00001 /* this field terminates header */
259# define H_RCPT 00002 /* contains recipient addresses */
260# define H_DEFAULT 00004 /* if another value is found, drop this */
261# define H_RESENT 00010 /* this address is a "Resent-..." address */
262# define H_CHECK 00020 /* check h_mflags against m_flags */
263# define H_ACHECK 00040 /* ditto, but always (not just default) */
264# define H_FORCE 00100 /* force this field, even if default */
265# define H_TRACE 00200 /* this field contains trace information */
266# define H_FROM 00400 /* this is a from-type field */
267# define H_VALID 01000 /* this field has a validated value */
6f14531a
RG
268# define H_RECEIPTTO 02000 /* this field has return receipt info */
269# define H_ERRORSTO 04000 /* this field has error address info */
15637ed4 270\f/*
c2714ef5 271** Information about currently open connections to mailers, or to
272** hosts that we have looked up recently.
273*/
274
275# define MCI struct mailer_con_info
276
277MCI
278{
279 short mci_flags; /* flag bits, see below */
280 short mci_errno; /* error number on last connection */
281 short mci_herrno; /* h_errno from last DNS lookup */
282 short mci_exitstat; /* exit status from last connection */
283 short mci_state; /* SMTP state */
284 long mci_maxsize; /* max size this server will accept */
285 FILE *mci_in; /* input side of connection */
286 FILE *mci_out; /* output side of connection */
287 int mci_pid; /* process id of subordinate proc */
288 char *mci_phase; /* SMTP phase string */
289 struct mailer *mci_mailer; /* ptr to the mailer for this conn */
290 char *mci_host; /* host name */
291 time_t mci_lastuse; /* last usage time */
292};
293
294
295/* flag bits */
296#define MCIF_VALID 000001 /* this entry is valid */
297#define MCIF_TEMP 000002 /* don't cache this connection */
298#define MCIF_CACHED 000004 /* currently in open cache */
299#define MCIF_ESMTP 000010 /* this host speaks ESMTP */
300#define MCIF_EXPN 000020 /* EXPN command supported */
301#define MCIF_SIZE 000040 /* SIZE option supported */
302#define MCIF_8BITMIME 000100 /* BODY=8BITMIME supported */
303#define MCIF_7BIT 000200 /* strip this message to 7 bits */
304#define MCIF_MULTSTAT 000400 /* MAIL11V3: handles MULT status */
305
306/* states */
307#define MCIS_CLOSED 0 /* no traffic on this connection */
308#define MCIS_OPENING 1 /* sending initial protocol */
309#define MCIS_OPEN 2 /* open, initial protocol sent */
310#define MCIS_ACTIVE 3 /* message being sent */
311#define MCIS_QUITING 4 /* running quit protocol */
312#define MCIS_SSD 5 /* service shutting down */
313#define MCIS_ERROR 6 /* I/O error on connection */
314\f/*
15637ed4
RG
315** Envelope structure.
316** This structure defines the message itself. There is usually
317** only one of these -- for the message that we originally read
318** and which is our primary interest -- but other envelopes can
319** be generated during processing. For example, error messages
320** will have their own envelope.
321*/
322
6f14531a
RG
323# define ENVELOPE struct envelope
324
325ENVELOPE
15637ed4
RG
326{
327 HDR *e_header; /* head of header list */
328 long e_msgpriority; /* adjusted priority of this message */
329 time_t e_ctime; /* time message appeared in the queue */
330 char *e_to; /* the target person */
331 char *e_receiptto; /* return receipt address */
332 ADDRESS e_from; /* the person it is from */
6f14531a 333 char *e_sender; /* e_from.q_paddr w comments stripped */
15637ed4
RG
334 char **e_fromdomain; /* the domain part of the sender */
335 ADDRESS *e_sendqueue; /* list of message recipients */
336 ADDRESS *e_errorqueue; /* the queue for error responses */
337 long e_msgsize; /* size of the message in bytes */
042b8fbf 338 long e_flags; /* flags, see below */
15637ed4
RG
339 int e_nrcpts; /* number of recipients */
340 short e_class; /* msg class (priority, junk, etc.) */
15637ed4 341 short e_hopcount; /* number of times processed */
6f14531a
RG
342 short e_nsent; /* number of sends since checkpoint */
343 short e_sendmode; /* message send mode */
344 short e_errormode; /* error return mode */
c2714ef5 345 int (*e_puthdr)__P((MCI *, ENVELOPE *));
6f14531a 346 /* function to put header of message */
c2714ef5 347 int (*e_putbody)__P((MCI *, ENVELOPE *, char *));
6f14531a 348 /* function to put body of message */
15637ed4
RG
349 struct envelope *e_parent; /* the message this one encloses */
350 struct envelope *e_sibling; /* the next envelope of interest */
6f14531a 351 char *e_bodytype; /* type of message body */
15637ed4
RG
352 char *e_df; /* location of temp file */
353 FILE *e_dfp; /* temporary file */
354 char *e_id; /* code for this entry in queue */
355 FILE *e_xfp; /* transcript file */
6f14531a 356 FILE *e_lockfp; /* the lock file for this message */
15637ed4 357 char *e_message; /* error message */
6f14531a
RG
358 char *e_statmsg; /* stat msg (changes per delivery) */
359 char *e_msgboundary; /* MIME-style message part boundary */
d747e748 360 char *e_origrcpt; /* original recipient (one only) */
15637ed4
RG
361 char *e_macro[128]; /* macro definitions */
362};
363
15637ed4 364/* values for e_flags */
042b8fbf
AM
365#define EF_OLDSTYLE 0x0000001 /* use spaces (not commas) in hdrs */
366#define EF_INQUEUE 0x0000002 /* this message is fully queued */
367#define EF_CLRQUEUE 0x0000008 /* disk copy is no longer needed */
368#define EF_SENDRECEIPT 0x0000010 /* send a return receipt */
369#define EF_FATALERRS 0x0000020 /* fatal errors occured */
370#define EF_KEEPQUEUE 0x0000040 /* keep queue files always */
371#define EF_RESPONSE 0x0000080 /* this is an error or return receipt */
372#define EF_RESENT 0x0000100 /* this message is being forwarded */
373#define EF_VRFYONLY 0x0000200 /* verify only (don't expand aliases) */
374#define EF_WARNING 0x0000400 /* warning message has been sent */
375#define EF_QUEUERUN 0x0000800 /* this envelope is from queue */
376#define EF_GLOBALERRS 0x0001000 /* treat errors as global */
377#define EF_PM_NOTIFY 0x0002000 /* send return mail to postmaster */
378#define EF_METOO 0x0004000 /* send to me too */
379#define EF_LOGSENDER 0x0008000 /* need to log the sender */
15637ed4
RG
380
381EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */
382\f/*
383** Message priority classes.
384**
385** The message class is read directly from the Priority: header
386** field in the message.
387**
388** CurEnv->e_msgpriority is the number of bytes in the message plus
389** the creation time (so that jobs ``tend'' to be ordered correctly),
390** adjusted by the message class, the number of recipients, and the
391** amount of time the message has been sitting around. This number
392** is used to order the queue. Higher values mean LOWER priority.
393**
394** Each priority class point is worth WkClassFact priority points;
395** each recipient is worth WkRecipFact priority points. Each time
396** we reprocess a message the priority is adjusted by WkTimeFact.
397** WkTimeFact should normally decrease the priority so that jobs
398** that have historically failed will be run later; thanks go to
399** Jay Lepreau at Utah for pointing out the error in my thinking.
400**
401** The "class" is this number, unadjusted by the age or size of
402** this message. Classes with negative representations will have
403** error messages thrown away if they are not local.
404*/
405
406struct priority
407{
408 char *pri_name; /* external name of priority */
409 int pri_val; /* internal value for same */
410};
411
412EXTERN struct priority Priorities[MAXPRIORITIES];
413EXTERN int NumPriorities; /* pointer into Priorities */
414\f/*
415** Rewrite rules.
416*/
417
418struct rewrite
419{
420 char **r_lhs; /* pattern match */
421 char **r_rhs; /* substitution value */
422 struct rewrite *r_next;/* next in chain */
423};
424
425EXTERN struct rewrite *RewriteRules[MAXRWSETS];
426
427/*
428** Special characters in rewriting rules.
429** These are used internally only.
430** The COND* rules are actually used in macros rather than in
431** rewriting rules, but are given here because they
432** cannot conflict.
433*/
434
435/* left hand side items */
6f14531a
RG
436# define MATCHZANY 0220 /* match zero or more tokens */
437# define MATCHANY 0221 /* match one or more tokens */
438# define MATCHONE 0222 /* match exactly one token */
439# define MATCHCLASS 0223 /* match one token in a class */
440# define MATCHNCLASS 0224 /* match anything not in class */
441# define MATCHREPL 0225 /* replacement on RHS for above */
15637ed4
RG
442
443/* right hand side items */
6f14531a
RG
444# define CANONNET 0226 /* canonical net, next token */
445# define CANONHOST 0227 /* canonical host, next token */
446# define CANONUSER 0230 /* canonical user, next N tokens */
447# define CALLSUBR 0231 /* call another rewriting set */
15637ed4
RG
448
449/* conditionals in macros */
6f14531a
RG
450# define CONDIF 0232 /* conditional if-then */
451# define CONDELSE 0233 /* conditional else */
452# define CONDFI 0234 /* conditional fi */
15637ed4
RG
453
454/* bracket characters for host name lookup */
6f14531a
RG
455# define HOSTBEGIN 0235 /* hostname lookup begin */
456# define HOSTEND 0236 /* hostname lookup end */
457
458/* bracket characters for generalized lookup */
459# define LOOKUPBEGIN 0205 /* generalized lookup begin */
460# define LOOKUPEND 0206 /* generalized lookup end */
461
462/* macro substitution character */
463# define MACROEXPAND 0201 /* macro expansion */
464# define MACRODEXPAND 0202 /* deferred macro expansion */
15637ed4 465
6f14531a
RG
466/* to make the code clearer */
467# define MATCHZERO CANONHOST
468
469/* external <==> internal mapping table */
470struct metamac
471{
472 char metaname; /* external code (after $) */
d747e748 473 u_char metaval; /* internal code (as above) */
6f14531a 474};
15637ed4 475\f/*
6f14531a 476** Name canonification short circuit.
15637ed4 477**
6f14531a
RG
478** If the name server for a host is down, the process of trying to
479** canonify the name can hang. This is similar to (but alas, not
480** identical to) looking up the name for delivery. This stab type
481** caches the result of the name server lookup so we don't hang
482** multiple times.
15637ed4
RG
483*/
484
6f14531a
RG
485#define NAMECANON struct _namecanon
486
487NAMECANON
488{
489 short nc_errno; /* cached errno */
490 short nc_herrno; /* cached h_errno */
491 short nc_stat; /* cached exit status code */
492 short nc_flags; /* flag bits */
493 char *nc_cname; /* the canonical name */
494};
495
496/* values for nc_flags */
497#define NCF_VALID 0x0001 /* entry valid */
498\f/*
499** Mapping functions
500**
501** These allow arbitrary mappings in the config file. The idea
502** (albeit not the implementation) comes from IDA sendmail.
503*/
504
505# define MAPCLASS struct _mapclass
506# define MAP struct _map
507
15637ed4 508
6f14531a
RG
509/*
510** An actual map.
511*/
15637ed4 512
6f14531a 513MAP
15637ed4 514{
6f14531a
RG
515 MAPCLASS *map_class; /* the class of this map */
516 char *map_mname; /* name of this map */
517 int map_mflags; /* flags, see below */
518 char *map_file; /* the (nominal) filename */
d747e748
JH
519 ARBPTR_T map_db1; /* the open database ptr */
520 ARBPTR_T map_db2; /* an "extra" database pointer */
6f14531a
RG
521 char *map_app; /* to append to successful matches */
522 char *map_domain; /* the (nominal) NIS domain */
523 char *map_rebuild; /* program to run to do auto-rebuild */
d747e748 524 time_t map_mtime; /* last database modification time */
15637ed4
RG
525};
526
6f14531a
RG
527/* bit values for map_flags */
528# define MF_VALID 0x0001 /* this entry is valid */
529# define MF_INCLNULL 0x0002 /* include null byte in key */
530# define MF_OPTIONAL 0x0004 /* don't complain if map not found */
531# define MF_NOFOLDCASE 0x0008 /* don't fold case in keys */
532# define MF_MATCHONLY 0x0010 /* don't use the map value */
533# define MF_OPEN 0x0020 /* this entry is open */
534# define MF_WRITABLE 0x0040 /* open for writing */
535# define MF_ALIAS 0x0080 /* this is an alias file */
3a363396
NW
536# define MF_TRY0NULL 0x0100 /* try with no null byte */
537# define MF_TRY1NULL 0x0200 /* try with the null byte */
d747e748
JH
538# define MF_LOCKED 0x0400 /* this map is currently locked */
539# define MF_ALIASWAIT 0x0800 /* alias map in aliaswait state */
6f14531a
RG
540# define MF_IMPL_HASH 0x1000 /* implicit: underlying hash database */
541# define MF_IMPL_NDBM 0x2000 /* implicit: underlying NDBM database */
15637ed4 542
15637ed4 543
6f14531a
RG
544/*
545** The class of a map -- essentially the functions to call
546*/
547
548MAPCLASS
549{
550 char *map_cname; /* name of this map class */
551 char *map_ext; /* extension for database file */
552 short map_cflags; /* flag bits, see below */
553 bool (*map_parse)__P((MAP *, char *));
554 /* argument parsing function */
555 char *(*map_lookup)__P((MAP *, char *, char **, int *));
556 /* lookup function */
557 void (*map_store)__P((MAP *, char *, char *));
558 /* store function */
559 bool (*map_open)__P((MAP *, int));
560 /* open function */
561 void (*map_close)__P((MAP *));
562 /* close function */
563};
564
565/* bit values for map_cflags */
566#define MCF_ALIASOK 0x0001 /* can be used for aliases */
567#define MCF_ALIASONLY 0x0002 /* usable only for aliases */
568#define MCF_REBUILDABLE 0x0004 /* can rebuild alias files */
15637ed4
RG
569\f/*
570** Symbol table definitions
571*/
572
573struct symtab
574{
575 char *s_name; /* name to be entered */
576 char s_type; /* general type (see below) */
577 struct symtab *s_next; /* pointer to next in chain */
578 union
579 {
580 BITMAP sv_class; /* bit-map of word classes */
581 ADDRESS *sv_addr; /* pointer to address header */
582 MAILER *sv_mailer; /* pointer to mailer */
583 char *sv_alias; /* alias */
6f14531a
RG
584 MAPCLASS sv_mapclass; /* mapping function class */
585 MAP sv_map; /* mapping function */
586 char *sv_hostsig; /* host signature */
587 MCI sv_mci; /* mailer connection info */
588 NAMECANON sv_namecanon; /* canonical name cache */
15637ed4
RG
589 } s_value;
590};
591
592typedef struct symtab STAB;
593
594/* symbol types */
595# define ST_UNDEF 0 /* undefined type */
596# define ST_CLASS 1 /* class map */
597# define ST_ADDRESS 2 /* an address in parsed format */
598# define ST_MAILER 3 /* a mailer header */
599# define ST_ALIAS 4 /* an alias */
6f14531a
RG
600# define ST_MAPCLASS 5 /* mapping function class */
601# define ST_MAP 6 /* mapping function */
602# define ST_HOSTSIG 7 /* host signature */
603# define ST_NAMECANON 8 /* cached canonical name */
604# define ST_MCI 16 /* mailer connection info (offset) */
15637ed4
RG
605
606# define s_class s_value.sv_class
607# define s_address s_value.sv_addr
608# define s_mailer s_value.sv_mailer
609# define s_alias s_value.sv_alias
6f14531a
RG
610# define s_mci s_value.sv_mci
611# define s_mapclass s_value.sv_mapclass
612# define s_hostsig s_value.sv_hostsig
613# define s_map s_value.sv_map
614# define s_namecanon s_value.sv_namecanon
15637ed4 615
6f14531a
RG
616extern STAB *stab __P((char *, int, int));
617extern void stabapply __P((void (*)(STAB *, int), int));
15637ed4
RG
618
619/* opcodes to stab */
620# define ST_FIND 0 /* find entry */
621# define ST_ENTER 1 /* enter if not there */
622\f/*
623** STRUCT EVENT -- event queue.
624**
625** Maintained in sorted order.
626**
627** We store the pid of the process that set this event to insure
628** that when we fork we will not take events intended for the parent.
629*/
630
631struct event
632{
633 time_t ev_time; /* time of the function call */
6f14531a
RG
634 int (*ev_func)__P((int));
635 /* function to call */
15637ed4
RG
636 int ev_arg; /* argument to ev_func */
637 int ev_pid; /* pid that set this event */
638 struct event *ev_link; /* link to next item */
639};
640
641typedef struct event EVENT;
642
643EXTERN EVENT *EventQueue; /* head of event queue */
644\f/*
645** Operation, send, and error modes
646**
647** The operation mode describes the basic operation of sendmail.
648** This can be set from the command line, and is "send mail" by
649** default.
650**
651** The send mode tells how to send mail. It can be set in the
652** configuration file. It's setting determines how quickly the
653** mail will be delivered versus the load on your system. If the
654** -v (verbose) flag is given, it will be forced to SM_DELIVER
655** mode.
656**
657** The error mode tells how to return errors.
658*/
659
660EXTERN char OpMode; /* operation mode, see below */
661
662#define MD_DELIVER 'm' /* be a mail sender */
15637ed4 663#define MD_SMTP 's' /* run SMTP on standard input */
c2714ef5 664#define MD_ARPAFTP 'a' /* obsolete ARPANET mode (Grey Book) */
15637ed4
RG
665#define MD_DAEMON 'd' /* run as a daemon */
666#define MD_VERIFY 'v' /* verify: don't collect or deliver */
667#define MD_TEST 't' /* test mode: resolve addrs only */
668#define MD_INITALIAS 'i' /* initialize alias database */
669#define MD_PRINT 'p' /* print the queue */
670#define MD_FREEZE 'z' /* freeze the configuration file */
671
672
6f14531a 673/* values for e_sendmode -- send modes */
15637ed4
RG
674#define SM_DELIVER 'i' /* interactive delivery */
675#define SM_QUICKD 'j' /* deliver w/o queueing */
676#define SM_FORK 'b' /* deliver in background */
677#define SM_QUEUE 'q' /* queue, don't deliver */
678#define SM_VERIFY 'v' /* verify only (used internally) */
679
680/* used only as a parameter to sendall */
681#define SM_DEFAULT '\0' /* unspecified, use SendMode */
682
683
6f14531a 684/* values for e_errormode -- error handling modes */
15637ed4
RG
685#define EM_PRINT 'p' /* print errors */
686#define EM_MAIL 'm' /* mail back errors */
687#define EM_WRITE 'w' /* write back errors */
688#define EM_BERKNET 'e' /* special berknet processing */
689#define EM_QUIET 'q' /* don't print messages (stat only) */
6f14531a
RG
690\f/*
691** Additional definitions
692*/
15637ed4 693
6f14531a 694
6f14531a
RG
695/*
696** Privacy flags
697** These are bit values for the PrivacyFlags word.
698*/
699
700#define PRIV_PUBLIC 0 /* what have I got to hide? */
701#define PRIV_NEEDMAILHELO 00001 /* insist on HELO for MAIL, at least */
702#define PRIV_NEEDEXPNHELO 00002 /* insist on HELO for EXPN */
703#define PRIV_NEEDVRFYHELO 00004 /* insist on HELO for VRFY */
704#define PRIV_NOEXPN 00010 /* disallow EXPN command entirely */
705#define PRIV_NOVRFY 00020 /* disallow VRFY command entirely */
706#define PRIV_AUTHWARNINGS 00040 /* flag possible authorization probs */
d747e748
JH
707#define PRIV_RESTRICTMAILQ 01000 /* restrict mailq command */
708#define PRIV_RESTRICTQRUN 02000 /* restrict queue run */
6f14531a
RG
709#define PRIV_GOAWAY 00777 /* don't give no info, anyway, anyhow */
710
711/* struct defining such things */
712struct prival
713{
714 char *pv_name; /* name of privacy flag */
715 int pv_flag; /* numeric level */
716};
717
718
719/*
d747e748 720** Flags passed to remotename, parseaddr, allocaddr, and buildaddr.
6f14531a
RG
721*/
722
723#define RF_SENDERADDR 0001 /* this is a sender address */
724#define RF_HEADERADDR 0002 /* this is a header address */
725#define RF_CANONICAL 0004 /* strip comment information */
726#define RF_ADDDOMAIN 0010 /* OK to do domain extension */
d747e748
JH
727#define RF_COPYPARSE 0020 /* copy parsed user & host */
728#define RF_COPYPADDR 0040 /* copy print address */
729#define RF_COPYALL (RF_COPYPARSE|RF_COPYPADDR)
730#define RF_COPYNONE 0
6f14531a 731
042b8fbf
AM
732
733/*
734** Flags passed to safefile.
735*/
736
737#define SFF_ANYFILE 0 /* no special restrictions */
738#define SFF_MUSTOWN 0x0001 /* user must own this file */
739#define SFF_NOSLINK 0x0002 /* file cannot be a symbolic link */
740#define SFF_ROOTOK 0x0004 /* ok for root to own this file */
741
742
6f14531a
RG
743/*
744** Regular UNIX sockaddrs are too small to handle ISO addresses, so
745** we are forced to declare a supertype here.
746*/
747
748union bigsockaddr
749{
750 struct sockaddr sa; /* general version */
042b8fbf 751#ifdef NETUNIX
69fc843f 752 struct sockaddr_un sunix; /* UNIX family */
042b8fbf 753#endif
6f14531a
RG
754#ifdef NETINET
755 struct sockaddr_in sin; /* INET family */
756#endif
757#ifdef NETISO
758 struct sockaddr_iso siso; /* ISO family */
759#endif
760#ifdef NETNS
761 struct sockaddr_ns sns; /* XNS family */
762#endif
763#ifdef NETX25
764 struct sockaddr_x25 sx25; /* X.25 family */
765#endif
766};
767
768#define SOCKADDR union bigsockaddr
15637ed4
RG
769\f/*
770** Global variables.
771*/
772
773EXTERN bool FromFlag; /* if set, "From" person is explicit */
15637ed4
RG
774EXTERN bool MeToo; /* send to the sender also */
775EXTERN bool IgnrDot; /* don't let dot end messages */
776EXTERN bool SaveFrom; /* save leading "From" lines */
777EXTERN bool Verbose; /* set if blow-by-blow desired */
778EXTERN bool GrabTo; /* if set, get recipients from msg */
779EXTERN bool NoReturn; /* don't return letter to sender */
780EXTERN bool SuprErrs; /* set if we are suppressing errors */
15637ed4
RG
781EXTERN bool HoldErrs; /* only output errors to transcript */
782EXTERN bool NoConnect; /* don't connect to non-local mailers */
783EXTERN bool SuperSafe; /* be extra careful, even if expensive */
784EXTERN bool ForkQueueRuns; /* fork for each job when running the queue */
785EXTERN bool AutoRebuild; /* auto-rebuild the alias database as needed */
786EXTERN bool CheckAliases; /* parse addresses during newaliases */
6f14531a 787EXTERN bool NoAlias; /* suppress aliasing */
15637ed4 788EXTERN bool UseNameServer; /* use internet domain name server */
6f14531a 789EXTERN bool SevenBit; /* force 7-bit data */
69fc843f 790EXTERN time_t SafeAlias; /* interval to wait until @:@ in alias file */
15637ed4
RG
791EXTERN FILE *InChannel; /* input connection */
792EXTERN FILE *OutChannel; /* output connection */
6f14531a
RG
793EXTERN uid_t RealUid; /* when Daemon, real uid of caller */
794EXTERN gid_t RealGid; /* when Daemon, real gid of caller */
795EXTERN uid_t DefUid; /* default uid to run as */
796EXTERN gid_t DefGid; /* default gid to run as */
15637ed4 797EXTERN char *DefUser; /* default user to run as (from DefUid) */
15637ed4
RG
798EXTERN int OldUmask; /* umask when sendmail starts up */
799EXTERN int Errors; /* set if errors (local to single pass) */
800EXTERN int ExitStat; /* exit status code */
801EXTERN int AliasLevel; /* depth of aliasing */
15637ed4 802EXTERN int LineNumber; /* line number in current input */
15637ed4
RG
803EXTERN int LogLevel; /* level of logging to perform */
804EXTERN int FileMode; /* mode on files */
805EXTERN int QueueLA; /* load average starting forced queueing */
806EXTERN int RefuseLA; /* load average refusing connections are */
6f14531a
RG
807EXTERN int CurrentLA; /* current load average */
808EXTERN long QueueFactor; /* slope of queue function */
15637ed4 809EXTERN time_t QueueIntvl; /* intervals between running the queue */
15637ed4 810EXTERN char *HelpFile; /* location of SMTP help file */
6f14531a 811EXTERN char *ErrMsgFile; /* file to prepend to all error messages */
15637ed4
RG
812EXTERN char *StatFile; /* location of statistics summary */
813EXTERN char *QueueDir; /* location of queue directory */
814EXTERN char *FileName; /* name to print on error messages */
815EXTERN char *SmtpPhase; /* current phase in SMTP processing */
816EXTERN char *MyHostName; /* name of this host for SMTP messages */
817EXTERN char *RealHostName; /* name of host we are talking to */
6f14531a 818EXTERN SOCKADDR RealHostAddr; /* address of host we are talking to */
15637ed4
RG
819EXTERN char *CurHostName; /* current host we are dealing with */
820EXTERN jmp_buf TopFrame; /* branch-to-top-of-loop-on-error frame */
821EXTERN bool QuickAbort; /* .... but only if we want a quick abort */
6f14531a
RG
822EXTERN bool LogUsrErrs; /* syslog user errors (e.g., SMTP RCPT cmd) */
823EXTERN bool SendMIMEErrors; /* send error messages in MIME format */
824EXTERN bool MatchGecos; /* look for user names in gecos field */
825EXTERN bool UseErrorsTo; /* use Errors-To: header (back compat) */
d747e748 826EXTERN bool TryNullMXList; /* if we are the best MX, try host directly */
042b8fbf 827extern bool CheckLoopBack; /* check for loopback on HELO packet */
d747e748 828EXTERN bool InChild; /* true if running in an SMTP subprocess */
c2714ef5 829EXTERN bool DisConnected; /* running with OutChannel redirected to xf */
6f14531a
RG
830EXTERN char SpaceSub; /* substitution for <lwsp> */
831EXTERN int PrivacyFlags; /* privacy flags */
d747e748 832EXTERN char *ConfFile; /* location of configuration file [conf.c] */
6f14531a 833extern char *PidFile; /* location of proc id file [conf.c] */
15637ed4 834extern ADDRESS NullAddress; /* a null (template) address [main.c] */
6f14531a
RG
835EXTERN long WkClassFact; /* multiplier for message class -> priority */
836EXTERN long WkRecipFact; /* multiplier for # of recipients -> priority */
837EXTERN long WkTimeFact; /* priority offset each time this job is run */
838EXTERN char *UdbSpec; /* user database source spec */
839EXTERN int MaxHopCount; /* max # of hops until bounce */
840EXTERN int ConfigLevel; /* config file level */
841EXTERN char *TimeZoneSpec; /* override time zone specification */
842EXTERN char *ForwardPath; /* path to search for .forward files */
843EXTERN long MinBlocksFree; /* min # of blocks free on queue fs */
844EXTERN char *FallBackMX; /* fall back MX host */
845EXTERN long MaxMessageSize; /* advertised max size we will accept */
15637ed4 846EXTERN char *PostMasterCopy; /* address to get errs cc's */
15637ed4 847EXTERN int CheckpointInterval; /* queue file checkpoint interval */
6f14531a 848EXTERN bool DontPruneRoutes; /* don't prune source routes */
042b8fbf 849extern bool BrokenSmtpPeers; /* peers can't handle 2-line greeting */
6f14531a
RG
850EXTERN int MaxMciCache; /* maximum entries in MCI cache */
851EXTERN time_t MciCacheTimeout; /* maximum idle time on connections */
852EXTERN char *QueueLimitRecipient; /* limit queue runs to this recipient */
853EXTERN char *QueueLimitSender; /* limit queue runs to this sender */
854EXTERN char *QueueLimitId; /* limit queue runs to this id */
3a363396 855EXTERN FILE *TrafficLogFile; /* file in which to log all traffic */
042b8fbf 856extern int errno;
6f14531a
RG
857
858
859/*
860** Timeouts
861**
862** Indicated values are the MINIMUM per RFC 1123 section 5.3.2.
863*/
864
865EXTERN struct
866{
d747e748 867 /* RFC 1123-specified timeouts [minimum value] */
6f14531a
RG
868 time_t to_initial; /* initial greeting timeout [5m] */
869 time_t to_mail; /* MAIL command [5m] */
870 time_t to_rcpt; /* RCPT command [5m] */
871 time_t to_datainit; /* DATA initiation [2m] */
872 time_t to_datablock; /* DATA block [3m] */
873 time_t to_datafinal; /* DATA completion [10m] */
874 time_t to_nextcommand; /* next command [5m] */
875 /* following timeouts are not mentioned in RFC 1123 */
876 time_t to_rset; /* RSET command */
877 time_t to_helo; /* HELO command */
878 time_t to_quit; /* QUIT command */
879 time_t to_miscshort; /* misc short commands (NOOP, VERB, etc) */
d747e748 880 time_t to_ident; /* IDENT protocol requests */
6f14531a
RG
881 /* following are per message */
882 time_t to_q_return; /* queue return timeout */
883 time_t to_q_warning; /* queue warning timeout */
884} TimeOuts;
885
886
887/*
15637ed4
RG
888** Trace information
889*/
890
891/* trace vector and macros for debugging flags */
892EXTERN u_char tTdvect[100];
893# define tTd(flag, level) (tTdvect[flag] >= level)
894# define tTdlevel(flag) (tTdvect[flag])
895\f/*
896** Miscellaneous information.
897*/
898
15637ed4
RG
899
900
901/*
902** Some in-line functions
903*/
904
905/* set exit status */
906#define setstat(s) { \
907 if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \
908 ExitStat = s; \
909 }
910
911/* make a copy of a string */
912#define newstr(s) strcpy(xalloc(strlen(s) + 1), s)
913
914#define STRUCTCOPY(s, d) d = s
915
916
917/*
918** Declarations of useful functions
919*/
920
6f14531a
RG
921extern ADDRESS *parseaddr __P((char *, ADDRESS *, int, int, char **, ENVELOPE *));
922extern char *xalloc __P((int));
923extern bool sameaddr __P((ADDRESS *, ADDRESS *));
924extern FILE *dfopen __P((char *, int, int));
925extern EVENT *setevent __P((time_t, int(*)(), int));
926extern char *sfgets __P((char *, int, FILE *, time_t, char *));
927extern char *queuename __P((ENVELOPE *, int));
928extern time_t curtime __P(());
929extern bool transienterror __P((int));
930extern const char *errstring __P((int));
931extern void expand __P((char *, char *, char *, ENVELOPE *));
932extern void define __P((int, char *, ENVELOPE *));
933extern char *macvalue __P((int, ENVELOPE *));
042b8fbf
AM
934extern char **prescan __P((char *, int, char[], int, char **));
935extern int rewrite __P((char **, int, int, ENVELOPE *));
6f14531a
RG
936extern char *fgetfolded __P((char *, int, FILE *));
937extern ADDRESS *recipient __P((ADDRESS *, ADDRESS **, ENVELOPE *));
938extern ENVELOPE *newenvelope __P((ENVELOPE *, ENVELOPE *));
939extern void dropenvelope __P((ENVELOPE *));
940extern void clearenvelope __P((ENVELOPE *, int));
941extern char *username __P(());
942extern MCI *mci_get __P((char *, MAILER *));
943extern char *pintvl __P((time_t, int));
944extern char *map_rewrite __P((MAP *, char *, int, char **));
945extern ADDRESS *getctladdr __P((ADDRESS *));
946extern char *anynet_ntoa __P((SOCKADDR *));
947extern char *remotename __P((char *, MAILER *, int, int *, ENVELOPE *));
948extern bool shouldqueue __P((long, time_t));
d747e748 949extern bool lockfile __P((int, char *, char *, int));
6f14531a
RG
950extern char *hostsignature __P((MAILER *, char *, ENVELOPE *));
951extern void openxscript __P((ENVELOPE *));
952extern void closexscript __P((ENVELOPE *));
d747e748 953extern sigfunc_t setsignal __P((int, sigfunc_t));
042b8fbf
AM
954extern char *shortenstring __P((char *, int));
955extern bool usershellok __P((char *));
c2714ef5 956extern void commaize __P((HDR *, char *, int, MCI *, ENVELOPE *));
6f14531a
RG
957
958/* ellipsis is a different case though */
959#ifdef __STDC__
960extern void auth_warning(ENVELOPE *, const char *, ...);
961extern void syserr(const char *, ...);
962extern void usrerr(const char *, ...);
963extern void message(const char *, ...);
964extern void nmessage(const char *, ...);
965#else
966extern void auth_warning();
967extern void syserr();
968extern void usrerr();
969extern void message();
970extern void nmessage();
971#endif