]> granicus.if.org Git - apache/commitdiff
Overhaul of dbmmanage to allow a groups arg (as in Apache 1.2)
authorWilliam A. Rowe Jr <wrowe@apache.org>
Wed, 20 Sep 2000 20:09:59 +0000 (20:09 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Wed, 20 Sep 2000 20:09:59 +0000 (20:09 +0000)
     as well as a comment arg to the add, adduser and update cmds.
     update allows the user to clear or preserve pw/groups/comment.
     Fixed a bug in dbmmanage that prevented the check option from
     parsing a password followed by :group... text.  Corrected the
     seed calcualation for Win32 systems, and added -lsdbm support.
     PR: 3810, 5527

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@86268 13f79535-47bb-0310-9956-ffa450edef68

support/dbmmanage

index da6852761e75ba7861c09d7d3f7e3ae48c0916f4..061749600902ec071d31230765e4c53be68ff86c 100644 (file)
@@ -68,7 +68,7 @@ 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}};
 
@@ -98,17 +98,33 @@ untie %DB;
 
 sub usage {
     my $cmds = join "|", sort keys %dbmc::;
-    die "usage: $0 filename [$cmds] [username]\n";
+    die <<SYNTAX;
+Usage: dbmmanage dbname command [username [pw [group[,group] [comment]]]]
+
+    where command is one of: $cmds
+
+    pw of . for update retains the old password
+    pw of - (or blank) for update prompts for the password
+
+    groups or comment of . (or blank) for update retains old values
+    groups or comment of - for update clears the existing value
+    groups or comment of - for add or adduser is an empty value
+SYNTAX
 }
 
 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)));
+    }
+    else {
+        for (qw(-xlwwa -le)) { 
+           `ps $_ 2>/dev/null`;
+            $psf = $_, last unless $?;
+        }
+        srand (time ^ $$ ^ unpack("%L*", `ps $psf | gzip -f`));
     }
-    srand (time ^ $$ ^ unpack("%L*", `ps $psf | gzip -f`));
     @range = (qw(. /), '0'..'9','a'..'z','A'..'Z');
     $x = int scalar @range;
 }
@@ -147,7 +163,15 @@ sub getpass {
 
 sub dbmc::update {
     die "Sorry, user `$key' doesn't exist!\n" unless $DB{$key};
-    dbmc->adduser;
+    $crypted_pwd = (split /:/, $DB{$key}, 4)[0] if $crypted_pwd eq '.';
+    $groups = (split /:/, $DB{$key}, 4)[1] if !$groups || $groups eq '.';
+    $comment = (split /:/, $DB{$key}, 4)[2] if !$comment || $comment eq '.';
+    if (!$crypted_pwd || $crypted_pwd eq '-') {
+        dbmc->adduser;
+    }
+    else {
+        dbmc->add;
+    }
 }
 
 sub dbmc::add {
@@ -155,6 +179,10 @@ sub dbmc::add {
     unless($is_update) {
        die "Sorry, user `$key' already exists!\n" if $DB{$key};
     }
+    $groups = '' if $groups eq '-';
+    $comment = '' if $comment eq '-';
+    $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";
@@ -178,13 +206,13 @@ sub dbmc::view {
 
 sub dbmc::check {
     die "Sorry, user `$key' doesn't exist!\n" unless $DB{$key};
-    my $chkpass = (split /:/, $DB{$key})[0];
+    my $chkpass = (split /:/, $DB{$key},4)[0];
     print crypt(getpass(), $chkpass) eq $chkpass ? "password ok\n" : "password mismatch\n";
 }
 
 sub dbmc::import {
     while(defined($_ = <STDIN>) and chomp) {
-       ($key,$crypted_pwd) = split /:/, $_, 2;
+       ($key,$crypted_pwd,$groups,$comment) = split /:/, $_, 4;
        dbmc->add;
     }
 }