Mercurial > dnsbl
comparison src/dnsbl.cpp @ 390:bcef093b1ba6
start parsing spf txt records
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Mon, 06 Mar 2017 17:14:41 -0800 |
parents | aa9795b407e8 |
children | dffedbdc8566 |
comparison
equal
deleted
inserted
replaced
389:aa9795b407e8 | 390:bcef093b1ba6 |
---|---|
335 | 335 |
336 glommer glom; | 336 glommer glom; |
337 char *buf = (char *)&glom; | 337 char *buf = (char *)&glom; |
338 priv.my_read(buf, sizeof(glom.length)); | 338 priv.my_read(buf, sizeof(glom.length)); |
339 buf += sizeof(glom.length); | 339 buf += sizeof(glom.length); |
340 //#ifdef RESOLVER_DEBUG | 340 #ifdef RESOLVER_DEBUG |
341 char text[1000]; | 341 char text[1000]; |
342 snprintf(text, sizeof(text), "dns_interface() wrote question %s and has answer length %d", question, glom.length); | 342 snprintf(text, sizeof(text), "dns_interface() wrote question %s and has answer length %d", question, glom.length); |
343 my_syslog(text); | 343 my_syslog(text); |
344 //#endif | 344 #endif |
345 if (glom.length == 0) return 0; | 345 if (glom.length == 0) return 0; |
346 if (glom.length > sizeof(glom.answer)) { | 346 if (glom.length > sizeof(glom.answer)) { |
347 priv.err = true; | 347 priv.err = true; |
348 return 0; // cannot process overlarge answers | 348 return 0; // cannot process overlarge answers |
349 } | 349 } |
420 while (ns_parserr(&handle, ns_s_an, rrnum++, &rr) == 0) { | 420 while (ns_parserr(&handle, ns_s_an, rrnum++, &rr) == 0) { |
421 if (ns_rr_type(rr) == qtype) { | 421 if (ns_rr_type(rr) == qtype) { |
422 size_t offset = 0; | 422 size_t offset = 0; |
423 size_t rdlen = ns_rr_rdlen(rr); | 423 size_t rdlen = ns_rr_rdlen(rr); |
424 const unsigned char *rdata = ns_rr_rdata(rr); | 424 const unsigned char *rdata = ns_rr_rdata(rr); |
425 //#ifdef RESOLVER_DEBUG | 425 #ifdef RESOLVER_DEBUG |
426 char text[1000]; | 426 char text[1000]; |
427 snprintf(text, sizeof(text), "found txt record rdlen = %d", rdlen); | 427 snprintf(text, sizeof(text), "found txt record rdlen = %d", rdlen); |
428 my_syslog(text); | 428 my_syslog(text); |
429 //#endif | 429 #endif |
430 while ((offset < txt_size) && rdlen) { | 430 while ((offset < txt_size) && rdlen) { |
431 size_t slen = size_t(*(rdata++)); | 431 size_t slen = size_t(*(rdata++)); |
432 rdlen--; | 432 rdlen--; |
433 size_t m = min(slen, rdlen); | 433 size_t m = min(slen, rdlen); |
434 m = min(m, txt_size-offset); | 434 m = min(m, txt_size-offset); |
436 offset += m; | 436 offset += m; |
437 rdata += m; | 437 rdata += m; |
438 rdlen -= m; | 438 rdlen -= m; |
439 } | 439 } |
440 txt_answer[offset] = '\0'; // trailing null | 440 txt_answer[offset] = '\0'; // trailing null |
441 //#ifdef RESOLVER_DEBUG | 441 #ifdef RESOLVER_DEBUG |
442 snprintf(text, sizeof(text), "found txt record %s", txt_answer); | 442 snprintf(text, sizeof(text), "found txt record %s", txt_answer); |
443 my_syslog(text); | 443 my_syslog(text); |
444 //#endif | 444 #endif |
445 if (strncasecmp(txt_answer, "v=spf1 ", 7) == 0) break; | 445 if (strncasecmp(txt_answer, "v=spf1 ", 7) == 0) break; |
446 } | 446 } |
447 } | 447 } |
448 //if (strncasecmp(txt_answer, "v=spf1 ", 7) != 0) { | 448 if (strncasecmp(txt_answer, "v=spf1 ", 7) != 0) { |
449 // txt_answer[0] = '\0'; // return null string if there are no spf1 txt answers | 449 txt_answer[0] = '\0'; // return null string if there are no spf1 txt answers |
450 //} | 450 } |
451 } | 451 } |
452 } | 452 } |
453 pthread_mutex_unlock(&resolve_mutex); | 453 pthread_mutex_unlock(&resolve_mutex); |
454 #ifdef RESOLVER_DEBUG | 454 #ifdef RESOLVER_DEBUG |
455 snprintf(text, sizeof(text), "dns_interface() found ip %d", ret_address); | 455 snprintf(text, sizeof(text), "dns_interface() found ip %d", ret_address); |
887 | 887 |
888 // find the answer | 888 // find the answer |
889 #ifdef NS_PACKETSZ | 889 #ifdef NS_PACKETSZ |
890 int qt = int8_t(question[0]); | 890 int qt = int8_t(question[0]); |
891 int res_result = res_query(question+1, ns_c_in, qt, glom.answer, sizeof(glom.answer)); | 891 int res_result = res_query(question+1, ns_c_in, qt, glom.answer, sizeof(glom.answer)); |
892 //#ifdef RESOLVER_DEBUG | 892 #ifdef RESOLVER_DEBUG |
893 char text[1000]; | 893 char text[1000]; |
894 snprintf(text, sizeof(text), "process_resolver_requests() has a question %s qtype %d buf len %d result %d", | 894 snprintf(text, sizeof(text), "process_resolver_requests() has a question %s qtype %d buf len %d result %d", |
895 question+1, qt, sizeof(glom.answer), res_result); | 895 question+1, qt, sizeof(glom.answer), res_result); |
896 my_syslog(text); | 896 my_syslog(text); |
897 //#endif | 897 #endif |
898 if (res_result < 0) glom.length = 0; // represent all errors as zero length answers | 898 if (res_result < 0) glom.length = 0; // represent all errors as zero length answers |
899 else glom.length = (size_t)res_result; | 899 else glom.length = (size_t)res_result; |
900 #else | 900 #else |
901 glom.length = sizeof(glom.answer); | 901 glom.length = sizeof(glom.answer); |
902 glom.answer = 0; | 902 glom.answer = 0; |