line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: DBM.pm,v 1.1.1.1 2001/02/20 03:33:50 lstein Exp $ |
2
|
|
|
|
|
|
|
package HTTPD::UserAdmin::DBM; |
3
|
2
|
|
|
2
|
|
9
|
use HTTPD::UserAdmin (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
40
|
|
4
|
2
|
|
|
2
|
|
8
|
use Carp (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
45
|
|
5
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
62
|
|
6
|
2
|
|
|
2
|
|
13
|
use vars qw(@ISA $VERSION); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1792
|
|
7
|
|
|
|
|
|
|
@ISA = qw(HTTPD::UserAdmin); |
8
|
|
|
|
|
|
|
$VERSION = (qw$Revision: 1.1.1.1 $)[1]; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my %Default = (PATH => ".", |
11
|
|
|
|
|
|
|
DB => ".htpasswd", |
12
|
|
|
|
|
|
|
DBMF => "NDBM", |
13
|
|
|
|
|
|
|
FLAGS => "rwc", |
14
|
|
|
|
|
|
|
MODE => 0644, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
0
|
|
|
0
|
1
|
0
|
my($class) = shift; |
19
|
0
|
|
|
|
|
0
|
my $self = bless { %Default, @_ } => $class; |
20
|
0
|
|
|
|
|
0
|
$self->_dbm_init; |
21
|
0
|
|
|
|
|
0
|
$self->db($self->{DB}); |
22
|
0
|
|
|
|
|
0
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub DESTROY { |
26
|
2
|
|
|
2
|
|
17
|
local($^W)=0; |
27
|
2
|
|
|
|
|
13
|
$_[0]->_untie('_HASH'); |
28
|
2
|
|
|
|
|
18
|
$_[0]->unlock; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub add { |
32
|
3
|
|
|
3
|
1
|
6
|
my($self, $user, $passwd, @rest) = @_; |
33
|
3
|
50
|
|
|
|
8
|
return(0, "add_user: no user name!") unless $user; |
34
|
3
|
50
|
|
|
|
5
|
return(0, "add_user: no password!") unless $passwd; |
35
|
3
|
50
|
|
|
|
7
|
return(0, "user '$user' exists in $self->{DB}") |
36
|
|
|
|
|
|
|
if $self->exists($user); |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
7
|
local($^W) = 0; #shutup uninit warnings |
39
|
3
|
50
|
|
|
|
10
|
if (ref($rest[0]) eq 'HASH') { |
40
|
3
|
|
|
|
|
3
|
my $f = $rest[0]; |
41
|
3
|
|
|
|
|
4
|
@rest = (); |
42
|
3
|
|
|
|
|
4
|
foreach (keys %{$f}) { push(@rest,"$_="._escape($f->{$_})); } |
|
3
|
|
|
|
|
10
|
|
|
9
|
|
|
|
|
19
|
|
43
|
|
|
|
|
|
|
} |
44
|
3
|
|
|
|
|
10
|
my $dlm = ":"; |
45
|
3
|
50
|
|
|
|
8
|
$dlm = $self->{DLM} if defined $self->{DLM}; |
46
|
3
|
|
|
|
|
15
|
my $pass = $self->encrypt($passwd); |
47
|
3
|
50
|
|
|
|
18
|
$self->{'_HASH'}{$user} = $pass . (@rest ? ($dlm . join($dlm,@rest)) : ""); |
48
|
3
|
|
|
|
|
12
|
1; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub fetch { |
52
|
1
|
|
|
1
|
1
|
3
|
my($self,$username,@fields) = @_; |
53
|
1
|
50
|
|
|
|
3
|
return(0, "fetch: no user name!") unless $username; |
54
|
1
|
50
|
|
|
|
15
|
return(0, "fetch: user '$username' doesn't exist") |
55
|
|
|
|
|
|
|
unless my $val = $self->exists($username); |
56
|
1
|
|
|
|
|
2
|
my (%f); |
57
|
1
|
|
|
|
|
2
|
foreach (@fields) { |
58
|
4
|
50
|
|
|
|
16
|
grep($f{$_}++,ref($_) ? @$_ : $_); |
59
|
|
|
|
|
|
|
} |
60
|
1
|
|
|
|
|
5
|
my(@bits) = split(':',$val); |
61
|
1
|
50
|
|
|
|
4
|
if ($self->{ENCRYPT} eq 'MD5') { |
62
|
0
|
|
|
|
|
0
|
splice(@bits,0,3); |
63
|
|
|
|
|
|
|
} else { |
64
|
1
|
|
|
|
|
2
|
shift(@bits); |
65
|
|
|
|
|
|
|
} |
66
|
1
|
|
|
|
|
2
|
my %r; |
67
|
1
|
|
|
|
|
2
|
foreach (@bits) { |
68
|
3
|
|
|
|
|
8
|
my($n,$v) = split('='); |
69
|
3
|
50
|
|
|
|
12
|
$r{$n}=_unescape($v) if $f{$n}; |
70
|
|
|
|
|
|
|
} |
71
|
1
|
|
|
|
|
9
|
return \%r; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Extended _escape to process control characters too [CJD] |
75
|
|
|
|
|
|
|
# sub _escape { $_=shift; s/([,=:])/uc sprintf("%%%02x",ord($1))/ge; return $_; } |
76
|
9
|
|
|
9
|
|
10
|
sub _escape { $_=shift; s/([\000-\037,=:%])/uc sprintf("%%%02x",ord($1))/ge; return $_; } |
|
9
|
|
|
|
|
13
|
|
|
0
|
|
|
|
|
0
|
|
|
9
|
|
|
|
|
20
|
|
77
|
3
|
|
|
3
|
|
10
|
sub _unescape { $_=shift; s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; return $_; } |
|
3
|
|
|
|
|
5
|
|
|
0
|
|
|
|
|
0
|
|
|
3
|
|
|
|
|
9
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
package HTTPD::UserAdmin::DBM::_generic; |
80
|
2
|
|
|
2
|
|
14
|
use vars qw(@ISA); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
166
|
|
81
|
|
|
|
|
|
|
@ISA = qw(HTTPD::UserAdmin::DBM HTTPD::UserAdmin); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |