1295Seric /* 23313Seric ** SENDMAIL.H -- Global definitions for sendmail. 3295Seric */ 4295Seric 5295Seric 6295Seric 74371Seric # ifdef _DEFINE 84371Seric # define EXTERN 95194Seric # ifndef lint 10*9883Seric static char SmailSccsId[] = "@(#)sendmail.h 3.105 12/24/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 */ 714438Seric short m_mno; /* mailer number internally */ 723049Seric char **m_argv; /* template argument vector */ 738061Seric short m_s_rwset; /* rewriting set for sender addresses */ 748061Seric short m_r_rwset; /* rewriting set for recipient addresses */ 75295Seric }; 76295Seric 774100Seric typedef struct mailer MAILER; 784100Seric 795601Seric /* bits for m_flags */ 806819Seric # define M_FOPT 000000001L /* mailer takes picky -f flag */ 816819Seric # define M_ROPT 000000002L /* mailer takes picky -r flag */ 829373Seric # define M_RPATH 000000004L /* wants a Return-Path: line */ 836819Seric # define M_RESTR 000000010L /* must be daemon to execute */ 846819Seric # define M_NHDR 000000020L /* don't insert From line */ 856819Seric # define M_LOCAL 000000040L /* delivery is to this host */ 866819Seric # define M_STRIPQ 000000100L /* strip quote chars from user/host */ 876819Seric # define M_MUSER 000000200L /* can handle multiple users at once */ 886819Seric # define M_NEEDFROM 000000400L /* need arpa-style From: line */ 896819Seric # define M_NEEDDATE 000001000L /* need arpa-style Date: line */ 906819Seric # define M_MSGID 000002000L /* need Message-Id: field */ 918180Seric # define M_CANONICAL 000004000L /* make addresses canonical "u@dom" */ 926819Seric # define M_USR_UPPER 000010000L /* preserve user case distinction */ 936819Seric # define M_HST_UPPER 000020000L /* preserve host case distinction */ 946819Seric # define M_FULLNAME 000040000L /* want Full-Name field */ 956819Seric # define M_UGLYUUCP 000100000L /* this wants an ugly UUCP from line */ 966819Seric # define M_EXPENSIVE 000200000L /* it costs to use this mailer.... */ 976982Seric # define M_FULLSMTP 000400000L /* must run full SMTP, inc. limits */ 989312Seric # define M_INTERNAL 001000000L /* SMTP to another sendmail site */ 99295Seric 1004317Seric # define M_ARPAFMT (M_NEEDDATE|M_NEEDFROM|M_MSGID) 1012899Seric 1024597Seric EXTERN MAILER *Mailer[MAXMAILERS+1]; 103295Seric 1044597Seric EXTERN MAILER *LocalMailer; /* ptr to local mailer */ 1054597Seric EXTERN MAILER *ProgMailer; /* ptr to program mailer */ 1066902Seric /* 1072899Seric ** Header structure. 1082899Seric ** This structure is used internally to store header items. 1092899Seric */ 110295Seric 1112899Seric struct header 1122899Seric { 1132899Seric char *h_field; /* the name of the field */ 1142899Seric char *h_value; /* the value of that field */ 1152899Seric struct header *h_link; /* the next header */ 1164149Seric u_short h_flags; /* status bits, see below */ 1174149Seric u_long h_mflags; /* m_flags bits needed */ 1182899Seric }; 119295Seric 1202899Seric typedef struct header HDR; 1212899Seric 122295Seric /* 1232899Seric ** Header information structure. 1242899Seric ** Defined in conf.c, this struct declares the header fields 1252899Seric ** that have some magic meaning. 1262899Seric */ 1272899Seric 1282899Seric struct hdrinfo 1292899Seric { 1302899Seric char *hi_field; /* the name of the field */ 1314149Seric u_short hi_flags; /* status bits, see below */ 1322899Seric }; 1332899Seric 1342899Seric extern struct hdrinfo HdrInfo[]; 1352899Seric 1362899Seric /* bits for h_flags and hi_flags */ 1373060Seric # define H_EOH 00001 /* this field terminates header */ 1385918Seric # define H_RCPT 00002 /* contains recipient addresses */ 1392899Seric # define H_DEFAULT 00004 /* if another value is found, drop this */ 1403386Seric # define H_CHECK 00020 /* check h_mflags against m_flags */ 1413390Seric # define H_ACHECK 00040 /* ditto, but always (not just default) */ 1424149Seric # define H_FORCE 00100 /* force this field, even if default */ 1438061Seric # define H_TRACE 00200 /* this field contains trace information */ 1447761Seric # define H_FROM 00400 /* this is a from-type field */ 1456902Seric /* 1466902Seric ** Envelope structure. 1476902Seric ** This structure defines the message itself. There is usually 1486902Seric ** only one of these -- for the message that we originally read 1496902Seric ** and which is our primary interest -- but other envelopes can 1506902Seric ** be generated during processing. For example, error messages 1516902Seric ** will have their own envelope. 1526902Seric */ 1532899Seric 1546902Seric struct envelope 1556902Seric { 1566987Seric HDR *e_header; /* head of header list */ 1576987Seric long e_msgpriority; /* adjusted priority of this message */ 1587859Seric time_t e_ctime; /* time message appeared in the queue */ 1596987Seric char *e_to; /* the target person */ 1608061Seric char *e_receiptto; /* return receipt address */ 1616987Seric ADDRESS e_from; /* the person it is from */ 1628180Seric char **e_fromdomain; /* the domain part of the sender */ 1636987Seric ADDRESS *e_sendqueue; /* list of message recipients */ 1647044Seric ADDRESS *e_errorqueue; /* the queue for error responses */ 1656987Seric long e_msgsize; /* size of the message in bytes */ 1666987Seric short e_class; /* msg class (priority, junk, etc.) */ 1679336Seric short e_flags; /* flags, see below */ 1689373Seric short e_hopcount; /* number of times processed */ 1696987Seric int (*e_puthdr)(); /* function to put header of message */ 1706987Seric int (*e_putbody)(); /* function to put body of message */ 1716987Seric struct envelope *e_parent; /* the message this one encloses */ 1729336Seric struct envelope *e_sibling; /* the next envelope of interest */ 1736987Seric char *e_df; /* location of temp file */ 1749541Seric FILE *e_dfp; /* temporary file */ 1757810Seric char *e_id; /* code for this entry in queue */ 1769541Seric FILE *e_xfp; /* transcript file */ 1776987Seric char *e_macro[128]; /* macro definitions */ 1786902Seric }; 1792899Seric 1806902Seric typedef struct envelope ENVELOPE; 1814624Seric 1829336Seric /* values for e_flags */ 1839336Seric #define EF_OLDSTYLE 000001 /* use spaces (not commas) in hdrs */ 1849336Seric #define EF_INQUEUE 000002 /* this message is fully queued */ 1859336Seric #define EF_TIMEOUT 000004 /* this message is too old */ 1869336Seric #define EF_CLRQUEUE 000010 /* disk copy is no longer needed */ 1879336Seric #define EF_SENDRECEIPT 000020 /* send a return receipt */ 1889336Seric #define EF_FATALERRS 000040 /* fatal errors occured */ 1899336Seric #define EF_KEEPQUEUE 000100 /* keep queue files always */ 1909373Seric #define EF_RESPONSE 000200 /* this is an error or return receipt */ 1919336Seric 1926902Seric EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */ 1936902Seric /* 1944624Seric ** Message priorities. 1954633Seric ** Priorities > 0 should be preemptive. 1965034Seric ** 1976902Seric ** CurEnv->e_msgpriority is the number of bytes in the message adjusted 1985034Seric ** by the message priority and the amount of time the message 1995034Seric ** has been sitting around. Each priority point is worth 2005034Seric ** WKPRIFACT bytes of message, and each time we reprocess a 2015034Seric ** message the size gets reduced by WKTIMEFACT. 2026910Seric ** 2036910Seric ** The "class" is this number, unadjusted by the age or size of 2046910Seric ** this message. Classes with negative representations will have 2056910Seric ** error messages thrown away if they are not local. 2064624Seric */ 2074624Seric 2088249Seric struct priority 2098249Seric { 2108249Seric char *pri_name; /* external name of priority */ 2118249Seric int pri_val; /* internal value for same */ 2128249Seric }; 2134624Seric 2148249Seric EXTERN struct priority Priorities[MAXPRIORITIES]; 2158249Seric EXTERN int NumPriorities; /* pointer into Priorities */ 2168249Seric 2175034Seric # define WKPRIFACT 1800 /* bytes each pri point is worth */ 2185034Seric # define WKTIMEFACT 400 /* bytes each time unit is worth */ 2196902Seric /* 2203153Seric ** Rewrite rules. 2213153Seric */ 2222899Seric 2233153Seric struct rewrite 2243153Seric { 2253153Seric char **r_lhs; /* pattern match */ 2263153Seric char **r_rhs; /* substitution value */ 2273153Seric struct rewrite *r_next;/* next in chain */ 2283153Seric }; 2292899Seric 2308057Seric EXTERN struct rewrite *RewriteRules[MAXRWSETS]; 2313153Seric 2328057Seric /* 2338057Seric ** Special characters in rewriting rules. 2348057Seric ** These are used internally only. 2358057Seric ** The COND* rules are actually used in macros rather than in 2368057Seric ** rewriting rules, but are given here because they 2378057Seric ** cannot conflict. 2388057Seric */ 2393153Seric 2408057Seric /* left hand side items */ 2418057Seric # define MATCHZANY '\020' /* match zero or more tokens */ 2428057Seric # define MATCHANY '\021' /* match one or more tokens */ 2438057Seric # define MATCHONE '\022' /* match exactly one token */ 2448057Seric # define MATCHCLASS '\023' /* match one token in a class */ 2459584Seric # define MATCHNCLASS '\034' /* match anything not in class */ 2468057Seric # define MATCHREPL '\024' /* replacement on RHS for above */ 2478057Seric 2488057Seric /* right hand side items */ 2493153Seric # define CANONNET '\025' /* canonical net, next token */ 2503153Seric # define CANONHOST '\026' /* canonical host, next token */ 2513153Seric # define CANONUSER '\027' /* canonical user, next N tokens */ 2528057Seric # define CALLSUBR '\030' /* call another rewriting set */ 2533153Seric 2548057Seric /* conditionals in macros */ 2558057Seric # define CONDIF '\031' /* conditional if-then */ 2568057Seric # define CONDELSE '\032' /* conditional else */ 2578057Seric # define CONDFI '\033' /* conditional fi */ 2586902Seric /* 2594056Seric ** Symbol table definitions 2604056Seric */ 2613153Seric 2624056Seric struct symtab 2634056Seric { 2644056Seric char *s_name; /* name to be entered */ 2654100Seric char s_type; /* general type (see below) */ 2664056Seric struct symtab *s_next; /* pointer to next in chain */ 2674100Seric union 2684100Seric { 2694100Seric long sv_class; /* bit-map of word classes */ 2704100Seric ADDRESS *sv_addr; /* pointer to address header */ 2714100Seric MAILER *sv_mailer; /* pointer to mailer */ 2724100Seric char *sv_alias; /* alias */ 2734100Seric } s_value; 2744056Seric }; 2754056Seric 2764056Seric typedef struct symtab STAB; 2774056Seric 2784100Seric /* symbol types */ 2794100Seric # define ST_UNDEF 0 /* undefined type */ 2804100Seric # define ST_CLASS 1 /* class map */ 2814100Seric # define ST_ADDRESS 2 /* an address in parsed format */ 2824100Seric # define ST_MAILER 3 /* a mailer header */ 2834100Seric # define ST_ALIAS 4 /* an alias */ 2844100Seric 2854100Seric # define s_class s_value.sv_class 2865976Seric # define s_address s_value.sv_addr 2874100Seric # define s_mailer s_value.sv_mailer 2884100Seric # define s_alias s_value.sv_alias 2894100Seric 2904056Seric extern STAB *stab(); 2914056Seric 2924056Seric /* opcodes to stab */ 2934056Seric # define ST_FIND 0 /* find entry */ 2944056Seric # define ST_ENTER 1 /* enter if not there */ 2956902Seric /* 2967684Seric ** STRUCT EVENT -- event queue. 2977684Seric ** 2987684Seric ** Maintained in sorted order. 2997931Seric ** 3007931Seric ** We store the pid of the process that set this event to insure 3017931Seric ** that when we fork we will not take events intended for the parent. 3027684Seric */ 3037684Seric 3047684Seric struct event 3057684Seric { 3067684Seric time_t ev_time; /* time of the function call */ 3077684Seric int (*ev_func)(); /* function to call */ 3087684Seric int ev_arg; /* argument to ev_func */ 3097931Seric int ev_pid; /* pid that set this event */ 3107684Seric struct event *ev_link; /* link to next item */ 3117684Seric }; 3127684Seric 3137684Seric typedef struct event EVENT; 3147684Seric 3157684Seric EXTERN EVENT *EventQueue; /* head of event queue */ 3167684Seric /* 3179373Seric ** Operation, send, and error modes 3189278Seric ** 3199278Seric ** The operation mode describes the basic operation of sendmail. 3209278Seric ** This can be set from the command line, and is "send mail" by 3219278Seric ** default. 3229278Seric ** 3239278Seric ** The send mode tells how to send mail. It can be set in the 3249278Seric ** configuration file. It's setting determines how quickly the 3259278Seric ** mail will be delivered versus the load on your system. If the 3269278Seric ** -v (verbose) flag is given, it will be forced to SM_DELIVER 3279278Seric ** mode. 3289278Seric ** 3299373Seric ** The error mode tells how to return errors. 3306997Seric */ 3316997Seric 3329278Seric EXTERN char OpMode; /* operation mode, see below */ 3336997Seric 3349278Seric #define MD_DELIVER 'm' /* be a mail sender */ 3359278Seric #define MD_ARPAFTP 'a' /* old-style arpanet protocols */ 3369278Seric #define MD_SMTP 's' /* run SMTP on standard input */ 3376997Seric #define MD_DAEMON 'd' /* run as a daemon */ 3386997Seric #define MD_VERIFY 'v' /* verify: don't collect or deliver */ 3398334Seric #define MD_TEST 't' /* test mode: resolve addrs only */ 3409144Seric #define MD_INITALIAS 'i' /* initialize alias database */ 3419144Seric #define MD_PRINT 'p' /* print the queue */ 3429144Seric #define MD_FREEZE 'z' /* freeze the configuration file */ 3436997Seric 3449278Seric 3459278Seric EXTERN char SendMode; /* send mode, see below */ 3469278Seric 3479278Seric #define SM_DELIVER 'i' /* interactive delivery */ 3489278Seric #define SM_QUICKD 'j' /* deliver w/o queueing */ 3499278Seric #define SM_FORK 'b' /* deliver in background */ 3509278Seric #define SM_QUEUE 'q' /* queue, don't deliver */ 3519278Seric #define SM_VERIFY 'v' /* verify only (used internally) */ 3529373Seric 3539373Seric 3549373Seric EXTERN char ErrorMode; /* error mode, see below */ 3559373Seric 3569373Seric #define EM_PRINT 'p' /* print errors */ 3579373Seric #define EM_MAIL 'm' /* mail back errors */ 3589373Seric #define EM_WRITE 'w' /* write back errors */ 3599373Seric #define EM_BERKNET 'e' /* special berknet processing */ 3609373Seric #define EM_QUIET 'q' /* don't print messages (stat only) */ 3616997Seric /* 362295Seric ** Global variables. 363295Seric */ 364295Seric 3654371Seric EXTERN bool FromFlag; /* if set, "From" person is explicit */ 3664371Seric EXTERN bool NoAlias; /* if set, don't do any aliasing */ 3674371Seric EXTERN bool ForceMail; /* if set, mail even if already got a copy */ 3684371Seric EXTERN bool MeToo; /* send to the sender also */ 3694371Seric EXTERN bool IgnrDot; /* don't let dot end messages */ 3704371Seric EXTERN bool SaveFrom; /* save leading "From" lines */ 3714371Seric EXTERN bool Verbose; /* set if blow-by-blow desired */ 3724371Seric EXTERN bool GrabTo; /* if set, get recipients from msg */ 3734371Seric EXTERN bool NoReturn; /* don't return letter to sender */ 3744553Seric EXTERN bool SuprErrs; /* set if we are suppressing errors */ 3756049Seric EXTERN bool QueueRun; /* currently running message from the queue */ 3764711Seric EXTERN bool HoldErrs; /* only output errors to transcript */ 3775904Seric EXTERN bool NoConnect; /* don't connect to non-local mailers */ 3788268Seric EXTERN bool SuperSafe; /* be extra careful, even if expensive */ 3798929Seric EXTERN bool SafeAlias; /* alias file must have "@:@" to be complete */ 3809144Seric EXTERN bool AutoRebuild; /* auto-rebuild the alias database as needed */ 3818268Seric EXTERN time_t TimeOut; /* time until timeout */ 3824553Seric EXTERN FILE *InChannel; /* input connection */ 3834553Seric EXTERN FILE *OutChannel; /* output connection */ 3844537Seric EXTERN int RealUid; /* when Daemon, real uid of caller */ 3854537Seric EXTERN int RealGid; /* when Daemon, real gid of caller */ 3868268Seric EXTERN int DefUid; /* default uid to run as */ 3878268Seric EXTERN int DefGid; /* default gid to run as */ 3884371Seric EXTERN int OldUmask; /* umask when sendmail starts up */ 3896049Seric EXTERN int Errors; /* set if errors (local to single pass) */ 3904371Seric EXTERN int ExitStat; /* exit status code */ 3914553Seric EXTERN int AliasLevel; /* depth of aliasing */ 3927282Seric EXTERN int MotherPid; /* proc id of parent process */ 3938057Seric EXTERN int LineNumber; /* line number in current input */ 3948268Seric EXTERN int ReadTimeout; /* timeout on reads */ 3958268Seric EXTERN int LogLevel; /* level of logging to perform */ 3969045Seric EXTERN int FileMode; /* mode on files */ 3974624Seric EXTERN time_t QueueIntvl; /* intervals between running the queue */ 3984553Seric EXTERN char *HostName; /* name of this host for SMTP messages */ 3998268Seric EXTERN char *AliasFile; /* location of alias file */ 4008268Seric EXTERN char *HelpFile; /* location of SMTP help file */ 4018268Seric EXTERN char *StatFile; /* location of statistics summary */ 4028268Seric EXTERN char *QueueDir; /* location of queue directory */ 4039373Seric EXTERN char *FileName; /* name to print on error messages */ 4048929Seric EXTERN char *TrustedUsers[MAXTRUST+1]; /* list of trusted users */ 4058268Seric EXTERN jmp_buf TopFrame; /* branch-to-top-of-loop-on-error frame */ 4068268Seric EXTERN bool QuickAbort; /* .... but only if we want a quick abort */ 4077859Seric extern char *ConfFile; /* location of configuration file [conf.c] */ 4089065Seric extern char *FreezeFile; /* location of frozen memory image [conf.c] */ 4097859Seric extern char Arpa_Info[]; /* the reply code for Arpanet info [conf.c] */ 4109041Seric extern char SpaceSub; /* substitution for <lwsp> [conf.c] */ 4117674Seric /* 4127674Seric ** Trace information 4137674Seric */ 414295Seric 4157674Seric /* trace vector and macros for debugging flags */ 4167674Seric EXTERN u_char tTdvect[100]; 4177674Seric # define tTd(flag, level) (tTdvect[flag] >= level) 4187674Seric # define tTdlevel(flag) (tTdvect[flag]) 4197674Seric /* 4207674Seric ** Miscellaneous information. 4217674Seric */ 422295Seric 423295Seric # include <sysexits.h> 424295Seric 425295Seric # define setstat(s) { if (ExitStat == EX_OK) ExitStat = s; } 4264085Seric 4274085Seric 4284085Seric /* useful functions */ 4294085Seric 4304085Seric extern char *newstr(); 431*9883Seric extern ADDRESS *parseaddr(); 4324085Seric extern char *xalloc(); 4334085Seric extern bool sameaddr(); 4346889Seric extern FILE *dfopen(); 4357684Seric extern EVENT *setevent(); 4367684Seric extern char *sfgets(); 4377810Seric extern char *queuename(); 4387884Seric extern time_t curtime(); 439