cvs: pear /Auth/Container LDAP.php
| From: | Adam Ashley | Date: | Mon, 27 Mar 2006 05:39:28 +0000 |
| Subject: | cvs: pear /Auth/Container LDAP.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-39362@lists.php.net to get a copy of this message | ||
aashley Mon Mar 27 05:39:28 2006 UTC
Modified files:
/pear/Auth/Container LDAP.php
Log:
Changes to LDAP connection handling
- Only connect as needed.
- Failures in connection will no longer abort script instead bubble up PEAR_Error objects.
http://cvs.php.net/viewcvs.cgi/pear/Auth/Container/LDAP.php?r1=1.31&r2=1.32&diff_format=u
Index: pear/Auth/Container/LDAP.php
diff -u pear/Auth/Container/LDAP.php:1.31 pear/Auth/Container/LDAP.php:1.32
--- pear/Auth/Container/LDAP.php:1.31 Mon Mar 27 05:23:34 2006
+++ pear/Auth/Container/LDAP.php Mon Mar 27 05:39:28 2006
@@ -19,7 +19,7 @@
* @author Hugues Peeters <hugues.peeters@claroline.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version CVS: $Id: LDAP.php,v 1.31 2006/03/27 05:23:34 aashley Exp $
+ * @version CVS: $Id: LDAP.php,v 1.32 2006/03/27 05:39:28 aashley Exp $
* @link http://pear.php.net/package/Auth
*/
@@ -184,7 +184,7 @@
* @author Hugues Peeters <hugues.peeters@claroline.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: @package_version@ File: $Revision: 1.31 $
+ * @version Release: @package_version@ File: $Revision: 1.32 $
* @link http://pear.php.net/package/Auth
*/
class Auth_Container_LDAP extends Auth_Container
@@ -229,6 +229,29 @@
}
// }}}
+ // {{{ _prepare()
+
+ /**
+ * Prepare LDAP connection
+ *
+ * This function checks if we have already opened a connection to
+ * the LDAP server. If that's not the case, a new connection is opened.
+ *
+ * @access private
+ * @return mixed True or a PEAR error object.
+ */
+ function _prepare()
+ {
+ if (!$this->_isValidLink()) {
+ $res = $this->_connect();
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+ }
+ return true;
+ }
+
+ // }}}
// {{{ _connect()
/**
@@ -281,6 +304,8 @@
return PEAR::raiseError("Auth_Container_LDAP: Could not bind to LDAP
server.", 41);
}
$this->_debug('Binding was successful', __LINE__);
+
+ return true;
}
// }}}
@@ -309,6 +334,11 @@
*/
function _getBaseDN()
{
+ $err = $this->_prepare();
+ if ($err !== true)) {
+ return PEAR::raiseError($err->getMessage(), $err->getCode());
+ }
+
if ($this->options['basedn'] == "" &&
$this->_isValidLink()) {
$this->_debug("basedn not set, searching via namingContexts.", __LINE__);
@@ -332,7 +362,7 @@
// if base ist still not set, raise error
if ($this->options['basedn'] == "") {
- return PEAR::raiseError("Auth_Container_LDAP: LDAP search base not
specified!", 41, PEAR_ERROR_DIE);
+ return PEAR::raiseError("Auth_Container_LDAP: LDAP search base not
specified!", 41);
}
return true;
}
@@ -483,8 +513,15 @@
*/
function fetchData($username, $password)
{
- $this->_connect();
- $this->_getBaseDN();
+ $err = $this->_prepare();
+ if ($err !== true)) {
+ return PEAR::raiseError($err->getMessage(), $err->getCode());
+ }
+
+ $err = $this->_getBaseDN();
+ if ($err !== true)) {
+ return PEAR::raiseError($err->getMessage(), $err->getCode());
+ }
// UTF8 Encode username for LDAPv3
if (@ldap_get_option($this->conn_id, LDAP_OPT_PROTOCOL_VERSION, $ver) && $ver ==
3) {
@@ -604,7 +641,7 @@
* Validate group membership
*
* Searches the LDAP server for group membership of the
- * authenticated user. Quotes all LDAP filter meta characters in
+ * supplied username. Quotes all LDAP filter meta characters in
* the user name before querying the LDAP server.
*
* @param string Distinguished Name of the authenticated User
@@ -612,6 +649,11 @@
*/
function checkGroup($user)
{
+ $err = $this->_prepare();
+ if ($err !== true)) {
+ return PEAR::raiseError($err->getMessage(), $err->getCode());
+ }
+
// make filter
$filter = sprintf('(&(%s=%s)(%s=%s)%s)',
$this->options['groupattr'],