You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2005/06/08 05:39:33 UTC

svn commit: r189514 - in /spamassassin/trunk: MANIFEST t/SATest.pm t/data/spamc_test.cf t/spamc_cf.t t/spamd_plugin.t t/spamd_unix.t

Author: jm
Date: Tue Jun  7 20:39:32 2005
New Revision: 189514

URL: http://svn.apache.org/viewcvs?rev=189514&view=rev
Log:
bug 4380: spamd on BSD platforms cannot use UNIX domain sockets with paths longer than about 100 characters.  create the sockets in /tmp (or TMPDIR) instead for our test suite

Removed:
    spamassassin/trunk/t/data/spamc_test.cf
Modified:
    spamassassin/trunk/MANIFEST
    spamassassin/trunk/t/SATest.pm
    spamassassin/trunk/t/spamc_cf.t
    spamassassin/trunk/t/spamd_plugin.t
    spamassassin/trunk/t/spamd_unix.t

Modified: spamassassin/trunk/MANIFEST
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/MANIFEST?rev=189514&r1=189513&r2=189514&view=diff
==============================================================================
--- spamassassin/trunk/MANIFEST (original)
+++ spamassassin/trunk/MANIFEST Tue Jun  7 20:39:32 2005
@@ -333,7 +333,6 @@
 t/data/spam/spf2
 t/data/spam/spf3
 t/data/spamc_blank.cf
-t/data/spamc_test.cf
 t/data/testplugin.pm
 t/data/validuserplugin.pm
 t/data/whitelists/action.eff.org

Modified: spamassassin/trunk/t/SATest.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/t/SATest.pm?rev=189514&r1=189513&r2=189514&view=diff
==============================================================================
--- spamassassin/trunk/t/SATest.pm (original)
+++ spamassassin/trunk/t/SATest.pm Tue Jun  7 20:39:32 2005
@@ -673,4 +673,40 @@
   return 0;                                 # n or 0
 }
 
+sub mk_safe_tmpdir {
+  return $safe_tmpdir if defined($safe_tmpdir);
+
+  my $dir = $ENV{TMPDIR} || '/tmp';
+
+  # be a little paranoid, since we're using a public tmp dir and
+  # are exposed to race conditions
+  my $retries = 10;
+  my $tmp;
+  while (1) {
+    $tmp = "$dir/satest.$$.".rand(99999);
+    if (!-d $tmp && mkdir ($tmp, 0755)) {
+      if (-d $tmp && -o $tmp) {     # check we own it
+        lstat($tmp);
+        if (-d _ && -o _) {         # double-check, ignoring symlinks
+          last;                     # we got it safely
+        }
+      }
+    }
+
+    die "cannot get tmp dir, giving up" if ($retries-- < 0);
+
+    warn "failed to create tmp dir '$tmp' safely, retrying...";
+    sleep 1;
+  }
+
+  $safe_tmpdir = $tmp;
+  return $tmp;
+}
+
+sub cleanup_safe_tmpdir {
+  if ($safe_tmpdir) {
+    rmtree($safe_tmpdir) or warn "cannot rmtree $safe_tmpdir";
+  }
+}
+
 1;

Modified: spamassassin/trunk/t/spamc_cf.t
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/t/spamc_cf.t?rev=189514&r1=189513&r2=189514&view=diff
==============================================================================
--- spamassassin/trunk/t/spamc_cf.t (original)
+++ spamassassin/trunk/t/spamc_cf.t Tue Jun  7 20:39:32 2005
@@ -17,8 +17,15 @@
 
 );
 
-start_spamd("-D -L --socketpath=log/spamd.sock");
-ok (spamcrun ("-F data/spamc_test.cf < data/spam/001", \&patterns_run_cb));
+my $sockpath = mk_safe_tmpdir()."/spamd.sock";
+start_spamd("-D -L --socketpath=$sockpath");
+
+open (OUT, ">log/spamc_cf.cf");
+print OUT "-U $sockpath\n";
+close OUT;
+
+ok (spamcrun ("-F log/spamc_cf.cf < data/spam/001", \&patterns_run_cb));
 ok_all_patterns();
 stop_spamd();
+cleanup_safe_tmpdir();
 

Modified: spamassassin/trunk/t/spamd_plugin.t
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/t/spamd_plugin.t?rev=189514&r1=189513&r2=189514&view=diff
==============================================================================
--- spamassassin/trunk/t/spamd_plugin.t (original)
+++ spamassassin/trunk/t/spamd_plugin.t Tue Jun  7 20:39:32 2005
@@ -23,12 +23,13 @@
 print COUNTER "0";
 close COUNTER;
 
