1295Seric /* 23313Seric ** SENDMAIL.H -- Global definitions for sendmail. 3295Seric */ 4295Seric 5295Seric 6295Seric 74371Seric # ifdef _DEFINE 84371Seric # define EXTERN 95194Seric # ifndef lint 10*6997Seric static char SmailSccsId[] = "@(#)sendmail.h 3.71 05/31/82"; 115194Seric # endif lint 124371Seric # else _DEFINE 134371Seric # define EXTERN extern 144371Seric # endif _DEFINE 15295Seric 164183Seric # include <stdio.h> 174183Seric # include <ctype.h> 181390Seric # include "useful.h" 191390Seric 20295Seric /* 214284Seric ** Configuration constants. 224284Seric ** There shouldn't be much need to change these.... 23295Seric */ 24295Seric 254374Seric # define MAXLINE 256 /* max line length */ 264374Seric # define MAXNAME 128 /* max length of a name */ 274374Seric # define MAXFIELD 2500 /* max total length of a hdr field */ 284374Seric # define MAXPV 40 /* max # of parms to mailers */ 294374Seric # define MAXHOP 30 /* max value of HopCount */ 304384Seric # define MAXATOM 30 /* max atoms per address */ 314374Seric # define MAXMAILERS 10 /* maximum mailers known to system */ 324374Seric # define SPACESUB ('.'|0200) /* substitution for <lwsp> */ 33295Seric 344167Seric extern char Arpa_Info[]; /* the message number for Arpanet info */ 356902Seric /* 363190Seric ** Address structure. 373190Seric ** Addresses are stored internally in this structure. 383190Seric */ 393190Seric 403190Seric struct address 413190Seric { 423190Seric char *q_paddr; /* the printname for the address */ 433190Seric char *q_user; /* user name */ 443190Seric char *q_host; /* host name */ 454597Seric struct mailer *q_mailer; /* mailer to use */ 463190Seric short q_rmailer; /* real mailer (before mapping) */ 474149Seric u_short q_flags; /* status flags, see below */ 484213Seric short q_uid; /* user-id of receiver (if known) */ 494398Seric short q_gid; /* group-id of receiver (if known) */ 504079Seric char *q_home; /* home dir (local mailer only) */ 514995Seric char *q_fullname; /* full name if known */ 524995Seric struct address *q_next; /* chain */ 534995Seric struct address *q_alias; /* address this results from */ 545034Seric struct address *q_tchain; /* temporary use chain */ 554987Seric time_t q_timeout; /* timeout for this address */ 563190Seric }; 573190Seric 583190Seric typedef struct address ADDRESS; 593190Seric 603190Seric # define QDONTSEND 000001 /* don't send to this address */ 614068Seric # define QBADADDR 000002 /* this address is verified bad */ 624403Seric # define QGOODUID 000004 /* the q_uid q_gid fields are good */ 634422Seric # define QPRIMARY 000010 /* set from argv */ 644624Seric # define QQUEUEUP 000020 /* queue for later transmission */ 656902Seric /* 66295Seric ** Mailer definition structure. 67295Seric ** Every mailer known to the system is declared in this 68295Seric ** structure. It defines the pathname of the mailer, some 69295Seric ** flags associated with it, and the argument vector to 701390Seric ** pass to it. The flags are defined in conf.c 71295Seric ** 724171Seric ** The argument vector is expanded before actual use. All 734171Seric ** words except the first are passed through the macro 744171Seric ** processor. 75295Seric */ 76295Seric 77295Seric struct mailer 78295Seric { 793190Seric char *m_name; /* symbolic name of this mailer */ 80295Seric char *m_mailer; /* pathname of the mailer to use */ 814149Seric u_long m_flags; /* status flags, see below */ 82295Seric short m_badstat; /* the status code to use on unknown error */ 834438Seric short m_mno; /* mailer number internally */ 842899Seric char *m_from; /* pattern for From: header */ 853049Seric char **m_argv; /* template argument vector */ 86295Seric }; 87295Seric 884100Seric typedef struct mailer MAILER; 894100Seric 905601Seric /* bits for m_flags */ 916819Seric # define M_FOPT 000000001L /* mailer takes picky -f flag */ 926819Seric # define M_ROPT 000000002L /* mailer takes picky -r flag */ 936819Seric # define M_QUIET 000000004L /* don't print error on bad status */ 946819Seric # define M_RESTR 000000010L /* must be daemon to execute */ 956819Seric # define M_NHDR 000000020L /* don't insert From line */ 966819Seric # define M_LOCAL 000000040L /* delivery is to this host */ 976819Seric # define M_STRIPQ 000000100L /* strip quote chars from user/host */ 986819Seric # define M_MUSER 000000200L /* can handle multiple users at once */ 996819Seric # define M_NEEDFROM 000000400L /* need arpa-style From: line */ 1006819Seric # define M_NEEDDATE 000001000L /* need arpa-style Date: line */ 1016819Seric # define M_MSGID 000002000L /* need Message-Id: field */ 1026819Seric # define M_RELRCPT 000004000L /* make recipient addresses relative */ 1036819Seric # define M_USR_UPPER 000010000L /* preserve user case distinction */ 1046819Seric # define M_HST_UPPER 000020000L /* preserve host case distinction */ 1056819Seric # define M_FULLNAME 000040000L /* want Full-Name field */ 1066819Seric # define M_UGLYUUCP 000100000L /* this wants an ugly UUCP from line */ 1076819Seric # define M_EXPENSIVE 000200000L /* it costs to use this mailer.... */ 1086982Seric # define M_FULLSMTP 000400000L /* must run full SMTP, inc. limits */ 109295Seric 1104317Seric # define M_ARPAFMT (M_NEEDDATE|M_NEEDFROM|M_MSGID) 1112899Seric 1124597Seric EXTERN MAILER *Mailer[MAXMAILERS+1]; 113295Seric 1144597Seric EXTERN MAILER *LocalMailer; /* ptr to local mailer */ 1154597Seric EXTERN MAILER *ProgMailer; /* ptr to program mailer */ 1166902Seric /* 1172899Seric ** Header structure. 1182899Seric ** This structure is used internally to store header items. 1192899Seric */ 120295Seric 1212899Seric struct header 1222899Seric { 1232899Seric char *h_field; /* the name of the field */ 1242899Seric char *h_value; /* the value of that field */ 1252899Seric struct header *h_link; /* the next header */ 1264149Seric u_short h_flags; /* status bits, see below */ 1274149Seric u_long h_mflags; /* m_flags bits needed */ 1282899Seric }; 129295Seric 1302899Seric typedef struct header HDR; 1312899Seric 132295Seric /* 1332899Seric ** Header information structure. 1342899Seric ** Defined in conf.c, this struct declares the header fields 1352899Seric ** that have some magic meaning. 1362899Seric */ 1372899Seric 1382899Seric struct hdrinfo 1392899Seric { 1402899Seric char *hi_field; /* the name of the field */ 1414149Seric u_short hi_flags; /* status bits, see below */ 1424149Seric u_short hi_mflags; /* m_flags needed for this field */ 1432899Seric }; 1442899Seric 1452899Seric extern struct hdrinfo HdrInfo[]; 1462899Seric 1472899Seric /* bits for h_flags and hi_flags */ 1483060Seric # define H_EOH 00001 /* this field terminates header */ 1495918Seric # define H_RCPT 00002 /* contains recipient addresses */ 1502899Seric # define H_DEFAULT 00004 /* if another value is found, drop this */ 1512899Seric # define H_USED 00010 /* indicates that this has been output */ 1523386Seric # define H_CHECK 00020 /* check h_mflags against m_flags */ 1533390Seric # define H_ACHECK 00040 /* ditto, but always (not just default) */ 1544149Seric # define H_FORCE 00100 /* force this field, even if default */ 1554222Seric # define H_ADDR 00200 /* this field contains addresses */ 1566902Seric /* 1576902Seric ** Envelope structure. 1586902Seric ** This structure defines the message itself. There is usually 1596902Seric ** only one of these -- for the message that we originally read 1606902Seric ** and which is our primary interest -- but other envelopes can 1616902Seric ** be generated during processing. For example, error messages 1626902Seric ** will have their own envelope. 1636902Seric */ 1642899Seric 1656902Seric struct envelope 1666902Seric { 1676987Seric HDR *e_header; /* head of header list */ 1686987Seric long e_msgpriority; /* adjusted priority of this message */ 1696987Seric bool e_queueup; /* queue this message */ 1706987Seric bool e_oldstyle; /* use spaces (not commas) in hdrs */ 1716987Seric bool e_retreceipt; /* give a return receipt */ 1726987Seric bool e_sendreceipt; /* actually send a receipt back */ 1736987Seric char *e_origfrom; /* the From: line first read */ 1746987Seric char *e_to; /* the target person */ 1756987Seric ADDRESS e_from; /* the person it is from */ 1766987Seric ADDRESS *e_sendqueue; /* list of message recipients */ 1776987Seric long e_msgsize; /* size of the message in bytes */ 1786987Seric short e_class; /* msg class (priority, junk, etc.) */ 1796987Seric int (*e_puthdr)(); /* function to put header of message */ 1806987Seric int (*e_putbody)(); /* function to put body of message */ 1816987Seric struct envelope *e_parent; /* the message this one encloses */ 1826987Seric char *e_df; /* location of temp file */ 1836987Seric char *e_macro[128]; /* macro definitions */ 1846902Seric }; 1852899Seric 1866902Seric typedef struct envelope ENVELOPE; 1874624Seric 1886902Seric EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */ 1896902Seric /* 1904624Seric ** Work queue. 1914624Seric */ 1924624Seric 1934624Seric struct work 1944624Seric { 1954624Seric char *w_name; /* name of control file */ 1965034Seric long w_pri; /* priority of message, see below */ 1974624Seric struct work *w_next; /* next in queue */ 1984624Seric }; 1994624Seric 2004624Seric typedef struct work WORK; 2014624Seric 2024624Seric EXTERN WORK *WorkQ; /* queue of things to be done */ 2034624Seric 2044624Seric 2054624Seric /* 2064624Seric ** Message priorities. 2074633Seric ** Priorities > 0 should be preemptive. 2085034Seric ** 2096902Seric ** CurEnv->e_msgpriority is the number of bytes in the message adjusted 2105034Seric ** by the message priority and the amount of time the message 2115034Seric ** has been sitting around. Each priority point is worth 2125034Seric ** WKPRIFACT bytes of message, and each time we reprocess a 2135034Seric ** message the size gets reduced by WKTIMEFACT. 2146910Seric ** 2156910Seric ** The "class" is this number, unadjusted by the age or size of 2166910Seric ** this message. Classes with negative representations will have 2176910Seric ** error messages thrown away if they are not local. 2184624Seric */ 2194624Seric 2206910Seric # define PRI_ALERT 50 2216910Seric # define PRI_QUICK 30 2226910Seric # define PRI_FIRSTCL 10 2235034Seric # define PRI_NORMAL 0 2244633Seric # define PRI_SECONDCL -10 2256910Seric # define PRI_THIRDCL -40 2266910Seric # define PRI_JUNK -100 2274624Seric 2285034Seric # define WKPRIFACT 1800 /* bytes each pri point is worth */ 2295034Seric # define WKTIMEFACT 400 /* bytes each time unit is worth */ 2306902Seric /* 2313153Seric ** Rewrite rules. 2323153Seric */ 2332899Seric 2343153Seric struct rewrite 2353153Seric { 2363153Seric char **r_lhs; /* pattern match */ 2373153Seric char **r_rhs; /* substitution value */ 2383153Seric struct rewrite *r_next;/* next in chain */ 2393153Seric }; 2402899Seric 2414090Seric extern struct rewrite *RewriteRules[]; 2423153Seric 2434060Seric # define MATCHANY '\020' /* match one or more tokens */ 2444060Seric # define MATCHONE '\021' /* match exactly one token */ 2454060Seric # define MATCHCLASS '\022' /* match one token in a class */ 2464467Seric # define MATCHREPL '\023' /* replacement on RHS for above */ 2473153Seric 2483153Seric # define CANONNET '\025' /* canonical net, next token */ 2493153Seric # define CANONHOST '\026' /* canonical host, next token */ 2503153Seric # define CANONUSER '\027' /* canonical user, next N tokens */ 2513153Seric 2526052Seric # define CONDIF '\030' /* conditional if-then */ 2536052Seric # define CONDELSE '\031' /* conditional else */ 2546052Seric # define CONDFI '\032' /* conditional fi */ 2556902Seric /* 2564056Seric ** Symbol table definitions 2574056Seric */ 2583153Seric 2594056Seric struct symtab 2604056Seric { 2614056Seric char *s_name; /* name to be entered */ 2624100Seric char s_type; /* general type (see below) */ 2634056Seric struct symtab *s_next; /* pointer to next in chain */ 2644100Seric union 2654100Seric { 2664100Seric long sv_class; /* bit-map of word classes */ 2674100Seric ADDRESS *sv_addr; /* pointer to address header */ 2684100Seric MAILER *sv_mailer; /* pointer to mailer */ 2694100Seric char *sv_alias; /* alias */ 2704100Seric } s_value; 2714056Seric }; 2724056Seric 2734056Seric typedef struct symtab STAB; 2744056Seric 2754100Seric /* symbol types */ 2764100Seric # define ST_UNDEF 0 /* undefined type */ 2774100Seric # define ST_CLASS 1 /* class map */ 2784100Seric # define ST_ADDRESS 2 /* an address in parsed format */ 2794100Seric # define ST_MAILER 3 /* a mailer header */ 2804100Seric # define ST_ALIAS 4 /* an alias */ 2814100Seric 2824100Seric # define s_class s_value.sv_class 2835976Seric # define s_address s_value.sv_addr 2844100Seric # define s_mailer s_value.sv_mailer 2854100Seric # define s_alias s_value.sv_alias 2864100Seric 2874056Seric extern STAB *stab(); 2884056Seric 2894056Seric /* opcodes to stab */ 2904056Seric # define ST_FIND 0 /* find entry */ 2914056Seric # define ST_ENTER 1 /* enter if not there */ 2926902Seric /* 2934284Seric ** Statistics structure. 2944284Seric */ 2954284Seric 2964284Seric struct statistics 2974284Seric { 2984284Seric time_t stat_itime; /* file initialization time */ 2994284Seric short stat_size; /* size of this structure */ 3004284Seric long stat_nf[MAXMAILERS]; /* # msgs from each mailer */ 3014284Seric long stat_bf[MAXMAILERS]; /* kbytes from each mailer */ 3024284Seric long stat_nt[MAXMAILERS]; /* # msgs to each mailer */ 3034284Seric long stat_bt[MAXMAILERS]; /* kbytes to each mailer */ 3044284Seric }; 3054284Seric 3064371Seric EXTERN struct statistics Stat; 3074284Seric extern long kbytes(); /* for _bf, _bt */ 3086902Seric /* 309*6997Seric ** Operation modes 310*6997Seric ** The default operation mode can be safely changed (except 311*6997Seric ** that the default cannot be MD_DAEMON). 312*6997Seric */ 313*6997Seric 314*6997Seric EXTERN char Mode; /* operation mode, see below */ 315*6997Seric 316*6997Seric #define MD_DELIVER 'a' /* collect and deliver */ 317*6997Seric #define MD_FORK 'f' /* verify & fork before delivery */ 318*6997Seric #define MD_QUEUE 'q' /* collect & queue, don't deliver */ 319*6997Seric #define MD_DAEMON 'd' /* run as a daemon */ 320*6997Seric #define MD_VERIFY 'v' /* verify: don't collect or deliver */ 321*6997Seric 322*6997Seric #define MD_DEFAULT MD_DELIVER /* default operation mode */ 323*6997Seric /* 324295Seric ** Global variables. 325295Seric */ 326295Seric 3274371Seric EXTERN bool FromFlag; /* if set, "From" person is explicit */ 3284371Seric EXTERN bool MailBack; /* mail back response on error */ 3294371Seric EXTERN bool BerkNet; /* called from BerkNet */ 3304371Seric EXTERN bool WriteBack; /* write back response on error */ 3314371Seric EXTERN bool NoAlias; /* if set, don't do any aliasing */ 3324371Seric EXTERN bool ForceMail; /* if set, mail even if already got a copy */ 3334371Seric EXTERN bool MeToo; /* send to the sender also */ 3344371Seric EXTERN bool IgnrDot; /* don't let dot end messages */ 3354371Seric EXTERN bool SaveFrom; /* save leading "From" lines */ 3364371Seric EXTERN bool Verbose; /* set if blow-by-blow desired */ 3374371Seric EXTERN bool GrabTo; /* if set, get recipients from msg */ 3384371Seric EXTERN bool DontSend; /* mark recipients as QDONTSEND */ 3394371Seric EXTERN bool NoReturn; /* don't return letter to sender */ 3404553Seric EXTERN bool Smtp; /* using SMTP over connection */ 3414553Seric EXTERN bool SuprErrs; /* set if we are suppressing errors */ 3426049Seric EXTERN bool QueueRun; /* currently running message from the queue */ 3434711Seric EXTERN bool HoldErrs; /* only output errors to transcript */ 3444711Seric EXTERN bool ArpaMode; /* set if running arpanet protocol */ 3455904Seric EXTERN bool NoConnect; /* don't connect to non-local mailers */ 3466049Seric EXTERN bool FatalErrors; /* set if fatal errors during processing */ 3474624Seric extern time_t TimeOut; /* time until timeout */ 3484553Seric EXTERN FILE *InChannel; /* input connection */ 3494553Seric EXTERN FILE *OutChannel; /* output connection */ 3504553Seric EXTERN FILE *TempFile; /* mail temp file */ 3514711Seric EXTERN FILE *Xscript; /* mail transcript file */ 3524537Seric EXTERN int RealUid; /* when Daemon, real uid of caller */ 3534537Seric EXTERN int RealGid; /* when Daemon, real gid of caller */ 3545703Seric extern int DefUid; /* default uid to run as */ 3555703Seric extern int DefGid; /* default gid to run as */ 3564371Seric EXTERN int OldUmask; /* umask when sendmail starts up */ 3574371Seric EXTERN int Debug; /* debugging level */ 3586049Seric EXTERN int Errors; /* set if errors (local to single pass) */ 3594371Seric EXTERN int ExitStat; /* exit status code */ 3604553Seric EXTERN int HopCount; /* hop count */ 3614553Seric EXTERN int AliasLevel; /* depth of aliasing */ 3624624Seric EXTERN time_t QueueIntvl; /* intervals between running the queue */ 3634553Seric EXTERN char *HostName; /* name of this host for SMTP messages */ 3644624Seric EXTERN char *Transcript; /* the transcript file name */ 3654624Seric extern char *XcriptFile; /* template for Transcript */ 3664624Seric extern char *AliasFile; /* location of alias file */ 3674624Seric extern char *ConfFile; /* location of configuration file */ 3684624Seric extern char *StatFile; /* location of statistics summary */ 3694624Seric extern char *QueueDir; /* location of queue directory */ 3704624Seric EXTERN time_t CurTime; /* time of this message */ 371295Seric 372295Seric 373295Seric # include <sysexits.h> 374295Seric 375295Seric # define setstat(s) { if (ExitStat == EX_OK) ExitStat = s; } 3764085Seric 3774085Seric 3784085Seric /* useful functions */ 3794085Seric 3804085Seric extern char *newstr(); 3814085Seric extern ADDRESS *parse(); 3824085Seric extern char *xalloc(); 3834085Seric extern bool sameaddr(); 3846889Seric extern FILE *dfopen(); 385