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::GroupAdmin::Text; |
3
|
4
|
|
|
4
|
|
19
|
use Carp (); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
74
|
|
4
|
4
|
|
|
4
|
|
24
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
127
|
|
5
|
4
|
|
|
4
|
|
19
|
use vars qw(@ISA $DLM $VERSION $LineMax); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
4451
|
|
6
|
|
|
|
|
|
|
@ISA = qw(CGI::Builder::Auth::GroupAdmin); |
7
|
|
|
|
|
|
|
$VERSION = (qw$Revision: 1.1.1.1 $)[1]; |
8
|
|
|
|
|
|
|
$DLM = ": "; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Maximum size of each line in the group file. Anytime we have more |
11
|
|
|
|
|
|
|
# group data than this we split it up into multiple lines. At least |
12
|
|
|
|
|
|
|
# Apache 1.3.4 this limitation on lines in the group file. |
13
|
|
|
|
|
|
|
$LineMax = 8 * 1024; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %Default = (PATH => ".", |
16
|
|
|
|
|
|
|
DB => ".htgroup", |
17
|
|
|
|
|
|
|
FLAGS => "rwc", |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
21
|
|
|
21
|
1
|
40
|
my($class) = shift; |
22
|
21
|
|
|
|
|
170
|
my $self = bless { %Default, @_ } => $class; |
23
|
|
|
|
|
|
|
#load the DBM methods |
24
|
21
|
|
|
|
|
111
|
$self->load("CGI::Builder::Auth::GroupAdmin::DBM"); |
25
|
21
|
|
|
|
|
161
|
$self->db($self->{DB}); |
26
|
21
|
|
|
|
|
126
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _tie { |
30
|
21
|
|
|
21
|
|
35
|
my($self) = @_; |
31
|
21
|
|
|
|
|
61
|
my($fh,$db) = ($self->gensym(), $self->{DB}); |
32
|
21
|
|
|
|
|
249
|
my($key,$val); |
33
|
21
|
50
|
|
|
|
114
|
printf STDERR "%s->_tie($db)\n", $self->class if $self->debug; |
34
|
|
|
|
|
|
|
|
35
|
21
|
50
|
|
|
|
296
|
$db =~ /^([^<>;|]+)$/ or Carp::croak("Bad file name '$db'"); $db = $1; #untaint |
|
21
|
|
|
|
|
50
|
|
36
|
21
|
100
|
|
|
|
1166
|
open($fh, $db) or return; #must be new |
37
|
|
|
|
|
|
|
|
38
|
18
|
|
|
|
|
1200
|
while(<$fh>) { |
39
|
16
|
|
|
|
|
72
|
($key,$val) = $self->_parseline($fh, $_); |
40
|
16
|
50
|
|
|
|
70
|
next unless $key =~ /\S/; |
41
|
16
|
50
|
|
|
|
165
|
$self->{'_HASH'}{$key} = (exists $self->{'_HASH'}{$key} ? |
42
|
|
|
|
|
|
|
join(" ", $self->{'_HASH'}{$key}, $val) : |
43
|
|
|
|
|
|
|
$val); |
44
|
|
|
|
|
|
|
} |
45
|
18
|
|
|
|
|
9024
|
CORE::close $fh; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _untie { |
49
|
18
|
|
|
18
|
|
24
|
my($self) = @_; |
50
|
18
|
100
|
|
|
|
52
|
return unless exists $self->{'_HASH'}; |
51
|
17
|
|
|
|
|
50
|
$self->commit; |
52
|
17
|
|
|
|
|
61
|
delete $self->{'_HASH'}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
DESTROY { |
56
|
18
|
|
|
18
|
|
67
|
$_[0]->_untie('_HASH'); |
57
|
18
|
|
|
|
|
93
|
$_[0]->unlock; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub commit { |
61
|
22
|
|
|
22
|
1
|
28
|
my($self) = @_; |
62
|
22
|
100
|
|
|
|
86
|
return if $self->readonly; |
63
|
21
|
|
|
|
|
65
|
my($fh,$db) = ($self->gensym(), $self->{DB}); |
64
|
21
|
|
|
|
|
244
|
my($key,$val); |
65
|
|
|
|
|
|
|
|
66
|
21
|
50
|
|
|
|
103
|
$db =~ /^([^<>;|]+)$/ or return (0, "Bad file name '$db'"); $db = $1; |
|
21
|
|
|
|
|
49
|
|
67
|
|
|
|
|
|
|
#untaint |
68
|
21
|
|
|
|
|
59
|
my $tmp_db = "$db.$$"; # Use temp file until write is complete. |
69
|
21
|
50
|
|
|
|
1524
|
open($fh, ">$tmp_db") or return (0, "open: '$tmp_db' $!"); |
70
|
|
|
|
|
|
|
|
71
|
21
|
|
|
|
|
39
|
while(($key,$val) = each %{$self->{'_HASH'}}) { |
|
43
|
|
|
|
|
190
|
|
72
|
22
|
50
|
|
|
|
128
|
print $fh $self->_formatline($key,$val) |
73
|
|
|
|
|
|
|
or return (0, "print: '$tmp_db' failed: $!"); |
74
|
|
|
|
|
|
|
} |
75
|
21
|
50
|
|
|
|
708
|
CORE::close $fh |
76
|
|
|
|
|
|
|
or return (0, "close: '$tmp_db' failed: $!"); |
77
|
21
|
|
|
|
|
251
|
my $mode = (stat $db)[2]; |
78
|
21
|
100
|
|
|
|
372
|
chmod $mode, $tmp_db if $mode; |
79
|
21
|
50
|
|
|
|
1530
|
rename( $tmp_db,$db ) |
80
|
|
|
|
|
|
|
or return (0, "rename '$tmp_db' to '$db' failed: $!"); |
81
|
21
|
|
|
|
|
85
|
1; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
sub _parseline { |
84
|
16
|
|
|
16
|
|
29
|
my($self,$fh) = (shift,shift); |
85
|
16
|
|
|
|
|
29
|
local $_ = shift; |
86
|
16
|
|
|
|
|
31
|
chomp; s/^\s+//; s/\s+$//; |
|
16
|
|
|
|
|
39
|
|
|
16
|
|
|
|
|
55
|
|
87
|
16
|
|
|
|
|
72
|
my($key, $val) = split(/:\s*/, $_, 2); |
88
|
16
|
|
|
|
|
46
|
$val =~ s/\s* \s*/ /g; |
89
|
16
|
|
|
|
|
49
|
return ($key,$val); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _formatline { |
93
|
22
|
|
|
22
|
|
37
|
my($self,$key,$val) = @_; |
94
|
22
|
|
|
|
|
44
|
my( $FieldMax ) = $LineMax - length( $key ); |
95
|
22
|
|
|
|
|
26
|
my( @fields ); |
96
|
22
|
|
|
|
|
66
|
$val =~ s/(\w) /$1 /g; |
97
|
22
|
|
|
|
|
62
|
while( length( $val ) > $FieldMax ) { |
98
|
0
|
|
|
|
|
0
|
my( $tail, $field ); |
99
|
0
|
|
|
|
|
0
|
$field = substr( $val, 0, $FieldMax ); |
100
|
0
|
|
|
|
|
0
|
$val = substr( $val, $FieldMax ); |
101
|
0
|
|
|
|
|
0
|
( $field, $tail ) = ( $field =~ m/^(.+) (\S+ ?)$/ ); |
102
|
0
|
|
|
|
|
0
|
$val = $tail . $val; |
103
|
0
|
|
|
|
|
0
|
push( @fields, $field ); |
104
|
|
|
|
|
|
|
} |
105
|
22
|
|
|
|
|
268
|
map( join($DLM, $key,$_) . "\n", @fields, $val ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub add { |
109
|
10
|
|
|
10
|
1
|
137
|
my $self = shift; |
110
|
10
|
50
|
|
|
|
59
|
return(0, $self->db . " is read-only!") if $self->readonly; |
111
|
10
|
|
|
|
|
61
|
$self->CGI::Builder::Auth::GroupAdmin::DBM::add(@_); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
package CGI::Builder::Auth::GroupAdmin::Text::_generic; |
115
|
4
|
|
|
4
|
|
31
|
use vars qw(@ISA); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
244
|
|
116
|
|
|
|
|
|
|
@ISA = qw(CGI::Builder::Auth::GroupAdmin::Text |
117
|
|
|
|
|
|
|
CGI::Builder::Auth::GroupAdmin::DBM); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |