Mercurial > dnsbl
comparison src/dnsbl.cpp @ 235:e6c66640f6f9
Add SRS decoding to envelope addresses
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 09 Jun 2009 08:36:34 -0700 |
parents | 5c3e9bf45bb5 |
children | c0d2e99c0a1d |
comparison
equal
deleted
inserted
replaced
234:1c45d50cbbc6 | 235:e6c66640f6f9 |
---|---|
1 /* | 1 /* |
2 | 2 |
3 Copyright (c) 2007 Carl Byington - 510 Software Group, released under | 3 Copyright (c) 2009 Carl Byington - 510 Software Group, released under |
4 the GPL version 3 or any later version at your choice available at | 4 the GPL version 3 or any later version at your choice available at |
5 http://www.gnu.org/licenses/gpl-3.0.txt | 5 http://www.gnu.org/licenses/gpl-3.0.txt |
6 | 6 |
7 Based on a sample milter Copyright (c) 2000-2003 Sendmail, Inc. and its | 7 Based on a sample milter Copyright (c) 2000-2003 Sendmail, Inc. and its |
8 suppliers. Inspired by the DCC by Rhyolite Software | 8 suppliers. Inspired by the DCC by Rhyolite Software |
94 bool use_syslog = true; // false to printf | 94 bool use_syslog = true; // false to printf |
95 bool loader_run = true; // used to stop the config loader thread | 95 bool loader_run = true; // used to stop the config loader thread |
96 CONFIG *config = NULL; // protected by the config_mutex | 96 CONFIG *config = NULL; // protected by the config_mutex |
97 int generation = 0; // protected by the config_mutex | 97 int generation = 0; // protected by the config_mutex |
98 const int maxlen = 1000; // used for snprintf buffers | 98 const int maxlen = 1000; // used for snprintf buffers |
99 regex_t srs_pattern; // used to detect srs coding in mail addresses | |
99 | 100 |
100 pthread_mutex_t config_mutex; | 101 pthread_mutex_t config_mutex; |
101 pthread_mutex_t syslog_mutex; | 102 pthread_mutex_t syslog_mutex; |
102 pthread_mutex_t resolve_mutex; | 103 pthread_mutex_t resolve_mutex; |
103 pthread_mutex_t fd_pool_mutex; | 104 pthread_mutex_t fd_pool_mutex; |
967 // enclosed in <>. I think older versions of sendmail supplied the <> | 968 // enclosed in <>. I think older versions of sendmail supplied the <> |
968 // wrapper if the mail client did not, but the current version does not do | 969 // wrapper if the mail client did not, but the current version does not do |
969 // that. So the <> wrapper is now optional. It may have mixed case, just | 970 // that. So the <> wrapper is now optional. It may have mixed case, just |
970 // as the mail client sent it. We dup the string and convert the duplicate | 971 // as the mail client sent it. We dup the string and convert the duplicate |
971 // to lower case. Some clients enclose the entire address in single quotes, | 972 // to lower case. Some clients enclose the entire address in single quotes, |
972 // so we strip those as well. | 973 // so we strip those as well. We also remove the SRS coding. |
973 // | 974 // |
974 const char *to_lower_string(const char *email); | 975 const char *to_lower_string(const char *email); |
975 const char *to_lower_string(const char *email) { | 976 const char *to_lower_string(const char *email) { |
976 int n = strlen(email); | 977 int n = strlen(email); |
977 if (email[0] == '<') { | 978 if (email[0] == '<') { |
985 email++; | 986 email++; |
986 } | 987 } |
987 char *key = strdup(email); | 988 char *key = strdup(email); |
988 key[n] = '\0'; | 989 key[n] = '\0'; |
989 for (int i=0; i<n; i++) key[i] = tolower(key[i]); | 990 for (int i=0; i<n; i++) key[i] = tolower(key[i]); |
991 if ((n > 12) && (strncmp(key, "srs", 3) == 0)) { | |
992 // might have srs coding to be removed | |
993 const int nmatch = 6; | |
994 regmatch_t match[nmatch]; | |
995 if (0 == regexec(&srs_pattern, key, nmatch, match, 0)) { | |
996 int s4 = match[4].rm_so; // domain | |
997 int e4 = match[4].rm_eo; | |
998 int s5 = match[5].rm_so; // user | |
999 int e5 = match[5].rm_eo; | |
1000 if ((s4 != -1) && (s5 != -1)) { | |
1001 char *newkey = strdup(key); // large enough | |
1002 key[e4] = '\0'; | |
1003 key[e5] = '\0'; | |
1004 strcpy(newkey, key+s5); // user | |
1005 strcat(newkey, "@"); // @ | |
1006 strcat(newkey, key+s4); // domain | |
1007 free(key); | |
1008 key = newkey; | |
1009 } | |
1010 } | |
1011 } | |
990 return key; | 1012 return key; |
991 } | 1013 } |
992 | 1014 |
993 | 1015 |
994 //////////////////////////////////////////////// | 1016 //////////////////////////////////////////////// |
1488 bool setreso = false; | 1510 bool setreso = false; |
1489 const char *email = NULL; | 1511 const char *email = NULL; |
1490 int c; | 1512 int c; |
1491 const char *args = "b:r:p:t:e:d:chs"; | 1513 const char *args = "b:r:p:t:e:d:chs"; |
1492 extern char *optarg; | 1514 extern char *optarg; |
1515 | |
1516 // setup srs coding detection | |
1517 if (regcomp(&srs_pattern, "^srs(0|1)=([^=]*)=([^=]*)=([^=]*)=([^@]*)@", REG_ICASE | REG_EXTENDED)) { | |
1518 printf("cannot compile regex pattern to find srs coding in mail addresses\n"); | |
1519 exit(3); | |
1520 } | |
1493 | 1521 |
1494 // Process command line options | 1522 // Process command line options |
1495 while ((c = getopt(argc, argv, args)) != -1) { | 1523 while ((c = getopt(argc, argv, args)) != -1) { |
1496 switch (c) { | 1524 switch (c) { |
1497 case 'b': | 1525 case 'b': |