<?php
require_once 'Horde/Group/ldap.php';
-require_once 'Horde/LDAP.php';
/**
* The Group_kolab class provides a Kolab backend for the Horde groups
*/
function dnForMail($mail)
{
- $filter = '(&(objectclass=kolabInetOrgPerson)(mail=' . Horde_LDAP::quote($mail) . '))';
+ $filter = '(&(objectclass=kolabInetOrgPerson)(mail=' . Horde_Ldap::quote($mail) . '))';
$search = @ldap_search($this->_ds, $this->_params['basedn'], $filter);
if (!$search) {
return PEAR::raiseError(_("Could not reach the LDAP server"));
<channel>pear.horde.org</channel>
</package>
<package>
- <name>Horde_LDAP</name>
+ <name>Ldap</name>
<channel>pear.horde.org</channel>
</package>
<package>
+++ /dev/null
-<?php
-/**
- * This is a utility class, every method is static.
- *
- * Copyright 1999-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @package Horde_LDAP
- */
-class Horde_LDAP
-{
- /**
- * Return a boolean expression using the specified operator.
- *
- * @param string $lhs The attribute to test.
- * @param string $op The operator.
- * @param string $rhs The comparison value.
- * @param array $params Any additional parameters for the operator.
- *
- * @return string The LDAP search fragment.
- */
- public static function buildClause($lhs, $op, $rhs, $params = array())
- {
- switch ($op) {
- case 'LIKE':
- if (empty($rhs)) {
- return '(' . $lhs . '=*)';
- } elseif (!empty($params['begin'])) {
- return sprintf('(|(%s=%s*)(%s=* %s*))', $lhs, Horde_LDAP::quote($rhs), $lhs, Horde_LDAP::quote($rhs));
- } elseif (!empty($params['approximate'])) {
- return sprintf('(%s=~%s)', $lhs, Horde_LDAP::quote($rhs));
- }
- return sprintf('(%s=*%s*)', $lhs, Horde_LDAP::quote($rhs));
-
- default:
- return sprintf('(%s%s%s)', $lhs, $op, Horde_LDAP::quote($rhs));
- }
- }
-
- /**
- * Escape characters with special meaning in LDAP searches.
- *
- * @param string $clause The string to escape.
- *
- * @return string The escaped string.
- */
- public static function quote($clause)
- {
- return str_replace(array('\\', '(', ')', '*', "\0"),
- array('\\5c', '\(', '\)', '\*', "\\00"),
- $clause);
- }
-
- /**
- * Take an array of DN elements and properly quote it according to RFC
- * 1485.
- *
- * @param array $parts An array of tuples containing the attribute
- * name and that attribute's value which make
- * up the DN. Example:
- *
- * $parts = array(0 => array('cn', 'John Smith'),
- * 1 => array('dc', 'example'),
- * 2 => array('dc', 'com'));
- *
- * @return string The properly quoted string DN.
- */
- public static function quoteDN($parts)
- {
- $dn = '';
- $count = count($parts);
- for ($i = 0; $i < $count; $i++) {
- if ($i > 0) {
- $dn .= ',';
- }
- $dn .= $parts[$i][0] . '=';
-
- // See if we need to quote the value.
- if (preg_match('/^\s|\s$|\s\s|[,+="\r\n<>#;]/', $parts[$i][1])) {
- $dn .= '"' . str_replace('"', '\\"', $parts[$i][1]) . '"';
- } else {
- $dn .= $parts[$i][1];
- }
- }
-
- return $dn;
- }
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.4.9" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
-http://pear.php.net/dtd/tasks-1.0.xsd
-http://pear.php.net/dtd/package-2.0
-http://pear.php.net/dtd/package-2.0.xsd">
- <name>Horde_LDAP</name>
- <channel>pear.horde.org</channel>
- <summary>LDAP Utility Class</summary>
- <description>Horde_LDAP:: contains some utility functions for dealing with LDAP
-servers and data.
- </description>
- <lead>
- <name>Chuck Hagenbuch</name>
- <user>chuck</user>
- <email>chuck@horde.org</email>
- <active>yes</active>
- </lead>
- <date>2006-05-08</date>
- <time>22:19:35</time>
- <version>
- <release>0.0.2</release>
- <api>0.0.2</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Converted to package.xml 2.0 for pear.horde.org
-* Support approximate LDAP searches (requires openldap or another supported server).
- </notes>
- <contents>
- <dir name="/">
- <dir name="tests">
- <file name="quoteDN.phpt" role="test" />
- </dir> <!-- //tests -->
- <file baseinstalldir="/Horde" name="LDAP.php" role="php" />
- </dir> <!-- / -->
- </contents>
- <dependencies>
- <required>
- <php>
- <min>4.0.0</min>
- </php>
- <pearinstaller>
- <min>1.4.0b1</min>
- </pearinstaller>
- </required>
- </dependencies>
- <phprelease />
- <changelog>
- <release>
- <version>
- <release>0.0.1</release>
- <api>0.0.1</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2004-01-12</date>
- <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>Initial release as a PEAR package
- </notes>
- </release>
- </changelog>
-</package>
+++ /dev/null
---TEST--
-Horde_LDAP::quoteDN() tests
---FILE--
-<?php
-
-require_once dirname(__FILE__) . '/../LDAP.php';
-
-echo Horde_LDAP::quoteDN(array(array('cn', 'John Smith'),
- array('dc', 'example'),
- array('dc', 'com'))) . "\n";
-
-echo Horde_LDAP::quoteDN(array(array('cn', 'Smith, John'),
- array('dc', 'example'),
- array('dc', 'com'))) . "\n";
-
-echo Horde_LDAP::quoteDN(array(array('cn', ' John Smith'),
- array('dc', 'example'),
- array('dc', 'com'))) . "\n";
-
-echo Horde_LDAP::quoteDN(array(array('cn', 'John Smith '),
- array('dc', 'example'),
- array('dc', 'com'))) . "\n";
-
-echo Horde_LDAP::quoteDN(array(array('cn', 'John Smith'),
- array('dc', 'example'),
- array('dc', 'com'))) . "\n";
-
-echo Horde_LDAP::quoteDN(array(array('cn', 'John+Smith'),
- array('dc', 'example'),
- array('dc', 'com'))) . "\n";
-
-echo Horde_LDAP::quoteDN(array(array('cn', 'John "Bugsy" Smith'),
- array('dc', 'example'),
- array('dc', 'com'))) . "\n";
-
-?>
---EXPECT--
-cn=John Smith,dc=example,dc=com
-cn="Smith, John",dc=example,dc=com
-cn=" John Smith",dc=example,dc=com
-cn="John Smith ",dc=example,dc=com
-cn="John Smith",dc=example,dc=com
-cn="John+Smith",dc=example,dc=com
-cn="John \"Bugsy\" Smith",dc=example,dc=com
--- /dev/null
+<?php
+/**
+ * This is a utility class, every method is static.
+ *
+ * Copyright 1999-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @category Horde
+ * @package Horde_Ldap
+ */
+class Horde_Ldap
+{
+ /**
+ * Return a boolean expression using the specified operator.
+ *
+ * @param string $lhs The attribute to test.
+ * @param string $op The operator.
+ * @param string $rhs The comparison value.
+ * @param array $params Any additional parameters for the operator.
+ *
+ * @return string The LDAP search fragment.
+ */
+ static public function buildClause($lhs, $op, $rhs, $params = array())
+ {
+ switch ($op) {
+ case 'LIKE':
+ if (empty($rhs)) {
+ return '(' . $lhs . '=*)';
+ } elseif (!empty($params['begin'])) {
+ return sprintf('(|(%s=%s*)(%s=* %s*))', $lhs, self::quote($rhs), $lhs, self::quote($rhs));
+ } elseif (!empty($params['approximate'])) {
+ return sprintf('(%s=~%s)', $lhs, self::quote($rhs));
+ }
+ return sprintf('(%s=*%s*)', $lhs, self::quote($rhs));
+
+ default:
+ return sprintf('(%s%s%s)', $lhs, $op, self::quote($rhs));
+ }
+ }
+
+ /**
+ * Escape characters with special meaning in LDAP searches.
+ *
+ * @param string $clause The string to escape.
+ *
+ * @return string The escaped string.
+ */
+ static public function quote($clause)
+ {
+ return str_replace(array('\\', '(', ')', '*', "\0"),
+ array('\\5c', '\(', '\)', '\*', "\\00"),
+ $clause);
+ }
+
+ /**
+ * Take an array of DN elements and properly quote it according to RFC
+ * 1485.
+ *
+ * @param array $parts An array of tuples containing the attribute
+ * name and that attribute's value which make
+ * up the DN. Example:
+ * <pre>
+ * $parts = array(
+ * 0 => array('cn', 'John Smith'),
+ * 1 => array('dc', 'example'),
+ * 2 => array('dc', 'com')
+ * );
+ * </pre>
+ *
+ * @return string The properly quoted string DN.
+ */
+ static public function quoteDN($parts)
+ {
+ $dn = '';
+
+ for ($i = 0, $cnt = count($parts); $i < $cnt; ++$i) {
+ if ($i > 0) {
+ $dn .= ',';
+ }
+ $dn .= $parts[$i][0] . '=';
+
+ // See if we need to quote the value.
+ if (preg_match('/^\s|\s$|\s\s|[,+="\r\n<>#;]/', $parts[$i][1])) {
+ $dn .= '"' . str_replace('"', '\\"', $parts[$i][1]) . '"';
+ } else {
+ $dn .= $parts[$i][1];
+ }
+ }
+
+ return $dn;
+ }
+
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.4.9" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
+http://pear.php.net/dtd/tasks-1.0.xsd
+http://pear.php.net/dtd/package-2.0
+http://pear.php.net/dtd/package-2.0.xsd">
+ <name>Ldap</name>
+ <channel>pear.horde.org</channel>
+ <summary>Ldap Utility Class</summary>
+ <description>This package contains utility functions for dealing with LDAP servers and data.
+ </description>
+ <lead>
+ <name>Chuck Hagenbuch</name>
+ <user>chuck</user>
+ <email>chuck@horde.org</email>
+ <active>yes</active>
+ </lead>
+ <date>2010-02-02</date>
+ <version>
+ <release>0.1.0</release>
+ <api>0.1.0</api>
+ </version>
+ <stability>
+ <release>beta</release>
+ <api>beta</api>
+ </stability>
+ <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
+ <notes>* Initial Horde 4 package.
+ </notes>
+ <contents>
+ <dir name="/">
+ <dir name="lib">
+ <dir name="Horde">
+ <file name="Ldap.php" role="php" />
+ </dir> <!-- /lib/Horde -->
+ </dir> <!-- /lib -->
+ <dir name="test">
+ <dir name="Horde">
+ <dir name="Ldap">
+ <file name="quoteDN.phpt" role="test" />
+ </dir> <!-- /test/Horde/Ldap -->
+ </dir> <!-- /test/Horde -->
+ </dir> <!-- /test -->
+ </dir> <!-- / -->
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>5.2.0</min>
+ </php>
+ <pearinstaller>
+ <min>1.5.0</min>
+ </pearinstaller>
+ </required>
+ </dependencies>
+ <phprelease>
+ <filelist>
+ <install name="lib/Horde/Ldap.php" as="Horde/Ldap.php" />
+ </filelist>
+ </phprelease>
+ <changelog>
+ <release>
+ <date>2006-05-08</date>
+ <time>22:19:35</time>
+ <version>
+ <release>0.0.2</release>
+ <api>0.0.2</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
+ <notes>* Converted to package.xml 2.0 for pear.horde.org
+ * Support approximate LDAP searches (requires openldap or another supported server).
+ </notes>
+ </release>
+ <release>
+ <version>
+ <release>0.0.1</release>
+ <api>0.0.1</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <date>2004-01-12</date>
+ <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
+ <notes>Initial release as a PEAR package
+ </notes>
+ </release>
+ </changelog>
+</package>
--- /dev/null
+--TEST--
+Horde_Ldap::quoteDN() tests
+--FILE--
+<?php
+
+require_once dirname(__FILE__) . '/../../../lib/Horde/Ldap.php';
+
+echo Horde_Ldap::quoteDN(array(array('cn', 'John Smith'),
+ array('dc', 'example'),
+ array('dc', 'com'))) . "\n";
+
+echo Horde_Ldap::quoteDN(array(array('cn', 'Smith, John'),
+ array('dc', 'example'),
+ array('dc', 'com'))) . "\n";
+
+echo Horde_Ldap::quoteDN(array(array('cn', ' John Smith'),
+ array('dc', 'example'),
+ array('dc', 'com'))) . "\n";
+
+echo Horde_Ldap::quoteDN(array(array('cn', 'John Smith '),
+ array('dc', 'example'),
+ array('dc', 'com'))) . "\n";
+
+echo Horde_Ldap::quoteDN(array(array('cn', 'John Smith'),
+ array('dc', 'example'),
+ array('dc', 'com'))) . "\n";
+
+echo Horde_Ldap::quoteDN(array(array('cn', 'John+Smith'),
+ array('dc', 'example'),
+ array('dc', 'com'))) . "\n";
+
+echo Horde_Ldap::quoteDN(array(array('cn', 'John "Bugsy" Smith'),
+ array('dc', 'example'),
+ array('dc', 'com'))) . "\n";
+
+?>
+--EXPECT--
+cn=John Smith,dc=example,dc=com
+cn="Smith, John",dc=example,dc=com
+cn=" John Smith",dc=example,dc=com
+cn="John Smith ",dc=example,dc=com
+cn="John Smith",dc=example,dc=com
+cn="John+Smith",dc=example,dc=com
+cn="John \"Bugsy\" Smith",dc=example,dc=com
$pairs[] = array($param, $attributes[$param]);
}
}
- return $this->_quoteDN($pairs);
+ return Horde_Ldap::quoteDN($pairs);
}
/**
} else {
if (isset($vals['field'])) {
$rhs = Horde_String::convertCharset($vals['test'], Horde_Nls::getCharset(), $this->_params['charset']);
- $clause .= Horde_LDAP::buildClause($vals['field'], $vals['op'], $rhs, array('begin' => !empty($vals['begin'])));
+ $clause .= Horde_Ldap::buildClause($vals['field'], $vals['op'], $rhs, array('begin' => !empty($vals['begin'])));
} else {
foreach ($vals as $test) {
if (!empty($test['OR'])) {
$clause .= '(&' . $this->_buildSearchQuery($test) . ')';
} else {
$rhs = Horde_String::convertCharset($test['test'], Horde_Nls::getCharset(), $this->_params['charset']);
- $clause .= Horde_LDAP::buildClause($test['field'], $test['op'], $rhs, array('begin' => !empty($vals['begin'])));
+ $clause .= Horde_Ldap::buildClause($test['field'], $test['op'], $rhs, array('begin' => !empty($vals['begin'])));
}
}
}
return $_schema;
}
- /**
- * Take an array of DN elements and properly quote it according to
- * RFC 1485.
- *
- * @see Horde_LDAP::quoteDN()
- *
- * @param array $parts An array of tuples containing the attribute
- * name and that attribute's value which make
- * up the DN. Example:
- *
- * $parts = array(0 => array('cn', 'John Smith'),
- * 1 => array('dc', 'example'),
- * 2 => array('dc', 'com'));
- *
- * @return string The properly quoted string DN.
- */
- function _quoteDN($parts)
- {
- $dn = '';
- $count = count($parts);
- for ($i = 0; $i < $count; $i++) {
- if ($i > 0) {
- $dn .= ',';
- }
- $dn .= $parts[$i][0] . '=';
-
- /* See if we need to quote the value. */
- if (preg_match('/^\s|\s$|\s\s|[,+="\r\n<>#;]/', $parts[$i][1])) {
- $dn .= '"' . str_replace('"', '\\"', $parts[$i][1]) . '"';
- } else {
- $dn .= $parts[$i][1];
- }
- }
-
- return $dn;
- }
-
}