-start_spamd("-D -L --socketpath=log/spamd.sock");
+my $sockpath = mk_safe_tmpdir()."/spamd.sock";
+start_spamd("-D -L --socketpath=$sockpath");
 
 %patterns = (
   q{ test: called myTestPlugin, round 1 }, 'called1'
 );
-ok (spamcrun ("-U log/spamd.sock < data/spam/001", \&patterns_run_cb));
+ok (spamcrun ("-U $sockpath < data/spam/001", \&patterns_run_cb));
 
 checkfile("spamd_plugin-spamd.err", \&patterns_run_cb);
 ok_all_patterns();
@@ -36,16 +37,17 @@
 %patterns = (
   q{ called myTestPlugin, round 2 }, 'called2'
 );
-ok (spamcrun ("-U log/spamd.sock < data/nice/001", \&patterns_run_cb));
+ok (spamcrun ("-U $sockpath < data/nice/001", \&patterns_run_cb));
 checkfile("spamd_plugin-spamd.err", \&patterns_run_cb);
 ok_all_patterns();
 
 %patterns = (
   q{ called myTestPlugin, round 3 }, 'called3'
 );
-ok (spamcrun ("-U log/spamd.sock < data/nice/001", \&patterns_run_cb));
+ok (spamcrun ("-U $sockpath < data/nice/001", \&patterns_run_cb));
 checkfile("spamd_plugin-spamd.err", \&patterns_run_cb);
 ok_all_patterns();
 
 stop_spamd();
+cleanup_safe_tmpdir();
 

Modified: spamassassin/trunk/t/spamd_unix.t
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/t/spamd_unix.t?rev=189514&r1=189513&r2=189514&view=diff
==============================================================================
--- spamassassin/trunk/t/spamd_unix.t (original)
+++ spamassassin/trunk/t/spamd_unix.t Tue Jun  7 20:39:32 2005
@@ -18,8 +18,10 @@
 
 );
 
-start_spamd("-D -L --socketpath=log/spamd.sock");
-ok (spamcrun ("-U log/spamd.sock < data/spam/001", \&patterns_run_cb));
+my $sockpath = mk_safe_tmpdir()."/spamd.sock";
+start_spamd("-D -L --socketpath=$sockpath");
+ok (spamcrun ("-U $sockpath < data/spam/001", \&patterns_run_cb));
 ok_all_patterns();
 stop_spamd();
+cleanup_safe_tmpdir();
 



Re: svn commit: r189514 - in /spamassassin/trunk: MANIFEST t/SATest.pm t/data/spamc_test.cf t/spamc_cf.t t/spamd_plugin.t t/spamd_unix.t

Posted by "Malte S. Stretz" <ms...@gmx.net>.
On Wednesday 08 June 2005 06:01 CET Duncan Findlay wrote:
> On Wed, Jun 08, 2005 at 03:39:33AM -0000, jm@apache.org wrote:
> > +sub mk_safe_tmpdir {
> > +  return $safe_tmpdir if defined($safe_tmpdir);
> > +
> > +  my $dir = $ENV{TMPDIR} || '/tmp';
> > +
> > +  # be a little paranoid, since we're using a public tmp dir and
> > +  # are exposed to race conditions
> > +  my $retries = 10;
>
> I think we should just use File::Temp, it's included with perl, AFAIK,
> and should do the right thing in more situations. This looks a little
> specific to unix-like environments.

... or at least File::Spec->tmpdir()

Cheers,
Malte

-- 
[SGT] Simon G. Tatham: "How to Report Bugs Effectively"
      <http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>
[ESR] Eric S. Raymond: "How To Ask Questions The Smart Way"
      <http://www.catb.org/~esr/faqs/smart-questions.html>

Re: svn commit: r189514 - in /spamassassin/trunk: MANIFEST t/SATest.pm t/data/spamc_test.cf t/spamc_cf.t t/spamd_plugin.t t/spamd_unix.t

Posted by Duncan Findlay <du...@debian.org>.
On Wed, Jun 08, 2005 at 03:39:33AM -0000, jm@apache.org wrote:
> +sub mk_safe_tmpdir {
> +  return $safe_tmpdir if defined($safe_tmpdir);
> +
> +  my $dir = $ENV{TMPDIR} || '/tmp';
> +
> +  # be a little paranoid, since we're using a public tmp dir and
> +  # are exposed to race conditions
> +  my $retries = 10;

I think we should just use File::Temp, it's included with perl, AFAIK,
and should do the right thing in more situations. This looks a little
specific to unix-like environments.

-- 
Duncan Findlay