f110833ca2c6c88a171f70514399cc91d7ccb078
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 $aclp[$attrs['dn']]= substr_count($attrs['dn'], ',');
112 $aclc[$attrs['dn']]= array();
113 $ol= array();
114 for($i= 0; $i<$attrs['gosaAclEntry']['count']; $i++){
115 $ol= array_merge($ol, acl::explodeAcl($attrs['gosaAclEntry'][$i]));
116 }
117 $aclc[$attrs['dn']]= $ol;
118 }
120 /* ACL's read, sort for tree depth */
121 asort($aclp);
123 /* Sort in tree order */
124 foreach ($aclp as $dn => $acl){
125 /* Check if we need to keep this ACL */
126 foreach($aclc[$dn] as $idx => $type){
127 $interresting= FALSE;
129 /* No members? This is good for all users... */
130 if (!count($type['members'])){
131 $interresting= TRUE;
132 }
134 /* Inspect members... */
135 foreach ($type['members'] as $grp => $grpdsc){
136 /* Some group inside the members that is relevant for us? */
137 if (in_array_ics(preg_replace('/^G:/', '', $grp), $this->groups)){
138 $interresting= TRUE;
139 }
141 /* User inside the members? */
142 if (preg_replace('/^U:/', '', $grp) == $this->dn){
143 $interresting= TRUE;
144 }
145 }
147 if ($interresting){
148 if (!isset($this->ACL[$dn])){
149 $this->ACL[$dn]= array();
150 }
151 $this->ACL[$dn][$idx]= $type;
152 }
153 }
155 }
156 }
159 function get_permissions($dn, $object= "", $attribute= "")
160 {
161 echo "Evaluating permissions for $dn, object $object/$attribute<br>";
162 }
164 }
166 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
167 ?>