From: Michael M Slusarz Date: Wed, 3 Feb 2010 08:35:17 +0000 (-0700) Subject: Convert Horde_Ldap to H4 format X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=8eaef864016080cc32cdfaff0f56e9a9a779a2cd;p=horde.git Convert Horde_Ldap to H4 format --- diff --git a/framework/Group/Group/kolab.php b/framework/Group/Group/kolab.php index 95ffed94e..d901e20fc 100644 --- a/framework/Group/Group/kolab.php +++ b/framework/Group/Group/kolab.php @@ -1,7 +1,6 @@ _ds, $this->_params['basedn'], $filter); if (!$search) { return PEAR::raiseError(_("Could not reach the LDAP server")); diff --git a/framework/Kolab_Storage/package.xml b/framework/Kolab_Storage/package.xml index ba419e6e3..31e10f22e 100644 --- a/framework/Kolab_Storage/package.xml +++ b/framework/Kolab_Storage/package.xml @@ -153,7 +153,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> pear.horde.org - Horde_LDAP + Ldap pear.horde.org diff --git a/framework/LDAP/LDAP.php b/framework/LDAP/LDAP.php deleted file mode 100644 index b9c471850..000000000 --- a/framework/LDAP/LDAP.php +++ /dev/null @@ -1,91 +0,0 @@ - - * @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; - } -} diff --git a/framework/LDAP/package.xml b/framework/LDAP/package.xml deleted file mode 100644 index 8de8a2645..000000000 --- a/framework/LDAP/package.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - Horde_LDAP - pear.horde.org - LDAP Utility Class - Horde_LDAP:: contains some utility functions for dealing with LDAP -servers and data. - - - Chuck Hagenbuch - chuck - chuck@horde.org - yes - - 2006-05-08 - - - 0.0.2 - 0.0.2 - - - alpha - alpha - - LGPL - * Converted to package.xml 2.0 for pear.horde.org -* Support approximate LDAP searches (requires openldap or another supported server). - - - - - - - - - - - - - 4.0.0 - - - 1.4.0b1 - - - - - - - - 0.0.1 - 0.0.1 - - - alpha - alpha - - 2004-01-12 - LGPL - Initial release as a PEAR package - - - - diff --git a/framework/LDAP/tests/quoteDN.phpt b/framework/LDAP/tests/quoteDN.phpt deleted file mode 100644 index 631efa45f..000000000 --- a/framework/LDAP/tests/quoteDN.phpt +++ /dev/null @@ -1,44 +0,0 @@ ---TEST-- -Horde_LDAP::quoteDN() tests ---FILE-- - ---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 diff --git a/framework/Ldap/lib/Horde/Ldap.php b/framework/Ldap/lib/Horde/Ldap.php new file mode 100644 index 000000000..08d4b4866 --- /dev/null +++ b/framework/Ldap/lib/Horde/Ldap.php @@ -0,0 +1,96 @@ + + * @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: + *
+     * $parts = array(
+     *     0 => array('cn', 'John Smith'),
+     *     1 => array('dc', 'example'),
+     *     2 => array('dc', 'com')
+     * );
+     * 
+ * + * @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; + } + +} diff --git a/framework/Ldap/package.xml b/framework/Ldap/package.xml new file mode 100644 index 000000000..52e4a286f --- /dev/null +++ b/framework/Ldap/package.xml @@ -0,0 +1,92 @@ + + + Ldap + pear.horde.org + Ldap Utility Class + This package contains utility functions for dealing with LDAP servers and data. + + + Chuck Hagenbuch + chuck + chuck@horde.org + yes + + 2010-02-02 + + 0.1.0 + 0.1.0 + + + beta + beta + + LGPL + * Initial Horde 4 package. + + + + + + + + + + + + + + + + + + + + + 5.2.0 + + + 1.5.0 + + + + + + + + + + + 2006-05-08 + + + 0.0.2 + 0.0.2 + + + alpha + alpha + + LGPL + * Converted to package.xml 2.0 for pear.horde.org + * Support approximate LDAP searches (requires openldap or another supported server). + + + + + 0.0.1 + 0.0.1 + + + alpha + alpha + + 2004-01-12 + LGPL + Initial release as a PEAR package + + + + diff --git a/framework/Ldap/test/Horde/Ldap/quoteDN.phpt b/framework/Ldap/test/Horde/Ldap/quoteDN.phpt new file mode 100644 index 000000000..a58ffcb14 --- /dev/null +++ b/framework/Ldap/test/Horde/Ldap/quoteDN.phpt @@ -0,0 +1,44 @@ +--TEST-- +Horde_Ldap::quoteDN() tests +--FILE-- + +--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 diff --git a/turba/lib/Driver/Ldap.php b/turba/lib/Driver/Ldap.php index 62f0d499e..7216f57e5 100644 --- a/turba/lib/Driver/Ldap.php +++ b/turba/lib/Driver/Ldap.php @@ -427,7 +427,7 @@ class Turba_Driver_Ldap extends Turba_Driver $pairs[] = array($param, $attributes[$param]); } } - return $this->_quoteDN($pairs); + return Horde_Ldap::quoteDN($pairs); } /** @@ -462,7 +462,7 @@ class Turba_Driver_Ldap extends Turba_Driver } 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'])) { @@ -471,7 +471,7 @@ class Turba_Driver_Ldap extends Turba_Driver $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']))); } } } @@ -759,41 +759,4 @@ class Turba_Driver_Ldap extends Turba_Driver 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; - } - }