line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Text.pm,v 1.1.1.1 2004/06/28 19:24:28 veselosky Exp $ |
2
|
|
|
|
|
|
|
package CGI::Builder::Auth::UserAdmin::Text; |
3
|
5
|
|
|
5
|
|
29
|
use CGI::Builder::Auth::UserAdmin (); |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
102
|
|
4
|
5
|
|
|
5
|
|
25
|
use Carp (); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
98
|
|
5
|
5
|
|
|
5
|
|
25
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
186
|
|
6
|
5
|
|
|
5
|
|
24
|
use vars qw(@ISA $DLM $VERSION); |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
4124
|
|
7
|
|
|
|
|
|
|
@ISA = qw(CGI::Builder::Auth::UserAdmin::DBM CGI::Builder::Auth::UserAdmin); |
8
|
|
|
|
|
|
|
$VERSION = (qw$Revision: 1.1.1.1 $)[1]; |
9
|
|
|
|
|
|
|
$DLM = ":"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %Default = (PATH => ".", |
12
|
|
|
|
|
|
|
DB => ".htpasswd", |
13
|
|
|
|
|
|
|
FLAGS => "rwc", |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
22
|
|
|
22
|
1
|
41
|
my($class) = shift; |
18
|
22
|
|
|
|
|
181
|
my $self = bless { %Default, @_ }, $class; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#load the DBM methods |
21
|
22
|
|
|
|
|
129
|
$self->load("CGI::Builder::Auth::UserAdmin::DBM"); |
22
|
|
|
|
|
|
|
|
23
|
22
|
|
|
|
|
166
|
$self->db($self->{DB}); |
24
|
22
|
|
|
|
|
134
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#do this so we can borrow from the DBM class |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _tie { |
30
|
22
|
|
|
22
|
|
44
|
my($self) = @_; |
31
|
22
|
|
|
|
|
63
|
my($fh,$db) = ($self->gensym(), $self->{DB}); |
32
|
22
|
50
|
|
|
|
382
|
printf STDERR "%s->_tie($db)\n", $self->class if $self->debug; |
33
|
|
|
|
|
|
|
|
34
|
22
|
50
|
|
|
|
115
|
$db =~ /^([^<>;|]+)$/ or Carp::croak("Bad file name '$db'"); $db = $1; #untaint |
|
22
|
|
|
|
|
48
|
|
35
|
22
|
100
|
|
|
|
616
|
open($fh, $db) or return; |
36
|
19
|
|
|
|
|
32
|
my($key,$val); |
37
|
|
|
|
|
|
|
|
38
|
19
|
|
|
|
|
368
|
while(<$fh>) { #slurp! need a better method here. |
39
|
26
|
|
|
|
|
92
|
($key,$val) = $self->_parseline($fh, $_); |
40
|
26
|
|
|
|
|
179
|
$self->{'_HASH'}{$key} = $val; |
41
|
|
|
|
|
|
|
} |
42
|
19
|
|
|
|
|
238
|
CORE::close $fh; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _untie { |
46
|
20
|
|
|
20
|
|
29
|
my($self) = @_; |
47
|
20
|
50
|
|
|
|
59
|
return unless exists $self->{'_HASH'}; |
48
|
20
|
|
|
|
|
68
|
$self->commit; |
49
|
20
|
|
|
|
|
90
|
delete $self->{'_HASH'}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub commit { |
53
|
25
|
|
|
25
|
1
|
41
|
my($self) = @_; |
54
|
25
|
100
|
|
|
|
179
|
return if $self->readonly; |
55
|
23
|
|
|
|
|
84
|
my($fh,$db) = ($self->gensym(), $self->{DB}); |
56
|
23
|
|
|
|
|
284
|
my($key,$val); |
57
|
|
|
|
|
|
|
|
58
|
23
|
50
|
|
|
|
125
|
$db =~ /^([^<>;|]+)$/ or return (0, "Bad file name '$db'"); $db = $1; |
|
23
|
|
|
|
|
59
|
|
59
|
|
|
|
|
|
|
#untaint |
60
|
23
|
|
|
|
|
80
|
my $tmp_db = "$db.$$"; # Use temp file until write is complete. |
61
|
23
|
50
|
|
|
|
1857
|
open($fh, ">$tmp_db") or return (0, "open: '$tmp_db' $!"); |
62
|
|
|
|
|
|
|
|
63
|
23
|
|
|
|
|
48
|
while(($key,$val) = each %{$self->{'_HASH'}}) { |
|
54
|
|
|
|
|
211
|
|
64
|
31
|
50
|
|
|
|
164
|
print $fh $self->_formatline($key,$val) |
65
|
|
|
|
|
|
|
or return (0, "print: '$tmp_db' failed: $!"); |
66
|
|
|
|
|
|
|
} |
67
|
23
|
50
|
|
|
|
902
|
CORE::close $fh |
68
|
|
|
|
|
|
|
or return (0, "close: '$tmp_db' failed: $!"); |
69
|
23
|
|
|
|
|
291
|
my $mode = (stat $db)[2]; |
70
|
23
|
100
|
|
|
|
442
|
chmod $mode, $tmp_db if $mode; |
71
|
23
|
50
|
|
|
|
1607
|
rename( $tmp_db,$db ) |
72
|
|
|
|
|
|
|
or return (0, "rename '$tmp_db' to '$db' failed: $!"); |
73
|
23
|
|
|
|
|
94
|
1; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _parseline { |
77
|
26
|
|
|
26
|
|
49
|
my($self,$fh,$line) = @_; |
78
|
26
|
|
|
|
|
45
|
chomp $line; |
79
|
26
|
|
|
|
|
144
|
my($key, $val) = split($DLM, $line, 2); |
80
|
26
|
|
|
|
|
79
|
return ($key,$val); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _formatline { |
84
|
31
|
|
|
31
|
|
49
|
my($self,$key,$val) = @_; |
85
|
31
|
|
|
|
|
313
|
join($DLM, $key,$val) . "\n"; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
package CGI::Builder::Auth::UserAdmin::Text::_generic; |
89
|
5
|
|
|
5
|
|
29
|
use vars qw(@ISA); |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
348
|
|
90
|
|
|
|
|
|
|
@ISA = qw(CGI::Builder::Auth::UserAdmin::Text |
91
|
|
|
|
|
|
|
CGI::Builder::Auth::UserAdmin::DBM); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |