1295Seric /* 23313Seric ** SENDMAIL.H -- Global definitions for sendmail. 3295Seric */ 4295Seric 5295Seric 6295Seric 74371Seric # ifdef _DEFINE 84371Seric # define EXTERN 95194Seric # ifndef lint 10*9312Seric static char SmailSccsId[] = "@(#)sendmail.h 3.100 11/21/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> 199144Seric # include "conf.h" 201390Seric # include "useful.h" 211390Seric 227674Seric # ifdef LOG 237674Seric # include <syslog.h> 247674Seric # endif LOG 257799Seric /* 263190Seric ** Address structure. 273190Seric ** Addresses are stored internally in this structure. 283190Seric */ 293190Seric 303190Seric struct address 313190Seric { 323190Seric char *q_paddr; /* the printname for the address */ 333190Seric char *q_user; /* user name */ 343190Seric char *q_host; /* host name */ 354597Seric struct mailer *q_mailer; /* mailer to use */ 364149Seric u_short q_flags; /* status flags, see below */ 374213Seric short q_uid; /* user-id of receiver (if known) */ 384398Seric short q_gid; /* group-id of receiver (if known) */ 394079Seric char *q_home; /* home dir (local mailer only) */ 404995Seric char *q_fullname; /* full name if known */ 414995Seric struct address *q_next; /* chain */ 424995Seric struct address *q_alias; /* address this results from */ 435034Seric struct address *q_tchain; /* temporary use chain */ 444987Seric time_t q_timeout; /* timeout for this address */ 453190Seric }; 463190Seric 473190Seric typedef struct address ADDRESS; 483190Seric 493190Seric # define QDONTSEND 000001 /* don't send to this address */ 504068Seric # define QBADADDR 000002 /* this address is verified bad */ 514403Seric # define QGOODUID 000004 /* the q_uid q_gid fields are good */ 524422Seric # define QPRIMARY 000010 /* set from argv */ 534624Seric # define QQUEUEUP 000020 /* queue for later transmission */ 546902Seric /* 55295Seric ** Mailer definition structure. 56295Seric ** Every mailer known to the system is declared in this 57295Seric ** structure. It defines the pathname of the mailer, some 58295Seric ** flags associated with it, and the argument vector to 591390Seric ** pass to it. The flags are defined in conf.c 60295Seric ** 614171Seric ** The argument vector is expanded before actual use. All 624171Seric ** words except the first are passed through the macro 634171Seric ** processor. 64295Seric */ 65295Seric 66295Seric struct mailer 67295Seric { 683190Seric char *m_name; /* symbolic name of this mailer */ 69295Seric char *m_mailer; /* pathname of the mailer to use */ 704149Seric u_long m_flags; /* status flags, see below */ 71295Seric short m_badstat; /* the status code to use on unknown error */ 724438Seric short m_mno; /* mailer number internally */ 733049Seric char **m_argv; /* template argument vector */ 748061Seric short m_s_rwset; /* rewriting set for sender addresses */ 758061Seric short m_r_rwset; /* rewriting set for recipient addresses */ 76295Seric }; 77295Seric 784100Seric typedef struct mailer MAILER; 794100Seric 805601Seric /* bits for m_flags */ 816819Seric # define M_FOPT 000000001L /* mailer takes picky -f flag */ 826819Seric # define M_ROPT 000000002L /* mailer takes picky -r flag */ 836819Seric # define M_QUIET 000000004L /* don't print error on bad status */ 846819Seric # define M_RESTR 000000010L /* must be daemon to execute */ 856819Seric # define M_NHDR 000000020L /* don't insert From line */ 866819Seric # define M_LOCAL 000000040L /* delivery is to this host */ 876819Seric # define M_STRIPQ 000000100L /* strip quote chars from user/host */ 886819Seric # define M_MUSER 000000200L /* can handle multiple users at once */ 896819Seric # define M_NEEDFROM 000000400L /* need arpa-style From: line */ 906819Seric # define M_NEEDDATE 000001000L /* need arpa-style Date: line */ 916819Seric # define M_MSGID 000002000L /* need Message-Id: field */ 928180Seric # define M_CANONICAL 000004000L /* make addresses canonical "u@dom" */ 936819Seric # define M_USR_UPPER 000010000L /* preserve user case distinction */ 946819Seric # define M_HST_UPPER 000020000L /* preserve host case distinction */ 956819Seric # define M_FULLNAME 000040000L /* want Full-Name field */ 966819Seric # define M_UGLYUUCP 000100000L /* this wants an ugly UUCP from line */ 976819Seric # define M_EXPENSIVE 000200000L /* it costs to use this mailer.... */ 986982Seric # define M_FULLSMTP 000400000L /* must run full SMTP, inc. limits */ 99*9312Seric # define M_INTERNAL 001000000L /* SMTP to another sendmail site */ 100295Seric 1014317Seric # define M_ARPAFMT (M_NEEDDATE|M_NEEDFROM|M_MSGID) 1022899Seric 1034597Seric EXTERN MAILER *Mailer[MAXMAILERS+1]; 104295Seric 1054597Seric EXTERN MAILER *LocalMailer; /* ptr to local mailer */ 1064597Seric EXTERN MAILER *ProgMailer; /* ptr to program mailer */ 1076902Seric /* 1082899Seric ** Header structure. 1092899Seric ** This structure is used internally to store header items. 1102899Seric */ 111295Seric 1122899Seric struct header 1132899Seric { 1142899Seric char *h_field; /* the name of the field */ 1152899Seric char *h_value; /* the value of that field */ 1162899Seric struct header *h_link; /* the next header */ 1174149Seric u_short h_flags; /* status bits, see below */ 1184149Seric u_long h_mflags; /* m_flags bits needed */ 1192899Seric }; 120295Seric 1212899Seric typedef struct header HDR; 1222899Seric 123295Seric /* 1242899Seric ** Header information structure. 1252899Seric ** Defined in conf.c, this struct declares the header fields 1262899Seric ** that have some magic meaning. 1272899Seric */ 1282899Seric 1292899Seric struct hdrinfo 1302899Seric { 1312899Seric char *hi_field; /* the name of the field */ 1324149Seric u_short hi_flags; /* status bits, see below */ 1332899Seric }; 1342899Seric 1352899Seric extern struct hdrinfo HdrInfo[]; 1362899Seric 1372899Seric /* bits for h_flags and hi_flags */ 1383060Seric # define H_EOH 00001 /* this field terminates header */ 1395918Seric # define H_RCPT 00002 /* contains recipient addresses */ 1402899Seric # define H_DEFAULT 00004 /* if another value is found, drop this */ 1412899Seric # define H_USED 00010 /* indicates that this has been output */ 1423386Seric # define H_CHECK 00020 /* check h_mflags against m_flags */ 1433390Seric # define H_ACHECK 00040 /* ditto, but always (not just default) */ 1444149Seric # define H_FORCE 00100 /* force this field, even if default */ 1458061Seric # define H_TRACE 00200 /* this field contains trace information */ 1467761Seric # define H_FROM 00400 /* this is a from-type field */ 1476902Seric /* 1486902Seric ** Envelope structure. 1496902Seric ** This structure defines the message itself. There is usually 1506902Seric ** only one of these -- for the message that we originally read 1516902Seric ** and which is our primary interest -- but other envelopes can 1526902Seric ** be generated during processing. For example, error messages 1536902Seric ** will have their own envelope. 1546902Seric */ 1552899Seric 1566902Seric struct envelope 1576902Seric { 1586987Seric HDR *e_header; /* head of header list */ 1596987Seric long e_msgpriority; /* adjusted priority of this message */ 1607859Seric time_t e_ctime; /* time message appeared in the queue */ 1616987Seric bool e_queueup; /* queue this message */ 1627859Seric bool e_dontqueue; /* override queueing */ 1636987Seric bool e_oldstyle; /* use spaces (not commas) in hdrs */ 1646987Seric bool e_sendreceipt; /* actually send a receipt back */ 1656987Seric char *e_to; /* the target person */ 1668061Seric char *e_receiptto; /* return receipt address */ 1676987Seric ADDRESS e_from; /* the person it is from */ 1688180Seric char **e_fromdomain; /* the domain part of the sender */ 1696987Seric ADDRESS *e_sendqueue; /* list of message recipients */ 1707044Seric ADDRESS *e_errorqueue; /* the queue for error responses */ 1716987Seric long e_msgsize; /* size of the message in bytes */ 1726987Seric short e_class; /* msg class (priority, junk, etc.) */ 1736987Seric int (*e_puthdr)(); /* function to put header of message */ 1746987Seric int (*e_putbody)(); /* function to put body of message */ 1756987Seric struct envelope *e_parent; /* the message this one encloses */ 1766987Seric char *e_df; /* location of temp file */ 1777810Seric char *e_qf; /* queue control file */ 1787810Seric char *e_id; /* code for this entry in queue */ 1796987Seric char *e_macro[128]; /* macro definitions */ 1806902Seric }; 1812899Seric 1826902Seric typedef struct envelope ENVELOPE; 1834624Seric 1846902Seric EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */ 1856902Seric /* 1864624Seric ** Work queue. 1874624Seric */ 1884624Seric 1894624Seric struct work 1904624Seric { 1914624Seric char *w_name; /* name of control file */ 1925034Seric long w_pri; /* priority of message, see below */ 1934624Seric struct work *w_next; /* next in queue */ 1944624Seric }; 1954624Seric 1964624Seric typedef struct work WORK; 1974624Seric 1984624Seric EXTERN WORK *WorkQ; /* queue of things to be done */ 1994624Seric 2004624Seric 2014624Seric /* 2024624Seric ** Message priorities. 2034633Seric ** Priorities > 0 should be preemptive. 2045034Seric ** 2056902Seric ** CurEnv->e_msgpriority is the number of bytes in the message adjusted 2065034Seric ** by the message priority and the amount of time the message 2075034Seric ** has been sitting around. Each priority point is worth 2085034Seric ** WKPRIFACT bytes of message, and each time we reprocess a 2095034Seric ** message the size gets reduced by WKTIMEFACT. 2106910Seric ** 2116910Seric ** The "class" is this number, unadjusted by the age or size of 2126910Seric ** this message. Classes with negative representations will have 2136910Seric ** error messages thrown away if they are not local. 2144624Seric */ 2154624Seric 2168249Seric struct priority 2178249Seric { 2188249Seric char *pri_name; /* external name of priority */ 2198249Seric int pri_val; /* internal value for same */ 2208249Seric }; 2214624Seric 2228249Seric EXTERN struct priority Priorities[MAXPRIORITIES]; 2238249Seric EXTERN int NumPriorities; /* pointer into Priorities */ 2248249Seric 2255034Seric # define WKPRIFACT 1800 /* bytes each pri point is worth */ 2265034Seric # define WKTIMEFACT 400 /* bytes each time unit is worth */ 2276902Seric /* 2283153Seric ** Rewrite rules. 2293153Seric */ 2302899Seric 2313153Seric struct rewrite 2323153Seric { 2333153Seric char **r_lhs; /* pattern match */ 2343153Seric char **r_rhs; /* substitution value */ 2353153Seric struct rewrite *r_next;/* next in chain */ 2363153Seric }; 2372899Seric 2388057Seric EXTERN struct rewrite *RewriteRules[MAXRWSETS]; 2393153Seric 2408057Seric /* 2418057Seric ** Special characters in rewriting rules. 2428057Seric ** These are used internally only. 2438057Seric ** The COND* rules are actually used in macros rather than in 2448057Seric ** rewriting rules, but are given here because they 2458057Seric ** cannot conflict. 2468057Seric */ 2473153Seric 2488057Seric /* left hand side items */ 2498057Seric # define MATCHZANY '\020' /* match zero or more tokens */ 2508057Seric # define MATCHANY '\021' /* match one or more tokens */ 2518057Seric # define MATCHONE '\022' /* match exactly one token */ 2528057Seric # define MATCHCLASS '\023' /* match one token in a class */ 2538057Seric # define MATCHREPL '\024' /* replacement on RHS for above */ 2548057Seric 2558057Seric /* right hand side items */ 2563153Seric # define CANONNET '\025' /* canonical net, next token */ 2573153Seric # define CANONHOST '\026' /* canonical host, next token */ 2583153Seric # define CANONUSER '\027' /* canonical user, next N tokens */ 2598057Seric # define CALLSUBR '\030' /* call another rewriting set */ 2603153Seric 2618057Seric /* conditionals in macros */ 2628057Seric # define CONDIF '\031' /* conditional if-then */ 2638057Seric # define CONDELSE '\032' /* conditional else */ 2648057Seric # define CONDFI '\033' /* conditional fi */ 2656902Seric /* 2664056Seric ** Symbol table definitions 2674056Seric */ 2683153Seric 2694056Seric struct symtab 2704056Seric { 2714056Seric char *s_name; /* name to be entered */ 2724100Seric char s_type; /* general type (see below) */ 2734056Seric struct symtab *s_next; /* pointer to next in chain */ 2744100Seric union 2754100Seric { 2764100Seric long sv_class; /* bit-map of word classes */ 2774100Seric ADDRESS *sv_addr; /* pointer to address header */ 2784100Seric MAILER *sv_mailer; /* pointer to mailer */ 2794100Seric char *sv_alias; /* alias */ 2804100Seric } s_value; 2814056Seric }; 2824056Seric 2834056Seric typedef struct symtab STAB; 2844056Seric 2854100Seric /* symbol types */ 2864100Seric # define ST_UNDEF 0 /* undefined type */ 2874100Seric # define ST_CLASS 1 /* class map */ 2884100Seric # define ST_ADDRESS 2 /* an address in parsed format */ 2894100Seric # define ST_MAILER 3 /* a mailer header */ 2904100Seric # define ST_ALIAS 4 /* an alias */ 2914100Seric 2924100Seric # define s_class s_value.sv_class 2935976Seric # define s_address s_value.sv_addr 2944100Seric # define s_mailer s_value.sv_mailer 2954100Seric # define s_alias s_value.sv_alias 2964100Seric 2974056Seric extern STAB *stab(); 2984056Seric 2994056Seric /* opcodes to stab */ 3004056Seric # define ST_FIND 0 /* find entry */ 3014056Seric # define ST_ENTER 1 /* enter if not there */ 3026902Seric /* 3037684Seric ** STRUCT EVENT -- event queue. 3047684Seric ** 3057684Seric ** Maintained in sorted order. 3067931Seric ** 3077931Seric ** We store the pid of the process that set this event to insure 3087931Seric ** that when we fork we will not take events intended for the parent. 3097684Seric */ 3107684Seric 3117684Seric struct event 3127684Seric { 3137684Seric time_t ev_time; /* time of the function call */ 3147684Seric int (*ev_func)(); /* function to call */ 3157684Seric int ev_arg; /* argument to ev_func */ 3167931Seric int ev_pid; /* pid that set this event */ 3177684Seric struct event *ev_link; /* link to next item */ 3187684Seric }; 3197684Seric 3207684Seric typedef struct event EVENT; 3217684Seric 3227684Seric EXTERN EVENT *EventQueue; /* head of event queue */ 3237684Seric /* 3244284Seric ** Statistics structure. 3254284Seric */ 3264284Seric 3274284Seric struct statistics 3284284Seric { 3294284Seric time_t stat_itime; /* file initialization time */ 3304284Seric short stat_size; /* size of this structure */ 3314284Seric long stat_nf[MAXMAILERS]; /* # msgs from each mailer */ 3324284Seric long stat_bf[MAXMAILERS]; /* kbytes from each mailer */ 3334284Seric long stat_nt[MAXMAILERS]; /* # msgs to each mailer */ 3344284Seric long stat_bt[MAXMAILERS]; /* kbytes to each mailer */ 3354284Seric }; 3364284Seric 3374371Seric EXTERN struct statistics Stat; 3384284Seric extern long kbytes(); /* for _bf, _bt */ 3396902Seric /* 3409278Seric ** Operation and send modes 3419278Seric ** 3429278Seric ** The operation mode describes the basic operation of sendmail. 3439278Seric ** This can be set from the command line, and is "send mail" by 3449278Seric ** default. 3459278Seric ** 3469278Seric ** The send mode tells how to send mail. It can be set in the 3479278Seric ** configuration file. It's setting determines how quickly the 3489278Seric ** mail will be delivered versus the load on your system. If the 3499278Seric ** -v (verbose) flag is given, it will be forced to SM_DELIVER 3509278Seric ** mode. 3519278Seric ** 3529278Seric ** The default send mode can be safely changed. 3536997Seric */ 3546997Seric 3559278Seric EXTERN char OpMode; /* operation mode, see below */ 3566997Seric 3579278Seric #define MD_DELIVER 'm' /* be a mail sender */ 3589278Seric #define MD_ARPAFTP 'a' /* old-style arpanet protocols */ 3599278Seric #define MD_SMTP 's' /* run SMTP on standard input */ 3606997Seric #define MD_DAEMON 'd' /* run as a daemon */ 3616997Seric #define MD_VERIFY 'v' /* verify: don't collect or deliver */ 3628334Seric #define MD_TEST 't' /* test mode: resolve addrs only */ 3639144Seric #define MD_INITALIAS 'i' /* initialize alias database */ 3649144Seric #define MD_PRINT 'p' /* print the queue */ 3659144Seric #define MD_FREEZE 'z' /* freeze the configuration file */ 3666997Seric 3679278Seric 3689278Seric EXTERN char SendMode; /* send mode, see below */ 3699278Seric 3709278Seric #define SM_DELIVER 'i' /* interactive delivery */ 3719278Seric #define SM_QUICKD 'j' /* deliver w/o queueing */ 3729278Seric #define SM_FORK 'b' /* deliver in background */ 3739278Seric #define SM_QUEUE 'q' /* queue, don't deliver */ 3749278Seric #define SM_VERIFY 'v' /* verify only (used internally) */ 3756997Seric /* 376295Seric ** Global variables. 377295Seric */ 378295Seric 3794371Seric EXTERN bool FromFlag; /* if set, "From" person is explicit */ 3804371Seric EXTERN bool MailBack; /* mail back response on error */ 3814371Seric EXTERN bool BerkNet; /* called from BerkNet */ 3824371Seric EXTERN bool WriteBack; /* write back response on error */ 3834371Seric EXTERN bool NoAlias; /* if set, don't do any aliasing */ 3844371Seric EXTERN bool ForceMail; /* if set, mail even if already got a copy */ 3854371Seric EXTERN bool MeToo; /* send to the sender also */ 3864371Seric EXTERN bool IgnrDot; /* don't let dot end messages */ 3874371Seric EXTERN bool SaveFrom; /* save leading "From" lines */ 3884371Seric EXTERN bool Verbose; /* set if blow-by-blow desired */ 3894371Seric EXTERN bool GrabTo; /* if set, get recipients from msg */ 3904371Seric EXTERN bool DontSend; /* mark recipients as QDONTSEND */ 3914371Seric EXTERN bool NoReturn; /* don't return letter to sender */ 3924553Seric EXTERN bool SuprErrs; /* set if we are suppressing errors */ 3936049Seric EXTERN bool QueueRun; /* currently running message from the queue */ 3944711Seric EXTERN bool HoldErrs; /* only output errors to transcript */ 3955904Seric EXTERN bool NoConnect; /* don't connect to non-local mailers */ 3966049Seric EXTERN bool FatalErrors; /* set if fatal errors during processing */ 3978268Seric EXTERN bool SuperSafe; /* be extra careful, even if expensive */ 3988929Seric EXTERN bool SafeAlias; /* alias file must have "@:@" to be complete */ 3999144Seric EXTERN bool AutoRebuild; /* auto-rebuild the alias database as needed */ 4008268Seric EXTERN time_t TimeOut; /* time until timeout */ 4014553Seric EXTERN FILE *InChannel; /* input connection */ 4024553Seric EXTERN FILE *OutChannel; /* output connection */ 4034553Seric EXTERN FILE *TempFile; /* mail temp file */ 4044711Seric EXTERN FILE *Xscript; /* mail transcript file */ 4054537Seric EXTERN int RealUid; /* when Daemon, real uid of caller */ 4064537Seric EXTERN int RealGid; /* when Daemon, real gid of caller */ 4078268Seric EXTERN int DefUid; /* default uid to run as */ 4088268Seric EXTERN int DefGid; /* default gid to run as */ 4094371Seric EXTERN int OldUmask; /* umask when sendmail starts up */ 4106049Seric EXTERN int Errors; /* set if errors (local to single pass) */ 4114371Seric EXTERN int ExitStat; /* exit status code */ 4124553Seric EXTERN int HopCount; /* hop count */ 4134553Seric EXTERN int AliasLevel; /* depth of aliasing */ 4147282Seric EXTERN int MotherPid; /* proc id of parent process */ 4158057Seric EXTERN int LineNumber; /* line number in current input */ 4168268Seric EXTERN int ReadTimeout; /* timeout on reads */ 4178268Seric EXTERN int LogLevel; /* level of logging to perform */ 4189045Seric EXTERN int FileMode; /* mode on files */ 4194624Seric EXTERN time_t QueueIntvl; /* intervals between running the queue */ 4204553Seric EXTERN char *HostName; /* name of this host for SMTP messages */ 4214624Seric EXTERN char *Transcript; /* the transcript file name */ 4228268Seric EXTERN char *AliasFile; /* location of alias file */ 4238268Seric EXTERN char *HelpFile; /* location of SMTP help file */ 4248268Seric EXTERN char *StatFile; /* location of statistics summary */ 4258268Seric EXTERN char *QueueDir; /* location of queue directory */ 4268929Seric EXTERN char *TrustedUsers[MAXTRUST+1]; /* list of trusted users */ 4278268Seric EXTERN jmp_buf TopFrame; /* branch-to-top-of-loop-on-error frame */ 4288268Seric EXTERN bool QuickAbort; /* .... but only if we want a quick abort */ 4297859Seric extern char *ConfFile; /* location of configuration file [conf.c] */ 4309065Seric extern char *FreezeFile; /* location of frozen memory image [conf.c] */ 4317859Seric extern char Arpa_Info[]; /* the reply code for Arpanet info [conf.c] */ 4329041Seric extern char SpaceSub; /* substitution for <lwsp> [conf.c] */ 4337674Seric /* 4347674Seric ** Trace information 4357674Seric */ 436295Seric 4377674Seric /* trace vector and macros for debugging flags */ 4387674Seric EXTERN u_char tTdvect[100]; 4397674Seric # define tTd(flag, level) (tTdvect[flag] >= level) 4407674Seric # define tTdlevel(flag) (tTdvect[flag]) 4417674Seric /* 4427674Seric ** Miscellaneous information. 4437674Seric */ 444295Seric 445295Seric # include <sysexits.h> 446295Seric 447295Seric # define setstat(s) { if (ExitStat == EX_OK) ExitStat = s; } 4484085Seric 4494085Seric 4504085Seric /* useful functions */ 4514085Seric 4524085Seric extern char *newstr(); 4534085Seric extern ADDRESS *parse(); 4544085Seric extern char *xalloc(); 4554085Seric extern bool sameaddr(); 4566889Seric extern FILE *dfopen(); 4577684Seric extern EVENT *setevent(); 4587684Seric extern char *sfgets(); 4597810Seric extern char *queuename(); 4607884Seric extern time_t curtime(); 461