af3103c0c4e2984f2d30f45ac70382c9dca65301
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 $uid;
28 var $gidNumber= -1;
29 var $language= "";
30 var $config;
31 var $gosaUnitTag= "";
32 var $subtreeACL= array();
33 var $ACL= array();
34 var $groups= array();
36 /* get acl's an put them into the userinfo object
37 attr subtreeACL (userdn:components, userdn:component1#sub1#sub2,component2,...) */
38 function userinfo($config, $userdn){
39 $this->config= $config;
40 $ldap= $this->config->get_ldap_link();
41 $ldap->cat($userdn,array('sn', 'givenName', 'uid', 'gidNumber', 'preferredLanguage', 'gosaUnitTag'));
42 $attrs= $ldap->fetch();
44 if (isset($attrs['givenName'][0]) && isset($attrs['sn'][0])){
45 $this->cn= $attrs['givenName'][0]." ".$attrs['sn'][0];
46 } else {
47 $this->cn= $attrs['uid'][0];
48 }
49 if (isset($attrs['gidNumber'][0])){
50 $this->gidNumber= $attrs['gidNumber'][0];
51 }
53 /* Assign user language */
54 if (isset($attrs['preferredLanguage'][0])){
55 $this->language= $attrs['preferredLanguage'][0];
56 }
58 if (isset($attrs['gosaUnitTag'][0])){
59 $this->gosaUnitTag= $attrs['gosaUnitTag'][0];
60 }
62 $this->dn= $userdn;
63 $this->uid= $attrs['uid'][0];
64 $this->ip= $_SERVER['REMOTE_ADDR'];
65 }
68 function loadACL()
69 {
70 $ldap= $this->config->get_ldap_link();
72 /* Load ACL's from all groups we're in */
73 $this->subtreeACL= array();
74 $ldap->cd($this->config->current['BASE']);
75 if ($this->gidNumber == -1){
76 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaObject)".
77 "(memberUid=$this->username))");
78 } else {
79 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaObject)".
80 "(|(memberUid=$this->username)(gidNumber=$this->gidNumber)))");
81 }
83 while($attrs = $ldap->fetch()){
84 $base= preg_replace('/^[^,]+,ou=[^,]+,/i', "",$ldap->getDN());
85 $base= preg_replace("/[ ]*,[ ]*/", ",", $base);
87 for ($i= 0; $i<$attrs["gosaSubtreeACL"]["count"]; $i++){
88 $this->subtreeACL[$base][]= $attrs["gosaSubtreeACL"][$i];
89 }
90 }
92 # echo "NEW ACL LOADING --------------------------------------------------------------------------------------------<br>";
93 $this->ACL= array();
94 $this->groups= array();
95 $ldap= $this->config->get_ldap_link();
96 $ldap->cd($this->config->current['BASE']);
98 /* Get member groups... */
99 $ldap->search("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array('dn'));
100 while ($attrs= $ldap->fetch()){
101 $this->groups[$attrs['dn']]= $attrs['dn'];
102 }
104 /* Crawl through ACLs and move relevant to the tree */
105 $ldap->search("(objectClass=gosaACL)", array('dn', 'gosaAclEntry'));
106 $aclp= array();
107 $aclc= array();
108 while ($attrs= $ldap->fetch()){
110 /* Insert links in ACL array */
111 $tree= split(',', $attrs['dn']);
112 $tree= array_reverse($tree);
114 $interresting= FALSE;
115 $t= acl::explodeAcl($attrs['gosaAclEntry'][0]);
116 # print_a($t);
118 /* We're interested in ACLs apply for *all* users... */
120 /* ... for groups we're member in... */
122 /* and for our DN as member. */
125 $aclp[$attrs['dn']]= substr_count($attrs['dn'], ',');
126 $aclc[$attrs['dn']]= $attrs['gosaAclEntry'];
128 }
130 /* ACL's read, sort for tree depth */
131 asort($aclp);
133 #print_a($aclp);
134 }
136 }
138 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
139 ?>