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