49 public $errors = array();
54 public $server = array();
59 public $connectedServer;
80 public $ldapProtocolVersion;
106 public $searchPassword;
121 public $ldapErrorCode;
126 public $ldapErrorText;
141 public $filtermember;
151 public $attr_sambalogin;
161 public $attr_firstname;
242 public $ldapcharset =
'UTF-8';
258 const SYNCHRO_NONE = 0;
263 const SYNCHRO_DOLIBARR_TO_LDAP = 1;
268 const SYNCHRO_LDAP_TO_DOLIBARR = 2;
320 global $dolibarr_main_auth_ldap_debug;
325 $this->connectedServer =
'';
327 $ldapdebug = !((empty($dolibarr_main_auth_ldap_debug) || $dolibarr_main_auth_ldap_debug ==
"false"));
331 print
"DEBUG: connectBind<br>\n";
335 if (count($this->server) == 0 || empty($this->server[0])) {
336 $this->error =
'LDAP setup (file conf.php) is not complete';
337 dol_syslog(get_class($this).
"::connectBind ".$this->error, LOG_WARNING);
341 if (!function_exists(
"ldap_connect")) {
342 $this->error =
'LDAPFunctionsNotAvailableOnPHP';
343 dol_syslog(get_class($this).
"::connectBind ".$this->error, LOG_WARNING);
347 if (empty($this->error)) {
349 foreach ($this->server as $host) {
357 if ($this->
serverPing($host, $this->serverPort)) {
359 dol_syslog(get_class($this).
"::connectBind serverPing true, we try ldap_connect to ".$host, LOG_DEBUG);
361 if (version_compare(PHP_VERSION,
'8.3.0',
'>=')) {
365 $uri = preg_match(
'/^ldaps?:\/\//i', $host) ? $host :
'ldap://'.$host.
':'.$this->serverPort;
366 $this->connection = ldap_connect($uri);
368 $this->connection = ldap_connect($host, $this->serverPort);
371 if (preg_match(
'/^ldaps/i', $host)) {
375 dol_syslog(get_class($this).
"::connectBind serverPing false, we try ldap_connect to ".$host, LOG_DEBUG);
377 if (version_compare(PHP_VERSION,
'8.3.0',
'>=')) {
378 $uri = preg_match(
'/^ldaps?:\/\//i', $host) ? $host :
'ldap://'.$host.
':'.$this->serverPort;
379 $this->connection = ldap_connect($uri);
381 $this->connection = ldap_connect($host, $this->serverPort);
385 dol_syslog(get_class($this).
"::connectBind serverPing false, no ldap_connect ".$host, LOG_DEBUG);
391 if ($this->connection !==
false) {
393 dol_syslog(get_class($this).
"::connectBind this->connection is ok", LOG_DEBUG);
403 $resulttls = ldap_start_tls($this->connection);
405 dol_syslog(get_class($this).
"::connectBind failed to start tls", LOG_WARNING);
406 $this->error =
'ldap_start_tls Failed to start TLS '.ldap_errno($this->connection).
' '.ldap_error($this->connection);
416 if ($this->serverType ==
"activedirectory") {
418 dol_syslog(get_class($this).
"::connectBind try bindauth for activedirectory on ".$host.
" user=".$this->searchUser.
" password=".preg_replace(
'/./',
'*', $this->searchPassword), LOG_DEBUG);
419 $this->result = $this->
bindauth($this->searchUser, $this->searchPassword);
421 $this->
bind = $this->result;
423 $this->connectedServer = $host;
426 $this->error = ldap_errno($this->connection).
' '.ldap_error($this->connection);
430 if ($this->searchUser && $this->searchPassword) {
431 dol_syslog(get_class($this).
"::connectBind try bindauth on ".$host.
" user=".$this->searchUser.
" password=".preg_replace(
'/./',
'*', $this->searchPassword), LOG_DEBUG);
432 $this->result = $this->
bindauth($this->searchUser, $this->searchPassword);
434 $this->
bind = $this->result;
436 $this->connectedServer = $host;
439 $this->error = ldap_errno($this->connection).
' '.ldap_error($this->connection);
444 dol_syslog(get_class($this).
"::connectBind try bind anonymously on ".$host, LOG_DEBUG);
445 $result = $this->
bind();
447 $this->
bind = $this->result;
449 $this->connectedServer = $host;
452 $this->error = ldap_errno($this->connection).
' '.ldap_error($this->connection);
465 dol_syslog(get_class($this).
"::connectBind ".$connected, LOG_DEBUG);
468 $this->error =
'Failed to connect to LDAP'.($this->error ?
': '.$this->error :
'');
469 dol_syslog(get_class($this).
"::connectBind ".$this->error, LOG_WARNING);
495 if (!$this->result = @ldap_bind($this->connection)) {
496 $this->ldapErrorCode = ldap_errno($this->connection);
497 $this->ldapErrorText = ldap_error($this->connection);
498 $this->error = $this->ldapErrorCode.
" ".$this->ldapErrorText;
517 if (!$this->result = @ldap_bind($this->connection, $bindDn, $pass)) {
518 $this->ldapErrorCode = ldap_errno($this->connection);
519 $this->ldapErrorText = ldap_error($this->connection);
520 $this->error = $this->ldapErrorCode.
" ".$this->ldapErrorText;
535 $this->result =
true;
536 if (version_compare(PHP_VERSION,
'8.1.0',
'>=')) {
537 if (is_object($this->connection)) {
539 $this->result = ldap_unbind($this->connection);
540 }
catch (Throwable $exception) {
541 $this->error =
'Failed to unbind LDAP connection: '.$exception;
542 $this->result =
false;
543 dol_syslog(get_class($this).
'::unbind - '.$this->error, LOG_WARNING);
547 if ($this->connection !==
false) {
549 $this->result = @ldap_unbind($this->connection);
567 @ldap_get_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $version);
579 return ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $this->ldapProtocolVersion);
589 return ldap_set_option($this->connection, LDAP_OPT_SIZELIMIT, 0);
600 return ldap_set_option($this->connection, LDAP_OPT_REFERRALS, 0);
613 public function add($dn, $info, $user)
615 dol_syslog(get_class($this).
"::add dn=".$dn.
" info=".print_r($info,
true));
618 if (!$this->connection) {
619 $this->error =
"NotConnected";
623 $this->error =
"NotConnected";
629 foreach ($info as $key => $val) {
630 if (!is_array($val)) {
635 $this->
dump($dn, $info);
638 $result = @ldap_add($this->connection, $dn, $info);
641 dol_syslog(get_class($this).
"::add successful", LOG_DEBUG);
644 $this->ldapErrorCode = @ldap_errno($this->connection);
645 $this->ldapErrorText = @ldap_error($this->connection);
646 $this->error = $this->ldapErrorCode.
" ".$this->ldapErrorText;
647 dol_syslog(get_class($this).
"::add failed: ".$this->error, LOG_ERR);
661 public function modify($dn, $info, $user)
663 dol_syslog(get_class($this).
"::modify dn=".$dn.
" info=".print_r($info,
true));
666 if (!$this->connection) {
667 $this->error =
"NotConnected";
671 $this->error =
"NotConnected";
677 foreach ($info as $key => $val) {
678 if (!is_array($val)) {
683 $this->
dump($dn, $info);
688 if ($this->serverType ==
"activedirectory") {
692 if (isset($info[
'unicodePwd'])) {
693 $info[
'unicodePwd'] = mb_convert_encoding(
"\"".$info[
'unicodePwd'].
"\"",
"UTF-16LE",
"UTF-8");
696 $result = @ldap_mod_replace($this->connection, $dn, $info);
699 dol_syslog(get_class($this).
"::modify successful", LOG_DEBUG);
702 $this->error = @ldap_error($this->connection);
703 dol_syslog(get_class($this).
"::modify failed: ".$this->error, LOG_ERR);
719 public function rename($dn, $newrdn, $newparent, $user, $deleteoldrdn =
true)
721 dol_syslog(get_class($this).
"::modify dn=".$dn.
" newrdn=".$newrdn.
" newparent=".$newparent.
" deleteoldrdn=".($deleteoldrdn ? 1 : 0));
724 if (!$this->connection) {
725 $this->error =
"NotConnected";
729 $this->error =
"NotConnected";
739 $result = @ldap_rename($this->connection, $dn, $newrdn, $newparent, $deleteoldrdn);
742 dol_syslog(get_class($this).
"::rename successful", LOG_DEBUG);
745 $this->error = @ldap_error($this->connection);
746 dol_syslog(get_class($this).
"::rename failed: ".$this->error, LOG_ERR);
763 public function update($dn, $info, $user, $olddn, $newrdn =
'', $newparent =
'')
765 dol_syslog(get_class($this).
"::update dn=".$dn.
" olddn=".$olddn);
768 if (!$this->connection) {
769 $this->error =
"NotConnected";
773 $this->error =
"NotConnected";
777 if (!$olddn || $olddn != $dn) {
778 if (!empty($olddn) && !empty($newrdn) && !empty($newparent) && $this->ldapProtocolVersion ===
'3') {
780 $result = $this->
rename($olddn, $newrdn, $newparent, $user,
true);
781 $result = $this->
modify($dn, $info, $user);
784 $result = $this->
add($dn, $info, $user);
785 if ($result > 0 && $olddn && $olddn != $dn) {
786 $result = $this->
delete($olddn);
791 $result = $this->
add($dn, $info, $user);
792 $result = $this->
modify($dn, $info, $user);
795 $this->error = ldap_error($this->connection).
' (Code '.ldap_errno($this->connection).
") ".$this->error;
796 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
800 dol_syslog(get_class($this).
"::update done successfully");
813 public function delete($dn)
815 dol_syslog(get_class($this).
"::delete Delete LDAP entry dn=".$dn);
818 if (!$this->connection) {
819 $this->error =
"NotConnected";
823 $this->error =
"NotConnected";
830 $result = @ldap_delete($this->connection, $dn);
850 if (preg_match(
'/^ldap/', $this->server[0])) {
851 $target =
"-H ".implode(
',', $this->server);
853 $target =
"-h ".implode(
',', $this->server).
" -p ".$this->serverPort;
855 $content .=
"# ldapadd $target -c -v -D ".$this->searchUser.
" -W -f ldapinput.in\n";
856 $content .=
"# ldapmodify $target -c -v -D ".$this->searchUser.
" -W -f ldapinput.in\n";
857 $content .=
"# ldapdelete $target -c -v -D ".$this->searchUser.
" -W -f ldapinput.in\n";
858 if (in_array(
'localhost', $this->server)) {
859 $content .=
"# If commands fails to connect, try without -h and -p\n";
861 $content .=
"dn: ".$dn.
"\n";
862 foreach ($info as $key => $value) {
863 if (!is_array($value)) {
864 $content .=
"$key: $value\n";
866 foreach ($value as $valuevalue) {
867 $content .=
"$key: $valuevalue\n";
881 public function dump($dn, $info)
884 $ldapDirTemp =
$conf->ldap->dir_temp;
891 $outputfile = $ldapDirTemp.
'/ldapinput.in';
892 $fp = fopen($outputfile,
"w");
894 fwrite($fp, $content);
917 if (preg_match(
'/^ldaps:\/\/([^\/]+)\/?$/', $host, $regs)) {
919 $host =
'ssl://'.$regs[1];
920 } elseif (preg_match(
'/^ldap:\/\/([^\/]+)\/?$/', $host, $regs)) {
929 $errno = $errstr = 0;
938 $op = @fsockopen($host, $port, $errno, $errstr, $timeout);
963 dol_syslog(get_class($this).
"::addAttribute dn=".$dn.
" info=".implode(
',', $info));
966 if (!$this->connection) {
967 $this->error =
"NotConnected";
971 $this->error =
"NotConnected";
977 foreach ($info as $key => $val) {
978 if (!is_array($val)) {
983 $this->
dump($dn, $info);
986 $result = @ldap_mod_add($this->connection, $dn, $info);
989 dol_syslog(get_class($this).
"::add_attribute successful", LOG_DEBUG);
992 $this->error = @ldap_error($this->connection);
993 dol_syslog(get_class($this).
"::add_attribute failed: ".$this->error, LOG_ERR);
1009 dol_syslog(get_class($this).
"::updateAttribute dn=".$dn.
" info=".implode(
',', $info));
1012 if (!$this->connection) {
1013 $this->error =
"NotConnected";
1017 $this->error =
"NotConnected";
1023 foreach ($info as $key => $val) {
1024 if (!is_array($val)) {
1029 $this->
dump($dn, $info);
1032 $result = @ldap_mod_replace($this->connection, $dn, $info);
1035 dol_syslog(get_class($this).
"::updateAttribute successful", LOG_DEBUG);
1038 $this->error = @ldap_error($this->connection);
1039 dol_syslog(get_class($this).
"::updateAttribute failed: ".$this->error, LOG_ERR);
1055 dol_syslog(get_class($this).
"::deleteAttribute dn=".$dn.
" info=".implode(
',', $info));
1058 if (!$this->connection) {
1059 $this->error =
"NotConnected";
1063 $this->error =
"NotConnected";
1069 foreach ($info as $key => $val) {
1070 if (!is_array($val)) {
1075 $this->
dump($dn, $info);
1078 $result = @ldap_mod_del($this->connection, $dn, $info);
1081 dol_syslog(get_class($this).
"::deleteAttribute successful", LOG_DEBUG);
1084 $this->error = @ldap_error($this->connection);
1085 dol_syslog(get_class($this).
"::deleteAttribute failed: ".$this->error, LOG_ERR);
1102 if (!$this->connection) {
1103 $this->error =
"NotConnected";
1107 $this->error =
"NotConnected";
1114 if (!empty($this->filter) && !preg_match(
'/^\s*\(\s*&\s*\(/', $filter)) {
1115 $filter =
'(&(' . $this->filter .
')' . $filter .
')';
1118 $search = @ldap_search($this->connection, $dn, $filter);
1121 $entry = @ldap_first_entry($this->connection, $search);
1124 $this->ldapErrorCode = -1;
1125 $this->ldapErrorText =
"Couldn't find entry";
1130 if (!($values = ldap_get_attributes($this->connection, $entry))) {
1131 $this->ldapErrorCode = ldap_errno($this->connection);
1132 $this->ldapErrorText = ldap_error($this->connection);
1149 $attributes = array();
1150 $attributes[0] = $attribute;
1153 $this->result = @ldap_search($this->connection, $this->people, $filterrecord, $attributes);
1159 $entry = ldap_first_entry($this->connection, $this->result);
1162 $this->ldapErrorCode = -1;
1163 $this->ldapErrorText =
"Couldn't find user";
1168 if (!$values = @ldap_get_values_len($this->connection, $entry, $attribute)) {
1169 $this->ldapErrorCode = ldap_errno($this->connection);
1170 $this->ldapErrorText = ldap_error($this->connection);
1190 public function getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter = 0, $attributeAsArray = array())
1192 $fulllist = array();
1194 dol_syslog(get_class($this).
"::getRecords search=".$search.
" userDn=".$userDn.
" useridentifier=".$useridentifier.
" attributeArray=array(".implode(
',', $attributeArray).
") activefilter=".$activefilter);
1197 if ($this->serverType ==
"activedirectory") {
1198 $this->
bindauth($this->searchUser, $this->searchPassword);
1199 dol_syslog(get_class($this).
"::bindauth serverType=activedirectory searchUser=".$this->searchUser);
1203 if (!empty($activefilter)) {
1204 if (((
string) $activefilter ==
'1' || (
string) $activefilter ==
'user') && $this->filter) {
1205 $filter =
'('.$this->filter.
')';
1206 } elseif (((
string) $activefilter ==
'group') && $this->filtergroup) {
1207 $filter =
'('.$this->filtergroup.
')';
1208 } elseif (((
string) $activefilter ==
'member') && $this->filter) {
1209 $filter =
'('.$this->filtermember.
')';
1212 $filter =
'('.ldap_escape($useridentifier,
'', LDAP_ESCAPE_FILTER).
'=*)';
1215 $filter =
'('.ldap_escape($useridentifier,
'', LDAP_ESCAPE_FILTER).
'='.ldap_escape($search,
'', LDAP_ESCAPE_FILTER).
')';
1218 if (is_array($attributeArray)) {
1220 $attributeArray = array_values($attributeArray);
1221 dol_syslog(get_class($this).
"::getRecords connection=".$this->connectedServer.
":".$this->serverPort.
" userDn=".$userDn.
" filter=".$filter.
" attributeArray=(".implode(
',', $attributeArray).
")");
1223 $this->result = @ldap_search($this->connection, $userDn, $filter, $attributeArray);
1226 dol_syslog(get_class($this).
"::getRecords connection=".$this->connectedServer.
":".$this->serverPort.
" userDn=".$userDn.
" filter=".$filter);
1227 $this->result = @ldap_search($this->connection, $userDn, $filter);
1229 if (!$this->result) {
1230 $this->error =
'LDAP search failed: '.ldap_errno($this->connection).
" ".ldap_error($this->connection);
1234 $info = @ldap_get_entries($this->connection, $this->result);
1240 for ($i = 0; $i < $info[
"count"]; $i++) {
1241 $recordid = $this->
convToOutputCharset($info[$i][strtolower($useridentifier)][0], $this->ldapcharset);
1244 $fulllist[$recordid][$useridentifier] = $recordid;
1247 $num = count($attributeArray);
1248 for ($j = 0; $j < $num; $j++) {
1249 $keyattributelower = strtolower($attributeArray[$j]);
1253 if ($this->serverType ==
"activedirectory" && $keyattributelower ==
"objectsid") {
1255 $fulllist[$recordid][$attributeArray[$j]] = $objectsid;
1257 if (in_array($attributeArray[$j], $attributeAsArray) && is_array($info[$i][$keyattributelower])) {
1258 $valueTab = array();
1259 foreach ($info[$i][$keyattributelower] as $key => $value) {
1262 $fulllist[$recordid][$attributeArray[$j]] = $valueTab;
1264 $fulllist[$recordid][$attributeArray[$j]] = $this->
convToOutputCharset($info[$i][$keyattributelower][0], $this->ldapcharset);
1285 for ($x =
dol_strlen($hex) - 2; $x >= 0; $x -= 2) {
1286 $result .= substr($hex, $x, 2);
1301 $criteria =
'('.$this->getUserIdentifier().
'='.$ldapUser.
')';
1302 $justthese = array(
"objectsid");
1305 if ($this->serverType ==
"activedirectory") {
1306 $this->
bindauth($this->searchUser, $this->searchPassword);
1311 $searchDN = $this->people;
1314 $ldapSearchResult = @ldap_search($this->connection, $searchDN, $criteria, $justthese);
1316 if (!$ldapSearchResult) {
1317 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1321 $entry = ldap_first_entry($this->connection, $ldapSearchResult);
1325 $searchDN = $this->domain;
1334 $ldapBinary = ldap_get_values_len($this->connection, $entry,
"objectsid");
1338 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1352 $hex_sid = bin2hex($binsid);
1353 $rev = hexdec(substr($hex_sid, 0, 2));
1354 $subcount = hexdec(substr($hex_sid, 2, 2));
1355 $auth = hexdec(substr($hex_sid, 4, 12));
1356 $result =
"$rev-$auth";
1357 for ($x = 0; $x < $subcount; $x++) {
1358 $result .=
"-".hexdec($this->
littleEndian(substr($hex_sid, 16 + ($x * 8), 8)));
1379 dol_syslog(get_class($this).
"::search checkDn=".$checkDn.
" filter=".$filter);
1385 if ($this->serverType ==
"activedirectory") {
1386 $this->
bindauth($this->searchUser, $this->searchPassword);
1389 $this->result = @ldap_search($this->connection, $checkDn, $filter);
1391 $result = @ldap_get_entries($this->connection, $this->result);
1393 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1396 ldap_free_result($this->result);
1415 if ($this->serverType ==
"activedirectory") {
1416 $this->
bindauth($this->searchUser, $this->searchPassword);
1419 $searchDN = $this->people;
1424 dol_syslog(get_class($this).
"::fetch search with searchDN=".$searchDN.
" filter=".$filter);
1425 $this->result = @ldap_search($this->connection, $searchDN, $filter);
1426 if ($this->result) {
1427 $result = @ldap_get_entries($this->connection, $this->result);
1428 if ($result[
'count'] > 0) {
1429 dol_syslog(
'Ldap::fetch search found '.$result[
'count'].
' records');
1431 dol_syslog(
'Ldap::fetch search returns but found no records');
1435 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1436 dol_syslog(get_class($this).
"::fetch search fails");
1442 $searchDN = $this->domain;
1450 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1454 $this->firstname = $this->
convToOutputCharset($result[0][$this->attr_firstname][0], $this->ldapcharset);
1455 $this->login = $this->
convToOutputCharset($result[0][$this->attr_login][0], $this->ldapcharset);
1456 $this->phone = $this->
convToOutputCharset($result[0][$this->attr_phone][0], $this->ldapcharset);
1457 $this->fax = $this->
convToOutputCharset($result[0][$this->attr_fax][0], $this->ldapcharset);
1458 $this->mail = $this->
convToOutputCharset($result[0][$this->attr_mail][0], $this->ldapcharset);
1459 $this->mobile = $this->
convToOutputCharset($result[0][$this->attr_mobile][0], $this->ldapcharset);
1462 if (isset($result[0][
"pwdlastset"][0])) {
1463 $this->pwdlastset = ($result[0][
"pwdlastset"][0] != 0) ? $this->
convertTime($this->
convToOutputCharset($result[0][
"pwdlastset"][0], $this->ldapcharset)) : 0;
1465 $this->pwdlastset = -1;
1467 if (!$this->
name && !$this->login) {
1468 $this->pwdlastset = -1;
1473 $domain = str_replace(
'dc=',
'', $this->domain);
1474 $domain = str_replace(
',',
'.', $domain);
1475 $this->domainFQDN = $domain;
1479 $this->ldapUserDN = $result[0][
'dn'];
1481 ldap_free_result($this->result);
1496 if ($this->serverType ==
"activedirectory") {
1497 return $this->attr_sambalogin;
1499 return $this->attr_login;
1513 "TRUSTED_TO_AUTH_FOR_DELEGATION" => 16777216,
1514 "PASSWORD_EXPIRED" => 8388608,
1515 "DONT_REQ_PREAUTH" => 4194304,
1516 "USE_DES_KEY_ONLY" => 2097152,
1517 "NOT_DELEGATED" => 1048576,
1518 "TRUSTED_FOR_DELEGATION" => 524288,
1519 "SMARTCARD_REQUIRED" => 262144,
1520 "MNS_LOGON_ACCOUNT" => 131072,
1521 "DONT_EXPIRE_PASSWORD" => 65536,
1522 "SERVER_TRUST_ACCOUNT" => 8192,
1523 "WORKSTATION_TRUST_ACCOUNT" => 4096,
1524 "INTERDOMAIN_TRUST_ACCOUNT" => 2048,
1525 "NORMAL_ACCOUNT" => 512,
1526 "TEMP_DUPLICATE_ACCOUNT" => 256,
1527 "ENCRYPTED_TEXT_PWD_ALLOWED" => 128,
1528 "PASSWD_CANT_CHANGE" => 64,
1529 "PASSWD_NOTREQD" => 32,
1531 "HOMEDIR_REQUIRED" => 8,
1532 "ACCOUNTDISABLE" => 2,
1539 foreach ($flags as $flag => $val) {
1540 if ($uacf >= $val) {
1542 $retval[$val] = $flag;
1559 805306368 =>
"NORMAL_ACCOUNT",
1560 805306369 =>
"WORKSTATION_TRUST",
1561 805306370 =>
"INTERDOMAIN_TRUST",
1562 268435456 =>
"SECURITY_GLOBAL_GROUP",
1563 268435457 =>
"DISTRIBUTION_GROUP",
1564 536870912 =>
"SECURITY_LOCAL_GROUP",
1565 536870913 =>
"DISTRIBUTION_LOCAL_GROUP"
1569 foreach ($stypes as $sat => $val) {
1570 if ($samtype == $sat) {
1575 if (empty($retval)) {
1576 $retval =
"UNKNOWN_TYPE_".$samtype;
1590 $dateLargeInt = $value;
1591 if (PHP_INT_SIZE < 8) {
1593 $secsAfterADEpoch = (float) $dateLargeInt / (10000000.);
1596 $secsAfterADEpoch = (int) $dateLargeInt / (10000000);
1598 $ADToUnixConvertor = ((1970 - 1601) * 365.242190) * 86400;
1599 $unixTimeStamp = intval($secsAfterADEpoch - $ADToUnixConvertor);
1600 return $unixTimeStamp;
1614 if ($pagecodefrom ==
'ISO-8859-1' &&
$conf->file->character_set_client ==
'UTF-8') {
1615 $str = mb_convert_encoding($str,
'UTF-8',
'ISO-8859-1');
1617 if ($pagecodefrom ==
'UTF-8' &&
$conf->file->character_set_client ==
'ISO-8859-1') {
1618 $str = mb_convert_encoding($str,
'ISO-8859-1');
1633 if ($pagecodeto ==
'ISO-8859-1' &&
$conf->file->character_set_client ==
'UTF-8') {
1634 $str = mb_convert_encoding($str,
'ISO-8859-1');
1636 if ($pagecodeto ==
'UTF-8' &&
$conf->file->character_set_client ==
'ISO-8859-1') {
1637 $str = mb_convert_encoding($str,
'UTF-8',
'ISO-8859-1');
1652 if (empty($keygroup)) {
1653 $keygroup =
'LDAP_KEY_GROUPS';
1657 $result = $this->
search($this->groups, $search);
1659 $c = $result[
'count'];
1661 for ($i = 0; $i <
$c; $i++) {
1662 $gids[] = (int) $result[$i][
'gidnumber'][0];
1666 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.