You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Doug MacEachern <do...@opengroup.org> on 1997/07/22 00:41:17 UTC

dbmmanage overhaul

I was just going to add the db,ndbm,gdbm search, but I slipped into more:

-tie to AnyDBM_File which will use one of DB_File, NDBM_File or
 GDBM_File (trying each in that order)

-provide much better seed for rand

-add `check' command to check a users' password

-add more descriptive usage

-general cleanup, 'use strict' clean, etc.

The patch is larger than just the code itself, so I've attached it
below for you to consider/try.

-Doug

---
[apache copyright]
package dbmmanage;
#                               -ldb    -lndbm    -lgdbm
BEGIN { @AnyDBM_File::ISA = qw(DB_File NDBM_File GDBM_File) }
use strict;
use Fcntl;
use AnyDBM_File ();

my($file,$command,$key,$value,$group) = @ARGV;

usage() unless $file and $command and defined &{$dbmc::{$command}};

my %DB = ();
my @range = ();
my($mode, $flags) = $command =~ 
    /^(?:view|check)$/ ? (undef, O_RDONLY) : (0644, O_RDWR|O_CREAT);

tie %DB, "AnyDBM_File", $file, $flags, $mode;
dbmc->$command();
untie %DB;

sub usage {
    my $cmds = join "|", sort map { $_ if defined &{$dbmc::{$_}} } keys %dbmc::;
    die "usage: $0 filename [$cmds] [username] [password] [group]\n";
}

sub genseed {
    my $psf;
    for (qw(-xlwwa -le)) { 
	`ps $_ 2>/dev/null`;
	$psf = $_, last unless $?;
    }
    srand (time ^ $$ ^ unpack("%L*", `ps $psf | gzip -f`));
    @range = ('0'..'9','a'..'z','A'..'Z');
}

sub salt {
    genseed() unless @range;
    my $x = int scalar @range;
    return join '', @range[rand($x), rand($x)];
}

sub dbmc::add {
    $DB{$key} = $group ? "$value:$group" : $value;
    print "Entry $key added with value $value.\n";
}

sub dbmc::adduser {
    my $hash = crypt $value, caller->salt;
    $DB{$key} = $group ? "$hash:$group" : $hash;
    print "User $key added with password $value, encrypted to $hash\n";
}

sub dbmc::delete {
    delete $DB{$key} and print "$key deleted\n";
}

sub dbmc::view {
    print $key ? "$key = $DB{$key}\n" : map { "$_ = $DB{$_}\n" if $DB{$_} } keys %DB;
}

sub dbmc::check {
    print crypt($value, $DB{$key}) eq $DB{$key} ? "password ok\n" : "password mismatch\n";
}


Re: dbmmanage overhaul

Posted by Brian Behlendorf <br...@organic.com>.
At 09:13 PM 7/21/97 -0400, you wrote:
>Brian Behlendorf <br...@organic.com> wrote:
>> Since there are now a myriad of dbm file formats, is there any way to
>> distinguish between them when presented with a file of unknown dbm type?
>> I.e. if I have a file called passwd.db, how can I tell whether it's ndbm,
>> gdbm, sdbm, etc?  Could we have that be an option in the dbmmanage program?
>
>I'm not sure of the best (portable) way.  I'll think about it and look
>into Marc's file(1) suggestion.

Mainly I want to make sure no one tries to use ndbm routines on an sdbm
database, etc.  Abstracting those differences would be real nice.

	Brian


--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--
"Why not?" - TL           brian@organic.com - hyperreal.org - apache.org

Re: dbmmanage overhaul

Posted by Dean Gaudet <dg...@arctic.org>.
Hey there's both a dbmmanage and a dbmmanage.new in the tree.  Hmm.  The
tradition at Hotwired would be to name the next one dbmmanage.waynew, not
delete the old ones, and don't provide any docs or links to indicate what
anyone should use.  (Oh yeah and bury a link to one of them in an obscure
file invoked by cron on another machine.)  Erm, just a bad memory
surfacing :) 

Dean

On Mon, 21 Jul 1997, Marc Slemko wrote:

> On Mon, 21 Jul 1997, Brian Behlendorf wrote:
> 
> > 
> > Well I personally liked that fact the old one was still perl 4 compatible,
> > but maybe I'm the only one still in the dark ages with /usr/local/bin/perl
> > = perl4.  At any rate I won't protest it.
> > 
> > Since there are now a myriad of dbm file formats, is there any way to
> > distinguish between them when presented with a file of unknown dbm type?
> > I.e. if I have a file called passwd.db, how can I tell whether it's ndbm,
> > gdbm, sdbm, etc?  Could we have that be an option in the dbmmanage program?
> 
> file(1) works.  <g>  
> 
> pagetabl.db: Berkeley DB Hash file (Version 2, Little Endian, Bucket Size
> 4096, Directory Size 12, Segment Size 256, Segment Shift 256, Overflow Point 8, Last Freed 3, Max Bucket 2, High Mask 0x6, Low Mask 0x7, Fill Factor 3, Number of Keys 40)
> 
> 


Re: dbmmanage overhaul

Posted by Marc Slemko <ma...@worldgate.com>.
On Mon, 21 Jul 1997, Brian Behlendorf wrote:

> 
> Well I personally liked that fact the old one was still perl 4 compatible,
> but maybe I'm the only one still in the dark ages with /usr/local/bin/perl
> = perl4.  At any rate I won't protest it.
> 
> Since there are now a myriad of dbm file formats, is there any way to
> distinguish between them when presented with a file of unknown dbm type?
> I.e. if I have a file called passwd.db, how can I tell whether it's ndbm,
> gdbm, sdbm, etc?  Could we have that be an option in the dbmmanage program?

file(1) works.  <g>  

pagetabl.db: Berkeley DB Hash file (Version 2, Little Endian, Bucket Size
4096, Directory Size 12, Segment Size 256, Segment Shift 256, Overflow Point 8, Last Freed 3, Max Bucket 2, High Mask 0x6, Low Mask 0x7, Fill Factor 3, Number of Keys 40)


Re: dbmmanage overhaul

Posted by Brian Behlendorf <br...@organic.com>.
Well I personally liked that fact the old one was still perl 4 compatible,
but maybe I'm the only one still in the dark ages with /usr/local/bin/perl
= perl4.  At any rate I won't protest it.

Since there are now a myriad of dbm file formats, is there any way to
distinguish between them when presented with a file of unknown dbm type?
I.e. if I have a file called passwd.db, how can I tell whether it's ndbm,
gdbm, sdbm, etc?  Could we have that be an option in the dbmmanage program?

	Brian


--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--
"Why not?" - TL           brian@organic.com - hyperreal.org - apache.org