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 6.46 (Berkeley) 04/14/93 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 6.46 04/14/93"; 19 # endif 20 # else /* _DEFINE */ 21 # define EXTERN extern 22 # endif /* _DEFINE */ 23 24 # include <unistd.h> 25 # include <stddef.h> 26 # include <stdlib.h> 27 # include <stdio.h> 28 # include <ctype.h> 29 # include <setjmp.h> 30 # include <sysexits.h> 31 # include <string.h> 32 # include <time.h> 33 # include <errno.h> 34 # include <sys/types.h> 35 36 # include "conf.h" 37 # include "useful.h" 38 39 # ifdef LOG 40 # include <syslog.h> 41 # endif /* LOG */ 42 43 # ifdef DAEMON 44 # include <sys/socket.h> 45 # endif 46 # ifdef NETINET 47 # include <netinet/in.h> 48 # endif 49 # ifdef NETISO 50 # include <netiso/iso.h> 51 # endif 52 # ifdef NETNS 53 # include <netns/ns.h> 54 # endif 55 # ifdef NETX25 56 # include <netccitt/x25.h> 57 # endif 58 59 60 61 62 /* 63 ** Data structure for bit maps. 64 ** 65 ** Each bit in this map can be referenced by an ascii character. 66 ** This is 128 possible bits, or 12 8-bit bytes. 67 */ 68 69 #define BITMAPBYTES 16 /* number of bytes in a bit map */ 70 #define BYTEBITS 8 /* number of bits in a byte */ 71 72 /* internal macros */ 73 #define _BITWORD(bit) (bit / (BYTEBITS * sizeof (int))) 74 #define _BITBIT(bit) (1 << (bit % (BYTEBITS * sizeof (int)))) 75 76 typedef int BITMAP[BITMAPBYTES / sizeof (int)]; 77 78 /* test bit number N */ 79 #define bitnset(bit, map) ((map)[_BITWORD(bit)] & _BITBIT(bit)) 80 81 /* set bit number N */ 82 #define setbitn(bit, map) (map)[_BITWORD(bit)] |= _BITBIT(bit) 83 84 /* clear bit number N */ 85 #define clrbitn(bit, map) (map)[_BITWORD(bit)] &= ~_BITBIT(bit) 86 87 /* clear an entire bit map */ 88 #define clrbitmap(map) bzero((char *) map, BITMAPBYTES) 89 /* 90 ** Address structure. 91 ** Addresses are stored internally in this structure. 92 */ 93 94 struct address 95 { 96 char *q_paddr; /* the printname for the address */ 97 char *q_user; /* user name */ 98 char *q_ruser; /* real user name, or NULL if q_user */ 99 char *q_host; /* host name */ 100 struct mailer *q_mailer; /* mailer to use */ 101 u_short q_flags; /* status flags, see below */ 102 uid_t q_uid; /* user-id of receiver (if known) */ 103 gid_t q_gid; /* group-id of receiver (if known) */ 104 char *q_home; /* home dir (local mailer only) */ 105 char *q_fullname; /* full name if known */ 106 struct address *q_next; /* chain */ 107 struct address *q_alias; /* address this results from */ 108 char *q_owner; /* owner of q_alias */ 109 struct address *q_tchain; /* temporary use chain */ 110 time_t q_timeout; /* timeout for this address */ 111 }; 112 113 typedef struct address ADDRESS; 114 115 # define QDONTSEND 000001 /* don't send to this address */ 116 # define QBADADDR 000002 /* this address is verified bad */ 117 # define QGOODUID 000004 /* the q_uid q_gid fields are good */ 118 # define QPRIMARY 000010 /* set from argv */ 119 # define QQUEUEUP 000020 /* queue for later transmission */ 120 # define QSENT 000040 /* has been successfully delivered */ 121 # define QNOTREMOTE 000100 /* not an address for remote forwarding */ 122 # define QSELFREF 000200 /* this address references itself */ 123 # define QVERIFIED 000400 /* verified, but not expanded */ 124 /* 125 ** Mailer definition structure. 126 ** Every mailer known to the system is declared in this 127 ** structure. It defines the pathname of the mailer, some 128 ** flags associated with it, and the argument vector to 129 ** pass to it. The flags are defined in conf.c 130 ** 131 ** The argument vector is expanded before actual use. All 132 ** words except the first are passed through the macro 133 ** processor. 134 */ 135 136 struct mailer 137 { 138 char *m_name; /* symbolic name of this mailer */ 139 char *m_mailer; /* pathname of the mailer to use */ 140 BITMAP m_flags; /* status flags, see below */ 141 short m_mno; /* mailer number internally */ 142 char **m_argv; /* template argument vector */ 143 short m_sh_rwset; /* rewrite set: sender header addresses */ 144 short m_se_rwset; /* rewrite set: sender envelope addresses */ 145 short m_rh_rwset; /* rewrite set: recipient header addresses */ 146 short m_re_rwset; /* rewrite set: recipient envelope addresses */ 147 char *m_eol; /* end of line string */ 148 long m_maxsize; /* size limit on message to this mailer */ 149 int m_linelimit; /* max # characters per line */ 150 char *m_execdir; /* directory to chdir to before execv */ 151 }; 152 153 typedef struct mailer MAILER; 154 155 /* bits for m_flags */ 156 # define M_NOCOMMENT 'c' /* don't include comment part of address */ 157 # define M_CANONICAL 'C' /* make addresses canonical "u@dom" */ 158 /* 'D' /* CF: include Date: */ 159 # define M_EXPENSIVE 'e' /* it costs to use this mailer.... */ 160 # define M_ESCFROM 'E' /* escape From lines to >From */ 161 # define M_FOPT 'f' /* mailer takes picky -f flag */ 162 /* 'F' /* CF: include From: or Resent-From: */ 163 # define M_HST_UPPER 'h' /* preserve host case distinction */ 164 /* 'H' /* UIUC: MAIL11V3: preview headers */ 165 # define M_INTERNAL 'I' /* SMTP to another sendmail site */ 166 # define M_LOCALMAILER 'l' /* delivery is to this host */ 167 # define M_LIMITS 'L' /* must enforce SMTP line limits */ 168 # define M_MUSER 'm' /* can handle multiple users at once */ 169 /* 'M' /* CF: include Message-Id: */ 170 # define M_NHDR 'n' /* don't insert From line */ 171 /* 'N' /* UIUC: MAIL11V3: DATA returns multi-status */ 172 # define M_FROMPATH 'p' /* use reverse-path in MAIL FROM: */ 173 /* 'P' /* CF: include Return-Path: */ 174 # define M_ROPT 'r' /* mailer takes picky -r flag */ 175 # define M_SECURE_PORT 'R' /* try to send on a reserved TCP port */ 176 # define M_STRIPQ 's' /* strip quote chars from user/host */ 177 # define M_RESTR 'S' /* must be daemon to execute */ 178 # define M_USR_UPPER 'u' /* preserve user case distinction */ 179 # define M_UGLYUUCP 'U' /* this wants an ugly UUCP from line */ 180 /* 'V' /* UIUC: !-relativize all addresses */ 181 # define M_XDOT 'X' /* use hidden-dot algorithm */ 182 # define M_7BITS '7' /* use 7-bit path */ 183 184 EXTERN MAILER *Mailer[MAXMAILERS+1]; 185 186 EXTERN MAILER *LocalMailer; /* ptr to local mailer */ 187 EXTERN MAILER *ProgMailer; /* ptr to program mailer */ 188 EXTERN MAILER *FileMailer; /* ptr to *file* mailer */ 189 EXTERN MAILER *InclMailer; /* ptr to *include* mailer */ 190 /* 191 ** Header structure. 192 ** This structure is used internally to store header items. 193 */ 194 195 struct header 196 { 197 char *h_field; /* the name of the field */ 198 char *h_value; /* the value of that field */ 199 struct header *h_link; /* the next header */ 200 u_short h_flags; /* status bits, see below */ 201 BITMAP h_mflags; /* m_flags bits needed */ 202 }; 203 204 typedef struct header HDR; 205 206 /* 207 ** Header information structure. 208 ** Defined in conf.c, this struct declares the header fields 209 ** that have some magic meaning. 210 */ 211 212 struct hdrinfo 213 { 214 char *hi_field; /* the name of the field */ 215 u_short hi_flags; /* status bits, see below */ 216 }; 217 218 extern struct hdrinfo HdrInfo[]; 219 220 /* bits for h_flags and hi_flags */ 221 # define H_EOH 00001 /* this field terminates header */ 222 # define H_RCPT 00002 /* contains recipient addresses */ 223 # define H_DEFAULT 00004 /* if another value is found, drop this */ 224 # define H_RESENT 00010 /* this address is a "Resent-..." address */ 225 # define H_CHECK 00020 /* check h_mflags against m_flags */ 226 # define H_ACHECK 00040 /* ditto, but always (not just default) */ 227 # define H_FORCE 00100 /* force this field, even if default */ 228 # define H_TRACE 00200 /* this field contains trace information */ 229 # define H_FROM 00400 /* this is a from-type field */ 230 # define H_VALID 01000 /* this field has a validated value */ 231 # define H_RECEIPTTO 02000 /* this field has return receipt info */ 232 # define H_ERRORSTO 04000 /* this field has error address info */ 233 /* 234 ** Envelope structure. 235 ** This structure defines the message itself. There is usually 236 ** only one of these -- for the message that we originally read 237 ** and which is our primary interest -- but other envelopes can 238 ** be generated during processing. For example, error messages 239 ** will have their own envelope. 240 */ 241 242 struct envelope 243 { 244 HDR *e_header; /* head of header list */ 245 long e_msgpriority; /* adjusted priority of this message */ 246 time_t e_ctime; /* time message appeared in the queue */ 247 char *e_to; /* the target person */ 248 char *e_receiptto; /* return receipt address */ 249 ADDRESS e_from; /* the person it is from */ 250 char *e_sender; /* e_from.q_paddr w comments stripped */ 251 char **e_fromdomain; /* the domain part of the sender */ 252 ADDRESS *e_sendqueue; /* list of message recipients */ 253 ADDRESS *e_errorqueue; /* the queue for error responses */ 254 long e_msgsize; /* size of the message in bytes */ 255 int e_nrcpts; /* number of recipients */ 256 short e_class; /* msg class (priority, junk, etc.) */ 257 short e_flags; /* flags, see below */ 258 short e_hopcount; /* number of times processed */ 259 short e_nsent; /* number of sends since checkpoint */ 260 short e_sendmode; /* message send mode */ 261 short e_errormode; /* error return mode */ 262 int (*e_puthdr)(); /* function to put header of message */ 263 int (*e_putbody)(); /* function to put body of message */ 264 struct envelope *e_parent; /* the message this one encloses */ 265 struct envelope *e_sibling; /* the next envelope of interest */ 266 char *e_bodytype; /* type of message body */ 267 char *e_df; /* location of temp file */ 268 FILE *e_dfp; /* temporary file */ 269 char *e_id; /* code for this entry in queue */ 270 FILE *e_xfp; /* transcript file */ 271 FILE *e_lockfp; /* the lock file for this message */ 272 char *e_message; /* error message */ 273 char *e_statmsg; /* stat msg (changes per delivery) */ 274 char *e_macro[128]; /* macro definitions */ 275 }; 276 277 typedef struct envelope ENVELOPE; 278 279 /* values for e_flags */ 280 #define EF_OLDSTYLE 000001 /* use spaces (not commas) in hdrs */ 281 #define EF_INQUEUE 000002 /* this message is fully queued */ 282 #define EF_TIMEOUT 000004 /* this message is too old */ 283 #define EF_CLRQUEUE 000010 /* disk copy is no longer needed */ 284 #define EF_SENDRECEIPT 000020 /* send a return receipt */ 285 #define EF_FATALERRS 000040 /* fatal errors occured */ 286 #define EF_KEEPQUEUE 000100 /* keep queue files always */ 287 #define EF_RESPONSE 000200 /* this is an error or return receipt */ 288 #define EF_RESENT 000400 /* this message is being forwarded */ 289 #define EF_VRFYONLY 001000 /* verify only (don't expand aliases) */ 290 #define EF_WARNING 002000 /* warning message has been sent */ 291 #define EF_QUEUERUN 004000 /* this envelope is from queue */ 292 293 EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */ 294 /* 295 ** Message priority classes. 296 ** 297 ** The message class is read directly from the Priority: header 298 ** field in the message. 299 ** 300 ** CurEnv->e_msgpriority is the number of bytes in the message plus 301 ** the creation time (so that jobs ``tend'' to be ordered correctly), 302 ** adjusted by the message class, the number of recipients, and the 303 ** amount of time the message has been sitting around. This number 304 ** is used to order the queue. Higher values mean LOWER priority. 305 ** 306 ** Each priority class point is worth WkClassFact priority points; 307 ** each recipient is worth WkRecipFact priority points. Each time 308 ** we reprocess a message the priority is adjusted by WkTimeFact. 309 ** WkTimeFact should normally decrease the priority so that jobs 310 ** that have historically failed will be run later; thanks go to 311 ** Jay Lepreau at Utah for pointing out the error in my thinking. 312 ** 313 ** The "class" is this number, unadjusted by the age or size of 314 ** this message. Classes with negative representations will have 315 ** error messages thrown away if they are not local. 316 */ 317 318 struct priority 319 { 320 char *pri_name; /* external name of priority */ 321 int pri_val; /* internal value for same */ 322 }; 323 324 EXTERN struct priority Priorities[MAXPRIORITIES]; 325 EXTERN int NumPriorities; /* pointer into Priorities */ 326 /* 327 ** Rewrite rules. 328 */ 329 330 struct rewrite 331 { 332 char **r_lhs; /* pattern match */ 333 char **r_rhs; /* substitution value */ 334 struct rewrite *r_next;/* next in chain */ 335 }; 336 337 EXTERN struct rewrite *RewriteRules[MAXRWSETS]; 338 339 /* 340 ** Special characters in rewriting rules. 341 ** These are used internally only. 342 ** The COND* rules are actually used in macros rather than in 343 ** rewriting rules, but are given here because they 344 ** cannot conflict. 345 */ 346 347 /* left hand side items */ 348 # define MATCHZANY 0220 /* match zero or more tokens */ 349 # define MATCHANY 0221 /* match one or more tokens */ 350 # define MATCHONE 0222 /* match exactly one token */ 351 # define MATCHCLASS 0223 /* match one token in a class */ 352 # define MATCHNCLASS 0224 /* match anything not in class */ 353 # define MATCHREPL 0225 /* replacement on RHS for above */ 354 355 /* right hand side items */ 356 # define CANONNET 0226 /* canonical net, next token */ 357 # define CANONHOST 0227 /* canonical host, next token */ 358 # define CANONUSER 0230 /* canonical user, next N tokens */ 359 # define CALLSUBR 0231 /* call another rewriting set */ 360 361 /* conditionals in macros */ 362 # define CONDIF 0232 /* conditional if-then */ 363 # define CONDELSE 0233 /* conditional else */ 364 # define CONDFI 0234 /* conditional fi */ 365 366 /* bracket characters for host name lookup */ 367 # define HOSTBEGIN 0235 /* hostname lookup begin */ 368 # define HOSTEND 0236 /* hostname lookup end */ 369 370 /* bracket characters for generalized lookup */ 371 # define LOOKUPBEGIN 0205 /* generalized lookup begin */ 372 # define LOOKUPEND 0206 /* generalized lookup end */ 373 374 /* macro substitution character */ 375 # define MACROEXPAND 0201 /* macro expansion */ 376 # define MACRODEXPAND 0202 /* deferred macro expansion */ 377 378 /* to make the code clearer */ 379 # define MATCHZERO CANONHOST 380 381 /* external <==> internal mapping table */ 382 struct metamac 383 { 384 char metaname; /* external code (after $) */ 385 char metaval; /* internal code (as above) */ 386 }; 387 /* 388 ** Information about currently open connections to mailers, or to 389 ** hosts that we have looked up recently. 390 */ 391 392 # define MCI struct mailer_con_info 393 394 MCI 395 { 396 short mci_flags; /* flag bits, see below */ 397 short mci_errno; /* error number on last connection */ 398 short mci_exitstat; /* exit status from last connection */ 399 short mci_state; /* SMTP state */ 400 FILE *mci_in; /* input side of connection */ 401 FILE *mci_out; /* output side of connection */ 402 int mci_pid; /* process id of subordinate proc */ 403 char *mci_phase; /* SMTP phase string */ 404 struct mailer *mci_mailer; /* ptr to the mailer for this conn */ 405 char *mci_host; /* host name */ 406 time_t mci_lastuse; /* last usage time */ 407 }; 408 409 410 /* flag bits */ 411 #define MCIF_VALID 00001 /* this entry is valid */ 412 #define MCIF_TEMP 00002 /* don't cache this connection */ 413 #define MCIF_CACHED 00004 /* currently in open cache */ 414 415 /* states */ 416 #define MCIS_CLOSED 0 /* no traffic on this connection */ 417 #define MCIS_OPENING 1 /* sending initial protocol */ 418 #define MCIS_OPEN 2 /* open, initial protocol sent */ 419 #define MCIS_ACTIVE 3 /* message being sent */ 420 #define MCIS_QUITING 4 /* running quit protocol */ 421 #define MCIS_SSD 5 /* service shutting down */ 422 #define MCIS_ERROR 6 /* I/O error on connection */ 423 /* 424 ** Mapping functions 425 ** 426 ** These allow arbitrary mappings in the config file. The idea 427 ** (albeit not the implementation) comes from IDA sendmail. 428 */ 429 430 431 /* 432 ** The class of a map -- essentially the functions to call 433 */ 434 435 # define MAPCLASS struct _mapclass 436 437 MAPCLASS 438 { 439 bool (*map_init)(); /* initialization function */ 440 char *(*map_lookup)(); /* lookup function */ 441 }; 442 443 444 /* 445 ** An actual map. 446 */ 447 448 # define MAP struct _map 449 450 MAP 451 { 452 MAPCLASS *map_class; /* the class of this map */ 453 int map_flags; /* flags, see below */ 454 char *map_file; /* the (nominal) filename */ 455 void *map_db; /* the open database ptr */ 456 char *map_app; /* to append to successful matches */ 457 char *map_domain; /* the (nominal) NIS domain */ 458 char *map_rebuild; /* program to run to do auto-rebuild */ 459 }; 460 461 /* bit values for map_flags */ 462 # define MF_VALID 00001 /* this entry is valid */ 463 # define MF_INCLNULL 00002 /* include null byte in key */ 464 # define MF_OPTIONAL 00004 /* don't complain if map not found */ 465 # define MF_NOFOLDCASE 00010 /* don't fold case in keys */ 466 # define MF_MATCHONLY 00020 /* don't use the map value */ 467 /* 468 ** Symbol table definitions 469 */ 470 471 struct symtab 472 { 473 char *s_name; /* name to be entered */ 474 char s_type; /* general type (see below) */ 475 struct symtab *s_next; /* pointer to next in chain */ 476 union 477 { 478 BITMAP sv_class; /* bit-map of word classes */ 479 ADDRESS *sv_addr; /* pointer to address header */ 480 MAILER *sv_mailer; /* pointer to mailer */ 481 char *sv_alias; /* alias */ 482 MAPCLASS sv_mapclass; /* mapping function class */ 483 MAP sv_map; /* mapping function */ 484 char *sv_hostsig; /* host signature */ 485 MCI sv_mci; /* mailer connection info */ 486 } s_value; 487 }; 488 489 typedef struct symtab STAB; 490 491 /* symbol types */ 492 # define ST_UNDEF 0 /* undefined type */ 493 # define ST_CLASS 1 /* class map */ 494 # define ST_ADDRESS 2 /* an address in parsed format */ 495 # define ST_MAILER 3 /* a mailer header */ 496 # define ST_ALIAS 4 /* an alias */ 497 # define ST_MAPCLASS 5 /* mapping function class */ 498 # define ST_MAP 6 /* mapping function */ 499 # define ST_HOSTSIG 7 /* host signature */ 500 # define ST_MCI 16 /* mailer connection info (offset) */ 501 502 # define s_class s_value.sv_class 503 # define s_address s_value.sv_addr 504 # define s_mailer s_value.sv_mailer 505 # define s_alias s_value.sv_alias 506 # define s_mci s_value.sv_mci 507 # define s_mapclass s_value.sv_mapclass 508 # define s_hostsig s_value.sv_hostsig 509 # define s_map s_value.sv_map 510 511 extern STAB *stab(); 512 513 /* opcodes to stab */ 514 # define ST_FIND 0 /* find entry */ 515 # define ST_ENTER 1 /* enter if not there */ 516 /* 517 ** STRUCT EVENT -- event queue. 518 ** 519 ** Maintained in sorted order. 520 ** 521 ** We store the pid of the process that set this event to insure 522 ** that when we fork we will not take events intended for the parent. 523 */ 524 525 struct event 526 { 527 time_t ev_time; /* time of the function call */ 528 int (*ev_func)(); /* function to call */ 529 int ev_arg; /* argument to ev_func */ 530 int ev_pid; /* pid that set this event */ 531 struct event *ev_link; /* link to next item */ 532 }; 533 534 typedef struct event EVENT; 535 536 EXTERN EVENT *EventQueue; /* head of event queue */ 537 /* 538 ** Operation, send, and error modes 539 ** 540 ** The operation mode describes the basic operation of sendmail. 541 ** This can be set from the command line, and is "send mail" by 542 ** default. 543 ** 544 ** The send mode tells how to send mail. It can be set in the 545 ** configuration file. It's setting determines how quickly the 546 ** mail will be delivered versus the load on your system. If the 547 ** -v (verbose) flag is given, it will be forced to SM_DELIVER 548 ** mode. 549 ** 550 ** The error mode tells how to return errors. 551 */ 552 553 EXTERN char OpMode; /* operation mode, see below */ 554 555 #define MD_DELIVER 'm' /* be a mail sender */ 556 #define MD_SMTP 's' /* run SMTP on standard input */ 557 #define MD_DAEMON 'd' /* run as a daemon */ 558 #define MD_VERIFY 'v' /* verify: don't collect or deliver */ 559 #define MD_TEST 't' /* test mode: resolve addrs only */ 560 #define MD_INITALIAS 'i' /* initialize alias database */ 561 #define MD_PRINT 'p' /* print the queue */ 562 #define MD_FREEZE 'z' /* freeze the configuration file */ 563 564 565 /* values for e_sendmode -- send modes */ 566 #define SM_DELIVER 'i' /* interactive delivery */ 567 #define SM_QUICKD 'j' /* deliver w/o queueing */ 568 #define SM_FORK 'b' /* deliver in background */ 569 #define SM_QUEUE 'q' /* queue, don't deliver */ 570 #define SM_VERIFY 'v' /* verify only (used internally) */ 571 572 /* used only as a parameter to sendall */ 573 #define SM_DEFAULT '\0' /* unspecified, use SendMode */ 574 575 576 /* values for e_errormode -- error handling modes */ 577 #define EM_PRINT 'p' /* print errors */ 578 #define EM_MAIL 'm' /* mail back errors */ 579 #define EM_WRITE 'w' /* write back errors */ 580 #define EM_BERKNET 'e' /* special berknet processing */ 581 #define EM_QUIET 'q' /* don't print messages (stat only) */ 582 583 /* Offset used to ensure that name server error * codes are unique */ 584 #define MAX_ERRNO 100 585 586 /* privacy flags */ 587 #define PRIV_PUBLIC 0 /* what have I got to hide? */ 588 #define PRIV_NEEDMAILHELO 00001 /* insist on HELO for MAIL, at least */ 589 #define PRIV_NEEDEXPNHELO 00002 /* insist on HELO for EXPN */ 590 #define PRIV_NEEDVRFYHELO 00004 /* insist on HELO for VRFY */ 591 #define PRIV_NOEXPN 00010 /* disallow EXPN command entirely */ 592 #define PRIV_NOVRFY 00020 /* disallow VRFY command entirely */ 593 #define PRIV_AUTHWARNINGS 00040 /* flag possible authorization probs */ 594 #define PRIV_RESTRMAILQ 01000 /* restrict mailq command */ 595 #define PRIV_GOAWAY 00777 /* don't give no info, anyway, anyhow */ 596 597 /* struct defining such things */ 598 struct prival 599 { 600 char *pv_name; /* name of privacy flag */ 601 int pv_flag; /* numeric level */ 602 }; 603 604 /* 605 ** Regular UNIX sockaddrs are too small to handle ISO addresses, so 606 ** we are forced to declare a supertype here. 607 */ 608 609 union bigsockaddr 610 { 611 struct sockaddr sa; /* general version */ 612 #ifdef NETINET 613 struct sockaddr_in sin; /* INET family */ 614 #endif 615 #ifdef NETISO 616 struct sockaddr_iso siso; /* ISO family */ 617 #endif 618 #ifdef NETNS 619 struct sockaddr_ns sns; /* XNS family */ 620 #endif 621 #ifdef NETX25 622 struct sockaddr_x25 sx25; /* X.25 family */ 623 #endif 624 }; 625 626 #define SOCKADDR union bigsockaddr 627 628 /* 629 ** Global variables. 630 */ 631 632 EXTERN bool FromFlag; /* if set, "From" person is explicit */ 633 EXTERN bool NoAlias; /* if set, don't do any aliasing */ 634 EXTERN bool MeToo; /* send to the sender also */ 635 EXTERN bool IgnrDot; /* don't let dot end messages */ 636 EXTERN bool SaveFrom; /* save leading "From" lines */ 637 EXTERN bool Verbose; /* set if blow-by-blow desired */ 638 EXTERN bool GrabTo; /* if set, get recipients from msg */ 639 EXTERN bool NoReturn; /* don't return letter to sender */ 640 EXTERN bool SuprErrs; /* set if we are suppressing errors */ 641 EXTERN bool HoldErrs; /* only output errors to transcript */ 642 EXTERN bool NoConnect; /* don't connect to non-local mailers */ 643 EXTERN bool SuperSafe; /* be extra careful, even if expensive */ 644 EXTERN bool ForkQueueRuns; /* fork for each job when running the queue */ 645 EXTERN bool AutoRebuild; /* auto-rebuild the alias database as needed */ 646 EXTERN bool CheckAliases; /* parse addresses during newaliases */ 647 EXTERN bool UseNameServer; /* use internet domain name server */ 648 EXTERN bool EightBit; /* try to preserve 8-bit data */ 649 EXTERN int SafeAlias; /* minutes to wait until @:@ in alias file */ 650 EXTERN FILE *InChannel; /* input connection */ 651 EXTERN FILE *OutChannel; /* output connection */ 652 EXTERN uid_t RealUid; /* when Daemon, real uid of caller */ 653 EXTERN gid_t RealGid; /* when Daemon, real gid of caller */ 654 EXTERN uid_t DefUid; /* default uid to run as */ 655 EXTERN gid_t DefGid; /* default gid to run as */ 656 EXTERN char *DefUser; /* default user to run as (from DefUid) */ 657 EXTERN int OldUmask; /* umask when sendmail starts up */ 658 EXTERN int Errors; /* set if errors (local to single pass) */ 659 EXTERN int ExitStat; /* exit status code */ 660 EXTERN int AliasLevel; /* depth of aliasing */ 661 EXTERN int LineNumber; /* line number in current input */ 662 EXTERN int LogLevel; /* level of logging to perform */ 663 EXTERN int FileMode; /* mode on files */ 664 EXTERN int QueueLA; /* load average starting forced queueing */ 665 EXTERN int RefuseLA; /* load average refusing connections are */ 666 EXTERN int CurrentLA; /* current load average */ 667 EXTERN long QueueFactor; /* slope of queue function */ 668 EXTERN time_t QueueIntvl; /* intervals between running the queue */ 669 EXTERN char *AliasFile; /* location of alias file */ 670 EXTERN char *HelpFile; /* location of SMTP help file */ 671 EXTERN char *ErrMsgFile; /* file to prepend to all error messages */ 672 EXTERN char *StatFile; /* location of statistics summary */ 673 EXTERN char *QueueDir; /* location of queue directory */ 674 EXTERN char *FileName; /* name to print on error messages */ 675 EXTERN char *SmtpPhase; /* current phase in SMTP processing */ 676 EXTERN char *MyHostName; /* name of this host for SMTP messages */ 677 EXTERN char *RealHostName; /* name of host we are talking to */ 678 EXTERN SOCKADDR RealHostAddr; /* address of host we are talking to */ 679 EXTERN char *CurHostName; /* current host we are dealing with */ 680 EXTERN jmp_buf TopFrame; /* branch-to-top-of-loop-on-error frame */ 681 EXTERN bool QuickAbort; /* .... but only if we want a quick abort */ 682 EXTERN bool LogUsrErrs; /* syslog user errors (e.g., SMTP RCPT cmd) */ 683 EXTERN int PrivacyFlags; /* privacy flags */ 684 extern char *ConfFile; /* location of configuration file [conf.c] */ 685 extern char *FreezeFile; /* location of frozen memory image [conf.c] */ 686 extern char *PidFile; /* location of proc id file [conf.c] */ 687 extern ADDRESS NullAddress; /* a null (template) address [main.c] */ 688 EXTERN char SpaceSub; /* substitution for <lwsp> */ 689 EXTERN long WkClassFact; /* multiplier for message class -> priority */ 690 EXTERN long WkRecipFact; /* multiplier for # of recipients -> priority */ 691 EXTERN long WkTimeFact; /* priority offset each time this job is run */ 692 EXTERN char *PostMasterCopy; /* address to get errs cc's */ 693 EXTERN int CheckpointInterval; /* queue file checkpoint interval */ 694 EXTERN char *UdbSpec; /* user database source spec [udbexpand.c] */ 695 EXTERN int MaxHopCount; /* number of hops until we give an error */ 696 EXTERN int ConfigLevel; /* config file level -- what does .cf expect? */ 697 EXTERN char *TimeZoneSpec; /* override time zone specification */ 698 EXTERN bool MatchGecos; /* look for user names in gecos field */ 699 EXTERN bool DontPruneRoutes; /* don't prune source routes */ 700 EXTERN int MaxMciCache; /* maximum entries in MCI cache */ 701 EXTERN time_t MciCacheTimeout; /* maximum idle time on connections */ 702 EXTERN char *ForwardPath; /* path to search for .forward files */ 703 EXTERN long MinBlocksFree; /* minimum number of blocks free on queue fs */ 704 EXTERN char *QueueLimitRecipient; /* limit queue runs to this recipient */ 705 EXTERN char *QueueLimitSender; /* limit queue runs to this sender */ 706 EXTERN char *QueueLimitId; /* limit queue runs to this id */ 707 EXTERN char *FallBackMX; /* fall back MX host */ 708 709 710 /* 711 ** Timeouts 712 ** 713 ** Indicated values are the MINIMUM per RFC 1123 section 5.3.2. 714 */ 715 716 EXTERN struct 717 { 718 time_t to_initial; /* initial greeting timeout [5m] */ 719 time_t to_mail; /* MAIL command [5m] */ 720 time_t to_rcpt; /* RCPT command [5m] */ 721 time_t to_datainit; /* DATA initiation [2m] */ 722 time_t to_datablock; /* DATA block [3m] */ 723 time_t to_datafinal; /* DATA completion [10m] */ 724 time_t to_nextcommand; /* next command [5m] */ 725 /* following timeouts are not mentioned in RFC 1123 */ 726 time_t to_rset; /* RSET command */ 727 time_t to_helo; /* HELO command */ 728 time_t to_quit; /* QUIT command */ 729 time_t to_miscshort; /* misc short commands (NOOP, VERB, etc) */ 730 /* following are per message */ 731 time_t to_q_return; /* queue return timeout */ 732 time_t to_q_warning; /* queue warning timeout */ 733 } TimeOuts; 734 735 736 /* 737 ** Trace information 738 */ 739 740 /* trace vector and macros for debugging flags */ 741 EXTERN u_char tTdvect[100]; 742 # define tTd(flag, level) (tTdvect[flag] >= level) 743 # define tTdlevel(flag) (tTdvect[flag]) 744 /* 745 ** Miscellaneous information. 746 */ 747 748 749 750 /* 751 ** Some in-line functions 752 */ 753 754 /* set exit status */ 755 #define setstat(s) { \ 756 if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \ 757 ExitStat = s; \ 758 } 759 760 /* make a copy of a string */ 761 #define newstr(s) strcpy(xalloc(strlen(s) + 1), s) 762 763 #define STRUCTCOPY(s, d) d = s 764 765 766 /* 767 ** Declarations of useful functions 768 */ 769 770 #if defined(__STDC__) && defined(_FORGIVING_CC_) 771 #define P(protos) protos 772 #else 773 #define P(protos) () 774 #endif 775 776 extern ADDRESS *parseaddr P((char *, ADDRESS *, int, char, char **, ENVELOPE *)); 777 extern char *xalloc P((int)); 778 extern bool sameaddr P((ADDRESS *, ADDRESS *)); 779 extern FILE *dfopen P((char *, char *)); 780 extern EVENT *setevent P((time_t, int(*)(), int)); 781 extern char *sfgets P((char *, int, FILE *, time_t)); 782 extern char *queuename P((ENVELOPE *, char)); 783 extern time_t curtime P(()); 784 extern bool transienterror P((int)); 785 extern char *errstring P((int)); 786 787 /* ellipsis is a different case though */ 788 #ifdef __STDC__ 789 extern void auth_warning(ENVELOPE *, char *, ...); 790 extern void syserr(char *, ...); 791 extern void usrerr(char *, ...); 792 extern void message(char *, ...); 793 extern void nmessage(char *, ...); 794 #else 795 extern void auth_warning(); 796 extern void syserr(); 797 extern void usrerr(); 798 extern void message(); 799 extern void nmessage(); 800 #endif 801