Added some CtdlThreadCheckStop() calls to exit rbl checks and stop the
authorDave West <davew@uncensored.citadel.org>
Sat, 5 Apr 2008 21:40:46 +0000 (21:40 +0000)
committerDave West <davew@uncensored.citadel.org>
Sat, 5 Apr 2008 21:40:46 +0000 (21:40 +0000)
SMTP negotiation if we are shutting down.
Also added a bit of code to log the time it takes to do an RBL check. If
it takes a long time maybe we can cache the results in a hash with
something like a 30 second life span.

citadel/locate_host.c
citadel/modules/smtp/serv_smtp.c

index f4d45f47fa4147798ff995d9f8e15f4d6558875f..ed566a42bc08d0479991db7a60d08d6fb04b776a 100644 (file)
@@ -24,6 +24,7 @@
 #include "sysdep_decls.h"
 #include "config.h"
 #include "domain.h"
+#include "ctdl_module.h"
 
 #ifdef HAVE_RESOLV_H
 #include <arpa/nameser.h>
@@ -140,6 +141,12 @@ int rblcheck_backend(char *domain, char *txtbuf, int txtbufsize) {
        /* Make our DNS query. */
        //res_init();
        answer = fixedans;
+       if (CtdlThreadCheckStop())
+       {
+               if (txtbuf != NULL)
+                       snprintf(txtbuf, txtbufsize, "System shutting down");
+               return (1);
+       }
        len = res_query( domain, C_IN, T_A, answer, PACKETSZ );
 
        /* Was there a problem? If so, the domain doesn't exist. */
@@ -164,6 +171,13 @@ int rblcheck_backend(char *domain, char *txtbuf, int txtbufsize) {
                        return(1);
                }
        }
+       if (CtdlThreadCheckStop())
+       {
+               if (txtbuf != NULL)
+                       snprintf(txtbuf, txtbufsize, "System shutting down");
+               if (need_to_free_answer) free(answer);
+               return (1);
+       }
 
        result = ( char * )malloc( RESULT_SIZE );
        result[ 0 ] = '\0';
@@ -174,6 +188,14 @@ int rblcheck_backend(char *domain, char *txtbuf, int txtbufsize) {
           nameserver we're using. */
        res_init();
        len = res_query( domain, C_IN, T_TXT, answer, PACKETSZ );
+       if (CtdlThreadCheckStop())
+       {
+               if (txtbuf != NULL)
+                       snprintf(txtbuf, txtbufsize, "System shutting down");
+               if (need_to_free_answer) free(answer);
+               free(result);
+               return (1);
+       }
 
        /* Just in case there's no TXT record... */
        if( len == -1 )
@@ -294,12 +316,22 @@ int rbl_check_addr(struct in_addr *addr, char *message_to_spammer)
 int rbl_check(char *message_to_spammer) {
        struct sockaddr_in sin;
        int len;        /* should be socklen_t but doesn't work on Macintosh */
+       struct timeval tv1, tv2;
+       suseconds_t total_time = 0;
 
+       gettimeofday(&tv1, NULL);
        len = 0;
        memset (&sin, 0, sizeof (struct sockaddr_in));
        if (!getpeername(CC->client_socket, (struct sockaddr *) &sin, (socklen_t *)&len)) {
                return(rbl_check_addr(&sin.sin_addr, message_to_spammer));
        }
+       
+       gettimeofday(&tv2, NULL);
+       total_time = (tv2.tv_usec + (tv2.tv_sec * 1000000)) - (tv1.tv_usec + (tv1.tv_sec * 1000000));
+       CtdlLogPrintf(CTDL_DEBUG, "RBL check completed in %ld.%ld seconds\n",
+               (total_time / 1000000),
+               (total_time % 1000000)
+       );
        return(0);
 }
 
index fbfeaa6b0f7d0b746dfff7a21f632cf9842b417c..ba50488e40a2e879beffdd2b337dd9d9ad3e45ea 100644 (file)
@@ -134,7 +134,10 @@ void smtp_greeting(int is_msa)
         */
        if ( (config.c_rbl_at_greeting) && (SMTP->is_msa == 0) ) {
                if (rbl_check(message_to_spammer)) {
-                       cprintf("550 %s\r\n", message_to_spammer);
+                       if (CtdlThreadCheckStop())
+                               cprintf("421 %s\r\n", message_to_spammer);
+                       else
+                               cprintf("550 %s\r\n", message_to_spammer);
                        CC->kill_me = 1;
                        /* no need to free_recipients(valid), it's not allocated yet */
                        return;
@@ -574,7 +577,10 @@ void smtp_rcpt(char *argbuf) {
           && (!SMTP->is_lmtp) ) {      /* Don't RBL LMTP clients */
                if (config.c_rbl_at_greeting == 0) {    /* Don't RBL again if we already did it */
                        if (rbl_check(message_to_spammer)) {
-                               cprintf("550 %s\r\n", message_to_spammer);
+                               if (CtdlThreadCheckStop())
+                                       cprintf("421 %s\r\n", message_to_spammer);
+                               else
+                                       cprintf("550 %s\r\n", message_to_spammer);
                                /* no need to free_recipients(valid), it's not allocated yet */
                                return;
                        }