comparison src/dnsbl.cpp @ 134:f9917ce924a3

all dns lookups fully qualified, my_read() bug fix
author carl
date Wed, 02 Aug 2006 21:06:05 -0700
parents ae9daf43d8eb
children f4746d8a12a3
comparison
equal deleted inserted replaced
133:b8ce1b31237d 134:f9917ce924a3
344 } 344 }
345 345
346 int mlfiPriv::my_read(char *buf, int len) { 346 int mlfiPriv::my_read(char *buf, int len) {
347 if (err) return 0; 347 if (err) return 0;
348 int rs = 0; 348 int rs = 0;
349 while (len > 1) { 349 while (len) {
350 int ws = read(fd, buf, len); 350 int ws = read(fd, buf, len);
351 if (ws > 0) { 351 if (ws > 0) {
352 rs += ws; 352 rs += ws;
353 len -= ws; 353 len -= ws;
354 buf += ws; 354 buf += ws;
502 int dns_interface(mlfiPriv &priv, char *question, bool maybe_ip, ns_map *nameservers) { 502 int dns_interface(mlfiPriv &priv, char *question, bool maybe_ip, ns_map *nameservers) {
503 // this part can be done without locking the resolver mutex. Each 503 // this part can be done without locking the resolver mutex. Each
504 // milter thread is talking over its own socket to a separate resolver 504 // milter thread is talking over its own socket to a separate resolver
505 // process, which does the actual dns resolution. 505 // process, which does the actual dns resolution.
506 if (priv.err) return 0; // cannot ask more questions on this socket. 506 if (priv.err) return 0; // cannot ask more questions on this socket.
507 priv.my_write(question, strlen(question)+1); // write the question including the null terminator 507 if (maybe_ip) {
508 // might be a bare ip address, try this first to avoid dns lookups that may not be needed
509 in_addr ip;
510 if (inet_aton(question, &ip)) {
511 return (int)ip.s_addr;
512 }
513 }
514 int n = strlen(question);
515 if (question[n-1] == '.') {
516 priv.my_write(question, n+1); // write the question including the null terminator
517 }
518 else {
519 priv.my_write(question, n); // write the question
520 priv.my_write(".", 2); // and the fully qualified . terminator and null string terminator
521 }
508 glommer glom; 522 glommer glom;
509 char *buf = (char *)&glom; 523 char *buf = (char *)&glom;
510 priv.my_read(buf, sizeof(glom.length)); 524 priv.my_read(buf, sizeof(glom.length));
511 buf += sizeof(glom.length); 525 buf += sizeof(glom.length);
512 #ifdef RESOLVER_DEBUG 526 #ifdef RESOLVER_DEBUG
584 ret_address = address; 598 ret_address = address;
585 } 599 }
586 } 600 }
587 } 601 }
588 } 602 }
589 if (maybe_ip && !ret_address) {
590 // might be a bare ip address
591 in_addr ip;
592 if (inet_aton(question, &ip)) {
593 ret_address = ip.s_addr;
594 }
595 }
596 pthread_mutex_unlock(&resolve_mutex); 603 pthread_mutex_unlock(&resolve_mutex);
597 return ret_address; 604 return ret_address;
598 #else 605 #else
599 return glom.answer; 606 return glom.answer;
600 #endif 607 #endif
656 return false; 663 return false;
657 } 664 }
658 665
659 666
660 //////////////////////////////////////////////// 667 ////////////////////////////////////////////////
661 // lookup the domain name part of a hostname on two lists 668 // lookup the domain name part of a hostname on the uribl
662 // 669 //
663 // if we find part of the hostname on the uribl, return 670 // if we find part of the hostname on the uribl, return
664 // true and point found to the part of the hostname that we found. 671 // true and point found to the part of the hostname that we found.
665 // otherwise, return false and preserve the value of found. 672 // otherwise, return false and preserve the value of found.
666 // 673 //