On Thu, Mar 20, 2003 at 02:16:29AM -0800, Ask Bjoern Hansen wrote: > Patches to make plugins/check_relay read the cdb file would be > gladly accepted.
I wrote most of one a while back before getting sidetracked. Never finished it, but here it is. It's implemented as a plugin which hooks config. -- Devin \ aqua(at)devin.com, 1024D/E9ABFCD2; http://www.devin.com Carraway \ IRC: Requiem GCS/CC/L s-:--- !a !tv C++++$ ULB+++$ O+@ P L+++
# $Id$
sub register {
my $self = shift;
$self->register_hook('config', 'map_config');
}
sub map_config {
my $self = shift;
my ($transaction, $var, $type) = @_;
return DECLINED unless $type and $type eq 'map';
my $workdir = ($0 =~ m:(.*)/[^/]+$:);
for my $cfdir ($workdir.'/config', '/var/qmail/control') {
for my $m ('cdb', 'db', 'gdbm') {
my $fn = $cfdir.'/'.$var;
$m = 'read_'.$m;
return $self->$m($fn) if -e $fn;
}
}
return DECLINED;
}
sub read_cdb {
my $fn = shift || return DECLINED;
my %h;
eval "use CDB_File";
unless (tie(%h, 'CDB_File', $fn)) {
$self->log(0, "$fn: $!");
return DECLINED;
}
(OK,\%h);
}
sub read_db {
my $fn = shift || return DECLINED;
my %h;
eval "use DB_File; use Fcntl";
unless (tie(%h, 'DB_File', $fn, O_RDONLY, 0)) {
$self->log(0, "$fn: $!");
return DECLINED;
}
(OK, \%h);
}
sub read_gdbm {
my $fn = shift || return DECLINED;
my %h;
eval "use GDBM_File";
unless (tie(%h, 'GDBM_File', $fn, GDBM_READER, 0)) {
$self->log(0, "$fn: $!");
return DECLINED;
}
(OK, \%h);
}
pgp00000.pgp
Description: PGP signature
