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