Permalink
Browse files

renamed start_tls to startTLS and added an alias function

added setLDAPVersion()
changed bind() to use startTLS() and setLDAPVersion()


git-svn-id: http://svn.php.net/repository/pear/packages/Net_LDAP/trunk@144349 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
Jan Wagner
Jan Wagner committed Nov 14, 2003
1 parent 0cdfb10 commit 662317a5b006ecb03d5593682934252b7f527bb9
Showing with 50 additions and 21 deletions.
  1. +50 −21 LDAP.php
View
@@ -26,9 +26,8 @@
/**
* Net_LDAP - manipulate LDAP servers the right way!
*
- * (the perl Net::LDAP way)
- *
- * @author Tarjei Huse
+ * @author Tarjei Huse
+ * @author Jan Wagner
* @version $Revision$
* @package Net_LDAP
*/
@@ -141,37 +140,35 @@ function bind($config = array())
}
if ($this->_config['host']) {
- $conn = @ldap_connect($this->_config['host'], $this->_config['port']);
+ $this->_link = @ldap_connect($this->_config['host'], $this->_config['port']);
} else {
return $this->raiseError("Host not defined in config. {$this->_config['host']}");
}
- if (!$conn) {
+ if (!$this->_link) {
// there is no good errorcode for this one! I chose 52.
return $this->raiseError("Could not connect to server. ldap_connect failed.",52 );
}
// You must set the version and start tls BEFORE binding!
- // (quite logical when you think of it...
- if ($this->_config['version'] == 3 && !@ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3)) {
- return $this->raiseError("Could not set ldap v3: " . ldap_error($conn),ldap_errno($conn));
+
+ if ($this->_config['version'] != 2 && Net_LDAP::isError($msg = $this->setLDAPVersion())) {
+ return $msg;
}
-
- if ($this->_config['tls'] && !@ldap_start_tls($conn)) {
- return $this->raiseError("TLS not started. Error:" . ldap_error($conn),ldap_errno($conn));
+
+ if ($this->_config['tls'] && Net_LDAP::isError($msg = $this->startTLS())) {
+ return $msg;
}
if (isset($this->_config['dn']) && isset($this->_config['password'])) {
- $bind = @ldap_bind($conn, $this->_config['dn'], $this->_config['password']);
+ $bind = @ldap_bind($this->_link, $this->_config['dn'], $this->_config['password']);
} else {
- $bind = @ldap_bind($conn);
+ $bind = @ldap_bind($this->_link);
}
if (!$bind) {
- return $this->raiseError("Bind failed " . @ldap_error($conn), ldap_errno($conn));
+ return $this->raiseError("Bind failed " . @ldap_error($this->_link), @ldap_errno($this->_link));
}
- $this->_link = $conn;
-
return true;
}
@@ -181,13 +178,24 @@ function bind($config = array())
* @access public
* @return mixed True or Net_LDAP_Error
*/
- function start_tls()
+ function startTLS()
{
- if (!@ldap_set_option($this->_link, LDAP_OPT_PROTOCOL_VERSION, 3)) {
- return $this->raiseError("Could not set ldap v3" . ldap_error($this->_link), ldap_errno($this->_link));
+ if (!@ldap_start_tls($this->_link)) {
+ return $this->raiseError("TLS not started. Error:" . @ldap_error($this->_link), @ldap_errno($this->_link));
}
return true;
}
+
+ /**
+ * alias function of startTLS() for perl-ldap interface
+ *
+ * @see startTLS()
+ */
+ function start_tls()
+ {
+ $args = func_get_args();
+ return call_user_func_array(array( &$this, 'startTLS' ), $args);
+ }
/**
* Close LDAP connection.
@@ -473,7 +481,7 @@ function search($base = null, $filter = null, $params = array())
$attrsonly,
$sizelimit,
$timelimit);
-
+
if ($err = ldap_errno($this->_link)) {
if ($err == 32) {
@@ -515,7 +523,28 @@ function getLDAPVersion()
}
return $version;
}
-
+
+ /**
+ * Set the LDAP_PROTOCOL_VERSION that is used on the connection.
+ *
+ * @param int Version to set
+ * @return mixed Net_LDAP_Error or TRUE
+ */
+ function setLDAPVersion($version = 0)
+ {
+ if (!$version) {
+ $version = $this->_config['version'];
+ }
+ if (!$this->_link) {
+ return $this->raiseError('No valid LDAP link');
+ }
+ if (!@ldap_set_option($this->_link, LDAP_OPT_PROTOCOL_VERSION, $version)) {
+ return $this->raiseError("Could not set LDAP version to $version " .
+ ldap_error($this->_link), ldap_errno($this->_link));
+ }
+ return true;
+ }
+
/**
* Get the Net_LDAP version.
*

0 comments on commit 662317a

Please sign in to comment.