X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fabook_ldap_server.php;h=e60f8bd236b5d399ae08099a84774869bddeef73;hb=d74abf737c7fbbb372fe5bfa54f4341339b60ba5;hp=96e433e8b9e5fe8b89d959bd1a0b356aeb887692;hpb=97445d7d882729c7b222b4f35395b61e31d5049e;p=squirrelmail.git diff --git a/functions/abook_ldap_server.php b/functions/abook_ldap_server.php index 96e433e8..e60f8bd2 100644 --- a/functions/abook_ldap_server.php +++ b/functions/abook_ldap_server.php @@ -3,7 +3,7 @@ /** * abook_ldap_server.php * - * Copyright (c) 1999-2002 The Squirrelmail Project Team + * Copyright (c) 1999-2004 The SquirrelMail Project Team * Licensed under the GNU GPL. For full terms see the file COPYING. * * Address book backend for LDAP server @@ -20,13 +20,22 @@ * ? maxrows => Maximum # of rows in search result * ? timeout => Timeout for LDAP operations (in seconds, default: 30) * Might not work for all LDAP libraries or servers. + * ? binddn => LDAP Bind DN. + * ? bindpw => LDAP Bind Password. + * ? protocol => LDAP Bind protocol. * * NOTE. This class should not be used directly. Use the * "AddressBook" class instead. * - * $Id$ + * @version $Id$ + * @package squirrelmail + * @subpackage addressbook */ +/** + * Undocumented class - fixme + * @package squirrelmail + */ class abook_ldap_server extends addressbook_backend { var $btype = 'remote'; var $bname = 'ldap_server'; @@ -41,6 +50,9 @@ class abook_ldap_server extends addressbook_backend { var $bound = false; /* True if LDAP server is bound */ var $maxrows = 250; /* Max rows in result */ var $timeout = 30; /* Timeout for LDAP operations (in seconds) */ + var $binddn = ''; /* DN to bind to (non-anonymous bind) */ + var $bindpw = ''; /* password to bind with (non-anonymous bind) */ + var $protocol = ''; /* protocol used to connect to ldap server */ /* Constructor. Connects to database */ function abook_ldap_server($param) { @@ -63,6 +75,15 @@ class abook_ldap_server extends addressbook_backend { if(isset($param['timeout'])) { $this->timeout = $param['timeout']; } + if(isset($param['binddn'])) { + $this->binddn = $param['binddn']; + } + if(isset($param['bindpw'])) { + $this->bindpw = $param['bindpw']; + } + if(isset($param['protocol'])) { + $this->protocol = $param['protocol']; + } if(empty($param['name'])) { $this->sname = 'LDAP: ' . $param['host']; } @@ -94,15 +115,35 @@ class abook_ldap_server extends addressbook_backend { return $this->set_error('ldap_connect failed'); } } - - if(!@ldap_bind($this->linkid)) { - if(function_exists('ldap_error')) { - return $this->set_error(ldap_error($this->linkid)); - } else { - return $this->set_error('ldap_bind failed'); - } + + if(!empty($this->protocol)) { + if(!@ldap_set_option($this->linkid, LDAP_OPT_PROTOCOL_VERSION, $this->protocol)) { + if(function_exists('ldap_error')) { + return $this->set_error(ldap_error($this->linkid)); + } else { + return $this->set_error('ldap_set_option failed'); + } + } + } + + if(!empty($this->binddn)) { + if(!@ldap_bind($this->linkid, $this->binddn, $this->bindpw)) { + if(function_exists('ldap_error')) { + return $this->set_error(ldap_error($this->linkid)); + } else { + return $this->set_error('authenticated ldap_bind failed'); + } + } + } else { + if(!@ldap_bind($this->linkid)) { + if(function_exists('ldap_error')) { + return $this->set_error(ldap_error($this->linkid)); + } else { + return $this->set_error('anonymous ldap_bind failed'); + } + } } - + $this->bound = true; return true; @@ -157,18 +198,10 @@ class abook_ldap_server extends addressbook_backend { return false; } - /* Do the search. Use improved ldap_search() if PHP version is - * 4.0.2 or newer. */ - if(sqCheckPHPVersion(4, 0, 2)) { - $sret = @ldap_search($this->linkid, $this->basedn, $expression, - array('dn', 'o', 'ou', 'sn', 'givenname', - 'cn', 'mail', 'telephonenumber'), - 0, $this->maxrows, $this->timeout); - } else { - $sret = @ldap_search($this->linkid, $this->basedn, $expression, - array('dn', 'o', 'ou', 'sn', 'givenname', - 'cn', 'mail', 'telephonenumber')); - } + $sret = @ldap_search($this->linkid, $this->basedn, $expression, + array('dn', 'o', 'ou', 'sn', 'givenname', + 'cn', 'mail', 'telephonenumber'), + 0, $this->maxrows, $this->timeout); /* Should get error from server using the ldap_error() function, * but it only exist in the PHP LDAP documentation. */ @@ -264,4 +297,4 @@ class abook_ldap_server extends addressbook_backend { * * Careful with this -- it could get quite large for big sites. */ } -?> \ No newline at end of file +?>