Hey all,

BI've been doing some hacks to Mimedefang to allow per-user configuration to be read from LDAP (using the SA ldap stuff), and have it working, except for the fact that preferences do not get cleared between runs of SpamAssassin. I took a look at the way Mimedefang is doing spam checking and hacked up a test script (attached) to verify this behavior. I've also included the .cf file I use to grab prefs out of LDAP.

For this script, I have two users defined in ldap - 'testuser1' and 'testuser2'. testuser1 has no specific sa configuration set; testuser2 has a all_spam_to entry for '[EMAIL PROTECTED]'. The script runs 3 SA tests on the message 'mailmessage'. The first test is run as 'testuser1', the session is ended, it's run as testuser2, session is ended again, and then run as testuser1 again. Here's the results I get:

$ perl sa-ldap-test.pl
Initializing SpamAssassin... compiling... done.
Testing for testuser1... -2.755 hits with ALL_TRUSTED,AWL.
Testing for testuser2... -102.705 hits with ALL_TRUSTED,AWL,USER_IN_ALL_SPAM_TO.
Testing for testuser1... -102.666 hits with ALL_TRUSTED,AWL,USER_IN_ALL_SPAM_TO.

I thought that doing a $status->finish (see script) would clear out all of the whitelist/blacklist it learns from LDAP (so when going from testuser2 back to testuser1 it would clear out the all_spam_to entry learned from testuser2), but it doesn't seem to do it. I tried taking a look at the spamd code to see what I'm doing differently, but can't figure it out - if someone could look at the script I'm running, and let me know what's necessary to clear out the conf files when switching users, I'd much appreciate it!

------------------------------------------------------------------------
| nate carlson | [EMAIL PROTECTED] | http://www.natecarlson.com |
|       depriving some poor village of its idiot since 1981            |
------------------------------------------------------------------------
#!/usr/bin/perl

$|=1;

use Mail::SpamAssassin;

my($SASpamTester);

open(MAIL, "< mailmessage");
@msg = <MAIL>;
close(MAIL);

sainit();
testmsg(testuser1);
testmsg(testuser2);
testmsg(testuser1);

sub sainit {
	print "Initializing SpamAssassin... ";
	$SASpamTester = Mail::SpamAssassin->new(
		{
			local_tests_only	=>	1,
			dont_copy_prefs		=>	1,
			LOCAL_RULES_DIR		=>	"/etc/spamassassin",
			userprefs_filename	=>	"/etc/sa-mimedefang.cf"
		}
	);
	print "compiling... ";
	$SASpamTester->compile_now(1);
	print "done.\n";
}

sub testmsg ($) {
	my ($username) = @_;

	print "Testing for $username... ";

	$SASpamTester->load_scoreonly_ldap("$username");
	$SASpamTester->signal_user_changed (
		{
			username	=>	"$username",
			user_dir	=>	undef
		}
	);

	my($mail) = $SASpamTester->parse([EMAIL PROTECTED]);
	my($status) = $SASpamTester->check($mail);
	$mail->finish();

	my($hits) = $status->get_hits;
	my($tests) = $status->get_names_of_tests_hit();
	print "$hits hits with $tests.\n";

	$status->finish();
}
Return-Path: <[EMAIL PROTECTED]>
Received: from localhost (localhost [127.0.0.1])
        by localhost with ESMTP id iB8I09Ti019209
        for <[EMAIL PROTECTED]>; Wed, 08 Dec 2004 12:01:18 -0600 (CST)
Date: Wed, 8 Dec 2004 12:00:09 -0600 (CST)
From: Test User <[EMAIL PROTECTED]>
To: Test User <[EMAIL PROTECTED]>
Subject: test
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed

test
user_scores_dsn 
ldap://localhost/dc=example,dc=com?spamassassin?sub?uid=__USERNAME__
user_scores_ldap_username     cn=ldapuser,dc=example,dc=com
user_scores_ldap_password     password

Reply via email to