FusionDirectory
Public Member Functions | Static Public Member Functions | Protected Member Functions
LDAP Class Reference

This class contains all ldap function needed to make ldap operations easy. More...

Public Member Functions

 __construct ($binddn, $bindpw, $hostname, $follow_referral=FALSE, $tls=FALSE)
 Create a LDAP connection. More...
 
 __wakeup ()
 Remove bogus resources after unserialize.
 
 getSearchResource ()
 Get the search ressource. More...
 
 connect ()
 Create a connection to LDAP server. More...
 
 rebind ($ldap, $referral)
 Rebind.
 
 reconnect ()
 Reconnect to LDAP server.
 
 unbind ()
 Unbind to LDAP server.
 
 disconnect ()
 Disconnect to LDAP server.
 
 cd ($dir)
 Change directory. More...
 
 getParentDir ($basedn='')
 Accessor of the parent directory of the basedn. More...
 
 search ($srp, $filter, $attrs=[], $scope='subtree', array $controls=NULL)
 Search about filter. More...
 
 parse_result ($srp)
 Parse last result. More...
 
 object_match_filter ($dn, $filter)
 Search object from a filter. More...
 
 set_size_limit ($size)
 Set a size limit. More...
 
 fetch ($srp, bool $cleanUpNumericIndices=FALSE)
 Fetch. More...
 
 resetResult ($srp)
 Reset the result. More...
 
 clearResult ($srp)
 Clear a result. More...
 
 getDN ($srp)
 Accessor of the DN. More...
 
 count ($srp)
 Return the numbers of entries. More...
 
 rm ($attrs="", $dn="")
 Remove. More...
 
 rmdir ($deletedn)
 Remove directory. More...
 
 rename_dn ($source, $dest)
 Move the given Ldap entry from $source to $dest. More...
 
 rmdir_recursive ($srp, $deletedn)
 Function rmdir_recursive. More...
 
 modify (array $attrs)
 Modify a entry of the directory LDAP. More...
 
 modify_batch (array $changes)
 Modify a entry of the directory LDAP with fine control. More...
 
 add ($attrs)
 Add entry in the LDAP directory. More...
 
 get_additional_error ()
 Get the LDAP additional error. More...
 
 success ()
 Success. More...
 
 get_error ($details=TRUE)
 Get the error.
 
 get_errno ()
 Get the errno. More...
 
 hitSizeLimit ()
 Check if the search hit the size limit. More...
 
 generateLdif (string $dn, string $filter='(objectClass=*)', string $scope='sub', int $limit=0, int $wrap=NULL)
 Generates an ldif for all entries matching the filter settings, scope and limit. More...
 
 import_complete_ldif ($srp, $str_attr, $JustModify, $DeleteOldEntries)
 Function to imports ldifs. More...
 
 get_objectclasses ($force_reload=FALSE)
 Get the object classes. More...
 
 log ($string)
 Add a string in log file. More...
 
 getCn ($dn)
 Function to get cn. More...
 

Static Public Member Functions

static init (string $server, string $base, string $binddn='', string $pass='')
 Initialize a LDAP connection. More...
 
static prepare4filter ($dn)
 Function to fix problematic characters in DN's that are used for search requests. I.e. member=.... More...
 
static invalidCredentialsError ()
 Error text that must be returned for invalid user or password. More...
 

Protected Member Functions

 import_single_entry ($srp, $data, $modify, $delete)
 Function to Imports a single entry. More...
 

Detailed Description

This class contains all ldap function needed to make ldap operations easy.

Definition at line 34 of file class_ldap.inc.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $binddn,
  $bindpw,
  $hostname,
  $follow_referral = FALSE,
  $tls = FALSE 
)

Create a LDAP connection.

Parameters
string$binddnBind of the DN
string$bindpwBind
string$hostnameThe hostname
boolean$follow_referralFALSE
boolean$tlsFALSE

Definition at line 86 of file class_ldap.inc.

References connect().

Member Function Documentation

◆ add()

add (   $attrs)

Add entry in the LDAP directory.

Parameters
string$attrsThe entry to add

Definition at line 892 of file class_ldap.inc.

References connect(), logging\debug(), DEBUG_LDAP, reconnect(), and success().

◆ cd()

cd (   $dir)

Change directory.

Parameters
string$dirThe new directory

Definition at line 315 of file class_ldap.inc.

References getParentDir().

Referenced by import_single_entry(), parse_result(), and rmdir_recursive().

◆ clearResult()

clearResult (   $srp)

Clear a result.

Parameters
integer$srpThe result to clear

Definition at line 576 of file class_ldap.inc.

Referenced by parse_result(), and search().

◆ connect()

connect ( )

Create a connection to LDAP server.

The string $error containts result of the connection

Definition at line 184 of file class_ldap.inc.

References class_available(), logging\debug(), DEBUG_LDAP, and reconnect().

Referenced by __construct(), add(), import_complete_ldif(), import_single_entry(), modify(), modify_batch(), object_match_filter(), parse_result(), rename_dn(), rm(), rmdir(), rmdir_recursive(), and search().

◆ count()

count (   $srp)

Return the numbers of entries.

Parameters
$srpsrp

Definition at line 616 of file class_ldap.inc.

References logging\debug(), and DEBUG_LDAP.

Referenced by import_complete_ldif(), modify(), and modify_batch().

◆ fetch()

fetch (   $srp,
bool  $cleanUpNumericIndices = FALSE 
)

Fetch.

Parameters
integer$srp
bool$cleanUpNumericIndiceswhether to remove numeric indices and "count" index at top level ("count" index in each attribute value is kept)

Definition at line 520 of file class_ldap.inc.

References logging\debug(), and DEBUG_LDAP.

Referenced by rmdir_recursive().

◆ generateLdif()

generateLdif ( string  $dn,
string  $filter = '(objectClass=*)',
string  $scope = 'sub',
int  $limit = 0,
int  $wrap = NULL 
)

Generates an ldif for all entries matching the filter settings, scope and limit.

Parameters
string$dnThe entry to export.
string$filterLimit the exported object to those maching this filter.
string$scope'base', 'sub' .. see manpage for 'ldapmodify' for details.
int$limitLimits the result.
?int$wrap Wraps line around this length (0 to disable).

Definition at line 1148 of file class_ldap.inc.

References logging\debug(), and DEBUG_LDAP.

◆ get_additional_error()

get_additional_error ( )

Get the LDAP additional error.

Returns
string containts LDAP_OPT_ERROR_STRING

Definition at line 1049 of file class_ldap.inc.

Referenced by get_error(), and rmdir_recursive().

◆ get_errno()

get_errno ( )

Get the errno.

Must be run right after the ldap request

Definition at line 1094 of file class_ldap.inc.

Referenced by hitSizeLimit().

◆ get_objectclasses()

get_objectclasses (   $force_reload = FALSE)

Get the object classes.

Parameters
boolean$force_reloadFALSE

Definition at line 1419 of file class_ldap.inc.

References class_available(), session\get(), session\is_set(), and session\set().

◆ getCn()

getCn (   $dn)

Function to get cn.

Parameters
$dnThe DN

Definition at line 1544 of file class_ldap.inc.

References logging\debug(), and DEBUG_LDAP.

◆ getDN()

getDN (   $srp)

Accessor of the DN.

Parameters
$srpsrp

Definition at line 589 of file class_ldap.inc.

◆ getParentDir()

getParentDir (   $basedn = '')

Accessor of the parent directory of the basedn.

Parameters
string$basednThe basedn which we want the parent directory
Returns
String, the parent directory

Definition at line 331 of file class_ldap.inc.

Referenced by cd().

◆ getSearchResource()

getSearchResource ( )

Get the search ressource.

Returns
increase srp

Definition at line 150 of file class_ldap.inc.

◆ hitSizeLimit()

hitSizeLimit ( )

Check if the search hit the size limit.

Must be run right after the search

Definition at line 1108 of file class_ldap.inc.

References get_errno().

◆ import_complete_ldif()

import_complete_ldif (   $srp,
  $str_attr,
  $JustModify,
  $DeleteOldEntries 
)

Function to imports ldifs.

If DeleteOldEntries is TRUE, the destination entry will be deleted first. If JustModify is TRUE the destination entry will only be touched by the attributes specified in the ldif. if JustMofify is FALSE the destination dn will be overwritten by the new ldif.

Parameters
integer$srp
string$str_attr
boolean$JustModify
boolean$DeleteOldEntries

Definition at line 1295 of file class_ldap.inc.

References connect(), count(), import_single_entry(), and reconnect().

◆ import_single_entry()

import_single_entry (   $srp,
  $data,
  $modify,
  $delete 
)
protected

Function to Imports a single entry.

If $delete is TRUE; The old entry will be deleted if it exists. if $modify is TRUE; All variables that are not touched by the new ldif will be kept. if $modify is FALSE; The new ldif overwrites the old entry, and all untouched attributes get lost.

Parameters
integer$srp
array$data
boolean$modify
boolean$delete

Definition at line 1332 of file class_ldap.inc.

References cd(), connect(), reconnect(), and rmdir_recursive().

Referenced by import_complete_ldif().

◆ init()

static init ( string  $server,
string  $base,
string  $binddn = '',
string  $pass = '' 
)
static

Initialize a LDAP connection.

Initializes a LDAP connection.

