You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by fe...@apache.org on 2004/04/29 06:59:05 UTC
svn commit: rev 10407 - in incubator/spamassassin/trunk: lib/Mail spamd
Author: felicity
Date: Wed Apr 28 21:59:04 2004
New Revision: 10407
Modified:
incubator/spamassassin/trunk/lib/Mail/SpamAssassin.pm
incubator/spamassassin/trunk/spamd/spamd.raw
Log:
bug 2762: if spamd is restarted, and a file needs to get written (AWL or Bayes for instance) which is configured to be outside the default area (ie: awl_path /var/foo/bar/blah), the file will be created by the user launching spamd (root in most cases) which could end up being unaccessible by children processes. in compile_now(), we backup the default configuration values which include __userstate__, reset the defaults after init(), then after the whole check() completes, reset to the init() values. this lets spamd (and any other caller, optionally,) put all the startup files in a temp area.
Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin.pm (original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin.pm Wed Apr 28 21:59:04 2004
@@ -1041,7 +1041,7 @@
###########################################################################
-=item $f->compile_now ($use_user_prefs)
+=item $f->compile_now ($use_user_prefs, $keep_userstate)
Compile all patterns, load all configuration files, and load all
possibly-required Perl modules.
@@ -1057,10 +1057,18 @@
configuration without reading the per-user configuration file and it will
assume that you will call C<read_scoreonly_config> at a later point.
+If C<$keep_userstate> is true, compile_now() will revert any configuration
+options which have a default with I<__userstate__> in it post-init(),
+and then re-change the option before returning. This lets you change
+I<$ENV{'HOME'}> to a temp directory, have compile_now() and create any
+files there as necessary (auto-whitelist, etc,) without disturbing the
+actual files as changed by a configuration option. By default, this
+is disabled.
+
=cut
sub compile_now {
- my ($self, $use_user_prefs) = @_;
+ my ($self, $use_user_prefs, $deal_with_userstate) = @_;
# note: this may incur network access. Good. We want to make sure
# as much as possible is preloaded!
@@ -1069,8 +1077,32 @@
"I need to make this message body somewhat long so TextCat preloads\n"x20);
dbg ("ignore: test message to precompile patterns and load modules");
+
+ # Backup default values which deal with userstate.
+ # This is done so we can create any new files in, presumably, a temp dir.
+ # see bug 2762 for more details.
+ my %backup = ();
+ if (defined $deal_with_userstate && $deal_with_userstate) {
+ while(my($k,$v) = each %{$self->{conf}}) {
+ $backup{$k} = $v if (!ref($v) && $v =~/__userstate__/);
+ }
+ }
+
$self->init($use_user_prefs);
+ # if init() didn't change the value from default, forget about it.
+ # if the value is different, remember the new version, and reset the default.
+ while(my($k,$v) = each %backup) {
+ if ($self->{conf}->{$k} eq $v) {
+ delete $backup{$k};
+ }
+ else {
+ my $backup = $backup{$k};
+ $backup{$k} = $self->{conf}->{$k};
+ $self->{conf}->{$k} = $backup;
+ }
+ }
+
my $mail = $self->parse(\@testmsg, 1);
my $status = Mail::SpamAssassin::PerMsgStatus->new($self, $mail,
{ disable_auto_learning => 1 } );
@@ -1090,6 +1122,11 @@
}
$self->{bayes_scanner}->sanity_check_is_untied();
+
+ # Reset any non-default values to the post-init() version.
+ while(my($k,$v) = each %backup) {
+ $self->{conf}->{$k} = $v;
+ }
1;
}
Modified: incubator/spamassassin/trunk/spamd/spamd.raw
==============================================================================
--- incubator/spamassassin/trunk/spamd/spamd.raw (original)
+++ incubator/spamassassin/trunk/spamd/spamd.raw Wed Apr 28 21:59:04 2004
@@ -1651,7 +1651,7 @@
mkdir( $tmpsadir, 0700 ) or die "fatal: Can't create $tmpsadir: $!";
$ENV{HOME} = $tmphome;
- $spamtest->compile_now(0); # ensure all modules etc. are loaded
+ $spamtest->compile_now(0,1); # ensure all modules etc. are loaded
$/ = "\n"; # argh, Razor resets this! Bad Razor!
# now clean up the stuff we just created, and make us taint-safe