]> code.citadel.org Git - citadel.git/blobdiff - citadel/locate_host.c
* Added support for any standard RBL
[citadel.git] / citadel / locate_host.c
index 3f50fe60a714d1882116e25e3b1c91a97359cfaf..de88d33f70d09a7096097026ef65f04837b64e90 100644 (file)
@@ -5,10 +5,6 @@
  *
  */
 
-#ifdef DLL_EXPORT
-#define IN_LIBCIT
-#endif
-
 #include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
@@ -27,6 +23,7 @@
 #include "sysdep_decls.h"
 #include "config.h"
 #include "tools.h"
+#include "domain.h"
 
 void locate_host(char *tbuf, size_t n, const struct in_addr *addr)
 {
@@ -79,3 +76,63 @@ void locate_host(char *tbuf, size_t n, const struct in_addr *addr)
        tbuf[63] = 0;
        lprintf(9, "locate_host() exiting\n");
 }
+
+
+/*
+ * Check to see if a host is on some sort of spam list (RBL)
+ * If spammer, returns nonzero and places reason in 'message_to_spammer'
+ */
+int rbl_check_addr(struct in_addr *addr, char *message_to_spammer)
+{
+       const char *i;
+       int a1, a2, a3, a4;
+       char tbuf[SIZ];
+       int rbl;
+       int num_rbl;
+       char rbl_domains[SIZ];
+
+       strcpy(message_to_spammer, "ok");
+
+       i = (const char *) addr;
+       a1 = ((*i++) & 0xff);
+       a2 = ((*i++) & 0xff);
+       a3 = ((*i++) & 0xff);
+       a4 = ((*i++) & 0xff);
+
+       /* See if we have any RBL domains configured */
+       num_rbl = get_hosts(rbl_domains, "rbl");
+       if (num_rbl < 1) return(0);
+
+       /* Try all configured RBL */
+        for (rbl=0; rbl<num_rbl; ++rbl) {
+               snprintf(tbuf, sizeof tbuf,
+                       "%d.%d.%d.%d.",
+                       a4, a3, a2, a1);
+                extract(&tbuf[strlen(tbuf)], rbl_domains, rbl);
+
+               if (gethostbyname(tbuf) != NULL) {
+                       strcpy(message_to_spammer,
+                               "Message rejected due to "
+                               "known spammer source IP address"
+                       );
+                       return(1);
+               }
+       }
+
+       return(0);
+}
+                       
+
+/*
+ * Check to see if the client host is on some sort of spam list (RBL)
+ * If spammer, returns nonzero and places reason in 'message_to_spammer'
+ */
+int rbl_check(char *message_to_spammer) {
+       struct sockaddr_in sin;
+       socklen_t len;
+
+       if (!getpeername(CC->client_socket, (struct sockaddr *) &sin, &len)) {
+               return(rbl_check_addr(&sin.sin_addr, message_to_spammer));
+       }
+       return(0);
+}