WE/DB/NISUser.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« WebEditor/OldFeatures/HTMLFilterHack.pm ↑ Summary WE/DB/User.pm »
1 # -*- perl -*-
2  
3 #
4 # $Id: NISUser.pm,v 1.4 2003/12/16 15:21:23 eserte Exp $
5 # Author: Slaven Rezic
6 #
7 # Copyright (C) 2001 Online Office Berlin. All rights reserved.
8 # Copyright (C) 2002 Slaven Rezic.
9 # This is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License, see the file COPYING.
11  
12 #
13 # Mail: slaven@rezic.de
14 # WWW: http://we-framework.sourceforge.net
15 #
16  
17 package WE::DB::NISUser;
18  
19 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 $VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
22  
23 0 ▶use Net::NIS;
Subroutine BEGIN: called CC=1 SCAR=2.6
24  
25 sub new {
26 my($class, $root, %args) = @_;
27 my $self = {};
28 bless $self, $class;
29 $self->{Domain} = scalar Net::NIS::yp_get_default_domain();
30 $self;
31 }
32  
33 sub identify {
34 my($self, $user, $password) = @_;
35 my $ret = 0;
36 my($status, $entry) = Net::NIS::yp_match($self->{Domain}, "passwd.byname", $user);
37 return 0 if $status;
38 my $hash = (split /:/, $entry)[1];
39 crypt($password, $hash) eq $hash ? 1 : 0;
40 }
41  
42 sub get_fullname {
43 my($self, $user) = @_;
44 my($status, $entry) = Net::NIS::yp_match($self->{Domain},"passwd.byname", $user);
45 return 0 if $status;
46 (split /:/, $entry)[4];
47 }
48  
49 sub user_exists {
50 my($self, $user) = @_;
51 my($status, $entry) = Net::NIS::yp_match($self->{Domain},"passwd.byname", $user);
52 $status ? 0 : 1;
53 }
54  
55 sub add_user {
56 my($self, $user, $password, $fullname) = @_;
57 die "Not implemented with " . __PACKAGE__;
58 }
59  
60 sub update_user {
61 my($self, $user, $password, $fullname,$groups) = @_;
62 die "Not implemented with " . __PACKAGE__;
63 }
64  
65 sub delete_user {
66 my($self, $user) = @_;
67 die "Not implemented with " . __PACKAGE__;
68 }
69  
70 sub is_in_group {
71 my($self, $user, $group) = @_;
72 my($status, $entry) = Net::NIS::yp_match($self->{Domain},"group.byname", $group);
73 return 0 if $status;
74 scalar grep { $user eq $_ } split(/,/, (split(/:/, $entry))[3]);
75 }
76  
77 sub get_groups {
78 my($self, $user) = @_;
79 my($status, $values) = Net::NIS::yp_all($self->{Domain},"group.byname");
80 return () if !$values;
81 my @groups;
82 while(my($group, $entry) = each %$values) {
83 my $users = (split(/:/, $entry))[3];
84 if (defined $users) {
85 if (grep { $user eq $_ } split(/,/, $users)) {
86 push @groups, $group;
87 }
88 }
89 }
90 @groups;
91 }
92  
93 sub get_user {
94 my($self, $user) = @_;
95 my($status, $entry) = Net::NIS::yp_match($self->{Domain},"passwd.byname", $user);
96 if ($status == 0) {
97 my @things = split /:/, $entry;
98 my @groups = $self->get_groups($user);
99 return {'groups' => \@groups,
100 'username' => $user,
101 'password' => $things[1],
102 'fullname' => $things[4],
103 };
104 }
105 0;
106 }
107  
108 sub add_group {
109 my($self, $user, $group) = @_;
110 die "Not implemented with " . __PACKAGE__;
111 }
112  
113 sub delete_group {
114 my($self, $user, $delgroup) = @_;
115 die "Not implemented with " . __PACKAGE__;
116 }
117  
118 sub get_users_of_group {
119 my($self, $group) = @_;
120 my @users;
121 foreach my $usr (keys %{$self->{DB}}) {
122 if ( $self->is_in_group($usr,$group) ) { push(@users,$usr); }
123 }
124 return @users;
125 }
126  
127 sub get_all_users {
128 my($self) = @_;
129 my($status, $values) = Net::NIS::yp_all($self->{Domain},"passwd.byname");
130 keys %$values;
131 }
132  
133 sub get_all_groups {
134 my($self) = @_;
135 my($status, $values) = Net::NIS::yp_all($self->{Domain},"group.byname");
136 keys %$values;
137 }
138  
139 1;
140  
141 __END__
« WebEditor/OldFeatures/HTMLFilterHack.pm ↑ Summary WE/DB/User.pm »