line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: DBM.pm,v 1.1.1.1 2004/06/28 19:24:28 veselosky Exp $ |
2
|
|
|
|
|
|
|
package CGI::Builder::Auth::UserAdmin::DBM; |
3
|
5
|
|
|
5
|
|
26
|
use CGI::Builder::Auth::UserAdmin (); |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
124
|
|
4
|
5
|
|
|
5
|
|
25
|
use Carp (); |
|
5
|
|
|
|
|
59
|
|
|
5
|
|
|
|
|
105
|
|
5
|
5
|
|
|
5
|
|
24
|
use strict; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
174
|
|
6
|
5
|
|
|
5
|
|
24
|
use vars qw(@ISA $VERSION); |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
4057
|
|
7
|
|
|
|
|
|
|
@ISA = qw(CGI::Builder::Auth::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
|
20
|
|
|
20
|
|
136
|
local($^W)=0; |
27
|
20
|
|
|
|
|
103
|
$_[0]->_untie('_HASH'); |
28
|
20
|
|
|
|
|
104
|
$_[0]->unlock; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub add { |
32
|
9
|
|
|
9
|
1
|
169
|
my($self, $user, $passwd, @rest) = @_; |
33
|
9
|
50
|
|
|
|
70
|
return(0, "add_user: no user name!") unless $user; |
34
|
9
|
50
|
|
|
|
30
|
return(0, "add_user: no password!") unless defined($passwd); |
35
|
9
|
50
|
|
|
|
33
|
return(0, "user '$user' exists in $self->{DB}") |
36
|
|
|
|
|
|
|
if $self->exists($user); |
37
|
|
|
|
|
|
|
|
38
|
9
|
|
|
|
|
37
|
local($^W) = 0; #shutup uninit warnings |
39
|
9
|
50
|
|
|
|
29
|
if (ref($rest[0]) eq 'HASH') { |
40
|
9
|
|
|
|
|
15
|
my $f = $rest[0]; |
41
|
9
|
|
|
|
|
137
|
@rest = (); |
42
|
9
|
|
|
|
|
13
|
foreach (keys %{$f}) { push(@rest,"$_="._escape($f->{$_})); } |
|
9
|
|
|
|
|
36
|
|
|
9
|
|
|
|
|
22
|
|
43
|
|
|
|
|
|
|
} |
44
|
9
|
|
|
|
|
18
|
my $dlm = ":"; |
45
|
9
|
50
|
|
|
|
29
|
$dlm = $self->{DLM} if defined $self->{DLM}; |
46
|
9
|
|
|
|
|
57
|
my $pass = $self->encrypt($passwd); |
47
|
9
|
100
|
|
|
|
52
|
$self->{'_HASH'}{$user} = $pass . (@rest ? ($dlm . join($dlm,@rest)) : ""); |
48
|
9
|
|
|
|
|
65
|
1; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub fetch { |
52
|
1
|
|
|
1
|
1
|
9
|
my($self,$username,@fields) = @_; |
53
|
1
|
50
|
|
|
|
7
|
return(0, "fetch: no user name!") unless $username; |
54
|
1
|
50
|
|
|
|
4
|
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
|
|
|
|
25
|
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
|
|
|
|
|
1
|
my %r; |
67
|
1
|
|
|
|
|
3
|
foreach (@bits) { |
68
|
3
|
|
|
|
|
8
|
my($n,$v) = split('='); |
69
|
3
|
50
|
|
|
|
11
|
$r{$n}=_unescape($v) if $f{$n}; |
70
|
|
|
|
|
|
|
} |
71
|
1
|
|
|
|
|
7
|
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
|
|
9
|
sub _escape { $_=shift; s/([\000-\037,=:%])/uc sprintf("%%%02x",ord($1))/ge; return $_; } |
|
9
|
|
|
|
|
18
|
|
|
0
|
|
|
|
|
0
|
|
|
9
|
|
|
|
|
24
|
|
77
|
3
|
|
|
3
|
|
6
|
sub _unescape { $_=shift; s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; return $_; } |
|
3
|
|
|
|
|
6
|
|
|
0
|
|
|
|
|
0
|
|
|
3
|
|
|
|
|
7
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
package CGI::Builder::Auth::UserAdmin::DBM::_generic; |
80
|
5
|
|
|
5
|
|
48
|
use vars qw(@ISA); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
305
|
|
81
|
|
|
|
|
|
|
@ISA = qw(CGI::Builder::Auth::UserAdmin::DBM CGI::Builder::Auth::UserAdmin); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |