changeset 211:4db1457cd11a stable-6-0-18

Extend auto-whitelisting when receiving mail even if the auto whitelist is specified in a parent context. Fixes for Solaris from sm-archive.
author Carl Byington <carl@five-ten-sg.com>
date Sat, 22 Mar 2008 11:19:36 -0700
parents cf2ecf5bacc9
children a47f161c76c9
files ChangeLog Makefile.am NEWS configure.in dnsbl.rc dnsbl.rc.in dnsbl.spec.in src/Makefile.am src/context.cpp src/daemon.c src/daemon.h src/dnsbl.cpp src/scanner.cpp src/test.cpp src/tokenizer.cpp
diffstat 15 files changed, 109 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Mar 05 18:24:36 2008 -0800
+++ b/ChangeLog	Sat Mar 22 11:19:36 2008 -0700
@@ -1,3 +1,7 @@
+6.18 2008-03-22
+    Extend auto-whitelisting when receiving mail even if the auto
+    whitelist is specified in a parent context. Fixes for Solaris from sm-archive.
+
 6.17 2008-03-04
     Verify from/to pairs even if they might be explicitly whitelisted.
     Document DCC greylisting and bulk detection usage. Fix DCC bulk
--- a/Makefile.am	Wed Mar 05 18:24:36 2008 -0800
+++ b/Makefile.am	Sat Mar 22 11:19:36 2008 -0700
@@ -1,3 +1,5 @@
+ACLOCAL_AMFLAGS = -I m4
+
 SUBDIRS = src man html info
 hackdir = $(sysconfdir)/dnsbl
 hack_SCRIPTS = dnsbl
--- a/NEWS	Wed Mar 05 18:24:36 2008 -0800
+++ b/NEWS	Sat Mar 22 11:19:36 2008 -0700
@@ -1,3 +1,4 @@
+6.18 2008-03-22 Extend auto-whitelisting even if specified in a parent context.
 6.17 2008-03-04 Verify all from/to pairs, fix dcc bulk thresholds of many.
 6.16 2008-02-02 Switch to Mercurial source control.
 6.15 2007-12-07 Fix null pointer dereference if macro _ not passed to this milter.
--- a/configure.in	Wed Mar 05 18:24:36 2008 -0800
+++ b/configure.in	Sat Mar 22 11:19:36 2008 -0700
@@ -1,6 +1,6 @@
 
 AC_PREREQ(2.59)
-AC_INIT(dnsbl,6.17,carl@five-ten-sg.com)
+AC_INIT(dnsbl,6.18,carl@five-ten-sg.com)
 AC_CONFIG_SRCDIR([config.h.in])
 AC_CONFIG_HEADER([config.h])
 
@@ -40,7 +40,7 @@
 AC_HEADER_STDC
 AC_FUNC_STAT
 AC_FUNC_STRFTIME
-AC_CHECK_FUNCS([dup2 gethostbyname gethostname memmove memset socket strchr strdup strerror strncasecmp strrchr strstr strtol])
+AC_CHECK_FUNCS([daemon dup2 gethostbyname gethostname memmove memset socket strchr strdup strerror strncasecmp strrchr strstr strtol])
 
 # check for posix threads
 ACX_PTHREAD
--- a/dnsbl.rc	Wed Mar 05 18:24:36 2008 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +0,0 @@
-#!/bin/sh
-#
-# dnsbl   This script controls the dnsbl milter daemon.
-#
-#
-# chkconfig: 2345 79 31
-# description: dnsbl is an interface between MTA and the various dns blocking lists
-# processname: dnsbl
-# pidfile: /var/run/dnsbl.pid
-# Source function library.
-#
-. /etc/rc.d/init.d/functions
-
-# Source networking configuration.
-. /etc/sysconfig/network
-
-RETVAL=0
-# See how we were called.
-case "$1" in
-    start)
-        # Start daemons.
-        echo -n "Starting dnsbl-milter: "
-        if [ ! -f /var/lock/subsys/dnsbl ]; then
-            cd SYSCONFDIR/dnsbl     # conf file is here
-            SBINDIR/dnsbl -d 10 -r /var/run/dnsbl/dnsbl.resolver.sock -p local:/var/run/dnsbl/dnsbl.sock
-            RETVAL=$?
-            pid=`pidof -s SBINDIR/dnsbl`
-            if [ $pid ]
-            then
-                success "Starting dnsbl milter:"
-                touch /var/lock/subsys/dnsbl
-                echo
-            else
-                failure "Starting dnsbl milter:"
-                echo
-            fi
-        else
-            echo -n "already running! "
-            failure "dnsbl milter already running!"
-            echo
-        fi
-
-        ;;
-    stop)
-        # Stop daemons.
-        echo -n "Shutting down dnsbl-milter: "
-        killproc dnsbl
-        RETVAL=$?
-        echo
-        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/dnsbl
-        ;;
-    restart|reload)
-        $0 stop
-        $0 start
-        RETVAL=$?
-        ;;
-    status)
-        status dnsbl
-        RETVAL=$?
-        ;;
-    *)
-        echo "Usage: dnsbl {start|stop|restart|status}"
-        exit 1
-esac
-exit $RETVAL
-
-# $Id$
--- a/dnsbl.rc.in	Wed Mar 05 18:24:36 2008 -0800
+++ b/dnsbl.rc.in	Sat Mar 22 11:19:36 2008 -0700
@@ -65,5 +65,3 @@
         exit 1
 esac
 exit $RETVAL
-
-# $Id$
--- a/dnsbl.spec.in	Wed Mar 05 18:24:36 2008 -0800
+++ b/dnsbl.spec.in	Sat Mar 22 11:19:36 2008 -0700
@@ -81,6 +81,8 @@
 
 
 %clean
