line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Apache::Auth::UserDB |
3
|
|
|
|
|
|
|
# An Apache user database manager class. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# (C) 2003-2007 Julian Mehnle |
6
|
|
|
|
|
|
|
# $Id: UserDB.pm 31 2007-09-18 01:39:14Z julian $ |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
############################################################################## |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package Apache::Auth::UserDB; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Apache::Auth::UserDB - Manipulation of Apache user authentication databases |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
11
|
use version; our $VERSION = qv('0.120'); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
10
|
|
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
160
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
46
|
|
21
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
51
|
|
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
216
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Constants: |
26
|
|
|
|
|
|
|
############################################################################## |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
2
|
|
11
|
use constant TRUE => (0 == 0); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
202
|
|
29
|
2
|
|
|
2
|
|
10
|
use constant FALSE => not TRUE; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
1339
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Interface: |
32
|
|
|
|
|
|
|
############################################################################## |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub clear; |
37
|
|
|
|
|
|
|
sub commit; |
38
|
|
|
|
|
|
|
sub users; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get_user; |
41
|
|
|
|
|
|
|
sub search_users; |
42
|
|
|
|
|
|
|
sub add_user; |
43
|
|
|
|
|
|
|
sub delete_user; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Implementation: |
46
|
|
|
|
|
|
|
############################################################################## |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
49
|
4
|
|
|
4
|
0
|
11
|
my ($class, %options) = @_; |
50
|
|
|
|
|
|
|
|
51
|
4
|
|
|
|
|
21
|
my $self = bless( |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
users => [], |
54
|
|
|
|
|
|
|
%options |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
$class |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
4
|
|
|
|
|
16
|
return $self; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub clear { |
63
|
2
|
|
|
2
|
0
|
4
|
my ($self) = @_; |
64
|
2
|
|
|
|
|
7
|
$self->{users} = []; |
65
|
2
|
|
|
|
|
6
|
return $self; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub commit { |
69
|
4
|
|
|
4
|
0
|
10
|
my ($self) = @_; |
70
|
4
|
|
|
|
|
24
|
return $self->_write(); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub users { |
74
|
7
|
|
|
7
|
0
|
916
|
my ($self) = @_; |
75
|
7
|
|
|
|
|
9
|
return @{ $self->{users} }; |
|
7
|
|
|
|
|
36
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub get_user { |
79
|
0
|
|
|
0
|
0
|
0
|
my ($self, %params) = @_; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
my @users = $self->search_users(%params); |
82
|
0
|
0
|
|
|
|
0
|
if (@users > 1) { |
|
|
0
|
|
|
|
|
|
83
|
0
|
|
|
|
|
0
|
carp( |
84
|
|
|
|
|
|
|
"There are multiple users matching your search criteria, returning *none*" . |
85
|
|
|
|
|
|
|
"for safety purposes. Fix your selection criteria or use search_users()!" |
86
|
|
|
|
|
|
|
); |
87
|
0
|
|
|
|
|
0
|
return undef; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
elsif (@users == 0) { |
90
|
0
|
|
|
|
|
0
|
return undef; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
else { |
93
|
0
|
|
|
|
|
0
|
return $users[0]; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub search_users { |
98
|
0
|
|
|
0
|
0
|
0
|
my ($self, %params) = @_; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
0
|
my @users; |
101
|
0
|
|
|
|
|
0
|
foreach my $user (@{$self->{users}}) { |
|
0
|
|
|
|
|
0
|
|
102
|
0
|
|
|
|
|
0
|
my $match = TRUE; |
103
|
0
|
|
|
|
|
0
|
foreach my $field (keys(%params)) { |
104
|
0
|
|
|
|
|
0
|
my $pattern = $params{$field}; |
105
|
0
|
0
|
|
|
|
0
|
$match = FALSE |
|
|
0
|
|
|
|
|
|
106
|
|
|
|
|
|
|
if ( |
107
|
|
|
|
|
|
|
ref($pattern) eq 'Regexp' ? |
108
|
|
|
|
|
|
|
$user->$field() !~ $pattern |
109
|
|
|
|
|
|
|
: $user->$field() ne $pattern |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
} |
112
|
0
|
0
|
|
|
|
0
|
push(@users, $user) if $match; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
0
|
return @users; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub add_user { |
119
|
5
|
|
|
5
|
0
|
37
|
my ($self, $user) = @_; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# Delete existing old user first: |
122
|
5
|
|
|
|
|
9
|
foreach my $old_user (@{$self->{users}}) { |
|
5
|
|
|
|
|
15
|
|
123
|
3
|
100
|
|
|
|
16
|
if ($user eq $old_user) { |
124
|
2
|
|
|
|
|
17
|
$self->delete_user($old_user); |
125
|
2
|
|
|
|
|
5
|
last; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Add new user: |
130
|
5
|
|
|
|
|
14
|
push(@{$self->{users}}, $user); |
|
5
|
|
|
|
|
12
|
|
131
|
|
|
|
|
|
|
|
132
|
5
|
|
|
|
|
12
|
return $self; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub delete_user { |
136
|
2
|
|
|
2
|
0
|
4
|
my ($self, $user) = @_; |
137
|
2
|
50
|
|
|
|
7
|
$self->{users} = [ grep($_ ne $user, @{$self->{users}}) ] |
|
2
|
|
|
|
|
9
|
|
138
|
|
|
|
|
|
|
if $user; |
139
|
2
|
|
|
|
|
73
|
return $self; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
TRUE; |