Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Reading Sendmail .db files

by Maddingue (Sexton)
on Nov 22, 2004 at 17:17 UTC ( #409653=perlquestion: print w/replies, xml ) Need Help??

Maddingue has asked for the wisdom of the Perl Monks concerning the following question:

Hello all, As I am trying to debug a quite hairy Sendmail problem, I'd like to read its virtuser.db (it's the DB for virtual users). Searching CPAN a module to read Berkeley databases, I found BerkeleyDB and wrote this little script:
#!/usr/bin/perl use BerkeleyDB; my $file = shift || die "usage: $0 file"; %hash = (); my $db = tie %hash, 'BerkeleyDB::Hash', -Filename => $file, -Flags => DB_RDONLY, -Property => DB_DUP | DB_DUPSORT or die "can't read file '$file': $!"; my $ref = $db->db_stat; print "db info: \n", map{" - ${_}: ".$ref->{$_}.$/} keys %$ref; print "db contains ", scalar(keys %hash), " entries\n"; print map { " $_ => $hash{$_}\n" } sort keys %hash;
The script fails at the tie() but with no error in $! Then I tried with DB_File, and wrote this script:
#!/usr/bin/perl use DB_File; my $file = shift || die "usage: $0 file"; %hash = (); tie %hash, 'DB_File', $file, O_RDONLY, 0666, DB_HASH or die "can't read file '$file': $!"; print "$file has ", scalar(keys %hash), " entries\n"; print map { " $_ => $hash{$_}\n" } sort keys %hash;
which also fails with the following error:
type parameter is not a reference at /usr/lib/perl5/5.6.1/i386-linux +/ line 262.
So.. my question is: if anyone has an experience with one of these modules, or with Sendmail .db files, or best, already has a script that dump the content of a Berkeley DB in human readable form, I'm all for it! (I know dbdump included with BerkeleyDB, but it does not dump the content in human readable form). Thanks in advance for anyone who has an idea

Replies are listed 'Best First'.
Re: Reading Sendmail .db files
by waswas-fng (Curate) on Nov 22, 2004 at 19:46 UTC
    Try makemap...

    makemap -u hash access.db
    Will dump a HASH type sendmail db to plaintext, you could also use btree instead. And then you can recreate the map from the text source file:
    makemap hash access.db < access.txt

      Oh thanks, that works. Although I'd still like to know why the Perl scripts (and the short C program) I wrote didn't work. Are the .db files Sendmail create so special that another program can't read them? But, thank you very much for the command, I didn't know the -u option of makemap. At least I can see the content of its db and check what is inside.

        With regard to BerkelyDB => RTFM. You can't just make syntax up and expect it to work. This works fine.....

        [root@www mail]# cat #!/usr/bin/perl use BerkeleyDB; tie %hash, 'BerkeleyDB::Hash', -Filename => $ARGV[0] or die "can't read file '$ARGV[0]': $!"; print map { " $_ => $hash{$_}\n" } sort keys %hash; [root@www mail]# ./ virtusertable.db => [snip]

        With regard to your second example, once again you need to RTFM. You have a syntax error in that DB_HASH is a $PERL_SCALAR not a constant as you assume. I would agree with your C style brain that it should logically be a constant but I did not design the interface.....

        tie %hash, 'DB_File', $file, O_RDONLY, 0666, $DB_HASH



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://409653]
Approved by Paladin
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2020-11-30 17:23 GMT
Find Nodes?
    Voting Booth?

    No recent polls found