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

We have a little *BSD box here that we are no longer getting support for. Among other things it is our SMTP gateway using Sendmail. I have the task of reverse-enbineering the alias file for it (it is built directly from a database that we do not have access too).

I wrote this;

#!/usr/bin/perl -w use DB_File; use strict; my %DB; my $key; my $val; tie (%DB, "DB_File", "./igusers.db", O_RDONLY, 0644, $DB_HASH); while (($key, $val) = each %DB) { print "$key = $val2\n"; } untie(%DB);
In hopes of it being simple. Ofcourse it is not... A sample of the output from $val looks like this;
mat071 = Ômat071*mat071ex group dlÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ +ÿÿÿÿÿÿÿÿÿÿÿÿexchforwardÿÿÿÿÿÿÿÿ¡ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
From there I tried;
#!/usr/bin/perl -w use DB_File; use strict; my %DB; my $key; my $val; my $val2; tie (%DB, "DB_File", "./igusers.db", O_RDONLY, 0644, $DB_HASH); while (($key, $val) = each %DB) { $val2 = ref($val); print "$key = $val2\n"; } untie(%DB);
but then $val2 has nothing in it. Can someone kick me in the butt and let me know what I am doing wrong here.

Thanks,

Kahn

Replies are listed 'Best First'.
Re: Reverse-Engineering sendmails alias file
by tadman (Prior) on Nov 08, 2002 at 20:04 UTC
    If $val2 is a regular scalar, then ref($val2) will return undef since it is not blessed. Makes perfect sense, right?

    I'm not sure why you have a ref call in there.

    You might also have made a mistake in your first loop. $val declared in your loop, $val2 used in your print. You should have got a warning.
Re: Reverse-Engineering sendmails alias file
by iburrell (Chaplain) on Nov 08, 2002 at 21:07 UTC
    Did you try makemap -u hash igusers.db? On some systems, it will dump out the contents of the database. Also, check that the file is a Berkeley DB database and that the version of the library is the same. The file format has changed with newer versions. From the sendmail maps that I looked at, they are standard key to value maps with no binary format.

    Your first code shouldn't work. $val2 isn't defined anywhere but I bet that is a typo in your posting. The second won't work because $val isn't a reference. Even if it was a reference, ref doesn't dereference it, it returns the type.

      Another way as well would be the 'db_dump -p ./igusers.db'.
      db_dump comes with berkeley db and should be under INSTALL_ROOT/bin.

      /* And the Creator, against his better judgement, wrote man.c */
Re: Reverse-Engineering sendmails alias file
by traveler (Parson) on Nov 08, 2002 at 20:57 UTC
    I know this is not a perl solution, but if you get desprate: you might consider hacking the postfix postalias(1) command. Postfix can access db, dbm and btree files so it should be able to help.

    Once you figure it out, you could enhance Mail::Alias :-)

    HTH, --traveler