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