Parameters
string$serverThe server we are connecting to
string$baseThe base of our ldap tree
string$binddnDefault: empty
string$passDefault: empty
Returns
LDAP object

Definition at line 127 of file class_ldap.inc.

References htmlescape().

Referenced by config\get_ldap_link().

◆ invalidCredentialsError()

static invalidCredentialsError ( )
static

Error text that must be returned for invalid user or password.

This is useful to make sure the same error text is shown whether a user exists or not, when the password is not correct.

Definition at line 174 of file class_ldap.inc.

Referenced by userinfo\loginUser().

◆ log()

log (   $string)

Add a string in log file.

Parameters
string$string

Definition at line 1527 of file class_ldap.inc.

References session\get(), and session\is_set().

Referenced by search().

◆ modify()

modify ( array  $attrs)

Modify a entry of the directory LDAP.

Parameters
array$attrsThe new entry

Definition at line 839 of file class_ldap.inc.

References connect(), count(), logging\debug(), DEBUG_LDAP, reconnect(), and success().

◆ modify_batch()

modify_batch ( array  $changes)

Modify a entry of the directory LDAP with fine control.

Parameters
array$changesThe changes

Definition at line 867 of file class_ldap.inc.

References connect(), count(), logging\debug(), DEBUG_LDAP, and reconnect().

◆ object_match_filter()

object_match_filter (   $dn,
  $filter 
)

Search object from a filter.

Parameters
string$dnThe DN
string$filterThe filter of the research

Definition at line 479 of file class_ldap.inc.

References connect(), logging\debug(), DEBUG_LDAP, and reconnect().

◆ parse_result()

parse_result (   $srp)

Parse last result.

Parameters
integer$srpsrp

Definition at line 410 of file class_ldap.inc.

References cd(), clearResult(), connect(), logging\debug(), DEBUG_LDAP, reconnect(), resetResult(), and search().

◆ prepare4filter()

static prepare4filter (   $dn)
static

Function to fix problematic characters in DN's that are used for search requests. I.e. member=....

Parameters
string$dnThe DN

Definition at line 163 of file class_ldap.inc.

◆ rename_dn()

rename_dn (   $source,
  $dest 
)

Move the given Ldap entry from $source to $dest.

Parameters
String$sourceThe source dn.
String$destThe destination dn.
Returns
Boolean TRUE on success else FALSE.

Definition at line 718 of file class_ldap.inc.

References connect(), logging\debug(), DEBUG_LDAP, and reconnect().

◆ resetResult()

resetResult (   $srp)

Reset the result.

Parameters
integer$srpValue to be reset

Definition at line 566 of file class_ldap.inc.

Referenced by parse_result(), and search().

◆ rm()

rm (   $attrs = "",
  $dn = "" 
)

Remove.

Parameters
string$attrsEmpty string
string$dnEmpty string

Definition at line 644 of file class_ldap.inc.

References connect(), logging\debug(), DEBUG_LDAP, and reconnect().

◆ rmdir()

rmdir (   $deletedn)

Remove directory.

Parameters
string$deletednThe DN to be deleted

Definition at line 691 of file class_ldap.inc.

References connect(), logging\debug(), DEBUG_LDAP, and reconnect().

◆ rmdir_recursive()

rmdir_recursive (   $srp,
  $deletedn 
)

Function rmdir_recursive.

Based on recursive_remove, adding two thing: full subtree remove, and delete own node.

Parameters
$srpsrp
string$deletednThe dn to delete
Returns
TRUE on sucessfull , 0 in error, and "" when we don't get a ldap conection

Definition at line 773 of file class_ldap.inc.

References cd(), connect(), logging\debug(), DEBUG_LDAP, fetch(), get_additional_error(), reconnect(), search(), and success().

Referenced by import_single_entry().

◆ search()

search (   $srp,
  $filter,
  $attrs = [],
  $scope = 'subtree',
array  $controls = NULL 
)

Search about filter.

Parameters
integer$srpsrp
string$filterThe filter
array$attrs
string$scopeScope of the search: subtree/base/one

Definition at line 350 of file class_ldap.inc.

References clearResult(), connect(), logging\debug(), DEBUG_LDAP, htmlescape(), log(), reconnect(), and resetResult().

Referenced by parse_result(), and rmdir_recursive().

◆ set_size_limit()

set_size_limit (   $size)

Set a size limit.

Parameters
$sizeThe limit

Definition at line 500 of file class_ldap.inc.

References logging\debug(), and DEBUG_LDAP.

◆ success()

success ( )

Success.

Returns
boolean TRUE if Success is found in $error, else return FALSE

Definition at line 1061 of file class_ldap.inc.

Referenced by add(), modify(), and rmdir_recursive().


The documentation for this class was generated from the following file: