comparison src/dnsbl.cpp @ 337:d68fda9be1c1

need to convert nl and tab to spaces in header values before regexec
author Carl Byington <carl@five-ten-sg.com>
date Tue, 20 Dec 2016 17:13:48 -0800
parents 354b15b8b263
children f375a67ee516
comparison
equal deleted inserted replaced
336:c5b8971534eb 337:d68fda9be1c1
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 *value = headerv;
1467 if ((priv.header_count < 4) || (strcasecmp(headerf, "from") == 0)) {
1468 for (size_t i=0; i<strlen(value); i++) {
1469 if (value[i] < 0x20) value[i] = ' ';
1470 }
1471 }
1472
1466 if (priv.dkim_ok) { 1473 if (priv.dkim_ok) {
1467 if ((priv.header_count == 1) && (strcasecmp(headerf, "DKIM-Filter") != 0)) priv.dkim_ok = false; 1474 if ((priv.header_count == 1) && (strcasecmp(headerf, "DKIM-Filter") != 0)) priv.dkim_ok = false;
1468 if (priv.header_count == 2) { 1475 if (priv.header_count == 2) {
1469 if (strcasecmp(headerf, "Authentication-Results") != 0) priv.dkim_ok = false; 1476 if (strcasecmp(headerf, "Authentication-Results") != 0) priv.dkim_ok = false;
1470 if (strncasecmp(headerv, token_myhostname, strlen(token_myhostname)) != 0) priv.dkim_ok = false; 1477 if (strncasecmp(headerv, token_myhostname, strlen(token_myhostname)) != 0) priv.dkim_ok = false;
1471 if (priv.dkim_ok) { 1478 if (priv.dkim_ok) {
1472 const int nmatch = 2; 1479 const int nmatch = 2;
1473 regmatch_t match[nmatch]; 1480 regmatch_t match[nmatch];
1474 char *msgo = headerv;
1475 while (true) { 1481 while (true) {
1476 if (0 == regexec(&dkim_pattern, msgo, nmatch, match, 0)) { 1482 if (0 == regexec(&dkim_pattern, value, nmatch, match, 0)) {
1477 int s1 = match[1].rm_so; // domain 1483 int s1 = match[1].rm_so; // domain
1478 int e1 = match[1].rm_eo; 1484 int e1 = match[1].rm_eo;
1479 if (s1 != -1) { 1485 if (s1 != -1) {
1480 char save = msgo[e1]; 1486 char save = value[e1];
1481 msgo[e1] = '\0'; 1487 value[e1] = '\0';
1482 priv.dkim_signers.insert(strdup(msgo+s1)); 1488 priv.dkim_signers.insert(strdup(value+s1));
1483 msgo[e1] = save; 1489 value[e1] = save;
1484 msgo += e1 + 1; 1490 value += e1 + 1;
1485 } 1491 }
1486 else break; 1492 else break;
1487 } 1493 }
1488 else break; 1494 else break;
1489 } 1495 }
1493 1499
1494 // only look at the first from header 1500 // only look at the first from header
1495 if ((!priv.fromaddr) && (strcasecmp(headerf, "from") == 0)) { 1501 if ((!priv.fromaddr) && (strcasecmp(headerf, "from") == 0)) {
1496 const int nmatch = 2; 1502 const int nmatch = 2;
1497 regmatch_t match[nmatch]; 1503 regmatch_t match[nmatch];
1498 int err = regexec(&from_pattern, headerv, nmatch, match, 0); 1504 int err = regexec(&from_pattern, value, nmatch, match, 0);
1499 if (err == 0) { 1505 if (err == 0) {
1500 int s1 = match[1].rm_so; // domain 1506 int s1 = match[1].rm_so; // domain
1501 int e1 = match[1].rm_eo; 1507 int e1 = match[1].rm_eo;
1502 if (s1 != -1) { 1508 if (s1 != -1) {
1503 char save = headerv[e1]; 1509 value[e1] = '\0';
1504 headerv[e1] = '\0'; 1510 priv.fromaddr = strdup(value+s1);
1505 priv.fromaddr = strdup(headerv+s1);
1506 headerv[e1] = save;
1507 } 1511 }
1508 } 1512 }
1509 } 1513 }
1510 1514
1511 // headers that avoid autowhitelisting 1515 // headers that avoid autowhitelisting