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