Commit 0c1f93a5 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Merge branch '2-allow-all-kinds-of-bind' into 'master'

Resolve "Allow all kinds of bind"

See merge request !4
parents 90cf8ff9 2187c913
Pipeline #14048 passed with stages
in 1 minute and 11 seconds
......@@ -12,8 +12,8 @@ require 'FusionDirectory/Ldap/autoload.php';
use FusionDirectory\Ldap;
$ldap = new Ldap\Link('ldapi:///');
/* Only EXTERNAL bind is available for now */
$ldap->bind();
/* Bind as EXTERNAL */
$ldap->saslBind('', '', 'EXTERNAL');
/* Make a search */
$list = $ldap->search('ou=people,dc=example,dc=com', '(cn=*)', ['cn'], 'one');
......
......@@ -57,11 +57,11 @@ class Link
/**
* Actually open the connection and bind to the LDAP server.
* Uses EXTERNAL for the bind.
* Uses SASL for the bind.
*
* @throws \FusionDirectory\Ldap\Exception
*/
public function bind (): void
public function saslBind (string $binddn = '', string $password = '', string $mech = '', string $realm = '', string $authc_id = '', string $authz_id = '', string $props = ''): void
{
$cid = ldap_connect($this->hostname);
......@@ -70,14 +70,46 @@ class Link
}
ldap_set_option($cid, LDAP_OPT_PROTOCOL_VERSION, 3);
if ($this->tls) {
ldap_start_tls($cid);
}
if (ldap_sasl_bind($cid, $binddn, $password, $mech, $realm, $authc_id, $authz_id, $props) !== TRUE) {
throw new Exception('Failed to bind to '.$this->hostname);
}
$this->cid = $cid;
}
/**
* Actually open the connection and bind to the LDAP server.
*
* @param array<array{oid:string,iscritical:bool,value:mixed}> $controls
* @throws \FusionDirectory\Ldap\Exception
*/
public function bind (string $dn = '', string $password = '', array $controls = []): void
{
$cid = ldap_connect($this->hostname);
if ($cid === FALSE) {
throw new Exception('Invalid URI: '.$this->hostname);
}
ldap_set_option($cid, LDAP_OPT_PROTOCOL_VERSION, 3);
if ($this->tls) {
ldap_start_tls($cid);
}
if (ldap_sasl_bind($cid, '', '', 'EXTERNAL') !== TRUE) {
$res = ldap_bind_ext($cid, $dn, $password, $controls);
if ($res === FALSE) {
throw new Exception('Failed to bind to '.$this->hostname);
}
$result = new Result($cid, $res);
$result->assert();
$this->cid = $cid;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment