summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-08-22 08:04:09 (GMT)
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-08-22 08:04:09 (GMT)
commit4d854fadc7273a8477d369d41cc43d5798888a5b (patch)
tree23e0854f8f834f694f3e86f0c58193fcd20a77eb /lib
parent8250a5b925c4791f7e0cd94093a7e6545dc3f7e2 (diff)
downloadNet_LDAP3-4d854fadc7273a8477d369d41cc43d5798888a5b.tar.gz
Make delete_entry() function public
Improve some debug verbosity Make sure return attributes are reset after intermediate searches
Diffstat (limited to 'lib')
-rw-r--r--lib/Net/LDAP3.php98
-rw-r--r--lib/Net/LDAP3/Result.php14
2 files changed, 72 insertions, 40 deletions
diff --git a/lib/Net/LDAP3.php b/lib/Net/LDAP3.php
index c8eada3..4acdf1c 100644
--- a/lib/Net/LDAP3.php
+++ b/lib/Net/LDAP3.php
@@ -473,6 +473,24 @@ class Net_LDAP3
return TRUE;
}
+ /**
+ * Shortcut to ldap_delete()
+ */
+ public function delete_entry($entry_dn)
+ {
+ $this->_debug("LDAP: C: Delete $entry_dn");
+
+ if (ldap_delete($this->conn, $entry_dn) === FALSE) {
+ $this->_debug("LDAP: S: " . ldap_error($this->conn));
+ $this->_debug("LDAP: Delete failed. " . ldap_error($this->conn));
+ return FALSE;
+ }
+
+ $this->_debug("LDAP: S: OK");
+
+ return TRUE;
+ }
+
public function effective_rights($subject)
{
$effective_rights_control_oid = "1.3.6.1.4.1.42.2.27.9.5.2";
@@ -529,7 +547,7 @@ class Net_LDAP3
escapeshellarg($_SESSION['user']->user_bind_pw),
'-J',
escapeshellarg(implode(':', array(
- '1.3.6.1.4.1.42.2.27.9.5.2', // OID
+ $effective_rights_control_oid, // OID
'TRUE', // Criticality
'dn:' . $_SESSION['user']->user_bind_dn // User DN
))),
@@ -585,7 +603,7 @@ class Net_LDAP3
{
$this->_debug("entry_dn on subject $subject");
$is_dn = ldap_explode_dn($subject, 1);
- $this->_debug($is_dn);
+ $this->_debug($is_dn ? "entry_dn is a dn" : "entry_dn is not a dn");
if (is_array($is_dn) && array_key_exists("count", $is_dn) && $is_dn["count"] > 0) {
return $subject;
@@ -1135,8 +1153,13 @@ class Net_LDAP3
if ($this->vlv_active && isset($this->additional_filter)) {
$filter = "(&" . $filter . $this->additional_filter . ")";
$this->_debug("C: Setting a filter of " . $filter);
+ } else {
+ $filter = "(&" . $filter . $this->additional_filter . ")";
+ $this->_debug("C: (Without VLV) Setting a filter of " . $filter);
}
+ $this->_debug("Executing search with return attributes: " . var_export($this->return_attributes, TRUE));
+
$ldap_result = @$function(
$this->conn,
$base_dn,
@@ -1160,7 +1183,7 @@ class Net_LDAP3
$this->result->set('count', $vlv_count);
$this->result->set('vlv', TRUE);
} else {
- $this->_debug("S: ".($errmsg ? $errmsg : ldap_error($this->conn)));
+ $this->_debug("S: " . ($errmsg ? $errmsg : ldap_error($this->conn)));
new PEAR_Error("Something went terribly wrong");
}
} else {
@@ -1178,8 +1201,12 @@ class Net_LDAP3
to an additional filter.
*/
- if (count($search) > 1) {
+ $this->_debug("Net_LDAP3::search_entries with search " . var_export($search, TRUE));
+
+ if (is_array($search) && array_key_exists('params', $search)) {
+ $this->_debug("C: Composing search filter");
$_search = $this->search_filter($search);
+ $this->_debug("C: Search filter: $_search");
if (!empty($_search)) {
$this->additional_filter = $_search;
@@ -1421,28 +1448,11 @@ class Net_LDAP3
}
private function config_set_return_attributes($attribute_names = Array('entrydn')) {
+ $this->_debug("setting return attributes: " . var_export($attribute_names, TRUE));
$this->return_attributes = (Array)($attribute_names);
}
/**
- * Shortcut to ldap_delete()
- */
- private function delete_entry($entry_dn)
- {
- $this->_debug("LDAP: C: Delete $entry_dn");
-
- if (ldap_delete($this->conn, $entry_dn) === FALSE) {
- $this->_debug("LDAP: S: " . ldap_error($this->conn));
- $this->_debug("LDAP: Delete failed. " . ldap_error($this->conn));
- return FALSE;
- }
-
- $this->_debug("LDAP: S: OK");
-
- return TRUE;
- }
-
- /**
* Find a matching VLV
*/
private function find_vlv($base_dn, $filter, $scope, $sort_attrs = NULL) {
@@ -1454,11 +1464,15 @@ class Net_LDAP3
return FALSE;
}
- if ($this->_vlv_indexes_and_searches === NULL) {
+ if (empty($this->_vlv_indexes_and_searches)) {
$this->_debug("No VLV information available yet, refreshing");
$this->find_vlv_indexes_and_searches(TRUE);
}
+ if (empty($this->_vlv_indexes_and_searches) && !is_array($this->_vlv_indexes_and_searches)) {
+ return FALSE;
+ }
+
$this->_debug("Existing vlv index and search information", $this->_vlv_indexes_and_searches);
if (array_key_exists($base_dn, $this->_vlv_indexes_and_searches) && !empty($this->_vlv_indexes_and_searches[$base_dn])) {
@@ -1514,13 +1528,13 @@ class Net_LDAP3
$return_attributes = $this->return_attributes;
- $this->return_attributes = Array('*');
-
$config_root_dn = $this->config_get('config_root_dn', NULL);
if (empty($config_root_dn)) {
return Array();
}
+ $this->return_attributes = Array('*');
+
$search_result = ldap_search(
$this->conn,
$config_root_dn,
@@ -1535,12 +1549,12 @@ class Net_LDAP3
if ($vlv_searches->count() < 1) {
$this->_debug("Empty result from search for '(objectclass=vlvsearch)' on '$config_root_dn'");
+ $this->return_attributes = $return_attributes;
return;
} else {
$vlv_searches = $vlv_searches->entries(TRUE);
}
-
foreach ($vlv_searches as $vlv_search_dn => $vlv_search_attrs) {
// The attributes we are interested in are as follows:
@@ -2101,18 +2115,34 @@ class Net_LDAP3
*
* @return string Quoted string
*/
- private static function _quote_string($str, $dn=FALSE)
+ private static function _quote_string($str, $is_dn = FALSE)
{
// take firt entry if array given
- if (is_array($str))
+ if (is_array($str)) {
$str = reset($str);
+ }
- if ($dn)
- $replace = Array(','=>'\2c', '='=>'\3d', '+'=>'\2b', '<'=>'\3c',
- '>'=>'\3e', ';'=>'\3b', '\\'=>'\5c', '"'=>'\22', '#'=>'\23');
- else
- $replace = Array('*'=>'\2a', '('=>'\28', ')'=>'\29', '\\'=>'\5c',
- '/'=>'\2f');
+ if ($is_dn) {
+ $replace = array(
+ ',' => '\2c',
+ '=' => '\3d',
+ '+' => '\2b',
+ '<' => '\3c',
+ '>' => '\3e',
+ ';' => '\3b',
+ "\\"=> '\5c',
+ '"' => '\22',
+ '#' => '\23'
+ );
+ } else {
+ $replace = array(
+ '*' => '\2a',
+ '(' => '\28',
+ ')' => '\29',
+ "\\" => '\5c',
+ '/' => '\2f'
+ );
+ }
return strtr($str, $replace);
}
diff --git a/lib/Net/LDAP3/Result.php b/lib/Net/LDAP3/Result.php
index ca68326..29f2c63 100644
--- a/lib/Net/LDAP3/Result.php
+++ b/lib/Net/LDAP3/Result.php
@@ -2,25 +2,27 @@
/*
+-----------------------------------------------------------------------+
- | program/include/rcube_ldap_result.php |
+ | Net/LDAP3/Result.php |
+ | |
+ | Based on rcube_ldap_result.php created by the Roundcube Webmail |
+ | client development team. |
| |
- | This file is part of the Roundcube Webmail client |
| Copyright (C) 2006-2012, The Roundcube Dev Team |
| Copyright (C) 2012, Kolab Systems AG |
| |
| Licensed under the GNU General Public License version 3 or |
- | any later version with exceptions for skins & plugins. |
+ | any later version with exceptions for plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
- | Model class that represents an LDAP search result |
+ | Provide advanced functionality for accessing LDAP directories |
| |
+-----------------------------------------------------------------------+
- | Author: Thomas Bruederli <roundcube@gmail.com> |
+ | Authors: Thomas Bruederli <roundcube@gmail.com> |
+ | Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> |
+-----------------------------------------------------------------------+
*/
-
/**
* Model class representing an LDAP search result
*