3 # ====================================================================
4 # Copyright (c) 1995-1999 The Apache Group. All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in
15 # the documentation and/or other materials provided with the
18 # 3. All advertising materials mentioning features or use of this
19 # software must display the following acknowledgment:
20 # "This product includes software developed by the Apache Group
21 # for use in the Apache HTTP server project (http://www.apache.org/)."
23 # 4. The names "Apache Server" and "Apache Group" must not be used to
24 # endorse or promote products derived from this software without
25 # prior written permission. For written permission, please contact
28 # 5. Products derived from this software may not be called "Apache"
29 # nor may "Apache" appear in their names without prior written
30 # permission of the Apache Group.
32 # 6. Redistributions of any form whatsoever must retain the following
34 # "This product includes software developed by the Apache Group
35 # for use in the Apache HTTP server project (http://www.apache.org/)."
37 # THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
38 # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
41 # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48 # OF THE POSSIBILITY OF SUCH DAMAGE.
49 # ====================================================================
51 # This software consists of voluntary contributions made by many
52 # individuals on behalf of the Apache Group and was originally based
53 # on public domain software written at the National Center for
54 # Supercomputing Applications, University of Illinois, Urbana-Champaign.
55 # For more information on the Apache Group and the Apache HTTP server
56 # project, please see <http://www.apache.org/>.
58 #for more functionality see the HTTPD::UserAdmin module:
59 # http://www.perl.com/CPAN/modules/by-module/HTTPD/HTTPD-Tools-x.xx.tar.gz
61 # usage: dbmmanage <DBMfile> <command> <key> <value>
65 BEGIN { @AnyDBM_File::ISA = qw(DB_File NDBM_File GDBM_File) }
70 my($file,$command,$key,$crypted_pwd) = @ARGV;
72 usage() unless $file and $command and defined &{$dbmc::{$command}};
74 # if your osname is in $newstyle_salt, then use new style salt (starts with '_' and contains
75 # four bytes of iteration count and four bytes of salt). Otherwise, just use
76 # the traditional two-byte salt.
77 # see the man page on your system to decide if you have a newer crypt() lib.
78 # I believe that 4.4BSD derived systems do (at least BSD/OS 2.0 does).
79 # The new style crypt() allows up to 20 characters of the password to be
80 # significant rather than only 8.
81 my $newstyle_salt = join '|', qw{bsdos}; #others?
83 # remove extension if any
84 my $chop = join '|', qw{db.? pag dir};
85 $file =~ s/\.($chop)$//;
87 my $is_update = $command eq "update";
88 my $Is_Win32 = $^O eq "MSWin32";
91 my($mode, $flags) = $command =~
92 /^(?:view|check)$/ ? (0644, O_RDONLY) : (0644, O_RDWR|O_CREAT);
94 tie %DB, "AnyDBM_File", $file, $flags, $mode || die "Can't tie $file: $!";
99 my $cmds = join "|", sort keys %dbmc::;
100 die "usage: $0 filename [$cmds] [username]\n";
106 for (qw(-xlwwa -le)) {
108 $psf = $_, last unless $?;
110 srand (time ^ $$ ^ unpack("%L*", `ps $psf | gzip -f`));
111 @range = (qw(. /), '0'..'9','a'..'z','A'..'Z');
112 $x = int scalar @range;
116 join '', map $range[rand $x], 1..shift||1;
120 my $newstyle = $^O =~ /(?:$newstyle_salt)/;
121 genseed() unless @range;
123 join '', "_", randchar, "a..", randchar(4) :
128 my $prompt = shift || "Enter password:";
131 open STDIN, "/dev/tty" or warn "couldn't open /dev/tty $!\n";
132 system "stty -echo;";
136 print STDERR $prompt;
137 while (($c = getc(STDIN)) ne '' and $c ne "\n" and $c ne "\r") {
141 system "stty echo" unless $Is_Win32;
143 die "Can't use empty password!\n" unless length $pwd;
148 die "Sorry, user `$key' doesn't exist!\n" unless $DB{$key};
153 die "Can't use empty password!\n" unless $crypted_pwd;
155 die "Sorry, user `$key' already exists!\n" if $DB{$key};
157 $DB{$key} = $crypted_pwd;
158 my $action = $is_update ? "updated" : "added";
159 print "User $key $action with password encrypted to $DB{$key}\n";
163 my $value = getpass "New password:";
164 die "They don't match, sorry.\n" unless getpass("Re-type new password:") eq $value;
165 $crypted_pwd = crypt $value, caller->salt;
170 die "Sorry, user `$key' doesn't exist!\n" unless $DB{$key};
171 delete $DB{$key}, print "`$key' deleted\n";
175 print $key ? "$key:$DB{$key}\n" : map { "$_:$DB{$_}\n" if $DB{$_} } keys %DB;
179 die "Sorry, user `$key' doesn't exist!\n" unless $DB{$key};
180 print crypt(getpass(), $DB{$key}) eq $DB{$key} ? "password ok\n" : "password mismatch\n";
184 while(defined($_ = <STDIN>) and chomp) {
185 ($key,$crypted_pwd) = split /:/, $_, 2;