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