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';
257 const SYNCHRO_NONE = 0;
262 const SYNCHRO_DOLIBARR_TO_LDAP = 1;
267 const SYNCHRO_LDAP_TO_DOLIBARR = 2;
319 global $dolibarr_main_auth_ldap_debug;
324 $this->connectedServer =
'';
326 $ldapdebug = !((empty($dolibarr_main_auth_ldap_debug) || $dolibarr_main_auth_ldap_debug ==
"false"));
330 print
"DEBUG: connectBind<br>\n";
334 if (count($this->server) == 0 || empty($this->server[0])) {
335 $this->error =
'LDAP setup (file conf.php) is not complete';
336 dol_syslog(get_class($this).
"::connectBind ".$this->error, LOG_WARNING);
340 if (!function_exists(
"ldap_connect")) {
341 $this->error =
'LDAPFunctionsNotAvailableOnPHP';
342 dol_syslog(get_class($this).
"::connectBind ".$this->error, LOG_WARNING);
346 if (empty($this->error)) {
348 foreach ($this->server as $host) {
356 if ($this->
serverPing($host, $this->serverPort)) {
358 dol_syslog(get_class($this).
"::connectBind serverPing true, we try ldap_connect to ".$host, LOG_DEBUG);
360 if (version_compare(PHP_VERSION,
'8.3.0',
'>=')) {
364 $uri = preg_match(
'/^ldaps?:\/\//i', $host) ? $host :
'ldap://'.$host.
':'.$this->serverPort;
365 $this->connection = ldap_connect($uri);
367 $this->connection = ldap_connect($host, $this->serverPort);
370 if (preg_match(
'/^ldaps/i', $host)) {
374 dol_syslog(get_class($this).
"::connectBind serverPing false, we try ldap_connect to ".$host, LOG_DEBUG);
376 if (version_compare(PHP_VERSION,
'8.3.0',
'>=')) {
377 $uri = preg_match(
'/^ldaps?:\/\//i', $host) ? $host :
'ldap://'.$host.
':'.$this->serverPort;
378 $this->connection = ldap_connect($uri);
380 $this->connection = ldap_connect($host, $this->serverPort);
384 dol_syslog(get_class($this).
"::connectBind serverPing false, no ldap_connect ".$host, LOG_DEBUG);
390 if (is_resource($this->connection) || is_object($this->connection)) {
392 dol_syslog(get_class($this).
"::connectBind this->connection is ok", LOG_DEBUG);
402 $resulttls = ldap_start_tls($this->connection);
404 dol_syslog(get_class($this).
"::connectBind failed to start tls", LOG_WARNING);
405 $this->error =
'ldap_start_tls Failed to start TLS '.ldap_errno($this->connection).
' '.ldap_error($this->connection);
415 if ($this->serverType ==
"activedirectory") {
417 dol_syslog(get_class($this).
"::connectBind try bindauth for activedirectory on ".$host.
" user=".$this->searchUser.
" password=".preg_replace(
'/./',
'*', $this->searchPassword), LOG_DEBUG);
418 $this->result = $this->
bindauth($this->searchUser, $this->searchPassword);
420 $this->
bind = $this->result;
422 $this->connectedServer = $host;
425 $this->error = ldap_errno($this->connection).
' '.ldap_error($this->connection);
429 if ($this->searchUser && $this->searchPassword) {
430 dol_syslog(get_class($this).
"::connectBind try bindauth on ".$host.
" user=".$this->searchUser.
" password=".preg_replace(
'/./',
'*', $this->searchPassword), LOG_DEBUG);
431 $this->result = $this->
bindauth($this->searchUser, $this->searchPassword);
433 $this->
bind = $this->result;
435 $this->connectedServer = $host;
438 $this->error = ldap_errno($this->connection).
' '.ldap_error($this->connection);
443 dol_syslog(get_class($this).
"::connectBind try bind anonymously on ".$host, LOG_DEBUG);
444 $result = $this->
bind();
446 $this->
bind = $this->result;
448 $this->connectedServer = $host;
451 $this->error = ldap_errno($this->connection).
' '.ldap_error($this->connection);
464 dol_syslog(get_class($this).
"::connectBind ".$connected, LOG_DEBUG);
467 $this->error =
'Failed to connect to LDAP'.($this->error ?
': '.$this->error :
'');
468 dol_syslog(get_class($this).
"::connectBind ".$this->error, LOG_WARNING);
494 if (!$this->result = @ldap_bind($this->connection)) {
495 $this->ldapErrorCode = ldap_errno($this->connection);
496 $this->ldapErrorText = ldap_error($this->connection);
497 $this->error = $this->ldapErrorCode.
" ".$this->ldapErrorText;
516 if (!$this->result = @ldap_bind($this->connection, $bindDn, $pass)) {
517 $this->ldapErrorCode = ldap_errno($this->connection);
518 $this->ldapErrorText = ldap_error($this->connection);
519 $this->error = $this->ldapErrorCode.
" ".$this->ldapErrorText;
534 $this->result =
true;
535 if (version_compare(PHP_VERSION,
'8.1.0',
'>=')) {
536 if (is_object($this->connection)) {
538 $this->result = ldap_unbind($this->connection);
539 }
catch (Throwable $exception) {
540 $this->error =
'Failed to unbind LDAP connection: '.$exception;
541 $this->result =
false;
542 dol_syslog(get_class($this).
'::unbind - '.$this->error, LOG_WARNING);
546 if (is_resource($this->connection)) {
548 $this->result = @ldap_unbind($this->connection);
566 @ldap_get_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $version);
578 return ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $this->ldapProtocolVersion);
588 return ldap_set_option($this->connection, LDAP_OPT_SIZELIMIT, 0);
599 return ldap_set_option($this->connection, LDAP_OPT_REFERRALS, 0);
612 public function add($dn, $info, $user)
614 dol_syslog(get_class($this).
"::add dn=".$dn.
" info=".print_r($info,
true));
617 if (!$this->connection) {
618 $this->error =
"NotConnected";
622 $this->error =
"NotConnected";
628 foreach ($info as $key => $val) {
629 if (!is_array($val)) {
634 $this->
dump($dn, $info);
637 $result = @ldap_add($this->connection, $dn, $info);
640 dol_syslog(get_class($this).
"::add successful", LOG_DEBUG);
643 $this->ldapErrorCode = @ldap_errno($this->connection);
644 $this->ldapErrorText = @ldap_error($this->connection);
645 $this->error = $this->ldapErrorCode.
" ".$this->ldapErrorText;
646 dol_syslog(get_class($this).
"::add failed: ".$this->error, LOG_ERR);
660 public function modify($dn, $info, $user)
662 dol_syslog(get_class($this).
"::modify dn=".$dn.
" info=".print_r($info,
true));
665 if (!$this->connection) {
666 $this->error =
"NotConnected";
670 $this->error =
"NotConnected";
676 foreach ($info as $key => $val) {
677 if (!is_array($val)) {
682 $this->
dump($dn, $info);
687 if ($this->serverType ==
"activedirectory") {
691 if (isset($info[
'unicodePwd'])) {
692 $info[
'unicodePwd'] = mb_convert_encoding(
"\"".$info[
'unicodePwd'].
"\"",
"UTF-16LE",
"UTF-8");
695 $result = @ldap_mod_replace($this->connection, $dn, $info);
698 dol_syslog(get_class($this).
"::modify successful", LOG_DEBUG);
701 $this->error = @ldap_error($this->connection);
702 dol_syslog(get_class($this).
"::modify failed: ".$this->error, LOG_ERR);
718 public function rename($dn, $newrdn, $newparent, $user, $deleteoldrdn =
true)
720 dol_syslog(get_class($this).
"::modify dn=".$dn.
" newrdn=".$newrdn.
" newparent=".$newparent.
" deleteoldrdn=".($deleteoldrdn ? 1 : 0));
723 if (!$this->connection) {
724 $this->error =
"NotConnected";
728 $this->error =
"NotConnected";
738 $result = @ldap_rename($this->connection, $dn, $newrdn, $newparent, $deleteoldrdn);
741 dol_syslog(get_class($this).
"::rename successful", LOG_DEBUG);
744 $this->error = @ldap_error($this->connection);
745 dol_syslog(get_class($this).
"::rename failed: ".$this->error, LOG_ERR);
762 public function update($dn, $info, $user, $olddn, $newrdn =
'', $newparent =
'')
764 dol_syslog(get_class($this).
"::update dn=".$dn.
" olddn=".$olddn);
767 if (!$this->connection) {
768 $this->error =
"NotConnected";
772 $this->error =
"NotConnected";
776 if (!$olddn || $olddn != $dn) {
777 if (!empty($olddn) && !empty($newrdn) && !empty($newparent) && $this->ldapProtocolVersion ===
'3') {
779 $result = $this->
rename($olddn, $newrdn, $newparent, $user,
true);
780 $result = $this->
modify($dn, $info, $user);
783 $result = $this->
add($dn, $info, $user);
784 if ($result > 0 && $olddn && $olddn != $dn) {
785 $result = $this->
delete($olddn);
790 $result = $this->
add($dn, $info, $user);
791 $result = $this->
modify($dn, $info, $user);
794 $this->error = ldap_error($this->connection).
' (Code '.ldap_errno($this->connection).
") ".$this->error;
795 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
799 dol_syslog(get_class($this).
"::update done successfully");
812 public function delete($dn)
814 dol_syslog(get_class($this).
"::delete Delete LDAP entry dn=".$dn);
817 if (!$this->connection) {
818 $this->error =
"NotConnected";
822 $this->error =
"NotConnected";
829 $result = @ldap_delete($this->connection, $dn);
849 if (preg_match(
'/^ldap/', $this->server[0])) {
850 $target =
"-H ".implode(
',', $this->server);
852 $target =
"-h ".implode(
',', $this->server).
" -p ".$this->serverPort;
854 $content .=
"# ldapadd $target -c -v -D ".$this->searchUser.
" -W -f ldapinput.in\n";
855 $content .=
"# ldapmodify $target -c -v -D ".$this->searchUser.
" -W -f ldapinput.in\n";
856 $content .=
"# ldapdelete $target -c -v -D ".$this->searchUser.
" -W -f ldapinput.in\n";
857 if (in_array(
'localhost', $this->server)) {
858 $content .=
"# If commands fails to connect, try without -h and -p\n";
860 $content .=
"dn: ".$dn.
"\n";
861 foreach ($info as $key => $value) {
862 if (!is_array($value)) {
863 $content .=
"$key: $value\n";
865 foreach ($value as $valuevalue) {
866 $content .=
"$key: $valuevalue\n";
880 public function dump($dn, $info)
883 $ldapDirTemp = $conf->ldap->dir_temp;
890 $outputfile = $ldapDirTemp.
'/ldapinput.in';
891 $fp = fopen($outputfile,
"w");
893 fwrite($fp, $content);
916 if (preg_match(
'/^ldaps:\/\/([^\/]+)\/?$/', $host, $regs)) {
918 $host =
'ssl://'.$regs[1];
919 } elseif (preg_match(
'/^ldap:\/\/([^\/]+)\/?$/', $host, $regs)) {
928 $errno = $errstr = 0;
937 $op = @fsockopen($host, $port, $errno, $errstr, $timeout);
962 dol_syslog(get_class($this).
"::addAttribute dn=".$dn.
" info=".implode(
',', $info));
965 if (!$this->connection) {
966 $this->error =
"NotConnected";
970 $this->error =
"NotConnected";
976 foreach ($info as $key => $val) {
977 if (!is_array($val)) {
982 $this->
dump($dn, $info);
985 $result = @ldap_mod_add($this->connection, $dn, $info);
988 dol_syslog(get_class($this).
"::add_attribute successful", LOG_DEBUG);
991 $this->error = @ldap_error($this->connection);
992 dol_syslog(get_class($this).
"::add_attribute failed: ".$this->error, LOG_ERR);
1008 dol_syslog(get_class($this).
"::updateAttribute dn=".$dn.
" info=".implode(
',', $info));
1011 if (!$this->connection) {
1012 $this->error =
"NotConnected";
1016 $this->error =
"NotConnected";
1022 foreach ($info as $key => $val) {
1023 if (!is_array($val)) {
1028 $this->
dump($dn, $info);
1031 $result = @ldap_mod_replace($this->connection, $dn, $info);
1034 dol_syslog(get_class($this).
"::updateAttribute successful", LOG_DEBUG);
1037 $this->error = @ldap_error($this->connection);
1038 dol_syslog(get_class($this).
"::updateAttribute failed: ".$this->error, LOG_ERR);
1054 dol_syslog(get_class($this).
"::deleteAttribute dn=".$dn.
" info=".implode(
',', $info));
1057 if (!$this->connection) {
1058 $this->error =
"NotConnected";
1062 $this->error =
"NotConnected";
1068 foreach ($info as $key => $val) {
1069 if (!is_array($val)) {
1074 $this->
dump($dn, $info);
1077 $result = @ldap_mod_del($this->connection, $dn, $info);
1080 dol_syslog(get_class($this).
"::deleteAttribute successful", LOG_DEBUG);
1083 $this->error = @ldap_error($this->connection);
1084 dol_syslog(get_class($this).
"::deleteAttribute failed: ".$this->error, LOG_ERR);
1101 if (!$this->connection) {
1102 $this->error =
"NotConnected";
1106 $this->error =
"NotConnected";
1113 if (!empty($this->filter) && !preg_match(
'/^\s*\(\s*&\s*\(/', $filter)) {
1114 $filter =
'(&(' . $this->filter .
')' . $filter .
')';
1117 $search = @ldap_search($this->connection, $dn, $filter);
1120 $entry = @ldap_first_entry($this->connection, $search);
1123 $this->ldapErrorCode = -1;
1124 $this->ldapErrorText =
"Couldn't find entry";
1129 if (!($values = ldap_get_attributes($this->connection, $entry))) {
1130 $this->ldapErrorCode = ldap_errno($this->connection);
1131 $this->ldapErrorText = ldap_error($this->connection);
1148 $attributes = array();
1149 $attributes[0] = $attribute;
1152 $this->result = @ldap_search($this->connection, $this->people, $filterrecord, $attributes);
1158 $entry = ldap_first_entry($this->connection, $this->result);
1161 $this->ldapErrorCode = -1;
1162 $this->ldapErrorText =
"Couldn't find user";
1167 if (!$values = @ldap_get_values_len($this->connection, $entry, $attribute)) {
1168 $this->ldapErrorCode = ldap_errno($this->connection);
1169 $this->ldapErrorText = ldap_error($this->connection);
1189 public function getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter = 0, $attributeAsArray = array())
1191 $fulllist = array();
1193 dol_syslog(get_class($this).
"::getRecords search=".$search.
" userDn=".$userDn.
" useridentifier=".$useridentifier.
" attributeArray=array(".implode(
',', $attributeArray).
") activefilter=".$activefilter);
1196 if ($this->serverType ==
"activedirectory") {
1197 $this->
bindauth($this->searchUser, $this->searchPassword);
1198 dol_syslog(get_class($this).
"::bindauth serverType=activedirectory searchUser=".$this->searchUser);
1202 if (!empty($activefilter)) {
1203 if (((
string) $activefilter ==
'1' || (
string) $activefilter ==
'user') && $this->filter) {
1204 $filter =
'('.$this->filter.
')';
1205 } elseif (((
string) $activefilter ==
'group') && $this->filtergroup) {
1206 $filter =
'('.$this->filtergroup.
')';
1207 } elseif (((
string) $activefilter ==
'member') && $this->filter) {
1208 $filter =
'('.$this->filtermember.
')';
1211 $filter =
'('.ldap_escape($useridentifier,
'', LDAP_ESCAPE_FILTER).
'=*)';
1214 $filter =
'('.ldap_escape($useridentifier,
'', LDAP_ESCAPE_FILTER).
'='.ldap_escape($search,
'', LDAP_ESCAPE_FILTER).
')';
1217 if (is_array($attributeArray)) {
1219 $attributeArray = array_values($attributeArray);
1220 dol_syslog(get_class($this).
"::getRecords connection=".$this->connectedServer.
":".$this->serverPort.
" userDn=".$userDn.
" filter=".$filter.
" attributeArray=(".implode(
',', $attributeArray).
")");
1222 $this->result = @ldap_search($this->connection, $userDn, $filter, $attributeArray);
1225 dol_syslog(get_class($this).
"::getRecords connection=".$this->connectedServer.
":".$this->serverPort.
" userDn=".$userDn.
" filter=".$filter);
1226 $this->result = @ldap_search($this->connection, $userDn, $filter);
1228 if (!$this->result) {
1229 $this->error =
'LDAP search failed: '.ldap_errno($this->connection).
" ".ldap_error($this->connection);
1233 $info = @ldap_get_entries($this->connection, $this->result);
1239 for ($i = 0; $i < $info[
"count"]; $i++) {
1240 $recordid = $this->
convToOutputCharset($info[$i][strtolower($useridentifier)][0], $this->ldapcharset);
1243 $fulllist[$recordid][$useridentifier] = $recordid;
1246 $num = count($attributeArray);
1247 for ($j = 0; $j < $num; $j++) {
1248 $keyattributelower = strtolower($attributeArray[$j]);
1252 if ($this->serverType ==
"activedirectory" && $keyattributelower ==
"objectsid") {
1254 $fulllist[$recordid][$attributeArray[$j]] = $objectsid;
1256 if (in_array($attributeArray[$j], $attributeAsArray) && is_array($info[$i][$keyattributelower])) {
1257 $valueTab = array();
1258 foreach ($info[$i][$keyattributelower] as $key => $value) {
1261 $fulllist[$recordid][$attributeArray[$j]] = $valueTab;
1263 $fulllist[$recordid][$attributeArray[$j]] = $this->
convToOutputCharset($info[$i][$keyattributelower][0], $this->ldapcharset);
1284 for ($x =
dol_strlen($hex) - 2; $x >= 0; $x -= 2) {
1285 $result .= substr($hex, $x, 2);
1300 $criteria =
'('.$this->getUserIdentifier().
'='.$ldapUser.
')';
1301 $justthese = array(
"objectsid");
1304 if ($this->serverType ==
"activedirectory") {
1305 $this->
bindauth($this->searchUser, $this->searchPassword);
1310 $searchDN = $this->people;
1313 $ldapSearchResult = @ldap_search($this->connection, $searchDN, $criteria, $justthese);
1315 if (!$ldapSearchResult) {
1316 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1320 $entry = ldap_first_entry($this->connection, $ldapSearchResult);
1324 $searchDN = $this->domain;
1333 $ldapBinary = ldap_get_values_len($this->connection, $entry,
"objectsid");
1337 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1351 $hex_sid = bin2hex($binsid);
1352 $rev = hexdec(substr($hex_sid, 0, 2));
1353 $subcount = hexdec(substr($hex_sid, 2, 2));
1354 $auth = hexdec(substr($hex_sid, 4, 12));
1355 $result =
"$rev-$auth";
1356 for ($x = 0; $x < $subcount; $x++) {
1357 $result .=
"-".hexdec($this->
littleEndian(substr($hex_sid, 16 + ($x * 8), 8)));
1378 dol_syslog(get_class($this).
"::search checkDn=".$checkDn.
" filter=".$filter);
1384 if ($this->serverType ==
"activedirectory") {
1385 $this->
bindauth($this->searchUser, $this->searchPassword);
1388 $this->result = @ldap_search($this->connection, $checkDn, $filter);
1390 $result = @ldap_get_entries($this->connection, $this->result);
1392 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1395 ldap_free_result($this->result);
1414 if ($this->serverType ==
"activedirectory") {
1415 $this->
bindauth($this->searchUser, $this->searchPassword);
1418 $searchDN = $this->people;
1423 dol_syslog(get_class($this).
"::fetch search with searchDN=".$searchDN.
" filter=".$filter);
1424 $this->result = @ldap_search($this->connection, $searchDN, $filter);
1425 if ($this->result) {
1426 $result = @ldap_get_entries($this->connection, $this->result);
1427 if ($result[
'count'] > 0) {
1428 dol_syslog(
'Ldap::fetch search found '.$result[
'count'].
' records');
1430 dol_syslog(
'Ldap::fetch search returns but found no records');
1434 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1435 dol_syslog(get_class($this).
"::fetch search fails");
1441 $searchDN = $this->domain;
1449 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1453 $this->firstname = $this->
convToOutputCharset($result[0][$this->attr_firstname][0], $this->ldapcharset);
1454 $this->login = $this->
convToOutputCharset($result[0][$this->attr_login][0], $this->ldapcharset);
1455 $this->phone = $this->
convToOutputCharset($result[0][$this->attr_phone][0], $this->ldapcharset);
1456 $this->fax = $this->
convToOutputCharset($result[0][$this->attr_fax][0], $this->ldapcharset);
1457 $this->mail = $this->
convToOutputCharset($result[0][$this->attr_mail][0], $this->ldapcharset);
1458 $this->mobile = $this->
convToOutputCharset($result[0][$this->attr_mobile][0], $this->ldapcharset);
1461 if (isset($result[0][
"pwdlastset"][0])) {
1462 $this->pwdlastset = ($result[0][
"pwdlastset"][0] != 0) ? $this->
convertTime($this->
convToOutputCharset($result[0][
"pwdlastset"][0], $this->ldapcharset)) : 0;
1464 $this->pwdlastset = -1;
1466 if (!$this->
name && !$this->login) {
1467 $this->pwdlastset = -1;
1472 $domain = str_replace(
'dc=',
'', $this->domain);
1473 $domain = str_replace(
',',
'.', $domain);
1474 $this->domainFQDN = $domain;
1478 $this->ldapUserDN = $result[0][
'dn'];
1480 ldap_free_result($this->result);
1495 if ($this->serverType ==
"activedirectory") {
1496 return $this->attr_sambalogin;
1498 return $this->attr_login;
1512 "TRUSTED_TO_AUTH_FOR_DELEGATION" => 16777216,
1513 "PASSWORD_EXPIRED" => 8388608,
1514 "DONT_REQ_PREAUTH" => 4194304,
1515 "USE_DES_KEY_ONLY" => 2097152,
1516 "NOT_DELEGATED" => 1048576,
1517 "TRUSTED_FOR_DELEGATION" => 524288,
1518 "SMARTCARD_REQUIRED" => 262144,
1519 "MNS_LOGON_ACCOUNT" => 131072,
1520 "DONT_EXPIRE_PASSWORD" => 65536,
1521 "SERVER_TRUST_ACCOUNT" => 8192,
1522 "WORKSTATION_TRUST_ACCOUNT" => 4096,
1523 "INTERDOMAIN_TRUST_ACCOUNT" => 2048,
1524 "NORMAL_ACCOUNT" => 512,
1525 "TEMP_DUPLICATE_ACCOUNT" => 256,
1526 "ENCRYPTED_TEXT_PWD_ALLOWED" => 128,
1527 "PASSWD_CANT_CHANGE" => 64,
1528 "PASSWD_NOTREQD" => 32,
1530 "HOMEDIR_REQUIRED" => 8,
1531 "ACCOUNTDISABLE" => 2,
1538 foreach ($flags as $flag => $val) {
1539 if ($uacf >= $val) {
1541 $retval[$val] = $flag;
1558 805306368 =>
"NORMAL_ACCOUNT",
1559 805306369 =>
"WORKSTATION_TRUST",
1560 805306370 =>
"INTERDOMAIN_TRUST",
1561 268435456 =>
"SECURITY_GLOBAL_GROUP",
1562 268435457 =>
"DISTRIBUTION_GROUP",
1563 536870912 =>
"SECURITY_LOCAL_GROUP",
1564 536870913 =>
"DISTRIBUTION_LOCAL_GROUP"
1568 foreach ($stypes as $sat => $val) {
1569 if ($samtype == $sat) {
1574 if (empty($retval)) {
1575 $retval =
"UNKNOWN_TYPE_".$samtype;
1589 $dateLargeInt = $value;
1590 if (PHP_INT_SIZE < 8) {
1592 $secsAfterADEpoch = (float) $dateLargeInt / (10000000.);
1595 $secsAfterADEpoch = (int) $dateLargeInt / (10000000);
1597 $ADToUnixConvertor = ((1970 - 1601) * 365.242190) * 86400;
1598 $unixTimeStamp = intval($secsAfterADEpoch - $ADToUnixConvertor);
1599 return $unixTimeStamp;
1613 if ($pagecodefrom ==
'ISO-8859-1' && $conf->file->character_set_client ==
'UTF-8') {
1614 $str = mb_convert_encoding($str,
'UTF-8',
'ISO-8859-1');
1616 if ($pagecodefrom ==
'UTF-8' && $conf->file->character_set_client ==
'ISO-8859-1') {
1617 $str = mb_convert_encoding($str,
'ISO-8859-1');
1632 if ($pagecodeto ==
'ISO-8859-1' && $conf->file->character_set_client ==
'UTF-8') {
1633 $str = mb_convert_encoding($str,
'ISO-8859-1');
1635 if ($pagecodeto ==
'UTF-8' && $conf->file->character_set_client ==
'ISO-8859-1') {
1636 $str = mb_convert_encoding($str,
'UTF-8',
'ISO-8859-1');
1651 if (empty($keygroup)) {
1652 $keygroup =
'LDAP_KEY_GROUPS';
1656 $result = $this->
search($this->groups, $search);
1658 $c = $result[
'count'];
1660 for ($i = 0; $i <
$c; $i++) {
1661 $gids[] = $result[$i][
'gidnumber'][0];
1665 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.