1 /* 2 * Copyright (c) 1998-2013, 2023,2024 Proofpoint, Inc. and its suppliers. 3 * All rights reserved. 4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. 5 * Copyright (c) 1988, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * By using this file, you agree to the terms and conditions set 9 * forth in the LICENSE file which can be found at the top level of 10 * the sendmail distribution. 11 */ 12 13 /* 14 ** SENDMAIL.H -- MTA-specific definitions for sendmail. 15 */ 16 17 #ifndef _SENDMAIL_H 18 # define _SENDMAIL_H 1 19 20 #ifndef MILTER 21 # define MILTER 1 /* turn on MILTER by default */ 22 #endif 23 24 #ifdef _DEFINE 25 # define EXTERN 26 #else 27 # define EXTERN extern 28 #endif 29 30 #include <unistd.h> 31 32 #include <stddef.h> 33 #include <stdlib.h> 34 #include <stdio.h> 35 #include <ctype.h> 36 #include <setjmp.h> 37 #include <string.h> 38 #include <time.h> 39 40 #include "sendmail/sendmail.h" 41 42 #if STARTTLS 43 # include <openssl/ssl.h> 44 # if _FFR_TLSA_DANE && !defined(DANE) 45 # define DANE _FFR_TLSA_DANE 46 # endif 47 #else /* STARTTLS */ 48 # if DANE 49 # error "DANE set but STARTTLS not defined" 50 # endif 51 # if _FFR_TLS_ALTNAMES 52 # error "_FFR_TLS_ALTNAMES set but STARTTLS not defined" 53 # endif 54 # if _FFR_TLSFB2CLEAR 55 # error "_FFR_TLSFB2CLEAR set but STARTTLS not defined" 56 # endif 57 # if _FFR_TLS_USE_CERTIFICATE_CHAIN_FILE 58 # error "_FFR_TLS_USE_CERTIFICATE_CHAIN_FILE set but STARTTLS not defined" 59 # endif 60 #endif /* STARTTLS */ 61 62 /* profiling? */ 63 #if MONCONTROL 64 # define SM_PROF(x) moncontrol(x) 65 #else 66 # define SM_PROF(x) 67 #endif 68 69 #ifdef _DEFINE 70 # ifndef lint 71 SM_UNUSED(static char SmailId[]) = "@(#)$Id: sendmail.h,v 8.1104 2013-11-22 20:51:56 ca Exp $"; 72 # endif 73 #endif 74 75 #include "bf.h" 76 #include "timers.h" 77 #include <sm/exc.h> 78 #include <sm/gen.h> 79 #include <sm/heap.h> 80 #include <sm/debug.h> 81 #include <sm/rpool.h> 82 #include <sm/io.h> 83 #include <sm/path.h> 84 #include <sm/signal.h> 85 #include <sm/clock.h> 86 #include <sm/mbdb.h> 87 #include <sm/errstring.h> 88 #include <sm/sysexits.h> 89 #include <sm/shm.h> 90 #include <sm/misc.h> 91 92 #ifdef LOG 93 # include <syslog.h> 94 #endif 95 96 #if NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25 97 # include <sys/socket.h> 98 #endif 99 #if NETUNIX 100 # include <sys/un.h> 101 #endif 102 #if NETINET || NETINET6 103 # include <netinet/in.h> 104 #endif 105 #if NETINET6 106 /* 107 ** There is no standard yet for IPv6 includes. 108 ** Specify OS specific implementation in conf.h 109 */ 110 #endif /* NETINET6 */ 111 #if NETISO 112 # include <netiso/iso.h> 113 #endif 114 #if NETNS 115 # include <netns/ns.h> 116 #endif 117 #if NETX25 118 # include <netccitt/x25.h> 119 #endif 120 121 #if NAMED_BIND 122 # include <arpa/nameser.h> 123 # ifdef NOERROR 124 # undef NOERROR /* avoid <sys/streams.h> conflict */ 125 # endif 126 # include <resolv.h> 127 # if !defined(NO_DATA) 128 # define NO_DATA NO_ADDRESS 129 # endif 130 #else /* NAMED_BIND */ 131 # undef SM_SET_H_ERRNO 132 # define SM_SET_H_ERRNO(err) 133 #endif /* NAMED_BIND */ 134 135 #if HESIOD 136 # include <hesiod.h> 137 # if !defined(HES_ER_OK) || defined(HESIOD_INTERFACES) 138 # define HESIOD_INIT /* support for the new interface */ 139 # endif 140 #endif /* HESIOD */ 141 142 #if USE_EAI && !defined(ALLOW_255) 143 # define ALLOW_255 1 144 #endif 145 #if _FFR_EAI && _FFR_EIGHT_BIT_ADDR_OK 146 # error "Cannot enable both of these FFRs: _FFR_EAI _FFR_EIGHT_BIT_ADDR_OK" 147 #endif 148 149 #if _FFR_OCC && !SM_CONF_SHM 150 # error "_FFR_OCC requires SM_CONF_SHM" 151 #endif 152 153 #if !NOT_SENDMAIL 154 # if _FFR_SM_LDAP_DBG && !(LDAPMAP && defined(LBER_OPT_LOG_PRINT_FN)) 155 # error "_FFR_SM_LDAP_DBG requires LDAPMAP and LBER_OPT_LOG_PRINT_FN" 156 # endif 157 #endif 158 159 #if _FFR_LOG_MORE1 > 1 || _FFR_LOG_MORE2 > 1 160 # if _FFR_LOG_MORE1 != _FFR_LOG_MORE2 161 # error "_FFR_LOG_MORE1 != _FFR_LOG_MORE2" 162 # endif 163 #endif 164 165 #if !NOT_SENDMAIL 166 # if LDAP_NETWORK_TIMEOUT && !(LDAPMAP && defined(LDAP_OPT_NETWORK_TIMEOUT)) 167 # error "LDAP_NETWORK_TIMEOUT requires LDAPMAP" 168 # endif 169 #endif 170 171 #if !NOT_SENDMAIL 172 # if LDAP_REFERRALS && !LDAPMAP 173 # error "LDAP_REFERRALS requires LDAPMAP" 174 # endif 175 #endif 176 177 #if _FFR_VRFY_TRUSTED_FIRST && !defined(X509_V_FLAG_TRUSTED_FIRST) 178 # error "_FFR_VRFY_TRUSTED_FIRST set but X509_V_FLAG_TRUSTED_FIRST not defined" 179 #endif 180 181 #if _FFR_8BITENVADDR 182 # define MAXNAME_I ((MAXNAME) * 2) 183 #else 184 # define MAXNAME_I MAXNAME 185 #endif 186 187 #if !defined(_FFR_M_ONLY_IPV4) 188 # define _FFR_M_ONLY_IPV4 1 189 #endif 190 191 #define SM_IS_EMPTY(s) (NULL == (s) || '\0' == *(s)) 192 193 #if STARTTLS 194 # if DANE 195 # define DANE_FP_LOG_LEN 256 196 # define DANE_FP_DBG_LEN 4096 197 struct dane_vrfy_ctx_S 198 { 199 /* see tls.h: values for DANE option and dane_vrfy_chk */ 200 int dane_vrfy_chk; 201 int dane_vrfy_res; 202 int dane_vrfy_port; 203 204 /* use OpenSSL functions for DANE checks? */ 205 bool dane_vrfy_dane_enabled; 206 207 /* look up TLSA RRs, SNI unless dane_tlsa_sni is set. */ 208 char *dane_vrfy_host; 209 char *dane_vrfy_sni; /* if not NULL: use for SNI */ 210 211 /* fingerprint in printable format - just for logging */ 212 char dane_vrfy_fp[DANE_FP_LOG_LEN]; 213 }; 214 215 typedef struct dane_tlsa_S dane_tlsa_T, *dane_tlsa_P; 216 typedef struct dane_vrfy_ctx_S dane_vrfy_ctx_T, *dane_vrfy_ctx_P; 217 218 # endif /* DANE */ 219 220 /* TLS information context */ 221 struct tlsi_ctx_S 222 { 223 /* use unsigned long? */ 224 BITMAP256 tlsi_flags; 225 # if DANE 226 dane_vrfy_ctx_T tlsi_dvc; 227 # endif 228 }; 229 typedef struct tlsi_ctx_S tlsi_ctx_T, *tlsi_ctx_P; 230 231 /* TLS information context flags */ 232 #define TLSI_FL_CRLREQ 'R' /* CRL required */ 233 #define TLSI_FL_FB2CLR 'C' /* fall back to clear text is ok */ 234 #define TLSI_FL_NOFB2CLR 'c' /* do not fall back to clear text */ 235 #define TLSI_FL_NODANE 'd' /* do not use/look up DANE */ 236 #define TLSI_FL_NOSTS 'M' /* do not use/look up STS */ 237 /* internal */ 238 #define TLSI_FL_STS_NOFB2CLR 0x01 /* no clear text: STS is used */ 239 #define SM_TLSI_IS(tlsi_ctx, flag) \ 240 (((tlsi_ctx) != NULL) && bitnset((flag), (tlsi_ctx)->tlsi_flags)) 241 242 /* ugly hack, is it worth using different values? */ 243 # if _FFR_LOG_MORE1 > 1 || _FFR_LOG_MORE2 > 1 244 # define LOG_MORE_2(buf, bp) \ 245 p = macvalue(macid("{tls_version}"), e); \ 246 if (SM_IS_EMPTY(p)) \ 247 p = "NONE"; \ 248 (void) sm_snprintf(bp, SPACELEFT(buf, bp), ", tls_version=%.10s", p); \ 249 bp += strlen(bp); \ 250 p = macvalue(macid("{cipher}"), e); \ 251 if (SM_IS_EMPTY(p)) \ 252 p = "NONE"; \ 253 (void) sm_snprintf(bp, SPACELEFT(buf, bp), ", cipher=%.20s", p); \ 254 bp += strlen(bp); 255 # else 256 # define LOG_MORE_2(buf, bp) 257 # endif 258 259 # define LOG_MORE(buf, bp) \ 260 p = macvalue(macid("{verify}"), e); \ 261 if (SM_IS_EMPTY(p)) \ 262 p = "NONE"; \ 263 (void) sm_snprintf(bp, SPACELEFT(buf, bp), ", tls_verify=%.20s", p); \ 264 bp += strlen(bp); \ 265 LOG_MORE_2(buf, bp) 266 267 #else 268 # define LOG_MORE(buf, bp) 269 #endif /* STARTTLS */ 270 271 #if SASL 272 /* include the sasl include files if we have them */ 273 # if SASL == 2 || SASL >= 20000 274 # include <sasl/sasl.h> 275 # include <sasl/saslplug.h> 276 # include <sasl/saslutil.h> 277 # if SASL_VERSION_FULL < 0x020119 278 typedef int (*sasl_callback_ft)(void); 279 # endif 280 # else /* SASL == 2 || SASL >= 20000 */ 281 # include <sasl.h> 282 # include <saslutil.h> 283 typedef int (*sasl_callback_ft)(void); 284 # endif /* SASL == 2 || SASL >= 20000 */ 285 # if defined(SASL_VERSION_MAJOR) && defined(SASL_VERSION_MINOR) && defined(SASL_VERSION_STEP) 286 # define SASL_VERSION (SASL_VERSION_MAJOR * 10000) + (SASL_VERSION_MINOR * 100) + SASL_VERSION_STEP 287 # if SASL == 1 || SASL == 2 288 # undef SASL 289 # define SASL SASL_VERSION 290 # else /* SASL == 1 || SASL == 2 */ 291 # if SASL != SASL_VERSION 292 # error "README: -DSASL (SASL) does not agree with the version of the CYRUS_SASL library (SASL_VERSION)" 293 # error "README: see README!" 294 # endif /* SASL != SASL_VERSION */ 295 # endif /* SASL == 1 || SASL == 2 */ 296 # else /* defined(SASL_VERSION_MAJOR) && defined(SASL_VERSION_MINOR) && defined(SASL_VERSION_STEP) */ 297 # if SASL == 1 298 # error "README: please set -DSASL to the version of the CYRUS_SASL library" 299 # error "README: see README!" 300 # endif /* SASL == 1 */ 301 # endif /* defined(SASL_VERSION_MAJOR) && defined(SASL_VERSION_MINOR) && defined(SASL_VERSION_STEP) */ 302 #endif /* SASL */ 303 304 /* 305 ** Following are "sort of" configuration constants, but they should 306 ** be pretty solid on most architectures today. They have to be 307 ** defined after <arpa/nameser.h> because some versions of that 308 ** file also define them. In all cases, we can't use sizeof because 309 ** some systems (e.g., Crays) always treat everything as being at 310 ** least 64 bits. 311 */ 312 313 #ifndef INADDRSZ 314 # define INADDRSZ 4 /* size of an IPv4 address in bytes */ 315 #endif 316 #ifndef IN6ADDRSZ 317 # define IN6ADDRSZ 16 /* size of an IPv6 address in bytes */ 318 #endif 319 #ifndef INT16SZ 320 # define INT16SZ 2 /* size of a 16 bit integer in bytes */ 321 #endif 322 #ifndef INT32SZ 323 # define INT32SZ 4 /* size of a 32 bit integer in bytes */ 324 #endif 325 #ifndef INADDR_LOOPBACK 326 # define INADDR_LOOPBACK 0x7f000001 /* loopback address */ 327 #endif 328 329 /* 330 ** Error return from inet_addr(3), in case not defined in /usr/include. 331 */ 332 333 #ifndef INADDR_NONE 334 # define INADDR_NONE 0xffffffff 335 #endif 336 337 /* By default use uncompressed IPv6 address format (no "::") */ 338 #ifndef IPV6_FULL 339 # define IPV6_FULL 1 340 #endif 341 342 /* (f)open() modes for queue files */ 343 #define QF_O_EXTRA 0 344 345 #define SM_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) 346 347 /* 348 ** An 'argument class' describes the storage allocation status 349 ** of an object pointed to by an argument to a function. 350 */ 351 352 typedef enum 353 { 354 A_HEAP, /* the storage was allocated by malloc, and the 355 * ownership of the storage is ceded by the caller 356 * to the called function. */ 357 A_TEMP, /* The storage is temporary, and is only guaranteed 358 * to be valid for the duration of the function call. */ 359 A_PERM /* The storage is 'permanent': this might mean static 360 * storage, or rpool storage. */ 361 } ARGCLASS_T; 362 363 /* forward references for prototypes */ 364 typedef struct envelope ENVELOPE; 365 typedef struct mailer MAILER; 366 typedef struct queuegrp QUEUEGRP; 367 368 /* 369 ** Address structure. 370 ** Addresses are stored internally in this structure. 371 */ 372 373 struct address 374 { 375 char *q_paddr; /* the printname for the address */ 376 char *q_user; /* user name */ 377 char *q_ruser; /* real user name, or NULL if q_user */ 378 char *q_host; /* host name [x] */ 379 #if DANE 380 char *q_qname; /* original query (host) name */ 381 #endif 382 struct mailer *q_mailer; /* mailer to use */ 383 unsigned long q_flags; /* status flags, see below */ 384 uid_t q_uid; /* user-id of receiver (if known) */ 385 gid_t q_gid; /* group-id of receiver (if known) */ 386 char *q_home; /* home dir (local mailer only) */ 387 char *q_fullname; /* full name if known */ 388 struct address *q_next; /* chain */ 389 struct address *q_alias; /* address this results from */ 390 char *q_owner; /* owner of q_alias */ 391 struct address *q_tchain; /* temporary use chain */ 392 #if PIPELINING 393 struct address *q_pchain; /* chain for pipelining */ 394 #endif 395 char *q_finalrcpt; /* Final-Recipient: DSN header */ 396 char *q_orcpt; /* ORCPT parameter from RCPT TO: line */ 397 char *q_status; /* status code for DSNs */ 398 char *q_rstatus; /* remote status message for DSNs */ 399 time_t q_statdate; /* date of status messages */ 400 char *q_statmta; /* MTA generating q_rstatus */ 401 short q_state; /* address state, see below */ 402 char *q_signature; /* MX-based sorting value */ 403 int q_qgrp; /* index into queue groups */ 404 char *q_message; /* error message */ 405 }; 406 407 typedef struct address ADDRESS; 408 409 410 /* 411 ** Note: only some of the flags are saved in the queue; 412 ** the code in queue.c does not use the actual value but maps each flag 413 ** to/from an associated character. 414 ** If the values would not change then those could be stored/retrieved 415 ** directly (applying a mask to select those flags which should be kep) -- 416 ** the mapping to/from characters provides a "defined" external interface 417 ** provided those mappings are kept (and if an old mapping is removed then 418 ** it should be kept as comment so it is not reused "too soon"). 419 */ 420 421 /* bit values for q_flags */ 422 #define QGOODUID 0x00000001 /* the q_uid q_gid fields are good */ 423 #define QPRIMARY 0x00000002 /* set from RCPT or argv */ 424 #define QNOTREMOTE 0x00000004 /* address not for remote forwarding */ 425 #define QSELFREF 0x00000008 /* this address references itself */ 426 #define QBOGUSSHELL 0x00000010 /* user has no valid shell listed */ 427 #define QUNSAFEADDR 0x00000020 /* address acquired via unsafe path */ 428 #define QPINGONSUCCESS 0x00000040 /* give return on successful delivery */ 429 #define QPINGONFAILURE 0x00000080 /* give return on failure */ 430 #define QPINGONDELAY 0x00000100 /* give return on message delay */ 431 #define QHASNOTIFY 0x00000200 /* propagate notify parameter */ 432 #define QRELAYED 0x00000400 /* DSN: relayed to non-DSN aware sys */ 433 #define QEXPANDED 0x00000800 /* DSN: undergone list expansion */ 434 #define QDELIVERED 0x00001000 /* DSN: successful final delivery */ 435 #define QDELAYED 0x00002000 /* DSN: message delayed */ 436 #define QALIAS 0x00004000 /* expanded alias */ 437 #define QBYTRACE 0x00008000 /* DeliverBy: trace */ 438 #define QBYNDELAY 0x00010000 /* DeliverBy: notify, delay */ 439 #define QBYNRELAY 0x00020000 /* DeliverBy: notify, relayed */ 440 #define QINTBCC 0x00040000 /* internal Bcc */ 441 #define QDYNMAILER 0x00080000 /* "dynamic mailer" */ 442 #define QSECURE 0x00100000 /* DNSSEC ok for host lookup */ 443 #define QQUEUED 0x00200000 /* queued */ 444 #define QINTREPLY 0x00400000 /* internally rejected (delivery) */ 445 #define QMXSECURE 0x00800000 /* DNSSEC ok for MX lookup */ 446 #define QTHISPASS 0x40000000 /* temp: address set this pass */ 447 #define QRCPTOK 0x80000000 /* recipient() processed address */ 448 449 #define QDYNMAILFLG 'Y' 450 451 #define Q_PINGFLAGS (QPINGONSUCCESS|QPINGONFAILURE|QPINGONDELAY) 452 453 #define QISSECURE(r) (0 != ((r)->q_flags & QSECURE)) 454 455 #if _FFR_RCPTFLAGS 456 # define QMATCHFLAGS (QINTBCC|QDYNMAILER) 457 # define QMATCH_FLAG(a) ((a)->q_flags & QMATCHFLAGS) 458 # define ADDR_FLAGS_MATCH(a, b) (QMATCH_FLAG(a) == QMATCH_FLAG(b)) 459 #else 460 # define ADDR_FLAGS_MATCH(a, b) true 461 #endif 462 463 /* values for q_state */ 464 #define QS_OK 0 /* address ok (for now)/not yet tried */ 465 #define QS_SENT 1 /* good address, delivery complete */ 466 #define QS_BADADDR 2 /* illegal address */ 467 #define QS_QUEUEUP 3 /* save address in queue */ 468 #define QS_RETRY 4 /* retry delivery for next MX */ 469 #define QS_VERIFIED 5 /* verified, but not expanded */ 470 471 /* 472 ** Notice: all of the following values are variations of QS_DONTSEND. 473 ** If new states are added, they must be inserted in the proper place! 474 ** See the macro definition of QS_IS_DEAD() down below. 475 */ 476 477 #define QS_DONTSEND 6 /* don't send to this address */ 478 #define QS_EXPANDED 7 /* expanded */ 479 #define QS_SENDER 8 /* message sender (MeToo) */ 480 #define QS_CLONED 9 /* addr cloned to split envelope */ 481 #define QS_DISCARDED 10 /* rcpt discarded (EF_DISCARD) */ 482 #define QS_REPLACED 11 /* maplocaluser()/UserDB replaced */ 483 #define QS_REMOVED 12 /* removed (removefromlist()) */ 484 #define QS_DUPLICATE 13 /* duplicate suppressed */ 485 #define QS_INCLUDED 14 /* :include: delivery */ 486 #define QS_FATALERR 15 /* fatal error, don't deliver */ 487 488 /* address state testing primitives */ 489 #define QS_IS_OK(s) ((s) == QS_OK) 490 #define QS_IS_SENT(s) ((s) == QS_SENT) 491 #define QS_IS_BADADDR(s) ((s) == QS_BADADDR) 492 #define QS_IS_QUEUEUP(s) ((s) == QS_QUEUEUP) 493 #define QS_IS_RETRY(s) ((s) == QS_RETRY) 494 #define QS_IS_VERIFIED(s) ((s) == QS_VERIFIED) 495 #define QS_IS_EXPANDED(s) ((s) == QS_EXPANDED) 496 #define QS_IS_REMOVED(s) ((s) == QS_REMOVED) 497 #define QS_IS_UNDELIVERED(s) ((s) == QS_OK || \ 498 (s) == QS_QUEUEUP || \ 499 (s) == QS_RETRY || \ 500 (s) == QS_VERIFIED) 501 #define QS_IS_UNMARKED(s) ((s) == QS_OK || \ 502 (s) == QS_RETRY) 503 #define QS_IS_SENDABLE(s) ((s) == QS_OK || \ 504 (s) == QS_QUEUEUP || \ 505 (s) == QS_RETRY) 506 #define QS_IS_ATTEMPTED(s) ((s) == QS_QUEUEUP || \ 507 (s) == QS_RETRY || \ 508 (s) == QS_SENT || \ 509 (s) == QS_DISCARDED) 510 #define QS_IS_DEAD(s) ((s) >= QS_DONTSEND) 511 #define QS_IS_TEMPFAIL(s) ((s) == QS_QUEUEUP || (s) == QS_RETRY) 512 513 #define QUP_FL_NONE 0x0000 514 #define QUP_FL_ANNOUNCE 0x0001 515 #define QUP_FL_MSYNC 0x0002 516 #define QUP_FL_UNLOCK 0x0004 517 518 #define NULLADDR ((ADDRESS *) NULL) 519 520 extern ADDRESS NullAddress; /* a null (template) address [main.c] */ 521 522 /* for cataddr() */ 523 #define NOSPACESEP 256 524 525 /* functions */ 526 extern void cataddr __P((char **, char **, char *, int, int, bool)); 527 extern char *crackaddr __P((char *, ENVELOPE *)); 528 extern bool emptyaddr __P((ADDRESS *)); 529 extern ADDRESS *getctladdr __P((ADDRESS *)); 530 extern int include __P((char *, bool, ADDRESS *, ADDRESS **, int, ENVELOPE *)); 531 extern bool invalidaddr __P((char *, char *, bool)); 532 extern ADDRESS *parseaddr __P((char *, ADDRESS *, int, int, char **, 533 ENVELOPE *, bool)); 534 extern char **prescan __P((char *, int, char[], int, char **, unsigned char *, bool)); 535 extern void printaddr __P((SM_FILE_T *, ADDRESS *, bool)); 536 extern ADDRESS *recipient __P((ADDRESS *, ADDRESS **, int, ENVELOPE *)); 537 extern char *remotename __P((char *, MAILER *, int, int *, ENVELOPE *)); 538 extern int rewrite __P((char **, int, int, ENVELOPE *, int)); 539 extern bool sameaddr __P((ADDRESS *, ADDRESS *)); 540 extern int sendtolist __P((char *, ADDRESS *, ADDRESS **, int, ENVELOPE *)); 541 #if MILTER 542 extern int removefromlist __P((char *, ADDRESS **, ENVELOPE *)); 543 #endif 544 extern void setsender __P((char *, ENVELOPE *, char **, int, bool)); 545 typedef void esmtp_args_F __P((ADDRESS *, char *, char *, ENVELOPE *)); 546 extern void parse_esmtp_args __P((ENVELOPE *, ADDRESS *, char *, char *, 547 char *, char *args[], esmtp_args_F)); 548 extern esmtp_args_F mail_esmtp_args; 549 extern esmtp_args_F rcpt_esmtp_args; 550 extern void reset_mail_esmtp_args __P((ENVELOPE *)); 551 552 /* macro to simplify the common call to rewrite() */ 553 #define REWRITE(pvp, rs, env) rewrite(pvp, rs, 0, env, MAXATOM) 554 555 /* 556 ** Token Tables for prescan 557 */ 558 559 extern unsigned char ExtTokenTab[256]; /* external strings */ 560 extern unsigned char IntTokenTab[256]; /* internal strings */ 561 562 563 /* 564 ** Mailer definition structure. 565 ** Every mailer known to the system is declared in this 566 ** structure. It defines the pathname of the mailer, some 567 ** flags associated with it, and the argument vector to 568 ** pass to it. The flags are defined in conf.c 569 ** 570 ** The argument vector is expanded before actual use. All 571 ** words except the first are passed through the macro 572 ** processor. 573 */ 574 575 struct mailer 576 { 577 char *m_name; /* symbolic name of this mailer */ 578 char *m_mailer; /* pathname of the mailer to use */ 579 char *m_mtatype; /* type of this MTA */ 580 char *m_addrtype; /* type for addresses */ 581 char *m_diagtype; /* type for diagnostics */ 582 BITMAP256 m_flags; /* status flags, see below */ 583 short m_mno; /* mailer number internally */ 584 short m_nice; /* niceness to run at (mostly for prog) */ 585 char **m_argv; /* template argument vector */ 586 short m_sh_rwset; /* rewrite set: sender header addresses */ 587 short m_se_rwset; /* rewrite set: sender envelope addresses */ 588 short m_rh_rwset; /* rewrite set: recipient header addresses */ 589 short m_re_rwset; /* rewrite set: recipient envelope addresses */ 590 char *m_eol; /* end of line string */ 591 long m_maxsize; /* size limit on message to this mailer */ 592 int m_linelimit; /* max # characters per line */ 593 int m_maxdeliveries; /* max deliveries per mailer connection */ 594 char *m_execdir; /* directory to chdir to before execv */ 595 char *m_rootdir; /* directory to chroot to before execv */ 596 uid_t m_uid; /* UID to run as */ 597 gid_t m_gid; /* GID to run as */ 598 char *m_defcharset; /* default character set */ 599 time_t m_wait; /* timeout to wait for end */ 600 int m_maxrcpt; /* max recipients per envelope client-side */ 601 short m_qgrp; /* queue group for this mailer */ 602 #if DANE 603 unsigned short m_port; /* port (if appropriate for mailer) */ 604 #endif 605 }; 606 607 /* bits for m_flags */ 608 #define M_xSMTP 0x01 /* internal: {ES,S,L}MTP */ 609 #define M_ESMTP 'a' /* run Extended SMTP */ 610 #define M_ALIASABLE 'A' /* user can be LHS of an alias */ 611 #define M_BLANKEND 'b' /* ensure blank line at end of message */ 612 #define M_STRIPBACKSL 'B' /* strip all leading backslashes from user */ 613 #define M_NOCOMMENT 'c' /* don't include comment part of address */ 614 #define M_CANONICAL 'C' /* make addresses canonical "u@dom" */ 615 #define M_NOBRACKET 'd' /* never angle bracket envelope route-addrs */ 616 /* 'D' CF: include Date: */ 617 #define M_EXPENSIVE 'e' /* it costs to use this mailer.... */ 618 #define M_ESCFROM 'E' /* escape From lines to >From */ 619 #define M_FOPT 'f' /* mailer takes picky -f flag */ 620 /* 'F' CF: include From: or Resent-From: */ 621 #define M_NO_NULL_FROM 'g' /* sender of errors should be $g */ 622 #define M_HST_UPPER 'h' /* preserve host case distinction */ 623 #define M_PREHEAD 'H' /* MAIL11V3: preview headers */ 624 #define M_UDBENVELOPE 'i' /* do udbsender rewriting on envelope */ 625 #define M_INTERNAL 'I' /* SMTP to another sendmail site */ 626 #define M_UDBRECIPIENT 'j' /* do udbsender rewriting on recipient lines */ 627 #define M_NOLOOPCHECK 'k' /* don't check for loops in HELO command */ 628 #define M_CHUNKING 'K' /* CHUNKING: reserved for future use */ 629 #define M_LOCALMAILER 'l' /* delivery is to this host */ 630 #define M_LIMITS 'L' /* must enforce SMTP line limits */ 631 #define M_MUSER 'm' /* can handle multiple users at once */ 632 /* 'M' CF: include Message-Id: */ 633 #define M_NHDR 'n' /* don't insert From line */ 634 #define M_MANYSTATUS 'N' /* MAIL11V3: DATA returns multi-status */ 635 #define M_RUNASRCPT 'o' /* always run mailer as recipient */ 636 /* 'O' free? */ 637 #define M_FROMPATH 'p' /* use reverse-path in MAIL FROM: */ 638 /* 'P' CF: include Return-Path: */ 639 #define M_VRFY250 'q' /* VRFY command returns 250 instead of 252 */ 640 #define M_ROPT 'r' /* mailer takes picky -r flag */ 641 #define M_SECURE_PORT 'R' /* try to send on a reserved TCP port */ 642 #define M_STRIPQ 's' /* strip quote chars from user/host */ 643 #define M_SPECIFIC_UID 'S' /* run as specific uid/gid */ 644 #define M_USR_UPPER 'u' /* preserve user case distinction */ 645 #define M_UGLYUUCP 'U' /* this wants an ugly UUCP from line */ 646 #define M_CONTENT_LEN 'v' /* add Content-Length: header (SVr4) */ 647 /* 'V' UIUC: !-relativize all addresses */ 648 #define M_HASPWENT 'w' /* check for /etc/passwd entry */ 649 #define M_NOHOSTSTAT 'W' /* ignore long term host status information */ 650 /* 'x' CF: include Full-Name: */ 651 #define M_XDOT 'X' /* use hidden-dot algorithm */ 652 /* 'y' free? */ 653 /* 'Y' free? */ 654 #define M_LMTP 'z' /* run Local Mail Transport Protocol */ 655 #define M_DIALDELAY 'Z' /* apply dial delay sleeptime */ 656 #define M_NOMX '0' /* turn off MX lookups */ 657 #define M_NONULLS '1' /* don't send null bytes */ 658 #define M_FSMTP '2' /* force SMTP (no ESMTP even if offered) */ 659 #define M_EBCDIC '3' /* extend Q-P encoding for EBCDIC */ 660 #define M_ONLY_IPV4 '4' /* Use only IPv4 */ 661 #define M_TRYRULESET5 '5' /* use ruleset 5 after local aliasing */ 662 #define M_7BITHDRS '6' /* strip headers to 7 bits even in 8 bit path */ 663 #define M_7BITS '7' /* use 7-bit path */ 664 #define M_8BITS '8' /* force "just send 8" behaviour */ 665 #define M_MAKE8BIT '9' /* convert 7 -> 8 bit if appropriate */ 666 #define M_CHECKINCLUDE ':' /* check for :include: files */ 667 #define M_CHECKPROG '|' /* check for |program addresses */ 668 #define M_CHECKFILE '/' /* check for /file addresses */ 669 #define M_CHECKUDB '@' /* user can be user database key */ 670 #define M_CHECKHDIR '~' /* SGI: check for valid home directory */ 671 #define M_HOLD '%' /* Hold delivery until ETRN/-qI/-qR/-qS */ 672 #define M_PLUS '+' /* Reserved: Used in mc for adding new flags */ 673 #define M_MINUS '-' /* Reserved: Used in mc for removing flags */ 674 #define M_NOMHHACK '!' /* Don't perform HM hack dropping explicit from */ 675 #if _FFR_SMTPS_CLIENT 676 # define M_SMTPS_CLIENT '_' /* use SMTP over TLS (465/TCP) */ 677 #endif 678 679 /* functions */ 680 extern void initerrmailers __P((void)); 681 extern void makemailer __P((char *)); 682 extern void makequeue __P((char *, bool)); 683 extern void runqueueevent __P((int)); 684 #if _FFR_QUEUE_RUN_PARANOIA 685 extern bool checkqueuerunner __P((void)); 686 #endif 687 688 EXTERN MAILER *FileMailer; /* ptr to *file* mailer */ 689 EXTERN MAILER *InclMailer; /* ptr to *include* mailer */ 690 EXTERN MAILER *LocalMailer; /* ptr to local mailer */ 691 EXTERN MAILER *ProgMailer; /* ptr to program mailer */ 692 #if _FFR_RCPTFLAGS 693 EXTERN MAILER *Mailer[MAXMAILERS * 2 + 1]; 694 #else 695 EXTERN MAILER *Mailer[MAXMAILERS + 1]; 696 #endif 697 698 /* 699 ** Queue group definition structure. 700 ** Every queue group known to the system is declared in this structure. 701 ** It defines the basic pathname of the queue group, some flags 702 ** associated with it, and the argument vector to pass to it. 703 */ 704 705 struct qpaths_s 706 { 707 char *qp_name; /* name of queue dir, relative path */ 708 short qp_subdirs; /* use subdirs? */ 709 short qp_fsysidx; /* file system index of this directory */ 710 #if SM_CONF_SHM 711 int qp_idx; /* index into array for queue information */ 712 #endif 713 }; 714 715 typedef struct qpaths_s QPATHS; 716 717 struct queuegrp 718 { 719 char *qg_name; /* symbolic name of this queue group */ 720 721 /* 722 ** For now this is the same across all queue groups. 723 ** Otherwise we have to play around with chdir(). 724 */ 725 726 char *qg_qdir; /* common component of queue directory */ 727 short qg_index; /* queue number internally, index in Queue[] */ 728 int qg_maxqrun; /* max # of jobs in one queuerun */ 729 int qg_numqueues; /* number of queues in this queue group */ 730 731 /* 732 ** qg_queueintvl == 0 denotes that no individual value is used. 733 ** Whatever accesses this must deal with "<= 0" as 734 ** "not set, use appropriate default". 735 */ 736 737 time_t qg_queueintvl; /* interval for queue runs */ 738 QPATHS *qg_qpaths; /* list of queue directories */ 739 BITMAP256 qg_flags; /* status flags, see below */ 740 short qg_nice; /* niceness for queue run */ 741 int qg_wgrp; /* Assigned to this work group */ 742 int qg_maxlist; /* max items in work queue for this group */ 743 int qg_curnum; /* current number of queue for queue runs */ 744 int qg_maxrcpt; /* max recipients per envelope, 0==no limit */ 745 746 time_t qg_nextrun; /* time for next queue runs */ 747 #if _FFR_QUEUE_GROUP_SORTORDER 748 short qg_sortorder; /* how do we sort this queuerun */ 749 #endif 750 #if 0 751 long qg_wkrcptfact; /* multiplier for # recipients -> priority */ 752 long qg_qfactor; /* slope of queue function */ 753 bool qg_doqueuerun; /* XXX flag is it time to do a queuerun */ 754 #endif /* 0 */ 755 }; 756 757 /* bits for qg_flags */ 758 #define QD_DEFINED ((char) 1) /* queue group has been defined */ 759 #define QD_FORK 'f' /* fork queue runs */ 760 761 extern void filesys_update __P((void)); 762 #if _FFR_ANY_FREE_FS 763 extern bool filesys_free __P((long)); 764 #endif 765 766 #if SASL 767 /* 768 ** SASL 769 */ 770 771 /* lines in authinfo file or index into SASL_AI_T */ 772 # define SASL_WRONG (-1) 773 # define SASL_USER 0 /* authorization id (user) */ 774 # define SASL_AUTHID 1 /* authentication id */ 775 # define SASL_PASSWORD 2 /* password fuer authid */ 776 # define SASL_DEFREALM 3 /* realm to use */ 777 # define SASL_MECHLIST 4 /* list of mechanisms to try */ 778 # define SASL_ID_REALM 5 /* authid@defrealm */ 779 780 /* 781 ** Current mechanism; this is just used to convey information between 782 ** invocation of SASL callback functions. 783 ** It must be last in the list, because it's not allocated by us 784 ** and hence we don't free() it. 785 */ 786 # define SASL_MECH 6 787 # define SASL_ENTRIES 7 /* number of entries in array */ 788 789 # define SASL_USER_BIT (1 << SASL_USER) 790 # define SASL_AUTHID_BIT (1 << SASL_AUTHID) 791 # define SASL_PASSWORD_BIT (1 << SASL_PASSWORD) 792 # define SASL_DEFREALM_BIT (1 << SASL_DEFREALM) 793 # define SASL_MECHLIST_BIT (1 << SASL_MECHLIST) 794 795 /* authenticated? */ 796 # define SASL_NOT_AUTH 0 /* not authenticated */ 797 # define SASL_PROC_AUTH 1 /* in process of authenticating */ 798 # define SASL_IS_AUTH 2 /* authenticated */ 799 800 /* SASL options */ 801 # define SASL_AUTH_AUTH 0x10000 /* use auth= only if authenticated */ 802 # if SASL >= 20101 803 # define SASL_SEC_MASK SASL_SEC_MAXIMUM /* mask for SASL_SEC_* values: sasl.h */ 804 # else /* SASL >= 20101 */ 805 # define SASL_SEC_MASK 0x0fff /* mask for SASL_SEC_* values: sasl.h */ 806 # if (SASL_SEC_NOPLAINTEXT & SASL_SEC_MASK) == 0 || \ 807 (SASL_SEC_NOACTIVE & SASL_SEC_MASK) == 0 || \ 808 (SASL_SEC_NODICTIONARY & SASL_SEC_MASK) == 0 || \ 809 (SASL_SEC_FORWARD_SECRECY & SASL_SEC_MASK) == 0 || \ 810 (SASL_SEC_NOANONYMOUS & SASL_SEC_MASK) == 0 || \ 811 (SASL_SEC_PASS_CREDENTIALS & SASL_SEC_MASK) == 0 812 # error "change SASL_SEC_MASK notify sendmail.org!" 813 # endif /* SASL_SEC_NOPLAINTEXT & SASL_SEC_MASK) == 0 ... */ 814 # endif /* SASL >= 20101 */ 815 # define MAXOUTLEN 8192 /* length of output buffer, should be 2^n */ 816 # if (SASL_AUTH_AUTH & SASL_SEC_MASK) != 0 817 # error "change SASL_AUTH_AUTH notify sendmail.org!" 818 # endif 819 820 /* functions */ 821 extern char *intersect __P((char *, char *, SM_RPOOL_T *)); 822 extern char *iteminlist __P((char *, char *, char *)); 823 # if SASL >= 20000 824 extern int proxy_policy __P((sasl_conn_t *, void *, const char *, unsigned, const char *, unsigned, const char *, unsigned, struct propctx *)); 825 extern int safesaslfile __P((void *, const char *, sasl_verify_type_t)); 826 # else /* SASL >= 20000 */ 827 extern int proxy_policy __P((void *, const char *, const char *, const char **, const char **)); 828 # if SASL > 10515 829 extern int safesaslfile __P((void *, char *, int)); 830 # else /* SASL > 10515 */ 831 extern int safesaslfile __P((void *, char *)); 832 # endif /* SASL > 10515 */ 833 # endif /* SASL >= 20000 */ 834 extern void stop_sasl_client __P((void)); 835 836 /* structure to store authinfo */ 837 typedef char *SASL_AI_T[SASL_ENTRIES]; 838 839 EXTERN char *AuthMechanisms; /* AUTH mechanisms */ 840 EXTERN char *AuthRealm; /* AUTH realm */ 841 EXTERN char *SASLInfo; /* file with AUTH info */ 842 EXTERN int SASLOpts; /* options for SASL */ 843 EXTERN int MaxSLBits; /* max. encryption bits for SASL */ 844 #endif /* SASL */ 845 846 /* 847 ** Structure to store macros. 848 */ 849 typedef struct 850 { 851 SM_RPOOL_T *mac_rpool; /* resource pool */ 852 BITMAP256 mac_allocated; /* storage has been alloc()? */ 853 char *mac_table[MAXMACROID + 1]; /* macros */ 854 } MACROS_T; 855 856 EXTERN MACROS_T GlobalMacros; 857 858 /* 859 ** Information about currently open connections to mailers, or to 860 ** hosts that we have looked up recently. 861 */ 862 863 #define MCI struct mailer_con_info 864 865 MCI 866 { 867 unsigned long mci_flags; /* flag bits, see below */ 868 short mci_errno; /* error number on last connection */ 869 short mci_herrno; /* h_errno from last DNS lookup */ 870 short mci_exitstat; /* exit status from last connection */ 871 short mci_state; /* SMTP state */ 872 int mci_deliveries; /* delivery attempts for connection */ 873 long mci_maxsize; /* max size this server will accept */ 874 SM_FILE_T *mci_in; /* input side of connection */ 875 SM_FILE_T *mci_out; /* output side of connection */ 876 pid_t mci_pid; /* process id of subordinate proc */ 877 char *mci_phase; /* SMTP phase string */ 878 struct mailer *mci_mailer; /* ptr to the mailer for this conn */ 879 char *mci_host; /* host name */ 880 char *mci_status; /* DSN status to be copied to addrs */ 881 char *mci_rstatus; /* SMTP status to be copied to addrs */ 882 time_t mci_lastuse; /* last usage time */ 883 SM_FILE_T *mci_statfile; /* long term status file */ 884 char *mci_heloname; /* name to use as HELO arg */ 885 long mci_min_by; /* minimum DELIVERBY */ 886 bool mci_retryrcpt; /* tempfail for at least one rcpt */ 887 char *mci_tolist; /* list of valid recipients */ 888 SM_RPOOL_T *mci_rpool; /* resource pool */ 889 int mci_okrcpts; /* number of valid recipients */ 890 #if PIPELINING 891 ADDRESS *mci_nextaddr; /* next address for pipelined status */ 892 #endif 893 #if SASL 894 SASL_AI_T mci_sai; /* authentication info */ 895 bool mci_sasl_auth; /* authenticated? */ 896 int mci_sasl_string_len; 897 char *mci_sasl_string; /* sasl reply string */ 898 char *mci_saslcap; /* SASL list of mechanisms */ 899 sasl_conn_t *mci_conn; /* SASL connection */ 900 #endif /* SASL */ 901 #if STARTTLS 902 SSL *mci_ssl; /* SSL connection */ 903 tlsi_ctx_T mci_tlsi; 904 #endif 905 MACROS_T mci_macro; /* macro definitions */ 906 }; 907 908 909 /* MCI flag bits */ 910 /* XREF: mci.c: MciFlags[]: needs to be kept in sync! */ 911 /* 0x00000001 unused, was MCIF_VALID: this entry is valid */ 912 #define MCIF_OCC_INCR 0x00000002 /* occ values increased */ 913 #define MCIF_CACHED 0x00000004 /* currently in open cache */ 914 #define MCIF_ESMTP 0x00000008 /* this host speaks ESMTP */ 915 #define MCIF_EXPN 0x00000010 /* EXPN command supported */ 916 #define MCIF_SIZE 0x00000020 /* SIZE option supported */ 917 #define MCIF_8BITMIME 0x00000040 /* BODY=8BITMIME supported */ 918 #define MCIF_7BIT 0x00000080 /* strip this message to 7 bits */ 919 /* 0x00000100 unused, was MCIF_MULTSTAT: MAIL11V3: handles MULT status */ 920 #define MCIF_INHEADER 0x00000200 /* currently outputting header */ 921 #define MCIF_CVT8TO7 0x00000400 /* convert from 8 to 7 bits */ 922 #define MCIF_DSN 0x00000800 /* DSN extension supported */ 923 #define MCIF_8BITOK 0x00001000 /* OK to send 8 bit characters */ 924 #define MCIF_CVT7TO8 0x00002000 /* convert from 7 to 8 bits */ 925 #define MCIF_INMIME 0x00004000 /* currently reading MIME header */ 926 #define MCIF_AUTH 0x00008000 /* AUTH= supported */ 927 #define MCIF_AUTHACT 0x00010000 /* SASL (AUTH) active */ 928 #define MCIF_ENHSTAT 0x00020000 /* ENHANCEDSTATUSCODES supported */ 929 #define MCIF_PIPELINED 0x00040000 /* PIPELINING supported */ 930 #define MCIF_VERB 0x00080000 /* VERB supported */ 931 #if STARTTLS 932 #define MCIF_TLS 0x00100000 /* STARTTLS supported */ 933 #define MCIF_TLSACT 0x00200000 /* STARTTLS active */ 934 #else /* STARTTLS */ 935 #define MCIF_TLS 0 936 #define MCIF_TLSACT 0 937 #endif /* STARTTLS */ 938 #define MCIF_DLVR_BY 0x00400000 /* DELIVERBY */ 939 #if _FFR_IGNORE_EXT_ON_HELO 940 # define MCIF_HELO 0x00800000 /* we used HELO: ignore extensions */ 941 #endif 942 #define MCIF_INLONGLINE 0x01000000 /* in the middle of a long line */ 943 #define MCIF_AUTH2 0x02000000 /* got 2 AUTH lines */ 944 #define MCIF_ONLY_EHLO 0x10000000 /* use only EHLO in smtpinit */ 945 #if _FFR_HANDLE_HDR_RW_TEMPFAIL 946 /* an error is not sticky (if put{header,body}() etc fail) */ 947 # define MCIF_NOTSTICKY 0x20000000 948 #else 949 # define MCIF_NOTSTICKY 0 950 #endif 951 #if USE_EAI 952 # define MCIF_EAI 0x40000000 /* SMTPUTF8 supported */ 953 #else 954 # define MCIF_EAI 0x00000000 /* for MCIF_EXTENS */ 955 #endif 956 957 #define MCIF_EXTENS (MCIF_EXPN|MCIF_SIZE|MCIF_8BITMIME|MCIF_DSN|MCIF_8BITOK|MCIF_AUTH|MCIF_ENHSTAT|MCIF_PIPELINED|MCIF_VERB|MCIF_TLS|MCIF_DLVR_BY|MCIF_AUTH2|MCIF_EAI) 958 959 /* states */ 960 /* XREF: deliver.c: mcis[] -- any changes here must be reflected there! */ 961 #define MCIS_CLOSED 0 /* no traffic on this connection */ 962 #define MCIS_OPENING 1 /* sending initial protocol */ 963 #define MCIS_OPEN 2 /* open, initial protocol sent */ 964 #define MCIS_MAIL 3 /* MAIL command sent */ 965 #define MCIS_RCPT 4 /* RCPT commands being sent */ 966 #define MCIS_DATA 5 /* DATA command sent */ 967 #define MCIS_QUITING 6 /* running quit protocol */ 968 #define MCIS_SSD 7 /* service shutting down */ 969 #define MCIS_ERROR 8 /* I/O error on connection */ 970 971 /* functions */ 972 extern void mci_cache __P((MCI *)); 973 extern void mci_close __P((MCI *, char *where)); 974 extern void mci_dump __P((SM_FILE_T *, MCI *, bool)); 975 extern void mci_dump_all __P((SM_FILE_T *, bool)); 976 extern void mci_flush __P((bool, MCI *)); 977 extern void mci_clr_extensions __P((MCI *)); 978 extern MCI *mci_get __P((char *, MAILER *)); 979 extern int mci_lock_host __P((MCI *)); 980 extern bool mci_match __P((char *, MAILER *)); 981 extern int mci_print_persistent __P((char *, char *)); 982 extern int mci_purge_persistent __P((char *, char *)); 983 extern MCI **mci_scan __P((MCI *)); 984 extern void mci_setstat __P((MCI *, int, char *, char *)); 985 extern void mci_store_persistent __P((MCI *)); 986 extern int mci_traverse_persistent __P((int (*)(char *, char *), char *)); 987 extern void mci_unlock_host __P((MCI *)); 988 989 EXTERN int MaxMciCache; /* maximum entries in MCI cache */ 990 EXTERN time_t MciCacheTimeout; /* maximum idle time on connections */ 991 EXTERN time_t MciInfoTimeout; /* how long 'til we retry down hosts */ 992 993 /* 994 ** Header structure. 995 ** This structure is used internally to store header items. 996 */ 997 998 struct header 999 { 1000 char *h_field; /* the name of the field */ 1001 char *h_value; /* the value of that field */ 1002 struct header *h_link; /* the next header */ 1003 unsigned char h_macro; /* include header if macro defined */ 1004 unsigned long h_flags; /* status bits, see below */ 1005 BITMAP256 h_mflags; /* m_flags bits needed */ 1006 }; 1007 1008 typedef struct header HDR; 1009 1010 /* 1011 ** Header information structure. 1012 ** Defined in conf.c, this struct declares the header fields 1013 ** that have some magic meaning. 1014 */ 1015 1016 struct hdrinfo 1017 { 1018 char *hi_field; /* the name of the field */ 1019 unsigned long hi_flags; /* status bits, see below */ 1020 char *hi_ruleset; /* validity check ruleset */ 1021 }; 1022 1023 extern struct hdrinfo HdrInfo[]; 1024 1025 /* bits for h_flags and hi_flags */ 1026 #define H_EOH 0x00000001 /* field terminates header */ 1027 #define H_RCPT 0x00000002 /* contains recipient addresses */ 1028 #define H_DEFAULT 0x00000004 /* if another value is found, drop this */ 1029 #define H_RESENT 0x00000008 /* this address is a "Resent-..." address */ 1030 #define H_CHECK 0x00000010 /* check h_mflags against m_flags */ 1031 #define H_ACHECK 0x00000020 /* ditto, but always (not just default) */ 1032 #define H_FORCE 0x00000040 /* force this field, even if default */ 1033 #define H_TRACE 0x00000080 /* this field contains trace information */ 1034 #define H_FROM 0x00000100 /* this is a from-type field */ 1035 #define H_VALID 0x00000200 /* this field has a validated value */ 1036 #define H_RECEIPTTO 0x00000400 /* field has return receipt info */ 1037 #define H_ERRORSTO 0x00000800 /* field has error address info */ 1038 #define H_CTE 0x00001000 /* field is a content-transfer-encoding */ 1039 #define H_CTYPE 0x00002000 /* this is a content-type field */ 1040 #define H_BCC 0x00004000 /* Bcc: header: strip value or delete */ 1041 #define H_ENCODABLE 0x00008000 /* field can be RFC 1522 encoded */ 1042 #define H_STRIPCOMM 0x00010000 /* header check: strip comments */ 1043 #define H_BINDLATE 0x00020000 /* only expand macros at deliver */ 1044 #define H_USER 0x00040000 /* header came from the user/SMTP */ 1045 #if _FFR_MTA_MODE 1046 # define H_ASIS 0x10000000 1047 #endif 1048 1049 /* bits for chompheader() */ 1050 #define CHHDR_DEF 0x0001 /* default header */ 1051 #define CHHDR_CHECK 0x0002 /* call ruleset for header */ 1052 #define CHHDR_USER 0x0004 /* header from user */ 1053 #define CHHDR_QUEUE 0x0008 /* header from queue file */ 1054 1055 /* functions */ 1056 extern void addheader __P((char *, char *, int, ENVELOPE *, bool)); 1057 extern unsigned long chompheader __P((char *, int, HDR **, ENVELOPE *)); 1058 extern bool commaize __P((HDR *, char *, bool, MCI *, ENVELOPE *, int)); 1059 extern HDR *copyheader __P((HDR *, SM_RPOOL_T *)); 1060 extern void eatheader __P((ENVELOPE *, bool, bool)); 1061 extern char *hvalue __P((char *, HDR *)); 1062 extern void insheader __P((int, char *, char *, int, ENVELOPE *, bool)); 1063 extern bool isheader __P((char *)); 1064 extern bool putfromline __P((MCI *, ENVELOPE *)); 1065 extern void setupheaders __P((void)); 1066 1067 /* 1068 ** Performance monitoring 1069 */ 1070 1071 #define TIMERS struct sm_timers 1072 1073 TIMERS 1074 { 1075 TIMER ti_overall; /* the whole process */ 1076 }; 1077 1078 #define PUSHTIMER(l, t) { if (tTd(98, l)) pushtimer(&t); } 1079 #define POPTIMER(l, t) { if (tTd(98, l)) poptimer(&t); } 1080 1081 /* 1082 ** Envelope structure. 1083 ** This structure defines the message itself. There is usually 1084 ** only one of these -- for the message that we originally read 1085 ** and which is our primary interest -- but other envelopes can 1086 ** be generated during processing. For example, error messages 1087 ** will have their own envelope. 1088 */ 1089 1090 struct envelope 1091 { 1092 HDR *e_header; /* head of header list */ 1093 long e_msgpriority; /* adjusted priority of this message */ 1094 time_t e_ctime; /* time message appeared in the queue */ 1095 char *e_to; /* (list of) target person(s) */ 1096 ADDRESS e_from; /* the person it is from */ 1097 char *e_sender; /* e_from.q_paddr w comments stripped */ 1098 char **e_fromdomain; /* the domain part of the sender */ 1099 #if USE_EAI 1100 bool e_smtputf8; /* requires SMTPUTF8? */ 1101 #endif 1102 ADDRESS *e_sendqueue; /* list of message recipients */ 1103 ADDRESS *e_errorqueue; /* the queue for error responses */ 1104 1105 /* 1106 ** Overflow detection is based on < 0, so don't change this 1107 ** to unsigned. We don't use unsigned and == ULONG_MAX because 1108 ** some libc's don't have strtoul(), see mail_esmtp_args(). 1109 */ 1110 1111 long e_msgsize; /* size of the message in bytes */ 1112 char *e_msgid; /* message id (for logging) */ 1113 unsigned long e_flags; /* flags, see below */ 1114 int e_nrcpts; /* number of recipients */ 1115 short e_class; /* msg class (priority, junk, etc.) */ 1116 short e_hopcount; /* number of times processed */ 1117 short e_nsent; /* number of sends since checkpoint */ 1118 short e_sendmode; /* message send mode */ 1119 short e_errormode; /* error return mode */ 1120 short e_timeoutclass; /* message timeout class */ 1121 bool (*e_puthdr)__P((MCI *, HDR *, ENVELOPE *, int)); 1122 /* function to put header of message */ 1123 bool (*e_putbody)__P((MCI *, ENVELOPE *, char *)); 1124 /* function to put body of message */ 1125 ENVELOPE *e_parent; /* the message this one encloses */ 1126 ENVELOPE *e_sibling; /* the next envelope of interest */ 1127 char *e_bodytype; /* type of message body */ 1128 SM_FILE_T *e_dfp; /* data file */ 1129 char *e_id; /* code for this entry in queue */ 1130 #if _FFR_SESSID 1131 char *e_sessid; /* session ID for this envelope */ 1132 #endif 1133 int e_qgrp; /* queue group (index into queues) */ 1134 int e_qdir; /* index into queue directories */ 1135 int e_dfqgrp; /* data file queue group index */ 1136 int e_dfqdir; /* data file queue directory index */ 1137 int e_xfqgrp; /* queue group (index into queues) */ 1138 int e_xfqdir; /* index into queue directories (xf) */ 1139 SM_FILE_T *e_xfp; /* transcript file */ 1140 SM_FILE_T *e_lockfp; /* the lock file for this message */ 1141 char *e_message; /* error message; readonly; NULL, 1142 * or allocated from e_rpool */ 1143 char *e_statmsg; /* stat msg (changes per delivery). 1144 * readonly. NULL or allocated from 1145 * e_rpool. */ 1146 char *e_quarmsg; /* why envelope is quarantined */ 1147 char e_qfletter; /* queue file letter on disk */ 1148 char *e_msgboundary; /* MIME-style message part boundary */ 1149 char *e_origrcpt; /* original recipient (one only) */ 1150 char *e_envid; /* envelope id from MAIL FROM: line */ 1151 char *e_status; /* DSN status for this message */ 1152 time_t e_dtime; /* time of last delivery attempt */ 1153 int e_ntries; /* number of delivery attempts */ 1154 dev_t e_dfdev; /* data file device (crash recovery) */ 1155 ino_t e_dfino; /* data file inode (crash recovery) */ 1156 MACROS_T e_macro; /* macro definitions */ 1157 MCI *e_mci; /* connection info */ 1158 char *e_auth_param; /* readonly; NULL or static storage or 1159 * allocated from e_rpool */ 1160 #if _FFR_TIMERS 1161 TIMERS e_timers; /* per job timers */ 1162 #endif 1163 long e_deliver_by; /* deliver by */ 1164 int e_dlvr_flag; /* deliver by flag */ 1165 SM_RPOOL_T *e_rpool; /* resource pool for this envelope */ 1166 unsigned long e_features; /* server features */ 1167 #define ENHSC_LEN 11 1168 #if _FFR_MILTER_ENHSC 1169 char e_enhsc[ENHSC_LEN]; /* enhanced status code */ 1170 #endif 1171 /* smtp error codes during delivery */ 1172 int e_rcode; /* reply code */ 1173 char e_renhsc[ENHSC_LEN]; /* enhanced status code */ 1174 char *e_text; /* reply text */ 1175 #if _FFR_LOG_STAGE 1176 int e_estate; /* protocol state when error happened */ 1177 #endif 1178 }; 1179 1180 #define PRT_NONNEGL(v) ((v) < 0 ? LONG_MAX : (v)) 1181 1182 /* values for e_flags */ 1183 #define EF_OLDSTYLE 0x00000001L /* use spaces (not commas) in hdrs */ 1184 #define EF_INQUEUE 0x00000002L /* this message is fully queued */ 1185 #define EF_NO_BODY_RETN 0x00000004L /* omit message body on error */ 1186 #define EF_CLRQUEUE 0x00000008L /* disk copy is no longer needed */ 1187 #define EF_SENDRECEIPT 0x00000010L /* send a return receipt */ 1188 #define EF_FATALERRS 0x00000020L /* fatal errors occurred */ 1189 #define EF_DELETE_BCC 0x00000040L /* delete Bcc: headers entirely */ 1190 #define EF_RESPONSE 0x00000080L /* this is an error or return receipt */ 1191 #define EF_RESENT 0x00000100L /* this message is being forwarded */ 1192 #define EF_VRFYONLY 0x00000200L /* verify only (don't expand aliases) */ 1193 #define EF_WARNING 0x00000400L /* warning message has been sent */ 1194 #define EF_QUEUERUN 0x00000800L /* this envelope is from queue */ 1195 #define EF_GLOBALERRS 0x00001000L /* treat errors as global */ 1196 #define EF_PM_NOTIFY 0x00002000L /* send return mail to postmaster */ 1197 #define EF_METOO 0x00004000L /* send to me too */ 1198 #define EF_LOGSENDER 0x00008000L /* need to log the sender */ 1199 #define EF_NORECEIPT 0x00010000L /* suppress all return-receipts */ 1200 #define EF_HAS8BIT 0x00020000L /* at least one 8-bit char in body */ 1201 /* was: EF_NL_NOT_EOL 0x00040000L * don't accept raw LF as EOLine */ 1202 /* was: EF_CRLF_NOT_EOL 0x00080000L * don't accept CRLF as EOLine */ 1203 #define EF_RET_PARAM 0x00100000L /* RCPT command had RET argument */ 1204 #define EF_HAS_DF 0x00200000L /* set when data file is instantiated */ 1205 #define EF_IS_MIME 0x00400000L /* really is a MIME message */ 1206 #define EF_DONT_MIME 0x00800000L /* never MIME this message */ 1207 #define EF_DISCARD 0x01000000L /* discard the message */ 1208 #define EF_TOOBIG 0x02000000L /* message is too big */ 1209 #define EF_SPLIT 0x04000000L /* envelope has been split */ 1210 #define EF_UNSAFE 0x08000000L /* unsafe: read from untrusted source */ 1211 #define EF_TOODEEP 0x10000000L /* message is nested too deep */ 1212 #define EF_SECURE 0x20000000L /* DNSSEC for currently parsed addr */ 1213 #define EF_7BITBODY 0x40000000L /* strip body to 7bit on input */ 1214 1215 #define DLVR_NOTIFY 0x01 1216 #define DLVR_RETURN 0x02 1217 #define DLVR_TRACE 0x10 1218 #define IS_DLVR_NOTIFY(e) (((e)->e_dlvr_flag & DLVR_NOTIFY) != 0) 1219 #define IS_DLVR_RETURN(e) (((e)->e_dlvr_flag & DLVR_RETURN) != 0) 1220 #define IS_DLVR_TRACE(e) (((e)->e_dlvr_flag & DLVR_TRACE) != 0) 1221 #define IS_DLVR_BY(e) ((e)->e_dlvr_flag != 0) 1222 1223 #define BODYTYPE_NONE (0) 1224 #define BODYTYPE_7BIT (1) 1225 #define BODYTYPE_8BITMIME (2) 1226 #define BODYTYPE_ILLEGAL (-1) 1227 #define BODYTYPE_VALID(b) ((b) == BODYTYPE_7BIT || (b) == BODYTYPE_8BITMIME) 1228 1229 extern ENVELOPE BlankEnvelope; 1230 1231 /* functions */ 1232 extern void clearenvelope __P((ENVELOPE *, bool, SM_RPOOL_T *)); 1233 extern int dropenvelope __P((ENVELOPE *, bool, bool)); 1234 extern ENVELOPE *newenvelope __P((ENVELOPE *, ENVELOPE *, SM_RPOOL_T *)); 1235 extern void clrsessenvelope __P((ENVELOPE *)); 1236 extern void printenvflags __P((ENVELOPE *)); 1237 extern bool putbody __P((MCI *, ENVELOPE *, char *)); 1238 extern bool putheader __P((MCI *, HDR *, ENVELOPE *, int)); 1239 1240 /* 1241 ** Message priority classes. 1242 ** 1243 ** The message class is read directly from the Priority: header 1244 ** field in the message. 1245 ** 1246 ** CurEnv->e_msgpriority is the number of bytes in the message plus 1247 ** the creation time (so that jobs ``tend'' to be ordered correctly), 1248 ** adjusted by the message class, the number of recipients, and the 1249 ** amount of time the message has been sitting around. This number 1250 ** is used to order the queue. Higher values mean LOWER priority. 1251 ** 1252 ** Each priority class point is worth WkClassFact priority points; 1253 ** each recipient is worth WkRecipFact priority points. Each time 1254 ** we reprocess a message the priority is adjusted by WkTimeFact. 1255 ** WkTimeFact should normally decrease the priority so that jobs 1256 ** that have historically failed will be run later; thanks go to 1257 ** Jay Lepreau at Utah for pointing out the error in my thinking. 1258 ** 1259 ** The "class" is this number, unadjusted by the age or size of 1260 ** this message. Classes with negative representations will have 1261 ** error messages thrown away if they are not local. 1262 */ 1263 1264 struct priority 1265 { 1266 char *pri_name; /* external name of priority */ 1267 int pri_val; /* internal value for same */ 1268 }; 1269 1270 EXTERN int NumPriorities; /* pointer into Priorities */ 1271 EXTERN struct priority Priorities[MAXPRIORITIES]; 1272 1273 /* 1274 ** Rewrite rules. 1275 */ 1276 1277 struct rewrite 1278 { 1279 char **r_lhs; /* pattern match */ 1280 char **r_rhs; /* substitution value */ 1281 struct rewrite *r_next;/* next in chain */ 1282 int r_line; /* rule line in sendmail.cf */ 1283 }; 1284 1285 /* 1286 ** Special characters in rewriting rules. 1287 ** These are used internally only. 1288 ** The COND* rules are actually used in macros rather than in 1289 ** rewriting rules, but are given here because they 1290 ** cannot conflict. 1291 */ 1292 1293 /* 1294 ** "out of band" indicator 1295 ** sm/sendmail.h #define METAQUOTE ((unsigned char)0377) 1296 ** quotes the next octet 1297 ** range: ((ch) & 0340) == 0200 1298 ** see #define SM_MM_QUOTE(ch) in libsm/util.c 1299 */ 1300 1301 /* left hand side items */ 1302 #define MATCHZANY ((unsigned char)0220) /* match zero or more tokens */ 1303 #define MATCHANY ((unsigned char)0221) /* match one or more tokens */ 1304 #define MATCHONE ((unsigned char)0222) /* match exactly one token */ 1305 #define MATCHCLASS ((unsigned char)0223) /* match one token in a class */ 1306 #define MATCHNCLASS ((unsigned char)0224) /* match tokens not in class */ 1307 1308 /* right hand side items */ 1309 #define MATCHREPL ((unsigned char)0225) /* RHS replacement for above */ 1310 #define CANONNET ((unsigned char)0226) /* canonical net, next token */ 1311 #define CANONHOST ((unsigned char)0227) /* canonical host, next token */ 1312 #define CANONUSER ((unsigned char)0230) /* canonical user, next N tokens */ 1313 #define CALLSUBR ((unsigned char)0231) /* call another rewriting set */ 1314 1315 /* conditionals in macros (anywhere) */ 1316 #define CONDIF ((unsigned char)0232) /* conditional if-then */ 1317 #define CONDELSE ((unsigned char)0233) /* conditional else */ 1318 #define CONDFI ((unsigned char)0234) /* conditional fi */ 1319 1320 /* bracket characters for RHS host name lookup */ 1321 #define HOSTBEGIN ((unsigned char)0235) /* hostname lookup begin */ 1322 #define HOSTEND ((unsigned char)0236) /* hostname lookup end */ 1323 1324 /* bracket characters for RHS generalized lookup */ 1325 #define LOOKUPBEGIN ((unsigned char)0205) /* generalized lookup begin */ 1326 #define LOOKUPEND ((unsigned char)0206) /* generalized lookup end */ 1327 1328 /* macro substitution characters (anywhere) */ 1329 #define MACROEXPAND ((unsigned char)0201) /* macro expansion */ 1330 #define MACRODEXPAND ((unsigned char)0202) /* deferred macro expansion */ 1331 1332 /* to make the code clearer */ 1333 #define MATCHZERO CANONHOST 1334 1335 #define MAXMATCH 9 /* max params per rewrite */ 1336 #define MAX_MAP_ARGS 10 /* max arguments for map */ 1337 1338 /* external <==> internal mapping table */ 1339 struct metamac 1340 { 1341 char metaname; /* external code (after $) */ 1342 unsigned char metaval; /* internal code (as above) */ 1343 }; 1344 1345 /* values for macros with external names only */ 1346 #define MID_OPMODE 0202 /* operation mode */ 1347 1348 /* functions */ 1349 #if SM_HEAP_CHECK 1350 extern void 1351 macdefine_tagged __P(( 1352 MACROS_T *_mac, 1353 ARGCLASS_T _vclass, 1354 int _id, 1355 char *_value, 1356 char *_file, 1357 int _line, 1358 int _group)); 1359 # define macdefine(mac,c,id,v) \ 1360 macdefine_tagged(mac,c,id,v,__FILE__,__LINE__,sm_heap_group()) 1361 #else /* SM_HEAP_CHECK */ 1362 extern void 1363 macdefine __P(( 1364 MACROS_T *_mac, 1365 ARGCLASS_T _vclass, 1366 int _id, 1367 char *_value)); 1368 # define macdefine_tagged(mac,c,id,v,file,line,grp) macdefine(mac,c,id,v) 1369 #endif /* SM_HEAP_CHECK */ 1370 extern void macset __P((MACROS_T *, int, char *)); 1371 #define macget(mac, i) (mac)->mac_table[i] 1372 extern void expand __P((char *, char *, size_t, ENVELOPE *)); 1373 extern int macid_parse __P((char *, char **)); 1374 #define macid(name) macid_parse(name, NULL) 1375 extern char *macname __P((int)); 1376 extern char *macvalue __P((int, ENVELOPE *)); 1377 extern void mactabclear __P((MACROS_T *)); 1378 extern int rscheck __P((char *, const char *, const char *, ENVELOPE *, int, int, const char *, const char *, ADDRESS *, char **)); 1379 extern int rscap __P((char *, char *, char *, ENVELOPE *, char ***, char *, int)); 1380 extern void setclass __P((int, char *)); 1381 extern int strtorwset __P((char *, char **, int)); 1382 extern char *translate_dollars __P((char *, char *, int *)); 1383 extern bool wordinclass __P((char *, int)); 1384 1385 /* 1386 ** Name canonification short circuit. 1387 ** 1388 ** If the name server for a host is down, the process of trying to 1389 ** canonify the name can hang. This is similar to (but alas, not 1390 ** identical to) looking up the name for delivery. This stab type 1391 ** caches the result of the name server lookup so we don't hang 1392 ** multiple times. 1393 */ 1394 1395 #define NAMECANON struct _namecanon 1396 1397 NAMECANON 1398 { 1399 short nc_errno; /* cached errno */ 1400 short nc_herrno; /* cached h_errno */ 1401 short nc_stat; /* cached exit status code */ 1402 short nc_flags; /* flag bits */ 1403 char *nc_cname; /* the canonical name */ 1404 time_t nc_exp; /* entry expires at */ 1405 }; 1406 1407 /* values for nc_flags */ 1408 #define NCF_VALID 0x0001 /* entry valid */ 1409 #define NCF_VALID 0x0001 /* entry valid */ 1410 #define NCF_SECURE 0x0002 /* entry secure (DNSSEC) */ 1411 1412 /* hostsignature structure */ 1413 1414 struct hostsig_t 1415 { 1416 char *hs_sig; /* hostsignature */ 1417 time_t hs_exp; /* entry expires at */ 1418 }; 1419 1420 typedef struct hostsig_t HOSTSIG_T; 1421 1422 /* 1423 ** The standard udp packet size PACKETSZ (512) is not sufficient for some 1424 ** nameserver answers containing very many resource records. The resolver 1425 ** may switch to tcp and retry if it detects udp packet overflow. 1426 ** Also note that the resolver routines res_query and res_search return 1427 ** the size of the *un*truncated answer in case the supplied answer buffer 1428 ** it not big enough to accommodate the entire answer. 1429 */ 1430 1431 #ifndef MAXPACKET 1432 # define MAXPACKET 8192 /* max packet size used internally by BIND */ 1433 #endif 1434 1435 /* 1436 ** The resolver functions res_{send,query,querydomain} expect the 1437 ** answer buffer to be aligned, but some versions of gcc4 reverse 1438 ** 25 years of history and no longer align char buffers on the 1439 ** stack, resulting in crashes on strict-alignment platforms. Use 1440 ** this union when putting the buffer on the stack to force the 1441 ** alignment, then cast to (HEADER *) or (unsigned char *) as needed. 1442 */ 1443 typedef union 1444 { 1445 HEADER qb1; 1446 unsigned char qb2[MAXPACKET]; 1447 } querybuf; 1448 1449 1450 /* result values for getcanonname() etc */ 1451 #define HOST_NOTFOUND 0 1452 #define HOST_OK 1 1453 #define HOST_SECURE 2 1454 1455 /* flags for getmxrr() */ 1456 #define DROPLOCALHOST 0x01 1457 #define TRYFALLBACK 0x02 1458 #define ISAD 0x04 1459 1460 /* RFC7505: Null MX */ 1461 #define NULLMX (-2) 1462 1463 /* functions */ 1464 extern int getcanonname __P((char *, int, bool, int *)); 1465 extern int getmxrr __P((char *, char **, unsigned short *, unsigned int, int *, int *, int, int *)); 1466 extern char *hostsignature __P((MAILER *, char *, bool, unsigned long *)); 1467 extern int getfallbackmxrr __P((char *)); 1468 1469 /* 1470 ** Mapping functions 1471 ** 1472 ** These allow arbitrary mappings in the config file. The idea 1473 ** (albeit not the implementation) comes from IDA sendmail. 1474 */ 1475 1476 #define MAPCLASS struct _mapclass 1477 #define MAP struct _map 1478 #define MAXMAPACTIONS 5 /* size of map_actions array */ 1479 1480 1481 /* 1482 ** An actual map. 1483 */ 1484 1485 MAP 1486 { 1487 MAPCLASS *map_class; /* the class of this map */ 1488 MAPCLASS *map_orgclass; /* the original class of this map */ 1489 char *map_mname; /* name of this map */ 1490 long map_mflags; /* flags, see below */ 1491 char *map_file; /* the (nominal) filename */ 1492 ARBPTR_T map_db1; /* the open database ptr */ 1493 ARBPTR_T map_db2; /* an "extra" database pointer */ 1494 char *map_keycolnm; /* key column name */ 1495 char *map_valcolnm; /* value column name */ 1496 unsigned char map_keycolno; /* key column number */ 1497 unsigned char map_valcolno; /* value column number */ 1498 char map_coldelim; /* column delimiter */ 1499 char map_spacesub; /* spacesub */ 1500 char *map_app; /* to append to successful matches */ 1501 char *map_tapp; /* to append to "tempfail" matches */ 1502 char *map_domain; /* the (nominal) NIS domain */ 1503 char *map_rebuild; /* program to run to do auto-rebuild */ 1504 time_t map_mtime; /* last database modification time */ 1505 time_t map_timeout; /* timeout for map accesses */ 1506 int map_retry; /* # of retries for map accesses */ 1507 pid_t map_pid; /* PID of process which opened map */ 1508 int map_lockfd; /* auxiliary lock file descriptor */ 1509 MAP *map_stack[MAXMAPSTACK]; /* list for stacked maps */ 1510 short map_return[MAXMAPACTIONS]; /* return bitmaps for stacked maps */ 1511 }; 1512 1513 #if _FFR_DYN_CLASS 1514 # define map_tag map_domain /* overload map field */ 1515 #endif 1516 1517 /* bit values for map_mflags */ 1518 #define MF_VALID 0x00000001 /* this entry is valid */ 1519 #define MF_INCLNULL 0x00000002 /* include null byte in key */ 1520 #define MF_OPTIONAL 0x00000004 /* don't complain if map not found */ 1521 #define MF_NOFOLDCASE 0x00000008 /* don't fold case in keys */ 1522 #define MF_MATCHONLY 0x00000010 /* don't use the map value */ 1523 #define MF_OPEN 0x00000020 /* this entry is open */ 1524 #define MF_WRITABLE 0x00000040 /* open for writing */ 1525 #define MF_ALIAS 0x00000080 /* this is an alias file */ 1526 #define MF_TRY0NULL 0x00000100 /* try with no null byte */ 1527 #define MF_TRY1NULL 0x00000200 /* try with the null byte */ 1528 #define MF_LOCKED 0x00000400 /* map is locked (RDWR) */ 1529 /* that means: no extra lockfile() calls must be made (in *map_lookup()) */ 1530 #define MF_ALIASWAIT 0x00000800 /* alias map in aliaswait state */ 1531 #define MF_IMPL_HASH 0x00001000 /* implicit: underlying hash database */ 1532 #define MF_IMPL_NDBM 0x00002000 /* implicit: underlying NDBM database */ 1533 #define MF_IMPL_CDB 0x00004000 /* implicit: underlying CDB database */ 1534 #define MF_APPEND 0x00008000 /* append new entry on rebuild */ 1535 #define MF_KEEPQUOTES 0x00010000 /* don't dequote key before lookup */ 1536 #define MF_NODEFER 0x00020000 /* don't defer if map lookup fails */ 1537 #define MF_REGEX_NOT 0x00040000 /* regular expression negation */ 1538 #define MF_DEFER 0x00080000 /* don't lookup map in defer mode */ 1539 #define MF_SINGLEMATCH 0x00100000 /* successful only if match one key */ 1540 #define MF_SINGLEDN 0x00200000 /* only one match, but multi values */ 1541 #define MF_FILECLASS 0x00400000 /* this is a file class map */ 1542 #define MF_OPENBOGUS 0x00800000 /* open failed, don't call map_close */ 1543 #define MF_CLOSING 0x01000000 /* map is being closed */ 1544 #define MF_SECURE 0x02000000 /* DNSSEC result is "secure" */ 1545 #define MF_KEEPXFMT 0x04000000 /* keep [x] format */ 1546 #define MF_CHKED_CHGD 0x08000000 /* checked whether underlying map changed */ 1547 1548 #define DYNOPENMAP(map) \ 1549 do \ 1550 { \ 1551 if (!bitset(MF_OPEN, (map)->map_mflags)) \ 1552 { \ 1553 if (!openmap(map)) \ 1554 return NULL; \ 1555 } \ 1556 } while (0) 1557 1558 1559 /* indices for map_actions */ 1560 #define MA_NOTFOUND 0 /* member map returned "not found" */ 1561 #define MA_UNAVAIL 1 /* member map is not available */ 1562 #define MA_TRYAGAIN 2 /* member map returns temp failure */ 1563 1564 /* 1565 ** The class of a map -- essentially the functions to call 1566 */ 1567 1568 MAPCLASS 1569 { 1570 char *map_cname; /* name of this map class */ 1571 char *map_ext; /* extension for database file */ 1572 short map_cflags; /* flag bits, see below */ 1573 bool (*map_parse)__P((MAP *, char *)); 1574 /* argument parsing function */ 1575 char *(*map_lookup)__P((MAP *, char *, char **, int *)); 1576 /* lookup function */ 1577 void (*map_store)__P((MAP *, char *, char *)); 1578 /* store function */ 1579 bool (*map_open)__P((MAP *, int)); 1580 /* open function */ 1581 void (*map_close)__P((MAP *)); 1582 /* close function */ 1583 }; 1584 1585 /* bit values for map_cflags */ 1586 #define MCF_ALIASOK 0x0001 /* can be used for aliases */ 1587 /* #define MCF_ALIASONLY 0x0002 * usable only for aliases */ 1588 #define MCF_REBUILDABLE 0x0004 /* can rebuild alias files */ 1589 #define MCF_OPTFILE 0x0008 /* file name is optional */ 1590 #define MCF_NOTPERSIST 0x0010 /* don't keep map open all the time */ 1591 1592 /* functions */ 1593 extern void closemaps __P((bool)); 1594 extern bool impl_map_open __P((MAP *, int)); 1595 extern void initmaps __P((void)); 1596 extern MAP *makemapentry __P((char *)); 1597 extern void maplocaluser __P((ADDRESS *, ADDRESS **, int, ENVELOPE *)); 1598 extern char *map_rewrite __P((MAP *, const char *, size_t, char **)); 1599 #if NETINFO 1600 extern char *ni_propval __P((char *, char *, char *, char *, int)); 1601 #endif 1602 extern bool openmap __P((MAP *)); 1603 extern int udbexpand __P((ADDRESS *, ADDRESS **, int, ENVELOPE *)); 1604 #if USERDB 1605 extern void _udbx_close __P((void)); 1606 extern char *udbsender __P((char *, SM_RPOOL_T *)); 1607 #endif 1608 #if _FFR_MAP_CHK_FILE > 1 1609 extern void maps_reset_chged __P((const char *)); 1610 #else 1611 # define maps_reset_chged(msg) 1612 #endif 1613 1614 /* 1615 ** LDAP related items 1616 */ 1617 #if LDAPMAP 1618 /* struct defining LDAP Auth Methods */ 1619 struct lamvalues 1620 { 1621 char *lam_name; /* name of LDAP auth method */ 1622 int lam_code; /* numeric code */ 1623 }; 1624 1625 /* struct defining LDAP Alias Dereferencing */ 1626 struct ladvalues 1627 { 1628 char *lad_name; /* name of LDAP alias dereferencing method */ 1629 int lad_code; /* numeric code */ 1630 }; 1631 1632 /* struct defining LDAP Search Scope */ 1633 struct lssvalues 1634 { 1635 char *lss_name; /* name of LDAP search scope */ 1636 int lss_code; /* numeric code */ 1637 }; 1638 1639 /* functions */ 1640 extern void ldapmap_set_defaults __P((char *)); 1641 #endif /* LDAPMAP */ 1642 1643 /* 1644 ** PH related items 1645 */ 1646 1647 #if PH_MAP 1648 1649 # include <phclient.h> 1650 1651 struct ph_map_struct 1652 { 1653 char *ph_servers; /* list of ph servers */ 1654 char *ph_field_list; /* list of fields to search for match */ 1655 PH *ph; /* PH server handle */ 1656 int ph_fastclose; /* send "quit" command on close */ 1657 time_t ph_timeout; /* timeout interval */ 1658 }; 1659 typedef struct ph_map_struct PH_MAP_STRUCT; 1660 1661 #endif /* PH_MAP */ 1662 1663 /* 1664 ** Regular UNIX sockaddrs are too small to handle ISO addresses, so 1665 ** we are forced to declare a supertype here. 1666 */ 1667 1668 #if NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25 1669 union bigsockaddr 1670 { 1671 struct sockaddr sa; /* general version */ 1672 # if NETUNIX 1673 struct sockaddr_un sunix; /* UNIX family */ 1674 # endif 1675 # if NETINET 1676 struct sockaddr_in sin; /* INET family */ 1677 # endif 1678 # if NETINET6 1679 struct sockaddr_in6 sin6; /* INET/IPv6 */ 1680 # endif 1681 # if NETISO 1682 struct sockaddr_iso siso; /* ISO family */ 1683 # endif 1684 # if NETNS 1685 struct sockaddr_ns sns; /* XNS family */ 1686 # endif 1687 # if NETX25 1688 struct sockaddr_x25 sx25; /* X.25 family */ 1689 # endif 1690 }; 1691 1692 # define SOCKADDR union bigsockaddr 1693 1694 /* functions */ 1695 extern char *anynet_ntoa __P((SOCKADDR *)); 1696 # if NETINET6 1697 extern char *anynet_ntop __P((struct in6_addr *, char *, size_t)); 1698 extern int anynet_pton __P((int, const char *, void *)); 1699 # endif 1700 extern char *hostnamebyanyaddr __P((SOCKADDR *)); 1701 extern char *validate_connection __P((SOCKADDR *, char *, ENVELOPE *)); 1702 # if SASL >= 20000 1703 extern bool iptostring __P((SOCKADDR *, SOCKADDR_LEN_T, char *, unsigned)); 1704 # endif 1705 1706 #endif /* NETINET || NETINET6 || NETUNIX || NETISO || NETNS || NETX25 */ 1707 1708 /* 1709 ** Process List (proclist) 1710 */ 1711 1712 #define NO_PID ((pid_t) 0) 1713 #ifndef PROC_LIST_SEG 1714 # define PROC_LIST_SEG 32 /* number of pids to alloc at a time */ 1715 #endif 1716 1717 /* process types */ 1718 #define PROC_NONE 0 1719 #define PROC_DAEMON 1 1720 #define PROC_DAEMON_CHILD 2 1721 #define PROC_QUEUE 3 1722 #define PROC_QUEUE_CHILD 3 1723 #define PROC_CONTROL 4 1724 #define PROC_CONTROL_CHILD 5 1725 #define PROC_QM 6 1726 1727 /* functions */ 1728 extern void proc_list_add __P((pid_t, char *, int, int, int, SOCKADDR *)); 1729 extern void proc_list_clear __P((void)); 1730 extern void proc_list_display __P((SM_FILE_T *, char *)); 1731 extern void proc_list_drop __P((pid_t, int, int *)); 1732 extern void proc_list_probe __P((void)); 1733 extern void proc_list_set __P((pid_t, char *)); 1734 extern void proc_list_signal __P((int, int)); 1735 1736 /* 1737 ** Symbol table definitions 1738 */ 1739 1740 struct symtab 1741 { 1742 char *s_name; /* name to be entered */ 1743 short s_symtype; /* general type (see below) */ 1744 struct symtab *s_next; /* pointer to next in chain */ 1745 union 1746 { 1747 BITMAP256 sv_class; /* bit-map of word classes */ 1748 MAILER *sv_mailer; /* pointer to mailer */ 1749 char *sv_alias; /* alias */ 1750 MAPCLASS sv_mapclass; /* mapping function class */ 1751 MAP sv_map; /* mapping function */ 1752 HOSTSIG_T sv_hostsig; /* host signature */ 1753 MCI sv_mci; /* mailer connection info */ 1754 NAMECANON sv_namecanon; /* canonical name cache */ 1755 int sv_macro; /* macro name => id mapping */ 1756 int sv_ruleset; /* ruleset index */ 1757 struct hdrinfo sv_header; /* header metainfo */ 1758 char *sv_service[MAXMAPSTACK]; /* service switch */ 1759 #if LDAPMAP 1760 MAP *sv_lmap; /* Maps for LDAP connection */ 1761 #endif 1762 #if SOCKETMAP 1763 MAP *sv_socketmap; /* Maps for SOCKET connection */ 1764 #endif 1765 #if MILTER 1766 struct milter *sv_milter; /* milter filter name */ 1767 #endif 1768 QUEUEGRP *sv_queue; /* pointer to queue */ 1769 #if DANE 1770 dane_tlsa_P sv_tlsa; /* pointer to TLSA RRs */ 1771 #endif 1772 #if _FFR_DYN_CLASS 1773 MAP sv_dynclass; /* map for dynamic class */ 1774 #endif 1775 } s_value; 1776 }; 1777 1778 typedef struct symtab STAB; 1779 1780 /* symbol types */ 1781 #define ST_UNDEF 0 /* undefined type */ 1782 #define ST_CLASS 1 /* class map */ 1783 /* #define ST_unused 2 UNUSED */ 1784 #define ST_MAILER 3 /* a mailer header */ 1785 #define ST_ALIAS 4 /* an alias */ 1786 #define ST_MAPCLASS 5 /* mapping function class */ 1787 #define ST_MAP 6 /* mapping function */ 1788 #define ST_HOSTSIG 7 /* host signature */ 1789 #define ST_NAMECANON 8 /* cached canonical name */ 1790 #define ST_MACRO 9 /* macro name to id mapping */ 1791 #define ST_RULESET 10 /* ruleset index */ 1792 #define ST_SERVICE 11 /* service switch entry */ 1793 #define ST_HEADER 12 /* special header flags */ 1794 #if LDAPMAP 1795 # define ST_LMAP 13 /* List head of maps for LDAP connection */ 1796 #endif 1797 #if MILTER 1798 # define ST_MILTER 14 /* milter filter */ 1799 #endif 1800 #define ST_QUEUE 15 /* a queue entry */ 1801 1802 #if SOCKETMAP 1803 # define ST_SOCKETMAP 16 /* List head of maps for SOCKET connection */ 1804 #endif 1805 1806 #if DANE 1807 # define ST_TLSA_RR 17 /* cached TLSA RRs */ 1808 #endif 1809 #if _FFR_DYN_CLASS 1810 # define ST_DYNMAP 18 /* dynamic map */ 1811 #endif 1812 1813 /* This entry must be last */ 1814 #define ST_MCI 19 /* mailer connection info (offset) */ 1815 1816 #define s_class s_value.sv_class 1817 #define s_mailer s_value.sv_mailer 1818 #define s_alias s_value.sv_alias 1819 #define s_mci s_value.sv_mci 1820 #define s_mapclass s_value.sv_mapclass 1821 #define s_hostsig s_value.sv_hostsig 1822 #define s_map s_value.sv_map 1823 #define s_namecanon s_value.sv_namecanon 1824 #define s_macro s_value.sv_macro 1825 #define s_ruleset s_value.sv_ruleset 1826 #define s_service s_value.sv_service 1827 #define s_header s_value.sv_header 1828 #if LDAPMAP 1829 # define s_lmap s_value.sv_lmap 1830 #endif 1831 #if SOCKETMAP 1832 # define s_socketmap s_value.sv_socketmap 1833 #endif 1834 #if MILTER 1835 # define s_milter s_value.sv_milter 1836 #endif 1837 #define s_quegrp s_value.sv_queue 1838 #if DANE 1839 # define s_tlsa s_value.sv_tlsa 1840 #endif 1841 #if _FFR_DYN_CLASS 1842 # define s_dynclass s_value.sv_dynclass 1843 #endif 1844 1845 /* opcodes to stab */ 1846 #define ST_FIND 0 /* find entry */ 1847 #define ST_ENTER 1 /* enter if not there */ 1848 1849 /* functions */ 1850 extern STAB *stab __P((char *, int, int)); 1851 extern void stabapply __P((void (*)(STAB *, int), int)); 1852 1853 /* 1854 ** Operation, send, error, and MIME modes 1855 ** 1856 ** The operation mode describes the basic operation of sendmail. 1857 ** This can be set from the command line, and is "send mail" by 1858 ** default. 1859 ** 1860 ** The send mode tells how to send mail. It can be set in the 1861 ** configuration file. Its setting determines how quickly the 1862 ** mail will be delivered versus the load on your system. If the 1863 ** -v (verbose) flag is given, it will be forced to SM_DELIVER 1864 ** mode. 1865 ** 1866 ** The error mode tells how to return errors. 1867 */ 1868 1869 #define MD_DELIVER 'm' /* be a mail sender */ 1870 #define MD_SMTP 's' /* run SMTP on standard input */ 1871 #define MD_ARPAFTP 'a' /* obsolete ARPANET mode (Grey Book) */ 1872 #define MD_DAEMON 'd' /* run as a daemon */ 1873 #define MD_FGDAEMON 'D' /* run daemon in foreground */ 1874 #define MD_LOCAL 'l' /* like daemon, but localhost only */ 1875 #define MD_VERIFY 'v' /* verify: don't collect or deliver */ 1876 #define MD_TEST 't' /* test mode: resolve addrs only */ 1877 #define MD_INITALIAS 'i' /* initialize alias database */ 1878 #define MD_PRINT 'p' /* print the queue */ 1879 #define MD_PRINTNQE 'P' /* print number of entries in queue */ 1880 #define MD_FREEZE 'z' /* freeze the configuration file */ 1881 #define MD_HOSTSTAT 'h' /* print persistent host stat info */ 1882 #define MD_PURGESTAT 'H' /* purge persistent host stat info */ 1883 #define MD_QUEUERUN 'q' /* queue run */ 1884 #define MD_CHECKCONFIG 'C' /* check configuration file */ 1885 #define MD_SHOWCONFIG 'O' /* show cf options */ 1886 1887 #if _FFR_LOCAL_DAEMON 1888 EXTERN bool LocalDaemon; 1889 # if NETINET6 1890 EXTERN bool V6LoopbackAddrFound; /* found an IPv6 loopback address */ 1891 # define SETV6LOOPBACKADDRFOUND(sa) \ 1892 do \ 1893 { \ 1894 if (isloopback(sa)) \ 1895 V6LoopbackAddrFound = true; \ 1896 } while (0) 1897 # endif /* NETINET6 */ 1898 #else /* _FFR_LOCAL_DAEMON */ 1899 # define LocalDaemon false 1900 # define V6LoopbackAddrFound false 1901 # define SETV6LOOPBACKADDRFOUND(sa) 1902 #endif /* _FFR_LOCAL_DAEMON */ 1903 1904 /* Note: see also include/sendmail/pathnames.h: GET_CLIENT_CF */ 1905 1906 /* values for e_sendmode -- send modes */ 1907 #define SM_DELIVER 'i' /* interactive delivery */ 1908 #if _FFR_PROXY 1909 # define SM_PROXY_REQ 's' /* synchronous mode requested */ 1910 # define SM_PROXY 'S' /* synchronous mode activated */ 1911 #endif 1912 #define SM_FORK 'b' /* deliver in background */ 1913 #if _FFR_DM_ONE 1914 # define SM_DM_ONE 'o' /* deliver first TA in background, then queue */ 1915 #endif 1916 #if _FFR_DMTRIGGER 1917 # define SM_TRIGGER 't' /* queue and tell "queue manager" */ 1918 # define IS_SM_TRIGGER(m) ((m) == SM_TRIGGER) 1919 #else 1920 # define IS_SM_TRIGGER(m) false 1921 #endif 1922 #define SM_QUEUE 'q' /* queue, don't deliver */ 1923 #define SM_DEFER 'd' /* defer map lookups as well as queue */ 1924 #define SM_VERIFY 'v' /* verify only (used internally) */ 1925 #define DM_NOTSET (-1) /* DeliveryMode (per daemon) option not set */ 1926 #if _FFR_PROXY 1927 # define SM_IS_INTERACTIVE(m) ((m) == SM_DELIVER || (m) == SM_PROXY_REQ || (m) == SM_PROXY) 1928 #else 1929 # define SM_IS_INTERACTIVE(m) ((m) == SM_DELIVER) 1930 #endif 1931 1932 #define WILL_BE_QUEUED(m) ((m) == SM_QUEUE || (m) == SM_DEFER || IS_SM_TRIGGER(m)) 1933 1934 /* used only as a parameter to sendall */ 1935 #define SM_DEFAULT '\0' /* unspecified, use SendMode */ 1936 1937 /* functions */ 1938 extern void set_delivery_mode __P((int, ENVELOPE *)); 1939 1940 /* values for e_errormode -- error handling modes */ 1941 #define EM_PRINT 'p' /* print errors */ 1942 #define EM_MAIL 'm' /* mail back errors */ 1943 #define EM_WRITE 'w' /* write back errors */ 1944 #define EM_BERKNET 'e' /* special berknet processing */ 1945 #define EM_QUIET 'q' /* don't print messages (stat only) */ 1946 1947 1948 /* bit values for MimeMode */ 1949 #define MM_CVTMIME 0x0001 /* convert 8 to 7 bit MIME */ 1950 #define MM_PASS8BIT 0x0002 /* just send 8 bit data blind */ 1951 #define MM_MIME8BIT 0x0004 /* convert 8-bit data to MIME */ 1952 1953 1954 /* how to handle messages without any recipient addresses */ 1955 #define NRA_NO_ACTION 0 /* just leave it as is */ 1956 #define NRA_ADD_TO 1 /* add To: header */ 1957 #define NRA_ADD_APPARENTLY_TO 2 /* add Apparently-To: header */ 1958 #define NRA_ADD_BCC 3 /* add empty Bcc: header */ 1959 #define NRA_ADD_TO_UNDISCLOSED 4 /* add To: undisclosed:; header */ 1960 1961 1962 /* flags to putxline */ 1963 #define PXLF_NOTHINGSPECIAL 0 /* no special mapping */ 1964 #define PXLF_MAPFROM 0x0001 /* map From_ to >From_ */ 1965 #define PXLF_STRIP8BIT 0x0002 /* strip 8th bit */ 1966 #define PXLF_HEADER 0x0004 /* map newlines in headers */ 1967 #define PXLF_NOADDEOL 0x0008 /* if EOL not present, don't add one */ 1968 #define PXLF_STRIPMQUOTE 0x0010 /* strip METAQUOTEs */ 1969 1970 /* 1971 ** Privacy flags 1972 ** These are bit values for the PrivacyFlags word. 1973 */ 1974 1975 #define PRIV_PUBLIC 0 /* what have I got to hide? */ 1976 #define PRIV_NEEDMAILHELO 0x00000001 /* insist on HELO for MAIL */ 1977 #define PRIV_NEEDEXPNHELO 0x00000002 /* insist on HELO for EXPN */ 1978 #define PRIV_NEEDVRFYHELO 0x00000004 /* insist on HELO for VRFY */ 1979 #define PRIV_NOEXPN 0x00000008 /* disallow EXPN command */ 1980 #define PRIV_NOVRFY 0x00000010 /* disallow VRFY command */ 1981 #define PRIV_AUTHWARNINGS 0x00000020 /* flag possible auth probs */ 1982 #define PRIV_NOVERB 0x00000040 /* disallow VERB command */ 1983 #define PRIV_RESTRICTMAILQ 0x00010000 /* restrict mailq command */ 1984 #define PRIV_RESTRICTQRUN 0x00020000 /* restrict queue run */ 1985 #define PRIV_RESTRICTEXPAND 0x00040000 /* restrict alias/forward expansion */ 1986 #define PRIV_NOETRN 0x00080000 /* disallow ETRN command */ 1987 #define PRIV_NOBODYRETN 0x00100000 /* do not return bodies on bounces */ 1988 #define PRIV_NORECEIPTS 0x00200000 /* disallow return receipts */ 1989 #define PRIV_NOACTUALRECIPIENT 0x00400000 /* no X-Actual-Recipient in DSNs */ 1990 #define PRIV_NOREFLECTION 0x00800000 /* do not show original command */ 1991 1992 /* don't give no info, anyway, anyhow (in the main SMTP transaction) */ 1993 #define PRIV_GOAWAY (0x0000ffff|PRIV_NOREFLECTION) 1994 1995 /* struct defining such things */ 1996 struct prival 1997 { 1998 char *pv_name; /* name of privacy flag */ 1999 unsigned long pv_flag; /* numeric level */ 2000 }; 2001 2002 EXTERN unsigned long PrivacyFlags; /* privacy flags */ 2003 2004 2005 /* 2006 ** Flags passed to remotename, parseaddr, allocaddr, and buildaddr. 2007 */ 2008 2009 #define RF_SENDERADDR 0x001 /* this is a sender address */ 2010 #define RF_HEADERADDR 0x002 /* this is a header address */ 2011 #define RF_CANONICAL 0x004 /* strip comment information */ 2012 #define RF_ADDDOMAIN 0x008 /* OK to do domain extension */ 2013 #define RF_COPYPARSE 0x010 /* copy parsed user & host */ 2014 #define RF_COPYPADDR 0x020 /* copy print address */ 2015 #define RF_COPYALL (RF_COPYPARSE|RF_COPYPADDR) 2016 #define RF_COPYNONE 0 2017 #define RF_RM_ADDR 0x040 /* address to be removed */ 2018 #define RF_IS_EXT 0x100 /* address is in external format */ 2019 2020 /* 2021 ** Flags passed to rscheck 2022 */ 2023 2024 #define RSF_RMCOMM 0x0001 /* strip comments */ 2025 #define RSF_UNSTRUCTURED 0x0002 /* unstructured, ignore syntax errors */ 2026 #define RSF_COUNT 0x0004 /* count rejections (statistics)? */ 2027 #define RSF_ADDR 0x0008 /* reassemble address */ 2028 #define RSF_STRING 0x0010 /* reassemble address as string */ 2029 #define RSF_STATUS 0x0020 /* log "status" instead of "reject" */ 2030 2031 /* 2032 ** Flags passed to mime8to7 and putheader. 2033 */ 2034 2035 #define M87F_OUTER 0 /* outer context */ 2036 #define M87F_NO8BIT 0x0001 /* can't have 8-bit in this section */ 2037 #define M87F_DIGEST 0x0002 /* processing multipart/digest */ 2038 #define M87F_NO8TO7 0x0004 /* don't do 8->7 bit conversions */ 2039 2040 /* functions */ 2041 extern bool mime7to8 __P((MCI *, HDR *, ENVELOPE *)); 2042 extern int mime8to7 __P((MCI *, HDR *, ENVELOPE *, char **, int, int)); 2043 2044 /* 2045 ** Flags passed to returntosender. 2046 */ 2047 2048 #define RTSF_NO_BODY 0 /* send headers only */ 2049 #define RTSF_SEND_BODY 0x0001 /* include body of message in return */ 2050 #define RTSF_PM_BOUNCE 0x0002 /* this is a postmaster bounce */ 2051 2052 /* functions */ 2053 extern int returntosender __P((char *, ADDRESS *, int, ENVELOPE *)); 2054 2055 /* 2056 ** Mail Filters (milter) 2057 */ 2058 2059 /* 2060 ** 32-bit type used by milter 2061 ** (needed by libmilter even if MILTER isn't defined) 2062 */ 2063 2064 typedef SM_INT32 mi_int32; 2065 2066 #if MILTER 2067 # define SMFTO_WRITE 0 /* Timeout for sending information */ 2068 # define SMFTO_READ 1 /* Timeout waiting for a response */ 2069 # define SMFTO_EOM 2 /* Timeout for ACK/NAK to EOM */ 2070 # define SMFTO_CONNECT 3 /* Timeout for connect() */ 2071 2072 # define SMFTO_NUM_TO 4 /* Total number of timeouts */ 2073 2074 struct milter 2075 { 2076 char *mf_name; /* filter name */ 2077 BITMAP256 mf_flags; /* MTA flags */ 2078 mi_int32 mf_fvers; /* filter version */ 2079 mi_int32 mf_fflags; /* filter flags */ 2080 mi_int32 mf_pflags; /* protocol flags */ 2081 char *mf_conn; /* connection info */ 2082 int mf_sock; /* connected socket */ 2083 char mf_state; /* state of filter */ 2084 char mf_lflags; /* "local" flags */ 2085 int mf_idx; /* milter number (index) */ 2086 time_t mf_timeout[SMFTO_NUM_TO]; /* timeouts */ 2087 # if _FFR_MILTER_CHECK 2088 /* for testing only */ 2089 mi_int32 mf_mta_prot_version; 2090 mi_int32 mf_mta_prot_flags; 2091 mi_int32 mf_mta_actions; 2092 # endif /* _FFR_MILTER_CHECK */ 2093 }; 2094 2095 # define MI_LFL_NONE 0x00000000 2096 # define MI_LFLAGS_SYM(st) (1 << (st)) /* has its own symlist for stage st */ 2097 2098 struct milters 2099 { 2100 mi_int32 mis_flags; /* filter flags */ 2101 }; 2102 typedef struct milters milters_T; 2103 2104 # define MIS_FL_NONE 0x00000000 /* no requirements... */ 2105 # define MIS_FL_DEL_RCPT 0x00000001 /* can delete rcpt */ 2106 # define MIS_FL_REJ_RCPT 0x00000002 /* can reject rcpt */ 2107 2108 2109 /* MTA flags */ 2110 # define SMF_REJECT 'R' /* Reject connection on filter fail */ 2111 # define SMF_TEMPFAIL 'T' /* tempfail connection on failure */ 2112 # define SMF_TEMPDROP '4' /* 421 connection on failure */ 2113 2114 EXTERN struct milter *InputFilters[MAXFILTERS]; 2115 EXTERN char *InputFilterList; 2116 EXTERN int MilterLogLevel; 2117 2118 /* functions */ 2119 extern void setup_daemon_milters __P((void)); 2120 #endif /* MILTER */ 2121 2122 /* 2123 ** Vendor codes 2124 ** 2125 ** Vendors can customize sendmail to add special behaviour, 2126 ** generally for back compatibility. Ideally, this should 2127 ** be set up in the .cf file using the "V" command. However, 2128 ** it's quite reasonable for some vendors to want the default 2129 ** be their old version; this can be set using 2130 ** -DVENDOR_DEFAULT=VENDOR_xxx 2131 ** in the Makefile. 2132 ** 2133 ** Vendors should apply to sendmail-YYYY@support.sendmail.org 2134 ** (replace YYYY with the current year) 2135 ** for unique vendor codes. 2136 */ 2137 2138 #define VENDOR_BERKELEY 1 /* Berkeley-native configuration file */ 2139 #define VENDOR_SUN 2 /* Sun-native configuration file */ 2140 #define VENDOR_HP 3 /* Hewlett-Packard specific config syntax */ 2141 #define VENDOR_IBM 4 /* IBM specific config syntax */ 2142 #define VENDOR_SENDMAIL 5 /* Proofpoint, Inc. specific config syntax */ 2143 #define VENDOR_DEC 6 /* Compaq, DEC, Digital */ 2144 2145 /* prototypes for vendor-specific hook routines */ 2146 extern void vendor_daemon_setup __P((ENVELOPE *)); 2147 extern void vendor_set_uid __P((UID_T)); 2148 2149 2150 /* 2151 ** Terminal escape codes. 2152 ** 2153 ** To make debugging output clearer. 2154 */ 2155 2156 struct termescape 2157 { 2158 char *te_rv_on; /* turn reverse-video on */ 2159 char *te_under_on; /* turn underlining on */ 2160 char *te_normal; /* revert to normal output */ 2161 }; 2162 2163 /* 2164 ** Additional definitions 2165 */ 2166 2167 /* 2168 ** d_flags, see daemon.c 2169 ** general rule: lower case: required, upper case: No 2170 */ 2171 2172 #define D_AUTHREQ 'a' /* authentication required */ 2173 #define D_BINDIF 'b' /* use if_addr for outgoing connection */ 2174 #define D_CANONREQ 'c' /* canonification required (cf) */ 2175 #define D_IFNHELO 'h' /* use if name for HELO */ 2176 #define D_FQMAIL 'f' /* fq sender address required (cf) */ 2177 #define D_FQRCPT 'r' /* fq recipient address required (cf) */ 2178 #define D_SMTPS 's' /* SMTP over SSL (smtps) */ 2179 #define D_UNQUALOK 'u' /* unqualified address is ok (cf) */ 2180 #define D_NOAUTH 'A' /* no AUTH */ 2181 #define D_NOCANON 'C' /* no canonification (cf) */ 2182 #define D_NODANE 'D' /* no DANE (client) */ 2183 #define D_NOETRN 'E' /* no ETRN (MSA) */ 2184 #define D_NOSTS 'M' /* no MTA-STS (client) */ 2185 #define D_NOTLS 'S' /* don't use STARTTLS */ 2186 #define D_ETRNONLY ((char)0x01) /* allow only ETRN (disk low) */ 2187 #define D_OPTIONAL 'O' /* optional socket */ 2188 #define D_DISABLE ((char)0x02) /* optional socket disabled */ 2189 #define D_ISSET ((char)0x03) /* this client struct is set */ 2190 #if _FFR_XCNCT 2191 #define D_XCNCT ((char)0x04) /* X-Connect was used */ 2192 #define D_XCNCT_M ((char)0x05) /* X-Connect was used + "forged" */ 2193 #endif 2194 2195 2196 /* 2197 ** Queue related items 2198 */ 2199 2200 /* queue file names */ 2201 #define ANYQFL_LETTER '?' 2202 #define QUARQF_LETTER 'h' 2203 #define DATAFL_LETTER 'd' 2204 #define XSCRPT_LETTER 'x' 2205 #define NORMQF_LETTER 'q' 2206 #define NEWQFL_LETTER 't' 2207 2208 # define TEMPQF_LETTER 'T' 2209 # define LOSEQF_LETTER 'Q' 2210 2211 /* queue sort order */ 2212 #define QSO_BYPRIORITY 0 /* sort by message priority */ 2213 #define QSO_BYHOST 1 /* sort by first host name */ 2214 #define QSO_BYTIME 2 /* sort by submission time */ 2215 #define QSO_BYFILENAME 3 /* sort by file name only */ 2216 #define QSO_RANDOM 4 /* sort in random order */ 2217 #define QSO_BYMODTIME 5 /* sort by modification time */ 2218 #define QSO_NONE 6 /* do not sort */ 2219 #if _FFR_RHS 2220 # define QSO_BYSHUFFLE 7 /* sort by shuffled host name */ 2221 #endif 2222 2223 #define NOQGRP (-1) /* no queue group (yet) */ 2224 #define ENVQGRP (-2) /* use queue group of envelope */ 2225 #define NOAQGRP (-3) /* no queue group in addr (yet) */ 2226 #define ISVALIDQGRP(x) ((x) >= 0) /* valid queue group? */ 2227 #define NOQDIR (-1) /* no queue directory (yet) */ 2228 #define ENVQDIR (-2) /* use queue directory of envelope */ 2229 #define NOAQDIR (-3) /* no queue directory in addr (yet) */ 2230 #define ISVALIDQDIR(x) ((x) >= 0) /* valid queue directory? */ 2231 #define RS_QUEUEGROUP "queuegroup" /* ruleset for queue group selection */ 2232 2233 #define NOW ((time_t) (-1)) /* queue return: now */ 2234 2235 /* SuperSafe values */ 2236 #define SAFE_NO 0 /* no fsync(): don't use... */ 2237 #define SAFE_INTERACTIVE 1 /* limit fsync() in -odi */ 2238 #define SAFE_REALLY 2 /* always fsync() */ 2239 #define SAFE_REALLY_POSTMILTER 3 /* fsync() if milter says OK */ 2240 2241 /* QueueMode bits */ 2242 #define QM_NORMAL ' ' 2243 #define QM_QUARANTINE 'Q' 2244 #define QM_LOST 'L' 2245 2246 /* Queue Run Limitations */ 2247 struct queue_char 2248 { 2249 char *queue_match; /* string to match */ 2250 bool queue_negate; /* or not match, if set */ 2251 struct queue_char *queue_next; 2252 }; 2253 2254 /* run_work_group() flags */ 2255 #define RWG_NONE 0x0000 2256 #define RWG_FORK 0x0001 2257 #define RWG_VERBOSE 0x0002 2258 #define RWG_PERSISTENT 0x0004 2259 #define RWG_FORCE 0x0008 2260 #define RWG_RUNALL 0x0010 2261 2262 typedef struct queue_char QUEUE_CHAR; 2263 2264 EXTERN int volatile CurRunners; /* current number of runner children */ 2265 EXTERN int MaxQueueRun; /* maximum number of jobs in one queue run */ 2266 EXTERN int MaxQueueChildren; /* max # of forked queue children */ 2267 EXTERN int MaxRunnersPerQueue; /* max # proc's active in queue group */ 2268 EXTERN int NiceQueueRun; /* nice queue runs to this value */ 2269 EXTERN int NumQueue; /* number of queue groups */ 2270 EXTERN int QueueFileMode; /* mode on files in mail queue */ 2271 EXTERN int QueueMode; /* which queue items to act upon */ 2272 EXTERN int QueueSortOrder; /* queue sorting order algorithm */ 2273 EXTERN time_t MinQueueAge; /* min delivery interval */ 2274 EXTERN time_t MaxQueueAge; /* max delivery interval */ 2275 EXTERN time_t QueueIntvl; /* intervals between running the queue */ 2276 EXTERN char *QueueDir; /* location of queue directory */ 2277 EXTERN QUEUE_CHAR *QueueLimitId; /* limit queue run to id */ 2278 EXTERN QUEUE_CHAR *QueueLimitQuarantine; /* limit queue run to quarantine reason */ 2279 EXTERN QUEUE_CHAR *QueueLimitRecipient; /* limit queue run to rcpt */ 2280 EXTERN QUEUE_CHAR *QueueLimitSender; /* limit queue run to sender */ 2281 EXTERN QUEUEGRP *Queue[MAXQUEUEGROUPS + 1]; /* queue groups */ 2282 #if _FFR_BOUNCE_QUEUE 2283 EXTERN int BounceQueue; 2284 #endif 2285 2286 /* functions */ 2287 extern void assign_queueid __P((ENVELOPE *)); 2288 extern ADDRESS *copyqueue __P((ADDRESS *, SM_RPOOL_T *)); 2289 extern void cleanup_queues __P((void)); 2290 extern bool doqueuerun __P((void)); 2291 extern void initsys __P((ENVELOPE *)); 2292 extern void loseqfile __P((ENVELOPE *, char *)); 2293 extern int name2qid __P((char *)); 2294 extern char *qid_printname __P((ENVELOPE *)); 2295 extern char *qid_printqueue __P((int, int)); 2296 extern void quarantine_queue __P((char *, int)); 2297 extern char *queuename __P((ENVELOPE *, int)); 2298 extern void queueup __P((ENVELOPE *, unsigned int)); 2299 extern bool runqueue __P((bool, bool, bool, bool)); 2300 extern bool run_work_group __P((int, int)); 2301 extern void set_def_queueval __P((QUEUEGRP *, bool)); 2302 extern void setup_queues __P((bool)); 2303 extern bool setnewqueue __P((ENVELOPE *)); 2304 extern bool shouldqueue __P((long, time_t)); 2305 extern void sync_queue_time __P((void)); 2306 extern void init_qid_alg __P((void)); 2307 extern int print_single_queue __P((int, int)); 2308 #if REQUIRES_DIR_FSYNC 2309 # define SYNC_DIR(path, panic) sync_dir(path, panic) 2310 extern void sync_dir __P((char *, bool)); 2311 #else 2312 # define SYNC_DIR(path, panic) ((void) 0) 2313 #endif 2314 #if _FFR_DMTRIGGER 2315 extern bool qm __P((void)); 2316 extern int deliver __P((ENVELOPE *, ADDRESS *)); 2317 #endif 2318 2319 /* 2320 ** Timeouts 2321 ** 2322 ** Indicated values are the MINIMUM per RFC 1123 section 5.3.2. 2323 */ 2324 2325 EXTERN struct 2326 { 2327 /* RFC 1123-specified timeouts [minimum value] */ 2328 time_t to_initial; /* initial greeting timeout [5m] */ 2329 time_t to_mail; /* MAIL command [5m] */ 2330 time_t to_rcpt; /* RCPT command [5m] */ 2331 time_t to_datainit; /* DATA initiation [2m] */ 2332 time_t to_datablock; /* DATA block [3m] */ 2333 time_t to_datafinal; /* DATA completion [10m] */ 2334 time_t to_nextcommand; /* next command [5m] */ 2335 /* following timeouts are not mentioned in RFC 1123 */ 2336 time_t to_iconnect; /* initial connection timeout (first try) */ 2337 time_t to_connect; /* initial connection timeout (later tries) */ 2338 time_t to_aconnect; /* all connections timeout (MX and A records) */ 2339 time_t to_rset; /* RSET command */ 2340 time_t to_helo; /* HELO command */ 2341 time_t to_quit; /* QUIT command */ 2342 time_t to_miscshort; /* misc short commands (NOOP, VERB, etc) */ 2343 time_t to_ident; /* IDENT protocol requests */ 2344 time_t to_fileopen; /* opening :include: and .forward files */ 2345 time_t to_control; /* process a control socket command */ 2346 time_t to_lhlo; /* LMTP: LHLO command */ 2347 #if SASL 2348 time_t to_auth; /* AUTH dialogue [10m] */ 2349 #endif 2350 #if STARTTLS 2351 time_t to_starttls; /* STARTTLS dialogue [10m] */ 2352 #endif 2353 /* following are per message */ 2354 time_t to_q_return[MAXTOCLASS]; /* queue return timeouts */ 2355 time_t to_q_warning[MAXTOCLASS]; /* queue warning timeouts */ 2356 time_t res_retrans[MAXRESTOTYPES]; /* resolver retransmit */ 2357 int res_retry[MAXRESTOTYPES]; /* resolver retry */ 2358 } TimeOuts; 2359 2360 /* timeout classes for return and warning timeouts */ 2361 #define TOC_NORMAL 0 /* normal delivery */ 2362 #define TOC_URGENT 1 /* urgent delivery */ 2363 #define TOC_NONURGENT 2 /* non-urgent delivery */ 2364 #define TOC_DSN 3 /* DSN delivery */ 2365 2366 /* resolver timeout specifiers */ 2367 #define RES_TO_FIRST 0 /* first attempt */ 2368 #define RES_TO_NORMAL 1 /* subsequent attempts */ 2369 #define RES_TO_DEFAULT 2 /* default value */ 2370 2371 /* functions */ 2372 extern void inittimeouts __P((char *, bool)); 2373 2374 /* 2375 ** Interface probing 2376 */ 2377 2378 #define DPI_PROBENONE 0 /* Don't probe any interfaces */ 2379 #define DPI_PROBEALL 1 /* Probe all interfaces */ 2380 #define DPI_SKIPLOOPBACK 2 /* Don't probe loopback interfaces */ 2381 2382 /* 2383 ** Trace information 2384 */ 2385 2386 /* macros for debugging flags */ 2387 #if NOT_SENDMAIL 2388 # define tTd(flag, level) (tTdvect[flag] >= (unsigned char)level) 2389 #else 2390 # define tTd(flag, level) (tTdvect[flag] >= (unsigned char)level && !IntSig) 2391 # if _FFR_TESTS 2392 # define TTD(flag, level) (tTdvect[flag] >= (unsigned char)level && !IntSig) 2393 # else 2394 # define TTD(flag, level) false 2395 # endif 2396 #endif 2397 #define tTdlevel(flag) (tTdvect[flag]) 2398 2399 /* variables */ 2400 extern unsigned char tTdvect[100]; /* trace vector */ 2401 2402 /* 2403 ** Miscellaneous information. 2404 */ 2405 2406 /* 2407 ** The "no queue id" queue id for sm_syslog 2408 */ 2409 2410 #define NOQID "" 2411 2412 #define CURHOSTNAME (CurHostName == NULL ? "local" : CurHostName) 2413 2414 /* 2415 ** Some in-line functions 2416 */ 2417 2418 /* set exit status */ 2419 #define setstat(s) \ 2420 do \ 2421 { \ 2422 if (ExitStat == EX_OK || ExitStat == EX_TEMPFAIL) \ 2423 ExitStat = s; \ 2424 } while (0) 2425 2426 2427 #define STRUCTCOPY(s, d) d = s 2428 2429 /* 2430 ** Update a permanent string variable with a new value. 2431 ** The old value is freed, the new value is strdup'ed. 2432 ** 2433 ** We use sm_pstrdup_x to duplicate the string because it raises 2434 ** an exception on error, and because it allocates "permanent storage" 2435 ** which is not expected to be freed before process exit. 2436 ** The latter is important for memory leak analysis. 2437 ** 2438 ** If an exception occurs while strdup'ing the new value, 2439 ** then the variable remains set to the old value. 2440 ** That's why the strdup must occur before we free the old value. 2441 */ 2442 #define PSTRSET(var, val) \ 2443 do \ 2444 { \ 2445 char *_newval = sm_pstrdup_x(val); \ 2446 if (var != NULL) \ 2447 sm_free(var); \ 2448 var = _newval; \ 2449 } while (0) 2450 2451 #define _CHECK_RESTART \ 2452 do \ 2453 { \ 2454 if (ShutdownRequest != NULL) \ 2455 shutdown_daemon(); \ 2456 else if (RestartRequest != NULL) \ 2457 restart_daemon(); \ 2458 else if (RestartWorkGroup) \ 2459 restart_marked_work_groups(); \ 2460 } while (0) 2461 2462 # define CHECK_RESTART _CHECK_RESTART 2463 2464 #define CHK_CUR_RUNNERS(fct, idx, count) \ 2465 do \ 2466 { \ 2467 if (CurRunners < 0) \ 2468 { \ 2469 if (LogLevel > 3) \ 2470 sm_syslog(LOG_ERR, NOQID, \ 2471 "%s: CurRunners=%d, i=%d, count=%d, status=should not happen", \ 2472 fct, CurRunners, idx, count); \ 2473 CurRunners = 0; \ 2474 } \ 2475 } while (0) 2476 2477 /* reply types (text in SmtpMsgBuffer) */ 2478 /* XREF: deliver.c: xs_states[] -- any changes here must be reflected there! */ 2479 #define XS_DEFAULT 0 /* other commands, e.g., RSET */ 2480 #define XS_STARTTLS 1 2481 #define XS_AUTH 2 2482 #define XS_GREET 3 2483 #define XS_EHLO 4 2484 #define XS_MAIL 5 2485 #define XS_RCPT 6 2486 #define XS_DATA 7 2487 #define XS_EOM 8 2488 #define XS_DATA2 9 /* LMTP */ 2489 #define XS_QUIT 10 2490 2491 /* 2492 ** Global variables. 2493 */ 2494 2495 #if _FFR_ADD_BCC 2496 EXTERN bool AddBcc; 2497 #endif 2498 #if _FFR_ADDR_TYPE_MODES 2499 EXTERN bool AddrTypeModes; /* addr_type: extra "mode" information */ 2500 #endif 2501 EXTERN bool AllowBogusHELO; /* allow syntax errors on HELO command */ 2502 EXTERN bool CheckAliases; /* parse addresses during newaliases */ 2503 #if _FFR_QUEUE_RUN_PARANOIA 2504 EXTERN int CheckQueueRunners; /* check whether queue runners are OK */ 2505 #endif 2506 EXTERN bool ColonOkInAddr; /* single colon legal in address */ 2507 #if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) 2508 EXTERN bool ConfigFileRead; /* configuration file has been read */ 2509 #endif 2510 EXTERN bool DisConnected; /* running with OutChannel redirect to transcript file */ 2511 EXTERN bool DontExpandCnames; /* do not $[...$] expand CNAMEs */ 2512 EXTERN bool DontInitGroups; /* avoid initgroups() because of NIS cost */ 2513 EXTERN bool DontLockReadFiles; /* don't read lock support files */ 2514 EXTERN bool DontPruneRoutes; /* don't prune source routes */ 2515 EXTERN bool ForkQueueRuns; /* fork for each job when running the queue */ 2516 EXTERN bool FromFlag; /* if set, "From" person is explicit */ 2517 EXTERN bool FipsMode; 2518 EXTERN bool GrabTo; /* if set, get recipients from msg */ 2519 #if _FFR_EIGHT_BIT_ADDR_OK 2520 EXTERN bool EightBitAddrOK; /* we'll let 8-bit addresses through */ 2521 #else 2522 # define EightBitAddrOK false 2523 #endif 2524 EXTERN bool HasEightBits; /* has at least one eight bit input byte */ 2525 EXTERN bool HasWildcardMX; /* don't use MX records when canonifying */ 2526 EXTERN bool HoldErrs; /* only output errors to transcript */ 2527 EXTERN bool IgnoreHostStatus; /* ignore long term host status files */ 2528 EXTERN bool IgnrDot; /* don't let dot end messages */ 2529 #if _FFR_KEEPBCC 2530 EXTERN bool KeepBcc; 2531 #else 2532 # define KeepBcc false 2533 #endif 2534 EXTERN bool LogUsrErrs; /* syslog user errors (e.g., SMTP RCPT cmd) */ 2535 EXTERN bool MatchGecos; /* look for user names in gecos field */ 2536 EXTERN bool MeToo; /* send to the sender also */ 2537 EXTERN bool NoAlias; /* suppress aliasing */ 2538 EXTERN bool NoConnect; /* don't connect to non-local mailers */ 2539 EXTERN bool OnlyOneError; /* .... or only want to give one SMTP reply */ 2540 EXTERN bool QuickAbort; /* .... but only if we want a quick abort */ 2541 #if _FFR_REJECT_NUL_BYTE 2542 EXTERN bool RejectNUL; /* reject NUL input byte? */ 2543 #endif 2544 #if REQUIRES_DIR_FSYNC 2545 EXTERN bool RequiresDirfsync; /* requires fsync() for directory */ 2546 #endif 2547 EXTERN bool volatile RestartWorkGroup; /* daemon needs to restart some work groups */ 2548 EXTERN bool RrtImpliesDsn; /* turn Return-Receipt-To: into DSN */ 2549 EXTERN bool SaveFrom; /* save leading "From" lines */ 2550 EXTERN bool SendMIMEErrors; /* send error messages in MIME format */ 2551 EXTERN bool SevenBitInput; /* force 7-bit data on input */ 2552 EXTERN bool SingleLineFromHeader; /* force From: header to be one line */ 2553 EXTERN bool SingleThreadDelivery; /* single thread hosts on delivery */ 2554 EXTERN bool SoftBounce; /* replace 5xy by 4xy (for testing) */ 2555 EXTERN bool volatile StopRequest; /* stop sending output */ 2556 EXTERN bool SuprErrs; /* set if we are suppressing errors */ 2557 EXTERN bool TryNullMXList; /* if we are the best MX, try host directly */ 2558 EXTERN bool UseMSP; /* mail submission: group writable queue ok? */ 2559 EXTERN bool WorkAroundBrokenAAAA; /* some nameservers return SERVFAIL on AAAA queries */ 2560 EXTERN bool UseErrorsTo; /* use Errors-To: header (back compat) */ 2561 EXTERN bool UseNameServer; /* using DNS -- interpret h_errno & MX RRs */ 2562 EXTERN bool UseCompressedIPv6Addresses; /* for more specific zero-subnet matches */ 2563 EXTERN char InetMode; /* default network for daemon mode */ 2564 EXTERN char OpMode; /* operation mode, see below */ 2565 EXTERN char SpaceSub; /* substitution for <lwsp> */ 2566 #if _FFR_BADRCPT_SHUTDOWN 2567 EXTERN int BadRcptShutdown; /* Shutdown connection for rejected RCPTs */ 2568 EXTERN int BadRcptShutdownGood; /* above even when there are good RCPTs */ 2569 #endif 2570 EXTERN int BadRcptThrottle; /* Throttle rejected RCPTs per SMTP message */ 2571 #if _FFR_RCPTTHROTDELAY 2572 EXTERN unsigned int BadRcptThrottleDelay; /* delay for BadRcptThrottle */ 2573 #else 2574 # define BadRcptThrottleDelay 1 2575 #endif 2576 #if _FFR_TLS_ALTNAMES 2577 EXTERN bool SetCertAltnames; 2578 #endif 2579 EXTERN int CheckpointInterval; /* queue file checkpoint interval */ 2580 EXTERN int ConfigLevel; /* config file level */ 2581 EXTERN int ConnRateThrottle; /* throttle for SMTP connection rate */ 2582 EXTERN int volatile CurChildren; /* current number of daemonic children */ 2583 EXTERN int CurrentLA; /* current load average */ 2584 #if DANE 2585 EXTERN int Dane; /* DANE */ 2586 #else 2587 # define Dane 0 /* XREF: see tls.h: #define DANE_NEVER */ 2588 #endif 2589 EXTERN int DefaultNotify; /* default DSN notification flags */ 2590 EXTERN int DelayLA; /* load average to delay connections */ 2591 EXTERN int DontProbeInterfaces; /* don't probe interfaces for names */ 2592 EXTERN int Errors; /* set if errors (local to single pass) */ 2593 EXTERN int ExitStat; /* exit status code */ 2594 EXTERN int FastSplit; /* fast initial splitting of envelopes */ 2595 EXTERN int FileMode; /* mode on files */ 2596 EXTERN int LineNumber; /* line number in current input */ 2597 EXTERN int LogLevel; /* level of logging to perform */ 2598 EXTERN int MaxAliasRecursion; /* maximum depth of alias recursion */ 2599 EXTERN int MaxChildren; /* maximum number of daemonic children */ 2600 EXTERN int MaxForwardEntries; /* maximum number of forward entries */ 2601 EXTERN int MaxHeadersLength; /* max length of headers */ 2602 EXTERN int MaxHopCount; /* max # of hops until bounce */ 2603 EXTERN int MaxMacroRecursion; /* maximum depth of macro recursion */ 2604 EXTERN int MaxMimeFieldLength; /* maximum MIME field length */ 2605 EXTERN int MaxMimeHeaderLength; /* maximum MIME header length */ 2606 EXTERN int MaxNOOPCommands; /* max "noise" commands before slowdown */ 2607 2608 EXTERN int MaxRcptPerMsg; /* max recipients per SMTP message */ 2609 EXTERN int MaxRuleRecursion; /* maximum depth of ruleset recursion */ 2610 #if _FFR_MSG_ACCEPT 2611 EXTERN char *MessageAccept; /* "Message accepted for delivery" reply text */ 2612 #endif 2613 2614 EXTERN int MimeMode; /* MIME processing mode */ 2615 #if _FFR_MTA_STS 2616 EXTERN bool MTASTS; 2617 EXTERN char *STS_SNI; 2618 #endif 2619 EXTERN int NoRecipientAction; 2620 2621 #if SM_CONF_SHM 2622 EXTERN int Numfilesys; /* number of queue file systems */ 2623 EXTERN int *PNumFileSys; 2624 # define NumFileSys (*PNumFileSys) 2625 #else /* SM_CONF_SHM */ 2626 EXTERN int NumFileSys; /* number of queue file systems */ 2627 #endif /* SM_CONF_SHM */ 2628 2629 EXTERN int QueueLA; /* load average starting forced queueing */ 2630 EXTERN int RefuseLA; /* load average refusing connections */ 2631 EXTERN time_t RejectLogInterval; /* time btwn log msgs while refusing */ 2632 #if _FFR_MEMSTAT 2633 EXTERN long QueueLowMem; /* low memory starting forced queueing */ 2634 EXTERN long RefuseLowMem; /* low memory refusing connections */ 2635 EXTERN char *MemoryResource;/* memory resource to look up */ 2636 #endif /* _FFR_MEMSTAT */ 2637 EXTERN int SuperSafe; /* be extra careful, even if expensive */ 2638 #if USE_EAI 2639 EXTERN int SMTP_UTF8; /* enable SMTPUTF8 support */ 2640 #else 2641 # define SMTP_UTF8 false 2642 #endif 2643 EXTERN int VendorCode; /* vendor-specific operation enhancements */ 2644 EXTERN int Verbose; /* set if blow-by-blow desired */ 2645 EXTERN gid_t DefGid; /* default gid to run as */ 2646 EXTERN gid_t RealGid; /* real gid of caller */ 2647 EXTERN gid_t RunAsGid; /* GID to become for bulk of run */ 2648 EXTERN gid_t EffGid; /* effective gid */ 2649 #if SM_CONF_SHM 2650 EXTERN key_t ShmKey; /* shared memory key */ 2651 EXTERN char *ShmKeyFile; /* shared memory key file */ 2652 #endif 2653 EXTERN pid_t CurrentPid; /* current process id */ 2654 EXTERN pid_t DaemonPid; /* process id of daemon */ 2655 EXTERN pid_t PidFilePid; /* daemon/queue runner who wrote pid file */ 2656 EXTERN uid_t DefUid; /* default uid to run as */ 2657 EXTERN uid_t RealUid; /* real uid of caller */ 2658 EXTERN uid_t RunAsUid; /* UID to become for bulk of run */ 2659 EXTERN uid_t TrustedUid; /* uid of trusted user for files and startup */ 2660 EXTERN size_t DataFileBufferSize; /* size of buf for in-core data file */ 2661 EXTERN time_t DeliverByMin; /* deliver by minimum time */ 2662 EXTERN time_t DialDelay; /* delay between dial-on-demand tries */ 2663 EXTERN time_t SafeAlias; /* interval to wait until @:@ in alias file */ 2664 EXTERN time_t ServiceCacheMaxAge; /* refresh interval for cache */ 2665 EXTERN size_t XscriptFileBufferSize; /* size of buf for in-core transcript file */ 2666 EXTERN MODE_T OldUmask; /* umask when sendmail starts up */ 2667 EXTERN long MaxMessageSize; /* advertised max size we will accept */ 2668 EXTERN long MinBlocksFree; /* min # of blocks free on queue fs */ 2669 EXTERN long QueueFactor; /* slope of queue function */ 2670 EXTERN long WkClassFact; /* multiplier for message class -> priority */ 2671 EXTERN long WkRecipFact; /* multiplier for # of recipients -> priority */ 2672 EXTERN long WkTimeFact; /* priority offset each time this job is run */ 2673 EXTERN char *ControlSocketName; /* control socket filename [control.c] */ 2674 EXTERN char *CurHostName; /* current host we are dealing with */ 2675 EXTERN char *DeadLetterDrop; /* path to dead letter office */ 2676 EXTERN char *DefUser; /* default user to run as (from DefUid) */ 2677 EXTERN char *DefaultCharSet; /* default character set for MIME */ 2678 EXTERN char *DoubleBounceAddr; /* where to send double bounces */ 2679 EXTERN char *ErrMsgFile; /* file to prepend to all error messages */ 2680 EXTERN char *FallbackMX; /* fall back MX host */ 2681 EXTERN char *FallbackSmartHost; /* fall back smart host */ 2682 EXTERN char *FileName; /* name to print on error messages */ 2683 EXTERN char *ForwardPath; /* path to search for .forward files */ 2684 EXTERN char *HeloName; /* hostname to announce in HELO */ 2685 EXTERN char *HelpFile; /* location of SMTP help file */ 2686 EXTERN char *HostStatDir; /* location of host status information */ 2687 EXTERN char *HostsFile; /* path to /etc/hosts file */ 2688 extern char *Mbdb; /* mailbox database type */ 2689 EXTERN char *MustQuoteChars; /* quote these characters in phrases */ 2690 EXTERN char *MyHostName; /* name of this host for SMTP messages */ 2691 EXTERN char *OperatorChars; /* operators (old $o macro) */ 2692 EXTERN char *PidFile; /* location of proc id file [conf.c] */ 2693 EXTERN char *PostMasterCopy; /* address to get errs cc's */ 2694 EXTERN char *ProcTitlePrefix; /* process title prefix */ 2695 EXTERN char *RealHostName; /* name of host we are talking to */ 2696 EXTERN char *RealUserName; /* real user name of caller */ 2697 EXTERN char *volatile RestartRequest;/* a sendmail restart has been requested */ 2698 EXTERN char *RunAsUserName; /* user to become for bulk of run */ 2699 EXTERN char *SafeFileEnv; /* chroot location for file delivery */ 2700 EXTERN char *ServiceSwitchFile; /* backup service switch */ 2701 EXTERN char *volatile ShutdownRequest;/* a sendmail shutdown has been requested */ 2702 EXTERN bool volatile IntSig; 2703 EXTERN char *SmtpGreeting; /* SMTP greeting message (old $e macro) */ 2704 EXTERN char *SmtpPhase; /* current phase in SMTP processing */ 2705 EXTERN char SmtpError[MAXLINE]; /* save failure error messages */ 2706 EXTERN char *StatFile; /* location of statistics summary */ 2707 EXTERN char *TimeZoneSpec; /* override time zone specification */ 2708 EXTERN char *UdbSpec; /* user database source spec */ 2709 EXTERN char *UnixFromLine; /* UNIX From_ line (old $l macro) */ 2710 EXTERN char **ExternalEnviron; /* saved user (input) environment */ 2711 EXTERN char **SaveArgv; /* argument vector for re-execing */ 2712 EXTERN BITMAP256 DontBlameSendmail; /* DontBlameSendmail bits */ 2713 EXTERN SM_FILE_T *InChannel; /* input connection */ 2714 EXTERN SM_FILE_T *OutChannel; /* output connection */ 2715 EXTERN SM_FILE_T *TrafficLogFile; /* file in which to log all traffic */ 2716 #if HESIOD 2717 EXTERN void *HesiodContext; 2718 #endif 2719 EXTERN ENVELOPE *CurEnv; /* envelope currently being processed */ 2720 EXTERN char *RuleSetNames[MAXRWSETS]; /* ruleset number to name */ 2721 EXTERN char *UserEnviron[MAXUSERENVIRON + 1]; 2722 EXTERN struct rewrite *RewriteRules[MAXRWSETS]; 2723 EXTERN struct termescape TermEscape; /* terminal escape codes */ 2724 EXTERN SOCKADDR ConnectOnlyTo; /* override connection address (for testing) */ 2725 EXTERN SOCKADDR RealHostAddr; /* address of host we are talking to */ 2726 extern const SM_EXC_TYPE_T EtypeQuickAbort; /* type of a QuickAbort exception */ 2727 2728 #if _FFR_BLANKENV_MACV 2729 EXTERN int Hacks; /* bit field of run-time enabled "hacks" */ 2730 # define H_LOOKUP_MACRO_IN_BLANKENV 0x0001 2731 # define LOOKUP_MACRO_IN_BLANKENV (Hacks & H_LOOKUP_MACRO_IN_BLANKENV) 2732 #else 2733 # define LOOKUP_MACRO_IN_BLANKENV false 2734 #endif 2735 2736 EXTERN int ConnectionRateWindowSize; 2737 2738 /* 2739 ** Declarations of useful functions 2740 */ 2741 2742 /* Transcript file */ 2743 extern void closexscript __P((ENVELOPE *)); 2744 extern void openxscript __P((ENVELOPE *)); 2745 2746 #if SM_DEVELOPER 2747 #define NR_PRINTFLIKE(a, b) PRINTFLIKE(a, b) 2748 #else 2749 #define NR_PRINTFLIKE(a, b) 2750 #endif 2751 2752 /* error related */ 2753 extern void buffer_errors __P((void)); 2754 extern void flush_errors __P((bool)); 2755 extern void NR_PRINTFLIKE(1, 2) message __P((const char *, ...)); 2756 extern void NR_PRINTFLIKE(1, 2) nmessage __P((const char *, ...)); 2757 #if _FFR_PROXY 2758 extern void NR_PRINTFLIKE(3, 4) emessage __P((const char *, const char *, const char *, ...)); 2759 extern int extsc __P((const char *, int, char *, char *)); 2760 #endif 2761 extern void NR_PRINTFLIKE(1, 2) syserr __P((const char *, ...)); 2762 extern void NR_PRINTFLIKE(2, 3) usrerrenh __P((char *, const char *, ...)); 2763 extern void NR_PRINTFLIKE(1, 2) usrerr __P((const char *, ...)); 2764 extern int isenhsc __P((const char *, int)); 2765 extern int extenhsc __P((const char *, int, char *)); 2766 extern int skipaddrhost __P((const char *, bool)); 2767 2768 /* alias file */ 2769 extern void alias __P((ADDRESS *, ADDRESS **, int, ENVELOPE *)); 2770 extern bool aliaswait __P((MAP *, const char *, bool)); 2771 extern void forward __P((ADDRESS *, ADDRESS **, int, ENVELOPE *)); 2772 extern void readaliases __P((MAP *, SM_FILE_T *, bool, bool)); 2773 extern bool rebuildaliases __P((MAP *)); 2774 extern void setalias __P((char *)); 2775 2776 /* logging */ 2777 extern void logdelivery __P((MAILER *, MCI *, char *, const char *, ADDRESS *, time_t, ENVELOPE *, ADDRESS *, int)); 2778 extern void logsender __P((ENVELOPE *, char *)); 2779 extern void PRINTFLIKE(3, 4) sm_syslog __P((int, const char *, const char *, ...)); 2780 2781 /* SMTP */ 2782 extern void giveresponse __P((int, char *, MAILER *, MCI *, ADDRESS *, time_t, ENVELOPE *, ADDRESS *)); 2783 extern int reply __P((MAILER *, MCI *, ENVELOPE *, time_t, void (*)__P((char *, bool, MAILER *, MCI *, ENVELOPE *)), char **, int, char **)); 2784 extern void smtp __P((char *volatile, BITMAP256, ENVELOPE *volatile)); 2785 #if SASL 2786 extern int smtpauth __P((MAILER *, MCI *, ENVELOPE *)); 2787 #endif 2788 extern void smtpclrse __P((ENVELOPE *)); 2789 extern int smtpdata __P((MAILER *, MCI *, ENVELOPE *, ADDRESS *, time_t)); 2790 extern int smtpgetstat __P((MAILER *, MCI *, ENVELOPE *)); 2791 extern int smtpmailfrom __P((MAILER *, MCI *, ENVELOPE *)); 2792 extern void smtpmessage __P((char *, MAILER *, MCI *, ...)); 2793 extern void smtpinit __P((MAILER *, MCI *, ENVELOPE *, bool)); 2794 extern char *smtptodsn __P((int)); 2795 extern int smtpprobe __P((MCI *)); 2796 extern void smtpquit __P((MAILER *, MCI *, ENVELOPE *)); 2797 extern int smtprcpt __P((ADDRESS *, MAILER *, MCI *, ENVELOPE *, ADDRESS *, time_t)); 2798 extern void smtprset __P((MAILER *, MCI *, ENVELOPE *)); 2799 2800 #define REPLYTYPE(r) ((r) / 100) /* first digit of reply code */ 2801 #define REPLYCLASS(r) (((r) / 10) % 10) /* second digit of reply code */ 2802 #define REPLYMINOR(r) ((r) % 10) /* last digit of reply code */ 2803 #define ISSMTPCODE(c) (isascii(c[0]) && isdigit(c[0]) && \ 2804 isascii(c[1]) && isdigit(c[1]) && \ 2805 isascii(c[2]) && isdigit(c[2])) 2806 #define ISSMTPREPLY(c) (ISSMTPCODE(c) && \ 2807 (c[3] == ' ' || c[3] == '-' || c[3] == '\0')) 2808 #define SM_ISSPACE(c) (isascii(c) && isspace(c)) 2809 2810 /* delivery */ 2811 extern pid_t dowork __P((int, int, char *, bool, bool, ENVELOPE *)); 2812 extern pid_t doworklist __P((ENVELOPE *, bool, bool)); 2813 extern int endmailer __P((MCI *, ENVELOPE *, char **)); 2814 extern int mailfile __P((char *volatile, MAILER *volatile, ADDRESS *, volatile long, ENVELOPE *)); 2815 extern void sendall __P((ENVELOPE *, int)); 2816 2817 /* stats */ 2818 #define STATS_NORMAL 'n' 2819 #define STATS_QUARANTINE 'q' 2820 #define STATS_REJECT 'r' 2821 #define STATS_CONNECT 'c' 2822 2823 extern void markstats __P((ENVELOPE *, ADDRESS *, int)); 2824 extern void clearstats __P((void)); 2825 extern void poststats __P((char *)); 2826 2827 /* control socket */ 2828 extern void closecontrolsocket __P((bool)); 2829 extern void clrcontrol __P((void)); 2830 extern void control_command __P((int, ENVELOPE *)); 2831 extern int opencontrolsocket __P((void)); 2832 2833 #if MILTER 2834 /* milter functions */ 2835 extern void milter_config __P((char *, struct milter **, int)); 2836 extern void milter_setup __P((char *)); 2837 extern void milter_set_option __P((char *, char *, bool)); 2838 extern bool milter_init __P((ENVELOPE *, char *, milters_T *)); 2839 extern void milter_quit __P((ENVELOPE *)); 2840 extern void milter_abort __P((ENVELOPE *)); 2841 extern char *milter_connect __P((char *, SOCKADDR, ENVELOPE *, char *)); 2842 extern char *milter_helo __P((char *, ENVELOPE *, char *)); 2843 extern char *milter_envfrom __P((char **, ENVELOPE *, char *)); 2844 extern char *milter_data_cmd __P((ENVELOPE *, char *)); 2845 extern char *milter_envrcpt __P((char **, ENVELOPE *, char *, bool)); 2846 extern char *milter_data __P((ENVELOPE *, char *)); 2847 extern char *milter_unknown __P((char *, ENVELOPE *, char *)); 2848 #endif /* MILTER */ 2849 2850 extern char *addquotes __P((char *, SM_RPOOL_T *)); 2851 extern char *arpadate __P((char *)); 2852 extern bool atobool __P((char *)); 2853 extern int atooct __P((char *)); 2854 extern void auth_warning __P((ENVELOPE *, const char *, ...)); 2855 extern int blocksignal __P((int)); 2856 extern bool bitintersect __P((BITMAP256, BITMAP256)); 2857 extern bool bitzerop __P((BITMAP256)); 2858 extern int check_bodytype __P((char *)); 2859 extern void buildfname __P((char *, char *, char *, int)); 2860 extern bool chkclientmodifiers __P((int)); 2861 extern bool chkdaemonmodifiers __P((int)); 2862 extern int checkcompat __P((ADDRESS *, ENVELOPE *)); 2863 #if XDEBUG 2864 extern void checkfd012 __P((char *)); 2865 extern void checkfdopen __P((int, char *)); 2866 #else 2867 # define checkfd012(str) ((void) 0) 2868 # define checkfdopen(n, str) ((void) 0) 2869 #endif 2870 extern void checkfds __P((char *)); 2871 extern bool chownsafe __P((int, bool)); 2872 extern void cleanstrcpy __P((char *, char *, int)); 2873 #if SM_CONF_SHM 2874 extern void cleanup_shm __P((bool)); 2875 #endif 2876 extern void close_sendmail_pid __P((void)); 2877 extern void clrdaemon __P((void)); 2878 extern void collect __P((SM_FILE_T *, int, HDR **, ENVELOPE *, bool)); 2879 extern time_t convtime __P((char *, int)); 2880 extern char **copyplist __P((char **, bool, SM_RPOOL_T *)); 2881 extern void copy_class __P((int, int)); 2882 extern int count_open_connections __P((SOCKADDR *)); 2883 extern time_t curtime __P((void)); 2884 extern char *defcharset __P((ENVELOPE *)); 2885 extern char *denlstring __P((char *, bool, bool)); 2886 extern void dferror __P((SM_FILE_T *volatile, char *, ENVELOPE *)); 2887 extern void disconnect __P((int, ENVELOPE *)); 2888 extern void disk_status __P((SM_FILE_T *, char *)); 2889 extern int dns_getcanonname __P((char *, int, bool, int *, int *)); 2890 extern pid_t dofork __P((void)); 2891 extern int drop_privileges __P((bool)); 2892 extern int dsntoexitstat __P((char *)); 2893 extern void dumpfd __P((int, bool, bool)); 2894 #if SM_HEAP_CHECK 2895 extern void dumpstab __P((void)); 2896 #endif 2897 extern void dumpstate __P((char *)); 2898 extern bool enoughdiskspace __P((long, ENVELOPE *)); 2899 extern char *exitstat __P((char *)); 2900 extern void fatal_error __P((SM_EXC_T *)); 2901 extern char *fgetfolded __P((char *, int *, SM_FILE_T *)); 2902 extern void fill_fd __P((int, char *)); 2903 extern char *find_character __P((char *, int)); 2904 extern int finduser __P((char *, bool *, SM_MBDB_T *)); 2905 extern void finis __P((bool, bool, volatile int)); 2906 extern void fixcrlf __P((char *, bool)); 2907 extern long freediskspace __P((const char *, long *)); 2908 #if NETINET6 && NEEDSGETIPNODE 2909 extern void freehostent __P((struct hostent *)); 2910 #endif 2911 extern char *get_column __P((char *, int, int, char *, int)); 2912 extern char *getauthinfo __P((int, bool *)); 2913 extern int getdtsize __P((void)); 2914 extern int getla __P((void)); 2915 extern char *getmodifiers __P((char *, BITMAP256)); 2916 extern BITMAP256 *getrequests __P((ENVELOPE *)); 2917 extern char *getvendor __P((int)); 2918 extern void help __P((char *, ENVELOPE *)); 2919 extern void init_md __P((int, char **)); 2920 extern void initdaemon __P((void)); 2921 extern void inithostmaps __P((void)); 2922 extern void initmacros __P((ENVELOPE *)); 2923 extern void initsetproctitle __P((int, char **, char **)); 2924 extern void init_vendor_macros __P((ENVELOPE *)); 2925 extern SIGFUNC_DECL intsig __P((int)); 2926 extern bool isatom __P((const char *)); 2927 extern bool isloopback __P((SOCKADDR sa)); 2928 extern void load_if_names __P((void)); 2929 extern bool lockfile __P((int, char *, char *, int)); 2930 extern void log_sendmail_pid __P((ENVELOPE *)); 2931 extern void logundelrcpts __P((ENVELOPE *, char *, int, bool)); 2932 extern char lower __P((int)); 2933 extern char *makelower_a __P((char **, SM_RPOOL_T *)); 2934 extern void makelower_buf __P((char *, char *, int)); 2935 extern int makeconnection_ds __P((char *, MCI *)); 2936 #if DANE 2937 extern int makeconnection __P((char *, volatile unsigned int, MCI *, ENVELOPE *, time_t, unsigned long *)); 2938 #else 2939 extern int makeconnection __P((char *, volatile unsigned int, MCI *, ENVELOPE *, time_t)); 2940 #endif 2941 extern void makeworkgroups __P((void)); 2942 extern void markfailure __P((ENVELOPE *, ADDRESS *, MCI *, int, bool)); 2943 extern void mark_work_group_restart __P((int, int)); 2944 extern MCI *mci_new __P((SM_RPOOL_T *)); 2945 extern char *munchstring __P((char *, char **, int)); 2946 extern struct hostent *myhostname __P((char *, int)); 2947 #if SM_HEAP_CHECK > 2 2948 extern char *newstr_tagged __P((const char *, char *, int, int)); 2949 # define newstr(str) newstr_tagged(str, "newstr:" __FILE__, __LINE__, SmHeapGroup) 2950 #else 2951 extern char *newstr __P((const char *)); 2952 # define newstr_tagged(str, file, line, grp) newstr(str) 2953 #endif 2954 #if NISPLUS 2955 extern char *nisplus_default_domain __P((void)); /* extern for Sun */ 2956 #endif 2957 extern bool path_is_dir __P((char *, bool)); 2958 extern int pickqdir __P((QUEUEGRP *qg, long fsize, ENVELOPE *e)); 2959 extern char *pintvl __P((time_t, bool)); 2960 extern void printav __P((SM_FILE_T *, char **)); 2961 extern void printmailer __P((SM_FILE_T *, MAILER *)); 2962 extern void printnqe __P((SM_FILE_T *, char *)); 2963 extern void printopenfds __P((bool)); 2964 extern void printqueue __P((void)); 2965 extern void printrules __P((void)); 2966 extern pid_t prog_open __P((char **, int *, ENVELOPE *)); 2967 extern bool putline __P((char *, MCI *)); 2968 extern bool putxline __P((char *, size_t, MCI *, int)); 2969 extern void queueup_macros __P((int, SM_FILE_T *, ENVELOPE *)); 2970 extern void readcf __P((char *, bool, ENVELOPE *)); 2971 extern SIGFUNC_DECL reapchild __P((int)); 2972 extern int releasesignal __P((int)); 2973 extern void resetlimits __P((void)); 2974 extern void restart_daemon __P((void)); 2975 extern void restart_marked_work_groups __P((void)); 2976 extern bool rfc822_string __P((char *)); 2977 extern void rmexpstab __P((void)); 2978 extern bool savemail __P((ENVELOPE *, bool)); 2979 extern void seed_random __P((void)); 2980 extern void sendtoargv __P((char **, ENVELOPE *)); 2981 extern void setclientoptions __P((char *)); 2982 extern bool setdaemonoptions __P((char *)); 2983 extern void setdefaults __P((ENVELOPE *)); 2984 extern void setdefuser __P((void)); 2985 extern bool setvendor __P((char *)); 2986 extern void set_op_mode __P((int)); 2987 extern void setoption __P((int, char *, bool, bool, ENVELOPE *)); 2988 extern sigfunc_t setsignal __P((int, sigfunc_t)); 2989 extern void sm_setuserenv __P((const char *, const char *)); 2990 extern void settime __P((ENVELOPE *)); 2991 #if STARTTLS 2992 extern int set_tls_rd_tmo __P((int)); 2993 #else 2994 # define set_tls_rd_tmo(rd_tmo) 0 2995 #endif 2996 extern char *sfgets __P((char *, int, SM_FILE_T *, time_t, char *)); 2997 extern char *shortenstring __P((const char *, size_t)); 2998 extern char *shorten_hostname __P((char [])); 2999 extern bool shorten_rfc822_string __P((char *, size_t)); 3000 extern void showcfopts __P((void)); 3001 extern void shutdown_daemon __P((void)); 3002 extern void sm_closefrom __P((int lowest, int highest)); 3003 extern void sm_close_on_exec __P((int lowest, int highest)); 3004 extern struct hostent *sm_gethostbyname __P((char *, int)); 3005 extern struct hostent *sm_gethostbyaddr __P((char *, int, int)); 3006 extern void sm_getla __P((void)); 3007 extern struct passwd *sm_getpwnam __P((char *)); 3008 extern struct passwd *sm_getpwuid __P((UID_T)); 3009 extern void sm_setproctitle __P((bool, ENVELOPE *, const char *, ...)); 3010 extern pid_t sm_wait __P((int *)); 3011 extern bool split_by_recipient __P((ENVELOPE *e)); 3012 extern void stop_sendmail __P((void)); 3013 extern void stripbackslash __P((char *)); 3014 extern bool strreplnonprt __P((char *, int)); 3015 extern bool strcontainedin __P((bool, char *, char *)); 3016 extern int switch_map_find __P((char *, char *[], short [])); 3017 #if STARTTLS 3018 extern void tls_set_verify __P((SSL_CTX *, SSL *, bool)); 3019 #endif 3020 extern bool transienterror __P((int)); 3021 extern void truncate_at_delim __P((char *, size_t, int)); 3022 extern void tTflag __P((char *)); 3023 extern void tTsetup __P((unsigned char *, unsigned int, char *)); 3024 extern SIGFUNC_DECL tick __P((int)); 3025 extern char *ttypath __P((void)); 3026 extern void unlockqueue __P((ENVELOPE *)); 3027 #if !HASUNSETENV 3028 extern void unsetenv __P((char *)); 3029 #endif 3030 3031 /* update file system information: +/- some blocks */ 3032 #if SM_CONF_SHM 3033 extern void upd_qs __P((ENVELOPE *, int, int, char *)); 3034 # define updfs(e, count, space, where) upd_qs(e, count, space, where) 3035 #else /* SM_CONF_SHM */ 3036 # define updfs(e, count, space, where) 3037 # define upd_qs(e, count, space, where) 3038 #endif /* SM_CONF_SHM */ 3039 3040 extern char *username __P((void)); 3041 extern bool usershellok __P((char *, char *)); 3042 extern void vendor_post_defaults __P((ENVELOPE *)); 3043 extern void vendor_pre_defaults __P((ENVELOPE *)); 3044 extern int waitfor __P((pid_t)); 3045 extern bool writable __P((char *, ADDRESS *, long)); 3046 #if SM_HEAP_CHECK 3047 # define xalloc(size) xalloc_tagged(size, __FILE__, __LINE__) 3048 extern char *xalloc_tagged __P((int, char *, int)); 3049 #else 3050 extern char *xalloc __P((int)); 3051 #endif /* SM_HEAP_CHECK */ 3052 #if _FFR_XCNCT 3053 extern int xconnect __P((SM_FILE_T *)); 3054 #endif 3055 extern void xputs __P((SM_FILE_T *, const char *)); 3056 extern char *xtextify __P((char *, char *)); 3057 extern bool xtextok __P((char *)); 3058 extern int xunlink __P((char *)); 3059 extern char *xuntextify __P((char *)); 3060 3061 /* flags for collect() */ 3062 #define SMTPMODE_NO 0 3063 #define SMTPMODE_LAX 0x01 3064 #define SMTPMODE_CRLF 0x02 /* CRLF.CRLF required for EOM */ 3065 #define SMTPMODE_LF_421 0x04 /* bare LF: drop connection */ 3066 #define SMTPMODE_CR_421 0x08 /* bare CR: drop connection */ 3067 #define SMTPMODE_LF_SP 0x10 /* bare LF: replace with space */ 3068 #define SMTPMODE_CR_SP 0x20 /* bare CR: replace with space */ 3069 3070 #define ASSIGN_IFDIFF(old, new) \ 3071 do \ 3072 { \ 3073 if ((new) != (old)) \ 3074 { \ 3075 SM_FREE(old); \ 3076 old = new; \ 3077 new = NULL; \ 3078 } \ 3079 } while (0); 3080 3081 #if USE_EAI 3082 extern bool addr_is_ascii __P((const char *)); 3083 extern bool str_is_print __P((const char *)); 3084 extern const char *hn2alabel __P((const char *)); 3085 #endif 3086 3087 #if _FFR_RCPTFLAGS 3088 extern bool newmodmailer __P((ADDRESS *, int)); 3089 #endif 3090 3091 #define SM_CLOSE_FP(fp) \ 3092 do \ 3093 { \ 3094 if ((fp) != NULL) \ 3095 { \ 3096 (void) sm_io_close((fp), SM_TIME_DEFAULT); \ 3097 fp = NULL; \ 3098 } \ 3099 } while (0); 3100 3101 #undef EXTERN 3102 #endif /* ! _SENDMAIL_H */ 3103