httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug MacEachern <do...@opengroup.org>
Subject dbmmanage overhaul
Date Mon, 21 Jul 1997 22:41:17 GMT
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";
}


Mime
View raw message