line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::FileManager::Auth; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
50551
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
134
|
|
4
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
126
|
|
5
|
4
|
|
|
4
|
|
20
|
use Carp qw(croak); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
242
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
2700
|
use FindBin qw($Bin); |
|
4
|
|
|
|
|
3796
|
|
|
4
|
|
|
|
|
534
|
|
8
|
4
|
|
|
4
|
|
3909
|
use Unix::PasswdFile; |
|
4
|
|
|
|
|
41760
|
|
|
4
|
|
|
|
|
1118
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $auth = CGI::FileManager::Auth->new(); |
13
|
|
|
|
|
|
|
if ($auth->verify($username, $password)) { |
14
|
|
|
|
|
|
|
# Valid user |
15
|
|
|
|
|
|
|
} else { |
16
|
|
|
|
|
|
|
$ Invalid username/password pair |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Currently username/password pairs are hard coded and clear text. Just for testing. |
20
|
|
|
|
|
|
|
Later we expect to have Authentication plugins to the system and this module will probably |
21
|
|
|
|
|
|
|
hide them from the real module. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 new |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $auth = CGI::FileManager::Auth->new; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Does nothing |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
sub new { |
34
|
1
|
|
|
1
|
1
|
2080
|
my $class = shift; |
35
|
1
|
|
|
|
|
3
|
my $args = shift; |
36
|
1
|
50
|
33
|
|
|
19
|
if (not $args or ref $args ne "HASH" or not defined $args->{PASSWD_FILE}) { |
|
|
|
33
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
croak __PACKAGE__ . " needs a PASSWD_FILE to work with"; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=pod |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $self = { |
43
|
|
|
|
|
|
|
users => { |
44
|
|
|
|
|
|
|
gabor => { |
45
|
|
|
|
|
|
|
password => 'nincs', |
46
|
|
|
|
|
|
|
home => "$Bin/../dir", |
47
|
|
|
|
|
|
|
#home => '/home/gabor/work/gabor/dev/CGI-FileManager/dir', |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
}, |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
bless $self, $class; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
5
|
bless $args, $class; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 home |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Return the home directory of the given user |
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
sub home { |
63
|
1
|
|
|
1
|
1
|
552
|
my ($self, $username) = @_; |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
7
|
my $pw = new Unix::PasswdFile $self->{PASSWD_FILE}; |
66
|
1
|
|
|
|
|
339
|
return $pw->home($username); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# return if not defined $self->{users}; |
70
|
|
|
|
|
|
|
# return if not defined $self->{users}->{$username}; |
71
|
|
|
|
|
|
|
# return if not defined $self->{users}->{$username}->{home}; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# return $self->{users}->{$username}->{home}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 verify |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
verify username password |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
sub verify { |
82
|
2
|
|
|
2
|
1
|
1243
|
my ($self, $username, $password) = @_; |
83
|
|
|
|
|
|
|
|
84
|
2
|
|
|
|
|
17
|
my $pw = new Unix::PasswdFile $self->{PASSWD_FILE}; |
85
|
|
|
|
|
|
|
|
86
|
2
|
50
|
|
|
|
733
|
return 0 if not $pw->user($username); |
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
26
|
my $saved_pw = $pw->passwd($username); |
89
|
2
|
100
|
|
|
|
105
|
return crypt($password, substr($saved_pw,0,2)) eq $saved_pw ? 1 : 0; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# return 0 if not defined $self->{users}; |
93
|
|
|
|
|
|
|
# return 0 if not defined $self->{users}->{$username}; |
94
|
|
|
|
|
|
|
# return 0 if not defined $self->{users}->{$username}->{password}; |
95
|
|
|
|
|
|
|
# return 1 if $self->{users}->{$username}->{password} eq $password; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# return 0; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|