dolibarr  16.0.1
Public Member Functions | Public Attributes | Private Member Functions | List of all members
Ldap Class Reference

Class to manage LDAP features. More...

+ Collaboration diagram for Ldap:

Public Member Functions

 __construct ()
 Constructor.
 
 connect_bind ()
 Connect and bind Use this->server, this->serverPort, this->ldapProtocolVersion, this->serverType, this->searchUser, this->searchPassword After return, this->connection and $this->bind are defined. More...
 
 close ()
 Simply closes the connection set up earlier. More...
 
 bind ()
 Anonymously binds to the connection. More...
 
 bindauth ($bindDn, $pass)
 Binds as an authenticated user, which usually allows for write access. More...
 
 unbind ()
 Unbind of LDAP server (close connection). More...
 
 getVersion ()
 Verification de la version du serveur ldap. More...
 
 setVersion ()
 Change ldap protocol version to use. More...
 
 setReferrals ()
 changement du referrals. More...
 
 add ($dn, $info, $user)
 Add a LDAP entry Ldap object connect and bind must have been done. More...
 
 modify ($dn, $info, $user)
 Modify a LDAP entry Ldap object connect and bind must have been done. More...
 
 rename ($dn, $newrdn, $newparent, $user, $deleteoldrdn=true)
 Rename a LDAP entry Ldap object connect and bind must have been done. More...
 
 update ($dn, $info, $user, $olddn, $newrdn=false, $newparent=false)
 Modify a LDAP entry (to use if dn != olddn) Ldap object connect and bind must have been done. More...
 
 delete ($dn)
 Delete a LDAP entry Ldap object connect and bind must have been done. More...
 
 dump_content ($dn, $info)
 Build a LDAP message. More...
 
 dump ($dn, $info)
 Dump a LDAP message to ldapinput.in file. More...
 
 serverPing ($host, $port=389, $timeout=1)
 Ping a server before ldap_connect for avoid waiting. More...
 
 addAttribute ($dn, $info, $user)
 Add a LDAP attribute in entry Ldap object connect and bind must have been done. More...
 
 updateAttribute ($dn, $info, $user)
 Update a LDAP attribute in entry Ldap object connect and bind must have been done. More...
 
 deleteAttribute ($dn, $info, $user)
 Delete a LDAP attribute in entry Ldap object connect and bind must have been done. More...
 
 getAttribute ($dn, $filter)
 Returns an array containing attributes and values for first record. More...
 
 getAttributeValues ($filterrecord, $attribute)
 Returns an array containing values for an attribute and for first record matching filterrecord. More...
 
 getRecords ($search, $userDn, $useridentifier, $attributeArray, $activefilter=0, $attributeAsArray=array())
 Returns an array containing a details or list of LDAP record(s) ldapsearch -LLLx -hlocalhost -Dcn=admin,dc=parinux,dc=org -w password -b "ou=adherents,ou=people,dc=parinux,dc=org" userPassword. More...
 
 littleEndian ($hex)
 Converts a little-endian hex-number to one, that 'hexdec' can convert Required by Active Directory. More...
 
 getObjectSid ($ldapUser)
 Recupere le SID de l'utilisateur Required by Active Directory. More...
 
 binSIDtoText ($binsid)
 Returns the textual SID Indispensable pour Active Directory. More...
 
 search ($checkDn, $filter)
 Fonction de recherche avec filtre this->connection doit etre defini donc la methode bind ou bindauth doit avoir deja ete appelee Ne pas utiliser pour recherche d'une liste donnee de proprietes car conflit majuscule-minuscule. More...
 
 fetch ($user, $filter)
 Load all attribute of a LDAP user. More...
 
 getUserIdentifier ()
 Returns the correct user identifier to use, based on the ldap server type. More...
 
 parseUACF ($uacf)
 UserAccountControl Flgs to more human understandable form... More...
 
 parseSAT ($samtype)
 SamAccountType value to text. More...
 
 convert_time ($value)
 Convertit le temps ActiveDirectory en Unix timestamp. More...
 
 convFromOutputCharset ($str, $pagecodeto= 'UTF-8')
 Convert a string from output/memory charset. More...
 
 getNextGroupGid ($keygroup= 'LDAP_KEY_GROUPS')
 Return available value of group GID. More...
 

