Mercurial > dnsbl
comparison src/dnsbl.cpp @ 223:da9e7f1c8160
fix unsigned signed compare, back to mixed -lresolv and libresolv.a with auto requires
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Sun, 28 Dec 2008 09:15:25 -0800 |
parents | b2a7ca398712 |
children | 8e1cbf3d96fc |
comparison
equal
deleted
inserted
replaced
222:b2a7ca398712 | 223:da9e7f1c8160 |
---|---|
530 #ifdef RESOLVER_DEBUG | 530 #ifdef RESOLVER_DEBUG |
531 char text[1000]; | 531 char text[1000]; |
532 snprintf(text, sizeof(text), "process_resolver_requests() has a question %s", question); | 532 snprintf(text, sizeof(text), "process_resolver_requests() has a question %s", question); |
533 my_syslog(text); | 533 my_syslog(text); |
534 #endif | 534 #endif |
535 glom.length = res_search(question, ns_c_in, ns_t_a, glom.answer, sizeof(glom.answer)); | 535 int res_result = res_search(question, ns_c_in, ns_t_a, glom.answer, sizeof(glom.answer)); |
536 if (glom.length < 0) glom.length = 0; // represent all errors as zero length answers | 536 if (res_result < 0) glom.length = 0; // represent all errors as zero length answers |
537 else glom.length = (size_t)res_result; | |
537 #else | 538 #else |
538 glom.length = sizeof(glom.answer); | 539 glom.length = sizeof(glom.answer); |
539 glom.answer = 0; | 540 glom.answer = 0; |
540 struct hostent *host = gethostbyname(question); | 541 struct hostent *host = gethostbyname(question); |
541 if (host && (host->h_addrtype == AF_INET)) { | 542 if (host && (host->h_addrtype == AF_INET)) { |
609 #ifdef RESOLVER_DEBUG | 610 #ifdef RESOLVER_DEBUG |
610 char text[1000]; | 611 char text[1000]; |
611 snprintf(text, sizeof(text), "dns_interface() wrote question %s and has answer length %d", question, glom.length); | 612 snprintf(text, sizeof(text), "dns_interface() wrote question %s and has answer length %d", question, glom.length); |
612 my_syslog(text); | 613 my_syslog(text); |
613 #endif | 614 #endif |
614 if ((glom.length < 0) || (glom.length > sizeof(glom.answer))) { | 615 if ((glom.length == 0) || (glom.length > sizeof(glom.answer))) { |
615 priv.err = true; | 616 priv.err = true; |
616 return 0; // cannot process overlarge answers | 617 return 0; // cannot process overlarge answers |
617 } | 618 } |
618 priv.my_read(buf, glom.length); | 619 priv.my_read(buf, glom.length); |
619 | 620 |
620 #ifdef NS_PACKETSZ | 621 #ifdef NS_PACKETSZ |
621 // now we need to lock the resolver mutex to keep the milter threads from | 622 // now we need to lock the resolver mutex to keep the milter threads from |
622 // stepping on each other while parsing the dns answer. | 623 // stepping on each other while parsing the dns answer. |
623 int ret_address = 0; | 624 int ret_address = 0; |
624 pthread_mutex_lock(&resolve_mutex); | 625 pthread_mutex_lock(&resolve_mutex); |
625 if (glom.length > 0) { | 626 // parse the answer |
626 // parse the answer | 627 ns_msg handle; |
627 ns_msg handle; | 628 ns_rr rr; |
628 ns_rr rr; | 629 if (ns_initparse(glom.answer, glom.length, &handle) == 0) { |
629 if (ns_initparse(glom.answer, glom.length, &handle) == 0) { | 630 // look for ns names |
630 // look for ns names | 631 if (nameservers) { |
631 if (nameservers) { | 632 ns_map &ns = *nameservers; |
632 ns_map &ns = *nameservers; | 633 int rrnum = 0; |
633 int rrnum = 0; | 634 while (ns_parserr(&handle, ns_s_ns, rrnum++, &rr) == 0) { |
634 while (ns_parserr(&handle, ns_s_ns, rrnum++, &rr) == 0) { | 635 if (ns_rr_type(rr) == ns_t_ns) { |
635 if (ns_rr_type(rr) == ns_t_ns) { | 636 char nam[NS_MAXDNAME+1]; |
636 char nam[NS_MAXDNAME+1]; | 637 char *n = nam; |
637 char *n = nam; | 638 const u_char *p = ns_rr_rdata(rr); |
638 const u_char *p = ns_rr_rdata(rr); | 639 while (((n-nam) < NS_MAXDNAME) && ((size_t)(p-glom.answer) < glom.length) && *p) { |
639 while (((n-nam) < NS_MAXDNAME) && ((size_t)(p-glom.answer) < glom.length) && *p) { | 640 size_t s = *(p++); |
640 size_t s = *(p++); | 641 if (s > 191) { |
641 if (s > 191) { | 642 // compression pointer |
642 // compression pointer | 643 s = (s-192)*256 + *(p++); |
643 s = (s-192)*256 + *(p++); | 644 if (s >= glom.length) break; // pointer outside bounds of answer |
644 if (s >= glom.length) break; // pointer outside bounds of answer | 645 p = glom.answer + s; |
645 p = glom.answer + s; | 646 s = *(p++); |
646 s = *(p++); | |
647 } | |
648 if (s > 0) { | |
649 if ((size_t)(n-nam) >= (NS_MAXDNAME-s)) break; // destination would overflow name buffer | |
650 if ((size_t)(p-glom.answer) >= (glom.length-s)) break; // source outside bounds of answer | |
651 memcpy(n, p, s); | |
652 n += s; | |
653 p += s; | |
654 *(n++) = '.'; | |
655 } | |
656 } | 647 } |
657 if (n-nam) n--; // remove trailing . | 648 if (s > 0) { |
658 *n = '\0'; // null terminate it | 649 if ((size_t)(n-nam) >= (NS_MAXDNAME-s)) break; // destination would overflow name buffer |
659 ns.add(nam, question); // ns host to lookup later | 650 if ((size_t)(p-glom.answer) >= (glom.length-s)) break; // source outside bounds of answer |
651 memcpy(n, p, s); | |
652 n += s; | |
653 p += s; | |
654 *(n++) = '.'; | |
655 } | |
656 } | |
657 if (n-nam) n--; // remove trailing . | |
658 *n = '\0'; // null terminate it | |
659 ns.add(nam, question); // ns host to lookup later | |
660 } | |
661 } | |
662 rrnum = 0; | |
663 while (ns_parserr(&handle, ns_s_ar, rrnum++, &rr) == 0) { | |
664 if (ns_rr_type(rr) == ns_t_a) { | |
665 char* nam = (char*)ns_rr_name(rr); | |
666 ns_mapper::iterator i = ns.ns_ip.find(nam); | |
667 if (i != ns.ns_ip.end()) { | |
668 // we want this ip address | |
669 int address; | |
670 memcpy(&address, ns_rr_rdata(rr), sizeof(address)); | |
671 ns.ns_ip[nam] = address; | |
660 } | 672 } |
661 } | 673 } |
662 rrnum = 0; | 674 } |
663 while (ns_parserr(&handle, ns_s_ar, rrnum++, &rr) == 0) { | 675 } |
664 if (ns_rr_type(rr) == ns_t_a) { | 676 int rrnum = 0; |
665 char* nam = (char*)ns_rr_name(rr); | 677 while (ns_parserr(&handle, ns_s_an, rrnum++, &rr) == 0) { |
666 ns_mapper::iterator i = ns.ns_ip.find(nam); | 678 if (ns_rr_type(rr) == ns_t_a) { |
667 if (i != ns.ns_ip.end()) { | 679 int address; |
668 // we want this ip address | 680 memcpy(&address, ns_rr_rdata(rr), sizeof(address)); |
669 int address; | 681 ret_address = address; |
670 memcpy(&address, ns_rr_rdata(rr), sizeof(address)); | |
671 ns.ns_ip[nam] = address; | |
672 } | |
673 } | |
674 } | |
675 } | |
676 int rrnum = 0; | |
677 while (ns_parserr(&handle, ns_s_an, rrnum++, &rr) == 0) { | |
678 if (ns_rr_type(rr) == ns_t_a) { | |
679 int address; | |
680 memcpy(&address, ns_rr_rdata(rr), sizeof(address)); | |
681 ret_address = address; | |
682 } | |
683 } | 682 } |
684 } | 683 } |
685 } | 684 } |
686 pthread_mutex_unlock(&resolve_mutex); | 685 pthread_mutex_unlock(&resolve_mutex); |
687 #ifdef RESOLVER_DEBUG | 686 #ifdef RESOLVER_DEBUG |