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