+rm -rf $RPM_BUILD_ROOT
+
 
 %files
 %defattr(-,root,root,-)
--- a/src/Makefile.am	Wed Mar 05 18:24:36 2008 -0800
+++ b/src/Makefile.am	Sat Mar 22 11:19:36 2008 -0700
@@ -1,6 +1,6 @@
 sbin_PROGRAMS = dnsbl
-dnsbl_SOURCES = dnsbl.cpp dnsbl.h dccifd.cpp dccifd.h spamass.cpp spamass.h context.cpp context.h tokenizer.cpp tokenizer.h scanner.cpp scanner.h includes.h
-EXTRA_DIST = test.cpp
+dnsbl_SOURCES = dnsbl.cpp dnsbl.h dccifd.cpp dccifd.h spamass.cpp spamass.h context.cpp context.h tokenizer.cpp tokenizer.h scanner.cpp scanner.h includes.h daemon.h
+EXTRA_DIST = daemon.c test.cpp
 
 # set the include path found by configure
 INCLUDES= $(all_includes)
--- a/src/context.cpp	Wed Mar 05 18:24:36 2008 -0800
+++ b/src/context.cpp	Sat Mar 22 11:19:36 2008 -0700
@@ -19,8 +19,6 @@
 #include <sys/un.h>
 #include <unistd.h>
 
-static char* context_version="$Id$";
-
 char *token_autowhite;
 char *token_black;
 char *token_cctld;
@@ -808,7 +806,13 @@
 
 
 char *CONTEXT::find_from(char *from, bool update_white) {
-    if (whitelister && whitelister->is_white(from)) {
+    WHITELISTERP w = whitelister;
+    CONTEXTP     p = parent;
+    while (!w && p) {
+        w = p->whitelister;
+        p = p->parent;
+    }
+    if (w && w->is_white(from)) {
         if (update_white) {
             // update senders timestamp to extend the whitelisting period
             if (debug_syslog > 1) {
@@ -817,7 +821,7 @@
                 snprintf(msg, sizeof(msg), "extend whitelist reply from <%s> in context %s", from, get_full_name(buf,maxlen));
                 my_syslog(msg);
             }
-            whitelister->sent(strdup(from));
+            w->sent(strdup(from));
         }
         return token_white;
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/daemon.c	Sat Mar 22 11:19:36 2008 -0700
@@ -0,0 +1,61 @@
+/*Add by Sergey Shapovalov */
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <errno.h>
+
+/* closeall() -- close all FDs >= a specified value */
+
+void closeall(int fd)
+{
+	int fdlimit = sysconf(_SC_OPEN_MAX);
+
+	while (fd < fdlimit)
+	  close(fd++);
+}
+
+/* daemon() - detach process from user and disappear into the background
+ * returns -1 on failure, but you can't do much except exit in that case
+ * since we may already have forked. This is based on the BSD version,
+ * so the caller is responsible for things like the umask, etc.
+ */
+
+/* believed to work on all Posix systems */
+
+int daemon(int nochdir, int noclose)
+{
+	switch (fork())
+	{
+		case 0:  break;
+		case -1: return -1;
+		default: _exit(0);			/* exit the original process */
+	}
+
+	if (setsid() < 0)				/* shoudn't fail */
+	  return -1;
+
+	/* dyke out this switch if you want to acquire a control tty in */
+	/* the future -- not normally advisable for daemons */
+
+	switch (fork())
+	{
+		case 0:  break;
+		case -1: return -1;
+		default: _exit(0);
+	}
+
+	if (!nochdir)
+	  chdir("/");
+
+	if (!noclose)
+	{
+		closeall(0);
+		open("/dev/null",O_RDWR);
+		dup(0); dup(0);
+	}
+
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/daemon.h	Sat Mar 22 11:19:36 2008 -0700
@@ -0,0 +1,23 @@
+/*
+ * File:   daemon.h
+ * Author: shasn
+ *
+ * Created on 22 Декабрь 2006 г., 15:28
+ */
+
+#ifndef _daemon_H
+#define _daemon_H
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+int daemon(int nochdir, int noclose);
+
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* _daemon_H */
+
--- a/src/dnsbl.cpp	Wed Mar 05 18:24:36 2008 -0800
+++ b/src/dnsbl.cpp	Sat Mar 22 11:19:36 2008 -0700
@@ -60,7 +60,10 @@
 
 #include "includes.h"
 
-static char* dnsbl_version="$Id$";
+#ifndef HAVE_DAEMON
+	#include "daemon.h"
+	#include "daemon.c"
+#endif
 
 extern "C" {
     sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr);
--- a/src/scanner.cpp	Wed Mar 05 18:24:36 2008 -0800
+++ b/src/scanner.cpp	Sat Mar 22 11:19:36 2008 -0700
@@ -11,8 +11,6 @@
 #include <arpa/inet.h>
 #include "includes.h"
 
-static char* scanner_version="$Id$";
-
 ////////////////////////////////////////////////
 // finite state machine
 //
--- a/src/test.cpp	Wed Mar 05 18:24:36 2008 -0800
+++ b/src/test.cpp	Sat Mar 22 11:19:36 2008 -0700
@@ -11,8 +11,6 @@
 #include <pthread.h>
 #include <set>
 
-static char* test_version="$Id$";
-
 using namespace std;
 
 struct ltstr {
--- a/src/tokenizer.cpp	Wed Mar 05 18:24:36 2008 -0800
+++ b/src/tokenizer.cpp	Sat Mar 22 11:19:36 2008 -0700
@@ -8,8 +8,6 @@
 
 #include "includes.h"
 
-static char* tokenizer_version="$Id$";
-
 const int maxlen = 1000;	// used for snprintf buffers
 
 enum state {s_init,