47 public $errors = array();
52 public $server = array();
57 public $connectedServer;
78 public $ldapProtocolVersion;
104 public $searchPassword;
119 public $ldapErrorCode;
124 public $ldapErrorText;
139 public $filtermember;
149 public $attr_sambalogin;
159 public $attr_firstname;
240 public $ldapcharset =
'UTF-8';
255 const SYNCHRO_NONE = 0;
260 const SYNCHRO_DOLIBARR_TO_LDAP = 1;
265 const SYNCHRO_LDAP_TO_DOLIBARR = 2;
318 global $dolibarr_main_auth_ldap_debug;
323 $this->connectedServer =
'';
325 $ldapdebug = !((empty($dolibarr_main_auth_ldap_debug) || $dolibarr_main_auth_ldap_debug ==
"false"));
329 print
"DEBUG: connectBind<br>\n";
333 if (count($this->server) == 0 || empty($this->server[0])) {
334 $this->error =
'LDAP setup (file conf.php) is not complete';
335 dol_syslog(get_class($this).
"::connectBind ".$this->error, LOG_WARNING);
339 if (!function_exists(
"ldap_connect")) {
340 $this->error =
'LDAPFunctionsNotAvailableOnPHP';
341 dol_syslog(get_class($this).
"::connectBind ".$this->error, LOG_WARNING);
345 if (empty($this->error)) {
347 foreach ($this->server as $host) {
355 if ($this->
serverPing($host, $this->serverPort)) {
357 dol_syslog(get_class($this).
"::connectBind serverPing true, we try ldap_connect to ".$host, LOG_DEBUG);
359 if (version_compare(PHP_VERSION,
'8.3.0',
'>=')) {
360 $uri = $host.
':'.$this->serverPort;
361 $this->connection = ldap_connect($uri);
363 $this->connection = ldap_connect($host, $this->serverPort);
366 if (preg_match(
'/^ldaps/i', $host)) {
370 dol_syslog(get_class($this).
"::connectBind serverPing false, we try ldap_connect to ".$host, LOG_DEBUG);
372 if (version_compare(PHP_VERSION,
'8.3.0',
'>=')) {
373 $uri = $host.
':'.$this->serverPort;
374 $this->connection = ldap_connect($uri);
376 $this->connection = ldap_connect($host, $this->serverPort);
380 dol_syslog(get_class($this).
"::connectBind serverPing false, no ldap_connect ".$host, LOG_DEBUG);
386 if (is_resource($this->connection) || is_object($this->connection)) {
388 dol_syslog(get_class($this).
"::connectBind this->connection is ok", LOG_DEBUG);
398 $resulttls = ldap_start_tls($this->connection);
400 dol_syslog(get_class($this).
"::connectBind failed to start tls", LOG_WARNING);
401 $this->error =
'ldap_start_tls Failed to start TLS '.ldap_errno($this->connection).
' '.ldap_error($this->connection);
411 if ($this->serverType ==
"activedirectory") {
413 dol_syslog(get_class($this).
"::connectBind try bindauth for activedirectory on ".$host.
" user=".$this->searchUser.
" password=".preg_replace(
'/./',
'*', $this->searchPassword), LOG_DEBUG);
414 $this->result = $this->
bindauth($this->searchUser, $this->searchPassword);
416 $this->
bind = $this->result;
418 $this->connectedServer = $host;
421 $this->error = ldap_errno($this->connection).
' '.ldap_error($this->connection);
425 if ($this->searchUser && $this->searchPassword) {
426 dol_syslog(get_class($this).
"::connectBind try bindauth on ".$host.
" user=".$this->searchUser.
" password=".preg_replace(
'/./',
'*', $this->searchPassword), LOG_DEBUG);
427 $this->result = $this->
bindauth($this->searchUser, $this->searchPassword);
429 $this->
bind = $this->result;
431 $this->connectedServer = $host;
434 $this->error = ldap_errno($this->connection).
' '.ldap_error($this->connection);
439 dol_syslog(get_class($this).
"::connectBind try bind anonymously on ".$host, LOG_DEBUG);
440 $result = $this->
bind();
442 $this->
bind = $this->result;
444 $this->connectedServer = $host;
447 $this->error = ldap_errno($this->connection).
' '.ldap_error($this->connection);
460 dol_syslog(get_class($this).
"::connectBind ".$connected, LOG_DEBUG);
463 $this->error =
'Failed to connect to LDAP'.($this->error ?
': '.$this->error :
'');
464 dol_syslog(get_class($this).
"::connectBind ".$this->error, LOG_WARNING);
490 if (!$this->result = @ldap_bind($this->connection)) {
491 $this->ldapErrorCode = ldap_errno($this->connection);
492 $this->ldapErrorText = ldap_error($this->connection);
493 $this->error = $this->ldapErrorCode.
" ".$this->ldapErrorText;
512 if (!$this->result = @ldap_bind($this->connection, $bindDn, $pass)) {
513 $this->ldapErrorCode = ldap_errno($this->connection);
514 $this->ldapErrorText = ldap_error($this->connection);
515 $this->error = $this->ldapErrorCode.
" ".$this->ldapErrorText;
530 $this->result =
true;
531 if (version_compare(PHP_VERSION,
'8.1.0',
'>=')) {
532 if (is_object($this->connection)) {
534 $this->result = ldap_unbind($this->connection);
535 }
catch (Throwable $exception) {
536 $this->error =
'Failed to unbind LDAP connection: '.$exception;
537 $this->result =
false;
538 dol_syslog(get_class($this).
'::unbind - '.$this->error, LOG_WARNING);
542 if (is_resource($this->connection)) {
544 $this->result = @ldap_unbind($this->connection);
562 @ldap_get_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $version);
574 return ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $this->ldapProtocolVersion);
584 return ldap_set_option($this->connection, LDAP_OPT_SIZELIMIT, 0);
595 return ldap_set_option($this->connection, LDAP_OPT_REFERRALS, 0);
608 public function add($dn, $info, $user)
610 dol_syslog(get_class($this).
"::add dn=".$dn.
" info=".print_r($info,
true));
613 if (!$this->connection) {
614 $this->error =
"NotConnected";
618 $this->error =
"NotConnected";
624 foreach ($info as $key => $val) {
625 if (!is_array($val)) {
630 $this->
dump($dn, $info);
633 $result = @ldap_add($this->connection, $dn, $info);
636 dol_syslog(get_class($this).
"::add successful", LOG_DEBUG);
639 $this->ldapErrorCode = @ldap_errno($this->connection);
640 $this->ldapErrorText = @ldap_error($this->connection);
641 $this->error = $this->ldapErrorCode.
" ".$this->ldapErrorText;
642 dol_syslog(get_class($this).
"::add failed: ".$this->error, LOG_ERR);
656 public function modify($dn, $info, $user)
658 dol_syslog(get_class($this).
"::modify dn=".$dn.
" info=".print_r($info,
true));
661 if (!$this->connection) {
662 $this->error =
"NotConnected";
666 $this->error =
"NotConnected";
672 foreach ($info as $key => $val) {
673 if (!is_array($val)) {
678 $this->
dump($dn, $info);
683 if ($this->serverType ==
"activedirectory") {
687 if (isset($info[
'unicodePwd'])) {
688 $info[
'unicodePwd'] = mb_convert_encoding(
"\"".$info[
'unicodePwd'].
"\"",
"UTF-16LE",
"UTF-8");
691 $result = @ldap_mod_replace($this->connection, $dn, $info);
694 dol_syslog(get_class($this).
"::modify successful", LOG_DEBUG);
697 $this->error = @ldap_error($this->connection);
698 dol_syslog(get_class($this).
"::modify failed: ".$this->error, LOG_ERR);
714 public function rename($dn, $newrdn, $newparent, $user, $deleteoldrdn =
true)
716 dol_syslog(get_class($this).
"::modify dn=".$dn.
" newrdn=".$newrdn.
" newparent=".$newparent.
" deleteoldrdn=".($deleteoldrdn ? 1 : 0));
719 if (!$this->connection) {
720 $this->error =
"NotConnected";
724 $this->error =
"NotConnected";
734 $result = @ldap_rename($this->connection, $dn, $newrdn, $newparent, $deleteoldrdn);
737 dol_syslog(get_class($this).
"::rename successful", LOG_DEBUG);
740 $this->error = @ldap_error($this->connection);
741 dol_syslog(get_class($this).
"::rename failed: ".$this->error, LOG_ERR);
758 public function update($dn, $info, $user, $olddn, $newrdn =
'', $newparent =
'')
760 dol_syslog(get_class($this).
"::update dn=".$dn.
" olddn=".$olddn);
763 if (!$this->connection) {
764 $this->error =
"NotConnected";
768 $this->error =
"NotConnected";
772 if (!$olddn || $olddn != $dn) {
773 if (!empty($olddn) && !empty($newrdn) && !empty($newparent) && $this->ldapProtocolVersion ===
'3') {
775 $result = $this->
rename($olddn, $newrdn, $newparent, $user,
true);
776 $result = $this->
modify($dn, $info, $user);
779 $result = $this->
add($dn, $info, $user);
780 if ($result > 0 && $olddn && $olddn != $dn) {
781 $result = $this->
delete($olddn);
786 $result = $this->
add($dn, $info, $user);
787 $result = $this->
modify($dn, $info, $user);
790 $this->error = ldap_error($this->connection).
' (Code '.ldap_errno($this->connection).
") ".$this->error;
791 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
795 dol_syslog(get_class($this).
"::update done successfully");
808 public function delete($dn)
810 dol_syslog(get_class($this).
"::delete Delete LDAP entry dn=".$dn);
813 if (!$this->connection) {
814 $this->error =
"NotConnected";
818 $this->error =
"NotConnected";
825 $result = @ldap_delete($this->connection, $dn);
846 if (preg_match(
'/^ldap/', $this->server[0])) {
847 $target =
"-H ".implode(
',', $this->server);
849 $target =
"-h ".implode(
',', $this->server).
" -p ".$this->serverPort;
851 $content .=
"# ldapadd $target -c -v -D ".$this->searchUser.
" -W -f ldapinput.in\n";
852 $content .=
"# ldapmodify $target -c -v -D ".$this->searchUser.
" -W -f ldapinput.in\n";
853 $content .=
"# ldapdelete $target -c -v -D ".$this->searchUser.
" -W -f ldapinput.in\n";
854 if (in_array(
'localhost', $this->server)) {
855 $content .=
"# If commands fails to connect, try without -h and -p\n";
857 $content .=
"dn: ".$dn.
"\n";
858 foreach ($info as $key => $value) {
859 if (!is_array($value)) {
860 $content .=
"$key: $value\n";
862 foreach ($value as $valuevalue) {
863 $content .=
"$key: $valuevalue\n";
877 public function dump($dn, $info)
880 $ldapDirTemp = $conf->ldap->dir_temp;
887 $outputfile = $ldapDirTemp.
'/ldapinput.in';
888 $fp = fopen($outputfile,
"w");
890 fwrite($fp, $content);
913 if (preg_match(
'/^ldaps:\/\/([^\/]+)\/?$/', $host, $regs)) {
915 $host =
'ssl://'.$regs[1];
916 } elseif (preg_match(
'/^ldap:\/\/([^\/]+)\/?$/', $host, $regs)) {
925 $errno = $errstr = 0;
934 $op = @fsockopen($host, $port, $errno, $errstr, $timeout);
959 dol_syslog(get_class($this).
"::addAttribute dn=".$dn.
" info=".implode(
',', $info));
962 if (!$this->connection) {
963 $this->error =
"NotConnected";
967 $this->error =
"NotConnected";
973 foreach ($info as $key => $val) {
974 if (!is_array($val)) {
979 $this->
dump($dn, $info);
982 $result = @ldap_mod_add($this->connection, $dn, $info);
985 dol_syslog(get_class($this).
"::add_attribute successful", LOG_DEBUG);
988 $this->error = @ldap_error($this->connection);
989 dol_syslog(get_class($this).
"::add_attribute failed: ".$this->error, LOG_ERR);
1005 dol_syslog(get_class($this).
"::updateAttribute dn=".$dn.
" info=".implode(
',', $info));
1008 if (!$this->connection) {
1009 $this->error =
"NotConnected";
1013 $this->error =
"NotConnected";
1019 foreach ($info as $key => $val) {
1020 if (!is_array($val)) {
1025 $this->
dump($dn, $info);
1028 $result = @ldap_mod_replace($this->connection, $dn, $info);
1031 dol_syslog(get_class($this).
"::updateAttribute successful", LOG_DEBUG);
1034 $this->error = @ldap_error($this->connection);
1035 dol_syslog(get_class($this).
"::updateAttribute failed: ".$this->error, LOG_ERR);
1051 dol_syslog(get_class($this).
"::deleteAttribute dn=".$dn.
" info=".implode(
',', $info));
1054 if (!$this->connection) {
1055 $this->error =
"NotConnected";
1059 $this->error =
"NotConnected";
1065 foreach ($info as $key => $val) {
1066 if (!is_array($val)) {
1071 $this->
dump($dn, $info);
1074 $result = @ldap_mod_del($this->connection, $dn, $info);
1077 dol_syslog(get_class($this).
"::deleteAttribute successful", LOG_DEBUG);
1080 $this->error = @ldap_error($this->connection);
1081 dol_syslog(get_class($this).
"::deleteAttribute failed: ".$this->error, LOG_ERR);
1098 if (!$this->connection) {
1099 $this->error =
"NotConnected";
1103 $this->error =
"NotConnected";
1107 $search = @ldap_search($this->connection, $dn, $filter);
1110 $entry = @ldap_first_entry($this->connection, $search);
1113 $this->ldapErrorCode = -1;
1114 $this->ldapErrorText =
"Couldn't find entry";
1119 if (!($values = ldap_get_attributes($this->connection, $entry))) {
1120 $this->ldapErrorCode = ldap_errno($this->connection);
1121 $this->ldapErrorText = ldap_error($this->connection);
1138 $attributes = array();
1139 $attributes[0] = $attribute;
1142 $this->result = @ldap_search($this->connection, $this->people, $filterrecord, $attributes);
1148 $entry = ldap_first_entry($this->connection, $this->result);
1151 $this->ldapErrorCode = -1;
1152 $this->ldapErrorText =
"Couldn't find user";
1157 if (!$values = @ldap_get_values_len($this->connection, $entry, $attribute)) {
1158 $this->ldapErrorCode = ldap_errno($this->connection);
1159 $this->ldapErrorText = ldap_error($this->connection);
1179 public function getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter = 0, $attributeAsArray = array())
1181 $fulllist = array();
1183 dol_syslog(get_class($this).
"::getRecords search=".$search.
" userDn=".$userDn.
" useridentifier=".$useridentifier.
" attributeArray=array(".implode(
',', $attributeArray).
") activefilter=".$activefilter);
1186 if ($this->serverType ==
"activedirectory") {
1187 $this->
bindauth($this->searchUser, $this->searchPassword);
1188 dol_syslog(get_class($this).
"::bindauth serverType=activedirectory searchUser=".$this->searchUser);
1192 if (!empty($activefilter)) {
1193 if (((
string) $activefilter ==
'1' || (
string) $activefilter ==
'user') && $this->filter) {
1194 $filter =
'('.$this->filter.
')';
1195 } elseif (((
string) $activefilter ==
'group') && $this->filtergroup) {
1196 $filter =
'('.$this->filtergroup.
')';
1197 } elseif (((
string) $activefilter ==
'member') && $this->filter) {
1198 $filter =
'('.$this->filtermember.
')';
1201 $filter =
'('.ldap_escape($useridentifier,
'', LDAP_ESCAPE_FILTER).
'=*)';
1204 $filter =
'('.ldap_escape($useridentifier,
'', LDAP_ESCAPE_FILTER).
'='.ldap_escape($search,
'', LDAP_ESCAPE_FILTER).
')';
1207 if (is_array($attributeArray)) {
1209 $attributeArray = array_values($attributeArray);
1210 dol_syslog(get_class($this).
"::getRecords connection=".$this->connectedServer.
":".$this->serverPort.
" userDn=".$userDn.
" filter=".$filter.
" attributeArray=(".implode(
',', $attributeArray).
")");
1212 $this->result = @ldap_search($this->connection, $userDn, $filter, $attributeArray);
1215 dol_syslog(get_class($this).
"::getRecords connection=".$this->connectedServer.
":".$this->serverPort.
" userDn=".$userDn.
" filter=".$filter);
1216 $this->result = @ldap_search($this->connection, $userDn, $filter);
1218 if (!$this->result) {
1219 $this->error =
'LDAP search failed: '.ldap_errno($this->connection).
" ".ldap_error($this->connection);
1223 $info = @ldap_get_entries($this->connection, $this->result);
1229 for ($i = 0; $i < $info[
"count"]; $i++) {
1230 $recordid = $this->
convToOutputCharset($info[$i][strtolower($useridentifier)][0], $this->ldapcharset);
1233 $fulllist[$recordid][$useridentifier] = $recordid;
1236 $num = count($attributeArray);
1237 for ($j = 0; $j < $num; $j++) {
1238 $keyattributelower = strtolower($attributeArray[$j]);
1242 if ($this->serverType ==
"activedirectory" && $keyattributelower ==
"objectsid") {
1244 $fulllist[$recordid][$attributeArray[$j]] = $objectsid;
1246 if (in_array($attributeArray[$j], $attributeAsArray) && is_array($info[$i][$keyattributelower])) {
1247 $valueTab = array();
1248 foreach ($info[$i][$keyattributelower] as $key => $value) {
1251 $fulllist[$recordid][$attributeArray[$j]] = $valueTab;
1253 $fulllist[$recordid][$attributeArray[$j]] = $this->
convToOutputCharset($info[$i][$keyattributelower][0], $this->ldapcharset);
1274 for ($x =
dol_strlen($hex) - 2; $x >= 0; $x -= 2) {
1275 $result .= substr($hex, $x, 2);
1290 $criteria =
'('.$this->getUserIdentifier().
'='.$ldapUser.
')';
1291 $justthese = array(
"objectsid");
1294 if ($this->serverType ==
"activedirectory") {
1295 $this->
bindauth($this->searchUser, $this->searchPassword);
1300 $searchDN = $this->people;
1303 $ldapSearchResult = @ldap_search($this->connection, $searchDN, $criteria, $justthese);
1305 if (!$ldapSearchResult) {
1306 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1310 $entry = ldap_first_entry($this->connection, $ldapSearchResult);
1314 $searchDN = $this->domain;
1323 $ldapBinary = ldap_get_values_len($this->connection, $entry,
"objectsid");
1327 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1341 $hex_sid = bin2hex($binsid);
1342 $rev = hexdec(substr($hex_sid, 0, 2));
1343 $subcount = hexdec(substr($hex_sid, 2, 2));
1344 $auth = hexdec(substr($hex_sid, 4, 12));
1345 $result =
"$rev-$auth";
1346 for ($x = 0; $x < $subcount; $x++) {
1347 $result .=
"-".hexdec($this->
littleEndian(substr($hex_sid, 16 + ($x * 8), 8)));
1368 dol_syslog(get_class($this).
"::search checkDn=".$checkDn.
" filter=".$filter);
1374 if ($this->serverType ==
"activedirectory") {
1375 $this->
bindauth($this->searchUser, $this->searchPassword);
1378 $this->result = @ldap_search($this->connection, $checkDn, $filter);
1380 $result = @ldap_get_entries($this->connection, $this->result);
1382 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1385 ldap_free_result($this->result);
1404 if ($this->serverType ==
"activedirectory") {
1405 $this->
bindauth($this->searchUser, $this->searchPassword);
1408 $searchDN = $this->people;
1413 dol_syslog(get_class($this).
"::fetch search with searchDN=".$searchDN.
" filter=".$filter);
1414 $this->result = @ldap_search($this->connection, $searchDN, $filter);
1415 if ($this->result) {
1416 $result = @ldap_get_entries($this->connection, $this->result);
1417 if ($result[
'count'] > 0) {
1418 dol_syslog(
'Ldap::fetch search found '.$result[
'count'].
' records');
1420 dol_syslog(
'Ldap::fetch search returns but found no records');
1424 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1425 dol_syslog(get_class($this).
"::fetch search fails");
1431 $searchDN = $this->domain;
1439 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1443 $this->firstname = $this->
convToOutputCharset($result[0][$this->attr_firstname][0], $this->ldapcharset);
1444 $this->login = $this->
convToOutputCharset($result[0][$this->attr_login][0], $this->ldapcharset);
1445 $this->phone = $this->
convToOutputCharset($result[0][$this->attr_phone][0], $this->ldapcharset);
1446 $this->fax = $this->
convToOutputCharset($result[0][$this->attr_fax][0], $this->ldapcharset);
1447 $this->mail = $this->
convToOutputCharset($result[0][$this->attr_mail][0], $this->ldapcharset);
1448 $this->mobile = $this->
convToOutputCharset($result[0][$this->attr_mobile][0], $this->ldapcharset);
1451 if (isset($result[0][
"pwdlastset"][0])) {
1452 $this->pwdlastset = ($result[0][
"pwdlastset"][0] != 0) ? $this->
convertTime($this->
convToOutputCharset($result[0][
"pwdlastset"][0], $this->ldapcharset)) : 0;
1454 $this->pwdlastset = -1;
1456 if (!$this->
name && !$this->login) {
1457 $this->pwdlastset = -1;
1462 $domain = str_replace(
'dc=',
'', $this->domain);
1463 $domain = str_replace(
',',
'.', $domain);
1464 $this->domainFQDN = $domain;
1468 $this->ldapUserDN = $result[0][
'dn'];
1470 ldap_free_result($this->result);
1485 if ($this->serverType ==
"activedirectory") {
1486 return $this->attr_sambalogin;
1488 return $this->attr_login;
1502 "TRUSTED_TO_AUTH_FOR_DELEGATION" => 16777216,
1503 "PASSWORD_EXPIRED" => 8388608,
1504 "DONT_REQ_PREAUTH" => 4194304,
1505 "USE_DES_KEY_ONLY" => 2097152,
1506 "NOT_DELEGATED" => 1048576,
1507 "TRUSTED_FOR_DELEGATION" => 524288,
1508 "SMARTCARD_REQUIRED" => 262144,
1509 "MNS_LOGON_ACCOUNT" => 131072,
1510 "DONT_EXPIRE_PASSWORD" => 65536,
1511 "SERVER_TRUST_ACCOUNT" => 8192,
1512 "WORKSTATION_TRUST_ACCOUNT" => 4096,
1513 "INTERDOMAIN_TRUST_ACCOUNT" => 2048,
1514 "NORMAL_ACCOUNT" => 512,
1515 "TEMP_DUPLICATE_ACCOUNT" => 256,
1516 "ENCRYPTED_TEXT_PWD_ALLOWED" => 128,
1517 "PASSWD_CANT_CHANGE" => 64,
1518 "PASSWD_NOTREQD" => 32,
1520 "HOMEDIR_REQUIRED" => 8,
1521 "ACCOUNTDISABLE" => 2,
1528 foreach ($flags as $flag => $val) {
1529 if ($uacf >= $val) {
1531 $retval[$val] = $flag;
1548 805306368 =>
"NORMAL_ACCOUNT",
1549 805306369 =>
"WORKSTATION_TRUST",
1550 805306370 =>
"INTERDOMAIN_TRUST",
1551 268435456 =>
"SECURITY_GLOBAL_GROUP",
1552 268435457 =>
"DISTRIBUTION_GROUP",
1553 536870912 =>
"SECURITY_LOCAL_GROUP",
1554 536870913 =>
"DISTRIBUTION_LOCAL_GROUP"
1558 foreach ($stypes as $sat => $val) {
1559 if ($samtype == $sat) {
1564 if (empty($retval)) {
1565 $retval =
"UNKNOWN_TYPE_".$samtype;
1579 $dateLargeInt = $value;
1580 if (PHP_INT_SIZE < 8) {
1582 $secsAfterADEpoch = (float) $dateLargeInt / (10000000.);
1585 $secsAfterADEpoch = (int) $dateLargeInt / (10000000);
1587 $ADToUnixConvertor = ((1970 - 1601) * 365.242190) * 86400;
1588 $unixTimeStamp = intval($secsAfterADEpoch - $ADToUnixConvertor);
1589 return $unixTimeStamp;
1603 if ($pagecodefrom ==
'ISO-8859-1' && $conf->file->character_set_client ==
'UTF-8') {
1604 $str = mb_convert_encoding($str,
'UTF-8',
'ISO-8859-1');
1606 if ($pagecodefrom ==
'UTF-8' && $conf->file->character_set_client ==
'ISO-8859-1') {
1607 $str = mb_convert_encoding($str,
'ISO-8859-1');
1622 if ($pagecodeto ==
'ISO-8859-1' && $conf->file->character_set_client ==
'UTF-8') {
1623 $str = mb_convert_encoding($str,
'ISO-8859-1');
1625 if ($pagecodeto ==
'UTF-8' && $conf->file->character_set_client ==
'ISO-8859-1') {
1626 $str = mb_convert_encoding($str,
'UTF-8',
'ISO-8859-1');
1641 if (empty($keygroup)) {
1642 $keygroup =
'LDAP_KEY_GROUPS';
1646 $result = $this->
search($this->groups, $search);
1648 $c = $result[
'count'];
1650 for ($i = 0; $i < $c; $i++) {
1651 $gids[] = $result[$i][
'gidnumber'][0];
1655 return $gids[0] + 1;
Class to manage LDAP features.
add($dn, $info, $user)
Add an LDAP entry LDAP object connect and bind must have been done.
convertTime($value)
Converts ActiveDirectory time to Unix timestamp.
modify($dn, $info, $user)
Modify an LDAP entry LDAP object connect and bind must have been done.
deleteAttribute($dn, $info, $user)
Delete an LDAP attribute in entry LDAP object connect and bind must have been done.
setVersion()
Set LDAP protocol version.
convToOutputCharset($str, $pagecodefrom='UTF-8')
Convert a string into output/memory charset.
littleEndian($hex)
Converts a little-endian hex-number to one, that 'hexdec' can convert Required by Active Directory.
fetch($user, $filter)
Load all attributes of an LDAP user.
update($dn, $info, $user, $olddn, $newrdn='', $newparent='')
Modify an LDAP entry (to use if dn != olddn) LDAP object connect and bind must have been done.
getObjectSid($ldapUser)
Gets LDAP user SID.
updateAttribute($dn, $info, $user)
Update an LDAP attribute in entry LDAP object connect and bind must have been done.
getUserIdentifier()
Returns the correct user identifier to use, based on the LDAP server type.
getAttribute($dn, $filter)
Returns an array containing attributes and values for first record.
close()
Simply closes the connection set up earlier.
parseSAT($samtype)
SamAccountType value to text.
rename($dn, $newrdn, $newparent, $user, $deleteoldrdn=true)
Rename an LDAP entry LDAP object connect and bind must have been done.
getNextGroupGid($keygroup='LDAP_KEY_GROUPS')
Return available value of group GID.
setSizeLimit()
Set LDAP size limit.
binSIDtoText($binsid)
Returns the textual SID Required by Active Directory.
connectBind()
Connect and bind Use this->server, this->serverPort, this->ldapProtocolVersion, this->serverType,...
setReferrals()
Set LDAP referrals.
search($checkDn, $filter)
Search method with filter this->connection must be defined.
getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter=0, $attributeAsArray=array())
Returns an array containing a details or list of LDAP record(s).
getVersion()
Verify LDAP server version.
dumpContent($dn, $info)
Build an LDAP message.
getAttributeValues($filterrecord, $attribute)
Returns an array containing values for an attribute and for first record matching filterrecord.
parseUACF($uacf)
UserAccountControl Flags to more human understandable form...
__construct()
Constructor.
convFromOutputCharset($str, $pagecodeto='UTF-8')
Convert a string from output/memory charset.
serverPing($host, $port=389, $timeout=1)
Ping a server before ldap_connect for avoid waiting.
bind()
Anonymously binds to the connection.
unbind()
Unbind of LDAP server (close connection).
bindauth($bindDn, $pass)
Binds as an authenticated user, which usually allows for write access.
dump($dn, $info)
Dump an LDAP message to ldapinput.in file.
addAttribute($dn, $info, $user)
Add an LDAP attribute in entry LDAP object connect and bind must have been done.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
$conf db name
Only used if Module[ID]Name translation string is not found.