Source code for file /joomla/client/ldap.php
Documentation is available at ldap.php
* @version $Id: ldap.php 6704 2007-02-23 11:16:43Z pasamio $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software and parts of it may contain or be derived from the
* GNU General Public License or other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
* @package Joomla.Framework
/** @var string Hostname of LDAP server
/** @var bool Authorization Method to use
/** @var int Port of LDAP server
/** @var string Base DN (e.g. o=MyDir)
/** @var string User DN (e.g. cn=Users,o=MyDir)
/** @var string Search String
/** @var boolean Use LDAP Version 3
/** @var boolean No referrals (server transfers)
/** @var boolean Negotiate TLS (encrypted communications)
/** @var string Username to connect to server
/** @var string Password to connect to server
/** @var mixed LDAP Resource Identifier
/** @var string Current DN
* @param object An object of configuration variables
function JLDAP($configObj =
null) {
if (substr($var, 0, 1) !=
'_') {
if ($param =
$configObj->get($var)) {
* @return boolean True if successful
if (!ldap_set_option($this->_resource, LDAP_OPT_PROTOCOL_VERSION, 3)) {
* Sets the DN with some template replacements
* @param string The username
function setDN($username,$nosub=
0) {
* @return string The current dn
* Anonymously Binds to LDAP Directory
* Binds to the LDAP directory
* @param string The username
* @param string The password
function bind($username =
null, $password =
null, $nosub =
0) {
$this->setDN($username,$nosub);
* Perform an LDAP search using comma seperated search strings
* @param string search string of search values
foreach($results as $key=>
$result) {
$results[$key] =
'('.
$result.
')';
return $this->search($results);
* @param array Search Filters (array of strings)
* @param string DN Override
* @return array Multidimensional array of results
function search($filters, $dnoverride =
null) {
foreach ($filters as $search_filter) {
$search_result =
ldap_search($resource, $dn, $search_filter);
if ($search_result &&
($count =
ldap_count_entries($resource, $search_result)) >
0) {
for ($i =
0; $i <
$count; $i++
) {
$attributes[$i] =
Array ();
$firstentry =
ldap_first_entry($resource, $search_result);
$firstentry =
ldap_next_entry($resource, $firstentry);
$attributes_array =
ldap_get_attributes($resource, $firstentry); // load user-specified attributes
// ldap returns an array of arrays, fit this into attributes result array
foreach ($attributes_array as $ki =>
$ai) {
$subcount =
$ai['count'];
$attributes[$i][$ki] =
Array ();
for ($k =
0; $k <
$subcount; $k++
) {
$attributes[$i][$ki][$k] =
$ai[$k];
$attributes[$i]['dn'] =
ldap_get_dn($resource, $firstentry);
* Compare an entry and return a true or false result
* @param string dn The DN which contains the attribute you want to compare
* @param string attribute The attribute whose value you want to compare
* @param string value The value you want to check against the LDAP attribute
* @return mixed result of comparison (true, false, -1 on error)
function compare($dn, $attribute, $value) {
return ldap_compare($this->_resource, $dn, $attribute, $value);
* Converts a dot notation IP address to net address (e.g. for Netware, etc)
* @param string IP Address (e.g. xxx.xxx.xxx.xxx)
* @return string Net address
foreach ($parts as $int) {
* extract readable network address from the LDAP encoded networkAddress attribute.
* @author Jay Burrell, Systems & Networks, Mississippi State University
* Please keep this document block and author attribution in place.
* Novell Docs, see: http://developer.novell.com/ndk/doc/ndslib/schm_enu/data/sdk5624.html#sdk5624
* for Address types: http://developer.novell.com/ndk/doc/ndslib/index.html?page=/ndk/doc/ndslib/schm_enu/data/sdk4170.html
* taggedData = uint32String "#" octetstring
* byte 0 = uint32String = Address Type: 0= IPX Address; 1 = IP Address
* byte 1 = char = "#" - separator
* byte 2+ = octetstring - the ordinal value of the address
* Note: with eDirectory 8.6.2, the IP address (type 1) returns
* correctly, however, an IPX address does not seem to. eDir 8.7 may
$networkaddress =
substr($networkaddress, 2); // throw away bytes 0 and 1 which should be the addrtype and the "#" separator
$len =
strlen($networkaddress);
for ($i =
0; $i <
$len; $i +=
1) {
$byte =
substr($networkaddress, $i, 1);
if ($addrtype ==
1) { // dot separate IP addresses...
if ($addrtype ==
1) { // strip last period from end of $addr
$addr .=
"address not available.";
return Array('protocol'=>
$addrtypes[$addrtype], 'address'=>
$addr);