comparison src/dnsbl.cpp @ 335:354b15b8b263

header from may appear very early in unsigned messages
author Carl Byington <carl@five-ten-sg.com>
date Tue, 20 Dec 2016 16:54:32 -0800
parents a4f2fda72422
children d68fda9be1c1
comparison
equal deleted inserted replaced
334:a4f2fda72422 335:354b15b8b263
1461 1461
1462 sfsistat mlfi_header(SMFICTX* ctx, char* headerf, char* headerv) 1462 sfsistat mlfi_header(SMFICTX* ctx, char* headerf, char* headerv)
1463 { 1463 {
1464 mlfiPriv &priv = *MLFIPRIV; 1464 mlfiPriv &priv = *MLFIPRIV;
1465 priv.header_count++; 1465 priv.header_count++;
1466 char msg[maxlen];
1467 if ((priv.header_count < 4) || (strcasecmp(headerf, "from") == 0)) {
1468 snprintf(msg, sizeof(msg), "header %s: %s", headerf, headerv);
1469 for (size_t i=0; i<strlen(msg); i++) {
1470 if (msg[i] < 0x20) msg[i] = ' ';
1471 }
1472 my_syslog(&priv, msg);
1473 }
1474
1475 if (priv.dkim_ok) { 1466 if (priv.dkim_ok) {
1476 if ((priv.header_count == 1) && (strcasecmp(headerf, "DKIM-Filter") != 0)) priv.dkim_ok = false; 1467 if ((priv.header_count == 1) && (strcasecmp(headerf, "DKIM-Filter") != 0)) priv.dkim_ok = false;
1477 if (priv.header_count == 2) { 1468 if (priv.header_count == 2) {
1478 if (strcasecmp(headerf, "Authentication-Results") != 0) priv.dkim_ok = false; 1469 if (strcasecmp(headerf, "Authentication-Results") != 0) priv.dkim_ok = false;
1479 if (strncasecmp(headerv, token_myhostname, strlen(token_myhostname)) != 0) priv.dkim_ok = false; 1470 if (strncasecmp(headerv, token_myhostname, strlen(token_myhostname)) != 0) priv.dkim_ok = false;
1480 if (priv.dkim_ok) { 1471 if (priv.dkim_ok) {
1481 const int nmatch = 2; 1472 const int nmatch = 2;
1482 regmatch_t match[nmatch]; 1473 regmatch_t match[nmatch];
1483 char *msgo = msg; 1474 char *msgo = headerv;
1484 while (true) { 1475 while (true) {
1485 if (0 == regexec(&dkim_pattern, msgo, nmatch, match, 0)) { 1476 if (0 == regexec(&dkim_pattern, msgo, nmatch, match, 0)) {
1486 int s1 = match[1].rm_so; // domain 1477 int s1 = match[1].rm_so; // domain
1487 int e1 = match[1].rm_eo; 1478 int e1 = match[1].rm_eo;
1488 if (s1 != -1) { 1479 if (s1 != -1) {
1499 } 1490 }
1500 } 1491 }
1501 } 1492 }
1502 1493
1503 // only look at the first from header 1494 // only look at the first from header
1504 if ((priv.header_count > 2) && (!priv.fromaddr) && (strcasecmp(headerf, "from") == 0)) { 1495 if ((!priv.fromaddr) && (strcasecmp(headerf, "from") == 0)) {
1505 const int nmatch = 2; 1496 const int nmatch = 2;
1506 regmatch_t match[nmatch]; 1497 regmatch_t match[nmatch];
1507 int err = regexec(&from_pattern, msg, nmatch, match, 0); 1498 int err = regexec(&from_pattern, headerv, nmatch, match, 0);
1508 if (err == 0) { 1499 if (err == 0) {
1509 int s1 = match[1].rm_so; // domain 1500 int s1 = match[1].rm_so; // domain
1510 int e1 = match[1].rm_eo; 1501 int e1 = match[1].rm_eo;
1511 if (s1 != -1) { 1502 if (s1 != -1) {
1512 msg[e1] = '\0'; 1503 char save = headerv[e1];
1513 priv.fromaddr = strdup(msg+s1); 1504 headerv[e1] = '\0';
1505 priv.fromaddr = strdup(headerv+s1);
1506 headerv[e1] = save;
1514 } 1507 }
1515 } 1508 }
1516 } 1509 }
1517 1510
1518 // headers that avoid autowhitelisting 1511 // headers that avoid autowhitelisting