View | Details | Raw Unified | Return to bug 5612
Collapse All | Expand All

(-)Mail-SpamAssassin-3.2.3.orig/lib/Mail/SpamAssassin/BayesStore/DBM.pm (-1 / +5 lines)
Lines 279-285 Link Here
279
    my $name = $path.'_'.$dbname;
279
    my $name = $path.'_'.$dbname;
280
    my $db_var = 'db_'.$dbname;
280
    my $db_var = 'db_'.$dbname;
281
    dbg("bayes: tie-ing to DB file R/W $name");
281
    dbg("bayes: tie-ing to DB file R/W $name");
282
    tie %{$self->{$db_var}},$self->DBM_MODULE,$name, O_RDWR|O_CREAT,
282
283
    ($self->DBM_MODULE eq 'DB_File') and
284
         Mail::SpamAssassin::Util::avoid_db_file_locking_bug ($name);
285
286
    tie %{$self->{$db_var}},$self->DBM_MODULE, $name, O_RDWR|O_CREAT,
283
		 (oct($main->{conf}->{bayes_file_mode}) & 0666)
287
		 (oct($main->{conf}->{bayes_file_mode}) & 0666)
284
       or goto failed_to_tie;
288
       or goto failed_to_tie;
285
  }
289
  }
(-)Mail-SpamAssassin-3.2.3.orig/lib/Mail/SpamAssassin/DBBasedAddrList.pm (-7 / +11 lines)
Lines 82-96 Link Here
82
82
83
    dbg("auto-whitelist: tie-ing to DB file of type $dbm_module $mod1 in $path");
83
    dbg("auto-whitelist: tie-ing to DB file of type $dbm_module $mod1 in $path");
84
84
85
    ($self->{is_locked} && $dbm_module eq 'DB_File') and 
86
            Mail::SpamAssassin::Util::avoid_db_file_locking_bug ($path);
87
85
    if (! tie %{ $self->{accum} }, $dbm_module, $path, $mod2,
88
    if (! tie %{ $self->{accum} }, $dbm_module, $path, $mod2,
86
      oct($main->{conf}->{auto_whitelist_file_mode}) ) {
89
            oct($main->{conf}->{auto_whitelist_file_mode}) )
87
        my $err = $!;   # might get overwritten later
90
    {
88
        if ($self->{is_locked}) {
91
      my $err = $!;   # might get overwritten later
89
          $self->{main}->{locker}->safe_unlock($self->{locked_file});
92
      if ($self->{is_locked}) {
90
          $self->{is_locked} = 0;
93
        $self->{main}->{locker}->safe_unlock($self->{locked_file});
91
        }
94
        $self->{is_locked} = 0;
92
        die "auto-whitelist: cannot open auto_whitelist_path $path: $err\n";
93
      }
95
      }
96
      die "auto-whitelist: cannot open auto_whitelist_path $path: $err\n";
97
    }
94
  }
98
  }
95
99
96
  bless ($self, $class);
100
  bless ($self, $class);
(-)Mail-SpamAssassin-3.2.3.orig/lib/Mail/SpamAssassin/Util.pm (+38 lines)
Lines 57-62 Link Here
57
57
58
use Config;
58
use Config;
59
use File::Spec;
59
use File::Spec;
60
use File::Basename;
60
use Time::Local;
61
use Time::Local;
61
use Sys::Hostname (); # don't import hostname() into this namespace!
62
use Sys::Hostname (); # don't import hostname() into this namespace!
62
use Fcntl;
63
use Fcntl;
Lines 1551-1556 Link Here
1551
1552
1552
###########################################################################
1553
###########################################################################
1553
1554
1555
# bug 5612: work around for bugs in Berkeley db 4.2
1556
#
1557
# on 4.2 having the __db.[DBNAME] file will cause an loop that will never finish
1558
# on 4.3+ the loop will timeout after 301 open attempts, but we will still
1559
# be unable to open the database.  This workaround solves both problems. 
1560
#
1561
sub avoid_db_file_locking_bug {
1562
  my $path = shift;
1563
  
1564
  my $db_tmp_file = '__db.'.basename($path);
1565
  my $db_tmp_file_match = $db_tmp_file . '.';
1566
1567
  my $parentdir = dirname($path);
1568
1569
  # The db bug is actually more pervasive then orignally thought we can also have __db.[DBNAME].* as well.
1570
1571
  opendir(my $sa_db_dir_fh, $parentdir);
1572
  while(my $test_filename = readdir($sa_db_dir_fh)) {  
1573
	# If the file is __db.[DBNAME] or the file is __db.[DBNAME].* (glob) then we need to remove it
1574
	# we use substr here as its slightly fater then using a regex 
1575
1576
	my $newtest = substr($test_filename,0,length($db_tmp_file_match));
1577
1578
	if ( substr($test_filename,0,length($db_tmp_file_match)) eq $db_tmp_file_match || $test_filename eq $db_tmp_file ) {
1579
		my $db_tmpfile = untaint_file_path( File::Spec->catfile($parentdir,$test_filename) );
1580
		
1581
		dbg("Berkeley DB bug work-around: cleaning tmp file $db_tmpfile");
1582
		if (!unlink($db_tmpfile)) {
1583
			die "cannot remove Berkeley DB tmp file $db_tmpfile: $!\n";
1584
		}
1585
	}
1586
  }
1587
  closedir($sa_db_dir_fh);
1588
}
1589
1590
###########################################################################
1591
1554
1;
1592
1;
1555
1593
1556
=back
1594
=back

Return to bug 5612