Mercurial > dnsbl
comparison src/dnsbl.cpp @ 436:7b072e16bd69 stable-6-0-64
fix syslog for long messages, supress dkim checks for mail from localhost
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 03 Nov 2017 09:57:13 -0700 |
parents | 4ffa356316d5 |
children | 1686cb639269 |
comparison
equal
deleted
inserted
replaced
435:afd10321eb70 | 436:7b072e16bd69 |
---|---|
847 | 847 |
848 //////////////////////////////////////////////// | 848 //////////////////////////////////////////////// |
849 // syslog a message | 849 // syslog a message |
850 // | 850 // |
851 void my_syslog(const char *queueid, const char *text) { | 851 void my_syslog(const char *queueid, const char *text) { |
852 char buf[maxlen]; | 852 const char* noqueue = "NOQUEUE"; |
853 if (queueid && queueid[0]) { | 853 if (!queueid || !queueid[0]) queueid = noqueue; |
854 | |
855 const int syslogmaxlen = 400; // buffer size | |
856 char buf[syslogmaxlen]; | |
857 snprintf(buf, sizeof(buf), "%s: ", queueid); | |
858 size_t hdrlen = strlen(buf); | |
859 const size_t maxsegment = syslogmaxlen - hdrlen - 1; | |
860 size_t msglen = strlen(text); | |
861 while (msglen > 0) { | |
854 snprintf(buf, sizeof(buf), "%s: %s", queueid, text); | 862 snprintf(buf, sizeof(buf), "%s: %s", queueid, text); |
855 text = buf; | 863 if (use_syslog) { |
856 } | 864 pthread_mutex_lock(&syslog_mutex); |
857 if (use_syslog) { | 865 if (!syslog_opened) { |
858 pthread_mutex_lock(&syslog_mutex); | 866 openlog("dnsbl", LOG_PID, LOG_MAIL); |
859 if (!syslog_opened) { | 867 syslog_opened = true; |
860 openlog("dnsbl", LOG_PID, LOG_MAIL); | 868 } |
861 syslog_opened = true; | 869 syslog(LOG_NOTICE, "%s", buf); |
862 } | 870 pthread_mutex_unlock(&syslog_mutex); |
863 syslog(LOG_NOTICE, "%s", text); | 871 } |
864 pthread_mutex_unlock(&syslog_mutex); | 872 else { |
865 } | 873 printf("%s \n", buf); |
866 else { | 874 } |
867 printf("%s \n", text); | 875 size_t segmentlen = min(msglen, maxsegment); |
868 } | 876 text += segmentlen; |
877 msglen -= segmentlen; | |
878 // assert(msglen == strlen(text)) | |
879 } | |
880 | |
869 } | 881 } |
870 | 882 |
871 void my_syslog(mlfiPriv *priv, const char *text) { | 883 void my_syslog(mlfiPriv *priv, const char *text) { |
872 if (priv) my_syslog(priv->queueid, text); | 884 if (priv) my_syslog(priv->queueid, text); |
873 else my_syslog((const char *)NULL, text); | 885 else my_syslog((const char *)NULL, text); |
1406 } | 1418 } |
1407 else if ((fromvalue == token_white) && !self) { | 1419 else if ((fromvalue == token_white) && !self) { |
1408 // whitelisting based on envelope from value, but ignore it if | 1420 // whitelisting based on envelope from value, but ignore it if |
1409 // we have a dkim requirement for the original domain | 1421 // we have a dkim requirement for the original domain |
1410 const char *domain = strchr(priv.origaddr, '@'); | 1422 const char *domain = strchr(priv.origaddr, '@'); |
1411 if (domain) { | 1423 if (domain && !local_source) { |
1412 DKIMP dk = con.find_dkim_from(domain+1); | 1424 DKIMP dk = con.find_dkim_from(domain+1); |
1413 if (dk && (dk->action == token_require_signed)) { | 1425 if (dk && (dk->action == token_require_signed)) { |
1414 my_syslog(&priv, "dkim require_signed overrides envelope from whitelist"); | 1426 my_syslog(&priv, "dkim require_signed overrides envelope from whitelist"); |
1415 st = oksofar; | 1427 st = oksofar; |
1416 } | 1428 } |
1714 priv.eom = true; | 1726 priv.eom = true; |
1715 if (priv.authenticated || priv.only_whites) rc = SMFIS_CONTINUE; | 1727 if (priv.authenticated || priv.only_whites) rc = SMFIS_CONTINUE; |
1716 else { | 1728 else { |
1717 // assert env_to not empty, it contains the | 1729 // assert env_to not empty, it contains the |
1718 // non-whitelisted folks that want content filtering | 1730 // non-whitelisted folks that want content filtering |
1719 int score = (priv.want_spamassassin) ? priv.assassin->mlfi_eom() : 0; | 1731 const u_char *src = (const u_char *)&priv.ip; |
1720 bool grey = false; | 1732 bool local_source = (src[0] == 127); |
1721 int bulk = 0; | 1733 int score = (priv.want_spamassassin) ? priv.assassin->mlfi_eom() : 0; |
1734 bool grey = false; | |
1735 int bulk = 0; | |
1722 if (priv.want_dccgrey || priv.want_dccbulk) priv.dccifd->mlfi_eom(grey, bulk); | 1736 if (priv.want_dccgrey || priv.want_dccbulk) priv.dccifd->mlfi_eom(grey, bulk); |
1723 | 1737 |
1724 char buf[maxlen]; | 1738 char buf[maxlen]; |
1725 string msg; | 1739 string msg; |
1726 string_set unknowns; | 1740 string_set unknowns; |
1746 for (context_map::iterator i=priv.env_to.begin(); i!=priv.env_to.end(); i++) { | 1760 for (context_map::iterator i=priv.env_to.begin(); i!=priv.env_to.end(); i++) { |
1747 const char *rcpt = (*i).first; | 1761 const char *rcpt = (*i).first; |
1748 CONTEXT *next = (*i).second; | 1762 CONTEXT *next = (*i).second; |
1749 if (con != next) { | 1763 if (con != next) { |
1750 con = next; | 1764 con = next; |
1751 st = con->acceptable_content(*priv.memory, score, bulk, priv.queueid, priv.dkim_signers, priv.fromaddr, &priv, msg); | 1765 st = con->acceptable_content(local_source, *priv.memory, score, bulk, priv.queueid, priv.dkim_signers, priv.fromaddr, &priv, msg); |
1752 } | 1766 } |
1753 if (st == token_black) { | 1767 if (st == token_black) { |
1754 // bad html tags or excessive hosts or | 1768 // bad html tags or excessive hosts or |
1755 // high spam assassin score or dcc bulk threshold exceedeed | 1769 // high spam assassin score or dcc bulk threshold exceedeed |
1756 // or signed by a dkim signer that we don't like | 1770 // or signed by a dkim signer that we don't like |