Mercurial > dnsbl
comparison src/context.cpp @ 467:f5b394bec28c
allow checking names without A records on uribl lists; improve extraction of fake TLDs from our RPZ zone
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 16 Dec 2020 10:25:37 -0800 |
parents | 79e944269c0b |
children | 5209e92b4885 |
comparison
equal
deleted
inserted
replaced
466:8ad675a5d448 | 467:f5b394bec28c |
---|---|
799 | 799 |
800 | 800 |
801 const char *CONTEXT::get_full_name(char *buffer, int size) { | 801 const char *CONTEXT::get_full_name(char *buffer, int size) { |
802 if (!parent) return name; | 802 if (!parent) return name; |
803 char buf[maxlen]; | 803 char buf[maxlen]; |
804 snprintf(buffer, size, "%s.%s", parent->get_full_name(buf, maxlen), name); | 804 snprintf(buffer, size, "%s.%s", parent->get_full_name(buf, maxlen-strlen(name)-2), name); |
805 return buffer; | 805 return buffer; |
806 } | 806 } |
807 | 807 |
808 | 808 |
809 bool CONTEXT::set_white(const char *regx) | 809 bool CONTEXT::set_white(const char *regx) |
1103 } | 1103 } |
1104 | 1104 |
1105 | 1105 |
1106 void CONTEXT::log(const char *queueid, const char *msg, const char *v) { | 1106 void CONTEXT::log(const char *queueid, const char *msg, const char *v) { |
1107 if (debug_syslog > 1) { | 1107 if (debug_syslog > 1) { |
1108 char buf[maxlen]; | 1108 char buf[maxdnslength+100]; |
1109 snprintf(buf, maxlen, msg, v); | 1109 snprintf(buf, sizeof(buf), msg, v); |
1110 my_syslog(queueid, buf); | 1110 my_syslog(queueid, buf); |
1111 } | 1111 } |
1112 } | 1112 } |
1113 | 1113 |
1114 | 1114 |
1217 if (p >= e) break; | 1217 if (p >= e) break; |
1218 char *b = strchr(p, ' '); | 1218 char *b = strchr(p, ' '); |
1219 if (b) *b = '\0'; | 1219 if (b) *b = '\0'; |
1220 if ((*p != '-') && (*p != '~') && (*p != '?')) { | 1220 if ((*p != '-') && (*p != '~') && (*p != '?')) { |
1221 if (*p == '+') p++; | 1221 if (*p == '+') p++; |
1222 if (strncmp(p, "ip4:", 4) == 0) { | 1222 if (strncasecmp(p, "ip4:", 4) == 0) { |
1223 p += 4; | 1223 p += 4; |
1224 char *s = strchr(p, '/'); | 1224 char *s = strchr(p, '/'); |
1225 if (s) *s = '\0'; | 1225 if (s) *s = '\0'; |
1226 in_addr ipx; | 1226 in_addr ipx; |
1227 if (inet_aton(p, &ipx)) { | 1227 if (inet_aton(p, &ipx)) { |
1241 return true; | 1241 return true; |
1242 } | 1242 } |
1243 } | 1243 } |
1244 } | 1244 } |
1245 } | 1245 } |
1246 else if (strncmp(p, "all", 3) == 0) { | 1246 else if (strncasecmp(p, "all", 3) == 0) { |
1247 // ignore it before looking for (a or a:) below | 1247 // ignore it before looking for (a or a:) below |
1248 } | 1248 } |
1249 else if (strncmp(p, "exists:", 7) == 0) { | 1249 else if (strncasecmp(p, "exists:", 7) == 0) { |
1250 p += 7; | 1250 p += 7; |
1251 char buf[maxdnslength]; | 1251 char buf[maxdnslength]; |
1252 dns_interface(*priv, p, ns_t_a, false, NULL, buf, maxdnslength); | 1252 dns_interface(*priv, p, ns_t_a, false, NULL, buf, maxdnslength); |
1253 uint32_t *a = (uint32_t *)buf; | 1253 uint32_t *a = (uint32_t *)buf; |
1254 if (a[0]) { | 1254 if (a[0]) { |
1255 log(priv->queueid, "match exists:%s", p); | 1255 log(priv->queueid, "match exists:%s", p); |
1256 return true; | 1256 return true; |
1257 } | 1257 } |
1258 } | 1258 } |
1259 else if (strncmp(p, "mx", 2) == 0) { | 1259 else if (strncasecmp(p, "mx", 2) == 0) { |
1260 const char *name = (p[2] == ':') ? p+3 : from; | 1260 const char *name = (p[2] == ':') ? p+3 : from; |
1261 char buf[maxdnslength]; | 1261 char buf[maxdnslength]; |
1262 dns_interface(*priv, name, ns_t_mx, false, NULL, buf, maxdnslength); | 1262 dns_interface(*priv, name, ns_t_mx, false, NULL, buf, maxdnslength); |
1263 char *b = buf; | 1263 char *b = buf; |
1264 while (*b) { | 1264 while (*b) { |
1293 log(priv->queueid, "match a:%s", name); | 1293 log(priv->queueid, "match a:%s", name); |
1294 return true; | 1294 return true; |
1295 } | 1295 } |
1296 } | 1296 } |
1297 } | 1297 } |
1298 else if (priv->client_dns_name && (!priv->client_dns_forged) && (strncmp(p, "ptr", 3) == 0)) { | 1298 else if (priv->client_dns_name && (!priv->client_dns_forged) && (strncasecmp(p, "ptr", 3) == 0)) { |
1299 const char *name = (p[3] == ':') ? p+4 : from; | 1299 const char *name = (p[3] == ':') ? p+4 : from; |
1300 size_t n = strlen(name); | 1300 size_t n = strlen(name); |
1301 size_t d = strlen(priv->client_dns_name); | 1301 size_t d = strlen(priv->client_dns_name); |
1302 if (d >= n) { | 1302 if (d >= n) { |
1303 if ((strncmp(priv->client_dns_name+d-n, name, n) == 0) && // trailing part matches | 1303 if ((strncasecmp(priv->client_dns_name+d-n, name, n) == 0) && // trailing part matches |
1304 ((d == n) || (priv->client_dns_name[d-n-1] == '.'))) { // same length, or dot just before match | 1304 ((d == n) || (priv->client_dns_name[d-n-1] == '.'))) { // same length, or dot just before match |
1305 log(priv->queueid, "match ptr:%s", priv->client_dns_name); | 1305 log(priv->queueid, "match ptr:%s", priv->client_dns_name); |
1306 return true; | 1306 return true; |
1307 } | 1307 } |
1308 } | 1308 } |
1309 } | 1309 } |
1310 else if ((level < 5) && (strncmp(p, "redirect=", 9) == 0)) { | 1310 else if ((level < 5) && (strncasecmp(p, "redirect=", 9) == 0)) { |
1311 p += 9; | 1311 p += 9; |
1312 if (resolve_one_spf(p, ip, priv, NULL, level+1)) return true; | 1312 if (resolve_one_spf(p, ip, priv, NULL, level+1)) return true; |
1313 } | 1313 } |
1314 else if ((level < 5) && (strncmp(p, "include:", 8) == 0)) { | 1314 else if ((level < 5) && (strncasecmp(p, "include:", 8) == 0)) { |
1315 p += 8; | 1315 p += 8; |
1316 if (resolve_one_spf(p, ip, priv, NULL, level+1)) return true; | 1316 if (resolve_one_spf(p, ip, priv, NULL, level+1)) return true; |
1317 } | 1317 } |
1318 } | 1318 } |
1319 p = (b) ? b+1 : e; | 1319 p = (b) ? b+1 : e; |