File Coverage

blib/lib/WE/DB/ComplexUser/AuthUnix.pm
Criterion Covered Total %
statement 9 20 45.0
branch 0 10 0.0
condition 0 3 0.0
subroutine 3 4 75.0
pod 0 1 0.0
total 12 38 31.5


line stmt bran cond sub pod time code
1             # -*- perl -*-
2              
3             #
4             # $Id: AuthUnix.pm,v 1.2 2005/02/03 00:06:28 eserte Exp $
5             # Author: Slaven Rezic
6             #
7             # Copyright (C) 2005 Slaven Rezic. All rights reserved.
8             # This package is free software; you can redistribute it and/or
9             # modify it under the same terms as Perl itself.
10             #
11             # Mail: slaven@rezic.de
12             # WWW: http://www.rezic.de/eserte/
13             #
14              
15             package WE::DB::ComplexUser::AuthUnix;
16              
17 1     1   964 use strict;
  1         1  
  1         31  
18 1     1   5 use vars qw($VERSION $DEBUG);
  1         2  
  1         83  
19             $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
20              
21 1     1   6 use mixin::with 'WE::DB::ComplexUser';
  1         2  
  1         7  
22              
23             # This works only on system without shadow passwords!
24              
25             sub identify_Unix {
26 0     0 0   my($self, $user, $password) = @_;
27              
28 0   0       my $unix_user = $user->{Auth_Unix_User} || $user->Username;
29 0 0         warn "Try unix authentication with user=$unix_user...\n" if $DEBUG;
30              
31 0           my(undef, $pwd, $uid) = getpwnam($unix_user);
32 0 0         if (!defined $uid) {
33 0 0         warn "The unix user <$unix_user> is undefined" if $DEBUG;
34 0           return 0;
35             }
36            
37 0 0         if (crypt($password, $pwd) eq $pwd) {
38 0           return 1;
39             } else {
40 0 0         warn "Password incorrect" if $DEBUG;
41 0           return 0;
42             }
43             }
44              
45             1;
46              
47             __END__