From 9647c3751661e6fb93746bf474484e47ff0ff2b9 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 14 Feb 2014 14:38:52 +0000 Subject: [PATCH] Fix LDAP DN concatenation, allow to define a search base --- library/Icinga/Protocol/Ldap/Connection.php | 3 ++- library/Icinga/Protocol/Ldap/Node.php | 2 +- library/Icinga/Protocol/Ldap/Query.php | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Protocol/Ldap/Connection.php b/library/Icinga/Protocol/Ldap/Connection.php index aca8d42aa..957161c0a 100644 --- a/library/Icinga/Protocol/Ldap/Connection.php +++ b/library/Icinga/Protocol/Ldap/Connection.php @@ -235,9 +235,10 @@ class Connection // We do not support pagination right now, and there is no chance to // do so for PHP < 5.4. Warnings about "Sizelimit exceeded" will // therefore not be hidden right now. + $base = $query->hasBase() ? $query->getBase() : $this->root_dn; $results = @ldap_search( $this->ds, - $this->root_dn, + $base, (string) $query, $fields, 0, // Attributes and values diff --git a/library/Icinga/Protocol/Ldap/Node.php b/library/Icinga/Protocol/Ldap/Node.php index e4eee9e43..0332de7b3 100644 --- a/library/Icinga/Protocol/Ldap/Node.php +++ b/library/Icinga/Protocol/Ldap/Node.php @@ -90,6 +90,6 @@ class Node extends Root */ public function getDN() { - return $this->parent->getDN() . '.' . $this->getRDN(); + return $this->getRDN() . ',' . $this->parent->getDN(); } } diff --git a/library/Icinga/Protocol/Ldap/Query.php b/library/Icinga/Protocol/Ldap/Query.php index 92289fbbc..eeb9cf8ef 100644 --- a/library/Icinga/Protocol/Ldap/Query.php +++ b/library/Icinga/Protocol/Ldap/Query.php @@ -30,6 +30,7 @@ class Query protected $limit_offset; protected $sort_columns = array(); protected $count; + protected $base; /** * Constructor @@ -42,6 +43,22 @@ class Query $this->connection = $connection; } + public function setBase($base) + { + $this->base = $base; + return $this; + } + + public function hasBase() + { + return $this->base !== null; + } + + public function getBase() + { + return $this->base; + } + /** * Count result set, ignoring limits *