Clarify DBM-specific functions

This changes function names only
This commit is contained in:
Jared Johnson 2014-11-24 17:09:42 -06:00
parent ea2f1e89dd
commit 5fe9d80f9b
4 changed files with 70 additions and 70 deletions

View File

@ -335,10 +335,10 @@ sub greylist {
return DECLINED if $self->exclude();
my $db = $self->get_db_location();
my $lock = $self->get_db_lock($db) or return DECLINED;
my $tied = $self->get_db_tie($db, $lock) or return DECLINED;
my $key = $self->get_db_key($sender, $rcpt) or return DECLINED;
my $db = $self->get_dbm_location();
my $lock = $self->get_dbm_lock($db) or return DECLINED;
my $tied = $self->get_dbm_tie($db, $lock) or return DECLINED;
my $key = $self->get_greylist_key($sender, $rcpt) or return DECLINED;
my $fmt = "%s:%d:%d:%d";
@ -395,7 +395,7 @@ sub cleanup_and_return {
return DENYSOFT, $DENYMSG;
}
sub get_db_key {
sub get_greylist_key {
my $self = shift;
my $sender = shift || $self->qp->transaction->sender;
my $rcpt = shift || ($self->qp->transaction->recipients)[0];
@ -415,7 +415,7 @@ sub get_db_key {
return join ':', @key;
}
sub get_db_tie {
sub get_dbm_tie {
my ($self, $db, $lock) = @_;
tie(my %db, 'AnyDBM_File', $db, O_CREAT | O_RDWR, oct('0600')) or do {
@ -426,7 +426,7 @@ sub get_db_tie {
return \%db;
}
sub get_db_location {
sub get_dbm_location {
my $self = shift;
my $transaction = $self->qp->transaction;
@ -461,10 +461,10 @@ sub get_db_location {
return $db;
}
sub get_db_lock {
sub get_dbm_lock {
my ($self, $db) = @_;
return $self->get_db_lock_nfs($db) if $self->{_args}{nfslock};
return $self->get_dbm_lock_nfs($db) if $self->{_args}{nfslock};
# Check denysoft db
open(my $lock, '>', "$db.lock") or do {
@ -481,7 +481,7 @@ sub get_db_lock {
return $lock;
}
sub get_db_lock_nfs {
sub get_dbm_lock_nfs {
my ($self, $db) = @_;
require File::NFSLock;
@ -509,9 +509,9 @@ sub get_db_lock_nfs {
sub convert_db {
my $self = shift;
my $db = $self->get_db_location();
my $lock = $self->get_db_lock($db) or return DECLINED;
my $tied = $self->get_db_tie($db, $lock) or return DECLINED;
my $db = $self->get_dbm_location();
my $lock = $self->get_dbm_lock($db) or return DECLINED;
my $tied = $self->get_dbm_tie($db, $lock) or return DECLINED;
my $count = keys %$tied;
my $converted = 0;
@ -534,9 +534,9 @@ sub convert_db {
sub prune_db {
my $self = shift;
my $db = $self->get_db_location();
my $lock = $self->get_db_lock($db) or return DECLINED;
my $tied = $self->get_db_tie($db, $lock) or return DECLINED;
my $db = $self->get_dbm_location();
my $lock = $self->get_dbm_lock($db) or return DECLINED;
my $tied = $self->get_dbm_tie($db, $lock) or return DECLINED;
my $count = keys %$tied;
my $pruned = 0;

View File

@ -264,10 +264,10 @@ sub hook_pre_connection {
my $remote_ip = $args{remote_ip};
my $db = $self->get_db_location();
my $lock = $self->get_db_lock($db) or return DECLINED;
my $tied = $self->get_db_tie($db, $lock) or return DECLINED;
my $key = $self->get_db_key($remote_ip) or do {
my $db = $self->get_dbm_location();
my $lock = $self->get_dbm_lock($db) or return DECLINED;
my $tied = $self->get_dbm_tie($db, $lock) or return DECLINED;
my $key = $self->get_karma_key($remote_ip) or do {
$self->log(LOGINFO, "skip, unable to get DB key");
return DECLINED;
};
@ -290,10 +290,10 @@ sub connect_handler {
return DECLINED if $self->is_immune();
my $db = $self->get_db_location();
my $lock = $self->get_db_lock($db) or return DECLINED;
my $tied = $self->get_db_tie($db, $lock) or return DECLINED;
my $key = $self->get_db_key() or do {
my $db = $self->get_dbm_location();
my $lock = $self->get_dbm_lock($db) or return DECLINED;
my $tied = $self->get_dbm_tie($db, $lock) or return DECLINED;
my $key = $self->get_karma_key() or do {
$self->log(LOGINFO, "skip, unable to get DB key");
return DECLINED;
};
@ -414,10 +414,10 @@ sub disconnect_handler {
return DECLINED;
};
my $db = $self->get_db_location();
my $lock = $self->get_db_lock($db) or return DECLINED;
my $tied = $self->get_db_tie($db, $lock) or return DECLINED;
my $key = $self->get_db_key();
my $db = $self->get_dbm_location();
my $lock = $self->get_dbm_lock($db) or return DECLINED;
my $tied = $self->get_dbm_tie($db, $lock) or return DECLINED;
my $key = $self->get_karma_key();
my ($penalty_start_ts, $naughty, $nice, $connects) =
$self->parse_db_record($tied->{$key});
@ -497,7 +497,7 @@ sub cleanup_and_return {
return DECLINED;
}
sub get_db_key {
sub get_karma_key {
my $self = shift;
my $ip = shift || $self->qp->connection->remote_ip;
my $nip = Net::IP->new($ip) or do {
@ -507,7 +507,7 @@ sub get_db_key {
return $nip->intip; # convert IP to an int
}
sub get_db_tie {
sub get_dbm_tie {
my ($self, $db, $lock) = @_;
tie(my %db, 'AnyDBM_File', $db, O_CREAT | O_RDWR, 0600) or do {
@ -518,7 +518,7 @@ sub get_db_tie {
return \%db;
}
sub get_db_location {
sub get_dbm_location {
my $self = shift;
# Setup database location
@ -540,10 +540,10 @@ sub get_db_location {
return $db;
}
sub get_db_lock {
sub get_dbm_lock {
my ($self, $db) = @_;
return $self->get_db_lock_nfs($db) if $self->{_args}{nfslock};
return $self->get_dbm_lock_nfs($db) if $self->{_args}{nfslock};
# Check denysoft db
open(my $lock, ">$db.lock") or do {
@ -560,7 +560,7 @@ sub get_db_lock {
return $lock;
}
sub get_db_lock_nfs {
sub get_dbm_lock_nfs {
my ($self, $db) = @_;
require File::NFSLock;
@ -588,9 +588,9 @@ sub get_db_lock_nfs {
sub prune_db {
my $self = shift;
my $db = $self->get_db_location();
my $lock = $self->get_db_lock($db) or return DECLINED;
my $tied = $self->get_db_tie($db, $lock) or return DECLINED;
my $db = $self->get_dbm_location();
my $lock = $self->get_dbm_lock($db) or return DECLINED;
my $tied = $self->get_dbm_tie($db, $lock) or return DECLINED;
my $count = keys %$tied;
my $pruned = 0;

View File

@ -65,10 +65,10 @@ sub capture {
return;
};
my $db = $self->get_db_location();
my $lock = $self->get_db_lock($db) or return;
my $tied = $self->get_db_tie($db, $lock) or return;
my $key = $self->get_db_key($ip);
my $db = $self->get_dbm_location();
my $lock = $self->get_dbm_lock($db) or return;
my $tied = $self->get_dbm_tie($db, $lock) or return;
my $key = $self->get_karma_key($ip);
my ($penalty_start_ts, $naughty, $nice, $connects) = split /:/,
$tied->{$key};
@ -82,10 +82,10 @@ sub release {
my $ip = shift or return;
is_ip($ip) or do { warn "not an IP: $ip\n"; return; };
my $db = $self->get_db_location();
my $lock = $self->get_db_lock($db) or return;
my $tied = $self->get_db_tie($db, $lock) or return;
my $key = $self->get_db_key($ip);
my $db = $self->get_dbm_location();
my $lock = $self->get_dbm_lock($db) or return;
my $tied = $self->get_dbm_tie($db, $lock) or return;
my $key = $self->get_karma_key($ip);
my ($penalty_start_ts, $naughty, $nice, $connects) = split /:/,
$tied->{$key};
@ -97,10 +97,10 @@ sub release {
sub show_ip {
my $self = shift;
my $ip = shift or return;
my $db = $self->get_db_location();
my $lock = $self->get_db_lock($db) or return;
my $tied = $self->get_db_tie($db, $lock) or return;
my $key = $self->get_db_key($ip);
my $db = $self->get_dbm_location();
my $lock = $self->get_dbm_lock($db) or return;
my $tied = $self->get_dbm_tie($db, $lock) or return;
my $key = $self->get_karma_key($ip);
my ($penalty_start_ts, $naughty, $nice, $connects) = split /:/,
$tied->{$key};
@ -122,9 +122,9 @@ sub show_ip {
sub main {
my $self = shift;
my $db = $self->get_db_location();
my $lock = $self->get_db_lock($db) or return;
my $tied = $self->get_db_tie($db, $lock) or return;
my $db = $self->get_dbm_location();
my $lock = $self->get_dbm_lock($db) or return;
my $tied = $self->get_dbm_tie($db, $lock) or return;
my %totals;
print
@ -182,13 +182,13 @@ sub cleanup_and_return {
close $lock;
}
sub get_db_key {
sub get_karma_key {
my $self = shift;
my $nip = Net::IP->new(shift) or return;
return $nip->intip; # convert IP to an int
}
sub get_db_tie {
sub get_dbm_tie {
my ($self, $db, $lock) = @_;
tie(my %db, 'AnyDBM_File', $db, O_CREAT | O_RDWR, 0600) or do {
@ -199,7 +199,7 @@ sub get_db_tie {
return \%db;
}
sub get_db_location {
sub get_dbm_location {
my $self = shift;
# Setup database location
@ -219,10 +219,10 @@ sub get_db_location {
return $db;
}
sub get_db_lock {
sub get_dbm_lock {
my ($self, $db) = @_;
return $self->get_db_lock_nfs($db) if $self->{_args}{nfslock};
return $self->get_dbm_lock_nfs($db) if $self->{_args}{nfslock};
# Check denysoft db
open(my $lock, ">$db.lock") or do {
@ -239,7 +239,7 @@ sub get_db_lock {
return $lock;
}
sub get_db_lock_nfs {
sub get_dbm_lock_nfs {
my ($self, $db) = @_;
require File::NFSLock;
@ -268,9 +268,9 @@ sub prune_db {
my $self = shift;
my $prune_days = shift;
my $db = $self->get_db_location();
my $lock = $self->get_db_lock($db) or return;
my $tied = $self->get_db_tie($db, $lock) or return;
my $db = $self->get_dbm_location();
my $lock = $self->get_dbm_lock($db) or return;
my $tied = $self->get_dbm_tie($db, $lock) or return;
my $count = keys %$tied;
my $pruned = 0;

View File

@ -18,8 +18,8 @@ sub register_tests {
$self->register_test("test_load_exclude_files");
$self->register_test('test_hook_data');
$self->register_test('test_get_db_key');
$self->register_test('test_get_db_location');
$self->register_test('test_get_greylist_key');
$self->register_test('test_get_dbm_location');
$self->register_test('test_exclude');
$self->register_test("test_greylist_geoip");
$self->register_test("test_greylist_p0f_genre");
@ -100,7 +100,7 @@ sub test_hook_data {
cmp_ok( $code, '==', DECLINED, "missing recipients");
}
sub test_get_db_key {
sub test_get_greylist_key {
my $self = shift;
$self->{_args}{sender} = 0;
@ -114,26 +114,26 @@ sub test_get_db_key {
$self->qp->transaction->add_recipient( $address );
$self->qp->connection->remote_ip($test_ip);
my $key = $self->get_db_key();
my $key = $self->get_greylist_key();
ok( ! $key, "db key empty: -");
$self->{_args}{remote_ip} = 1;
$key = $self->get_db_key( $address, $address );
$key = $self->get_greylist_key( $address, $address );
cmp_ok( $key, 'eq', '3232235777', "db key: $key");
$self->{_args}{sender} = 1;
$key = $self->get_db_key( $address, $address );
$key = $self->get_greylist_key( $address, $address );
cmp_ok( $key, 'eq', "3232235777:$test_email", "db key: $key");
$self->{_args}{recipient} = 1;
$key = $self->get_db_key( $address, $address );
$key = $self->get_greylist_key( $address, $address );
cmp_ok( $key, 'eq', "3232235777:$test_email:$test_email", "db key: $key");
}
sub test_get_db_location {
sub test_get_dbm_location {
my $self = shift;
my $db = $self->get_db_location();
my $db = $self->get_dbm_location();
ok( $db, "db location: $db");
}