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