# HG changeset patch # User carl # Date 1105215990 28800 # Node ID 7f44a4974bf6d96f4995b53fdaaa7931417610ff # Parent 390ed250c5d289a80d2c6ff0727e70520f1d5bdd Use resolver processes even if we don't have the interfaces, and need to use gethostbyname. diff -r 390ed250c5d2 -r 7f44a4974bf6 ChangeLog --- a/ChangeLog Thu Jan 06 11:35:38 2005 -0800 +++ b/ChangeLog Sat Jan 08 12:26:30 2005 -0800 @@ -1,5 +1,9 @@ $Id$ +4.2 2005-01-08 + Use the separate resolver processes even if we don't have the + resolver interfaces and need gethostbyname. + 4.1 2005-01-06 Use a local unix domain socket for the resolver process communication, rather than a tcp/ip socket. diff -r 390ed250c5d2 -r 7f44a4974bf6 dnsbl.spec.in --- a/dnsbl.spec.in Thu Jan 06 11:35:38 2005 -0800 +++ b/dnsbl.spec.in Sat Jan 08 12:26:30 2005 -0800 @@ -1,6 +1,6 @@ Summary: DNSBL Sendmail Milter Name: dnsbl -Version: 4.1 +Version: 4.2 Release: 2 Copyright: GPL Group: System Environment/Daemons diff -r 390ed250c5d2 -r 7f44a4974bf6 package.bash --- a/package.bash Thu Jan 06 11:35:38 2005 -0800 +++ b/package.bash Sat Jan 08 12:26:30 2005 -0800 @@ -1,6 +1,6 @@ #!/bin/bash -VER=dnsbl-4.1 +VER=dnsbl-4.2 mkdir $VER target1=/home/httpd/html/510sg/util/dnsbl.tar.gz target2=/home/httpd/html/510sg/dnsbl.conf diff -r 390ed250c5d2 -r 7f44a4974bf6 sendmail.st Binary file sendmail.st has changed diff -r 390ed250c5d2 -r 7f44a4974bf6 src/dnsbl.cpp --- a/src/dnsbl.cpp Thu Jan 06 11:35:38 2005 -0800 +++ b/src/dnsbl.cpp Sat Jan 08 12:26:30 2005 -0800 @@ -206,14 +206,17 @@ static time_t ERROR_SOCKET_TIME = 60; // number of seconds between attempts to open the spam filter socket static time_t last_error_time; -#ifdef NS_PACKETSZ + // packed structure to allow a single socket write to dump the // length and the following answer. The packing attribute is gcc specific. struct glommer { int length; - u_char answer[NS_PACKETSZ]; + #ifdef NS_PACKETSZ + u_char answer[NS_PACKETSZ]; // with a resolver, we return resolver answers + #else + int answer; // without a resolver, we return a single ip4 address, 0 == no answer + #endif } __attribute__ ((packed)); -#endif struct mlfiPriv; @@ -609,7 +612,6 @@ // read a resolver request from the socket, process it, and // write the result back to the socket. -#ifdef NS_PACKETSZ static void process_resolver_requests(int socket); static void process_resolver_requests(int socket) { #ifdef NS_MAXDNAME @@ -642,11 +644,20 @@ } // find the answer +#ifdef NS_PACKETSZ //char text[1000]; //snprintf(text, sizeof(text), "!!child worker process has a question %s", question); //my_syslog(text); glom.length = res_search(question, ns_c_in, ns_t_a, glom.answer, sizeof(glom.answer)); if (glom.length < 0) glom.length = 0; // represent all errors as zero length answers +#else + glom.length = sizeof(glom.answer); + glom.answer = 0; + struct hostent *host = gethostbyname(question); + if (host && (host->h_addrtype == AF_INET)) { + memcpy(&glom.answer, host->h_addr, sizeof(glom.answer)); + } +#endif // write the answer char *buf = (char *)&glom; @@ -669,7 +680,6 @@ } } } -#endif //////////////////////////////////////////////// @@ -680,9 +690,6 @@ // static int dns_interface(mlfiPriv &priv, char *question, bool maybe_ip, ns_map *nameservers); static int dns_interface(mlfiPriv &priv, char *question, bool maybe_ip, ns_map *nameservers) { - int ret_address = 0; -#ifdef NS_PACKETSZ - // this part can be done without locking the resolver mutex. Each // milter thread is talking over its own socket to a separate resolver // process, which does the actual dns resolution. @@ -701,8 +708,10 @@ } priv.my_read(buf, glom.length); +#ifdef NS_PACKETSZ // now we need to lock the resolver mutex to keep the milter threads from // stepping on each other while parsing the dns answer. + int ret_address = 0; pthread_mutex_lock(&resolve_mutex); if (glom.length > 0) { // parse the answer @@ -776,14 +785,7 @@ return ret_address; #else - // systems without the resolver interface - pthread_mutex_lock(&resolve_mutex); - struct hostent *host = gethostbyname(question); - if (host && (host->h_addrtype == AF_INET)) { - memcpy(&ret_address, host->h_addr, sizeof(ret_address)); - } - pthread_mutex_unlock(&resolve_mutex); - return ret_address; + return glom.answer; #endif } @@ -1759,7 +1761,6 @@ } } -#ifdef NS_PACKETSZ // fork off the resolver listener process pid_t child = fork(); if (child < 0) { @@ -1817,9 +1818,9 @@ // this is the worker process // child does not need the listening socket close(resolver_socket); - my_syslog("child forked a worker process"); + //my_syslog("child forked a worker process"); process_resolver_requests(s); - my_syslog("child terminated a worker process"); + //my_syslog("child terminated a worker process"); exit(0); } else { @@ -1834,7 +1835,6 @@ else { sleep(2); // allow child to get started } -#endif // load the initial config config = new_conf(); diff -r 390ed250c5d2 -r 7f44a4974bf6 xml/dnsbl.in --- a/xml/dnsbl.in Thu Jan 06 11:35:38 2005 -0800 +++ b/xml/dnsbl.in Sat Jan 08 12:26:30 2005 -0800 @@ -2,7 +2,7 @@ -DNSBL Sendmail milter - Version 4.1 +DNSBL Sendmail milter - Version 4.2
Introduction