1 /* 2 * Copyright (c) 1983 Eric P. Allman 3 * Copyright (c) 1988 Regents of the University of California. 4 * All rights reserved. 5 * 6 * %sccs.include.redist.c% 7 * 8 * @(#)sendmail.h 5.18 (Berkeley) 07/25/91 9 */ 10 11 /* 12 ** SENDMAIL.H -- Global definitions for sendmail. 13 */ 14 15 # ifdef _DEFINE 16 # define EXTERN 17 # ifndef lint 18 static char SmailSccsId[] = "@(#)sendmail.h 5.18 07/25/91"; 19 # endif lint 20 # else _DEFINE 21 # define EXTERN extern 22 # endif _DEFINE 23 24 # include <sys/types.h> 25 # include <stdio.h> 26 # include <ctype.h> 27 # include <setjmp.h> 28 # include "conf.h" 29 # include "useful.h" 30 31 # ifdef LOG 32 # include <sys/syslog.h> 33 # endif LOG 34 35 # ifdef DAEMON 36 # ifdef VMUNIX 37 # include <sys/socket.h> 38 # include <netinet/in.h> 39 # endif VMUNIX 40 # endif DAEMON 41 42 43 # define PSBUFSIZE (MAXNAME + MAXATOM) /* size of prescan buffer */ 44 45 46 /* 47 ** Data structure for bit maps. 48 ** 49 ** Each bit in this map can be referenced by an ascii character. 50 ** This is 128 possible bits, or 12 8-bit bytes. 51 */ 52 53 #define BITMAPBYTES 16 /* number of bytes in a bit map */ 54 #define BYTEBITS 8 /* number of bits in a byte */ 55 56 /* internal macros */ 57 #define _BITWORD(bit) (bit / (BYTEBITS * sizeof (int))) 58 #define _BITBIT(bit) (1 << (bit % (BYTEBITS * sizeof (int)))) 59 60 typedef int BITMAP[BITMAPBYTES / sizeof (int)]; 61 62 /* test bit number N */ 63 #define bitnset(bit, map) ((map)[_BITWORD(bit)] & _BITBIT(bit)) 64 65 /* set bit number N */ 66 #define setbitn(bit, map) (map)[_BITWORD(bit)] |= _BITBIT(bit) 67 68 /* clear bit number N */ 69 #define clrbitn(bit, map) (map)[_BITWORD(bit)] &= ~_BITBIT(bit) 70 71 /* clear an entire bit map */ 72 #define clrbitmap(map) bzero((char *) map, BITMAPBYTES) 73 /* 74 ** Address structure. 75 ** Addresses are stored internally in this structure. 76 */ 77 78 struct address 79 { 80 char *q_paddr; /* the printname for the address */ 81 char *q_user; /* user name */ 82 char *q_ruser; /* real user name, or NULL if q_user */ 83 char *q_host; /* host name */ 84 struct mailer *q_mailer; /* mailer to use */ 85 u_short q_flags; /* status flags, see below */ 86 short q_uid; /* user-id of receiver (if known) */ 87 short q_gid; /* group-id of receiver (if known) */ 88 char *q_home; /* home dir (local mailer only) */ 89 char *q_fullname; /* full name if known */ 90 struct address *q_next; /* chain */ 91 struct address *q_alias; /* address this results from */ 92 struct address *q_tchain; /* temporary use chain */ 93 time_t q_timeout; /* timeout for this address */ 94 }; 95 96 typedef struct address ADDRESS; 97 98 # define QDONTSEND 000001 /* don't send to this address */ 99 # define QBADADDR 000002 /* this address is verified bad */ 100 # define QGOODUID 000004 /* the q_uid q_gid fields are good */ 101 # define QPRIMARY 000010 /* set from argv */ 102 # define QQUEUEUP 000020 /* queue for later transmission */ 103 # define QSENT 000040 /* has been successfully delivered */ 104 /* 105 ** Mailer definition structure. 106 ** Every mailer known to the system is declared in this 107 ** structure. It defines the pathname of the mailer, some 108 ** flags associated with it, and the argument vector to 109 ** pass to it. The flags are defined in conf.c 110 ** 111 ** The argument vector is expanded before actual use. All 112 ** words except the first are passed through the macro 113 ** processor. 114 */ 115 116 struct mailer 117 { 118 char *m_name; /* symbolic name of this mailer */ 119 char *m_mailer; /* pathname of the mailer to use */ 120 BITMAP m_flags; /* status flags, see below */ 121 short m_mno; /* mailer number internally */ 122 char **m_argv; /* template argument vector */ 123 short m_s_rwset; /* rewriting set for sender addresses */ 124 short m_r_rwset; /* rewriting set for recipient addresses */ 125 char *m_eol; /* end of line string */ 126 long m_maxsize; /* size limit on message to this mailer */ 127 }; 128 129 typedef struct mailer MAILER; 130 131 /* bits for m_flags */ 132 # define M_CANONICAL 'C' /* make addresses canonical "u@dom" */ 133 # define M_EXPENSIVE 'e' /* it costs to use this mailer.... */ 134 # define M_ESCFROM 'E' /* escape From lines to >From */ 135 # define M_FOPT 'f' /* mailer takes picky -f flag */ 136 # define M_HST_UPPER 'h' /* preserve host case distinction */ 137 # define M_INTERNAL 'I' /* SMTP to another sendmail site */ 138 # define M_LOCAL 'l' /* delivery is to this host */ 139 # define M_LIMITS 'L' /* must enforce SMTP line limits */ 140 # define M_MUSER 'm' /* can handle multiple users at once */ 141 # define M_NHDR 'n' /* don't insert From line */ 142 # define M_FROMPATH 'p' /* use reverse-path in MAIL FROM: */ 143 # define M_ROPT 'r' /* mailer takes picky -r flag */ 144 # define M_SECURE_PORT 'R' /* try to send on a reserved TCP port */ 145 # define M_STRIPQ 's' /* strip quote chars from user/host */ 146 # define M_RESTR 'S' /* must be daemon to execute */ 147 # define M_USR_UPPER 'u' /* preserve user case distinction */ 148 # define M_UGLYUUCP 'U' /* this wants an ugly UUCP from line */ 149 # define M_XDOT 'X' /* use hidden-dot algorithm */ 150 151 EXTERN MAILER *Mailer[MAXMAILERS+1]; 152 153 EXTERN MAILER *LocalMailer; /* ptr to local mailer */ 154 EXTERN MAILER *ProgMailer; /* ptr to program mailer */ 155 /* 156 ** Header structure. 157 ** This structure is used internally to store header items. 158 */ 159 160 struct header 161 { 162 char *h_field; /* the name of the field */ 163 char *h_value; /* the value of that field */ 164 struct header *h_link; /* the next header */ 165 u_short h_flags; /* status bits, see below */ 166 BITMAP h_mflags; /* m_flags bits needed */ 167 }; 168 169 typedef struct header HDR; 170 171 /* 172 ** Header information structure. 173 ** Defined in conf.c, this struct declares the header fields 174 ** that have some magic meaning. 175 */ 176 177 struct hdrinfo 178 { 179 char *hi_field; /* the name of the field */ 180 u_short hi_flags; /* status bits, see below */ 181 }; 182 183 extern struct hdrinfo HdrInfo[]; 184 185 /* bits for h_flags and hi_flags */ 186 # define H_EOH 00001 /* this field terminates header */ 187 # define H_RCPT 00002 /* contains recipient addresses */ 188 # define H_DEFAULT 00004 /* if another value is found, drop this */ 189 # define H_RESENT 00010 /* this address is a "Resent-..." address */ 190 # define H_CHECK 00020 /* check h_mflags against m_flags */ 191 # define H_ACHECK 00040 /* ditto, but always (not just default) */ 192 # define H_FORCE 00100 /* force this field, even if default */ 193 # define H_TRACE 00200 /* this field contains trace information */ 194 # define H_FROM 00400 /* this is a from-type field */ 195 # define H_VALID 01000 /* this field has a validated value */ 196 /* 197 ** Envelope structure. 198 ** This structure defines the message itself. There is usually 199 ** only one of these -- for the message that we originally read 200 ** and which is our primary interest -- but other envelopes can 201 ** be generated during processing. For example, error messages 202 ** will have their own envelope. 203 */ 204 205 struct envelope 206 { 207 HDR *e_header; /* head of header list */ 208 long e_msgpriority; /* adjusted priority of this message */ 209 time_t e_ctime; /* time message appeared in the queue */ 210 char *e_to; /* the target person */ 211 char *e_receiptto; /* return receipt address */ 212 ADDRESS e_from; /* the person it is from */ 213 char **e_fromdomain; /* the domain part of the sender */ 214 ADDRESS *e_sendqueue; /* list of message recipients */ 215 ADDRESS *e_errorqueue; /* the queue for error responses */ 216 long e_msgsize; /* size of the message in bytes */ 217 int e_nrcpts; /* number of recipients */ 218 short e_class; /* msg class (priority, junk, etc.) */ 219 short e_flags; /* flags, see below */ 220 short e_hopcount; /* number of times processed */ 221 int (*e_puthdr)(); /* function to put header of message */ 222 int (*e_putbody)(); /* function to put body of message */ 223 struct envelope *e_parent; /* the message this one encloses */ 224 struct envelope *e_sibling; /* the next envelope of interest */ 225 char *e_df; /* location of temp file */ 226 FILE *e_dfp; /* temporary file */ 227 char *e_id; /* code for this entry in queue */ 228 FILE *e_xfp; /* transcript file */ 229 char *e_message; /* error message */ 230 char *e_macro[128]; /* macro definitions */ 231 }; 232 233 typedef struct envelope ENVELOPE; 234 235 /* values for e_flags */ 236 #define EF_OLDSTYLE 000001 /* use spaces (not commas) in hdrs */ 237 #define EF_INQUEUE 000002 /* this message is fully queued */ 238 #define EF_TIMEOUT 000004 /* this message is too old */ 239 #define EF_CLRQUEUE 000010 /* disk copy is no longer needed */ 240 #define EF_SENDRECEIPT 000020 /* send a return receipt */ 241 #define EF_FATALERRS 000040 /* fatal errors occured */ 242 #define EF_KEEPQUEUE 000100 /* keep queue files always */ 243 #define EF_RESPONSE 000200 /* this is an error or return receipt */ 244 #define EF_RESENT 000400 /* this message is being forwarded */ 245 246 EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */ 247 /* 248 ** Message priority classes. 249 ** 250 ** The message class is read directly from the Priority: header 251 ** field in the message. 252 ** 253 ** CurEnv->e_msgpriority is the number of bytes in the message plus 254 ** the creation time (so that jobs ``tend'' to be ordered correctly), 255 ** adjusted by the message class, the number of recipients, and the 256 ** amount of time the message has been sitting around. This number 257 ** is used to order the queue. Higher values mean LOWER priority. 258 ** 259 ** Each priority class point is worth WkClassFact priority points; 260 ** each recipient is worth WkRecipFact priority points. Each time 261 ** we reprocess a message the priority is adjusted by WkTimeFact. 262 ** WkTimeFact should normally decrease the priority so that jobs 263 ** that have historically failed will be run later; thanks go to 264 ** Jay Lepreau at Utah for pointing out the error in my thinking. 265 ** 266 ** The "class" is this number, unadjusted by the age or size of 267 ** this message. Classes with negative representations will have 268 ** error messages thrown away if they are not local. 269 */ 270 271 struct priority 272 { 273 char *pri_name; /* external name of priority */ 274 int pri_val; /* internal value for same */ 275 }; 276 277 EXTERN struct priority Priorities[MAXPRIORITIES]; 278 EXTERN int NumPriorities; /* pointer into Priorities */ 279 /* 280 ** Rewrite rules. 281 */ 282 283 struct rewrite 284 { 285 char **r_lhs; /* pattern match */ 286 char **r_rhs; /* substitution value */ 287 struct rewrite *r_next;/* next in chain */ 288 }; 289 290 EXTERN struct rewrite *RewriteRules[MAXRWSETS]; 291 292 /* 293 ** Special characters in rewriting rules. 294 ** These are used internally only. 295 ** The COND* rules are actually used in macros rather than in 296 ** rewriting rules, but are given here because they 297 ** cannot conflict. 298 */ 299 300 /* left hand side items */ 301 # define MATCHZANY '\020' /* match zero or more tokens */ 302 # define MATCHANY '\021' /* match one or more tokens */ 303 # define MATCHONE '\022' /* match exactly one token */ 304 # define MATCHCLASS '\023' /* match one token in a class */ 305 # define MATCHNCLASS '\024' /* match anything not in class */ 306 # define MATCHREPL '\025' /* replacement on RHS for above */ 307 308 /* right hand side items */ 309 # define CANONNET '\026' /* canonical net, next token */ 310 # define CANONHOST '\027' /* canonical host, next token */ 311 # define CANONUSER '\030' /* canonical user, next N tokens */ 312 # define CALLSUBR '\031' /* call another rewriting set */ 313 314 /* conditionals in macros */ 315 # define CONDIF '\032' /* conditional if-then */ 316 # define CONDELSE '\033' /* conditional else */ 317 # define CONDFI '\034' /* conditional fi */ 318 319 /* bracket characters for host name lookup */ 320 # define HOSTBEGIN '\035' /* hostname lookup begin */ 321 # define HOSTEND '\036' /* hostname lookup end */ 322 323 /* \001 is also reserved as the macro expansion character */ 324 /* 325 ** Information about hosts that we have looked up recently. 326 ** 327 ** This stuff is 4.2/3bsd specific. 328 */ 329 330 # ifdef DAEMON 331 # ifdef VMUNIX 332 333 # define HOSTINFO struct hostinfo 334 335 HOSTINFO 336 { 337 char *ho_name; /* name of this host */ 338 struct in_addr ho_inaddr; /* internet address */ 339 short ho_flags; /* flag bits, see below */ 340 short ho_errno; /* error number on last connection */ 341 short ho_exitstat; /* exit status from last connection */ 342 }; 343 344 345 /* flag bits */ 346 #define HOF_VALID 00001 /* this entry is valid */ 347 348 # endif VMUNIX 349 # endif DAEMON 350 /* 351 ** Symbol table definitions 352 */ 353 354 struct symtab 355 { 356 char *s_name; /* name to be entered */ 357 char s_type; /* general type (see below) */ 358 struct symtab *s_next; /* pointer to next in chain */ 359 union 360 { 361 BITMAP sv_class; /* bit-map of word classes */ 362 ADDRESS *sv_addr; /* pointer to address header */ 363 MAILER *sv_mailer; /* pointer to mailer */ 364 char *sv_alias; /* alias */ 365 # ifdef HOSTINFO 366 HOSTINFO sv_host; /* host information */ 367 # endif HOSTINFO 368 } s_value; 369 }; 370 371 typedef struct symtab STAB; 372 373 /* symbol types */ 374 # define ST_UNDEF 0 /* undefined type */ 375 # define ST_CLASS 1 /* class map */ 376 # define ST_ADDRESS 2 /* an address in parsed format */ 377 # define ST_MAILER 3 /* a mailer header */ 378 # define ST_ALIAS 4 /* an alias */ 379 # define ST_HOST 5 /* host information */ 380 381 # define s_class s_value.sv_class 382 # define s_address s_value.sv_addr 383 # define s_mailer s_value.sv_mailer 384 # define s_alias s_value.sv_alias 385 # undef s_host 386 # define s_host s_value.sv_host 387 388 extern STAB *stab(); 389 390 /* opcodes to stab */ 391 # define ST_FIND 0 /* find entry */ 392 # define ST_ENTER 1 /* enter if not there */ 393 /* 394 ** STRUCT EVENT -- event queue. 395 ** 396 ** Maintained in sorted order. 397 ** 398 ** We store the pid of the process that set this event to insure 399 ** that when we fork we will not take events intended for the parent. 400 */ 401 402 struct event 403 { 404 time_t ev_time; /* time of the function call */ 405 int (*ev_func)(); /* function to call */ 406 int ev_arg; /* argument to ev_func */ 407 int ev_pid; /* pid that set this event */ 408 struct event *ev_link; /* link to next item */ 409 }; 410 411 typedef struct event EVENT; 412 413 EXTERN EVENT *EventQueue; /* head of event queue */ 414 /* 415 ** Operation, send, and error modes 416 ** 417 ** The operation mode describes the basic operation of sendmail. 418 ** This can be set from the command line, and is "send mail" by 419 ** default. 420 ** 421 ** The send mode tells how to send mail. It can be set in the 422 ** configuration file. It's setting determines how quickly the 423 ** mail will be delivered versus the load on your system. If the 424 ** -v (verbose) flag is given, it will be forced to SM_DELIVER 425 ** mode. 426 ** 427 ** The error mode tells how to return errors. 428 */ 429 430 EXTERN char OpMode; /* operation mode, see below */ 431 432 #define MD_DELIVER 'm' /* be a mail sender */ 433 #define MD_ARPAFTP 'a' /* old-style arpanet protocols */ 434 #define MD_SMTP 's' /* run SMTP on standard input */ 435 #define MD_DAEMON 'd' /* run as a daemon */ 436 #define MD_VERIFY 'v' /* verify: don't collect or deliver */ 437 #define MD_TEST 't' /* test mode: resolve addrs only */ 438 #define MD_INITALIAS 'i' /* initialize alias database */ 439 #define MD_PRINT 'p' /* print the queue */ 440 #define MD_FREEZE 'z' /* freeze the configuration file */ 441 442 443 EXTERN char SendMode; /* send mode, see below */ 444 445 #define SM_DELIVER 'i' /* interactive delivery */ 446 #define SM_QUICKD 'j' /* deliver w/o queueing */ 447 #define SM_FORK 'b' /* deliver in background */ 448 #define SM_QUEUE 'q' /* queue, don't deliver */ 449 #define SM_VERIFY 'v' /* verify only (used internally) */ 450 451 /* used only as a parameter to sendall */ 452 #define SM_DEFAULT '\0' /* unspecified, use SendMode */ 453 454 455 EXTERN char ErrorMode; /* error mode, see below */ 456 457 #define EM_PRINT 'p' /* print errors */ 458 #define EM_MAIL 'm' /* mail back errors */ 459 #define EM_WRITE 'w' /* write back errors */ 460 #define EM_BERKNET 'e' /* special berknet processing */ 461 #define EM_QUIET 'q' /* don't print messages (stat only) */ 462 463 /* offset used to issure that the error messages for name server error 464 * codes are unique. 465 */ 466 #define MAX_ERRNO 100 467 /* 468 ** Global variables. 469 */ 470 471 EXTERN bool FromFlag; /* if set, "From" person is explicit */ 472 EXTERN bool NoAlias; /* if set, don't do any aliasing */ 473 EXTERN bool ForceMail; /* if set, mail even if already got a copy */ 474 EXTERN bool MeToo; /* send to the sender also */ 475 EXTERN bool IgnrDot; /* don't let dot end messages */ 476 EXTERN bool SaveFrom; /* save leading "From" lines */ 477 EXTERN bool Verbose; /* set if blow-by-blow desired */ 478 EXTERN bool GrabTo; /* if set, get recipients from msg */ 479 EXTERN bool NoReturn; /* don't return letter to sender */ 480 EXTERN bool SuprErrs; /* set if we are suppressing errors */ 481 EXTERN bool QueueRun; /* currently running message from the queue */ 482 EXTERN bool HoldErrs; /* only output errors to transcript */ 483 EXTERN bool NoConnect; /* don't connect to non-local mailers */ 484 EXTERN bool SuperSafe; /* be extra careful, even if expensive */ 485 EXTERN bool ForkQueueRuns; /* fork for each job when running the queue */ 486 EXTERN bool AutoRebuild; /* auto-rebuild the alias database as needed */ 487 EXTERN bool CheckAliases; /* parse addresses during newaliases */ 488 EXTERN bool UseNameServer; /* use internet domain name server */ 489 EXTERN int SafeAlias; /* minutes to wait until @:@ in alias file */ 490 EXTERN time_t TimeOut; /* time until timeout */ 491 EXTERN FILE *InChannel; /* input connection */ 492 EXTERN FILE *OutChannel; /* output connection */ 493 EXTERN int RealUid; /* when Daemon, real uid of caller */ 494 EXTERN int RealGid; /* when Daemon, real gid of caller */ 495 EXTERN int DefUid; /* default uid to run as */ 496 EXTERN char *DefUser; /* default user to run as (from DefUid) */ 497 EXTERN int DefGid; /* default gid to run as */ 498 EXTERN int OldUmask; /* umask when sendmail starts up */ 499 EXTERN int Errors; /* set if errors (local to single pass) */ 500 EXTERN int ExitStat; /* exit status code */ 501 EXTERN int AliasLevel; /* depth of aliasing */ 502 EXTERN int MotherPid; /* proc id of parent process */ 503 EXTERN int LineNumber; /* line number in current input */ 504 EXTERN time_t ReadTimeout; /* timeout on reads */ 505 EXTERN int LogLevel; /* level of logging to perform */ 506 EXTERN int FileMode; /* mode on files */ 507 EXTERN int QueueLA; /* load average starting forced queueing */ 508 EXTERN int RefuseLA; /* load average refusing connections are */ 509 EXTERN int QueueFactor; /* slope of queue function */ 510 EXTERN time_t QueueIntvl; /* intervals between running the queue */ 511 EXTERN char *AliasFile; /* location of alias file */ 512 EXTERN char *HelpFile; /* location of SMTP help file */ 513 EXTERN char *StatFile; /* location of statistics summary */ 514 EXTERN char *QueueDir; /* location of queue directory */ 515 EXTERN char *FileName; /* name to print on error messages */ 516 EXTERN char *SmtpPhase; /* current phase in SMTP processing */ 517 EXTERN char *MyHostName; /* name of this host for SMTP messages */ 518 EXTERN char *RealHostName; /* name of host we are talking to */ 519 EXTERN struct sockaddr_in RealHostAddr;/* address of host we are talking to */ 520 EXTERN char *CurHostName; /* current host we are dealing with */ 521 EXTERN jmp_buf TopFrame; /* branch-to-top-of-loop-on-error frame */ 522 EXTERN bool QuickAbort; /* .... but only if we want a quick abort */ 523 extern char *ConfFile; /* location of configuration file [conf.c] */ 524 extern char *FreezeFile; /* location of frozen memory image [conf.c] */ 525 extern char Arpa_Info[]; /* the reply code for Arpanet info [conf.c] */ 526 extern ADDRESS NullAddress; /* a null (template) address [main.c] */ 527 EXTERN char SpaceSub; /* substitution for <lwsp> */ 528 EXTERN int WkClassFact; /* multiplier for message class -> priority */ 529 EXTERN int WkRecipFact; /* multiplier for # of recipients -> priority */ 530 EXTERN int WkTimeFact; /* priority offset each time this job is run */ 531 EXTERN int CheckPointLimit; /* deliveries before checkpointing */ 532 EXTERN int Nmx; /* number of MX RRs */ 533 EXTERN char *PostMasterCopy; /* address to get errs cc's */ 534 EXTERN char *MxHosts[MAXMXHOSTS+1]; /* for MX RRs */ 535 EXTERN char *TrustedUsers[MAXTRUST+1]; /* list of trusted users */ 536 EXTERN char *UserEnviron[MAXUSERENVIRON+1]; /* saved user environment */ 537 EXTERN int CheckpointInterval; /* queue file checkpoint interval */ 538 EXTERN bool WildcardMX; /* we have wildcard MX records */ 539 /* 540 ** Trace information 541 */ 542 543 /* trace vector and macros for debugging flags */ 544 EXTERN u_char tTdvect[100]; 545 # define tTd(flag, level) (tTdvect[flag] >= level) 546 # define tTdlevel(flag) (tTdvect[flag]) 547 /* 548 ** Miscellaneous information. 549 */ 550 551 # include <sysexits.h> 552 553 554 /* 555 ** Some in-line functions 556 */ 557 558 /* set exit status */ 559 #define setstat(s) { \ 560 if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \ 561 ExitStat = s; \ 562 } 563 564 /* make a copy of a string */ 565 #define newstr(s) strcpy(xalloc(strlen(s) + 1), s) 566 567 #define STRUCTCOPY(s, d) d = s 568 569 570 /* 571 ** Declarations of useful functions 572 */ 573 574 extern ADDRESS *parseaddr(); 575 extern char *xalloc(); 576 extern bool sameaddr(); 577 extern FILE *dfopen(); 578 extern EVENT *setevent(); 579 extern char *sfgets(); 580 extern char *queuename(); 581 extern time_t curtime(); 582