httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "William A. Rowe, Jr." <wr...@rowe-clan.net>
Subject [patch] dbmmanage
Date Tue, 19 Sep 2000 19:52:33 GMT
Here's my little contribution to something I know next to nothing about.

Doesn't include the MD5 I inquired about.  Is this worthwhile?

--- e:\apache\apache-1.3\src\support\dbmmanage	Sun Nov 28 07:37:54 1999
+++ dbmmanage	Tue Sep 19 14:46:34 2000
@@ -61,13 +61,13 @@
 # usage: dbmmanage <DBMfile> <command> <key> <value>
 
 package dbmmanage;
-#                               -ldb    -lndbm    -lgdbm
-BEGIN { @AnyDBM_File::ISA = qw(DB_File NDBM_File GDBM_File) }
+#                               -ldb    -lndbm    -lgdbm    -lsdbm
+BEGIN { @AnyDBM_File::ISA = qw(DB_File NDBM_File GDBM_File SDBM_File) }
 use strict;
 use Fcntl;
 use AnyDBM_File ();
 
-my($file,$command,$key,$crypted_pwd) = @ARGV;
+my($file,$command,$key,$crypted_pwd,$groups,$comment) = @ARGV;
 
 usage() unless $file and $command and defined &{$dbmc::{$command}};
 
@@ -84,7 +84,7 @@
 my $chop = join '|', qw{db.? pag dir};
 $file =~ s/\.($chop)$//;
 
-my $is_update = $command eq "update";
+my $is_update = (substr($command,0,6) eq "update");
 my $Is_Win32  = $^O eq "MSWin32"; 
 my %DB = ();
 my @range = ();
@@ -97,17 +97,22 @@
 
 sub usage {
     my $cmds = join "|", sort keys %dbmc::;
-    die "usage: $0 filename [$cmds] [username]\n";
+    die "usage: $0 filename [$cmds] [username] [pw] [group[,group]] [comment]\n";
 }
 
 my $x;
 sub genseed {
     my $psf;
-    for (qw(-xlwwa -le)) { 
-	`ps $_ 2>/dev/null`;
-	$psf = $_, last unless $?;
+    if ($Is_Win32) {
+        srand (time ^ $$ or time ^ ($$ + ($$ << 15)));
     }
-    srand (time ^ $$ ^ unpack("%L*", `ps $psf | gzip -f`));
+    else {
+        for (qw(-xlwwa -le)) { 
+	    `ps $_ 2>/dev/null`;
+            $psf = $_, last unless $?;
+        }
+        srand (time ^ $$ ^ unpack("%L*", `ps $psf | gzip -f`));
+    }
     @range = (qw(. /), '0'..'9','a'..'z','A'..'Z');
     $x = int scalar @range;
 }
@@ -149,11 +154,34 @@
     dbmc->adduser;
 }
 
+sub dbmc::updatepw {
+    die "Sorry, user `$key' doesn't exist!\n" unless $DB{$key};
+    $groups = (split(":", $DB{$key}))[1];
+    $comment = (split(":", $DB{$key}))[2];
+    dbmc->adduser;
+}
+
+sub dbmc::updategroups {
+    die "Sorry, user `$key' doesn't exist!\n" unless $DB{$key};
+    $crypted_pwd = (split(":", $DB{$key}))[0];
+    $comment = (split(":", $DB{$key}))[2];
+    dbmc->add;
+}
+
+sub dbmc::updatecomment {
+    die "Sorry, user `$key' doesn't exist!\n" unless $DB{$key};
+    $crypted_pwd = (split(":", $DB{$key}))[0];
+    $groups = (split(":", $DB{$key}))[1];
+    dbmc->add;
+}
+
 sub dbmc::add {
     die "Can't use empty password!\n" unless $crypted_pwd;
     unless($is_update) {
 	die "Sorry, user `$key' already exists!\n" if $DB{$key};
     }
+    $groups .= ":" . $comment if $comment;
+    $crypted_pwd .= ":" . $groups if $groups;
     $DB{$key} = $crypted_pwd;
     my $action = $is_update ? "updated" : "added";
     print "User $key $action with password encrypted to $DB{$key}\n";
@@ -176,8 +204,10 @@
 }
 
 sub dbmc::check {
+    my $chkpass;
     die "Sorry, user `$key' doesn't exist!\n" unless $DB{$key};
-    print crypt(getpass(), $DB{$key}) eq $DB{$key} ? "password ok\n" : "password mismatch\n";
+    $chkpass = (split(":", $DB{$key}))[0];
+    print crypt(getpass(), $chkpass) eq $chkpass ? "password ok\n" : "password mismatch\n";
 }
 
 sub dbmc::import {


Mime
View raw message