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.44 (Berkeley) 04/04/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.44 04/04/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_df; /* location of temp file */ 267 FILE *e_dfp; /* temporary file */ 268 char *e_id; /* code for this entry in queue */ 269 FILE *e_xfp; /* transcript file */ 270 FILE *e_lockfp; /* the lock file for this message */ 271 char *e_message; /* error message */ 272 char *e_statmsg; /* stat msg (changes per delivery) */ 273 char *e_macro[128]; /* macro definitions */ 274 }; 275 276 typedef struct envelope ENVELOPE; 277 278 /* values for e_flags */ 279 #define EF_OLDSTYLE 000001 /* use spaces (not commas) in hdrs */ 280 #define EF_INQUEUE 000002 /* this message is fully queued */ 281 #define EF_TIMEOUT 000004 /* this message is too old */ 282 #define EF_CLRQUEUE 000010 /* disk copy is no longer needed */ 283 #define EF_SENDRECEIPT 000020 /* send a return receipt */ 284 #define EF_FATALERRS 000040 /* fatal errors occured */ 285 #define EF_KEEPQUEUE 000100 /* keep queue files always */ 286 #define EF_RESPONSE 000200 /* this is an error or return receipt */ 287 #define EF_RESENT 000400 /* this message is being forwarded */ 288 #define EF_VRFYONLY 001000 /* verify only (don't expand aliases) */ 289 #define EF_WARNING 002000 /* warning message has been sent */ 290 #define EF_QUEUERUN 004000 /* this envelope is from queue */ 291 292 EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */ 293 /* 294 ** Message priority classes. 295 ** 296 ** The message class is read directly from the Priority: header 297 ** field in the message. 298 ** 299 ** CurEnv->e_msgpriority is the number of bytes in the message plus 300 ** the creation time (so that jobs ``tend'' to be ordered correctly), 301 ** adjusted by the message class, the number of recipients, and the 302 ** amount of time the message has been sitting around. This number 303 ** is used to order the queue. Higher values mean LOWER priority. 304 ** 305 ** Each priority class point is worth WkClassFact priority points; 306 ** each recipient is worth WkRecipFact priority points. Each time 307 ** we reprocess a message the priority is adjusted by WkTimeFact. 308 ** WkTimeFact should normally decrease the priority so that jobs 309 ** that have historically failed will be run later; thanks go to 310 ** Jay Lepreau at Utah for pointing out the error in my thinking. 311 ** 312 ** The "class" is this number, unadjusted by the age or size of 313 ** this message. Classes with negative representations will have 314 ** error messages thrown away if they are not local. 315 */ 316 317 struct priority 318 { 319 char *pri_name; /* external name of priority */ 320 int pri_val; /* internal value for same */ 321 }; 322 323 EXTERN struct priority Priorities[MAXPRIORITIES]; 324 EXTERN int NumPriorities; /* pointer into Priorities */ 325 /* 326 ** Rewrite rules. 327 */ 328 329 struct rewrite 330 { 331 char **r_lhs; /* pattern match */ 332 char **r_rhs; /* substitution value */ 333 struct rewrite *r_next;/* next in chain */ 334 }; 335 336 EXTERN struct rewrite *RewriteRules[MAXRWSETS]; 337 338 /* 339 ** Special characters in rewriting rules. 340 ** These are used internally only. 341 ** The COND* rules are actually used in macros rather than in 342 ** rewriting rules, but are given here because they 343 ** cannot conflict. 344 */ 345 346 /* left hand side items */ 347 # define MATCHZANY 0220 /* match zero or more tokens */ 348 # define MATCHANY 0221 /* match one or more tokens */ 349 # define MATCHONE 0222 /* match exactly one token */ 350 # define MATCHCLASS 0223 /* match one token in a class */ 351 # define MATCHNCLASS 0224 /* match anything not in class */ 352 # define MATCHREPL 0225 /* replacement on RHS for above */ 353 354 /* right hand side items */ 355 # define CANONNET 0226 /* canonical net, next token */ 356 # define CANONHOST 0227 /* canonical host, next token */ 357 # define CANONUSER 0230 /* canonical user, next N tokens */ 358 # define CALLSUBR 0231 /* call another rewriting set */ 359 360 /* conditionals in macros */ 361 # define CONDIF 0232 /* conditional if-then */ 362 # define CONDELSE 0233 /* conditional else */ 363 # define CONDFI 0234 /* conditional fi */ 364 365 /* bracket characters for host name lookup */ 366 # define HOSTBEGIN 0235 /* hostname lookup begin */ 367 # define HOSTEND 0236 /* hostname lookup end */ 368 369 /* bracket characters for generalized lookup */ 370 # define LOOKUPBEGIN 0205 /* generalized lookup begin */ 371 # define LOOKUPEND 0206 /* generalized lookup end */ 372 373 /* macro substitution character */ 374 # define MACROEXPAND 0201 /* macro expansion */ 375 376 /* to make the code clearer */ 377 # define MATCHZERO CANONHOST 378 379 /* external <==> internal mapping table */ 380 struct metamac 381 { 382 char metaname; /* external code (after $) */ 383 char metaval; /* internal code (as above) */ 384 }; 385 /* 386 ** Information about currently open connections to mailers, or to 387 ** hosts that we have looked up recently. 388 */ 389 390 # define MCI struct mailer_con_info 391 392 MCI 393 { 394 short mci_flags; /* flag bits, see below */ 395 short mci_errno; /* error number on last connection */ 396 short mci_exitstat; /* exit status from last connection */ 397 short mci_state; /* SMTP state */ 398 FILE *mci_in; /* input side of connection */ 399 FILE *mci_out; /* output side of connection */ 400 int mci_pid; /* process id of subordinate proc */ 401 char *mci_phase; /* SMTP phase string */ 402 struct mailer *mci_mailer; /* ptr to the mailer for this conn */ 403 char *mci_host; /* host name */ 404 time_t mci_lastuse; /* last usage time */ 405 }; 406 407 408 /* flag bits */ 409 #define MCIF_VALID 00001 /* this entry is valid */ 410 #define MCIF_TEMP 00002 /* don't cache this connection */ 411 #define MCIF_CACHED 00004 /* currently in open cache */ 412 413 /* states */ 414 #define MCIS_CLOSED 0 /* no traffic on this connection */ 415 #define MCIS_OPENING 1 /* sending initial protocol */ 416 #define MCIS_OPEN 2 /* open, initial protocol sent */ 417 #define MCIS_ACTIVE 3 /* message being sent */ 418 #define MCIS_QUITING 4 /* running quit protocol */ 419 #define MCIS_SSD 5 /* service shutting down */ 420 #define MCIS_ERROR 6 /* I/O error on connection */ 421 /* 422 ** Mapping functions 423 ** 424 ** These allow arbitrary mappings in the config file. The idea 425 ** (albeit not the implementation) comes from IDA sendmail. 426 */ 427 428 429 /* 430 ** The class of a map -- essentially the functions to call 431 */ 432 433 # define MAPCLASS struct _mapclass 434 435 MAPCLASS 436 { 437 bool (*map_init)(); /* initialization function */ 438 char *(*map_lookup)(); /* lookup function */ 439 }; 440 441 442 /* 443 ** An actual map. 444 */ 445 446 # define MAP struct _map 447 448 MAP 449 { 450 MAPCLASS *map_class; /* the class of this map */ 451 int map_flags; /* flags, see below */ 452 char *map_file; /* the (nominal) filename */ 453 void *map_db; /* the open database ptr */ 454 char *map_app; /* to append to successful matches */ 455 char *map_domain; /* the (nominal) NIS domain */ 456 char *map_rebuild; /* program to run to do auto-rebuild */ 457 }; 458 459 /* bit values for map_flags */ 460 # define MF_VALID 00001 /* this entry is valid */ 461 # define MF_INCLNULL 00002 /* include null byte in key */ 462 # define MF_OPTIONAL 00004 /* don't complain if map not found */ 463 # define MF_NOFOLDCASE 00010 /* don't fold case in keys */ 464 # define MF_MATCHONLY 00020 /* don't use the map value */ 465 /* 466 ** Symbol table definitions 467 */ 468 469 struct symtab 470 { 471 char *s_name; /* name to be entered */ 472 char s_type; /* general type (see below) */ 473 struct symtab *s_next; /* pointer to next in chain */ 474 union 475 { 476 BITMAP sv_class; /* bit-map of word classes */ 477 ADDRESS *sv_addr; /* pointer to address header */ 478 MAILER *sv_mailer; /* pointer to mailer */ 479 char *sv_alias; /* alias */ 480 MAPCLASS sv_mapclass; /* mapping function class */ 481 MAP sv_map; /* mapping function */ 482 char *sv_hostsig; /* host signature */ 483 MCI sv_mci; /* mailer connection info */ 484 } s_value; 485 }; 486 487 typedef struct symtab STAB; 488 489 /* symbol types */ 490 # define ST_UNDEF 0 /* undefined type */ 491 # define ST_CLASS 1 /* class map */ 492 # define ST_ADDRESS 2 /* an address in parsed format */ 493 # define ST_MAILER 3 /* a mailer header */ 494 # define ST_ALIAS 4 /* an alias */ 495 # define ST_MAPCLASS 5 /* mapping function class */ 496 # define ST_MAP 6 /* mapping function */ 497 # define ST_HOSTSIG 7 /* host signature */ 498 # define ST_MCI 16 /* mailer connection info (offset) */ 499 500 # define s_class s_value.sv_class 501 # define s_address s_value.sv_addr 502 # define s_mailer s_value.sv_mailer 503 # define s_alias s_value.sv_alias 504 # define s_mci s_value.sv_mci 505 # define s_mapclass s_value.sv_mapclass 506 # define s_hostsig s_value.sv_hostsig 507 # define s_map s_value.sv_map 508 509 extern STAB *stab(); 510 511 /* opcodes to stab */ 512 # define ST_FIND 0 /* find entry */ 513 # define ST_ENTER 1 /* enter if not there */ 514 /* 515 ** STRUCT EVENT -- event queue. 516 ** 517 ** Maintained in sorted order. 518 ** 519 ** We store the pid of the process that set this event to insure 520 ** that when we fork we will not take events intended for the parent. 521 */ 522 523 struct event 524 { 525 time_t ev_time; /* time of the function call */ 526 int (*ev_func)(); /* function to call */ 527 int ev_arg; /* argument to ev_func */ 528 int ev_pid; /* pid that set this event */ 529 struct event *ev_link; /* link to next item */ 530 }; 531 532 typedef struct event EVENT; 533 534 EXTERN EVENT *EventQueue; /* head of event queue */ 535 /* 536 ** Operation, send, and error modes 537 ** 538 ** The operation mode describes the basic operation of sendmail. 539 ** This can be set from the command line, and is "send mail" by 540 ** default. 541 ** 542 ** The send mode tells how to send mail. It can be set in the 543 ** configuration file. It's setting determines how quickly the 544 ** mail will be delivered versus the load on your system. If the 545 ** -v (verbose) flag is given, it will be forced to SM_DELIVER 546 ** mode. 547 ** 548 ** The error mode tells how to return errors. 549 */ 550 551 EXTERN char OpMode; /* operation mode, see below */ 552 553 #define MD_DELIVER 'm' /* be a mail sender */ 554 #define MD_SMTP 's' /* run SMTP on standard input */ 555 #define MD_DAEMON 'd' /* run as a daemon */ 556 #define MD_VERIFY 'v' /* verify: don't collect or deliver */ 557 #define MD_TEST 't' /* test mode: resolve addrs only */ 558 #define MD_INITALIAS 'i' /* initialize alias database */ 559 #define MD_PRINT 'p' /* print the queue */ 560 #define MD_FREEZE 'z' /* freeze the configuration file */ 561 562 563 /* values for e_sendmode -- send modes */ 564 #define SM_DELIVER 'i' /* interactive delivery */ 565 #define SM_QUICKD 'j' /* deliver w/o queueing */ 566 #define SM_FORK 'b' /* deliver in background */ 567 #define SM_QUEUE 'q' /* queue, don't deliver */ 568 #define SM_VERIFY 'v' /* verify only (used internally) */ 569 570 /* used only as a parameter to sendall */ 571 #define SM_DEFAULT '\0' /* unspecified, use SendMode */ 572 573 574 /* values for e_errormode -- error handling modes */ 575 #define EM_PRINT 'p' /* print errors */ 576 #define EM_MAIL 'm' /* mail back errors */ 577 #define EM_WRITE 'w' /* write back errors */ 578 #define EM_BERKNET 'e' /* special berknet processing */ 579 #define EM_QUIET 'q' /* don't print messages (stat only) */ 580 581 /* Offset used to ensure that name server error * codes are unique */ 582 #define MAX_ERRNO 100 583 584 /* privacy flags */ 585 #define PRIV_PUBLIC 0 /* what have I got to hide? */ 586 #define PRIV_NEEDMAILHELO 00001 /* insist on HELO for MAIL, at least */ 587 #define PRIV_NEEDEXPNHELO 00002 /* insist on HELO for EXPN */ 588 #define PRIV_NEEDVRFYHELO 00004 /* insist on HELO for VRFY */ 589 #define PRIV_NOEXPN 00010 /* disallow EXPN command entirely */ 590 #define PRIV_NOVRFY 00020 /* disallow VRFY command entirely */ 591 #define PRIV_AUTHWARNINGS 00040 /* flag possible authorization probs */ 592 #define PRIV_RESTRMAILQ 01000 /* restrict mailq command */ 593 #define PRIV_GOAWAY 00777 /* don't give no info, anyway, anyhow */ 594 595 /* struct defining such things */ 596 struct prival 597 { 598 char *pv_name; /* name of privacy flag */ 599 int pv_flag; /* numeric level */ 600 }; 601 602 /* 603 ** Regular UNIX sockaddrs are too small to handle ISO addresses, so 604 ** we are forced to declare a supertype here. 605 */ 606 607 union bigsockaddr 608 { 609 struct sockaddr sa; /* general version */ 610 #ifdef NETINET 611 struct sockaddr_in sin; /* INET family */ 612 #endif 613 #ifdef NETISO 614 struct sockaddr_iso siso; /* ISO family */ 615 #endif 616 #ifdef NETNS 617 struct sockaddr_ns sns; /* XNS family */ 618 #endif 619 #ifdef NETX25 620 struct sockaddr_x25 sx25; /* X.25 family */ 621 #endif 622 }; 623 624 #define SOCKADDR union bigsockaddr 625 626 /* 627 ** Global variables. 628 */ 629 630 EXTERN bool FromFlag; /* if set, "From" person is explicit */ 631 EXTERN bool NoAlias; /* if set, don't do any aliasing */ 632 EXTERN bool MeToo; /* send to the sender also */ 633 EXTERN bool IgnrDot; /* don't let dot end messages */ 634 EXTERN bool SaveFrom; /* save leading "From" lines */ 635 EXTERN bool Verbose; /* set if blow-by-blow desired */ 636 EXTERN bool GrabTo; /* if set, get recipients from msg */ 637 EXTERN bool NoReturn; /* don't return letter to sender */ 638 EXTERN bool SuprErrs; /* set if we are suppressing errors */ 639 EXTERN bool HoldErrs; /* only output errors to transcript */ 640 EXTERN bool NoConnect; /* don't connect to non-local mailers */ 641 EXTERN bool SuperSafe; /* be extra careful, even if expensive */ 642 EXTERN bool ForkQueueRuns; /* fork for each job when running the queue */ 643 EXTERN bool AutoRebuild; /* auto-rebuild the alias database as needed */ 644 EXTERN bool CheckAliases; /* parse addresses during newaliases */ 645 EXTERN bool UseNameServer; /* use internet domain name server */ 646 EXTERN bool EightBit; /* try to preserve 8-bit data */ 647 EXTERN int SafeAlias; /* minutes to wait until @:@ in alias file */ 648 EXTERN FILE *InChannel; /* input connection */ 649 EXTERN FILE *OutChannel; /* output connection */ 650 EXTERN uid_t RealUid; /* when Daemon, real uid of caller */ 651 EXTERN gid_t RealGid; /* when Daemon, real gid of caller */ 652 EXTERN uid_t DefUid; /* default uid to run as */ 653 EXTERN gid_t DefGid; /* default gid to run as */ 654 EXTERN char *DefUser; /* default user to run as (from DefUid) */ 655 EXTERN int OldUmask; /* umask when sendmail starts up */ 656 EXTERN int Errors; /* set if errors (local to single pass) */ 657 EXTERN int ExitStat; /* exit status code */ 658 EXTERN int AliasLevel; /* depth of aliasing */ 659 EXTERN int LineNumber; /* line number in current input */ 660 EXTERN int LogLevel; /* level of logging to perform */ 661 EXTERN int FileMode; /* mode on files */ 662 EXTERN int QueueLA; /* load average starting forced queueing */ 663 EXTERN int RefuseLA; /* load average refusing connections are */ 664 EXTERN int CurrentLA; /* current load average */ 665 EXTERN long QueueFactor; /* slope of queue function */ 666 EXTERN time_t QueueIntvl; /* intervals between running the queue */ 667 EXTERN char *AliasFile; /* location of alias file */ 668 EXTERN char *HelpFile; /* location of SMTP help file */ 669 EXTERN char *ErrMsgFile; /* file to prepend to all error messages */ 670 EXTERN char *StatFile; /* location of statistics summary */ 671 EXTERN char *QueueDir; /* location of queue directory */ 672 EXTERN char *FileName; /* name to print on error messages */ 673 EXTERN char *SmtpPhase; /* current phase in SMTP processing */ 674 EXTERN char *MyHostName; /* name of this host for SMTP messages */ 675 EXTERN char *RealHostName; /* name of host we are talking to */ 676 EXTERN SOCKADDR RealHostAddr; /* address of host we are talking to */ 677 EXTERN char *CurHostName; /* current host we are dealing with */ 678 EXTERN jmp_buf TopFrame; /* branch-to-top-of-loop-on-error frame */ 679 EXTERN bool QuickAbort; /* .... but only if we want a quick abort */ 680 EXTERN bool LogUsrErrs; /* syslog user errors (e.g., SMTP RCPT cmd) */ 681 EXTERN int PrivacyFlags; /* privacy flags */ 682 extern char *ConfFile; /* location of configuration file [conf.c] */ 683 extern char *FreezeFile; /* location of frozen memory image [conf.c] */ 684 extern char *PidFile; /* location of proc id file [conf.c] */ 685 extern ADDRESS NullAddress; /* a null (template) address [main.c] */ 686 EXTERN char SpaceSub; /* substitution for <lwsp> */ 687 EXTERN long WkClassFact; /* multiplier for message class -> priority */ 688 EXTERN long WkRecipFact; /* multiplier for # of recipients -> priority */ 689 EXTERN long WkTimeFact; /* priority offset each time this job is run */ 690 EXTERN char *PostMasterCopy; /* address to get errs cc's */ 691 EXTERN int CheckpointInterval; /* queue file checkpoint interval */ 692 EXTERN char *UdbSpec; /* user database source spec [udbexpand.c] */ 693 EXTERN int MaxHopCount; /* number of hops until we give an error */ 694 EXTERN int ConfigLevel; /* config file level -- what does .cf expect? */ 695 EXTERN char *TimeZoneSpec; /* override time zone specification */ 696 EXTERN bool MatchGecos; /* look for user names in gecos field */ 697 EXTERN bool DontPruneRoutes; /* don't prune source routes */ 698 EXTERN int MaxMciCache; /* maximum entries in MCI cache */ 699 EXTERN time_t MciCacheTimeout; /* maximum idle time on connections */ 700 EXTERN char *ForwardPath; /* path to search for .forward files */ 701 EXTERN long MinBlocksFree; /* minimum number of blocks free on queue fs */ 702 EXTERN char *QueueLimitRecipient; /* limit queue runs to this recipient */ 703 EXTERN char *QueueLimitSender; /* limit queue runs to this sender */ 704 EXTERN char *QueueLimitId; /* limit queue runs to this id */ 705 EXTERN char *FallBackMX; /* fall back MX host */ 706 707 708 /* 709 ** Timeouts 710 ** 711 ** Indicated values are the MINIMUM per RFC 1123 section 5.3.2. 712 */ 713 714 EXTERN struct 715 { 716 time_t to_initial; /* initial greeting timeout [5m] */ 717 time_t to_mail; /* MAIL command [5m] */ 718 time_t to_rcpt; /* RCPT command [5m] */ 719 time_t to_datainit; /* DATA initiation [2m] */ 720 time_t to_datablock; /* DATA block [3m] */ 721 time_t to_datafinal; /* DATA completion [10m] */ 722 time_t to_nextcommand; /* next command [5m] */ 723 /* following timeouts are not mentioned in RFC 1123 */ 724 time_t to_rset; /* RSET command */ 725 time_t to_helo; /* HELO command */ 726 time_t to_quit; /* QUIT command */ 727 time_t to_miscshort; /* misc short commands (NOOP, VERB, etc) */ 728 /* following are per message */ 729 time_t to_q_return; /* queue return timeout */ 730 time_t to_q_warning; /* queue warning timeout */ 731 } TimeOuts; 732 733 734 /* 735 ** Trace information 736 */ 737 738 /* trace vector and macros for debugging flags */ 739 EXTERN u_char tTdvect[100]; 740 # define tTd(flag, level) (tTdvect[flag] >= level) 741 # define tTdlevel(flag) (tTdvect[flag]) 742 /* 743 ** Miscellaneous information. 744 */ 745 746 747 748 /* 749 ** Some in-line functions 750 */ 751 752 /* set exit status */ 753 #define setstat(s) { \ 754 if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \ 755 ExitStat = s; \ 756 } 757 758 /* make a copy of a string */ 759 #define newstr(s) strcpy(xalloc(strlen(s) + 1), s) 760 761 #define STRUCTCOPY(s, d) d = s 762 763 764 /* 765 ** Declarations of useful functions 766 */ 767 768 #if defined(__STDC__) && defined(_FORGIVING_CC_) 769 #define P(protos) protos 770 #else 771 #define P(protos) () 772 #endif 773 774 extern ADDRESS *parseaddr P((char *, ADDRESS *, int, char, char **, ENVELOPE *)); 775 extern char *xalloc P((int)); 776 extern bool sameaddr P((ADDRESS *, ADDRESS *)); 777 extern FILE *dfopen P((char *, char *)); 778 extern EVENT *setevent P((time_t, int(*)(), int)); 779 extern char *sfgets P((char *, int, FILE *, time_t)); 780 extern char *queuename P((ENVELOPE *, char)); 781 extern time_t curtime P(()); 782 extern bool transienterror P((int)); 783 extern char *errstring P((int)); 784 785 /* ellipsis is a different case though */ 786 #ifdef __STDC__ 787 extern void auth_warning(ENVELOPE *, char *, ...); 788 extern void syserr(char *, ...); 789 extern void usrerr(char *, ...); 790 extern void message(char *, ...); 791 extern void nmessage(char *, ...); 792 #else 793 extern void auth_warning(); 794 extern void syserr(); 795 extern void usrerr(); 796 extern void message(); 797 extern void nmessage(); 798 #endif 799