1295Seric /* 23313Seric ** SENDMAIL.H -- Global definitions for sendmail. 3295Seric */ 4295Seric 5295Seric 6295Seric 74371Seric # ifdef _DEFINE 84371Seric # define EXTERN 95194Seric # ifndef lint 10*7684Seric static char SmailSccsId[] = "@(#)sendmail.h 3.77 08/08/82"; 115194Seric # endif lint 124371Seric # else _DEFINE 134371Seric # define EXTERN extern 144371Seric # endif _DEFINE 15295Seric 164183Seric # include <stdio.h> 174183Seric # include <ctype.h> 187355Seric # include <setjmp.h> 191390Seric # include "useful.h" 201390Seric 217674Seric # ifdef LOG 227674Seric # include <syslog.h> 237674Seric # endif LOG 247674Seric 25295Seric /* 264284Seric ** Configuration constants. 274284Seric ** There shouldn't be much need to change these.... 28295Seric */ 29295Seric 304374Seric # define MAXLINE 256 /* max line length */ 314374Seric # define MAXNAME 128 /* max length of a name */ 324374Seric # define MAXFIELD 2500 /* max total length of a hdr field */ 334374Seric # define MAXPV 40 /* max # of parms to mailers */ 344374Seric # define MAXHOP 30 /* max value of HopCount */ 354384Seric # define MAXATOM 30 /* max atoms per address */ 364374Seric # define MAXMAILERS 10 /* maximum mailers known to system */ 374374Seric # define SPACESUB ('.'|0200) /* substitution for <lwsp> */ 38295Seric 394167Seric extern char Arpa_Info[]; /* the message number for Arpanet info */ 406902Seric /* 413190Seric ** Address structure. 423190Seric ** Addresses are stored internally in this structure. 433190Seric */ 443190Seric 453190Seric struct address 463190Seric { 473190Seric char *q_paddr; /* the printname for the address */ 483190Seric char *q_user; /* user name */ 493190Seric char *q_host; /* host name */ 504597Seric struct mailer *q_mailer; /* mailer to use */ 513190Seric short q_rmailer; /* real mailer (before mapping) */ 524149Seric u_short q_flags; /* status flags, see below */ 534213Seric short q_uid; /* user-id of receiver (if known) */ 544398Seric short q_gid; /* group-id of receiver (if known) */ 554079Seric char *q_home; /* home dir (local mailer only) */ 564995Seric char *q_fullname; /* full name if known */ 574995Seric struct address *q_next; /* chain */ 584995Seric struct address *q_alias; /* address this results from */ 595034Seric struct address *q_tchain; /* temporary use chain */ 604987Seric time_t q_timeout; /* timeout for this address */ 613190Seric }; 623190Seric 633190Seric typedef struct address ADDRESS; 643190Seric 653190Seric # define QDONTSEND 000001 /* don't send to this address */ 664068Seric # define QBADADDR 000002 /* this address is verified bad */ 674403Seric # define QGOODUID 000004 /* the q_uid q_gid fields are good */ 684422Seric # define QPRIMARY 000010 /* set from argv */ 694624Seric # define QQUEUEUP 000020 /* queue for later transmission */ 706902Seric /* 71295Seric ** Mailer definition structure. 72295Seric ** Every mailer known to the system is declared in this 73295Seric ** structure. It defines the pathname of the mailer, some 74295Seric ** flags associated with it, and the argument vector to 751390Seric ** pass to it. The flags are defined in conf.c 76295Seric ** 774171Seric ** The argument vector is expanded before actual use. All 784171Seric ** words except the first are passed through the macro 794171Seric ** processor. 80295Seric */ 81295Seric 82295Seric struct mailer 83295Seric { 843190Seric char *m_name; /* symbolic name of this mailer */ 85295Seric char *m_mailer; /* pathname of the mailer to use */ 864149Seric u_long m_flags; /* status flags, see below */ 87295Seric short m_badstat; /* the status code to use on unknown error */ 884438Seric short m_mno; /* mailer number internally */ 892899Seric char *m_from; /* pattern for From: header */ 903049Seric char **m_argv; /* template argument vector */ 91295Seric }; 92295Seric 934100Seric typedef struct mailer MAILER; 944100Seric 955601Seric /* bits for m_flags */ 966819Seric # define M_FOPT 000000001L /* mailer takes picky -f flag */ 976819Seric # define M_ROPT 000000002L /* mailer takes picky -r flag */ 986819Seric # define M_QUIET 000000004L /* don't print error on bad status */ 996819Seric # define M_RESTR 000000010L /* must be daemon to execute */ 1006819Seric # define M_NHDR 000000020L /* don't insert From line */ 1016819Seric # define M_LOCAL 000000040L /* delivery is to this host */ 1026819Seric # define M_STRIPQ 000000100L /* strip quote chars from user/host */ 1036819Seric # define M_MUSER 000000200L /* can handle multiple users at once */ 1046819Seric # define M_NEEDFROM 000000400L /* need arpa-style From: line */ 1056819Seric # define M_NEEDDATE 000001000L /* need arpa-style Date: line */ 1066819Seric # define M_MSGID 000002000L /* need Message-Id: field */ 1076819Seric # define M_RELRCPT 000004000L /* make recipient addresses relative */ 1086819Seric # define M_USR_UPPER 000010000L /* preserve user case distinction */ 1096819Seric # define M_HST_UPPER 000020000L /* preserve host case distinction */ 1106819Seric # define M_FULLNAME 000040000L /* want Full-Name field */ 1116819Seric # define M_UGLYUUCP 000100000L /* this wants an ugly UUCP from line */ 1126819Seric # define M_EXPENSIVE 000200000L /* it costs to use this mailer.... */ 1136982Seric # define M_FULLSMTP 000400000L /* must run full SMTP, inc. limits */ 114295Seric 1154317Seric # define M_ARPAFMT (M_NEEDDATE|M_NEEDFROM|M_MSGID) 1162899Seric 1174597Seric EXTERN MAILER *Mailer[MAXMAILERS+1]; 118295Seric 1194597Seric EXTERN MAILER *LocalMailer; /* ptr to local mailer */ 1204597Seric EXTERN MAILER *ProgMailer; /* ptr to program mailer */ 1216902Seric /* 1222899Seric ** Header structure. 1232899Seric ** This structure is used internally to store header items. 1242899Seric */ 125295Seric 1262899Seric struct header 1272899Seric { 1282899Seric char *h_field; /* the name of the field */ 1292899Seric char *h_value; /* the value of that field */ 1302899Seric struct header *h_link; /* the next header */ 1314149Seric u_short h_flags; /* status bits, see below */ 1324149Seric u_long h_mflags; /* m_flags bits needed */ 1332899Seric }; 134295Seric 1352899Seric typedef struct header HDR; 1362899Seric 137295Seric /* 1382899Seric ** Header information structure. 1392899Seric ** Defined in conf.c, this struct declares the header fields 1402899Seric ** that have some magic meaning. 1412899Seric */ 1422899Seric 1432899Seric struct hdrinfo 1442899Seric { 1452899Seric char *hi_field; /* the name of the field */ 1464149Seric u_short hi_flags; /* status bits, see below */ 1474149Seric u_short hi_mflags; /* m_flags needed for this field */ 1482899Seric }; 1492899Seric 1502899Seric extern struct hdrinfo HdrInfo[]; 1512899Seric 1522899Seric /* bits for h_flags and hi_flags */ 1533060Seric # define H_EOH 00001 /* this field terminates header */ 1545918Seric # define H_RCPT 00002 /* contains recipient addresses */ 1552899Seric # define H_DEFAULT 00004 /* if another value is found, drop this */ 1562899Seric # define H_USED 00010 /* indicates that this has been output */ 1573386Seric # define H_CHECK 00020 /* check h_mflags against m_flags */ 1583390Seric # define H_ACHECK 00040 /* ditto, but always (not just default) */ 1594149Seric # define H_FORCE 00100 /* force this field, even if default */ 1604222Seric # define H_ADDR 00200 /* this field contains addresses */ 1616902Seric /* 1626902Seric ** Envelope structure. 1636902Seric ** This structure defines the message itself. There is usually 1646902Seric ** only one of these -- for the message that we originally read 1656902Seric ** and which is our primary interest -- but other envelopes can 1666902Seric ** be generated during processing. For example, error messages 1676902Seric ** will have their own envelope. 1686902Seric */ 1692899Seric 1706902Seric struct envelope 1716902Seric { 1726987Seric HDR *e_header; /* head of header list */ 1736987Seric long e_msgpriority; /* adjusted priority of this message */ 1746987Seric bool e_queueup; /* queue this message */ 1756987Seric bool e_oldstyle; /* use spaces (not commas) in hdrs */ 1766987Seric bool e_retreceipt; /* give a return receipt */ 1776987Seric bool e_sendreceipt; /* actually send a receipt back */ 1786987Seric char *e_origfrom; /* the From: line first read */ 1796987Seric char *e_to; /* the target person */ 1806987Seric ADDRESS e_from; /* the person it is from */ 1816987Seric ADDRESS *e_sendqueue; /* list of message recipients */ 1827044Seric ADDRESS *e_errorqueue; /* the queue for error responses */ 1836987Seric long e_msgsize; /* size of the message in bytes */ 1846987Seric short e_class; /* msg class (priority, junk, etc.) */ 1856987Seric int (*e_puthdr)(); /* function to put header of message */ 1866987Seric int (*e_putbody)(); /* function to put body of message */ 1876987Seric struct envelope *e_parent; /* the message this one encloses */ 1886987Seric char *e_df; /* location of temp file */ 1896987Seric char *e_macro[128]; /* macro definitions */ 1906902Seric }; 1912899Seric 1926902Seric typedef struct envelope ENVELOPE; 1934624Seric 1946902Seric EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */ 1956902Seric /* 1964624Seric ** Work queue. 1974624Seric */ 1984624Seric 1994624Seric struct work 2004624Seric { 2014624Seric char *w_name; /* name of control file */ 2025034Seric long w_pri; /* priority of message, see below */ 2034624Seric struct work *w_next; /* next in queue */ 2044624Seric }; 2054624Seric 2064624Seric typedef struct work WORK; 2074624Seric 2084624Seric EXTERN WORK *WorkQ; /* queue of things to be done */ 2094624Seric 2104624Seric 2114624Seric /* 2124624Seric ** Message priorities. 2134633Seric ** Priorities > 0 should be preemptive. 2145034Seric ** 2156902Seric ** CurEnv->e_msgpriority is the number of bytes in the message adjusted 2165034Seric ** by the message priority and the amount of time the message 2175034Seric ** has been sitting around. Each priority point is worth 2185034Seric ** WKPRIFACT bytes of message, and each time we reprocess a 2195034Seric ** message the size gets reduced by WKTIMEFACT. 2206910Seric ** 2216910Seric ** The "class" is this number, unadjusted by the age or size of 2226910Seric ** this message. Classes with negative representations will have 2236910Seric ** error messages thrown away if they are not local. 2244624Seric */ 2254624Seric 2266910Seric # define PRI_ALERT 50 2276910Seric # define PRI_QUICK 30 2286910Seric # define PRI_FIRSTCL 10 2295034Seric # define PRI_NORMAL 0 2304633Seric # define PRI_SECONDCL -10 2316910Seric # define PRI_THIRDCL -40 2326910Seric # define PRI_JUNK -100 2334624Seric 2345034Seric # define WKPRIFACT 1800 /* bytes each pri point is worth */ 2355034Seric # define WKTIMEFACT 400 /* bytes each time unit is worth */ 2366902Seric /* 2373153Seric ** Rewrite rules. 2383153Seric */ 2392899Seric 2403153Seric struct rewrite 2413153Seric { 2423153Seric char **r_lhs; /* pattern match */ 2433153Seric char **r_rhs; /* substitution value */ 2443153Seric struct rewrite *r_next;/* next in chain */ 2453153Seric }; 2462899Seric 2474090Seric extern struct rewrite *RewriteRules[]; 2483153Seric 2494060Seric # define MATCHANY '\020' /* match one or more tokens */ 2504060Seric # define MATCHONE '\021' /* match exactly one token */ 2514060Seric # define MATCHCLASS '\022' /* match one token in a class */ 2524467Seric # define MATCHREPL '\023' /* replacement on RHS for above */ 2533153Seric 2543153Seric # define CANONNET '\025' /* canonical net, next token */ 2553153Seric # define CANONHOST '\026' /* canonical host, next token */ 2563153Seric # define CANONUSER '\027' /* canonical user, next N tokens */ 2573153Seric 2586052Seric # define CONDIF '\030' /* conditional if-then */ 2596052Seric # define CONDELSE '\031' /* conditional else */ 2606052Seric # define CONDFI '\032' /* conditional fi */ 2616902Seric /* 2624056Seric ** Symbol table definitions 2634056Seric */ 2643153Seric 2654056Seric struct symtab 2664056Seric { 2674056Seric char *s_name; /* name to be entered */ 2684100Seric char s_type; /* general type (see below) */ 2694056Seric struct symtab *s_next; /* pointer to next in chain */ 2704100Seric union 2714100Seric { 2724100Seric long sv_class; /* bit-map of word classes */ 2734100Seric ADDRESS *sv_addr; /* pointer to address header */ 2744100Seric MAILER *sv_mailer; /* pointer to mailer */ 2754100Seric char *sv_alias; /* alias */ 2764100Seric } s_value; 2774056Seric }; 2784056Seric 2794056Seric typedef struct symtab STAB; 2804056Seric 2814100Seric /* symbol types */ 2824100Seric # define ST_UNDEF 0 /* undefined type */ 2834100Seric # define ST_CLASS 1 /* class map */ 2844100Seric # define ST_ADDRESS 2 /* an address in parsed format */ 2854100Seric # define ST_MAILER 3 /* a mailer header */ 2864100Seric # define ST_ALIAS 4 /* an alias */ 2874100Seric 2884100Seric # define s_class s_value.sv_class 2895976Seric # define s_address s_value.sv_addr 2904100Seric # define s_mailer s_value.sv_mailer 2914100Seric # define s_alias s_value.sv_alias 2924100Seric 2934056Seric extern STAB *stab(); 2944056Seric 2954056Seric /* opcodes to stab */ 2964056Seric # define ST_FIND 0 /* find entry */ 2974056Seric # define ST_ENTER 1 /* enter if not there */ 2986902Seric /* 299*7684Seric ** STRUCT EVENT -- event queue. 300*7684Seric ** 301*7684Seric ** Maintained in sorted order. 302*7684Seric */ 303*7684Seric 304*7684Seric struct event 305*7684Seric { 306*7684Seric time_t ev_time; /* time of the function call */ 307*7684Seric int (*ev_func)(); /* function to call */ 308*7684Seric int ev_arg; /* argument to ev_func */ 309*7684Seric struct event *ev_link; /* link to next item */ 310*7684Seric }; 311*7684Seric 312*7684Seric typedef struct event EVENT; 313*7684Seric 314*7684Seric EXTERN EVENT *EventQueue; /* head of event queue */ 315*7684Seric /* 3164284Seric ** Statistics structure. 3174284Seric */ 3184284Seric 3194284Seric struct statistics 3204284Seric { 3214284Seric time_t stat_itime; /* file initialization time */ 3224284Seric short stat_size; /* size of this structure */ 3234284Seric long stat_nf[MAXMAILERS]; /* # msgs from each mailer */ 3244284Seric long stat_bf[MAXMAILERS]; /* kbytes from each mailer */ 3254284Seric long stat_nt[MAXMAILERS]; /* # msgs to each mailer */ 3264284Seric long stat_bt[MAXMAILERS]; /* kbytes to each mailer */ 3274284Seric }; 3284284Seric 3294371Seric EXTERN struct statistics Stat; 3304284Seric extern long kbytes(); /* for _bf, _bt */ 3316902Seric /* 3326997Seric ** Operation modes 3336997Seric ** The default operation mode can be safely changed (except 3346997Seric ** that the default cannot be MD_DAEMON). 3356997Seric */ 3366997Seric 3376997Seric EXTERN char Mode; /* operation mode, see below */ 3386997Seric 3396997Seric #define MD_DELIVER 'a' /* collect and deliver */ 3406997Seric #define MD_FORK 'f' /* verify & fork before delivery */ 3416997Seric #define MD_QUEUE 'q' /* collect & queue, don't deliver */ 3426997Seric #define MD_DAEMON 'd' /* run as a daemon */ 3436997Seric #define MD_VERIFY 'v' /* verify: don't collect or deliver */ 3446997Seric 3456997Seric #define MD_DEFAULT MD_DELIVER /* default operation mode */ 3466997Seric /* 347295Seric ** Global variables. 348295Seric */ 349295Seric 3504371Seric EXTERN bool FromFlag; /* if set, "From" person is explicit */ 3514371Seric EXTERN bool MailBack; /* mail back response on error */ 3524371Seric EXTERN bool BerkNet; /* called from BerkNet */ 3534371Seric EXTERN bool WriteBack; /* write back response on error */ 3544371Seric EXTERN bool NoAlias; /* if set, don't do any aliasing */ 3554371Seric EXTERN bool ForceMail; /* if set, mail even if already got a copy */ 3564371Seric EXTERN bool MeToo; /* send to the sender also */ 3574371Seric EXTERN bool IgnrDot; /* don't let dot end messages */ 3584371Seric EXTERN bool SaveFrom; /* save leading "From" lines */ 3594371Seric EXTERN bool Verbose; /* set if blow-by-blow desired */ 3604371Seric EXTERN bool GrabTo; /* if set, get recipients from msg */ 3614371Seric EXTERN bool DontSend; /* mark recipients as QDONTSEND */ 3624371Seric EXTERN bool NoReturn; /* don't return letter to sender */ 3634553Seric EXTERN bool Smtp; /* using SMTP over connection */ 3644553Seric EXTERN bool SuprErrs; /* set if we are suppressing errors */ 3656049Seric EXTERN bool QueueRun; /* currently running message from the queue */ 3664711Seric EXTERN bool HoldErrs; /* only output errors to transcript */ 3674711Seric EXTERN bool ArpaMode; /* set if running arpanet protocol */ 3685904Seric EXTERN bool NoConnect; /* don't connect to non-local mailers */ 3696049Seric EXTERN bool FatalErrors; /* set if fatal errors during processing */ 3704624Seric extern time_t TimeOut; /* time until timeout */ 3714553Seric EXTERN FILE *InChannel; /* input connection */ 3724553Seric EXTERN FILE *OutChannel; /* output connection */ 3734553Seric EXTERN FILE *TempFile; /* mail temp file */ 3744711Seric EXTERN FILE *Xscript; /* mail transcript file */ 3754537Seric EXTERN int RealUid; /* when Daemon, real uid of caller */ 3764537Seric EXTERN int RealGid; /* when Daemon, real gid of caller */ 3775703Seric extern int DefUid; /* default uid to run as */ 3785703Seric extern int DefGid; /* default gid to run as */ 3794371Seric EXTERN int OldUmask; /* umask when sendmail starts up */ 3806049Seric EXTERN int Errors; /* set if errors (local to single pass) */ 3814371Seric EXTERN int ExitStat; /* exit status code */ 3824553Seric EXTERN int HopCount; /* hop count */ 3834553Seric EXTERN int AliasLevel; /* depth of aliasing */ 3847282Seric EXTERN int MotherPid; /* proc id of parent process */ 3854624Seric EXTERN time_t QueueIntvl; /* intervals between running the queue */ 3864553Seric EXTERN char *HostName; /* name of this host for SMTP messages */ 3874624Seric EXTERN char *Transcript; /* the transcript file name */ 3884624Seric extern char *XcriptFile; /* template for Transcript */ 3894624Seric extern char *AliasFile; /* location of alias file */ 3904624Seric extern char *ConfFile; /* location of configuration file */ 3914624Seric extern char *StatFile; /* location of statistics summary */ 3924624Seric extern char *QueueDir; /* location of queue directory */ 3937349Seric EXTERN char *ControlFile; /* when queued, name of control file temp */ 3947674Seric EXTERN char *MsgId; /* Message-Id: for this message */ 3954624Seric EXTERN time_t CurTime; /* time of this message */ 3967355Seric EXTERN jmp_buf TickFrame; /* frame for clock ticks to jump to */ 3977355Seric extern int ReadTimeout; /* timeout on reads before clock ticks */ 3987674Seric extern int LogLevel; /* level of logging to perform */ 3997674Seric /* 4007674Seric ** Trace information 4017674Seric */ 402295Seric 4037674Seric /* trace vector and macros for debugging flags */ 4047674Seric EXTERN u_char tTdvect[100]; 4057674Seric # define tTd(flag, level) (tTdvect[flag] >= level) 4067674Seric # define tTdlevel(flag) (tTdvect[flag]) 4077674Seric /* 4087674Seric ** Miscellaneous information. 4097674Seric */ 410295Seric 411295Seric # include <sysexits.h> 412295Seric 413295Seric # define setstat(s) { if (ExitStat == EX_OK) ExitStat = s; } 4144085Seric 4154085Seric 4164085Seric /* useful functions */ 4174085Seric 4184085Seric extern char *newstr(); 4194085Seric extern ADDRESS *parse(); 4204085Seric extern char *xalloc(); 4214085Seric extern bool sameaddr(); 4226889Seric extern FILE *dfopen(); 423*7684Seric extern EVENT *setevent(); 424*7684Seric extern char *sfgets(); 425