Code

Added external resolution hook to environment
[gosa.git] / include / class_userinfo.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003-2005  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 class userinfo
22 {
23   var $dn;
24   var $ip;
25   var $username;
26   var $cn;
27   var $gidNumber= -1;
28   var $language= "";
29   var $config;
30   var $subtreeACL= array();
32   /* get acl's an put them into the userinfo object
33      attr subtreeACL (userdn:components, userdn:component1#sub1#sub2,component2,...) */
34   function userinfo($config, $userdn){
35     $this->config= $config;
36     $ldap= $this->config->get_ldap_link();
37     $ldap->cat($userdn,array('sn', 'givenName', 'uid', 'gidNumber', 'preferredLanguage'));
38     $attrs= $ldap->fetch();
40     if (isset($attrs['givenName'][0]) && isset($attrs['sn'][0])){
41       $this->cn= $attrs['givenName'][0]." ".$attrs['sn'][0];
42     } else {
43       $this->cn= $attrs['uid'][0];
44     }
45     if (isset($attrs['gidNumber'][0])){
46       $this->gidNumber= $attrs['gidNumber'][0];
47     }
49     /* Assign user language */
50     if (isset($attrs['preferredLanguage'][0])){
51       $this->language= $attrs['preferredLanguage'][0];
52     }
54     $this->dn= $userdn;
55     $this->ip= $_SERVER['REMOTE_ADDR'];
56   }
59   function loadACL()
60   {
61     $ldap= $this->config->get_ldap_link();
63     /* Load ACL's from all groups we're in */
64     $this->subtreeACL= array();
65     $ldap->cd($this->config->current['BASE']);
66     if ($this->gidNumber == -1){
67       $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaObject)".
68           "(memberUid=$this->username))");
69     } else {
70       $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaObject)".
71           "(|(memberUid=$this->username)(gidNumber=$this->gidNumber)))");
72     }
74     while($attrs = $ldap->fetch()){
75       $base= preg_replace('/^[^,]+,ou=[^,]+,/i', "",$ldap->getDN());
76       $base= preg_replace("/[ ]*,[ ]*/", ",", $base);
78       for ($i= 0; $i<$attrs["gosaSubtreeACL"]["count"]; $i++){
79         $this->subtreeACL[$base][]= $attrs["gosaSubtreeACL"][$i];
80       }
81     }
82   }
84 }
86 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
87 ?>