Public Attributes

 $server = array()
 Tableau des serveurs (IP addresses ou nom d'hotes)
 
 $connectedServer
 Current connected server.
 
 $dn
 Base DN (e.g. More...
 
 $serverType
 type de serveur, actuellement OpenLdap et Active Directory
 
 $ldapProtocolVersion
 Version du protocole ldap.
 
 $domain
 Server DN.
 
 $searchUser
 User administrateur Ldap Active Directory ne supporte pas les connexions anonymes.
 
 $searchPassword
 Mot de passe de l'administrateur Active Directory ne supporte pas les connexions anonymes.
 
 $people
 DN des utilisateurs.
 
 $groups
 DN des groupes.
 
 $ldapErrorCode
 Code erreur retourne par le serveur Ldap.
 
 $ldapErrorText
 Message texte de l'erreur.
 
 $connection
 The internal LDAP connection handle.
 
 $result
 Result of any connections etc.
 
const SYNCHRO_NONE = 0
 No Ldap synchronization.
 
const SYNCHRO_DOLIBARR_TO_LDAP = 1
 Dolibarr to Ldap synchronization.
 
const SYNCHRO_LDAP_TO_DOLIBARR = 2
 Ldap to Dolibarr synchronization.
 

Private Member Functions

 convToOutputCharset ($str, $pagecodefrom= 'UTF-8')
 Convert a string into output/memory charset. More...
 

Detailed Description

Class to manage LDAP features.

Definition at line 34 of file ldap.class.php.

Member Function Documentation

Ldap::add (   $dn,
  $info,
  $user 
)

Add a LDAP entry Ldap object connect and bind must have been done.

Parameters
string$dnDN entry key
array$infoAttributes array
User$userObjet user that create
Returns
int <0 if KO, >0 if OK

Definition at line 443 of file ldap.class.php.

References $dn, $ldapErrorText, $result, bind(), convFromOutputCharset(), dol_syslog(), and dump().

Referenced by update().

Ldap::addAttribute (   $dn,
  $info,
  $user 
)

Add a LDAP attribute in entry Ldap object connect and bind must have been done.

Parameters
string$dnDN entry key
array$infoAttributes array
User$userObjet user that create
Returns
int <0 if KO, >0 if OK

Definition at line 792 of file ldap.class.php.

References $dn, $result, bind(), convFromOutputCharset(), dol_syslog(), and dump().

Ldap::bind ( )

Anonymously binds to the connection.

After this is done, queries and searches can be done - but read-only.

Returns
boolean true or false

Definition at line 343 of file ldap.class.php.

References $ldapErrorText.

Referenced by add(), addAttribute(), connect_bind(), delete(), deleteAttribute(), getAttribute(), modify(), rename(), update(), and updateAttribute().

Ldap::bindauth (   $bindDn,
  $pass 
)

Binds as an authenticated user, which usually allows for write access.

The FULL dn must be passed. For a directory manager, this is "cn=Directory Manager" under iPlanet. For a user, it will be something like "uid=jbloggs,ou=People,dc=foo,dc=com".

Parameters
string$bindDnDN
string$passPassword
Returns
boolean true or false

Definition at line 365 of file ldap.class.php.

References $ldapErrorText.

Referenced by connect_bind(), fetch(), getObjectSid(), getRecords(), and search().

Ldap::binSIDtoText (   $binsid)

Returns the textual SID Indispensable pour Active Directory.

Parameters
string$binsidBinary SID
Returns
string Textual SID

Definition at line 1171 of file ldap.class.php.

References $result, and littleEndian().

Referenced by getObjectSid().

Ldap::close ( )

Simply closes the connection set up earlier.

Returns true if OK, false if there was an error. This method seems a duplicate/alias of unbind().

Returns
boolean true or false
Deprecated:
ldap_close is an alias of ldap_unbind
See Also
unbind()

Definition at line 327 of file ldap.class.php.

Ldap::connect_bind ( )

Connect and bind Use this->server, this->serverPort, this->ldapProtocolVersion, this->serverType, this->searchUser, this->searchPassword After return, this->connection and $this->bind are defined.

Returns
int <0 if KO, 1 if bind anonymous, 2 if bind auth

Definition at line 192 of file ldap.class.php.

References $result, bind(), bindauth(), dol_syslog(), serverPing(), setReferrals(), setVersion(), and unbind().

Ldap::convert_time (   $value)

Convertit le temps ActiveDirectory en Unix timestamp.

Parameters
string$valueAD time to convert
Returns
integer Unix timestamp

Definition at line 1409 of file ldap.class.php.

Referenced by fetch().

Ldap::convFromOutputCharset (   $str,
  $pagecodeto = 'UTF-8' 
)

Convert a string from output/memory charset.

Parameters
string$strString to convert
string$pagecodetoPage code for result string
Returns
string Converted string

Definition at line 1446 of file ldap.class.php.

Referenced by add(), addAttribute(), delete(), deleteAttribute(), modify(), rename(), search(), and updateAttribute().

Ldap::convToOutputCharset (   $str,
  $pagecodefrom = 'UTF-8' 
)
private

Convert a string into output/memory charset.

Parameters
string$strString to convert
string$pagecodefromPage code of src string
Returns
string Converted string

Definition at line 1427 of file ldap.class.php.

Referenced by fetch(), and getRecords().

Ldap::delete (   $dn)

Delete a LDAP entry Ldap object connect and bind must have been done.

Parameters
string$dnDN entry key
Returns
int <0 if KO, >0 if OK

Definition at line 643 of file ldap.class.php.

References $dn, $result, bind(), convFromOutputCharset(), and dol_syslog().

Ldap::deleteAttribute (   $dn,
  $info,
  $user 
)

Delete a LDAP attribute in entry Ldap object connect and bind must have been done.

Parameters
string$dnDN entry key
array$infoAttributes array
User$userObjet user that create
Returns
int <0 if KO, >0 if OK

Definition at line 884 of file ldap.class.php.

References $dn, $result, bind(), convFromOutputCharset(), dol_syslog(), and dump().

Ldap::dump (   $dn,
  $info 
)

Dump a LDAP message to ldapinput.in file.

Parameters
string$dnDN entry key
array$infoAttributes array
Returns
int <0 if KO, >0 if OK

Definition at line 713 of file ldap.class.php.

References $dn, $result, dol_mkdir(), and dump_content().

Referenced by add(), addAttribute(), deleteAttribute(), modify(), and updateAttribute().

Ldap::dump_content (   $dn,
  $info 
)

Build a LDAP message.

Parameters
string$dnDN entry key
array$infoAttributes array
Returns
string Content of file

Definition at line 676 of file ldap.class.php.

Referenced by dump().

Ldap::fetch (   $user,
  $filter 
)

Load all attribute of a LDAP user.

Parameters
User$userUser to search for. Not used if a filter is provided.
string$filterFilter for search. Must start with &. Examples: &(objectClass=inetOrgPerson) &(objectClass=user)(objectCategory=person) &(isMemberOf=cn=Sales,ou=Groups,dc=opencsi,dc=com)
Returns
int >0 if OK, <0 if KO

Definition at line 1229 of file ldap.class.php.

References $domain, $people, $result, bindauth(), convert_time(), convToOutputCharset(), dol_syslog(), name, and parseUACF().

Ldap::getAttribute (   $dn,
  $filter 
)

Returns an array containing attributes and values for first record.

Parameters
string$dnDN entry key
string$filterFilter
Returns
int|array <0 or false if KO, array if OK

Definition at line 928 of file ldap.class.php.

References $dn, and bind().

Ldap::getAttributeValues (   $filterrecord,
  $attribute 
)

Returns an array containing values for an attribute and for first record matching filterrecord.

Parameters
string$filterrecordRecord
string$attributeAttributes
Returns
void

Definition at line 969 of file ldap.class.php.

Ldap::getNextGroupGid (   $keygroup = 'LDAP_KEY_GROUPS')

Return available value of group GID.

Parameters
string$keygroupKey of group
Returns
int gid number

Definition at line 1465 of file ldap.class.php.

References $result, and search().

Ldap::getObjectSid (   $ldapUser)

Recupere le SID de l'utilisateur Required by Active Directory.

Parameters
string$ldapUserLogin de l'utilisateur
Returns
string Sid

Definition at line 1121 of file ldap.class.php.

References $domain, $people, bindauth(), and binSIDtoText().

Referenced by getRecords().

Ldap::getRecords (   $search,
  $userDn,
  $useridentifier,
  $attributeArray,
  $activefilter = 0,
  $attributeAsArray = array() 
)

Returns an array containing a details or list of LDAP record(s) ldapsearch -LLLx -hlocalhost -Dcn=admin,dc=parinux,dc=org -w password -b "ou=adherents,ou=people,dc=parinux,dc=org" userPassword.

Parameters
string$searchValue of field to search, '*' for all. Not used if $activefilter is set.
string$userDnDN (Ex: ou=adherents,ou=people,dc=parinux,dc=org)
string$useridentifierName of key field (Ex: uid)
array$attributeArrayArray of fields required. Note this array must also contains field $useridentifier (Ex: sn,userPassword)
int$activefilter'1' or 'user'=use field this->filter as filter instead of parameter $search, 'group'=use field this->filtergroup as filter, 'member'=use field this->filtermember as filter
array$attributeAsArrayArray of fields wanted as an array not a string
Returns
array Array of [id_record][ldap_field]=value

Definition at line 1012 of file ldap.class.php.

References bindauth(), convToOutputCharset(), dol_syslog(), and getObjectSid().

Ldap::getUserIdentifier ( )

Returns the correct user identifier to use, based on the ldap server type.

Returns
string Login

Definition at line 1314 of file ldap.class.php.

Ldap::getVersion ( )

Verification de la version du serveur ldap.

Returns
string version

Definition at line 402 of file ldap.class.php.

Ldap::littleEndian (   $hex)

Converts a little-endian hex-number to one, that 'hexdec' can convert Required by Active Directory.

Parameters
string$hexHex value
Returns
string Little endian

Definition at line 1104 of file ldap.class.php.

References $result, and dol_strlen().

Referenced by binSIDtoText().

Ldap::modify (   $dn,
  $info,
  $user 
)

Modify a LDAP entry Ldap object connect and bind must have been done.

Parameters
string$dnDN entry key
array$infoAttributes array
User$userObjet user that modify
Returns
int <0 if KO, >0 if OK

Definition at line 491 of file ldap.class.php.

References $dn, $result, bind(), convFromOutputCharset(), dol_syslog(), and dump().

Referenced by update().

Ldap::parseSAT (   $samtype)

SamAccountType value to text.

Parameters
string$samtypeSamType
Returns
string Sam string

Definition at line 1376 of file ldap.class.php.

Ldap::parseUACF (   $uacf)

UserAccountControl Flgs to more human understandable form...

Parameters
string$uacfUACF
Returns
void

Definition at line 1329 of file ldap.class.php.

Referenced by fetch().

Ldap::rename (   $dn,
  $newrdn,
  $newparent,
  $user,
  $deleteoldrdn = true 
)

Rename a LDAP entry Ldap object connect and bind must have been done.

Parameters
string$dnOld DN entry key (uid=qqq,ou=xxx,dc=aaa,dc=bbb) (before update)
string$newrdnNew RDN entry key (uid=qqq)
string$newparentNew parent (ou=xxx,dc=aaa,dc=bbb)
User$userObjet user that modify
bool$deleteoldrdnIf true the old RDN value(s) is removed, else the old RDN value(s) is retained as non-distinguished values of the entry.
Returns
int <0 if KO, >0 if OK

Definition at line 549 of file ldap.class.php.

References $dn, $result, bind(), convFromOutputCharset(), and dol_syslog().

Referenced by update().

Ldap::search (   $checkDn,
  $filter 
)

Fonction de recherche avec filtre this->connection doit etre defini donc la methode bind ou bindauth doit avoir deja ete appelee Ne pas utiliser pour recherche d'une liste donnee de proprietes car conflit majuscule-minuscule.

A n'utiliser que pour les pages 'Fiche LDAP' qui affiche champ lisibles par defaut.

Parameters
string$checkDnDN de recherche (Ex: ou=users,cn=my-domain,cn=com)
string$filterSearch filter (ex: (sn=nom_personne) )
Returns
array|int Array with answers (key lowercased - value)

Definition at line 1196 of file ldap.class.php.

References $result, bindauth(), convFromOutputCharset(), and dol_syslog().

Referenced by getNextGroupGid().

Ldap::serverPing (   $host,
  $port = 389,
  $timeout = 1 
)

Ping a server before ldap_connect for avoid waiting.

Parameters
string$hostServer host or address
int$portServer port (default 389)
int$timeoutTimeout in second (default 1s)
Returns
boolean true or false

Definition at line 745 of file ldap.class.php.

Referenced by connect_bind().

Ldap::setReferrals ( )

changement du referrals.

Returns
boolean referrals

Definition at line 426 of file ldap.class.php.

Referenced by connect_bind().

Ldap::setVersion ( )

Change ldap protocol version to use.

Returns
boolean version

Definition at line 414 of file ldap.class.php.

Referenced by connect_bind().

Ldap::unbind ( )

Unbind of LDAP server (close connection).

Returns
boolean true or false
See Also
close()

Definition at line 383 of file ldap.class.php.

Referenced by connect_bind().

Ldap::update (   $dn,
  $info,
  $user,
  $olddn,
  $newrdn = false,
  $newparent = false 
)

Modify a LDAP entry (to use if dn != olddn) Ldap object connect and bind must have been done.

Parameters
string$dnDN entry key
array$infoAttributes array
User$userObjet user that update
string$olddnOld DN entry key (before update)
string$newrdnNew RDN entry key (uid=qqq) (for ldap_rename)
string$newparentNew parent (ou=xxx,dc=aaa,dc=bbb) (for ldap_rename)
Returns
int <0 if KO, >0 if OK

Definition at line 593 of file ldap.class.php.

References $dn, $result, add(), bind(), dol_syslog(), modify(), and rename().

Ldap::updateAttribute (   $dn,
  $info,
  $user 
)

Update a LDAP attribute in entry Ldap object connect and bind must have been done.

Parameters
string$dnDN entry key
array$infoAttributes array
User$userObjet user that create
Returns
int <0 if KO, >0 if OK

Definition at line 838 of file ldap.class.php.

References $dn, $result, bind(), convFromOutputCharset(), dol_syslog(), and dump().

Member Data Documentation

Ldap::$dn

Base DN (e.g.

"dc=foo,dc=com")

Definition at line 59 of file ldap.class.php.

Referenced by add(), addAttribute(), delete(), deleteAttribute(), dump(), getAttribute(), modify(), rename(), update(), and updateAttribute().


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