1 /* 2 ** SENDMAIL.H -- Global definitions for sendmail. 3 */ 4 5 6 7 # ifdef _DEFINE 8 # define EXTERN 9 # ifndef lint 10 static char SmailSccsId[] = "@(#)sendmail.h 3.110 01/09/83"; 11 # endif lint 12 # else _DEFINE 13 # define EXTERN extern 14 # endif _DEFINE 15 16 # include <stdio.h> 17 # include <ctype.h> 18 # include <setjmp.h> 19 # include "conf.h" 20 # include "useful.h" 21 22 # ifdef LOG 23 # include <syslog.h> 24 # endif LOG 25 /* 26 ** Address structure. 27 ** Addresses are stored internally in this structure. 28 */ 29 30 struct address 31 { 32 char *q_paddr; /* the printname for the address */ 33 char *q_user; /* user name */ 34 char *q_host; /* host name */ 35 struct mailer *q_mailer; /* mailer to use */ 36 u_short q_flags; /* status flags, see below */ 37 short q_uid; /* user-id of receiver (if known) */ 38 short q_gid; /* group-id of receiver (if known) */ 39 char *q_home; /* home dir (local mailer only) */ 40 char *q_fullname; /* full name if known */ 41 struct address *q_next; /* chain */ 42 struct address *q_alias; /* address this results from */ 43 struct address *q_tchain; /* temporary use chain */ 44 time_t q_timeout; /* timeout for this address */ 45 }; 46 47 typedef struct address ADDRESS; 48 49 # define QDONTSEND 000001 /* don't send to this address */ 50 # define QBADADDR 000002 /* this address is verified bad */ 51 # define QGOODUID 000004 /* the q_uid q_gid fields are good */ 52 # define QPRIMARY 000010 /* set from argv */ 53 # define QQUEUEUP 000020 /* queue for later transmission */ 54 /* 55 ** Mailer definition structure. 56 ** Every mailer known to the system is declared in this 57 ** structure. It defines the pathname of the mailer, some 58 ** flags associated with it, and the argument vector to 59 ** pass to it. The flags are defined in conf.c 60 ** 61 ** The argument vector is expanded before actual use. All 62 ** words except the first are passed through the macro 63 ** processor. 64 */ 65 66 struct mailer 67 { 68 char *m_name; /* symbolic name of this mailer */ 69 char *m_mailer; /* pathname of the mailer to use */ 70 u_long m_flags; /* status flags, see below */ 71 short m_mno; /* mailer number internally */ 72 char **m_argv; /* template argument vector */ 73 short m_s_rwset; /* rewriting set for sender addresses */ 74 short m_r_rwset; /* rewriting set for recipient addresses */ 75 }; 76 77 typedef struct mailer MAILER; 78 79 /* bits for m_flags */ 80 # define M_FOPT 000000001L /* mailer takes picky -f flag */ 81 # define M_ROPT 000000002L /* mailer takes picky -r flag */ 82 # define M_RPATH 000000004L /* wants a Return-Path: line */ 83 # define M_RESTR 000000010L /* must be daemon to execute */ 84 # define M_NHDR 000000020L /* don't insert From line */ 85 # define M_LOCAL 000000040L /* delivery is to this host */ 86 # define M_STRIPQ 000000100L /* strip quote chars from user/host */ 87 # define M_MUSER 000000200L /* can handle multiple users at once */ 88 # define M_NEEDFROM 000000400L /* need arpa-style From: line */ 89 # define M_NEEDDATE 000001000L /* need arpa-style Date: line */ 90 # define M_MSGID 000002000L /* need Message-Id: field */ 91 # define M_CANONICAL 000004000L /* make addresses canonical "u@dom" */ 92 # define M_USR_UPPER 000010000L /* preserve user case distinction */ 93 # define M_HST_UPPER 000020000L /* preserve host case distinction */ 94 # define M_FULLNAME 000040000L /* want Full-Name field */ 95 # define M_UGLYUUCP 000100000L /* this wants an ugly UUCP from line */ 96 # define M_EXPENSIVE 000200000L /* it costs to use this mailer.... */ 97 # define M_LIMITS 000400000L /* must enforce SMTP line limits */ 98 # define M_INTERNAL 001000000L /* SMTP to another sendmail site */ 99 # define M_CRLF 002000000L /* use CRLF instead of NL as EOLine */ 100 # define M_FROMPATH 004000000L /* use reverse-path in MAIL FROM: */ 101 # define M_XDOT 010000000L /* use hidden-dot algorithm */ 102 103 # define M_ARPAFMT (M_NEEDDATE|M_NEEDFROM|M_MSGID) 104 105 EXTERN MAILER *Mailer[MAXMAILERS+1]; 106 107 EXTERN MAILER *LocalMailer; /* ptr to local mailer */ 108 EXTERN MAILER *ProgMailer; /* ptr to program mailer */ 109 /* 110 ** Header structure. 111 ** This structure is used internally to store header items. 112 */ 113 114 struct header 115 { 116 char *h_field; /* the name of the field */ 117 char *h_value; /* the value of that field */ 118 struct header *h_link; /* the next header */ 119 u_short h_flags; /* status bits, see below */ 120 u_long h_mflags; /* m_flags bits needed */ 121 }; 122 123 typedef struct header HDR; 124 125 /* 126 ** Header information structure. 127 ** Defined in conf.c, this struct declares the header fields 128 ** that have some magic meaning. 129 */ 130 131 struct hdrinfo 132 { 133 char *hi_field; /* the name of the field */ 134 u_short hi_flags; /* status bits, see below */ 135 }; 136 137 extern struct hdrinfo HdrInfo[]; 138 139 /* bits for h_flags and hi_flags */ 140 # define H_EOH 00001 /* this field terminates header */ 141 # define H_RCPT 00002 /* contains recipient addresses */ 142 # define H_DEFAULT 00004 /* if another value is found, drop this */ 143 # define H_CHECK 00020 /* check h_mflags against m_flags */ 144 # define H_ACHECK 00040 /* ditto, but always (not just default) */ 145 # define H_FORCE 00100 /* force this field, even if default */ 146 # define H_TRACE 00200 /* this field contains trace information */ 147 # define H_FROM 00400 /* this is a from-type field */ 148 /* 149 ** Envelope structure. 150 ** This structure defines the message itself. There is usually 151 ** only one of these -- for the message that we originally read 152 ** and which is our primary interest -- but other envelopes can 153 ** be generated during processing. For example, error messages 154 ** will have their own envelope. 155 */ 156 157 struct envelope 158 { 159 HDR *e_header; /* head of header list */ 160 long e_msgpriority; /* adjusted priority of this message */ 161 time_t e_ctime; /* time message appeared in the queue */ 162 char *e_to; /* the target person */ 163 char *e_receiptto; /* return receipt address */ 164 ADDRESS e_from; /* the person it is from */ 165 char **e_fromdomain; /* the domain part of the sender */ 166 ADDRESS *e_sendqueue; /* list of message recipients */ 167 ADDRESS *e_errorqueue; /* the queue for error responses */ 168 long e_msgsize; /* size of the message in bytes */ 169 short e_class; /* msg class (priority, junk, etc.) */ 170 short e_flags; /* flags, see below */ 171 short e_hopcount; /* number of times processed */ 172 int (*e_puthdr)(); /* function to put header of message */ 173 int (*e_putbody)(); /* function to put body of message */ 174 struct envelope *e_parent; /* the message this one encloses */ 175 struct envelope *e_sibling; /* the next envelope of interest */ 176 char *e_df; /* location of temp file */ 177 FILE *e_dfp; /* temporary file */ 178 char *e_id; /* code for this entry in queue */ 179 FILE *e_xfp; /* transcript file */ 180 char *e_message; /* error message */ 181 char *e_macro[128]; /* macro definitions */ 182 }; 183 184 typedef struct envelope ENVELOPE; 185 186 /* values for e_flags */ 187 #define EF_OLDSTYLE 000001 /* use spaces (not commas) in hdrs */ 188 #define EF_INQUEUE 000002 /* this message is fully queued */ 189 #define EF_TIMEOUT 000004 /* this message is too old */ 190 #define EF_CLRQUEUE 000010 /* disk copy is no longer needed */ 191 #define EF_SENDRECEIPT 000020 /* send a return receipt */ 192 #define EF_FATALERRS 000040 /* fatal errors occured */ 193 #define EF_KEEPQUEUE 000100 /* keep queue files always */ 194 #define EF_RESPONSE 000200 /* this is an error or return receipt */ 195 196 EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */ 197 /* 198 ** Message priorities. 199 ** Priorities > 0 should be preemptive. 200 ** 201 ** CurEnv->e_msgpriority is the number of bytes in the message adjusted 202 ** by the message priority and the amount of time the message 203 ** has been sitting around. Each priority point is worth 204 ** WKPRIFACT bytes of message, and each time we reprocess a 205 ** message the size gets reduced by WKTIMEFACT. 206 ** 207 ** The "class" is this number, unadjusted by the age or size of 208 ** this message. Classes with negative representations will have 209 ** error messages thrown away if they are not local. 210 */ 211 212 struct priority 213 { 214 char *pri_name; /* external name of priority */ 215 int pri_val; /* internal value for same */ 216 }; 217 218 EXTERN struct priority Priorities[MAXPRIORITIES]; 219 EXTERN int NumPriorities; /* pointer into Priorities */ 220 221 # define WKPRIFACT 1800 /* bytes each pri point is worth */ 222 # define WKTIMEFACT 400 /* bytes each time unit is worth */ 223 /* 224 ** Rewrite rules. 225 */ 226 227 struct rewrite 228 { 229 char **r_lhs; /* pattern match */ 230 char **r_rhs; /* substitution value */ 231 struct rewrite *r_next;/* next in chain */ 232 }; 233 234 EXTERN struct rewrite *RewriteRules[MAXRWSETS]; 235 236 /* 237 ** Special characters in rewriting rules. 238 ** These are used internally only. 239 ** The COND* rules are actually used in macros rather than in 240 ** rewriting rules, but are given here because they 241 ** cannot conflict. 242 */ 243 244 /* left hand side items */ 245 # define MATCHZANY '\020' /* match zero or more tokens */ 246 # define MATCHANY '\021' /* match one or more tokens */ 247 # define MATCHONE '\022' /* match exactly one token */ 248 # define MATCHCLASS '\023' /* match one token in a class */ 249 # define MATCHNCLASS '\034' /* match anything not in class */ 250 # define MATCHREPL '\024' /* replacement on RHS for above */ 251 252 /* right hand side items */ 253 # define CANONNET '\025' /* canonical net, next token */ 254 # define CANONHOST '\026' /* canonical host, next token */ 255 # define CANONUSER '\027' /* canonical user, next N tokens */ 256 # define CALLSUBR '\030' /* call another rewriting set */ 257 258 /* conditionals in macros */ 259 # define CONDIF '\031' /* conditional if-then */ 260 # define CONDELSE '\032' /* conditional else */ 261 # define CONDFI '\033' /* conditional fi */ 262 /* 263 ** Symbol table definitions 264 */ 265 266 struct symtab 267 { 268 char *s_name; /* name to be entered */ 269 char s_type; /* general type (see below) */ 270 struct symtab *s_next; /* pointer to next in chain */ 271 union 272 { 273 long sv_class; /* bit-map of word classes */ 274 ADDRESS *sv_addr; /* pointer to address header */ 275 MAILER *sv_mailer; /* pointer to mailer */ 276 char *sv_alias; /* alias */ 277 } s_value; 278 }; 279 280 typedef struct symtab STAB; 281 282 /* symbol types */ 283 # define ST_UNDEF 0 /* undefined type */ 284 # define ST_CLASS 1 /* class map */ 285 # define ST_ADDRESS 2 /* an address in parsed format */ 286 # define ST_MAILER 3 /* a mailer header */ 287 # define ST_ALIAS 4 /* an alias */ 288 289 # define s_class s_value.sv_class 290 # define s_address s_value.sv_addr 291 # define s_mailer s_value.sv_mailer 292 # define s_alias s_value.sv_alias 293 294 extern STAB *stab(); 295 296 /* opcodes to stab */ 297 # define ST_FIND 0 /* find entry */ 298 # define ST_ENTER 1 /* enter if not there */ 299 /* 300 ** STRUCT EVENT -- event queue. 301 ** 302 ** Maintained in sorted order. 303 ** 304 ** We store the pid of the process that set this event to insure 305 ** that when we fork we will not take events intended for the parent. 306 */ 307 308 struct event 309 { 310 time_t ev_time; /* time of the function call */ 311 int (*ev_func)(); /* function to call */ 312 int ev_arg; /* argument to ev_func */ 313 int ev_pid; /* pid that set this event */ 314 struct event *ev_link; /* link to next item */ 315 }; 316 317 typedef struct event EVENT; 318 319 EXTERN EVENT *EventQueue; /* head of event queue */ 320 /* 321 ** Operation, send, and error modes 322 ** 323 ** The operation mode describes the basic operation of sendmail. 324 ** This can be set from the command line, and is "send mail" by 325 ** default. 326 ** 327 ** The send mode tells how to send mail. It can be set in the 328 ** configuration file. It's setting determines how quickly the 329 ** mail will be delivered versus the load on your system. If the 330 ** -v (verbose) flag is given, it will be forced to SM_DELIVER 331 ** mode. 332 ** 333 ** The error mode tells how to return errors. 334 */ 335 336 EXTERN char OpMode; /* operation mode, see below */ 337 338 #define MD_DELIVER 'm' /* be a mail sender */ 339 #define MD_ARPAFTP 'a' /* old-style arpanet protocols */ 340 #define MD_SMTP 's' /* run SMTP on standard input */ 341 #define MD_DAEMON 'd' /* run as a daemon */ 342 #define MD_VERIFY 'v' /* verify: don't collect or deliver */ 343 #define MD_TEST 't' /* test mode: resolve addrs only */ 344 #define MD_INITALIAS 'i' /* initialize alias database */ 345 #define MD_PRINT 'p' /* print the queue */ 346 #define MD_FREEZE 'z' /* freeze the configuration file */ 347 348 349 EXTERN char SendMode; /* send mode, see below */ 350 351 #define SM_DELIVER 'i' /* interactive delivery */ 352 #define SM_QUICKD 'j' /* deliver w/o queueing */ 353 #define SM_FORK 'b' /* deliver in background */ 354 #define SM_QUEUE 'q' /* queue, don't deliver */ 355 #define SM_VERIFY 'v' /* verify only (used internally) */ 356 357 358 EXTERN char ErrorMode; /* error mode, see below */ 359 360 #define EM_PRINT 'p' /* print errors */ 361 #define EM_MAIL 'm' /* mail back errors */ 362 #define EM_WRITE 'w' /* write back errors */ 363 #define EM_BERKNET 'e' /* special berknet processing */ 364 #define EM_QUIET 'q' /* don't print messages (stat only) */ 365 /* 366 ** Global variables. 367 */ 368 369 EXTERN bool FromFlag; /* if set, "From" person is explicit */ 370 EXTERN bool NoAlias; /* if set, don't do any aliasing */ 371 EXTERN bool ForceMail; /* if set, mail even if already got a copy */ 372 EXTERN bool MeToo; /* send to the sender also */ 373 EXTERN bool IgnrDot; /* don't let dot end messages */ 374 EXTERN bool SaveFrom; /* save leading "From" lines */ 375 EXTERN bool Verbose; /* set if blow-by-blow desired */ 376 EXTERN bool GrabTo; /* if set, get recipients from msg */ 377 EXTERN bool NoReturn; /* don't return letter to sender */ 378 EXTERN bool SuprErrs; /* set if we are suppressing errors */ 379 EXTERN bool QueueRun; /* currently running message from the queue */ 380 EXTERN bool HoldErrs; /* only output errors to transcript */ 381 EXTERN bool NoConnect; /* don't connect to non-local mailers */ 382 EXTERN bool SuperSafe; /* be extra careful, even if expensive */ 383 EXTERN bool SafeAlias; /* alias file must have "@:@" to be complete */ 384 EXTERN bool AutoRebuild; /* auto-rebuild the alias database as needed */ 385 EXTERN time_t TimeOut; /* time until timeout */ 386 EXTERN FILE *InChannel; /* input connection */ 387 EXTERN FILE *OutChannel; /* output connection */ 388 EXTERN int RealUid; /* when Daemon, real uid of caller */ 389 EXTERN int RealGid; /* when Daemon, real gid of caller */ 390 EXTERN int DefUid; /* default uid to run as */ 391 EXTERN int DefGid; /* default gid to run as */ 392 EXTERN int OldUmask; /* umask when sendmail starts up */ 393 EXTERN int Errors; /* set if errors (local to single pass) */ 394 EXTERN int ExitStat; /* exit status code */ 395 EXTERN int AliasLevel; /* depth of aliasing */ 396 EXTERN int MotherPid; /* proc id of parent process */ 397 EXTERN int LineNumber; /* line number in current input */ 398 EXTERN int ReadTimeout; /* timeout on reads */ 399 EXTERN int LogLevel; /* level of logging to perform */ 400 EXTERN int FileMode; /* mode on files */ 401 EXTERN time_t QueueIntvl; /* intervals between running the queue */ 402 EXTERN char *HostName; /* name of this host for SMTP messages */ 403 EXTERN char *AliasFile; /* location of alias file */ 404 EXTERN char *HelpFile; /* location of SMTP help file */ 405 EXTERN char *StatFile; /* location of statistics summary */ 406 EXTERN char *QueueDir; /* location of queue directory */ 407 EXTERN char *FileName; /* name to print on error messages */ 408 EXTERN char *TrustedUsers[MAXTRUST+1]; /* list of trusted users */ 409 EXTERN jmp_buf TopFrame; /* branch-to-top-of-loop-on-error frame */ 410 EXTERN bool QuickAbort; /* .... but only if we want a quick abort */ 411 extern char *ConfFile; /* location of configuration file [conf.c] */ 412 extern char *FreezeFile; /* location of frozen memory image [conf.c] */ 413 extern char Arpa_Info[]; /* the reply code for Arpanet info [conf.c] */ 414 extern char SpaceSub; /* substitution for <lwsp> [conf.c] */ 415 /* 416 ** Trace information 417 */ 418 419 /* trace vector and macros for debugging flags */ 420 EXTERN u_char tTdvect[100]; 421 # define tTd(flag, level) (tTdvect[flag] >= level) 422 # define tTdlevel(flag) (tTdvect[flag]) 423 /* 424 ** Miscellaneous information. 425 */ 426 427 # include <sysexits.h> 428 429 430 /* 431 ** Some in-line functions 432 */ 433 434 /* set exit status */ 435 # define setstat(s) { if (ExitStat == EX_OK) ExitStat = s; } 436 437 /* line terminator appropriate for a given mailer */ 438 # define crlf(m) (bitset(M_CRLF, (m)->m_flags) ? "\r\n" : "\n") 439 440 /* make a copy of a string */ 441 # define newstr(s) strcpy(xalloc(strlen(s) + 1), s) 442 443 444 /* 445 ** Declarations of useful functions 446 */ 447 448 extern ADDRESS *parseaddr(); 449 extern char *xalloc(); 450 extern bool sameaddr(); 451 extern FILE *dfopen(); 452 extern EVENT *setevent(); 453 extern char *sfgets(); 454 extern char *queuename(); 455 extern time_t curtime(); 456