48 public $errors = array();
53 public $server = array();
58 public $connectedServer;
79 public $ldapProtocolVersion;
105 public $searchPassword;
120 public $ldapErrorCode;
125 public $ldapErrorText;
140 public $filtermember;
150 public $attr_sambalogin;
160 public $attr_firstname;
241 public $ldapcharset =
'UTF-8';
256 const SYNCHRO_NONE = 0;
261 const SYNCHRO_DOLIBARR_TO_LDAP = 1;
266 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',
'>=')) {
361 $uri = $host.
':'.$this->serverPort;
362 $this->connection = ldap_connect($uri);
364 $this->connection = ldap_connect($host, $this->serverPort);
367 if (preg_match(
'/^ldaps/i', $host)) {
371 dol_syslog(get_class($this).
"::connectBind serverPing false, we try ldap_connect to ".$host, LOG_DEBUG);
373 if (version_compare(PHP_VERSION,
'8.3.0',
'>=')) {
374 $uri = $host.
':'.$this->serverPort;
375 $this->connection = ldap_connect($uri);
377 $this->connection = ldap_connect($host, $this->serverPort);
381 dol_syslog(get_class($this).
"::connectBind serverPing false, no ldap_connect ".$host, LOG_DEBUG);
387 if (is_resource($this->connection) || is_object($this->connection)) {
389 dol_syslog(get_class($this).
"::connectBind this->connection is ok", LOG_DEBUG);
399 $resulttls = ldap_start_tls($this->connection);
401 dol_syslog(get_class($this).
"::connectBind failed to start tls", LOG_WARNING);
402 $this->error =
'ldap_start_tls Failed to start TLS '.ldap_errno($this->connection).
' '.ldap_error($this->connection);
412 if ($this->serverType ==
"activedirectory") {
414 dol_syslog(get_class($this).
"::connectBind try bindauth for activedirectory on ".$host.
" user=".$this->searchUser.
" password=".preg_replace(
'/./',
'*', $this->searchPassword), LOG_DEBUG);
415 $this->result = $this->
bindauth($this->searchUser, $this->searchPassword);
417 $this->
bind = $this->result;
419 $this->connectedServer = $host;
422 $this->error = ldap_errno($this->connection).
' '.ldap_error($this->connection);
426 if ($this->searchUser && $this->searchPassword) {
427 dol_syslog(get_class($this).
"::connectBind try bindauth on ".$host.
" user=".$this->searchUser.
" password=".preg_replace(
'/./',
'*', $this->searchPassword), LOG_DEBUG);
428 $this->result = $this->
bindauth($this->searchUser, $this->searchPassword);
430 $this->
bind = $this->result;
432 $this->connectedServer = $host;
435 $this->error = ldap_errno($this->connection).
' '.ldap_error($this->connection);
440 dol_syslog(get_class($this).
"::connectBind try bind anonymously on ".$host, LOG_DEBUG);
441 $result = $this->
bind();
443 $this->
bind = $this->result;
445 $this->connectedServer = $host;
448 $this->error = ldap_errno($this->connection).
' '.ldap_error($this->connection);
461 dol_syslog(get_class($this).
"::connectBind ".$connected, LOG_DEBUG);
464 $this->error =
'Failed to connect to LDAP'.($this->error ?
': '.$this->error :
'');
465 dol_syslog(get_class($this).
"::connectBind ".$this->error, LOG_WARNING);
491 if (!$this->result = @ldap_bind($this->connection)) {
492 $this->ldapErrorCode = ldap_errno($this->connection);
493 $this->ldapErrorText = ldap_error($this->connection);
494 $this->error = $this->ldapErrorCode.
" ".$this->ldapErrorText;
513 if (!$this->result = @ldap_bind($this->connection, $bindDn, $pass)) {
514 $this->ldapErrorCode = ldap_errno($this->connection);
515 $this->ldapErrorText = ldap_error($this->connection);
516 $this->error = $this->ldapErrorCode.
" ".$this->ldapErrorText;
531 $this->result =
true;
532 if (version_compare(PHP_VERSION,
'8.1.0',
'>=')) {
533 if (is_object($this->connection)) {
535 $this->result = ldap_unbind($this->connection);
536 }
catch (Throwable $exception) {
537 $this->error =
'Failed to unbind LDAP connection: '.$exception;
538 $this->result =
false;
539 dol_syslog(get_class($this).
'::unbind - '.$this->error, LOG_WARNING);
543 if (is_resource($this->connection)) {
545 $this->result = @ldap_unbind($this->connection);
563 @ldap_get_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $version);
575 return ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $this->ldapProtocolVersion);
585 return ldap_set_option($this->connection, LDAP_OPT_SIZELIMIT, 0);
596 return ldap_set_option($this->connection, LDAP_OPT_REFERRALS, 0);
609 public function add($dn, $info, $user)
611 dol_syslog(get_class($this).
"::add dn=".$dn.
" info=".print_r($info,
true));
614 if (!$this->connection) {
615 $this->error =
"NotConnected";
619 $this->error =
"NotConnected";
625 foreach ($info as $key => $val) {
626 if (!is_array($val)) {
631 $this->
dump($dn, $info);
634 $result = @ldap_add($this->connection, $dn, $info);
637 dol_syslog(get_class($this).
"::add successful", LOG_DEBUG);
640 $this->ldapErrorCode = @ldap_errno($this->connection);
641 $this->ldapErrorText = @ldap_error($this->connection);
642 $this->error = $this->ldapErrorCode.
" ".$this->ldapErrorText;
643 dol_syslog(get_class($this).
"::add failed: ".$this->error, LOG_ERR);
657 public function modify($dn, $info, $user)
659 dol_syslog(get_class($this).
"::modify dn=".$dn.
" info=".print_r($info,
true));
662 if (!$this->connection) {
663 $this->error =
"NotConnected";
667 $this->error =
"NotConnected";
673 foreach ($info as $key => $val) {
674 if (!is_array($val)) {
679 $this->
dump($dn, $info);
684 if ($this->serverType ==
"activedirectory") {
688 if (isset($info[
'unicodePwd'])) {
689 $info[
'unicodePwd'] = mb_convert_encoding(
"\"".$info[
'unicodePwd'].
"\"",
"UTF-16LE",
"UTF-8");
692 $result = @ldap_mod_replace($this->connection, $dn, $info);
695 dol_syslog(get_class($this).
"::modify successful", LOG_DEBUG);
698 $this->error = @ldap_error($this->connection);
699 dol_syslog(get_class($this).
"::modify failed: ".$this->error, LOG_ERR);
715 public function rename($dn, $newrdn, $newparent, $user, $deleteoldrdn =
true)
717 dol_syslog(get_class($this).
"::modify dn=".$dn.
" newrdn=".$newrdn.
" newparent=".$newparent.
" deleteoldrdn=".($deleteoldrdn ? 1 : 0));
720 if (!$this->connection) {
721 $this->error =
"NotConnected";
725 $this->error =
"NotConnected";
735 $result = @ldap_rename($this->connection, $dn, $newrdn, $newparent, $deleteoldrdn);
738 dol_syslog(get_class($this).
"::rename successful", LOG_DEBUG);
741 $this->error = @ldap_error($this->connection);
742 dol_syslog(get_class($this).
"::rename failed: ".$this->error, LOG_ERR);
759 public function update($dn, $info, $user, $olddn, $newrdn =
'', $newparent =
'')
761 dol_syslog(get_class($this).
"::update dn=".$dn.
" olddn=".$olddn);
764 if (!$this->connection) {
765 $this->error =
"NotConnected";
769 $this->error =
"NotConnected";
773 if (!$olddn || $olddn != $dn) {
774 if (!empty($olddn) && !empty($newrdn) && !empty($newparent) && $this->ldapProtocolVersion ===
'3') {
776 $result = $this->
rename($olddn, $newrdn, $newparent, $user,
true);
777 $result = $this->
modify($dn, $info, $user);
780 $result = $this->
add($dn, $info, $user);
781 if ($result > 0 && $olddn && $olddn != $dn) {
782 $result = $this->
delete($olddn);
787 $result = $this->
add($dn, $info, $user);
788 $result = $this->
modify($dn, $info, $user);
791 $this->error = ldap_error($this->connection).
' (Code '.ldap_errno($this->connection).
") ".$this->error;
792 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
796 dol_syslog(get_class($this).
"::update done successfully");
809 public function delete($dn)
811 dol_syslog(get_class($this).
"::delete Delete LDAP entry dn=".$dn);
814 if (!$this->connection) {
815 $this->error =
"NotConnected";
819 $this->error =
"NotConnected";
826 $result = @ldap_delete($this->connection, $dn);
847 if (preg_match(
'/^ldap/', $this->server[0])) {
848 $target =
"-H ".implode(
',', $this->server);
850 $target =
"-h ".implode(
',', $this->server).
" -p ".$this->serverPort;
852 $content .=
"# ldapadd $target -c -v -D ".$this->searchUser.
" -W -f ldapinput.in\n";
853 $content .=
"# ldapmodify $target -c -v -D ".$this->searchUser.
" -W -f ldapinput.in\n";
854 $content .=
"# ldapdelete $target -c -v -D ".$this->searchUser.
" -W -f ldapinput.in\n";
855 if (in_array(
'localhost', $this->server)) {
856 $content .=
"# If commands fails to connect, try without -h and -p\n";
858 $content .=
"dn: ".$dn.
"\n";
859 foreach ($info as $key => $value) {
860 if (!is_array($value)) {
861 $content .=
"$key: $value\n";
863 foreach ($value as $valuevalue) {
864 $content .=
"$key: $valuevalue\n";
878 public function dump($dn, $info)
881 $ldapDirTemp =
$conf->ldap->dir_temp;
888 $outputfile = $ldapDirTemp.
'/ldapinput.in';
889 $fp = fopen($outputfile,
"w");
891 fwrite($fp, $content);
914 if (preg_match(
'/^ldaps:\/\/([^\/]+)\/?$/', $host, $regs)) {
916 $host =
'ssl://'.$regs[1];
917 } elseif (preg_match(
'/^ldap:\/\/([^\/]+)\/?$/', $host, $regs)) {
926 $errno = $errstr = 0;
935 $op = @fsockopen($host, $port, $errno, $errstr, $timeout);
960 dol_syslog(get_class($this).
"::addAttribute dn=".$dn.
" info=".implode(
',', $info));
963 if (!$this->connection) {
964 $this->error =
"NotConnected";
968 $this->error =
"NotConnected";
974 foreach ($info as $key => $val) {
975 if (!is_array($val)) {
980 $this->
dump($dn, $info);
983 $result = @ldap_mod_add($this->connection, $dn, $info);
986 dol_syslog(get_class($this).
"::add_attribute successful", LOG_DEBUG);
989 $this->error = @ldap_error($this->connection);
990 dol_syslog(get_class($this).
"::add_attribute failed: ".$this->error, LOG_ERR);
1006 dol_syslog(get_class($this).
"::updateAttribute dn=".$dn.
" info=".implode(
',', $info));
1009 if (!$this->connection) {
1010 $this->error =
"NotConnected";
1014 $this->error =
"NotConnected";
1020 foreach ($info as $key => $val) {
1021 if (!is_array($val)) {
1026 $this->
dump($dn, $info);
1029 $result = @ldap_mod_replace($this->connection, $dn, $info);
1032 dol_syslog(get_class($this).
"::updateAttribute successful", LOG_DEBUG);
1035 $this->error = @ldap_error($this->connection);
1036 dol_syslog(get_class($this).
"::updateAttribute failed: ".$this->error, LOG_ERR);
1052 dol_syslog(get_class($this).
"::deleteAttribute dn=".$dn.
" info=".implode(
',', $info));
1055 if (!$this->connection) {
1056 $this->error =
"NotConnected";
1060 $this->error =
"NotConnected";
1066 foreach ($info as $key => $val) {
1067 if (!is_array($val)) {
1072 $this->
dump($dn, $info);
1075 $result = @ldap_mod_del($this->connection, $dn, $info);
1078 dol_syslog(get_class($this).
"::deleteAttribute successful", LOG_DEBUG);
1081 $this->error = @ldap_error($this->connection);
1082 dol_syslog(get_class($this).
"::deleteAttribute failed: ".$this->error, LOG_ERR);
1099 if (!$this->connection) {
1100 $this->error =
"NotConnected";
1104 $this->error =
"NotConnected";
1108 $search = @ldap_search($this->connection, $dn, $filter);
1111 $entry = @ldap_first_entry($this->connection, $search);
1114 $this->ldapErrorCode = -1;
1115 $this->ldapErrorText =
"Couldn't find entry";
1120 if (!($values = ldap_get_attributes($this->connection, $entry))) {
1121 $this->ldapErrorCode = ldap_errno($this->connection);
1122 $this->ldapErrorText = ldap_error($this->connection);
1139 $attributes = array();
1140 $attributes[0] = $attribute;
1143 $this->result = @ldap_search($this->connection, $this->people, $filterrecord, $attributes);
1149 $entry = ldap_first_entry($this->connection, $this->result);
1152 $this->ldapErrorCode = -1;
1153 $this->ldapErrorText =
"Couldn't find user";
1158 if (!$values = @ldap_get_values_len($this->connection, $entry, $attribute)) {
1159 $this->ldapErrorCode = ldap_errno($this->connection);
1160 $this->ldapErrorText = ldap_error($this->connection);
1180 public function getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter = 0, $attributeAsArray = array())
1182 $fulllist = array();
1184 dol_syslog(get_class($this).
"::getRecords search=".$search.
" userDn=".$userDn.
" useridentifier=".$useridentifier.
" attributeArray=array(".implode(
',', $attributeArray).
") activefilter=".$activefilter);
1187 if ($this->serverType ==
"activedirectory") {
1188 $this->
bindauth($this->searchUser, $this->searchPassword);
1189 dol_syslog(get_class($this).
"::bindauth serverType=activedirectory searchUser=".$this->searchUser);
1193 if (!empty($activefilter)) {
1194 if (((
string) $activefilter ==
'1' || (
string) $activefilter ==
'user') && $this->filter) {
1195 $filter =
'('.$this->filter.
')';
1196 } elseif (((
string) $activefilter ==
'group') && $this->filtergroup) {
1197 $filter =
'('.$this->filtergroup.
')';
1198 } elseif (((
string) $activefilter ==
'member') && $this->filter) {
1199 $filter =
'('.$this->filtermember.
')';
1202 $filter =
'('.ldap_escape($useridentifier,
'', LDAP_ESCAPE_FILTER).
'=*)';
1205 $filter =
'('.ldap_escape($useridentifier,
'', LDAP_ESCAPE_FILTER).
'='.ldap_escape($search,
'', LDAP_ESCAPE_FILTER).
')';
1208 if (is_array($attributeArray)) {
1210 $attributeArray = array_values($attributeArray);
1211 dol_syslog(get_class($this).
"::getRecords connection=".$this->connectedServer.
":".$this->serverPort.
" userDn=".$userDn.
" filter=".$filter.
" attributeArray=(".implode(
',', $attributeArray).
")");
1213 $this->result = @ldap_search($this->connection, $userDn, $filter, $attributeArray);
1216 dol_syslog(get_class($this).
"::getRecords connection=".$this->connectedServer.
":".$this->serverPort.
" userDn=".$userDn.
" filter=".$filter);
1217 $this->result = @ldap_search($this->connection, $userDn, $filter);
1219 if (!$this->result) {
1220 $this->error =
'LDAP search failed: '.ldap_errno($this->connection).
" ".ldap_error($this->connection);
1224 $info = @ldap_get_entries($this->connection, $this->result);
1230 for ($i = 0; $i < $info[
"count"]; $i++) {
1231 $recordid = $this->
convToOutputCharset($info[$i][strtolower($useridentifier)][0], $this->ldapcharset);
1234 $fulllist[$recordid][$useridentifier] = $recordid;
1237 $num = count($attributeArray);
1238 for ($j = 0; $j < $num; $j++) {
1239 $keyattributelower = strtolower($attributeArray[$j]);
1243 if ($this->serverType ==
"activedirectory" && $keyattributelower ==
"objectsid") {
1245 $fulllist[$recordid][$attributeArray[$j]] = $objectsid;
1247 if (in_array($attributeArray[$j], $attributeAsArray) && is_array($info[$i][$keyattributelower])) {
1248 $valueTab = array();
1249 foreach ($info[$i][$keyattributelower] as $key => $value) {
1252 $fulllist[$recordid][$attributeArray[$j]] = $valueTab;
1254 $fulllist[$recordid][$attributeArray[$j]] = $this->
convToOutputCharset($info[$i][$keyattributelower][0], $this->ldapcharset);
1275 for ($x =
dol_strlen($hex) - 2; $x >= 0; $x -= 2) {
1276 $result .= substr($hex, $x, 2);
1291 $criteria =
'('.$this->getUserIdentifier().
'='.$ldapUser.
')';
1292 $justthese = array(
"objectsid");
1295 if ($this->serverType ==
"activedirectory") {
1296 $this->
bindauth($this->searchUser, $this->searchPassword);
1301 $searchDN = $this->people;
1304 $ldapSearchResult = @ldap_search($this->connection, $searchDN, $criteria, $justthese);
1306 if (!$ldapSearchResult) {
1307 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1311 $entry = ldap_first_entry($this->connection, $ldapSearchResult);
1315 $searchDN = $this->domain;
1324 $ldapBinary = ldap_get_values_len($this->connection, $entry,
"objectsid");
1328 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1342 $hex_sid = bin2hex($binsid);
1343 $rev = hexdec(substr($hex_sid, 0, 2));
1344 $subcount = hexdec(substr($hex_sid, 2, 2));
1345 $auth = hexdec(substr($hex_sid, 4, 12));
1346 $result =
"$rev-$auth";
1347 for ($x = 0; $x < $subcount; $x++) {
1348 $result .=
"-".hexdec($this->
littleEndian(substr($hex_sid, 16 + ($x * 8), 8)));
1369 dol_syslog(get_class($this).
"::search checkDn=".$checkDn.
" filter=".$filter);
1375 if ($this->serverType ==
"activedirectory") {
1376 $this->
bindauth($this->searchUser, $this->searchPassword);
1379 $this->result = @ldap_search($this->connection, $checkDn, $filter);
1381 $result = @ldap_get_entries($this->connection, $this->result);
1383 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1386 ldap_free_result($this->result);
1405 if ($this->serverType ==
"activedirectory") {
1406 $this->
bindauth($this->searchUser, $this->searchPassword);
1409 $searchDN = $this->people;
1414 dol_syslog(get_class($this).
"::fetch search with searchDN=".$searchDN.
" filter=".$filter);
1415 $this->result = @ldap_search($this->connection, $searchDN, $filter);
1416 if ($this->result) {
1417 $result = @ldap_get_entries($this->connection, $this->result);
1418 if ($result[
'count'] > 0) {
1419 dol_syslog(
'Ldap::fetch search found '.$result[
'count'].
' records');
1421 dol_syslog(
'Ldap::fetch search returns but found no records');
1425 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1426 dol_syslog(get_class($this).
"::fetch search fails");
1432 $searchDN = $this->domain;
1440 $this->error = ldap_errno($this->connection).
" ".ldap_error($this->connection);
1444 $this->firstname = $this->
convToOutputCharset($result[0][$this->attr_firstname][0], $this->ldapcharset);
1445 $this->login = $this->
convToOutputCharset($result[0][$this->attr_login][0], $this->ldapcharset);
1446 $this->phone = $this->
convToOutputCharset($result[0][$this->attr_phone][0], $this->ldapcharset);
1447 $this->fax = $this->
convToOutputCharset($result[0][$this->attr_fax][0], $this->ldapcharset);
1448 $this->mail = $this->
convToOutputCharset($result[0][$this->attr_mail][0], $this->ldapcharset);
1449 $this->mobile = $this->
convToOutputCharset($result[0][$this->attr_mobile][0], $this->ldapcharset);
1452 if (isset($result[0][
"pwdlastset"][0])) {
1453 $this->pwdlastset = ($result[0][
"pwdlastset"][0] != 0) ? $this->
convertTime($this->
convToOutputCharset($result[0][
"pwdlastset"][0], $this->ldapcharset)) : 0;
1455 $this->pwdlastset = -1;
1457 if (!$this->
name && !$this->login) {
1458 $this->pwdlastset = -1;
1463 $domain = str_replace(
'dc=',
'', $this->domain);
1464 $domain = str_replace(
',',
'.', $domain);
1465 $this->domainFQDN = $domain;
1469 $this->ldapUserDN = $result[0][
'dn'];
1471 ldap_free_result($this->result);
1486 if ($this->serverType ==
"activedirectory") {
1487 return $this->attr_sambalogin;
1489 return $this->attr_login;
1503 "TRUSTED_TO_AUTH_FOR_DELEGATION" => 16777216,
1504 "PASSWORD_EXPIRED" => 8388608,
1505 "DONT_REQ_PREAUTH" => 4194304,
1506 "USE_DES_KEY_ONLY" => 2097152,
1507 "NOT_DELEGATED" => 1048576,
1508 "TRUSTED_FOR_DELEGATION" => 524288,
1509 "SMARTCARD_REQUIRED" => 262144,
1510 "MNS_LOGON_ACCOUNT" => 131072,
1511 "DONT_EXPIRE_PASSWORD" => 65536,
1512 "SERVER_TRUST_ACCOUNT" => 8192,
1513 "WORKSTATION_TRUST_ACCOUNT" => 4096,
1514 "INTERDOMAIN_TRUST_ACCOUNT" => 2048,
1515 "NORMAL_ACCOUNT" => 512,
1516 "TEMP_DUPLICATE_ACCOUNT" => 256,
1517 "ENCRYPTED_TEXT_PWD_ALLOWED" => 128,
1518 "PASSWD_CANT_CHANGE" => 64,
1519 "PASSWD_NOTREQD" => 32,
1521 "HOMEDIR_REQUIRED" => 8,
1522 "ACCOUNTDISABLE" => 2,
1529 foreach ($flags as $flag => $val) {
1530 if ($uacf >= $val) {
1532 $retval[$val] = $flag;
1549 805306368 =>
"NORMAL_ACCOUNT",
1550 805306369 =>
"WORKSTATION_TRUST",
1551 805306370 =>
"INTERDOMAIN_TRUST",
1552 268435456 =>
"SECURITY_GLOBAL_GROUP",
1553 268435457 =>
"DISTRIBUTION_GROUP",
1554 536870912 =>
"SECURITY_LOCAL_GROUP",
1555 536870913 =>
"DISTRIBUTION_LOCAL_GROUP"
1559 foreach ($stypes as $sat => $val) {
1560 if ($samtype == $sat) {
1565 if (empty($retval)) {
1566 $retval =
"UNKNOWN_TYPE_".$samtype;
1580 $dateLargeInt = $value;
1581 if (PHP_INT_SIZE < 8) {
1583 $secsAfterADEpoch = (float) $dateLargeInt / (10000000.);
1586 $secsAfterADEpoch = (int) $dateLargeInt / (10000000);
1588 $ADToUnixConvertor = ((1970 - 1601) * 365.242190) * 86400;
1589 $unixTimeStamp = intval($secsAfterADEpoch - $ADToUnixConvertor);
1590 return $unixTimeStamp;
1604 if ($pagecodefrom ==
'ISO-8859-1' &&
$conf->file->character_set_client ==
'UTF-8') {
1605 $str = mb_convert_encoding($str,
'UTF-8',
'ISO-8859-1');
1607 if ($pagecodefrom ==
'UTF-8' &&
$conf->file->character_set_client ==
'ISO-8859-1') {
1608 $str = mb_convert_encoding($str,
'ISO-8859-1');
1623 if ($pagecodeto ==
'ISO-8859-1' &&
$conf->file->character_set_client ==
'UTF-8') {
1624 $str = mb_convert_encoding($str,
'ISO-8859-1');
1626 if ($pagecodeto ==
'UTF-8' &&
$conf->file->character_set_client ==
'ISO-8859-1') {
1627 $str = mb_convert_encoding($str,
'UTF-8',
'ISO-8859-1');
1642 if (empty($keygroup)) {
1643 $keygroup =
'LDAP_KEY_GROUPS';
1647 $result = $this->
search($this->groups, $search);
1649 $c = $result[
'count'];
1651 for ($i = 0; $i < $c; $i++) {
1652 $gids[] = $result[$i][
'gidnumber'][0];
1656 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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
$conf db name
Only used if Module[ID]Name translation string is not found.