|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Eric P. Allman
3: * Copyright (c) 1988 Regents of the University of California.
4: * All rights reserved.
5: *
6: * Redistribution and use in source and binary forms are permitted provided
7: * that: (1) source distributions retain this entire copyright notice and
8: * comment, and (2) distributions including binaries display the following
9: * acknowledgement: ``This product includes software developed by the
10: * University of California, Berkeley and its contributors'' in the
11: * documentation or other materials provided with the distribution and in
12: * all advertising materials mentioning features or use of this software.
13: * Neither the name of the University nor the names of its contributors may
14: * be used to endorse or promote products derived from this software without
15: * specific prior written permission.
16: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19: *
20: * @(#)sendmail.h 5.16 (Berkeley) 6/1/90
21: */
22:
23: /*
24: ** SENDMAIL.H -- Global definitions for sendmail.
25: */
26:
27: # ifdef _DEFINE
28: # define EXTERN
29: # ifndef lint
30: static char SmailSccsId[] = "@(#)sendmail.h 5.16 6/1/90";
31: # endif lint
32: # else _DEFINE
33: # define EXTERN extern
34: # endif _DEFINE
35:
36: # include <stdio.h>
37: # include <ctype.h>
38: # include <setjmp.h>
39: # include "conf.h"
40: # include "useful.h"
41:
42: # ifdef LOG
43: # include <sys/syslog.h>
44: # endif LOG
45:
46: # ifdef DAEMON
47: # ifdef VMUNIX
48: # include <sys/socket.h>
49: # include <netinet/in.h>
50: # endif VMUNIX
51: # endif DAEMON
52:
53:
54: # define PSBUFSIZE (MAXNAME + MAXATOM) /* size of prescan buffer */
55:
56:
57: /*
58: ** Data structure for bit maps.
59: **
60: ** Each bit in this map can be referenced by an ascii character.
61: ** This is 128 possible bits, or 12 8-bit bytes.
62: */
63:
64: #define BITMAPBYTES 16 /* number of bytes in a bit map */
65: #define BYTEBITS 8 /* number of bits in a byte */
66:
67: /* internal macros */
68: #define _BITWORD(bit) (bit / (BYTEBITS * sizeof (int)))
69: #define _BITBIT(bit) (1 << (bit % (BYTEBITS * sizeof (int))))
70:
71: typedef int BITMAP[BITMAPBYTES / sizeof (int)];
72:
73: /* test bit number N */
74: #define bitnset(bit, map) ((map)[_BITWORD(bit)] & _BITBIT(bit))
75:
76: /* set bit number N */
77: #define setbitn(bit, map) (map)[_BITWORD(bit)] |= _BITBIT(bit)
78:
79: /* clear bit number N */
80: #define clrbitn(bit, map) (map)[_BITWORD(bit)] &= ~_BITBIT(bit)
81:
82: /* clear an entire bit map */
83: #define clrbitmap(map) bzero((char *) map, BITMAPBYTES)
84: /*
85: ** Address structure.
86: ** Addresses are stored internally in this structure.
87: */
88:
89: struct address
90: {
91: char *q_paddr; /* the printname for the address */
92: char *q_user; /* user name */
93: char *q_ruser; /* real user name, or NULL if q_user */
94: char *q_host; /* host name */
95: struct mailer *q_mailer; /* mailer to use */
96: u_short q_flags; /* status flags, see below */
97: short q_uid; /* user-id of receiver (if known) */
98: short q_gid; /* group-id of receiver (if known) */
99: char *q_home; /* home dir (local mailer only) */
100: char *q_fullname; /* full name if known */
101: struct address *q_next; /* chain */
102: struct address *q_alias; /* address this results from */
103: struct address *q_tchain; /* temporary use chain */
104: time_t q_timeout; /* timeout for this address */
105: };
106:
107: typedef struct address ADDRESS;
108:
109: # define QDONTSEND 000001 /* don't send to this address */
110: # define QBADADDR 000002 /* this address is verified bad */
111: # define QGOODUID 000004 /* the q_uid q_gid fields are good */
112: # define QPRIMARY 000010 /* set from argv */
113: # define QQUEUEUP 000020 /* queue for later transmission */
114: /*
115: ** Mailer definition structure.
116: ** Every mailer known to the system is declared in this
117: ** structure. It defines the pathname of the mailer, some
118: ** flags associated with it, and the argument vector to
119: ** pass to it. The flags are defined in conf.c
120: **
121: ** The argument vector is expanded before actual use. All
122: ** words except the first are passed through the macro
123: ** processor.
124: */
125:
126: struct mailer
127: {
128: char *m_name; /* symbolic name of this mailer */
129: char *m_mailer; /* pathname of the mailer to use */
130: BITMAP m_flags; /* status flags, see below */
131: short m_mno; /* mailer number internally */
132: char **m_argv; /* template argument vector */
133: short m_s_rwset; /* rewriting set for sender addresses */
134: short m_r_rwset; /* rewriting set for recipient addresses */
135: char *m_eol; /* end of line string */
136: long m_maxsize; /* size limit on message to this mailer */
137: };
138:
139: typedef struct mailer MAILER;
140:
141: /* bits for m_flags */
142: # define M_CANONICAL 'C' /* make addresses canonical "u@dom" */
143: # define M_EXPENSIVE 'e' /* it costs to use this mailer.... */
144: # define M_ESCFROM 'E' /* escape From lines to >From */
145: # define M_FOPT 'f' /* mailer takes picky -f flag */
146: # define M_HST_UPPER 'h' /* preserve host case distinction */
147: # define M_INTERNAL 'I' /* SMTP to another sendmail site */
148: # define M_LOCAL 'l' /* delivery is to this host */
149: # define M_LIMITS 'L' /* must enforce SMTP line limits */
150: # define M_MUSER 'm' /* can handle multiple users at once */
151: # define M_NHDR 'n' /* don't insert From line */
152: # define M_FROMPATH 'p' /* use reverse-path in MAIL FROM: */
153: # define M_ROPT 'r' /* mailer takes picky -r flag */
154: # define M_SECURE_PORT 'R' /* try to send on a reserved TCP port */
155: # define M_STRIPQ 's' /* strip quote chars from user/host */
156: # define M_RESTR 'S' /* must be daemon to execute */
157: # define M_USR_UPPER 'u' /* preserve user case distinction */
158: # define M_UGLYUUCP 'U' /* this wants an ugly UUCP from line */
159: # define M_XDOT 'X' /* use hidden-dot algorithm */
160:
161: EXTERN MAILER *Mailer[MAXMAILERS+1];
162:
163: EXTERN MAILER *LocalMailer; /* ptr to local mailer */
164: EXTERN MAILER *ProgMailer; /* ptr to program mailer */
165: /*
166: ** Header structure.
167: ** This structure is used internally to store header items.
168: */
169:
170: struct header
171: {
172: char *h_field; /* the name of the field */
173: char *h_value; /* the value of that field */
174: struct header *h_link; /* the next header */
175: u_short h_flags; /* status bits, see below */
176: BITMAP h_mflags; /* m_flags bits needed */
177: };
178:
179: typedef struct header HDR;
180:
181: /*
182: ** Header information structure.
183: ** Defined in conf.c, this struct declares the header fields
184: ** that have some magic meaning.
185: */
186:
187: struct hdrinfo
188: {
189: char *hi_field; /* the name of the field */
190: u_short hi_flags; /* status bits, see below */
191: };
192:
193: extern struct hdrinfo HdrInfo[];
194:
195: /* bits for h_flags and hi_flags */
196: # define H_EOH 00001 /* this field terminates header */
197: # define H_RCPT 00002 /* contains recipient addresses */
198: # define H_DEFAULT 00004 /* if another value is found, drop this */
199: # define H_RESENT 00010 /* this address is a "Resent-..." address */
200: # define H_CHECK 00020 /* check h_mflags against m_flags */
201: # define H_ACHECK 00040 /* ditto, but always (not just default) */
202: # define H_FORCE 00100 /* force this field, even if default */
203: # define H_TRACE 00200 /* this field contains trace information */
204: # define H_FROM 00400 /* this is a from-type field */
205: # define H_VALID 01000 /* this field has a validated value */
206: /*
207: ** Envelope structure.
208: ** This structure defines the message itself. There is usually
209: ** only one of these -- for the message that we originally read
210: ** and which is our primary interest -- but other envelopes can
211: ** be generated during processing. For example, error messages
212: ** will have their own envelope.
213: */
214:
215: struct envelope
216: {
217: HDR *e_header; /* head of header list */
218: long e_msgpriority; /* adjusted priority of this message */
219: time_t e_ctime; /* time message appeared in the queue */
220: char *e_to; /* the target person */
221: char *e_receiptto; /* return receipt address */
222: ADDRESS e_from; /* the person it is from */
223: char **e_fromdomain; /* the domain part of the sender */
224: ADDRESS *e_sendqueue; /* list of message recipients */
225: ADDRESS *e_errorqueue; /* the queue for error responses */
226: long e_msgsize; /* size of the message in bytes */
227: int e_nrcpts; /* number of recipients */
228: short e_class; /* msg class (priority, junk, etc.) */
229: short e_flags; /* flags, see below */
230: short e_hopcount; /* number of times processed */
231: int (*e_puthdr)(); /* function to put header of message */
232: int (*e_putbody)(); /* function to put body of message */
233: struct envelope *e_parent; /* the message this one encloses */
234: struct envelope *e_sibling; /* the next envelope of interest */
235: char *e_df; /* location of temp file */
236: FILE *e_dfp; /* temporary file */
237: char *e_id; /* code for this entry in queue */
238: FILE *e_xfp; /* transcript file */
239: char *e_message; /* error message */
240: char *e_macro[128]; /* macro definitions */
241: };
242:
243: typedef struct envelope ENVELOPE;
244:
245: /* values for e_flags */
246: #define EF_OLDSTYLE 000001 /* use spaces (not commas) in hdrs */
247: #define EF_INQUEUE 000002 /* this message is fully queued */
248: #define EF_TIMEOUT 000004 /* this message is too old */
249: #define EF_CLRQUEUE 000010 /* disk copy is no longer needed */
250: #define EF_SENDRECEIPT 000020 /* send a return receipt */
251: #define EF_FATALERRS 000040 /* fatal errors occured */
252: #define EF_KEEPQUEUE 000100 /* keep queue files always */
253: #define EF_RESPONSE 000200 /* this is an error or return receipt */
254: #define EF_RESENT 000400 /* this message is being forwarded */
255:
256: EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */
257: /*
258: ** Message priority classes.
259: **
260: ** The message class is read directly from the Priority: header
261: ** field in the message.
262: **
263: ** CurEnv->e_msgpriority is the number of bytes in the message plus
264: ** the creation time (so that jobs ``tend'' to be ordered correctly),
265: ** adjusted by the message class, the number of recipients, and the
266: ** amount of time the message has been sitting around. This number
267: ** is used to order the queue. Higher values mean LOWER priority.
268: **
269: ** Each priority class point is worth WkClassFact priority points;
270: ** each recipient is worth WkRecipFact priority points. Each time
271: ** we reprocess a message the priority is adjusted by WkTimeFact.
272: ** WkTimeFact should normally decrease the priority so that jobs
273: ** that have historically failed will be run later; thanks go to
274: ** Jay Lepreau at Utah for pointing out the error in my thinking.
275: **
276: ** The "class" is this number, unadjusted by the age or size of
277: ** this message. Classes with negative representations will have
278: ** error messages thrown away if they are not local.
279: */
280:
281: struct priority
282: {
283: char *pri_name; /* external name of priority */
284: int pri_val; /* internal value for same */
285: };
286:
287: EXTERN struct priority Priorities[MAXPRIORITIES];
288: EXTERN int NumPriorities; /* pointer into Priorities */
289: /*
290: ** Rewrite rules.
291: */
292:
293: struct rewrite
294: {
295: char **r_lhs; /* pattern match */
296: char **r_rhs; /* substitution value */
297: struct rewrite *r_next;/* next in chain */
298: };
299:
300: EXTERN struct rewrite *RewriteRules[MAXRWSETS];
301:
302: /*
303: ** Special characters in rewriting rules.
304: ** These are used internally only.
305: ** The COND* rules are actually used in macros rather than in
306: ** rewriting rules, but are given here because they
307: ** cannot conflict.
308: */
309:
310: /* left hand side items */
311: # define MATCHZANY '\020' /* match zero or more tokens */
312: # define MATCHANY '\021' /* match one or more tokens */
313: # define MATCHONE '\022' /* match exactly one token */
314: # define MATCHCLASS '\023' /* match one token in a class */
315: # define MATCHNCLASS '\024' /* match anything not in class */
316: # define MATCHREPL '\025' /* replacement on RHS for above */
317:
318: /* right hand side items */
319: # define CANONNET '\026' /* canonical net, next token */
320: # define CANONHOST '\027' /* canonical host, next token */
321: # define CANONUSER '\030' /* canonical user, next N tokens */
322: # define CALLSUBR '\031' /* call another rewriting set */
323:
324: /* conditionals in macros */
325: # define CONDIF '\032' /* conditional if-then */
326: # define CONDELSE '\033' /* conditional else */
327: # define CONDFI '\034' /* conditional fi */
328:
329: /* bracket characters for host name lookup */
330: # define HOSTBEGIN '\035' /* hostname lookup begin */
331: # define HOSTEND '\036' /* hostname lookup end */
332:
333: /* \001 is also reserved as the macro expansion character */
334: /*
335: ** Information about hosts that we have looked up recently.
336: **
337: ** This stuff is 4.2/3bsd specific.
338: */
339:
340: # ifdef DAEMON
341: # ifdef VMUNIX
342:
343: # define HOSTINFO struct hostinfo
344:
345: HOSTINFO
346: {
347: char *ho_name; /* name of this host */
348: struct in_addr ho_inaddr; /* internet address */
349: short ho_flags; /* flag bits, see below */
350: short ho_errno; /* error number on last connection */
351: short ho_exitstat; /* exit status from last connection */
352: };
353:
354:
355: /* flag bits */
356: #define HOF_VALID 00001 /* this entry is valid */
357:
358: # endif VMUNIX
359: # endif DAEMON
360: /*
361: ** Symbol table definitions
362: */
363:
364: struct symtab
365: {
366: char *s_name; /* name to be entered */
367: char s_type; /* general type (see below) */
368: struct symtab *s_next; /* pointer to next in chain */
369: union
370: {
371: BITMAP sv_class; /* bit-map of word classes */
372: ADDRESS *sv_addr; /* pointer to address header */
373: MAILER *sv_mailer; /* pointer to mailer */
374: char *sv_alias; /* alias */
375: # ifdef HOSTINFO
376: HOSTINFO sv_host; /* host information */
377: # endif HOSTINFO
378: } s_value;
379: };
380:
381: typedef struct symtab STAB;
382:
383: /* symbol types */
384: # define ST_UNDEF 0 /* undefined type */
385: # define ST_CLASS 1 /* class map */
386: # define ST_ADDRESS 2 /* an address in parsed format */
387: # define ST_MAILER 3 /* a mailer header */
388: # define ST_ALIAS 4 /* an alias */
389: # define ST_HOST 5 /* host information */
390:
391: # define s_class s_value.sv_class
392: # define s_address s_value.sv_addr
393: # define s_mailer s_value.sv_mailer
394: # define s_alias s_value.sv_alias
395: # define s_host s_value.sv_host
396:
397: extern STAB *stab();
398:
399: /* opcodes to stab */
400: # define ST_FIND 0 /* find entry */
401: # define ST_ENTER 1 /* enter if not there */
402: /*
403: ** STRUCT EVENT -- event queue.
404: **
405: ** Maintained in sorted order.
406: **
407: ** We store the pid of the process that set this event to insure
408: ** that when we fork we will not take events intended for the parent.
409: */
410:
411: struct event
412: {
413: time_t ev_time; /* time of the function call */
414: int (*ev_func)(); /* function to call */
415: int ev_arg; /* argument to ev_func */
416: int ev_pid; /* pid that set this event */
417: struct event *ev_link; /* link to next item */
418: };
419:
420: typedef struct event EVENT;
421:
422: EXTERN EVENT *EventQueue; /* head of event queue */
423: /*
424: ** Operation, send, and error modes
425: **
426: ** The operation mode describes the basic operation of sendmail.
427: ** This can be set from the command line, and is "send mail" by
428: ** default.
429: **
430: ** The send mode tells how to send mail. It can be set in the
431: ** configuration file. It's setting determines how quickly the
432: ** mail will be delivered versus the load on your system. If the
433: ** -v (verbose) flag is given, it will be forced to SM_DELIVER
434: ** mode.
435: **
436: ** The error mode tells how to return errors.
437: */
438:
439: EXTERN char OpMode; /* operation mode, see below */
440:
441: #define MD_DELIVER 'm' /* be a mail sender */
442: #define MD_ARPAFTP 'a' /* old-style arpanet protocols */
443: #define MD_SMTP 's' /* run SMTP on standard input */
444: #define MD_DAEMON 'd' /* run as a daemon */
445: #define MD_VERIFY 'v' /* verify: don't collect or deliver */
446: #define MD_TEST 't' /* test mode: resolve addrs only */
447: #define MD_INITALIAS 'i' /* initialize alias database */
448: #define MD_PRINT 'p' /* print the queue */
449: #define MD_FREEZE 'z' /* freeze the configuration file */
450:
451:
452: EXTERN char SendMode; /* send mode, see below */
453:
454: #define SM_DELIVER 'i' /* interactive delivery */
455: #define SM_QUICKD 'j' /* deliver w/o queueing */
456: #define SM_FORK 'b' /* deliver in background */
457: #define SM_QUEUE 'q' /* queue, don't deliver */
458: #define SM_VERIFY 'v' /* verify only (used internally) */
459:
460: /* used only as a parameter to sendall */
461: #define SM_DEFAULT '\0' /* unspecified, use SendMode */
462:
463:
464: EXTERN char ErrorMode; /* error mode, see below */
465:
466: #define EM_PRINT 'p' /* print errors */
467: #define EM_MAIL 'm' /* mail back errors */
468: #define EM_WRITE 'w' /* write back errors */
469: #define EM_BERKNET 'e' /* special berknet processing */
470: #define EM_QUIET 'q' /* don't print messages (stat only) */
471:
472: /* offset used to issure that the error messages for name server error
473: * codes are unique.
474: */
475: #define MAX_ERRNO 100
476: /*
477: ** Global variables.
478: */
479:
480: EXTERN bool FromFlag; /* if set, "From" person is explicit */
481: EXTERN bool NoAlias; /* if set, don't do any aliasing */
482: EXTERN bool ForceMail; /* if set, mail even if already got a copy */
483: EXTERN bool MeToo; /* send to the sender also */
484: EXTERN bool IgnrDot; /* don't let dot end messages */
485: EXTERN bool SaveFrom; /* save leading "From" lines */
486: EXTERN bool Verbose; /* set if blow-by-blow desired */
487: EXTERN bool GrabTo; /* if set, get recipients from msg */
488: EXTERN bool NoReturn; /* don't return letter to sender */
489: EXTERN bool SuprErrs; /* set if we are suppressing errors */
490: EXTERN bool QueueRun; /* currently running message from the queue */
491: EXTERN bool HoldErrs; /* only output errors to transcript */
492: EXTERN bool NoConnect; /* don't connect to non-local mailers */
493: EXTERN bool SuperSafe; /* be extra careful, even if expensive */
494: EXTERN bool ForkQueueRuns; /* fork for each job when running the queue */
495: EXTERN bool AutoRebuild; /* auto-rebuild the alias database as needed */
496: EXTERN bool CheckAliases; /* parse addresses during newaliases */
497: EXTERN bool UseNameServer; /* use internet domain name server */
498: EXTERN int SafeAlias; /* minutes to wait until @:@ in alias file */
499: EXTERN time_t TimeOut; /* time until timeout */
500: EXTERN FILE *InChannel; /* input connection */
501: EXTERN FILE *OutChannel; /* output connection */
502: EXTERN int RealUid; /* when Daemon, real uid of caller */
503: EXTERN int RealGid; /* when Daemon, real gid of caller */
504: EXTERN int DefUid; /* default uid to run as */
505: EXTERN char *DefUser; /* default user to run as (from DefUid) */
506: EXTERN int DefGid; /* default gid to run as */
507: EXTERN int OldUmask; /* umask when sendmail starts up */
508: EXTERN int Errors; /* set if errors (local to single pass) */
509: EXTERN int ExitStat; /* exit status code */
510: EXTERN int AliasLevel; /* depth of aliasing */
511: EXTERN int MotherPid; /* proc id of parent process */
512: EXTERN int LineNumber; /* line number in current input */
513: EXTERN time_t ReadTimeout; /* timeout on reads */
514: EXTERN int LogLevel; /* level of logging to perform */
515: EXTERN int FileMode; /* mode on files */
516: EXTERN int QueueLA; /* load average starting forced queueing */
517: EXTERN int RefuseLA; /* load average refusing connections are */
518: EXTERN int QueueFactor; /* slope of queue function */
519: EXTERN time_t QueueIntvl; /* intervals between running the queue */
520: EXTERN char *AliasFile; /* location of alias file */
521: EXTERN char *HelpFile; /* location of SMTP help file */
522: EXTERN char *StatFile; /* location of statistics summary */
523: EXTERN char *QueueDir; /* location of queue directory */
524: EXTERN char *FileName; /* name to print on error messages */
525: EXTERN char *SmtpPhase; /* current phase in SMTP processing */
526: EXTERN char *MyHostName; /* name of this host for SMTP messages */
527: EXTERN char *RealHostName; /* name of host we are talking to */
528: EXTERN struct sockaddr_in RealHostAddr;/* address of host we are talking to */
529: EXTERN char *CurHostName; /* current host we are dealing with */
530: EXTERN jmp_buf TopFrame; /* branch-to-top-of-loop-on-error frame */
531: EXTERN bool QuickAbort; /* .... but only if we want a quick abort */
532: extern char *ConfFile; /* location of configuration file [conf.c] */
533: extern char *FreezeFile; /* location of frozen memory image [conf.c] */
534: extern char Arpa_Info[]; /* the reply code for Arpanet info [conf.c] */
535: extern ADDRESS NullAddress; /* a null (template) address [main.c] */
536: EXTERN char SpaceSub; /* substitution for <lwsp> */
537: EXTERN int WkClassFact; /* multiplier for message class -> priority */
538: EXTERN int WkRecipFact; /* multiplier for # of recipients -> priority */
539: EXTERN int WkTimeFact; /* priority offset each time this job is run */
540: EXTERN int CheckPointLimit; /* deliveries before checkpointing */
541: EXTERN int Nmx; /* number of MX RRs */
542: EXTERN char *PostMasterCopy; /* address to get errs cc's */
543: EXTERN char *MxHosts[MAXMXHOSTS+1]; /* for MX RRs */
544: EXTERN char *TrustedUsers[MAXTRUST+1]; /* list of trusted users */
545: EXTERN char *UserEnviron[MAXUSERENVIRON+1]; /* saved user environment */
546: /*
547: ** Trace information
548: */
549:
550: /* trace vector and macros for debugging flags */
551: EXTERN u_char tTdvect[100];
552: # define tTd(flag, level) (tTdvect[flag] >= level)
553: # define tTdlevel(flag) (tTdvect[flag])
554: /*
555: ** Miscellaneous information.
556: */
557:
558: # include <sysexits.h>
559:
560:
561: /*
562: ** Some in-line functions
563: */
564:
565: /* set exit status */
566: #define setstat(s) { \
567: if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \
568: ExitStat = s; \
569: }
570:
571: /* make a copy of a string */
572: #define newstr(s) strcpy(xalloc(strlen(s) + 1), s)
573:
574: #define STRUCTCOPY(s, d) d = s
575:
576:
577: /*
578: ** Declarations of useful functions
579: */
580:
581: extern ADDRESS *parseaddr();
582: extern char *xalloc();
583: extern bool sameaddr();
584: extern FILE *dfopen();
585: extern EVENT *setevent();
586: extern char *sfgets();
587: extern char *queuename();
588: extern time_t curtime();
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.