Mercurial > dnsbl
diff src/dnsbl.cpp @ 61:7f44a4974bf6 stable-4-2
Use resolver processes even if we don't have the interfaces, and need to use gethostbyname.
author | carl |
---|---|
date | Sat, 08 Jan 2005 12:26:30 -0800 |
parents | 390ed250c5d2 |
children | 7ad7d8b100bf |
line wrap: on
line diff
--- 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();