[Mimedefang] Silly perl error, PEBCAK, or something odd with MD?

Kris Deugau kdeugau at webhart.net
Fri Oct 3 19:52:02 EDT 2003


I'm using filter_recipient to reject invalid recipients for virtual
domains.  For a variety of legacy reasons, the setup I'm starting with
blindly accepts all email for all valid accounts.  When I first set it
up, I thought I had blocked that.  :(

In filter_recipient, I use a tied hash db file to verify the users, and
I'll eventually use another to decide whether to check for a valid user
(in the case of hosted domains) or just continue (for outbound mail
relay) and I've set it up so that I can use it to determine whether to
runs spamscans or AV scans on a per-domain basis as well.

I use the following to do the check (I've removed some other checks I do
first).  Note the commented if statements;  they didn't solve the
problem I'm seeing:

# near start of mimedefang-filter
require DB_File;
tie %validusers, "DB_File", "/etc/mail/validusers.db";
tie %domainlist, "DB_File", "/etc/mail/hosteddomains.db";


sub filter_recipient {
  my ($recip, $sender, $ip, $host, $first, $helo, $rcpt_mailer,
$rcpt_host, $rcpt_addr) = @_;

  $recip =~ s/\>//;
  $recip =~ s/\<//;
  ($user,$domain) = split /\@/, $recip;
  if ($domain =~ /^webhart.deepnet.cx$/) {
#  if ($domain eq "^webhart.deepnet.cx") {
md_syslog("info", "checking $domain for $user");
#if ($domainlist{$domain}) {
    if ($validusers{"$user.$domain"} =~ /^OK$/) {
#    if ($validusers{"$user.$domain"} eq "OK") {
      return ('CONTINUE',"ok");
    } else {
      return ('REJECT', "$recip is not a valid recipient address");
    }
  } else {
    return ('CONTINUE',"Email not to test domain OK");
#    return ('CONTINUE',"Email not to hosted domain OK");
  }
}

I've (very carefully) checked that the tied hashes are compatible (I
create them with a perl script that uses DB_File explicitly.  (Although
I have found that makemap creates effectively identical files (identical
in type according to file) once you convince it to actually process the
plaintext file. :/  )

I'm seeing "Slave 0 stderr: Use of uninitialized value in pattern m
atch (m//) at /etc/mail/mimedefang-filter line 161, <STDIN> line 5." log
messages every time it hits either if statement- in a consistently
inconsistent way.

-> If the first if uses ($domain eq "webhart.deepnet.cx"), it happens. 
Er...  OK...  What uninitialized value?  $domain is derived from $recip,
and the md_syslog statement produces the correct result in the log
("checking webhart.deepnet.cx for testuser" if I had tested with rcpt
to:testuser at webhart.deepnet.cx).

-> If the first if uses ($domain =~ /^webhart.deepnet.cx$/), it does NOT
happen...  but the message then comes up with the second if statement,
where I actually check the tied hash.

In the second if statement, it again errors out if I use eq... but it
also errors out with the regex form, and in either case returns a
REJECT.

I can't figure out what might be "unintialized" in the first if
statement, comparing to a bare string;  and while I can see that it
might cause the error on the second if when the user doesn't exist, I
can't figure out why it's happening when the user *does* exist in the
file.

The tied hash files are currently in /etc/mail (makemap errors out with
"makemap: error opening type hash map domainlist: Permission denied"
anywhere else, and the perl I hacked together to create the hashes
originally isn't smart enough to delete existing data before stuffing
data in- I may have to expand it.)

I've apparently misinterpreted *something*, *somewhere*, but I'm not
sure what.

-kgd
-- 
<erno> hm. I've lost a machine.. literally _lost_. it responds to
ping, it works completely, I just can't figure out where in my
apartment it is.



More information about the MIMEDefang mailing list