--- a/Makefile Tue Jan 02 16:59:20 2007 +0000
+++ b/Makefile Tue Jan 02 19:50:02 2007 +0000
@@ -1,8 +1,9 @@
# $Id$
# $URL$
+#
+PERL = $(shell which perl)
exim = exim
-
prefix = /usr/local
sbindir = ${prefix}/sbin
libdir = ${prefix}/share/${exim}
@@ -30,5 +31,6 @@
.%.pl: %.pl
@sed -e 's,@LIBDIR@,$(libdir),g' \
+ -e 's,@PERL@,$(PERL),g' \
<$< >$@
@perl -c $@
--- a/debian/changelog Tue Jan 02 16:59:20 2007 +0000
+++ b/debian/changelog Tue Jan 02 19:50:02 2007 +0000
@@ -1,3 +1,9 @@
+exigrey (0.4-1) stable; urgency=low
+
+ * new upstream (DB_File instead of BerkeleyDB)
+
+ -- Heiko Schlittermann <hs@schlittermann.de> Tue, 02 Jan 2007 20:49:13 +0100
+
exigrey (0.3-1) stable; urgency=low
* new upstream (--clean added)
--- a/debian/control Tue Jan 02 16:59:20 2007 +0000
+++ b/debian/control Tue Jan 02 19:50:02 2007 +0000
@@ -7,7 +7,7 @@
Package: exigrey
Architecture: all
-Depends: ${shlibs:Depends}, ${misc:Depends}, libberkeleydb-perl
+Depends: ${shlibs:Depends}, ${misc:Depends}
Suggests: exim4
Description: greylist implementation for exim (perl)
Yet another greylist implementation for exim, using Exims
--- a/exigrey.pl Tue Jan 02 16:59:20 2007 +0000
+++ b/exigrey.pl Tue Jan 02 19:50:02 2007 +0000
@@ -1,4 +1,4 @@
-#! /usr/bin/perl
+#! @PERL@
# © 2006,2007 Heiko Schlittermann <hs@schlittermann.de>
# Quick and dirty. Absolutly no warranty. Not even for spelling ;-)
# $Id$
@@ -25,7 +25,9 @@
use FindBin qw/$Bin/;
use POSIX qw/strftime mktime/;
-do "@LIBDIR@/exigrey.pl" or die;
+do "@LIBDIR@/exigrey.pl"
+ or do "./exim-exigrey.pl" or die $!;
+
my %DEFAULT = getDefault();
$DEFAULT{days} = 7;
@@ -35,7 +37,6 @@
my $opt_clean;
sub iterate(\%$);
-sub connectDB(\%$);
MAIN: {
@@ -54,7 +55,7 @@
if ($opt_list) {
my %h;
- connectDB(%h, shift || $DEFAULT{db});
+ connectDB(\%h, shift || $DEFAULT{db});
iterate(%h, sub {
my ($item, $v0, $v1, $dv) = @_;
printf "%-16s:\t$v0 $v1 (%3ds %s %s)\n",
@@ -67,7 +68,7 @@
if ($opt_stats) {
my %h;
- my $db = connectDB(%h, shift || $DEFAULT{db});
+ my $db = connectDB(\%h, shift || $DEFAULT{db});
my ($seen, $returned, $oldest);
$oldest = time();
@@ -102,7 +103,7 @@
my $cut = time() - ($days * 86400);
my $tmp = tmpfile();
- $db = connectDB(%h, $db);
+ $db = connectDB(\%h, $db);
iterate(%h, sub {
my ($item, $v0, $v1, $dv) = @_;
print $tmp $item if $v1 <= $cut;
@@ -130,11 +131,5 @@
}
}
-sub connectDB(\%$) {
- my ($h, $db) = @_;
- $db = getDBDir() ."/$db" unless $db =~ /^\//;
- tie %$h, "BerkeleyDB::Hash", -Filename => $db or die;
- return $db;
-}
# vim:ft=perl aw sts=4 sw=4:
--- a/exim-exigrey.pl Tue Jan 02 16:59:20 2007 +0000
+++ b/exim-exigrey.pl Tue Jan 02 19:50:02 2007 +0000
@@ -4,7 +4,14 @@
use strict;
use warnings;
-use BerkeleyDB;
+use Carp;
+
+# You may choose, but DB_File's footprint is smaller.
+# perl -MDB_File -e 'tie %h, ...': real 0m0.063s
+# perl -MBerkeleyDB -e 'tie %h, ...': real 0m0.112s
+# And DB_File is part of the Perl core distribution (?)
+# use BerkeleyDB;
+use DB_File;
my %DEFAULT = (
delay => 600,
@@ -13,8 +20,10 @@
sub unseen($;$$);
+# some helper functions
sub getDBDir();
sub findExim(;$);
+sub connectDB($$);
sub getDefault() { %DEFAULT };
# Usage:
@@ -33,19 +42,10 @@
$db = $DEFAULT{db} unless defined $db;
my $now = time();
- my $umask;
my $rc;
- $db = getDBDir() . "/$db" unless $db =~ /^\//;
-
- $umask = umask 0077 if !-f $db;
-
- my %h; tie %h, "BerkeleyDB::Hash",
- -Filename => $db,
- -Flags => DB_CREATE
- or die;
-
- umask $umask if defined $umask;
+ my %h;
+ $db = connectDB(\%h, $db || $DEFAULT{db});
if (not exists $h{$item}) {
$h{$item} = "$now $now\0";
@@ -83,9 +83,31 @@
-x ($exim = "$_/exim") and return $exim;
-x ($exim = "$_/exim4") and return $exim;
}
- return undef;
+ die "Can't find exim binary (missing .../sbin dirs in PATH?";
}
+sub connectDB($$) {
+ my ($h, $db) = @_;
+ $db = getDBDir() ."/$db" unless $db =~ /^\//;
+
+ if (exists &BerkeleyDB::Hash::TIEHASH) {
+ no strict;
+ my $umask = umask 077;
+ tie %$h, "BerkeleyDB::Hash",
+ -Filename => $db,
+ -Flags => DB_CREATE
+ or die "$0: $db: $!";
+ return $db;
+ }
+
+ if (exists &DB_File::TIEHASH) {
+ tie %$h, "DB_File", $db, undef, 0600
+ or die "$0: $db: $!";
+ return $db;
+ }
+
+ die "Can't connect to database driver";
+}
1;
# vim:aw: