1295Seric /* 23313Seric ** SENDMAIL.H -- Global definitions for sendmail. 3295Seric */ 4295Seric 5295Seric 6295Seric 74371Seric # ifdef _DEFINE 84371Seric # define EXTERN 95194Seric # ifndef lint 10*7355Seric static char SmailSccsId[] = "@(#)sendmail.h 3.75 07/05/82"; 115194Seric # endif lint 124371Seric # else _DEFINE 134371Seric # define EXTERN extern 144371Seric # endif _DEFINE 15295Seric 164183Seric # include <stdio.h> 174183Seric # include <ctype.h> 18*7355Seric # include <setjmp.h> 191390Seric # include "useful.h" 201390Seric 21295Seric /* 224284Seric ** Configuration constants. 234284Seric ** There shouldn't be much need to change these.... 24295Seric */ 25295Seric 264374Seric # define MAXLINE 256 /* max line length */ 274374Seric # define MAXNAME 128 /* max length of a name */ 284374Seric # define MAXFIELD 2500 /* max total length of a hdr field */ 294374Seric # define MAXPV 40 /* max # of parms to mailers */ 304374Seric # define MAXHOP 30 /* max value of HopCount */ 314384Seric # define MAXATOM 30 /* max atoms per address */ 324374Seric # define MAXMAILERS 10 /* maximum mailers known to system */ 334374Seric # define SPACESUB ('.'|0200) /* substitution for <lwsp> */ 34295Seric 354167Seric extern char Arpa_Info[]; /* the message number for Arpanet info */ 366902Seric /* 373190Seric ** Address structure. 383190Seric ** Addresses are stored internally in this structure. 393190Seric */ 403190Seric 413190Seric struct address 423190Seric { 433190Seric char *q_paddr; /* the printname for the address */ 443190Seric char *q_user; /* user name */ 453190Seric char *q_host; /* host name */ 464597Seric struct mailer *q_mailer; /* mailer to use */ 473190Seric short q_rmailer; /* real mailer (before mapping) */ 484149Seric u_short q_flags; /* status flags, see below */ 494213Seric short q_uid; /* user-id of receiver (if known) */ 504398Seric short q_gid; /* group-id of receiver (if known) */ 514079Seric char *q_home; /* home dir (local mailer only) */ 524995Seric char *q_fullname; /* full name if known */ 534995Seric struct address *q_next; /* chain */ 544995Seric struct address *q_alias; /* address this results from */ 555034Seric struct address *q_tchain; /* temporary use chain */ 564987Seric time_t q_timeout; /* timeout for this address */ 573190Seric }; 583190Seric 593190Seric typedef struct address ADDRESS; 603190Seric 613190Seric # define QDONTSEND 000001 /* don't send to this address */ 624068Seric # define QBADADDR 000002 /* this address is verified bad */ 634403Seric # define QGOODUID 000004 /* the q_uid q_gid fields are good */ 644422Seric # define QPRIMARY 000010 /* set from argv */ 654624Seric # define QQUEUEUP 000020 /* queue for later transmission */ 666902Seric /* 67295Seric ** Mailer definition structure. 68295Seric ** Every mailer known to the system is declared in this 69295Seric ** structure. It defines the pathname of the mailer, some 70295Seric ** flags associated with it, and the argument vector to 711390Seric ** pass to it. The flags are defined in conf.c 72295Seric ** 734171Seric ** The argument vector is expanded before actual use. All 744171Seric ** words except the first are passed through the macro 754171Seric ** processor. 76295Seric */ 77295Seric 78295Seric struct mailer 79295Seric { 803190Seric char *m_name; /* symbolic name of this mailer */ 81295Seric char *m_mailer; /* pathname of the mailer to use */ 824149Seric u_long m_flags; /* status flags, see below */ 83295Seric short m_badstat; /* the status code to use on unknown error */ 844438Seric short m_mno; /* mailer number internally */ 852899Seric char *m_from; /* pattern for From: header */ 863049Seric char **m_argv; /* template argument vector */ 87295Seric }; 88295Seric 894100Seric typedef struct mailer MAILER; 904100Seric 915601Seric /* bits for m_flags */ 926819Seric # define M_FOPT 000000001L /* mailer takes picky -f flag */ 936819Seric # define M_ROPT 000000002L /* mailer takes picky -r flag */ 946819Seric # define M_QUIET 000000004L /* don't print error on bad status */ 956819Seric # define M_RESTR 000000010L /* must be daemon to execute */ 966819Seric # define M_NHDR 000000020L /* don't insert From line */ 976819Seric # define M_LOCAL 000000040L /* delivery is to this host */ 986819Seric # define M_STRIPQ 000000100L /* strip quote chars from user/host */ 996819Seric # define M_MUSER 000000200L /* can handle multiple users at once */ 1006819Seric # define M_NEEDFROM 000000400L /* need arpa-style From: line */ 1016819Seric # define M_NEEDDATE 000001000L /* need arpa-style Date: line */ 1026819Seric # define M_MSGID 000002000L /* need Message-Id: field */ 1036819Seric # define M_RELRCPT 000004000L /* make recipient addresses relative */ 1046819Seric # define M_USR_UPPER 000010000L /* preserve user case distinction */ 1056819Seric # define M_HST_UPPER 000020000L /* preserve host case distinction */ 1066819Seric # define M_FULLNAME 000040000L /* want Full-Name field */ 1076819Seric # define M_UGLYUUCP 000100000L /* this wants an ugly UUCP from line */ 1086819Seric # define M_EXPENSIVE 000200000L /* it costs to use this mailer.... */ 1096982Seric # define M_FULLSMTP 000400000L /* must run full SMTP, inc. limits */ 110295Seric 1114317Seric # define M_ARPAFMT (M_NEEDDATE|M_NEEDFROM|M_MSGID) 1122899Seric 1134597Seric EXTERN MAILER *Mailer[MAXMAILERS+1]; 114295Seric 1154597Seric EXTERN MAILER *LocalMailer; /* ptr to local mailer */ 1164597Seric EXTERN MAILER *ProgMailer; /* ptr to program mailer */ 1176902Seric /* 1182899Seric ** Header structure. 1192899Seric ** This structure is used internally to store header items. 1202899Seric */ 121295Seric 1222899Seric struct header 1232899Seric { 1242899Seric char *h_field; /* the name of the field */ 1252899Seric char *h_value; /* the value of that field */ 1262899Seric struct header *h_link; /* the next header */ 1274149Seric u_short h_flags; /* status bits, see below */ 1284149Seric u_long h_mflags; /* m_flags bits needed */ 1292899Seric }; 130295Seric 1312899Seric typedef struct header HDR; 1322899Seric 133295Seric /* 1342899Seric ** Header information structure. 1352899Seric ** Defined in conf.c, this struct declares the header fields 1362899Seric ** that have some magic meaning. 1372899Seric */ 1382899Seric 1392899Seric struct hdrinfo 1402899Seric { 1412899Seric char *hi_field; /* the name of the field */ 1424149Seric u_short hi_flags; /* status bits, see below */ 1434149Seric u_short hi_mflags; /* m_flags needed for this field */ 1442899Seric }; 1452899Seric 1462899Seric extern struct hdrinfo HdrInfo[]; 1472899Seric 1482899Seric /* bits for h_flags and hi_flags */ 1493060Seric # define H_EOH 00001 /* this field terminates header */ 1505918Seric # define H_RCPT 00002 /* contains recipient addresses */ 1512899Seric # define H_DEFAULT 00004 /* if another value is found, drop this */ 1522899Seric # define H_USED 00010 /* indicates that this has been output */ 1533386Seric # define H_CHECK 00020 /* check h_mflags against m_flags */ 1543390Seric # define H_ACHECK 00040 /* ditto, but always (not just default) */ 1554149Seric # define H_FORCE 00100 /* force this field, even if default */ 1564222Seric # define H_ADDR 00200 /* this field contains addresses */ 1576902Seric /* 1586902Seric ** Envelope structure. 1596902Seric ** This structure defines the message itself. There is usually 1606902Seric ** only one of these -- for the message that we originally read 1616902Seric ** and which is our primary interest -- but other envelopes can 1626902Seric ** be generated during processing. For example, error messages 1636902Seric ** will have their own envelope. 1646902Seric */ 1652899Seric 1666902Seric struct envelope 1676902Seric { 1686987Seric HDR *e_header; /* head of header list */ 1696987Seric long e_msgpriority; /* adjusted priority of this message */ 1706987Seric bool e_queueup; /* queue this message */ 1716987Seric bool e_oldstyle; /* use spaces (not commas) in hdrs */ 1726987Seric bool e_retreceipt; /* give a return receipt */ 1736987Seric bool e_sendreceipt; /* actually send a receipt back */ 1746987Seric char *e_origfrom; /* the From: line first read */ 1756987Seric char *e_to; /* the target person */ 1766987Seric ADDRESS e_from; /* the person it is from */ 1776987Seric ADDRESS *e_sendqueue; /* list of message recipients */ 1787044Seric ADDRESS *e_errorqueue; /* the queue for error responses */ 1796987Seric long e_msgsize; /* size of the message in bytes */ 1806987Seric short e_class; /* msg class (priority, junk, etc.) */ 1816987Seric int (*e_puthdr)(); /* function to put header of message */ 1826987Seric int (*e_putbody)(); /* function to put body of message */ 1836987Seric struct envelope *e_parent; /* the message this one encloses */ 1846987Seric char *e_df; /* location of temp file */ 1856987Seric char *e_macro[128]; /* macro definitions */ 1866902Seric }; 1872899Seric 1886902Seric typedef struct envelope ENVELOPE; 1894624Seric 1906902Seric EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */ 1916902Seric /* 1924624Seric ** Work queue. 1934624Seric */ 1944624Seric 1954624Seric struct work 1964624Seric { 1974624Seric char *w_name; /* name of control file */ 1985034Seric long w_pri; /* priority of message, see below */ 1994624Seric struct work *w_next; /* next in queue */ 2004624Seric }; 2014624Seric 2024624Seric typedef struct work WORK; 2034624Seric 2044624Seric EXTERN WORK *WorkQ; /* queue of things to be done */ 2054624Seric 2064624Seric 2074624Seric /* 2084624Seric ** Message priorities. 2094633Seric ** Priorities > 0 should be preemptive. 2105034Seric ** 2116902Seric ** CurEnv->e_msgpriority is the number of bytes in the message adjusted 2125034Seric ** by the message priority and the amount of time the message 2135034Seric ** has been sitting around. Each priority point is worth 2145034Seric ** WKPRIFACT bytes of message, and each time we reprocess a 2155034Seric ** message the size gets reduced by WKTIMEFACT. 2166910Seric ** 2176910Seric ** The "class" is this number, unadjusted by the age or size of 2186910Seric ** this message. Classes with negative representations will have 2196910Seric ** error messages thrown away if they are not local. 2204624Seric */ 2214624Seric 2226910Seric # define PRI_ALERT 50 2236910Seric # define PRI_QUICK 30 2246910Seric # define PRI_FIRSTCL 10 2255034Seric # define PRI_NORMAL 0 2264633Seric # define PRI_SECONDCL -10 2276910Seric # define PRI_THIRDCL -40 2286910Seric # define PRI_JUNK -100 2294624Seric 2305034Seric # define WKPRIFACT 1800 /* bytes each pri point is worth */ 2315034Seric # define WKTIMEFACT 400 /* bytes each time unit is worth */ 2326902Seric /* 2333153Seric ** Rewrite rules. 2343153Seric */ 2352899Seric 2363153Seric struct rewrite 2373153Seric { 2383153Seric char **r_lhs; /* pattern match */ 2393153Seric char **r_rhs; /* substitution value */ 2403153Seric struct rewrite *r_next;/* next in chain */ 2413153Seric }; 2422899Seric 2434090Seric extern struct rewrite *RewriteRules[]; 2443153Seric 2454060Seric # define MATCHANY '\020' /* match one or more tokens */ 2464060Seric # define MATCHONE '\021' /* match exactly one token */ 2474060Seric # define MATCHCLASS '\022' /* match one token in a class */ 2484467Seric # define MATCHREPL '\023' /* replacement on RHS for above */ 2493153Seric 2503153Seric # define CANONNET '\025' /* canonical net, next token */ 2513153Seric # define CANONHOST '\026' /* canonical host, next token */ 2523153Seric # define CANONUSER '\027' /* canonical user, next N tokens */ 2533153Seric 2546052Seric # define CONDIF '\030' /* conditional if-then */ 2556052Seric # define CONDELSE '\031' /* conditional else */ 2566052Seric # define CONDFI '\032' /* conditional fi */ 2576902Seric /* 2584056Seric ** Symbol table definitions 2594056Seric */ 2603153Seric 2614056Seric struct symtab 2624056Seric { 2634056Seric char *s_name; /* name to be entered */ 2644100Seric char s_type; /* general type (see below) */ 2654056Seric struct symtab *s_next; /* pointer to next in chain */ 2664100Seric union 2674100Seric { 2684100Seric long sv_class; /* bit-map of word classes */ 2694100Seric ADDRESS *sv_addr; /* pointer to address header */ 2704100Seric MAILER *sv_mailer; /* pointer to mailer */ 2714100Seric char *sv_alias; /* alias */ 2724100Seric } s_value; 2734056Seric }; 2744056Seric 2754056Seric typedef struct symtab STAB; 2764056Seric 2774100Seric /* symbol types */ 2784100Seric # define ST_UNDEF 0 /* undefined type */ 2794100Seric # define ST_CLASS 1 /* class map */ 2804100Seric # define ST_ADDRESS 2 /* an address in parsed format */ 2814100Seric # define ST_MAILER 3 /* a mailer header */ 2824100Seric # define ST_ALIAS 4 /* an alias */ 2834100Seric 2844100Seric # define s_class s_value.sv_class 2855976Seric # define s_address s_value.sv_addr 2864100Seric # define s_mailer s_value.sv_mailer 2874100Seric # define s_alias s_value.sv_alias 2884100Seric 2894056Seric extern STAB *stab(); 2904056Seric 2914056Seric /* opcodes to stab */ 2924056Seric # define ST_FIND 0 /* find entry */ 2934056Seric # define ST_ENTER 1 /* enter if not there */ 2946902Seric /* 2954284Seric ** Statistics structure. 2964284Seric */ 2974284Seric 2984284Seric struct statistics 2994284Seric { 3004284Seric time_t stat_itime; /* file initialization time */ 3014284Seric short stat_size; /* size of this structure */ 3024284Seric long stat_nf[MAXMAILERS]; /* # msgs from each mailer */ 3034284Seric long stat_bf[MAXMAILERS]; /* kbytes from each mailer */ 3044284Seric long stat_nt[MAXMAILERS]; /* # msgs to each mailer */ 3054284Seric long stat_bt[MAXMAILERS]; /* kbytes to each mailer */ 3064284Seric }; 3074284Seric 3084371Seric EXTERN struct statistics Stat; 3094284Seric extern long kbytes(); /* for _bf, _bt */ 3106902Seric /* 3116997Seric ** Operation modes 3126997Seric ** The default operation mode can be safely changed (except 3136997Seric ** that the default cannot be MD_DAEMON). 3146997Seric */ 3156997Seric 3166997Seric EXTERN char Mode; /* operation mode, see below */ 3176997Seric 3186997Seric #define MD_DELIVER 'a' /* collect and deliver */ 3196997Seric #define MD_FORK 'f' /* verify & fork before delivery */ 3206997Seric #define MD_QUEUE 'q' /* collect & queue, don't deliver */ 3216997Seric #define MD_DAEMON 'd' /* run as a daemon */ 3226997Seric #define MD_VERIFY 'v' /* verify: don't collect or deliver */ 3236997Seric 3246997Seric #define MD_DEFAULT MD_DELIVER /* default operation mode */ 3256997Seric /* 326295Seric ** Global variables. 327295Seric */ 328295Seric 3294371Seric EXTERN bool FromFlag; /* if set, "From" person is explicit */ 3304371Seric EXTERN bool MailBack; /* mail back response on error */ 3314371Seric EXTERN bool BerkNet; /* called from BerkNet */ 3324371Seric EXTERN bool WriteBack; /* write back response on error */ 3334371Seric EXTERN bool NoAlias; /* if set, don't do any aliasing */ 3344371Seric EXTERN bool ForceMail; /* if set, mail even if already got a copy */ 3354371Seric EXTERN bool MeToo; /* send to the sender also */ 3364371Seric EXTERN bool IgnrDot; /* don't let dot end messages */ 3374371Seric EXTERN bool SaveFrom; /* save leading "From" lines */ 3384371Seric EXTERN bool Verbose; /* set if blow-by-blow desired */ 3394371Seric EXTERN bool GrabTo; /* if set, get recipients from msg */ 3404371Seric EXTERN bool DontSend; /* mark recipients as QDONTSEND */ 3414371Seric EXTERN bool NoReturn; /* don't return letter to sender */ 3424553Seric EXTERN bool Smtp; /* using SMTP over connection */ 3434553Seric EXTERN bool SuprErrs; /* set if we are suppressing errors */ 3446049Seric EXTERN bool QueueRun; /* currently running message from the queue */ 3454711Seric EXTERN bool HoldErrs; /* only output errors to transcript */ 3464711Seric EXTERN bool ArpaMode; /* set if running arpanet protocol */ 3475904Seric EXTERN bool NoConnect; /* don't connect to non-local mailers */ 3486049Seric EXTERN bool FatalErrors; /* set if fatal errors during processing */ 3494624Seric extern time_t TimeOut; /* time until timeout */ 3504553Seric EXTERN FILE *InChannel; /* input connection */ 3514553Seric EXTERN FILE *OutChannel; /* output connection */ 3524553Seric EXTERN FILE *TempFile; /* mail temp file */ 3534711Seric EXTERN FILE *Xscript; /* mail transcript file */ 3544537Seric EXTERN int RealUid; /* when Daemon, real uid of caller */ 3554537Seric EXTERN int RealGid; /* when Daemon, real gid of caller */ 3565703Seric extern int DefUid; /* default uid to run as */ 3575703Seric extern int DefGid; /* default gid to run as */ 3584371Seric EXTERN int OldUmask; /* umask when sendmail starts up */ 3594371Seric EXTERN int Debug; /* debugging level */ 3606049Seric EXTERN int Errors; /* set if errors (local to single pass) */ 3614371Seric EXTERN int ExitStat; /* exit status code */ 3624553Seric EXTERN int HopCount; /* hop count */ 3634553Seric EXTERN int AliasLevel; /* depth of aliasing */ 3647282Seric EXTERN int MotherPid; /* proc id of parent process */ 3654624Seric EXTERN time_t QueueIntvl; /* intervals between running the queue */ 3664553Seric EXTERN char *HostName; /* name of this host for SMTP messages */ 3674624Seric EXTERN char *Transcript; /* the transcript file name */ 3684624Seric extern char *XcriptFile; /* template for Transcript */ 3694624Seric extern char *AliasFile; /* location of alias file */ 3704624Seric extern char *ConfFile; /* location of configuration file */ 3714624Seric extern char *StatFile; /* location of statistics summary */ 3724624Seric extern char *QueueDir; /* location of queue directory */ 3737349Seric EXTERN char *ControlFile; /* when queued, name of control file temp */ 3744624Seric EXTERN time_t CurTime; /* time of this message */ 375*7355Seric EXTERN jmp_buf TickFrame; /* frame for clock ticks to jump to */ 376*7355Seric extern int ReadTimeout; /* timeout on reads before clock ticks */ 377295Seric 378295Seric 379295Seric # include <sysexits.h> 380295Seric 381295Seric # define setstat(s) { if (ExitStat == EX_OK) ExitStat = s; } 3824085Seric 3834085Seric 3844085Seric /* useful functions */ 3854085Seric 3864085Seric extern char *newstr(); 3874085Seric extern ADDRESS *parse(); 3884085Seric extern char *xalloc(); 3894085Seric extern bool sameaddr(); 3906889Seric extern FILE *dfopen(); 391