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...
 
 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=array(), $scope='subtree')
 Search about filter. More...
 
 object_match_filter ($dn, $filter)
 Search object from a filter. More...
 
 set_size_limit ($size)
 Set a size limit. More...
 
 fetch ($srp)
 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...
 
 add ($attrs)
 Add entry in the LDAP directory. More...
 
 get_additional_error ()
 Get the LDAP additional error. More...
 
 success ()
 Success. More...
 
 get_error ()
 Get the error.
 
 get_errno ()
 Get the errno. More...
 
 hitSizeLimit ()
 Check if the search hit the size limit. More...
 
 generateLdif ($dn, $filter="(objectClass=*)", $scope='sub', $limit=0)
 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 prepare4filter ($dn)
 Function to fix problematic characters in DN's that are used for search requests. I.e. member=.... 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 82 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 708 of file class_ldap.inc.

References connect(), reconnect(), and success().

Referenced by import_single_entry().

◆ cd()

cd (   $dir)

Change directory.

Parameters
string$dirThe new directory

Definition at line 213 of file class_ldap.inc.

References getParentDir().

Referenced by import_single_entry(), and rmdir_recursive().

◆ clearResult()

clearResult (   $srp)

Clear a result.

Parameters
integer$srpThe result to clear

Definition at line 431 of file class_ldap.inc.

Referenced by search().

◆ connect()

connect ( )

Create a connection to LDAP server.

The string $error containts result of the connection

Definition at line 129 of file class_ldap.inc.

References reconnect().

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

◆ count()

count (   $srp)

Return the numbers of entries.

Parameters
$srpsrp

Definition at line 471 of file class_ldap.inc.

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

◆ fetch()

fetch (   $srp)

Fetch.

Parameters
integer$srp

Definition at line 382 of file class_ldap.inc.

Referenced by import_single_entry(), and rmdir_recursive().

◆ generateLdif()

generateLdif (   $dn,
  $filter = "(objectClass=*)",
  $scope = 'sub',
  $limit = 0 
)

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

Parameters
$dnThe entry to export.
$filterLimit the exported object to those maching this filter.
$scope'base', 'sub' .. see manpage for 'ldapmodify' for details.
$limitLimits the result.

Definition at line 962 of file class_ldap.inc.

◆ get_additional_error()

get_additional_error ( )

Get the LDAP additional error.

Returns
string $error containts LDAP_OPT_ERROR_STRING

Definition at line 870 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 910 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 1218 of file class_ldap.inc.

References class_available(), session\global_get(), session\global_is_set(), and session\global_set().

◆ getCn()

getCn (   $dn)

Function to get cn.

Parameters
$dnThe DN

Definition at line 1346 of file class_ldap.inc.

◆ getDN()

getDN (   $srp)

Accessor of the DN.

Parameters
$srpsrp

Definition at line 444 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 229 of file class_ldap.inc.

Referenced by cd().

◆ getSearchResource()

getSearchResource ( )

Get the search ressource.

Returns
increase srp

Definition at line 105 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 924 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 1038 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 1141 of file class_ldap.inc.

References add(), cd(), connect(), count(), msg_dialog\display(), fetch(), get_error(), msgPool\ldaperror(), modify(), reconnect(), rmdir_recursive(), and success().

Referenced by import_complete_ldif().

◆ log()

log (   $string)

Add a string in log file.

Parameters
string$string

Definition at line 1329 of file class_ldap.inc.

References session\global_get(), and session\global_is_set().

◆ modify()

modify ( array  $attrs)

Modify a entry of the directory LDAP.

Parameters
array$attrsThe new entry

Definition at line 682 of file class_ldap.inc.

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

Referenced by import_single_entry().

◆ 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 344 of file class_ldap.inc.

References connect(), and reconnect().

◆ 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 118 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 564 of file class_ldap.inc.

References connect(), and reconnect().

◆ resetResult()

resetResult (   $srp)

Reset the result.

Parameters
integer$srpValue to be reset

Definition at line 421 of file class_ldap.inc.

Referenced by search().

◆ rm()

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

Remove.

Parameters
string$attrsEmpty string
string$dnEmpty string

Definition at line 496 of file class_ldap.inc.

References connect(), and reconnect().

◆ rmdir()

rmdir (   $deletedn)

Remove directory.

Parameters
string$deletednThe DN to be deleted

Definition at line 539 of file class_ldap.inc.

References connect(), 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 618 of file class_ldap.inc.

References cd(), connect(), DEBUG(), DEBUG_LDAP, fetch(), get_additional_error(), reconnect(), search(), and success().

Referenced by import_single_entry().

◆ search()

search (   $srp,
  $filter,
  $attrs = array(),
  $scope = 'subtree' 
)

Search about filter.

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

Definition at line 248 of file class_ldap.inc.

References clearResult(), connect(), msg_dialog\display(), reconnect(), and resetResult().

Referenced by rmdir_recursive().

◆ set_size_limit()

set_size_limit (   $size)

Set a size limit.

Parameters
$sizeThe limit

Definition at line 364 of file class_ldap.inc.

◆ success()

success ( )

Success.

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

Definition at line 882 of file class_ldap.inc.

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


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