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