Horde_Ldap
in package
The main Horde_Ldap class.
Copyright 2003-2007 Tarjej Huse, Jan Wagner, Del Elson, Benedikt Hallinger Copyright 2009-2017 Horde LLC (http://www.horde.org/)
Tags
Table of Contents
- $_config : array<string|int, mixed>
- Class configuration array.
- $_downHostList : array<string|int, mixed>
- List of hosts that are known to be down.
- $_hostList : array<string|int, mixed>
- List of hosts we try to establish a connection to.
- $_link : resource
- LDAP resource link.
- $_rootDSE : array<string|int, mixed>
- Cache for rootDSE objects.
- $_schema : Horde_Ldap_Schema
- Schema object.
- $_schemaAttrs : array<string|int, mixed>
- Cache for attribute encoding checks.
- __construct() : mixed
- Constructor.
- __destruct() : mixed
- Destructor.
- add() : mixed
- Adds a new entry to the directory.
- bind() : mixed
- Bind or rebind to the LDAP server.
- buildClause() : string
- Builds an LDAP search filter fragment.
- checkLDAPExtension() : mixed
- Checks if PHP's LDAP extension is loaded.
- copy() : Horde_Ldap_Entry
- Copies an entry to a new location.
- delete() : mixed
- Deletes an entry from the directory.
- disconnect() : mixed
- Closes the LDAP connection.
- errorName() : string
- Returns the string for an LDAP errorcode.
- exists() : bool
- Returns whether a DN exists in the directory.
- findUserDN() : string
- Returns the DN of a user.
- getEntry() : Horde_Ldap_Entry
- Returns a specific entry based on the DN.
- getLink() : resource
- Returns the LDAP link resource.
- getOption() : Horde_Ldap_Error|string
- Returns an LDAP option value.
- getVersion() : int
- Returns the LDAP protocol version that is used on the connection.
- modify() : mixed
- Modifies an LDAP entry on the server.
- move() : mixed
- Renames or moves an entry.
- quote() : string
- Escapes characters with special meaning in LDAP searches.
- quoteDN() : string
- Takes an array of DN elements and properly quotes it according to RFC 1485.
- rootDSE() : Horde_Ldap_RootDse
- Returns a rootDSE object
- schema() : Horde_Ldap_Schema
- Returns a schema object
- search() : Horde_Ldap_Search
- Runs an LDAP search query.
- setOption() : mixed
- Sets an LDAP option.
- setVersion() : mixed
- Sets the LDAP protocol version that is used on the connection.
- startTLS() : mixed
- Starts an encrypted session.
- utf8Decode() : array<string|int, mixed>|Horde_Ldap_Error
- utf8Encode() : array<string|int, mixed>|Horde_Ldap_Error
- _connect() : mixed
- Connects to the LDAP server.
- _quoteRDN() : string
- Takes an RDN array with an attribute name and value and properly quotes it according to RFC 1485.
- _quoteRDNs() : string
- Takes a single or a list of RDN arrays with an attribute name and value and properly quotes it according to RFC 1485.
- _reconnect() : mixed
- Reconnects to the LDAP server.
- setConfig() : mixed
- Sets the internal configuration array.
- utf8() : array<string|int, mixed>
Properties
$_config
Class configuration array.
protected
array<string|int, mixed>
$_config
= array('hostspec' => 'localhost', 'port' => 389, 'version' => 3, 'tls' => \false, 'binddn' => '', 'bindpw' => '', 'basedn' => '', 'options' => array(), 'filter' => '(objectClass=*)', 'scope' => 'sub', 'user' => array(), 'timeout' => 5, 'auto_reconnect' => \false, 'min_backoff' => 1, 'current_backoff' => 1, 'max_backoff' => 32, 'cache' => \false, 'cache_root_dse' => \false, 'cachettl' => 3600)
- hostspec: The LDAP host to connect to (may be an array of several hosts to try).
- port: The server port.
- version: LDAP version (defaults to 3).
- tls: When set, ldap_start_tls() is run after connecting.
- binddn: The DN to bind as when searching.
- bindpw: Password to use when searching LDAP.
- basedn: LDAP base.
- options: Hash of LDAP options to set.
- filter: Default search filter.
- scope: Default search scope.
- user: Configuration parameters for , must contain 'uid', and may contain 'basedn' entries.
- timeout: Connection timeout in seconds (defaults to 5).
- auto_reconnect: If true, the class will automatically attempt to reconnect to the LDAP server in certain failure conditions when attempting a search, or other LDAP operations. Defaults to false. Note that if you set this to true, calls to search() may block indefinitely if there is a catastrophic server failure.
- min_backoff: Minimum reconnection delay period (in seconds).
- current_backof: Initial reconnection delay period (in seconds).
- max_backoff: Maximum reconnection delay period (in seconds).
- cache: A Horde_Cache instance for caching schema requests.
$_downHostList
List of hosts that are known to be down.
protected
array<string|int, mixed>
$_downHostList
= array()
$_hostList
List of hosts we try to establish a connection to.
protected
array<string|int, mixed>
$_hostList
= array()
$_link
LDAP resource link.
protected
resource
$_link
$_rootDSE
Cache for rootDSE objects.
protected
array<string|int, mixed>
$_rootDSE
= array()
Hash with requested rootDSE attr names as key and rootDSE object as value.
Since the RootDSE object itself may request a rootDSE object, caches successful requests. Internally, Horde_Ldap needs several lookups to this object, so caching increases performance significally.
$_schema
Schema object.
protected
Horde_Ldap_Schema
$_schema
Tags
$_schemaAttrs
Cache for attribute encoding checks.
protected
array<string|int, mixed>
$_schemaAttrs
= array()
Hash with attribute names as key and boolean value to determine whether they should be utf8 encoded or not.
Methods
__construct()
Constructor.
public
__construct([array<string|int, mixed> $config = array() ]) : mixed
Parameters
- $config : array<string|int, mixed> = array()
-
Configuration array.
Tags
Return values
mixed —__destruct()
Destructor.
public
__destruct() : mixed
Return values
mixed —add()
Adds a new entry to the directory.
public
add(Horde_Ldap_Entry $entry) : mixed
This also links the entry to the connection used for the add, if it was a fresh entry.
Parameters
- $entry : Horde_Ldap_Entry
-
An LDAP entry.
Tags
Return values
mixed —bind()
Bind or rebind to the LDAP server.
public
bind([string $dn = null ][, string $password = null ]) : mixed
This function binds with the given DN and password to the server. In case no connection has been made yet, it will be started and STARTTLS issued if appropiate.
The internal bind configuration is not being updated, so if you call bind() without parameters, you can rebind with the credentials provided at first connecting to the server.
Parameters
- $dn : string = null
-
DN for binding.
- $password : string = null
-
Password for binding.
Tags
Return values
mixed —buildClause()
Builds an LDAP search filter fragment.
public
static buildClause(string $lhs, string $op, string $rhs[, array<string|int, mixed> $params = array() ]) : string
Parameters
- $lhs : string
-
The attribute to test.
- $op : string
-
The operator.
- $rhs : string
-
The comparison value.
- $params : array<string|int, mixed> = array()
-
Any additional parameters for the operator.
Return values
string —The LDAP search fragment.
checkLDAPExtension()
Checks if PHP's LDAP extension is loaded.
public
static checkLDAPExtension() : mixed
If it is not loaded, it tries to load it manually using PHP's dl(). It knows both windows-dll and *nix-so.
Tags
Return values
mixed —copy()
Copies an entry to a new location.
public
copy(Horde_Ldap_Entry $entry, string $newdn) : Horde_Ldap_Entry
The entry will be immediately copied. Only attributes you have selected will be copied.
Parameters
- $entry : Horde_Ldap_Entry
-
An LDAP entry.
- $newdn : string
-
New FQF-DN of the entry.
Tags
Return values
Horde_Ldap_Entry —The copied entry.
delete()
Deletes an entry from the directory.
public
delete(string|Horde_Ldap_Entry $dn[, bool $recursive = false ]) : mixed
Parameters
- $dn : string|Horde_Ldap_Entry
-
DN string or Horde_Ldap_Entry.
- $recursive : bool = false
-
Should we delete all children recursivelx as well?
Tags
Return values
mixed —disconnect()
Closes the LDAP connection.
public
disconnect() : mixed
Return values
mixed —errorName()
Returns the string for an LDAP errorcode.
public
static errorName(int $errorcode) : string
Made to be able to make better errorhandling. Function based on DB::errorMessage().
Hint: The best description of the errorcodes is found here: http://www.directory-info.com/Ldap/LDAPErrorCodes.html
Parameters
- $errorcode : int
-
An error code.
Return values
string —The description for the error.
exists()
Returns whether a DN exists in the directory.
public
exists(string|Horde_Ldap_Entry $dn) : bool
Parameters
- $dn : string|Horde_Ldap_Entry
-
The DN of the object to test.
Tags
Return values
bool —True if the DN exists.
findUserDN()
Returns the DN of a user.
public
findUserDN(string $user) : string
The purpose is to quickly find the full DN of a user so it can be used to re-bind as this user. This method requires the 'user' configuration parameter to be set.
Parameters
- $user : string
-
The user to find.
Tags
Return values
string —The user's full DN.
getEntry()
Returns a specific entry based on the DN.
public
getEntry(string $dn[, array<string|int, mixed> $attributes = array() ]) : Horde_Ldap_Entry
Parameters
- $dn : string
-
DN of the entry that should be fetched.
- $attributes : array<string|int, mixed> = array()
-
Array of Attributes to select. If ommitted, all attributes are fetched.
Tags
Return values
Horde_Ldap_Entry —A Horde_Ldap_Entry object.
getLink()
Returns the LDAP link resource.
public
getLink() : resource
It will loop attempting to re-establish the connection if the connection attempt fails and auto_reconnect has been turned on (see the _config array documentation).
Return values
resource —LDAP link.
getOption()
Returns an LDAP option value.
public
getOption(string $option) : Horde_Ldap_Error|string
Parameters
- $option : string
-
Option to get.
Tags
Return values
Horde_Ldap_Error|string —Horde_Ldap_Error or option value
getVersion()
Returns the LDAP protocol version that is used on the connection.
public
getVersion() : int
A lot of LDAP functionality is defined by what protocol version the LDAP server speaks. This might be 2 or 3.
Return values
int —The protocol version.
modify()
Modifies an LDAP entry on the server.
public
modify(string|Horde_Ldap_Entry $entry[, array<string|int, mixed> $parms = array() ]) : mixed
The $params argument is an array of actions and should be something like
this:
array('add' => array('attribute1' => array('val1', 'val2'),
'attribute2' => array('val1')),
'delete' => array('attribute1'),
'replace' => array('attribute1' => array('val1')),
'changes' => array('add' => ...,
'replace' => ...,
'delete' => array('attribute1', 'attribute2' => array('val1')))
The order of execution is as following:
- adds from 'add' array
- deletes from 'delete' array
- replaces from 'replace' array
- changes (add, replace, delete) in order of appearance
The function calls the corresponding functions of an Horde_Ldap_Entry object. A detailed description of array structures can be found there.
Unlike the modification methods provided by the Horde_Ldap_Entry object, this method will instantly carry out an update() after each operation, thus modifying "directly" on the server.
Parameters
- $entry : string|Horde_Ldap_Entry
-
DN string or Horde_Ldap_Entry.
- $parms : array<string|int, mixed> = array()
-
Array of changes
Tags
Return values
mixed —move()
Renames or moves an entry.
public
move(string|Horde_Ldap_Entry $entry, string $newdn[, Horde_Ldap $target_ldap = null ]) : mixed
This method will instantly carry out an update() after the move, so the entry is moved instantly.
You can pass an optional Horde_Ldap object. In this case, a cross directory move will be performed which deletes the entry in the source (THIS) directory and adds it in the directory $target_ldap.
A cross directory move will switch the entry's internal LDAP reference so updates to the entry will go to the new directory.
If you want to do a cross directory move, you need to pass an Horde_Ldap_Entry object, otherwise the attributes will be empty.
Parameters
- $entry : string|Horde_Ldap_Entry
-
An LDAP entry.
- $newdn : string
-
The new location.
- $target_ldap : Horde_Ldap = null
-
Target directory for cross server move.
Tags
Return values
mixed —quote()
Escapes characters with special meaning in LDAP searches.
public
static quote(string $clause) : string
Parameters
- $clause : string
-
The string to escape.
Return values
string —The escaped string.
quoteDN()
Takes an array of DN elements and properly quotes it according to RFC 1485.
public
static quoteDN(array<string|int, mixed> $parts) : string
Parameters
- $parts : array<string|int, mixed>
-
An array of tuples containing the attribute name and that attribute's value which make up the DN. Example:
$parts = array( array('cn', 'John Smith'), array('dc', 'example'), array('dc', 'com') );
Nested arrays are supported since 2.1.0, to form multi-valued RDNs. Example:$parts = array( array( array('cn', 'John'), array('sn', 'Smith'), array('o', 'Acme Inc.'), ), array('dc', 'example'), array('dc', 'com') );
which will result in cn=John+sn=Smith+o=Acme Inc.,dc=example,dc=com
Return values
string —The properly quoted string DN.
rootDSE()
Returns a rootDSE object
public
rootDSE([array<string|int, mixed> $attrs = array() ]) : Horde_Ldap_RootDse
This either fetches a fresh rootDSE object or returns it from the internal cache for performance reasons, if possible.
Parameters
- $attrs : array<string|int, mixed> = array()
-
Array of attributes to search for.
Tags
Return values
Horde_Ldap_RootDse —Horde_Ldap_RootDse object
schema()
Returns a schema object
public
schema([string $dn = null ]) : Horde_Ldap_Schema
Parameters
- $dn : string = null
-
Subschema entry dn.
Tags
Return values
Horde_Ldap_Schema —Horde_Ldap_Schema object
search()
Runs an LDAP search query.
public
search([string|Horde_Ldap_Entry $base = null ][, string|Horde_Ldap_Filter $filter = null ][, array<string|int, mixed> $params = array() ]) : Horde_Ldap_Search
$base and $filter may be ommitted. The one from config will then be used. $base is either a DN-string or an Horde_Ldap_Entry object in which case its DN will be used.
$params may contain:
- scope: The scope which will be used for searching, defaults to 'sub': - base: Just one entry - sub: The whole tree - one: Immediately below $base
- sizelimit: Limit the number of entries returned (default: 0 = unlimited)
- timelimit: Limit the time spent for searching (default: 0 = unlimited)
- attrsonly: If true, the search will only return the attribute names
- attributes: Array of attribute names, which the entry should contain. It is good practice to limit this to just the ones you need.
You cannot override server side limitations to sizelimit and timelimit: You can always only lower a given limit.
Parameters
- $base : string|Horde_Ldap_Entry = null
-
LDAP searchbase.
- $filter : string|Horde_Ldap_Filter = null
-
LDAP search filter.
- $params : array<string|int, mixed> = array()
-
Array of options.
Tags
Return values
Horde_Ldap_Search —The search result.
setOption()
Sets an LDAP option.
public
setOption(string $option, mixed $value) : mixed
Parameters
- $option : string
-
Option to set.
- $value : mixed
-
Value to set option to.
Tags
Return values
mixed —setVersion()
Sets the LDAP protocol version that is used on the connection.
public
setVersion(int $version[, bool $force = false ]) : mixed
Parameters
- $version : int
-
LDAP version that should be used.
- $force : bool = false
-
If set to true, the check against the rootDSE will be skipped.
Tags
Return values
mixed —startTLS()
Starts an encrypted session.
public
startTLS() : mixed
Tags
Return values
mixed —utf8Decode()
public
utf8Decode(array<string|int, mixed> $attributes) : array<string|int, mixed>|Horde_Ldap_Error
Parameters
- $attributes : array<string|int, mixed>
-
Array of attributes
Tags
Return values
array<string|int, mixed>|Horde_Ldap_Error —Array with decoded attribute values or Error
utf8Encode()
public
utf8Encode(array<string|int, mixed> $attributes) : array<string|int, mixed>|Horde_Ldap_Error
Parameters
- $attributes : array<string|int, mixed>
-
An array of attributes.
Tags
Return values
array<string|int, mixed>|Horde_Ldap_Error —An array of UTF8 encoded attributes or an error.
_connect()
Connects to the LDAP server.
protected
_connect() : mixed
This function connects to the LDAP server specified in the configuration, binds and set up the LDAP protocol as needed.
Tags
Return values
mixed —_quoteRDN()
Takes an RDN array with an attribute name and value and properly quotes it according to RFC 1485.
protected
static _quoteRDN(array<string|int, mixed> $attribute) : string
Parameters
- $attribute : array<string|int, mixed>
-
A tuple containing the attribute name and that attribute's value which make up the RDN.
Return values
string —The properly quoted string RDN.
_quoteRDNs()
Takes a single or a list of RDN arrays with an attribute name and value and properly quotes it according to RFC 1485.
protected
static _quoteRDNs(array<string|int, mixed> $attribute) : string
Parameters
- $attribute : array<string|int, mixed>
-
A tuple or array of tuples containing the attribute name and that attribute's value which make up the RDN.
Return values
string —The properly quoted string RDN.
_reconnect()
Reconnects to the LDAP server.
protected
_reconnect() : mixed
In case the connection to the LDAP service has dropped out for some reason, this function will reconnect, and re-bind if a bind has been attempted in the past. It is probably most useful when the server list provided to the new() or _connect() function is an array rather than a single host name, because in that case it will be able to connect to a failover or secondary server in case the primary server goes down.
This method just tries to re-establish the current connection. It will sleep for the current backoff period (seconds) before attempting the connect, and if the connection fails it will double the backoff period, but not try again. If you want to ensure a reconnection during a transient period of server downtime then you need to call this function in a loop.
Tags
Return values
mixed —setConfig()
Sets the internal configuration array.
protected
setConfig(array<string|int, mixed> $config) : mixed
Parameters
- $config : array<string|int, mixed>
-
Configuration hash.
Return values
mixed —utf8()
protected
utf8(array<string|int, mixed> $attributes, array<string|int, mixed> $function) : array<string|int, mixed>
Parameters
- $attributes : array<string|int, mixed>
-
Array of attributes
- $function : array<string|int, mixed>
-
Function to apply to attribute values
Tags
Return values
array<string|int, mixed> —Array of attributes with function applied to values.