Lines Matching +full:v +full:- +full:pos +full:- +full:supply
2 * Copyright (c) 1998-2010, 2012, 2020-2023 Proofpoint, Inc. and its suppliers.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
17 SM_RCSID("@(#)$Id: deliver.c,v 8.1030 2013-11-22 20:51:55 ca Exp $")
152 ** SENDALL -- actually send all the messages.
155 ** e -- the envelope to send.
156 ** mode -- the delivery mode to use. If SM_DEFAULT, use
157 ** the current e->e_sendmode.
165 ** If we are running in a non-interactive mode, takes the
189 if (bitset(EF_DISCARD, e->e_flags))
192 sm_dprintf("sendall: discarding id %s\n", e->e_id);
193 e->e_flags |= EF_CLRQUEUE;
197 sm_syslog(LOG_INFO, e->e_id, "discarded");
209 if (bitset(EF_FATALERRS, e->e_flags) &&
212 e->e_flags |= EF_CLRQUEUE;
219 mode = e->e_sendmode;
221 shouldqueue(e->e_msgpriority, e->e_ctime))
228 mode, e->e_id);
229 printaddr(sm_debug_file(), &e->e_from, false);
233 printaddr(sm_debug_file(), e->e_sendqueue, true);
246 if (e->e_hopcount > MaxHopCount)
250 if (e->e_sendqueue != NULL &&
251 e->e_sendqueue->q_paddr != NULL)
252 recip = e->e_sendqueue->q_paddr;
258 e->e_flags |= EF_FATALERRS|EF_PM_NOTIFY|EF_CLRQUEUE;
261 e->e_hopcount, MaxHopCount, e->e_from.q_paddr,
264 for (q = e->e_sendqueue; q != NULL; q = q->q_next)
266 if (QS_IS_DEAD(q->q_state))
268 q->q_state = QS_BADADDR;
269 q->q_status = "5.4.6";
270 q->q_rstatus = "554 5.4.6 Too many hops";
284 if (!bitset(EF_METOO, e->e_flags) &&
285 !QS_IS_QUEUEUP(e->e_from.q_state))
290 printaddr(sm_debug_file(), &e->e_from, false);
292 e->e_from.q_state = QS_SENDER;
293 (void) recipient(&e->e_from, &e->e_sendqueue, 0, e);
303 for (q = e->e_sendqueue; q != NULL; q = q->q_next)
307 for (a = q; a != NULL && a->q_owner == NULL; a = a->q_alias)
310 q->q_owner = a->q_owner;
312 if (q->q_owner != NULL &&
313 !QS_IS_DEAD(q->q_state) &&
314 strcmp(q->q_owner, e->e_from.q_paddr) == 0)
315 q->q_owner = NULL;
321 printaddr(sm_debug_file(), e->e_sendqueue, true);
332 otherowners = bitset(EF_SENDRECEIPT, e->e_flags) ? 1 : 0;
334 for (q = e->e_sendqueue; q != NULL; q = q->q_next)
341 if (QS_IS_DEAD(q->q_state))
353 if (q->q_owner != NULL)
359 q->q_owner);
360 owner = q->q_owner;
362 else if (owner != q->q_owner)
364 if (strcmp(owner, q->q_owner) == 0)
371 q->q_owner = owner;
377 q->q_owner);
380 owner = q->q_owner;
393 if (QS_IS_BADADDR(q->q_state))
400 if (QS_IS_QUEUEUP(q->q_state))
402 MAILER *m = q->q_mailer;
413 !bitnset(M_NOMX, m->m_flags) &&
414 strcmp(m->m_mailer, "[IPC]") == 0 &&
415 m->m_argv[0] != NULL &&
416 strcmp(m->m_argv[0], "TCP") == 0)
425 p = sm_rpool_malloc_x(e->e_rpool, len);
427 q->q_state = QS_OK;
428 q->q_host = p;
448 bitnset(M_EXPENSIVE, q->q_mailer->m_flags))
452 q->q_state = QS_QUEUEUP;
455 else if (bitnset(M_HOLD, q->q_mailer->m_flags) &&
462 q->q_state = QS_QUEUEUP;
466 e->e_quarmsg != NULL)
470 e->e_quarmsg);
471 q->q_state = QS_QUEUEUP;
488 ee = (ENVELOPE *) sm_rpool_malloc_x(e->e_rpool,
491 ee->e_message = NULL;
492 ee->e_id = NULL;
497 e->e_id, ee->e_id, owner,
500 ee->e_header = copyheader(e->e_header, ee->e_rpool);
501 ee->e_sendqueue = copyqueue(e->e_sendqueue,
502 ee->e_rpool);
503 ee->e_errorqueue = copyqueue(e->e_errorqueue,
504 ee->e_rpool);
505 ee->e_flags = e->e_flags & ~(EF_INQUEUE|EF_CLRQUEUE|EF_FATALERRS|EF_SENDRECEIPT|EF_RET_PARAM);
506 ee->e_flags |= EF_NORECEIPT;
511 printaddr(sm_debug_file(), &ee->e_from, false);
513 ee->e_from.q_state = QS_SENDER;
514 ee->e_dfp = NULL;
515 ee->e_lockfp = NULL;
516 ee->e_xfp = NULL;
517 ee->e_qgrp = e->e_qgrp;
518 ee->e_qdir = e->e_qdir;
519 ee->e_errormode = EM_MAIL;
520 ee->e_sibling = splitenv;
521 ee->e_statmsg = NULL;
522 if (e->e_quarmsg != NULL)
523 ee->e_quarmsg = sm_rpool_strdup_x(ee->e_rpool,
524 e->e_quarmsg);
527 for (q = e->e_sendqueue; q != NULL; q = q->q_next)
529 if (q->q_owner == owner)
531 q->q_state = QS_CLONED;
534 q->q_paddr);
537 for (q = ee->e_sendqueue; q != NULL; q = q->q_next)
539 if (q->q_owner != owner)
541 q->q_state = QS_CLONED;
544 q->q_paddr);
549 q->q_flags &= ~(QHASNOTIFY|Q_PINGFLAGS);
550 q->q_flags |= DefaultNotify & ~QPINGONSUCCESS;
553 q->q_paddr);
557 if (mode != SM_VERIFY && bitset(EF_HAS_DF, e->e_flags))
567 if (e->e_xfp != NULL)
568 ee->e_xfp = sm_io_dup(e->e_xfp);
570 /* failed to dup e->e_xfp, start a new transcript */
571 if (ee->e_xfp == NULL)
575 sm_syslog(LOG_INFO, e->e_id,
577 ee->e_id, owner);
587 printaddr(sm_debug_file(), &e->e_from, false);
589 e->e_from.q_state = QS_SENDER;
590 e->e_errormode = EM_MAIL;
591 e->e_flags |= EF_NORECEIPT;
592 e->e_flags &= ~EF_FATALERRS;
602 sm_dprintf("No deliveries: auto-queueing\n");
607 e->e_dtime = now;
609 e->e_ntries++;
610 for (ee = splitenv; ee != NULL; ee = ee->e_sibling)
612 ee->e_dtime = now;
614 ee->e_ntries++;
622 (!bitset(EF_INQUEUE, e->e_flags) || splitenv != NULL))
642 for (ee = splitenv; ee != NULL; ee = ee->e_sibling)
661 e->e_id, e->e_from.q_paddr);
662 printaddr(sm_debug_file(), e->e_sendqueue, true);
663 for (ee = splitenv; ee != NULL; ee = ee->e_sibling)
666 ee->e_id, ee->e_from.q_paddr);
667 printaddr(sm_debug_file(), ee->e_sendqueue, true);
683 if (e->e_nrcpts > 0)
684 e->e_flags |= EF_INQUEUE;
686 for (ee = splitenv; ee != NULL; ee = ee->e_sibling)
688 if (ee->e_nrcpts > 0)
689 ee->e_flags |= EF_INQUEUE;
695 if (e->e_xfp != NULL)
696 (void) sm_io_flush(e->e_xfp, SM_TIME_DEFAULT);
708 char *qid = e->e_id;
711 e->e_flags |= EF_INQUEUE;
715 e->e_id = qid;
718 for (ee = splitenv; ee != NULL; ee = ee->e_sibling)
721 char *qid = ee->e_id;
724 ee->e_flags |= EF_INQUEUE;
728 ee->e_id = qid;
750 e->e_id = NULL;
751 for (ee = splitenv; ee != NULL; ee = ee->e_sibling)
752 ee->e_id = NULL;
762 SM_CLOSE_FP(e->e_dfp);
763 e->e_flags &= ~EF_HAS_DF;
766 if (e->e_lockfp != NULL)
767 (void) sm_io_close(e->e_lockfp, SM_TIME_DEFAULT);
769 syserr("%s: sendall: null lockfp", e->e_id);
770 e->e_lockfp = NULL;
774 e->e_id = NULL;
825 e->e_flags |= EF_INQUEUE;
827 e->e_id = NULL;
855 for (ee = splitenv; ee != NULL; ee = ee->e_sibling)
857 ENVELOPE *sibling = ee->e_sibling;
859 (void) dowork(ee->e_qgrp, ee->e_qdir, ee->e_id,
861 ee->e_sibling = sibling;
863 (void) dowork(e->e_qgrp, e->e_qdir, e->e_id,
871 for (ee = splitenv; ee != NULL; ee = ee->e_sibling)
896 e->e_id == NULL ? "[NOQUEUE]" : e->e_id,
897 e->e_flags);
899 sm_syslog(LOG_DEBUG, e->e_id,
901 e->e_flags);
910 if (bitset(EF_FATALERRS, e->e_flags) &&
913 e->e_flags |= EF_CLRQUEUE;
919 ** or if deliver-by time is exceeded.
922 if (!bitset(EF_RESPONSE, e->e_flags) &&
923 (TimeOuts.to_q_return[e->e_timeoutclass] == NOW ||
924 (IS_DLVR_RETURN(e) && e->e_deliver_by > 0 &&
925 curtime() > e->e_ctime + e->e_deliver_by)))
935 e->e_nsent = 0;
936 e->e_flags |= EF_GLOBALERRS;
938 macdefine(&e->e_macro, A_PERM, macid("{envid}"), e->e_envid);
939 macdefine(&e->e_macro, A_PERM, macid("{bodytype}"), e->e_bodytype);
942 if (!bitset(EF_SPLIT, e->e_flags))
954 oldsib = e->e_sibling;
955 e->e_sibling = NULL;
957 bitset(EF_FATALERRS, e->e_flags))
960 e->e_flags |= EF_CLRQUEUE;
963 for (ee = e->e_sibling; ee != NULL; ee = ee->e_sibling)
967 for (ee = e->e_sibling; ee != NULL; ee = ee->e_sibling)
974 SM_CLOSE_FP(ee->e_dfp);
975 ee->e_id = NULL;
976 ee->e_flags &= ~EF_HAS_DF;
978 e->e_sibling = oldsib;
982 for (q = e->e_sendqueue; q != NULL; q = q->q_next)
988 MAXNAME, q->q_paddr); /* EAI: see above */
993 e->e_to = q->q_paddr;
994 if (QS_IS_SENDABLE(q->q_state))
996 if (q->q_host != NULL && q->q_host[0] != '\0')
998 q->q_mailer->m_name,
999 q->q_host,
1000 q->q_user);
1003 q->q_mailer->m_name,
1004 q->q_user);
1007 else if (QS_IS_OK(q->q_state))
1014 e->e_nsent >= CheckpointInterval)
1017 e->e_nsent = 0;
1025 e->e_dtime = curtime();
1026 e->e_ntries++;
1036 ** SYNC_DIR -- fsync a directory based on a filename
1039 ** filename -- path of file
1040 ** panic -- panic?
1064 dir[dirp - filename] = '\0';
1090 ** DUP_QUEUE_FILE -- duplicate a queue file into a split queue
1093 ** e -- the existing envelope
1094 ** ee -- the new envelope
1095 ** type -- the queue file type (e.g., DATAFL_LETTER)
1108 ee->e_dfp = NULL;
1109 ee->e_xfp = NULL;
1119 if (type == DATAFL_LETTER && e->e_dfp != NULL &&
1120 sm_io_setinfo(e->e_dfp, SM_BF_COMMIT, NULL) < 0 &&
1151 ** DOFORK -- do a fork, retrying a couple of times on failure.
1165 ** -1 on unrecoverable error.
1182 for (i = NFORKTRIES; --i >= 0; )\
1188 (void) sleep((unsigned) NFORKTRIES - i);\
1192 ** DOFORK -- simple fork interface to DOFORK.
1200 ** -1 on error.
1209 register pid_t pid = -1; in dofork()
1216 ** COLONCMP -- compare host-signatures up to first ':' or EOS
1218 ** This takes two strings which happen to be host-signatures and
1219 ** compares them. If the lowest preference portions of the MX-RR's
1221 ** match. This is used for coattail-piggybacking messages during
1225 ** re-examining the first part of the signatures.
1228 ** a - first host-signature
1229 ** b - second host-signature
1232 ** HS_MATCH_NO -- no "match".
1233 ** HS_MATCH_FIRST -- "match" for the first MX preference
1235 ** HS_MATCH_FULL -- match for the entire MX record.
1236 ** HS_MATCH_SKIP -- match but only one of the entries has a "mark"
1275 braclev--;
1295 ((*a == '\0' && *(b - 1) == ':') ||
1296 (*a == ':' && *(b - 1) == '\0')))
1312 ** SHOULD_TRY_FBSH -- Should try FallbackSmartHost?
1315 ** e -- envelope
1316 ** tried_fallbacksmarthost -- has been tried already? (in/out)
1317 ** hostbuf -- buffer for hostname (expand FallbackSmartHost) (out)
1318 ** hbsz -- size of hostbuf
1319 ** status -- current delivery status
1359 ** CLTFEATURES -- Get features for SMTP client
1362 ** e -- envelope
1363 ** servername -- name of server.
1381 SM_ASSERT(e->e_mci != NULL);
1382 macdefine(&e->e_mci->mci_macro, A_PERM, macid("{client_flags}"), "");
1399 if (idx >= sizeof(flags) - 4)
1408 macdefine(&e->e_mci->mci_macro, A_TEMP, macid("{client_flags}"), flags);
1411 servername, e->e_mci, flags,
1419 ** LOGFAILOVER -- log reason why trying another host
1422 ** e -- envelope
1423 ** m -- the mailer info for this mailer
1424 ** mci -- mailer connection information
1425 ** rcode -- the code signifying the particular failure
1426 ** rcpt -- current RCPT
1447 if (m != NULL && m->m_name != NULL)
1450 "mailer=%s, ", m->m_name);
1453 if (mci != NULL && mci->mci_host != NULL)
1458 "relay=%.100s", mci->mci_host);
1471 if (mci->mci_state >= 0 && mci->mci_state < SM_ARRAY_SIZE(mcis))
1473 "state=%s, ", mcis[mci->mci_state]);
1476 "state=%d, ", mci->mci_state);
1483 rcode, mci->mci_okrcpts, mci->mci_retryrcpt,
1484 e->e_rcode);
1488 && !SM_IS_EMPTY(rcpt->q_rstatus)
1489 && !bitset(QINTREPLY, rcpt->q_flags))
1492 "q_rstatus=%s, ", rcpt->q_rstatus);
1495 else if (e->e_text != NULL)
1499 e->e_rcode,
1500 e->e_renhsc,
1501 (e->e_renhsc[0] != '\0') ? " " : "",
1502 e->e_text);
1508 sm_syslog(LOG_INFO, e->e_id, "%s", cbuf);
1517 dotpos = strlen(name) - 1; \
1523 dotpos = -1; \
1535 ** SETSERVERMACROS -- set ${server_addr} and ${server_name}
1538 ** mci -- mailer connection information
1539 ** pdotpos -- return pointer to former dot position in hostname
1557 if (mci->mci_host != NULL)
1559 srvname = mci->mci_host;
1562 else if (mci->mci_mailer != NULL)
1564 srvname = mci->mci_mailer->m_name;
1565 dotpos = -1;
1570 dotpos = -1;
1574 macdefine(&mci->mci_macro, A_TEMP, macid("{server_name}"),
1580 macdefine(&mci->mci_macro, A_TEMP,
1584 else if (mci->mci_mailer != NULL)
1587 macdefine(&mci->mci_macro, A_PERM,
1589 mci->mci_mailer->m_name);
1594 macdefine(&mci->mci_macro, A_PERM,
1607 ** DELIVER -- Deliver a message to a list of addresses.
1612 ** that it will deliver to all these addresses however -- so
1623 ** piggybacking based on all the mail host addresses in the MX-RR. This
1627 ** domain1 IN MX 10 mxhost-A
1628 ** IN MX 20 mxhost-B
1629 ** domain2 IN MX 4 mxhost-A
1630 ** IN MX 8 mxhost-B
1631 ** Domain1 and domain2 can piggyback the same message to mxhost-A or
1632 ** mxhost-B (if mxhost-A cannot be reached).
1637 ** domain3 IN MX 100 mxhost-C
1638 ** IN MX 100 mxhost-D
1639 ** IN MX 200 mxhost-E
1640 ** domain4 IN MX 50 mxhost-C
1641 ** IN MX 50 mxhost-D
1642 ** IN MX 80 mxhost-F
1643 ** A message for domain3 and domain4 can piggyback to mxhost-C if mxhost-C
1644 ** is available. Same with mxhost-D because in both RR's the preference
1645 ** value is the same as mxhost-C, respectively.
1649 ** cannot deliver to mxhost-F for domain3 regardless of preference value.
1655 ** e -- the envelope to deliver.
1656 ** firstto -- head of the address list to deliver to.
1659 ** zero -- successfully delivered.
1660 ** else -- some failure, see ExitStat for more info.
1693 volatile pid_t pid = -1;
1720 # define RCPT_MXSECURE(rcpt) (0 != ((rcpt)->q_flags & QMXSECURE))
1722 # define STE_HAS_TLSA(ste) ((ste) != NULL && (ste)->s_tlsa != NULL)
1734 && TLSA_IS_FL(ste->s_tlsa, TLSAFLSUP))
1737 && TLSA_IS_FL(ste->s_tlsa, TLSAFLUNS))
1763 if (!QS_IS_OK(to->q_state))
1769 m = to->q_mailer;
1770 host = to->q_host;
1772 e->e_statmsg = NULL;
1784 sm_dprintf("\n--deliver, id=%s, mailer=%s, host=`%s', first user=`%s'\n",
1785 e->e_id, m->m_name, host, to->q_user);
1795 if (bitset(EF_RESPONSE, e->e_flags))
1797 macdefine(&e->e_macro, A_PERM, macid("{client_name}"), "");
1798 macdefine(&e->e_macro, A_PERM, macid("{client_ptr}"), "");
1799 macdefine(&e->e_macro, A_PERM, macid("{client_addr}"), "");
1800 macdefine(&e->e_macro, A_PERM, macid("{client_port}"), "");
1801 macdefine(&e->e_macro, A_PERM, macid("{client_resolve}"), "");
1812 ** a picky -f flag, we insert it as appropriate. This
1821 SM_ASSERT(e->e_from.q_mailer != NULL);
1822 if (bitnset(M_UDBENVELOPE, e->e_from.q_mailer->m_flags))
1823 p = e->e_sender;
1825 p = e->e_from.q_paddr;
1827 if (rcode != EX_OK && bitnset(M_xSMTP, m->m_flags))
1839 rpath = sm_rpool_strdup_x(e->e_rpool, rpath);
1840 macdefine(&e->e_macro, A_PERM, 'g', rpath);
1844 macdefine(&e->e_macro, A_PERM, 'h', host);
1847 *pvp++ = m->m_argv[0];
1850 if (bitnset(M_NOHOSTSTAT, m->m_flags))
1853 /* insert -f or -r flag as appropriate */
1855 (bitnset(M_FOPT, m->m_flags) ||
1856 bitnset(M_ROPT, m->m_flags)))
1858 if (bitnset(M_FOPT, m->m_flags))
1859 *pvp++ = "-f";
1861 *pvp++ = "-r";
1872 for (mvp = m->m_argv; (p = *++mvp) != NULL; )
1887 /* this entry is safe -- go ahead and process it */
1892 if (strcmp(m->m_mailer, "[IPC]") == 0
1894 /* for now only apply [i] -> [x] conversion to $h by default */
1909 *pvp++ = sm_rpool_strdup_x(e->e_rpool, p);
1910 if (pvp >= &pv[MAXPV - 3])
1914 rcode = -1;
1921 ** list, we know that we must supply the names otherwise -- and
1930 setbitn(M_xSMTP, m->m_flags);
1932 else if (bitnset(M_LMTP, m->m_flags))
1937 m->m_name);
1938 clrbitn(M_LMTP, m->m_flags);
1948 e->e_to = NULL;
1952 if (firstto->q_signature == NULL)
1953 firstto->q_signature = hostsignature(firstto->q_mailer,
1954 firstto->q_host,
1956 &firstto->q_flags);
1957 firstsig = firstto->q_signature;
1959 # define NODANEREQYET (-1)
1963 for (; to != NULL; to = to->q_next)
1966 if (tochain != NULL && !bitnset(M_MUSER, m->m_flags))
1970 if (!QS_IS_OK(to->q_state)) /* already sent; look at next */
1979 if (to->q_mailer != firstto->q_mailer)
1982 if (to->q_signature == NULL) /* for safety */
1983 to->q_signature = hostsignature(to->q_mailer,
1984 to->q_host,
1986 &to->q_flags);
1991 ** (that's the MX-RR's are identical) we can do coincidental
2000 coloncmp(to->q_signature, firstsig);
2013 strsize += strlen(to->q_paddr) + 1;
2018 if (++rcptcount > to->q_mailer->m_maxrcpt)
2026 parse_hostsignature(to->q_signature, mxhosts, m, mxads);
2030 to->q_flags |= QMXSECURE;
2032 to->q_flags &= ~QMXSECURE;
2035 gettlsa(mxhosts[0], NULL, &ste, RCPT_MXSECURE(to) ? TLSAFLADMX : 0, 0, m->m_port);
2037 to->q_user, rcptcount, QISSECURE(to),
2040 , to->q_signature, mxhosts[0]
2041 , STE_HAS_TLSA(ste) ? ste->s_tlsa->dane_tlsa_n : -1
2042 , STE_HAS_TLSA(ste) ? ste->s_tlsa->dane_tlsa_flags : -1
2055 to->q_user, rcptcount);
2074 if (bitnset(M_RUNASRCPT, to->q_mailer->m_flags))
2087 user = to->q_user;
2088 e->e_to = to->q_paddr;
2096 if (m->m_maxsize != 0 &&
2097 (e->e_msgsize > m->m_maxsize || e->e_msgsize < 0))
2099 e->e_flags |= EF_NO_BODY_RETN;
2100 if (bitnset(M_LOCALMAILER, to->q_mailer->m_flags))
2101 to->q_status = "5.2.3";
2103 to->q_status = "5.3.4";
2105 /* set to->q_rstatus = NULL; or to the following? */
2106 usrerrenh(to->q_status,
2108 m->m_maxsize);
2110 giveresponse(EX_UNAVAILABLE, to->q_status, m,
2118 quarantine = (e->e_quarmsg != NULL);
2119 rcode = rscheck("check_compat", e->e_from.q_paddr, to->q_paddr,
2121 e->e_id, NULL, NULL);
2124 /* do in-code checking if not discarding */
2125 if (!bitset(EF_DISCARD, e->e_flags))
2134 giveresponse(rcode, to->q_status, m,
2138 if (!quarantine && e->e_quarmsg != NULL)
2146 e->e_quarmsg = NULL;
2147 macdefine(&e->e_macro, A_PERM,
2150 if (bitset(EF_DISCARD, e->e_flags))
2160 to->q_state = QS_DISCARDED;
2169 e->e_flags &= ~EF_DISCARD;
2178 if (bitnset(M_STRIPQ, m->m_flags))
2190 if (bitnset(M_STRIPBACKSL, m->m_flags) && user[0] == '\\')
2193 /* hack attack -- delivermail compatibility */
2206 if (!QS_IS_OK(to->q_state))
2212 ** is a file -- send it off without further ado. Note
2217 if (strcmp(m->m_mailer, "[FILE]") == 0)
2219 macdefine(&e->e_macro, A_PERM, 'u', user);
2220 p = to->q_home;
2222 p = ctladdr->q_home;
2223 macdefine(&e->e_macro, A_PERM, 'z', p);
2224 expand(m->m_argv[1], buf, sizeof(buf), e);
2230 m->m_name);
2233 giveresponse(rcode, to->q_status, m, NULL,
2236 e->e_nsent++;
2239 to->q_state = QS_SENT;
2240 if (bitnset(M_LOCALMAILER, m->m_flags) &&
2241 bitset(QPINGONSUCCESS, to->q_flags))
2243 to->q_flags |= QDELIVERED;
2244 to->q_status = "2.1.5";
2245 (void) sm_io_fprintf(e->e_xfp,
2248 to->q_paddr);
2251 to->q_statdate = curtime();
2257 ** Address is verified -- add this user to mailer
2262 to->q_tchain = tochain;
2264 e->e_to = "[CHAIN]";
2266 macdefine(&e->e_macro, A_PERM, 'u', user); /* to user */
2267 p = to->q_home;
2269 p = ctladdr->q_home;
2270 macdefine(&e->e_macro, A_PERM, 'z', p); /* user's home */
2273 if (bitset(QHASNOTIFY, to->q_flags))
2278 if (bitset(QPINGONSUCCESS, to->q_flags))
2281 if (bitset(QPINGONFAILURE, to->q_flags))
2284 if (bitset(QPINGONDELAY, to->q_flags))
2293 notify[strlen(notify) - 1] = '\0';
2295 macdefine(&e->e_macro, A_TEMP,
2299 macdefine(&e->e_macro, A_PERM,
2319 *pvp++ = sm_rpool_strdup_x(e->e_rpool, p);
2320 if (pvp >= &pv[MAXPV - 2])
2337 for (to = tochain; to != NULL; to = to->q_tchain)
2338 strsize += strlen(to->q_paddr) + 1;
2349 for (to = tochain; to != NULL; to = to->q_tchain)
2351 (void) sm_strlcpyn(p, tobufsize - (p - tobuf), 2,
2352 ",", to->q_paddr);
2355 e->e_to = tobuf + 1;
2368 /* disabled for now - is there a use case for this? */
2377 *pvp++ = sm_rpool_strdup_x(e->e_rpool, p);
2395 bitset(QGOODUID, e->e_from.q_flags))
2396 ctladdr = &e->e_from;
2431 shortenstring(e->e_to, MAXSHORTSTR),
2432 m->m_name);
2437 /* check for 8-bit available */
2438 if (bitset(EF_HAS8BIT, e->e_flags) &&
2439 bitnset(M_7BITS, m->m_flags) &&
2440 (bitset(EF_DONT_MIME, e->e_flags) ||
2442 (bitset(EF_IS_MIME, e->e_flags) &&
2445 e->e_status = "5.6.3";
2446 usrerrenh(e->e_status,
2447 "554 Cannot send 8-bit data to 7-bit destination");
2455 /* check for Local Person Communication -- not for mortals!!! */
2456 if (strcmp(m->m_mailer, "[LPC]") == 0)
2464 mci = mci_get(m->m_name, m);
2465 if (mci->mci_host == NULL)
2466 mci->mci_host = m->m_name;
2467 CurHostName = mci->mci_host;
2468 if (mci->mci_state != MCIS_CLOSED)
2471 m->m_name);
2472 mci->mci_deliveries++;
2478 mci = mci_new(e->e_rpool);
2480 mci->mci_in = smioin;
2481 mci->mci_out = smioout;
2482 mci->mci_mailer = m;
2483 mci->mci_host = m->m_name;
2486 mci->mci_state = MCIS_OPENING;
2490 mci->mci_state = MCIS_OPEN;
2492 else if (strcmp(m->m_mailer, "[IPC]") == 0)
2498 syserr("null destination for %s mailer", m->m_mailer);
2517 &firstto->q_flags);
2529 syserr("554 5.3.5 non-clever IPC");
2550 port = sp->s_port;
2627 firstto->q_flags |= QMXSECURE;
2629 firstto->q_flags &= ~QMXSECURE;
2634 mci->mci_state, RCPT_MXSECURE(firstto),
2637 firstto->q_user, e->e_to);
2643 0, m->m_port);
2651 if (ste != NULL && TLSA_RR_TEMPFAIL(ste->s_tlsa))
2656 , ste->s_tlsa->dane_tlsa_dnsrc);
2662 if (ste->s_tlsa != NULL)
2665 , ste->s_tlsa->dane_tlsa_n
2666 , ste->s_tlsa->dane_tlsa_flags
2667 , mci->mci_ssl
2668 , mci->mci_tlsi.tlsi_dvc.dane_vrfy_chk
2669 , mci->mci_tlsi.tlsi_dvc.dane_vrfy_res
2675 if (mci->mci_state != MCIS_CLOSED)
2681 ste != NULL && ste->s_tlsa != NULL &&
2682 TLSA_IS_FL(ste->s_tlsa, TLSAFLSUP);
2683 dane_old = CHK_DANE(mci->mci_tlsi.tlsi_dvc.dane_vrfy_chk);
2688 vrfy = macget(&mci->mci_macro, macid("{verify}"));
2700 mci, mci->mci_state);
2701 smtpquit(mci->mci_mailer, mci, e);
2705 mci, mci->mci_state);
2710 tlsa_flags = mci->mci_tlsi.tlsi_dvc.dane_vrfy_chk;
2712 &mci->mci_tlsi.tlsi_dvc.dane_vrfy_chk,
2718 host, hostbuf, mci->mci_tlsi.tlsi_dvc.dane_vrfy_chk);
2722 if (mci->mci_state != MCIS_CLOSED)
2731 CurHostName = mci->mci_host;
2732 if (bitnset(M_LMTP, m->m_flags))
2734 else if (bitset(MCIF_ESMTP, mci->mci_flags))
2739 type, hostbuf, m->m_name);
2740 mci->mci_deliveries++;
2743 mci->mci_mailer = m;
2745 if (mci->mci_exitstat != EX_OK)
2747 if (mci->mci_exitstat == EX_TEMPFAIL)
2753 mci->mci_exitstat))
2772 e->e_mci = mci;
2777 sm_syslog(LOG_WARNING, e->e_id,
2794 dane_vrfy_ctx.dane_vrfy_port = m->m_port;
2807 mux_path, m->m_name);
2823 hostbuf, m->m_name);
2827 m->m_name);
2831 ** required to set {client_flags} in e->e_mci
2865 mci->mci_errno = errno;
2866 mci->mci_lastuse = curtime();
2867 mci->mci_deliveries = 0;
2868 mci->mci_exitstat = i;
2871 mci->mci_herrno = h_errno;
2880 if (enough > 0 && mci->mci_lastuse >= enough)
2890 sm_syslog(LOG_INFO, e->e_id,
2898 h = nummxhosts - NumFallbackMXHosts;
2906 mci->mci_state = MCIS_OPENING;
2934 /* should print some message here for -v mode */
2942 mci->mci_pid = 0;
2950 if (bitnset(M_LMTP, m->m_flags))
2953 mci = mci_get(m->m_name, m);
2954 if (mci->mci_host == NULL)
2955 mci->mci_host = m->m_name;
2956 CurHostName = mci->mci_host;
2957 if (mci->mci_state != MCIS_CLOSED)
2960 m->m_name);
2961 mci->mci_deliveries++;
2968 message("Connecting to %s...", m->m_name);
2970 message("Connecting to %s via %s...", host, m->m_name);
2991 shortenstring(e->e_to, MAXSHORTSTR), m->m_name);
3003 shortenstring(e->e_to, MAXSHORTSTR), m->m_name,
3016 (e->e_lockfp != NULL &&
3017 (mpvect[0] == sm_io_getinfo(e->e_lockfp, SM_IO_WHAT_FD,
3019 mpvect[1] == sm_io_getinfo(e->e_lockfp, SM_IO_WHAT_FD,
3022 if (e->e_lockfp == NULL)
3024 shortenstring(e->e_to, MAXSHORTSTR),
3025 m->m_name, mpvect[0], mpvect[1]);
3028 shortenstring(e->e_to, MAXSHORTSTR),
3029 m->m_name, mpvect[0], mpvect[1],
3030 sm_io_getinfo(e->e_lockfp,
3039 shortenstring(e->e_to, MAXSHORTSTR),
3040 m->m_name);
3059 if (e->e_xfp != NULL) /* for debugging */
3060 (void) sm_io_flush(e->e_xfp, SM_TIME_DEFAULT);
3072 shortenstring(e->e_to, MAXSHORTSTR), m->m_name);
3104 if (e->e_lockfp != NULL)
3105 (void) close(sm_io_getinfo(e->e_lockfp,
3109 /* child -- set up input & exec mailer */
3119 if (m != FileMailer || stat(tochain->q_user, &stb) < 0)
3132 if (contextaddr->q_ruser != NULL)
3133 pwd = sm_getpwnam(contextaddr->q_ruser);
3135 pwd = sm_getpwnam(contextaddr->q_user);
3147 setusercontext(NULL, pwd, pwd->pw_uid,
3148 sucflags) == -1 &&
3159 if (m->m_nice != 0)
3160 (void) nice(m->m_nice);
3164 if (bitnset(M_SPECIFIC_UID, m->m_flags))
3166 if (m->m_gid == NO_GID)
3169 new_gid = m->m_gid;
3173 else if (ctladdr != NULL && ctladdr->q_gid != 0)
3177 user = ctladdr->q_ruser;
3179 user = ctladdr->q_user;
3182 ctladdr->q_gid) == -1
3186 user, (long) ctladdr->q_gid);
3194 gidset[0] = ctladdr->q_gid;
3195 if (setgroups(1, gidset) == -1
3202 new_gid = ctladdr->q_gid;
3209 if (initgroups(DefUser, DefGid) == -1 &&
3222 if (setgroups(1, gidset) == -1
3229 if (m->m_gid == NO_GID)
3232 new_gid = m->m_gid;
3237 bitnset(M_SPECIFIC_UID, m->m_flags) &&
3257 if (m->m_rootdir != NULL)
3259 expand(m->m_rootdir, cbuf, sizeof(cbuf), e);
3279 if (bitnset(M_SPECIFIC_UID, m->m_flags))
3281 if (m->m_uid == NO_UID)
3284 new_euid = m->m_uid;
3312 else if (ctladdr != NULL && ctladdr->q_uid != 0)
3313 new_ruid = ctladdr->q_uid;
3314 else if (m->m_uid != NO_UID)
3315 new_ruid = m->m_uid;
3322 ctladdr != NULL && ctladdr->q_uid != 0 &&
3323 new_euid == ctladdr->q_uid)
3327 pwd = sm_getpwuid(ctladdr->q_uid);
3329 (void) setlogin(pwd->pw_name);
3387 if (m->m_execdir != NULL)
3391 for (p = m->m_execdir; p != NULL; p = q)
3418 ret = safefile(m->m_mailer, getuid(), getgid(),
3421 sm_syslog(LOG_INFO, e->e_id,
3423 m->m_mailer, sm_errstring(ret));
3430 shortenstring(e->e_to, MAXSHORTSTR),
3431 m->m_name, rpvect[1]);
3439 shortenstring(e->e_to, MAXSHORTSTR),
3440 m->m_name);
3449 shortenstring(e->e_to, MAXSHORTSTR),
3450 m->m_name, mpvect[0]);
3464 (void) execve(m->m_mailer, (ARGV_T) pv,
3467 syserr("Cannot exec %s", m->m_mailer);
3468 if (bitnset(M_LOCALMAILER, m->m_flags) ||
3497 mci = mci_new(e->e_rpool);
3500 mci->mci_mailer = m;
3503 mci->mci_state = MCIS_OPENING;
3508 mci->mci_state = MCIS_OPEN;
3510 mci->mci_pid = pid;
3512 mci->mci_out = sm_io_open(SmFtStdiofd, SM_TIME_DEFAULT,
3515 if (mci->mci_out == NULL)
3527 mci->mci_in = sm_io_open(SmFtStdiofd, SM_TIME_DEFAULT,
3530 if (mci->mci_in == NULL)
3535 SM_CLOSE_FP(mci->mci_out);
3545 if (bitnset(M_7BITS, m->m_flags) &&
3546 (!clever || mci->mci_state == MCIS_OPENING))
3547 mci->mci_flags |= MCIF_7BIT;
3548 if (clever && mci->mci_state != MCIS_CLOSED)
3565 if (STE_HAS_TLSA(ste) && ste->s_tlsa->dane_tlsa_sni != NULL)
3566 dane_vrfy_ctx.dane_vrfy_sni = sm_strdup(ste->s_tlsa->dane_tlsa_sni);
3569 /* undo change of srvname (== mci->mci_host) */
3574 if (DONE_STARTTLS(mci->mci_flags))
3593 e->e_mci = mci;
3595 mci->mci_saslcap = NULL;
3598 # define USEMTASTS (MTASTS && !SM_TLSI_IS(&(mci->mci_tlsi), TLSI_FL_NOSTS) && !iscltflgset(e, D_NOS…
3600 # define CHKMTASTS (USEMTASTS && (ste == NULL || ste->s_tlsa == NULL || SM_TLSI_IS(&(mci->mci_tlsi…
3606 if (!DONE_STARTTLS(mci->mci_flags))
3616 macdefine(&e->e_macro, A_PERM, macid("{rcpt_addr}"), "");
3619 macdefine(&e->e_macro, A_PERM, macid("{sts_sni}"), "DANE");
3622 macdefine(&e->e_macro, A_PERM, macid("{sts_sni}"), "");
3623 if (USEMTASTS && firstto->q_user != NULL)
3630 macdefine(&e->e_macro, A_TEMP,
3631 macid("{rcpt_addr}"), firstto->q_user);
3640 for (to = tochain; to != NULL; to = to->q_tchain)
3642 if (!QS_IS_UNMARKED(to->q_state))
3644 if (to->q_user == NULL)
3646 macdefine(&e->e_macro, A_TEMP,
3647 macid("{rcpt_addr}"), to->q_user);
3654 if (!addr_is_ascii(e->e_from.q_paddr) && !e->e_smtputf8)
3655 e->e_smtputf8 = true;
3656 for (to = tochain; to != NULL && !e->e_smtputf8; to = to->q_tchain)
3658 if (!QS_IS_UNMARKED(to->q_state))
3660 if (!addr_is_ascii(to->q_user))
3661 e->e_smtputf8 = true;
3676 implicittls = bitnset(M_SMTPS_CLIENT, mci->mci_mailer->m_flags);
3682 smtpinit(m, mci, e, ONLY_HELO(mci->mci_flags));
3683 CLR_HELO(mci->mci_flags);
3688 ** Check whether other side can deliver e-mail
3692 if (!bitset(MCIF_DLVR_BY, mci->mci_flags))
3694 e->e_status = "5.4.7";
3695 usrerrenh(e->e_status,
3700 if (e->e_deliver_by > 0 &&
3701 e->e_deliver_by - (curtime() - e->e_ctime) <
3702 mci->mci_min_by)
3704 e->e_status = "5.4.7";
3705 usrerrenh(e->e_status,
3707 e->e_deliver_by - (long) (curtime() -
3708 e->e_ctime),
3709 mci->mci_min_by);
3720 if (mci->mci_state != MCIS_CLOSED &&
3721 !DONE_STARTTLS(mci->mci_flags))
3730 usetls = bitset(MCIF_TLS, mci->mci_flags) || implicittls;
3762 mci->mci_flags |= MCIF_TLSACT;
3767 !SM_TLSI_IS(&(mci->mci_tlsi), TLSI_FL_NODANE))
3768 macdefine(&e->e_macro, A_PERM, macid("{rcpt_addr}"), "");
3782 mci->mci_flags &= ~MCIF_TLS;
3828 TLSA_HAS_RRs(ste->s_tlsa))
3851 macdefine(&e->e_macro, A_PERM,
3865 if (!bitset(MCIF_TLS, mci->mci_flags) &&
3868 TLSA_HAS_RRs(ste->s_tlsa))
3877 macdefine(&e->e_macro, A_PERM,
3906 p = sm_rpool_strdup_x(e->e_rpool,
3921 mci->mci_state = MCIS_ERROR;
3922 SM_CLOSE_FP(mci->mci_out);
3923 mci->mci_flags &= ~MCIF_TLSACT;
3927 SM_TLSI_IS(&(mci->mci_tlsi),
3929 !SM_TLSI_IS(&(mci->mci_tlsi),
3936 && !SM_TLSI_IS(&(mci->mci_tlsi),
3951 mci->mci_errno = 0;
3966 else if (mci->mci_state == MCIS_CLOSED)
3969 mci->mci_errno = 0;
3978 if (DONE_STARTTLS(mci->mci_flags) &&
3979 mci->mci_state != MCIS_CLOSED
3985 SET_HELO(mci->mci_flags);
3995 mci->mci_host, tlsstate);
4006 mci->mci_errno = 0;
4022 if (!DONE_STARTTLS(mci->mci_flags))
4026 e->e_status = "4.3.3";
4027 usrerrenh(e->e_status, "454 TLS session initiation failed");
4031 e->e_status = "5.3.3";
4032 usrerrenh(e->e_status, "554 TLS session initiation failed");
4042 if (mci->mci_state != MCIS_CLOSED &&
4043 mci->mci_saslcap != NULL &&
4044 !DONE_AUTH(mci->mci_flags) && !iscltflgset(e, D_NOAUTH))
4053 result = sasl_getprop(mci->mci_conn, SASL_SSF,
4064 mci->mci_host,
4084 if (sfdcsasl(&mci->mci_in,
4085 &mci->mci_out,
4086 mci->mci_conn, tmo) == 0)
4089 mci->mci_flags |= MCIF_AUTHACT|
4096 mci->mci_flags |= MCIF_AUTHACT;
4104 mci->mci_host);
4108 mci->mci_errno = 0;
4126 /* clear out per-message flags from connection structure */
4127 mci->mci_flags &= ~(MCIF_CVT7TO8|MCIF_CVT8TO7);
4129 if (bitset(EF_HAS8BIT, e->e_flags) &&
4130 !bitset(EF_DONT_MIME, e->e_flags) &&
4131 bitnset(M_7BITS, m->m_flags))
4132 mci->mci_flags |= MCIF_CVT8TO7;
4135 if (bitnset(M_MAKE8BIT, m->m_flags) &&
4136 !bitset(MCIF_7BIT, mci->mci_flags) &&
4137 (p = hvalue("Content-Transfer-Encoding", e->e_header)) != NULL &&
4138 (SM_STRCASEEQ(p, "quoted-printable") ||
4140 (p = hvalue("Content-Type", e->e_header)) != NULL)
4142 /* may want to convert 7 -> 8 */
4143 /* XXX should really parse it here -- and use a class XXX */
4146 mci->mci_flags |= MCIF_CVT7TO8;
4164 if (bitset(MCIF_SIZE, mci->mci_flags) &&
4165 mci->mci_maxsize > 0 &&
4166 e->e_msgsize > mci->mci_maxsize)
4168 e->e_flags |= EF_NO_BODY_RETN;
4169 if (bitnset(M_LOCALMAILER, m->m_flags))
4170 e->e_status = "5.2.3";
4172 e->e_status = "5.3.4";
4174 usrerrenh(e->e_status,
4176 mci->mci_maxsize);
4182 mci->mci_maxsize);
4187 if (mci->mci_state != MCIS_OPEN)
4190 rcode = mci->mci_exitstat;
4191 errno = mci->mci_errno;
4192 SM_SET_H_ERRNO(mci->mci_herrno);
4198 mci->mci_state, firstsig);
4221 ok = (*e->e_puthdr)(mci, e->e_header, e, M87F_OUTER);
4223 ok = (*e->e_putbody)(mci, e, NULL);
4224 if (ok && bitset(MCIF_INLONGLINE, mci->mci_flags))
4233 if (!ok && (sm_io_error(mci->mci_out) && errno == EPIPE))
4249 m->m_name, m->m_mailer);
4260 mci->mci_okrcpts = 0;
4261 mci->mci_retryrcpt = rcode == EX_TEMPFAIL;
4275 mci->mci_retryrcpt = false;
4276 mci->mci_tolist = tobuf;
4279 mci->mci_nextaddr = NULL;
4282 for (to = tochain; to != NULL; to = to->q_tchain)
4284 if (!QS_IS_UNMARKED(to->q_state))
4288 to->q_state = QS_OK;
4289 e->e_to = to->q_paddr;
4291 if (CHKMTASTS && to->q_user != NULL)
4292 macdefine(&e->e_macro, A_TEMP,
4293 macid("{rcpt_addr}"), to->q_user);
4295 macdefine(&e->e_macro, A_PERM,
4306 vrfy, to->q_user, CurHostName, RCPT_MXSECURE(to),
4312 0, m->m_port);
4316 vrfy, to->q_user,
4318 STE_HAS_TLSA(ste) ? TLSA_IS_FL(ste->s_tlsa, TLSAFLSUP) : -1,
4323 mci->mci_flags
4329 macdefine(&mci->mci_macro, A_PERM, macid("{verify}"), "FAIL");
4343 macdefine(&mci->mci_macro, A_PERM, macid("{verify}"),
4346 (bitset(MCIF_TLS|MCIF_TLSACT, mci->mci_flags) ?
4352 && (!bitset(MCIF_TLS|MCIF_TLSACT, mci->mci_flags)
4355 macdefine(&mci->mci_macro, A_PERM, macid("{verify}"),
4367 rc = rscheck("tls_rcpt", to->q_user, NULL, e,
4369 mci->mci_host, e->e_id, &addr, NULL);
4374 macdefine(&mci->mci_macro, A_PERM, macid("{verify}"), vrfy);
4382 to->q_user, rc);
4388 to->q_flags |= QINTREPLY;
4399 mci->mci_retryrcpt = true;
4400 to->q_state = QS_RETRY;
4409 bitset(MCIF_PIPELINED, mci->mci_flags))
4416 to->q_pchain = NULL;
4417 if (mci->mci_nextaddr == NULL)
4418 mci->mci_nextaddr = to;
4423 pchain->q_pchain = to;
4424 pchain = pchain->q_pchain;
4431 giveresponse(rc, to->q_status, m, mci,
4434 to->q_state = QS_RETRY;
4441 /* && bitset(MCIF_PIPELINED, mci->mci_flags) */
4442 && mci->mci_nextaddr == NULL
4447 e->e_to = NULL;
4448 if (bitset(MCIF_CACHED, mci->mci_flags))
4453 e->e_to = tobuf + 1;
4459 && (mci->mci_retryrcpt || mci->mci_okrcpts > 0)
4483 if (bitnset(M_LMTP, m->m_flags))
4493 for (to = tochain; to != NULL; to = to->q_tchain)
4496 if (!QS_IS_OK(to->q_state))
4500 if (bitnset(M_LMTP, m->m_flags))
4507 to->q_paddr,
4508 tobufsize - strsize);
4514 e->e_to = to->q_paddr;
4516 giveresponse(rcode, to->q_status, m, mci,
4518 e->e_to = tobuf + 1;
4535 to->q_state = QS_SENT;
4536 to->q_statdate = curtime();
4537 e->e_nsent++;
4543 if (CheckpointInterval > 0 && e->e_nsent >= CheckpointInterval)
4546 e->e_nsent = 0;
4549 if (bitnset(M_LOCALMAILER, m->m_flags) &&
4550 bitset(QPINGONSUCCESS, to->q_flags))
4552 to->q_flags |= QDELIVERED;
4553 to->q_status = "2.1.5";
4554 (void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
4556 to->q_paddr);
4558 else if (bitset(QPINGONSUCCESS, to->q_flags) &&
4559 bitset(QPRIMARY, to->q_flags) &&
4560 !bitset(MCIF_DSN, mci->mci_flags))
4562 to->q_flags |= QRELAYED;
4563 (void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
4565 to->q_paddr);
4568 !bitset(MCIF_DLVR_BY, mci->mci_flags) &&
4569 bitset(QPRIMARY, to->q_flags) &&
4570 (!bitset(QHASNOTIFY, to->q_flags) ||
4571 bitset(QPINGONSUCCESS, to->q_flags) ||
4572 bitset(QPINGONFAILURE, to->q_flags) ||
4573 bitset(QPINGONDELAY, to->q_flags)))
4576 to->q_flags |= QBYNRELAY;
4577 (void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
4578 "%s... Deliver-by notify: relayed\n",
4579 to->q_paddr);
4582 (!bitset(QHASNOTIFY, to->q_flags) ||
4583 bitset(QPINGONSUCCESS, to->q_flags) ||
4584 bitset(QPINGONFAILURE, to->q_flags) ||
4585 bitset(QPINGONDELAY, to->q_flags)) &&
4586 bitset(QPRIMARY, to->q_flags))
4589 to->q_flags |= QBYTRACE;
4590 (void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
4591 "%s... Deliver-By trace: relayed\n",
4592 to->q_paddr);
4596 if (bitnset(M_LMTP, m->m_flags))
4604 e->e_statmsg = NULL;
4608 (mci->mci_state == MCIS_MAIL ||
4609 mci->mci_state == MCIS_RCPT ||
4610 mci->mci_state == MCIS_DATA))
4612 mci->mci_state = MCIS_OPEN;
4613 SmtpPhase = mci->mci_phase = "idle";
4615 mci->mci_phase);
4623 (NULL == mci || SM_IS_EMPTY(mci->mci_status))
4626 mci->mci_status,
4632 ** to all non-status'ed recipients is a good idea.
4635 if (tochain->q_message != NULL &&
4636 !bitnset(M_LMTP, m->m_flags) && rcode != EX_OK)
4638 for (to = tochain->q_tchain; to != NULL;
4639 to = to->q_tchain)
4642 if (QS_IS_QUEUEUP(to->q_state) &&
4643 to->q_message == NULL)
4644 to->q_message = sm_rpool_strdup_x(e->e_rpool,
4645 tochain->q_message);
4672 if (mci != NULL && mci->mci_retryrcpt && nummxhosts > hostnum)
4680 if (clever && mci != NULL && mci->mci_state != MCIS_CLOSED &&
4681 !bitset(MCIF_CACHED, mci->mci_flags))
4697 e->e_to == NULL ? "NO-TO-LIST"
4698 : shortenstring(e->e_to,
4700 m->m_name);
4712 macdefine(&e->e_macro, A_PERM, 'g', (char *) NULL);
4713 e->e_to = NULL;
4720 ** EX2ENHSC -- return proper enhanced status code for an EX_ code
4723 ** xcode -- EX_* code
4781 ** MARKFAILURE -- mark a failure on a specific address.
4784 ** e -- the envelope we are sending.
4785 ** q -- the address to mark.
4786 ** mci -- mailer connection information.
4787 ** rcode -- the code signifying the particular failure.
4788 ** ovr -- override an existing code?
4819 q->q_state = QS_QUEUEUP;
4823 q->q_state = QS_BADADDR;
4828 if (mci != NULL && mci->mci_status != NULL)
4830 status = sm_rpool_strdup_x(e->e_rpool, mci->mci_status);
4831 if (mci->mci_rstatus != NULL)
4832 rstatus = sm_rpool_strdup_x(e->e_rpool,
4833 mci->mci_rstatus);
4835 else if (e->e_status != NULL)
4836 status = e->e_status;
4841 if (status != NULL && *status != '\0' && (ovr || q->q_status == NULL ||
4842 *q->q_status == '\0' || *q->q_status < *status))
4844 q->q_status = status;
4845 q->q_rstatus = rstatus;
4847 if (rcode != EX_OK && q->q_rstatus == NULL &&
4848 q->q_mailer != NULL && q->q_mailer->m_diagtype != NULL &&
4849 SM_STRCASEEQ(q->q_mailer->m_diagtype, "X-UNIX"))
4854 q->q_rstatus = sm_rpool_strdup_x(e->e_rpool, buf);
4857 q->q_statdate = curtime();
4859 mci != NULL && !bitset(M_LOCALMAILER, mci->mci_flags))
4860 q->q_statmta = sm_rpool_strdup_x(e->e_rpool, CurHostName);
4866 ** ENDMAILER -- Wait for mailer to terminate.
4874 ** mci -- the mailer connection info.
4875 ** e -- the current envelope.
4876 ** pv -- the parameter vector that invoked the mailer
4917 SM_CLOSE_FP(mci->mci_out);
4920 if (mci->mci_in != NULL && mci->mci_state != MCIS_ERROR &&
4921 e->e_xfp != NULL)
4923 while (sfgets(buf, sizeof(buf), mci->mci_in,
4925 (void) sm_io_fputs(e->e_xfp, SM_TIME_DEFAULT, buf);
4930 if (bitset(MCIF_AUTHACT, mci->mci_flags))
4932 sasl_dispose(&mci->mci_conn);
4933 mci->mci_flags &= ~MCIF_AUTHACT;
4943 SM_CLOSE_FP(mci->mci_in);
4944 mci->mci_state = MCIS_CLOSED;
4949 if (mci->mci_pid == 0)
4953 if (mci->mci_mailer->m_wait > 0)
4956 ev = sm_setevent(mci->mci_mailer->m_wait,
4961 mci->mci_mailer->m_name,
4962 (long) mci->mci_mailer->m_wait);
4968 st = waitfor(mci->mci_pid);
4974 if (st == -1)
4976 syserr("endmailer %s: wait", mci->mci_mailer->m_name);
4982 /* normal death -- return status */
4988 mci->mci_mailer->m_name, WTERMSIG(st),
4993 if (pv != NULL && e->e_xfp != NULL)
4997 (void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT, "Arguments:");
4999 (void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT, " %s",
5001 (void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT, "\n");
5008 ** GIVERESPONSE -- Interpret an error response from a mailer
5011 ** status -- the status code from the mailer (high byte
5014 ** dsn -- the DSN associated with the address, if any.
5015 ** m -- the mailer info for this mailer.
5016 ** mci -- the mailer connection info -- can be NULL if the
5018 ** ctladdr -- the controlling address for the recipient
5020 ** xstart -- the transaction start time, for computing
5022 ** e -- the current envelope.
5023 ** to -- the current recipient (NULL if none).
5060 sm_dprintf("giveresponse: status=%d, e->e_message=%s, dsn=%s, SmtpError=%s\n",
5061 status, e->e_message, dsn, SmtpError);
5071 if (e->e_statmsg != NULL)
5075 shortenstring(e->e_statmsg, 403));
5127 if (mci != NULL && mci->mci_host != NULL)
5132 mci->mci_host);
5142 mci->mci_exitstat == EX_TEMPFAIL)
5165 && e->e_message != NULL && e->e_message[0] != '\0')
5170 m = skipaddrhost(e->e_message, false);
5174 ** How to avoid a hard-coded value?
5177 (void) sm_snprintf(buf, sizeof(buf), "550 %s", e->e_message + m);
5192 else if (bitnset(M_LMTP, m->m_flags) && e->e_statmsg != NULL)
5195 shortenstring(e->e_statmsg, 403));
5224 if (status == EX_TEMPFAIL && e->e_xfp != NULL)
5225 (void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT, "%s\n",
5234 off < sizeof(mbuf) - 4)
5261 ** -- if we already had an error, stick with that.
5264 if (OpMode != MD_VERIFY && !bitset(EF_VRFYONLY, e->e_flags) &&
5269 sm_dprintf("giveresponse: status=%d, dsn=%s, e->e_message=%s, errnum=%d, statmsg=%s\n",
5272 e->e_message == NULL ? "<NULL>" : e->e_message,
5277 if (status != EX_OK && (status != EX_TEMPFAIL || e->e_message == NULL))
5278 e->e_message = sm_rpool_strdup_x(e->e_rpool, statmsg + off);
5279 if (status != EX_OK && to != NULL && to->q_message == NULL)
5281 if (!usestat && e->e_message != NULL)
5282 to->q_message = sm_rpool_strdup_x(e->e_rpool,
5283 e->e_message);
5285 to->q_message = sm_rpool_strdup_x(e->e_rpool,
5301 ** LOGDELIVERY -- log the delivery in the system log
5308 ** m -- the mailer info. Can be NULL for initial queue.
5309 ** mci -- the mailer connection info -- can be NULL if the
5311 ** dsn -- the DSN attached to the status.
5312 ** status -- the message to print for the status.
5313 ** ctladdr -- the controlling address for the to list.
5314 ** xstart -- the transaction start time, used for
5316 ** e -- the current envelope.
5317 ** to -- the current recipient (NULL if none).
5318 ** rcode -- status code.
5357 shortenstring(ctladdr->q_paddr, 83));
5359 if (bitset(QGOODUID, ctladdr->q_flags))
5362 (int) ctladdr->q_uid,
5363 (int) ctladdr->q_gid);
5370 pintvl(now - e->e_ctime, true));
5376 pintvl(now - xstart, true));
5384 m->m_name);
5394 PRT_NONNEGL(e->e_msgpriority));
5398 if (mci != NULL && mci->mci_host != NULL)
5403 shortenstring(mci->mci_host, 40));
5414 if (e->e_quarmsg != NULL)
5417 shortenstring(e->e_quarmsg, 40));
5433 xtype = p[0] - '0';
5448 (rtype = dsn[0] - '0') > 0 && rtype != xtype)
5449 sm_syslog(LOG_ERR, e->e_id,
5456 if (e->e_ntries >= 0)
5459 ", ntries=%d", e->e_ntries + 1);
5464 # define STATLEN (((SYSLOG_BUFSIZE) - 100) / 4)
5476 if (rcode != EX_OK && e->e_estate >= 0)
5478 if (e->e_estate >= 0 && e->e_estate < SM_ARRAY_SIZE(xs_states))
5480 ", stage=%s", xs_states[e->e_estate]);
5483 ", stage=%d", e->e_estate);
5490 ** per-rcpt status: to->q_rstatus
5491 ** global status: e->e_text
5499 ** reply - how to avoid that?
5503 if (rcode != EX_OK && (NULL == to || !bitset(QINTREPLY, to->q_flags)))
5505 if (to != NULL && !SM_IS_EMPTY(to->q_rstatus))
5509 shortenstring(to->q_rstatus, STATLEN));
5511 if (ISSMTPCODE(to->q_rstatus) &&
5512 (rtype = to->q_rstatus[0] - '0') > 0 &&
5514 sm_syslog(LOG_ERR, e->e_id,
5516 WHERE2REPORT, rcode, to->q_rstatus);
5518 else if (e->e_text != NULL)
5522 e->e_rcode,
5523 e->e_renhsc,
5524 (e->e_renhsc[0] != '\0') ? " " : "",
5525 shortenstring(e->e_text, STATLEN));
5527 rtype = REPLYTYPE(e->e_rcode);
5530 sm_syslog(LOG_ERR, e->e_id,
5532 WHERE2REPORT, rcode, e->e_rcode, e->e_text);
5547 if ((bp - buf) > (sizeof(buf) - ((STATLEN) + 20)))
5549 /* desperation move -- truncate data */
5550 bp = buf + sizeof(buf) - ((STATLEN) + 17);
5562 l = SYSLOG_BUFSIZE - 100 - strlen(buf);
5565 p = e->e_to == NULL ? "NO-TO-LIST" : e->e_to;
5570 for (q = p + l; q > p; q--)
5585 sm_syslog(LOG_INFO, e->e_id, "to=%.*s [more]%s",
5586 (int) (++q - p), xstr, buf);
5595 sm_syslog(LOG_INFO, e->e_id, "to=%.*s%s", l, xstr, buf);
5599 l = SYSLOG_BUFSIZE - 85;
5602 p = e->e_to == NULL ? "NO-TO-LIST" : e->e_to;
5607 for (q = p + l; q > p; q--)
5615 sm_syslog(LOG_INFO, e->e_id, "to=%.*s [more]",
5616 (int) (++q - p), p);
5619 sm_syslog(LOG_INFO, e->e_id, "to=%.*s", l, p);
5625 shortenstring(ctladdr->q_paddr, 83));
5627 if (bitset(QGOODUID, ctladdr->q_flags))
5630 ctladdr->q_uid, ctladdr->q_gid);
5633 sm_syslog(LOG_INFO, e->e_id, "%s", buf);
5637 pintvl(now - e->e_ctime, true));
5642 pintvl(now - xstart, true));
5649 m->m_name);
5652 sm_syslog(LOG_INFO, e->e_id, "%.1000s", buf);
5656 if (mci != NULL && mci->mci_host != NULL)
5661 mci->mci_host);
5671 if (e->e_quarmsg != NULL)
5674 e->e_quarmsg);
5686 sm_syslog(LOG_INFO, e->e_id, "%.1000s", buf);
5688 sm_syslog(LOG_INFO, e->e_id, "stat=%s", shortenstring(status, 63));
5692 ** PUTFROMLINE -- output a UNIX-style from line (or whatever)
5698 ** does a well-meaning programmer such as myself have to deal with
5702 ** mci -- the connection information.
5703 ** e -- the envelope.
5721 if (bitnset(M_NHDR, mci->mci_mailer->m_flags))
5724 mci->mci_flags |= MCIF_INHEADER;
5726 if (bitnset(M_UGLYUUCP, mci->mci_mailer->m_flags))
5767 ** PUTBODY -- put the body of a message.
5770 ** mci -- the connection information.
5771 ** e -- the envelope to put out.
5772 ** separator -- if non-NULL, a message separator that must
5805 if (e->e_dfp == NULL && bitset(EF_HAS_DF, e->e_flags))
5809 e->e_dfp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, df,
5811 if (e->e_dfp == NULL)
5817 syserr(msg, df, e->e_to, e->e_from.q_paddr);
5821 if (e->e_dfp == NULL)
5823 if (bitset(MCIF_INHEADER, mci->mci_flags))
5827 mci->mci_flags &= ~MCIF_INHEADER;
5834 if (e->e_dfino == (ino_t) 0)
5838 if (fstat(sm_io_getinfo(e->e_dfp, SM_IO_WHAT_FD, NULL), &stbuf)
5840 e->e_dfino = -1;
5843 e->e_dfdev = stbuf.st_dev;
5844 e->e_dfino = stbuf.st_ino;
5849 (void) bfrewind(e->e_dfp);
5856 if (bitset(MCIF_CVT8TO7, mci->mci_flags))
5863 if (hvalue("MIME-Version", e->e_header) == NULL &&
5864 !putline("MIME-Version: 1.0", mci))
5867 if (hvalue("Content-Type", e->e_header) == NULL)
5870 "Content-Type: text/plain; charset=%s",
5878 mci->mci_flags |= MCIF_INHEADER;
5879 if (mime8to7(mci, e->e_header, e, boundaries, M87F_OUTER, 0) ==
5884 else if (bitset(MCIF_CVT7TO8, mci->mci_flags))
5886 if (!mime7to8(mci, e->e_header, e))
5896 mci->mci_flags |= MCIF_INHEADER;
5906 if (bitset(EF_DONT_MIME, e->e_flags))
5909 if (mime8to7(mci, e->e_header, e, boundaries,
5926 int pos = 0; local
5929 if (bitset(MCIF_INHEADER, mci->mci_flags))
5933 mci->mci_flags &= ~MCIF_INHEADER;
5937 buflim = &buf[sizeof(buf) - 1];
5938 if (mci->mci_mailer->m_linelimit > 0 &&
5939 mci->mci_mailer->m_linelimit < sizeof(buf) - 1)
5940 buflim = &buf[mci->mci_mailer->m_linelimit - 1];
5946 while (!sm_io_error(mci->mci_out) && !dead)
5949 c = *--pbp;
5950 else if ((c = sm_io_getc(e->e_dfp, SM_TIME_DEFAULT))
5953 if (bitset(MCIF_7BIT, mci->mci_flags))
5960 mci->mci_mailer->m_flags))
5970 pos = 0;
5973 bitnset(M_ESCFROM, mci->mci_mailer->m_flags)
5978 if (buf[0] == '-' && buf[1] == '-' &&
5989 bitnset(M_XDOT, mci->mci_mailer->m_flags))
6012 mci->mci_mailer->m_eol);
6016 if (sm_io_putc(mci->mci_out,
6023 pos++;
6027 if (sm_io_putc(mci->mci_out,
6040 if (sm_io_fputs(mci->mci_out,
6042 mci->mci_mailer->m_eol)
6045 pos = 0;
6049 pos += bp - buf;
6073 if (sm_io_fputs(mci->mci_out,
6075 mci->mci_mailer->m_eol)
6083 mci->mci_mailer->m_eol);
6085 pos = 0;
6105 mci->mci_mailer->m_flags))
6108 if (mci->mci_mailer->m_linelimit > 0 &&
6109 pos >= mci->mci_mailer->m_linelimit - 1 &&
6116 d = *(pbp - 1);
6117 else if ((d = sm_io_getc(e->e_dfp,
6132 if (sm_io_putc(mci->mci_out,
6140 pos++;
6144 if (sm_io_putc(mci->mci_out,
6147 sm_io_fputs(mci->mci_out,
6149 mci->mci_mailer->m_eol)
6161 mci->mci_mailer->m_eol);
6174 mci->mci_mailer->m_eol);
6175 if (sm_io_fputs(mci->mci_out,
6177 mci->mci_mailer->m_eol)
6180 pos = 0;
6189 if (sm_io_putc(mci->mci_out,
6197 pos++;
6216 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
6224 pos += bp - buf;
6226 if (!dead && pos > 0)
6231 mci->mci_mailer->m_eol);
6232 if (sm_io_fputs(mci->mci_out, SM_TIME_DEFAULT,
6233 mci->mci_mailer->m_eol) == SM_IO_EOF)
6238 if (sm_io_error(e->e_dfp))
6241 qid_printqueue(e->e_dfqgrp, e->e_dfqdir),
6242 DATAFL_LETTER, e->e_id);
6251 ** parent process will not agree with the in-kernel
6260 if (e->e_dfp != NULL)
6261 (void) bfrewind(e->e_dfp);
6264 if (!dead && bitnset(M_BLANKEND, mci->mci_mailer->m_flags) &&
6272 (sm_io_flush(mci->mci_out, SM_TIME_DEFAULT) == SM_IO_EOF ||
6273 (sm_io_error(mci->mci_out) && errno != EPIPE)))
6289 ** MAILFILE -- Send a message to a file.
6291 ** If the file has the set-user-ID/set-group-ID bits set, but NO
6303 ** filename -- the name of the file to send to.
6304 ** mailer -- mailer definition for recipient -- if NULL,
6306 ** ctladdr -- the controlling address header -- includes
6308 ** sfflags -- flags for opening.
6309 ** e -- the current envelope.
6331 register pid_t pid = -1;
6351 if (e->e_xfp != NULL)
6352 (void) sm_io_flush(e->e_xfp, SM_TIME_DEFAULT);
6362 /* check for 8-bit available */
6363 if (bitset(EF_HAS8BIT, e->e_flags) &&
6364 bitnset(M_7BITS, mailer->m_flags) &&
6365 (bitset(EF_DONT_MIME, e->e_flags) ||
6367 (bitset(EF_IS_MIME, e->e_flags) &&
6370 e->e_status = "5.6.3";
6371 usrerrenh(e->e_status,
6372 "554 Cannot send 8-bit data to 7-bit destination");
6398 if (targetfile[len - 1] != '/')
6405 else if (mailer->m_rootdir != NULL)
6407 expand(mailer->m_rootdir, targetfile, sizeof(targetfile), e);
6420 if (targetfile[len - 1] != '/')
6460 /* child -- actually write to file */
6473 if (e->e_lockfp != NULL)
6477 fd = sm_io_getinfo(e->e_lockfp, SM_IO_WHAT_FD, NULL);
6487 e->e_to = filename;
6501 /* check file mode to see if set-user-ID */
6512 if ((ctladdr != NULL && !bitset(QALIAS, ctladdr->q_flags)) ||
6515 /* ignore set-user-ID and set-group-ID bits */
6518 sm_dprintf("mailfile: ignoring set-user-ID/set-group-ID bits\n");
6522 if (e->e_dfp == NULL && bitset(EF_HAS_DF, e->e_flags))
6526 e->e_dfp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, df,
6528 if (e->e_dfp == NULL)
6531 df, e->e_to, e->e_from.q_paddr);
6538 if (bitnset(M_SPECIFIC_UID, mailer->m_flags))
6541 if (mailer->m_uid == NO_UID)
6544 RealUid = mailer->m_uid;
6558 else if (ctladdr != NULL && ctladdr->q_uid != 0)
6560 if (ctladdr->q_ruser != NULL)
6561 RealUserName = ctladdr->q_ruser;
6563 RealUserName = ctladdr->q_user;
6564 RealUid = ctladdr->q_uid;
6566 else if (mailer != NULL && mailer->m_uid != NO_UID)
6569 RealUid = mailer->m_uid;
6578 if (bitnset(M_SPECIFIC_UID, mailer->m_flags))
6580 if (mailer->m_gid == NO_GID)
6583 RealGid = mailer->m_gid;
6598 ctladdr->q_uid == DefUid &&
6599 ctladdr->q_gid == 0)
6610 else if (ctladdr != NULL && ctladdr->q_uid != 0)
6611 RealGid = ctladdr->q_gid;
6612 else if (mailer != NULL && mailer->m_gid != NO_GID)
6613 RealGid = mailer->m_gid;
6630 if (initgroups(RealUserName, RealGid) == -1 && suidwarn)
6642 if (setgroups(1, gidset) == -1 && suidwarn)
6701 if (mailer->m_execdir != NULL)
6705 for (p = mailer->m_execdir; p != NULL; p = q)
6797 if (bitnset(M_7BITS, mailer->m_flags))
6800 /* clear out per-message flags from connection structure */
6803 if (bitset(EF_HAS8BIT, e->e_flags) &&
6804 !bitset(EF_DONT_MIME, e->e_flags) &&
6805 bitnset(M_7BITS, mailer->m_flags))
6809 if (bitnset(M_MAKE8BIT, mailer->m_flags) &&
6811 (p = hvalue("Content-Transfer-Encoding", e->e_header)) != NULL &&
6812 (SM_STRCASEEQ(p, "quoted-printable") ||
6814 (p = hvalue("Content-Type", e->e_header)) != NULL)
6816 /* may want to convert 7 -> 8 */
6817 /* XXX should really parse it here -- and use a class XXX */
6825 !(*e->e_puthdr)(&mcibuf, e->e_header, e, M87F_OUTER) ||
6826 !(*e->e_putbody)(&mcibuf, e, NULL) ||
6856 /* parent -- wait for exit status */
6860 if (st == -1)
6862 syserr("mailfile: %s: wait", mailer->m_name);
6873 mailer->m_name, st);
6898 ** GETMPORT -- return the port of a mailer
6901 ** m -- the mailer describing this host.
6918 if (m->m_port > 0)
6919 return m->m_port;
6921 if (NULL == m->m_argv[0] ||NULL == m->m_argv[1])
6922 return -1;
6923 buf = m->m_argv[2];
6930 return -1;
6932 return -1;
6934 return -1;
6935 m->m_port = (unsigned short) ulval;
6937 sm_dprintf("getmport: mailer=%s, port=%d\n", m->m_name,
6938 m->m_port);
6939 return m->m_port;
6947 ** HOSTSIGNATURE -- return the "signature" for a host (list).
6949 ** The signature describes how we are going to send this -- it
6950 ** can be just the hostname (for non-Internet hosts) or can be
6954 ** m -- the mailer describing this host.
6955 ** host -- the host name (can be a list).
6956 ** ad -- DNSSEC: ad flag for lookup of host.
6957 ** pqflags -- (pointer to) q_flags (can be NULL)
7003 if (bitnset(M_LOCALMAILER, m->m_flags) &&
7004 strcmp(m->m_mailer, "[IPC]") != 0 &&
7005 !(m->m_argv[0] != NULL && strcmp(m->m_argv[0], "TCP") == 0))
7013 ** Check to see if this uses IPC -- if not, it can't have MX records.
7016 if (strcmp(m->m_mailer, "[IPC]") != 0 ||
7017 CurEnv->e_sendmode == SM_DEFER)
7023 else if (m->m_argv[0] != NULL &&
7024 strcmp(m->m_argv[0], "FILE") == 0)
7037 if (s->s_hostsig.hs_sig != NULL)
7039 if (s->s_hostsig.hs_exp >= now)
7043 s->s_hostsig.hs_sig);
7044 return s->s_hostsig.hs_sig;
7048 sm_free(s->s_hostsig.hs_sig);
7049 s->s_hostsig.hs_sig = NULL;
7053 s->s_hostsig.hs_exp = now + SM_DEFAULT_TTL;
7056 ** Not already there or expired -- create a signature.
7083 if (bitnset(M_NOMX, m->m_flags))
7107 mci->mci_errno = save_errno;
7108 mci->mci_herrno = h_errno;
7109 mci->mci_lastuse = now;
7140 s->s_hostsig.hs_exp = now + SM_MIN(ttl, SM_DEFAULT_TTL);
7146 if (s->s_hostsig.hs_sig != NULL)
7147 len += strlen(s->s_hostsig.hs_sig) + 1;
7159 if (s->s_hostsig.hs_sig != NULL)
7161 (void) sm_strlcpy(p, s->s_hostsig.hs_sig, len);
7162 sm_free(s->s_hostsig.hs_sig); /* XXX */
7163 s->s_hostsig.hs_sig = p;
7167 len -= hl + 1;
7170 s->s_hostsig.hs_sig = p;
7176 len - 1 < (hl + ((admx && DANE_SEC(Dane)) ? 1 : 0))
7178 len - 1 < hl
7183 len = -1;
7188 if (mxprefs[i] == mxprefs[i - 1])
7192 len--;
7198 len--;
7203 len -= hl;
7218 lstr = makelower_a(&s->s_hostsig.hs_sig, NULL);
7219 ASSIGN_IFDIFF(s->s_hostsig.hs_sig, lstr);
7223 /* not using BIND -- the signature is just the host name */
7228 s->s_hostsig.hs_sig = sm_pstrdup_x(host);
7231 sm_dprintf("hostsignature: host=%s, result=%s\n", host, s->s_hostsig.hs_sig);
7232 return s->s_hostsig.hs_sig;
7236 ** PARSE_HOSTSIGNATURE -- parse the "signature" and return MX host array.
7238 ** The signature describes how we are going to send this -- it
7239 ** can be just the hostname (for non-Internet hosts) or can be
7244 ** sig -- the host signature.
7245 ** mxhosts -- array to populate.
7246 ** mailer -- mailer.
7253 ** mxhosts[] will point to elements in sig --
7363 ** SETCLTTLS -- client side TLS: allow/disallow.
7366 ** tls_ok -- should tls be done?
7384 ** INITCLTTLS -- initialize client side TLS
7387 ** tls_ok -- should TLS initialization be done?
7440 r = -1;
7466 ** STARTTLS -- try to start secure connection (client side)
7469 ** m -- the mailer.
7470 ** mci -- the mailer connection info.
7471 ** e -- the envelope.
7472 ** implicit -- implicit TLS (SMTP over TLS, no STARTTLS command)
7505 Dane,dane_vrfy_ctx->dane_vrfy_chk);
7530 ret = get_tls_se_features(e, clt_ssl, &mci->mci_tlsi, false);
7568 if (smtpresult == -1)
7591 result = SSL_set_ex_data(clt_ssl, TLSsslidx, &mci->mci_tlsi);
7604 if (SM_TLSI_IS(&(mci->mci_tlsi), TLSI_FL_NODANE))
7605 dane_vrfy_ctx->dane_vrfy_chk = DANE_NEVER;
7608 dane_vrfy_ctx->dane_vrfy_chk,
7609 CHK_DANE(dane_vrfy_ctx->dane_vrfy_chk));
7610 if (CHK_DANE(dane_vrfy_ctx->dane_vrfy_chk))
7618 dane_vrfy_ctx->dane_vrfy_host,
7619 dane_vrfy_ctx->dane_vrfy_sni,
7621 dane_vrfy_ctx->dane_vrfy_dane_enabled);
7623 !(SM_IS_EMPTY(dane_vrfy_ctx->dane_vrfy_host) &&
7624 SM_IS_EMPTY(dane_vrfy_ctx->dane_vrfy_sni)))
7629 dane_vrfy_ctx->dane_vrfy_dane_enabled = ctx_dane_enabled;
7632 dane_vrfy_ctx->dane_vrfy_dane_enabled = false;
7637 dane_vrfy_ctx->dane_vrfy_host, r);
7641 dane_vrfy_ctx->dane_vrfy_dane_enabled = false;
7644 r, dane_vrfy_ctx->dane_vrfy_chk,
7645 dane_vrfy_ctx->dane_vrfy_dane_enabled);
7647 (!SM_IS_EMPTY(dane_vrfy_ctx->dane_vrfy_sni)
7648 ? dane_vrfy_ctx->dane_vrfy_sni
7649 : dane_vrfy_ctx->dane_vrfy_host))) <= 0)
7655 dane_vrfy_ctx->dane_vrfy_host, r);
7662 memcpy(&mci->mci_tlsi.tlsi_dvc, dane_vrfy_ctx, sizeof(*dane_vrfy_ctx));
7683 rfd = sm_io_getinfo(mci->mci_in, SM_IO_WHAT_FD, NULL);
7684 wfd = sm_io_getinfo(mci->mci_out, SM_IO_WHAT_FD, NULL);
7730 mci->mci_ssl = clt_ssl;
7731 result = tls_get_info(mci->mci_ssl, false, mci->mci_host,
7732 &mci->mci_macro, true);
7735 if (sfdctls(&mci->mci_in, &mci->mci_out, mci->mci_ssl) == 0)
7745 ** ENDTLSCLT -- shutdown secure connection (client side)
7748 ** mci -- the mailer connection info.
7760 if (!bitset(MCIF_TLSACT, mci->mci_flags))
7762 r = endtls(&mci->mci_ssl, "client");
7763 mci->mci_flags &= ~MCIF_TLSACT;
7769 ** ISCLTFLGSET -- check whether client flag is set.
7772 ** e -- envelope.
7773 ** flag -- flag to check in {client_flags}
7834 q = hostsignature(a->q_mailer, a->q_host, true, &a->q_flags);
7843 t_parsehostsig(q, (NULL != a) ? a->q_mailer : mailer);