FusionDirectory
class_acl.inc
Go to the documentation of this file.
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4  Copyright (C) 2003-2010 Cajus Pollmeier
5  Copyright (C) 2011-2020 FusionDirectory
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 
30 class acl
31 {
32  static function plInfo ()
33  {
34  return [
35  'plShortName' => _('ACL'),
36  'plDescription' => _('Manage access control lists'),
37  'plCategory' => [
38  'acl' => [
39  'description' => _('ACL').'&nbsp;&amp;&nbsp;'._('ACL roles'),
40  'objectClass' => ['gosaAcl','gosaRole']
41  ]
42  ],
43  'plObjectType' => [],
44 
45  'plProvidedAcls' => []
46  ];
47  }
48 
54  static function explodeRole ($role)
55  {
56  if (!is_array($role)) {
57  $role = [$role];
58  }
59  unset($role['count']);
60  $result = [];
61  foreach ($role as $aclTemplate) {
62  $list = explode(':', $aclTemplate, 2);
63  $result[$list[0]] = static::extractACL($list[1]);
64  }
65  ksort($result);
66  return $result;
67  }
68 
74  static function explodeACL ($acl)
75  {
76  $list = explode(':', $acl);
77  if (count($list) == 6) {
78  list($index, $type, $role, $members, $userfilter, $targetfilter) = $list;
79  $userfilter = base64_decode($userfilter);
80  $targetfilter = base64_decode($targetfilter);
81  } elseif (count($list) == 5) {
82  list($index, $type, $role, $members, $userfilter) = $list;
83  $userfilter = base64_decode($userfilter);
84  $targetfilter = '';
85  } else {
86  list($index, $type, $role, $members) = $list;
87  $userfilter = '';
88  $targetfilter = '';
89  }
90 
91  $a = [
92  $index => [
93  'type' => $type,
94  'userfilter' => $userfilter,
95  'targetfilter' => $targetfilter,
96  'members' => acl::extractMembers($members),
97  'acl' => base64_decode($role),
98  ]
99  ];
100 
101  /* Handle unknown types */
102  if (!in_array($type, ['subtree', 'base'])) {
103  $error = new FusionDirectoryError(
104  nl2br(htmlescape(sprintf(
105  _("Unkown ACL type \"%s\"!\nYou might need to run \"fusiondirectory-configuration-manager --migrate-acls\" to migrate your acls to the new format."),
106  $type
107  )))
108  );
109  $error->display();
110  $a = [];
111  }
112  return $a;
113  }
114 
122  static function extractMembers (string $ms)
123  {
124  global $config;
125  $a = [];
126 
127  /* Seperate by ',' and place it in an array */
128  $ma = explode(',', $ms);
129 
130  /* Decode dn's, fill with informations from LDAP */
131  $ldap = $config->get_ldap_link();
132  foreach ($ma as $memberdn) {
133  // Check for wildcard here
134  $dn = base64_decode($memberdn);
135  if ($dn != '*') {
136  if (empty($dn)) {
137  trigger_error('Empty dn found in members of ACL');
138  continue;
139  }
140 
141  $ldap->cat($dn, ['cn', 'objectClass', 'description', 'uid']);
142 
143  /* Found entry... */
144  if ($ldap->count()) {
145  $attrs = $ldap->fetch();
146  if (in_array_ics('inetOrgPerson', $attrs['objectClass'])) {
147  $a['U:'.$dn] = $attrs['cn'][0].' ['.$attrs['uid'][0].']';
148  } elseif (in_array_ics('organizationalRole', $attrs['objectClass'])) {
149  $a['R:'.$dn] = $attrs['cn'][0];
150  if (isset($attrs['description'][0])) {
151  $a['R:'.$dn] .= ' ['.$attrs['description'][0].']';
152  }
153  } else {
154  $a['G:'.$dn] = $attrs['cn'][0];
155  if (isset($attrs['description'][0])) {
156  $a['G:'.$dn] .= ' ['.$attrs['description'][0].']';
157  }
158  }
159  /* ... or not */
160  } else {
161  $a['U:'.$dn] = sprintf(_("Unknown entry '%s'!"), $dn);
162  }
163  } else {
164  $a['G:*'] = sprintf(_("All users"));
165  }
166  }
167 
168  return $a;
169  }
170 
176  static function extractACL (string $acl)
177  {
178  /* Rip acl off the string, seperate by ',' and place it in an array */
179  $as = preg_replace('/^[^:]+:[^:]+:[^:]*:([^:]*).*$/', '\1', $acl);
180  $aa = explode(',', $as);
181  $a = [];
182 
183  /* Dis-assemble single ACLs */
184  foreach ($aa as $sacl) {
185 
186  /* Dis-assemble field ACLs */
187  $ao = explode('#', $sacl);
188  $gobject = "";
189  foreach ($ao as $idx => $ssacl) {
190 
191  /* First is department with global acl */
192  $object = preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
193  $gacl = preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
194  if ($idx == 0) {
195  /* Create hash for this object */
196  $gobject = $object;
197  $a[$gobject] = [];
198 
199  /* Append ACL if set */
200  if ($gacl != "") {
201  $a[$gobject] = [new ACLPermissions($gacl)];
202  }
203  } else {
204  /* All other entries get appended... */
205  list($field, $facl) = explode(';', $ssacl);
206  $a[$gobject][$field] = new ACLPermissions($facl);
207  }
208  }
209  }
210 
211  return $a;
212  }
213 }
htmlescape(string $str)
Escape string for HTML output.
Definition: php_setup.inc:32
in_array_ics($value, array $items)
Check if a value exists in an array (case-insensitive)
Definition: functions.inc:814
This class contains all the function needed to manage acl.
Definition: class_acl.inc:30
static explodeRole($role)
Explode a role.
Definition: class_acl.inc:54
Parent class for all errors in FusionDirectory.
static explodeACL($acl)
Explode an acl.
Definition: class_acl.inc:74
static extractACL(string $acl)
Extract an acl.
Definition: class_acl.inc:176
static extractMembers(string $ms)
Extract members of an acl.
Definition: class_acl.inc:122