1 # Copyright (C) 2002 Stanislav Sinyagin
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17 # $Id: ACL.pm,v 1.1 2010-12-27 00:03:43 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
30 eval( 'require ' . $Torrus::ACL::userAuthModule );
41 eval( '$self->{"auth"} = new ' . $Torrus::ACL::userAuthModule );
44 my $writing = $options{'-WriteAccess'};
46 $self->{'db_users'} = new Torrus::DB('users', -WriteAccess => $writing );
47 defined( $self->{'db_users'} ) or return( undef );
49 $self->{'db_acl'} = new Torrus::DB('acl', -WriteAccess => $writing );
50 defined( $self->{'db_acl'} ) or return( undef );
52 $self->{'is_writing'} = $writing;
62 Debug('Destroying ACL object');
64 undef $self->{'db_users'};
65 undef $self->{'db_acl'};
74 my $privilege = shift;
76 foreach my $group ( $self->memberOf( $uid ) )
78 if( $self->{'db_acl'}->get( $group.':'.$object.':'.$privilege ) )
80 Debug('User ' . $uid . ' has privilege ' . $privilege .
88 return $self->hasPrivilege( $uid, '*', $privilege );
91 Debug('User ' . $uid . ' has NO privilege ' . $privilege .
102 my $glist = $self->{'db_users'}->get( 'gm:' . $uid );
103 return( defined( $glist ) ? split(',', $glist) : () );
111 my $password = shift;
113 my @attrList = $self->{'auth'}->getUserAttrList();
115 foreach my $attr ( @attrList )
117 $attrValues->{$attr} = $self->userAttribute( $uid, $attr );
120 my $ret = $self->{'auth'}->authenticateUser( $uid, $password,
122 Debug('User authentication: uid=' . $uid . ', result=' .
123 ($ret ? 'true':'false'));
134 return $self->{'db_users'}->get( 'ua:' . $uid . ':' . $attr );
144 return $self->{'db_users'}->get( 'ga:' . $group . ':' . $attr );
154 # indent-tabs-mode: nil
155 # perl-indent-level: 4