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