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