FusionDirectory
 All Data Structures Files Functions Variables
class_filterLDAP.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-2016 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 
33 {
51  static function query($parent, $base, $scope, $filter, $attributes, $category, $objectStorage = array(""))
52  {
53  return static::get_list($parent, $base, $filter, $attributes, $category, $objectStorage, (($scope == 'sub') ? 'subtree' : 'one'), TRUE);
54  }
55 
77  static function get_list($parent, $base, $filter, $attributes, $category, $objectStorage, $scope, $sizelimit = TRUE, $skipAcl = FALSE)
78  {
79  global $config, $ui;
80 
81  // Move to arrays for category and objectStorage
82  if (!is_array($category)) {
83  $category = array($category);
84  }
85 
86  // Initialize search bases
87  $bases = array();
88 
89  foreach ($objectStorage as $oc) {
90  $oc = preg_replace('/,$/', '', $oc);
91  if ($scope == 'one') {
92  if (empty($oc)) {
93  $bases[$base] = TRUE;
94  } else {
95  $bases[$oc.','.$base] = TRUE;
96  }
97  } else {
98  if (empty($oc)) {
99  /* If we search on the base as well because of an empty storage string,
100  * it makes no sense to do dn filters */
101  $bases[$base] = TRUE;
102  break;
103  }
104  $parts = ldap_explode_dn($oc, 0);
105  unset($parts['count']);
106  $dnFilter = array();
107  foreach ($parts as $part) {
108  preg_match('/([^=]+)=(.*)$/', $part, $m);
109  $dnFilter[] = '('.$m[1].':dn:='.$m[2].')';
110  }
111  if (count($dnFilter) > 1) {
112  $bases[$base][] = '(&'.implode('', $dnFilter).')';
113  } else {
114  $bases[$base][] = $dnFilter[0];
115  }
116  }
117  }
118 
119  // Get LDAP link
120  $ldap = $config->get_ldap_link($sizelimit);
121 
122  // Do search for every base
123  $result = array();
124  $limit_exceeded = FALSE;
125 
126  foreach ($bases as $base => $dnFilters) {
127  // Break if the size limit is exceeded
128  if ($limit_exceeded) {
129  return $result;
130  }
131 
132  // Switch to new base and search
133  if (is_array($dnFilters)) {
134  $dnFilter = '(|'.implode('', $dnFilters).')';
135  } else {
136  $dnFilter = '';
137  }
138  $ldap->cd($base);
139 
140  $ldap->search('(&'.$filter.$dnFilter.')', $attributes, $scope);
141 
142  // Check for size limit exceeded messages for GUI feedback
143  if (preg_match("/size limit/i", $ldap->get_error())) {
144  session::set('limit_exceeded', TRUE);
145  $limit_exceeded = TRUE;
146  }
147 
148  /* Crawl through result entries and perform the migration to the
149  result array */
150  while ($attrs = $ldap->fetch()) {
151  $dn = $attrs['dn'];
152 
153  /* Skip ACL checks if we are forced to skip those checks */
154  if ($skipAcl) {
155  $result[] = $attrs;
156  } else {
157  // Check entry permission
158  $obj = $parent->headpage->getObjectTypeInfos($dn, $attrs);
159  if (isset($obj['category'])) {
160  $o = $obj['category'].'/'.$obj['class'];
161  if (strpos($ui->get_permissions($dn, $o), 'r') !== FALSE) {
162  $result[] = $attrs;
163  }
164  } else {
165  trigger_error('Could not find objectType for '.$dn.'!');
166  }
167  }
168  }
169  }
170 
171  return $result;
172  }
173 }
174 ?>
static set($name, $value)
Set a value in a session.
This class contains all the function to manage LDAP filter.
static query($parent, $base, $scope, $filter, $attributes, $category, $objectStorage=array(""))
Query.
static get_list($parent, $base, $filter, $attributes, $category, $objectStorage, $scope, $sizelimit=TRUE, $skipAcl=FALSE)
Get list.