dolibarr 23.0.3
ldap.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
4 * Copyright (C) 2005-2021 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2006-2021 Laurent Destailleur <eldy@users.sourceforge.net>
6 * Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 * or see https://www.gnu.org/
23 */
24
39class Ldap
40{
44 public $error = '';
45
49 public $errors = array();
50
54 public $server = array();
55
59 public $connectedServer;
60
64 public $serverPort;
65
70 public $dn;
75 public $serverType;
80 public $ldapProtocolVersion;
85 public $domain;
86
90 public $domainFQDN;
91
95 public $bind;
96
101 public $searchUser;
106 public $searchPassword;
107
111 public $people;
112
116 public $groups;
117
121 public $ldapErrorCode;
122
126 public $ldapErrorText;
127
131 public $filter;
132
136 public $filtergroup;
137
141 public $filtermember;
142
146 public $attr_login;
147
151 public $attr_sambalogin;
152
156 public $attr_name;
157
161 public $attr_firstname;
162
166 public $attr_mail;
167
171 public $attr_phone;
172
176 public $attr_fax;
177
181 public $attr_mobile;
182
186 public $badpwdtime;
187
191 public $ldapUserDN;
192
196 public $name;
197
201 public $firstname;
202
206 public $login;
207
211 public $phone;
212
216 public $fax;
217
221 public $mail;
222
226 public $mobile;
227
231 public $uacf;
232
236 public $pwdlastset;
237
242 public $ldapcharset = 'UTF-8';
243
247 public $connection;
248
252 public $result;
253
257 const SYNCHRO_NONE = 0;
258
262 const SYNCHRO_DOLIBARR_TO_LDAP = 1;
263
267 const SYNCHRO_LDAP_TO_DOLIBARR = 2;
268
272 public function __construct()
273 {
274
275 // Server
276 if (getDolGlobalString('LDAP_SERVER_HOST')) {
277 $this->server[] = getDolGlobalString('LDAP_SERVER_HOST');
278 }
279 if (getDolGlobalString('LDAP_SERVER_HOST_SLAVE')) {
280 $this->server[] = getDolGlobalString('LDAP_SERVER_HOST_SLAVE');
281 }
282 $this->serverPort = getDolGlobalInt('LDAP_SERVER_PORT', 389);
283 $this->ldapProtocolVersion = getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION');
284 $this->dn = getDolGlobalString('LDAP_SERVER_DN');
285 $this->serverType = getDolGlobalString('LDAP_SERVER_TYPE');
286
287 $this->domain = getDolGlobalString('LDAP_SERVER_DN');
288 $this->searchUser = getDolGlobalString('LDAP_ADMIN_DN');
289 $this->searchPassword = getDolGlobalString('LDAP_ADMIN_PASS');
290 $this->people = getDolGlobalString('LDAP_USER_DN');
291 $this->groups = getDolGlobalString('LDAP_GROUP_DN');
292
293 $this->filter = getDolGlobalString('LDAP_FILTER_CONNECTION'); // Filter on user
294 $this->filtergroup = getDolGlobalString('LDAP_GROUP_FILTER'); // Filter on groups
295 $this->filtermember = getDolGlobalString('LDAP_MEMBER_FILTER'); // Filter on member
296
297 // Users
298 $this->attr_login = getDolGlobalString('LDAP_FIELD_LOGIN'); //unix
299 $this->attr_sambalogin = getDolGlobalString('LDAP_FIELD_LOGIN_SAMBA'); //samba, activedirectory
300 $this->attr_name = getDolGlobalString('LDAP_FIELD_NAME');
301 $this->attr_firstname = getDolGlobalString('LDAP_FIELD_FIRSTNAME');
302 $this->attr_mail = getDolGlobalString('LDAP_FIELD_MAIL');
303 $this->attr_phone = getDolGlobalString('LDAP_FIELD_PHONE');
304 $this->attr_fax = getDolGlobalString('LDAP_FIELD_FAX');
305 $this->attr_mobile = getDolGlobalString('LDAP_FIELD_MOBILE');
306 }
307
308 // Connection handling methods -------------------------------------------
309
317 public function connectBind()
318 {
319 global $dolibarr_main_auth_ldap_debug;
320
321 $connected = 0;
322 $this->bind = false;
323 $this->error = '';
324 $this->connectedServer = '';
325
326 $ldapdebug = !((empty($dolibarr_main_auth_ldap_debug) || $dolibarr_main_auth_ldap_debug == "false"));
327
328 if ($ldapdebug) {
329 dol_syslog(get_class($this)."::connectBind");
330 print "DEBUG: connectBind<br>\n";
331 }
332
333 // Check parameters
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);
337 return -1;
338 }
339
340 if (!function_exists("ldap_connect")) {
341 $this->error = 'LDAPFunctionsNotAvailableOnPHP';
342 dol_syslog(get_class($this)."::connectBind ".$this->error, LOG_WARNING);
343 return -1;
344 }
345
346 if (empty($this->error)) {
347 // Loop on each ldap server
348 foreach ($this->server as $host) {
349 if ($connected) {
350 break;
351 }
352 if (empty($host)) {
353 continue;
354 }
355
356 if ($this->serverPing($host, $this->serverPort)) {
357 if ($ldapdebug) {
358 dol_syslog(get_class($this)."::connectBind serverPing true, we try ldap_connect to ".$host, LOG_DEBUG);
359 }
360 if (version_compare(PHP_VERSION, '8.3.0', '>=')) {
361 // Since PHP 8.3, ldap_connect() expects a single URI argument. A scheme-less
362 // host (ex: localhost, 192.168.0.2) must be turned into a valid ldap:// URI,
363 // otherwise the host is parsed as the URI scheme and the later bind fails.
364 $uri = preg_match('/^ldaps?:\/\//i', $host) ? $host : 'ldap://'.$host.':'.$this->serverPort;
365 $this->connection = ldap_connect($uri);
366 } else {
367 $this->connection = ldap_connect($host, $this->serverPort);
368 }
369 } else {
370 if (preg_match('/^ldaps/i', $host)) {
371 // With host = ldaps://server, the serverPing to ssl://server sometimes fails, even if the ldap_connect succeed, so
372 // we test this case and continue in such a case even if serverPing fails.
373 if ($ldapdebug) {
374 dol_syslog(get_class($this)."::connectBind serverPing false, we try ldap_connect to ".$host, LOG_DEBUG);
375 }
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);
379 } else {
380 $this->connection = ldap_connect($host, $this->serverPort);
381 }
382 } else {
383 if ($ldapdebug) {
384 dol_syslog(get_class($this)."::connectBind serverPing false, no ldap_connect ".$host, LOG_DEBUG);
385 }
386 continue;
387 }
388 }
389
390 if (is_resource($this->connection) || is_object($this->connection)) {
391 if ($ldapdebug) {
392 dol_syslog(get_class($this)."::connectBind this->connection is ok", LOG_DEBUG);
393 }
394
395 // Upgrade connection to TLS, if requested by the configuration
396 if (getDolGlobalString('LDAP_SERVER_USE_TLS')) {
397 // For test/debug
398 //ldap_set_option($this->connection, LDAP_OPT_DEBUG_LEVEL, 7);
399 //ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, 3);
400 //ldap_set_option($this->connection, LDAP_OPT_REFERRALS, 0);
401
402 $resulttls = ldap_start_tls($this->connection);
403 if (!$resulttls) {
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);
406 $connected = 0;
407 $this->unbind();
408 }
409 }
410
411 // Execute the ldap_set_option here (after connect and before bind)
412 $this->setVersion();
413 $this->setSizeLimit();
414
415 if ($this->serverType == "activedirectory") {
416 $result = $this->setReferrals();
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);
419 if ($this->result) {
420 $this->bind = $this->result;
421 $connected = 2;
422 $this->connectedServer = $host;
423 break;
424 } else {
425 $this->error = ldap_errno($this->connection).' '.ldap_error($this->connection);
426 }
427 } else {
428 // Try in auth mode
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);
432 if ($this->result) {
433 $this->bind = $this->result;
434 $connected = 2;
435 $this->connectedServer = $host;
436 break;
437 } else {
438 $this->error = ldap_errno($this->connection).' '.ldap_error($this->connection);
439 }
440 }
441 // Try in anonymous
442 if (!$this->bind) {
443 dol_syslog(get_class($this)."::connectBind try bind anonymously on ".$host, LOG_DEBUG);
444 $result = $this->bind();
445 if ($result) {
446 $this->bind = $this->result;
447 $connected = 1;
448 $this->connectedServer = $host;
449 break;
450 } else {
451 $this->error = ldap_errno($this->connection).' '.ldap_error($this->connection);
452 }
453 }
454 }
455 }
456
457 if (!$connected) {
458 $this->unbind();
459 }
460 } // End loop on each server
461 }
462
463 if ($connected) {
464 dol_syslog(get_class($this)."::connectBind ".$connected, LOG_DEBUG);
465 return $connected;
466 } else {
467 $this->error = 'Failed to connect to LDAP'.($this->error ? ': '.$this->error : '');
468 dol_syslog(get_class($this)."::connectBind ".$this->error, LOG_WARNING);
469 return -1;
470 }
471 }
472
481 public function close()
482 {
483 return $this->unbind();
484 }
485
492 public function bind()
493 {
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;
498 return false;
499 } else {
500 return true;
501 }
502 }
503
514 public function bindauth($bindDn, $pass)
515 {
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;
520 return false;
521 } else {
522 return true;
523 }
524 }
525
532 public function unbind()
533 {
534 $this->result = true;
535 if (version_compare(PHP_VERSION, '8.1.0', '>=')) {
536 if (is_object($this->connection)) {
537 try {
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);
543 }
544 }
545 } else {
546 if (is_resource($this->connection)) {
547 // @phan-suppress-next-line PhanTypeMismatchArgumentInternalReal
548 $this->result = @ldap_unbind($this->connection);
549 }
550 }
551 if ($this->result) {
552 return true;
553 } else {
554 return false;
555 }
556 }
557
558
564 public function getVersion()
565 {
566 @ldap_get_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $version);
567 return $version;
568 }
569
576 public function setVersion()
577 {
578 return ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $this->ldapProtocolVersion);
579 }
580
586 public function setSizeLimit()
587 {
588 return ldap_set_option($this->connection, LDAP_OPT_SIZELIMIT, 0);
589 }
590
597 public function setReferrals()
598 {
599 return ldap_set_option($this->connection, LDAP_OPT_REFERRALS, 0);
600 }
601
602
612 public function add($dn, $info, $user)
613 {
614 dol_syslog(get_class($this)."::add dn=".$dn." info=".print_r($info, true));
615
616 // Check parameters
617 if (!$this->connection) {
618 $this->error = "NotConnected";
619 return -2;
620 }
621 if (!$this->bind) {
622 $this->error = "NotConnected";
623 return -3;
624 }
625
626 // Encode to LDAP page code
627 $dn = $this->convFromOutputCharset($dn, $this->ldapcharset);
628 foreach ($info as $key => $val) {
629 if (!is_array($val)) {
630 $info[$key] = $this->convFromOutputCharset($val, $this->ldapcharset);
631 }
632 }
633
634 $this->dump($dn, $info);
635
636 //print_r($info);
637 $result = @ldap_add($this->connection, $dn, $info);
638
639 if ($result) {
640 dol_syslog(get_class($this)."::add successful", LOG_DEBUG);
641 return 1;
642 } else {
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);
647 return -1;
648 }
649 }
650
660 public function modify($dn, $info, $user)
661 {
662 dol_syslog(get_class($this)."::modify dn=".$dn." info=".print_r($info, true));
663
664 // Check parameters
665 if (!$this->connection) {
666 $this->error = "NotConnected";
667 return -2;
668 }
669 if (!$this->bind) {
670 $this->error = "NotConnected";
671 return -3;
672 }
673
674 // Encode to LDAP page code
675 $dn = $this->convFromOutputCharset($dn, $this->ldapcharset);
676 foreach ($info as $key => $val) {
677 if (!is_array($val)) {
678 $info[$key] = $this->convFromOutputCharset($val, $this->ldapcharset);
679 }
680 }
681
682 $this->dump($dn, $info);
683
684 //print_r($info);
685
686 // For better compatibility with Samba4 AD
687 if ($this->serverType == "activedirectory") {
688 unset($info['cn']); // To avoid error : Operation not allowed on RDN (Code 67)
689
690 // To avoid error : LDAP Error: 53 (Unwilling to perform)
691 if (isset($info['unicodePwd'])) {
692 $info['unicodePwd'] = mb_convert_encoding("\"".$info['unicodePwd']."\"", "UTF-16LE", "UTF-8");
693 }
694 }
695 $result = @ldap_mod_replace($this->connection, $dn, $info);
696
697 if ($result) {
698 dol_syslog(get_class($this)."::modify successful", LOG_DEBUG);
699 return 1;
700 } else {
701 $this->error = @ldap_error($this->connection);
702 dol_syslog(get_class($this)."::modify failed: ".$this->error, LOG_ERR);
703 return -1;
704 }
705 }
706
718 public function rename($dn, $newrdn, $newparent, $user, $deleteoldrdn = true)
719 {
720 dol_syslog(get_class($this)."::modify dn=".$dn." newrdn=".$newrdn." newparent=".$newparent." deleteoldrdn=".($deleteoldrdn ? 1 : 0));
721
722 // Check parameters
723 if (!$this->connection) {
724 $this->error = "NotConnected";
725 return -2;
726 }
727 if (!$this->bind) {
728 $this->error = "NotConnected";
729 return -3;
730 }
731
732 // Encode to LDAP page code
733 $dn = $this->convFromOutputCharset($dn, $this->ldapcharset);
734 $newrdn = $this->convFromOutputCharset($newrdn, $this->ldapcharset);
735 $newparent = $this->convFromOutputCharset($newparent, $this->ldapcharset);
736
737 //print_r($info);
738 $result = @ldap_rename($this->connection, $dn, $newrdn, $newparent, $deleteoldrdn);
739
740 if ($result) {
741 dol_syslog(get_class($this)."::rename successful", LOG_DEBUG);
742 return 1;
743 } else {
744 $this->error = @ldap_error($this->connection);
745 dol_syslog(get_class($this)."::rename failed: ".$this->error, LOG_ERR);
746 return -1;
747 }
748 }
749
762 public function update($dn, $info, $user, $olddn, $newrdn = '', $newparent = '')
763 {
764 dol_syslog(get_class($this)."::update dn=".$dn." olddn=".$olddn);
765
766 // Check parameters
767 if (!$this->connection) {
768 $this->error = "NotConnected";
769 return -2;
770 }
771 if (!$this->bind) {
772 $this->error = "NotConnected";
773 return -3;
774 }
775
776 if (!$olddn || $olddn != $dn) {
777 if (!empty($olddn) && !empty($newrdn) && !empty($newparent) && $this->ldapProtocolVersion === '3') {
778 // This function currently only works with LDAPv3
779 $result = $this->rename($olddn, $newrdn, $newparent, $user, true);
780 $result = $this->modify($dn, $info, $user); // We force "modify" for avoid some fields not modify
781 } else {
782 // If change we make is rename the key of LDAP record, we create new one and if ok, we delete old one.
783 $result = $this->add($dn, $info, $user);
784 if ($result > 0 && $olddn && $olddn != $dn) {
785 $result = $this->delete($olddn); // If add fails, we do not try to delete old one
786 }
787 }
788 } else {
789 //$result = $this->delete($olddn);
790 $result = $this->add($dn, $info, $user); // If record has been deleted from LDAP, we recreate it. We ignore error if it already exists.
791 $result = $this->modify($dn, $info, $user); // We use add/modify instead of delete/add when olddn is received
792 }
793 if ($result <= 0) {
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);
796 //print_r($info);
797 return -1;
798 } else {
799 dol_syslog(get_class($this)."::update done successfully");
800 return 1;
801 }
802 }
803
804
812 public function delete($dn)
813 {
814 dol_syslog(get_class($this)."::delete Delete LDAP entry dn=".$dn);
815
816 // Check parameters
817 if (!$this->connection) {
818 $this->error = "NotConnected";
819 return -2;
820 }
821 if (!$this->bind) {
822 $this->error = "NotConnected";
823 return -3;
824 }
825
826 // Encode to LDAP page code
827 $dn = $this->convFromOutputCharset($dn, $this->ldapcharset);
828
829 $result = @ldap_delete($this->connection, $dn);
830
831 if ($result) {
832 return 1;
833 }
834 return -1;
835 }
836
844 public function dumpContent($dn, $info)
845 {
846 $content = '';
847
848 // Create file content
849 if (preg_match('/^ldap/', $this->server[0])) {
850 $target = "-H ".implode(',', $this->server);
851 } else {
852 $target = "-h ".implode(',', $this->server)." -p ".$this->serverPort;
853 }
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";
859 }
860 $content .= "dn: ".$dn."\n";
861 foreach ($info as $key => $value) {
862 if (!is_array($value)) {
863 $content .= "$key: $value\n";
864 } else {
865 foreach ($value as $valuevalue) {
866 $content .= "$key: $valuevalue\n";
867 }
868 }
869 }
870 return $content;
871 }
872
880 public function dump($dn, $info)
881 {
882 global $conf;
883 $ldapDirTemp = $conf->ldap->dir_temp;
884 // Create content
885 $content = $this->dumpContent($dn, $info);
886
887 //Create directory & file
888 $result = dol_mkdir($ldapDirTemp);
889 if ($result != 0) {
890 $outputfile = $ldapDirTemp.'/ldapinput.in';
891 $fp = fopen($outputfile, "w");
892 if ($fp) {
893 fwrite($fp, $content);
894 fclose($fp);
895 dolChmod($outputfile);
896 return 1;
897 } else {
898 return -1;
899 }
900 } else {
901 return -1;
902 }
903 }
904
913 public function serverPing($host, $port = 389, $timeout = 1)
914 {
915 $regs = array();
916 if (preg_match('/^ldaps:\/\/([^\/]+)\/?$/', $host, $regs)) {
917 // Replace ldaps:// by ssl://
918 $host = 'ssl://'.$regs[1];
919 } elseif (preg_match('/^ldap:\/\/([^\/]+)\/?$/', $host, $regs)) {
920 // Remove ldap://
921 $host = $regs[1];
922 }
923
924 //var_dump($newhostforstream); var_dump($host); var_dump($port);
925 //$host = 'ssl://ldap.test.local:636';
926 //$port = 636;
927
928 $errno = $errstr = 0;
929 /*
930 if ($methodtochecktcpconnect == 'socket') {
931 Try to use socket_create() method.
932 Method that use stream_context_create() works only on registered listed in stream stream_get_wrappers(): http, https, ftp, ...
933 }
934 */
935
936 // Use the method fsockopen to test tcp connect. No way to ignore ssl certificate errors with this method !
937 $op = @fsockopen($host, $port, $errno, $errstr, $timeout);
938
939 //var_dump($op);
940 if (!$op) {
941 return false; //DC is N/A
942 } else {
943 fclose($op); //explicitly close open socket connection
944 return true; //DC is up & running, we can safely connect with ldap_connect
945 }
946 }
947
948
949 // Attribute methods -----------------------------------------------------
950
960 public function addAttribute($dn, $info, $user)
961 {
962 dol_syslog(get_class($this)."::addAttribute dn=".$dn." info=".implode(',', $info));
963
964 // Check parameters
965 if (!$this->connection) {
966 $this->error = "NotConnected";
967 return -2;
968 }
969 if (!$this->bind) {
970 $this->error = "NotConnected";
971 return -3;
972 }
973
974 // Encode to LDAP page code
975 $dn = $this->convFromOutputCharset($dn, $this->ldapcharset);
976 foreach ($info as $key => $val) {
977 if (!is_array($val)) {
978 $info[$key] = $this->convFromOutputCharset($val, $this->ldapcharset);
979 }
980 }
981
982 $this->dump($dn, $info);
983
984 //print_r($info);
985 $result = @ldap_mod_add($this->connection, $dn, $info);
986
987 if ($result) {
988 dol_syslog(get_class($this)."::add_attribute successful", LOG_DEBUG);
989 return 1;
990 } else {
991 $this->error = @ldap_error($this->connection);
992 dol_syslog(get_class($this)."::add_attribute failed: ".$this->error, LOG_ERR);
993 return -1;
994 }
995 }
996
1006 public function updateAttribute($dn, $info, $user)
1007 {
1008 dol_syslog(get_class($this)."::updateAttribute dn=".$dn." info=".implode(',', $info));
1009
1010 // Check parameters
1011 if (!$this->connection) {
1012 $this->error = "NotConnected";
1013 return -2;
1014 }
1015 if (!$this->bind) {
1016 $this->error = "NotConnected";
1017 return -3;
1018 }
1019
1020 // Encode to LDAP page code
1021 $dn = $this->convFromOutputCharset($dn, $this->ldapcharset);
1022 foreach ($info as $key => $val) {
1023 if (!is_array($val)) {
1024 $info[$key] = $this->convFromOutputCharset($val, $this->ldapcharset);
1025 }
1026 }
1027
1028 $this->dump($dn, $info);
1029
1030 //print_r($info);
1031 $result = @ldap_mod_replace($this->connection, $dn, $info);
1032
1033 if ($result) {
1034 dol_syslog(get_class($this)."::updateAttribute successful", LOG_DEBUG);
1035 return 1;
1036 } else {
1037 $this->error = @ldap_error($this->connection);
1038 dol_syslog(get_class($this)."::updateAttribute failed: ".$this->error, LOG_ERR);
1039 return -1;
1040 }
1041 }
1042
1052 public function deleteAttribute($dn, $info, $user)
1053 {
1054 dol_syslog(get_class($this)."::deleteAttribute dn=".$dn." info=".implode(',', $info));
1055
1056 // Check parameters
1057 if (!$this->connection) {
1058 $this->error = "NotConnected";
1059 return -2;
1060 }
1061 if (!$this->bind) {
1062 $this->error = "NotConnected";
1063 return -3;
1064 }
1065
1066 // Encode to LDAP page code
1067 $dn = $this->convFromOutputCharset($dn, $this->ldapcharset);
1068 foreach ($info as $key => $val) {
1069 if (!is_array($val)) {
1070 $info[$key] = $this->convFromOutputCharset($val, $this->ldapcharset);
1071 }
1072 }
1073
1074 $this->dump($dn, $info);
1075
1076 //print_r($info);
1077 $result = @ldap_mod_del($this->connection, $dn, $info);
1078
1079 if ($result) {
1080 dol_syslog(get_class($this)."::deleteAttribute successful", LOG_DEBUG);
1081 return 1;
1082 } else {
1083 $this->error = @ldap_error($this->connection);
1084 dol_syslog(get_class($this)."::deleteAttribute failed: ".$this->error, LOG_ERR);
1085 return -1;
1086 }
1087 }
1088
1098 public function getAttribute($dn, $filter)
1099 {
1100 // Check parameters
1101 if (!$this->connection) {
1102 $this->error = "NotConnected";
1103 return -2;
1104 }
1105 if (!$this->bind) {
1106 $this->error = "NotConnected";
1107 return -3;
1108 }
1109
1110 // Honor the admin-configured user search filter (LDAP_FILTER_CONNECTION)
1111 // so an identifier match outside the configured scope does not leak
1112 // attributes for an unrelated LDAP user (see #37120).
1113 if (!empty($this->filter) && !preg_match('/^\s*\‍(\s*&\s*\‍(/', $filter)) {
1114 $filter = '(&(' . $this->filter . ')' . $filter . ')';
1115 }
1116
1117 $search = @ldap_search($this->connection, $dn, $filter);
1118
1119 // Only one entry should ever be returned
1120 $entry = @ldap_first_entry($this->connection, $search);
1121
1122 if (!$entry) {
1123 $this->ldapErrorCode = -1;
1124 $this->ldapErrorText = "Couldn't find entry";
1125 return 0; // Couldn't find entry...
1126 }
1127
1128 // Get values
1129 if (!($values = ldap_get_attributes($this->connection, $entry))) {
1130 $this->ldapErrorCode = ldap_errno($this->connection);
1131 $this->ldapErrorText = ldap_error($this->connection);
1132 return 0; // No matching attributes
1133 }
1134
1135 // Return an array containing the attributes.
1136 return $values;
1137 }
1138
1146 public function getAttributeValues($filterrecord, $attribute)
1147 {
1148 $attributes = array();
1149 $attributes[0] = $attribute;
1150
1151 // We need to search for this user in order to get their entry.
1152 $this->result = @ldap_search($this->connection, $this->people, $filterrecord, $attributes);
1153
1154 // Pourquoi cette ligne ?
1155 //$info = ldap_get_entries($this->connection, $this->result);
1156
1157 // Only one entry should ever be returned (no user will have the same uid)
1158 $entry = ldap_first_entry($this->connection, $this->result);
1159
1160 if (!$entry) {
1161 $this->ldapErrorCode = -1;
1162 $this->ldapErrorText = "Couldn't find user";
1163 return false; // Couldn't find the user...
1164 }
1165
1166 // Get values
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);
1170 return false; // No matching attributes
1171 }
1172
1173 // Return an array containing the attributes.
1174 return $values;
1175 }
1176
1189 public function getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter = 0, $attributeAsArray = array())
1190 {
1191 $fulllist = array();
1192
1193 dol_syslog(get_class($this)."::getRecords search=".$search." userDn=".$userDn." useridentifier=".$useridentifier." attributeArray=array(".implode(',', $attributeArray).") activefilter=".$activefilter);
1194
1195 // if the directory is AD, then bind first with the search user first
1196 if ($this->serverType == "activedirectory") {
1197 $this->bindauth($this->searchUser, $this->searchPassword);
1198 dol_syslog(get_class($this)."::bindauth serverType=activedirectory searchUser=".$this->searchUser);
1199 }
1200
1201 // Define filter
1202 if (!empty($activefilter)) { // Use a predefined trusted filter (defined into setup by admin).
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.')';
1209 } else {
1210 // If this->filter/this->filtergroup is empty, make filter on * (all)
1211 $filter = '('.ldap_escape($useridentifier, '', LDAP_ESCAPE_FILTER).'=*)';
1212 }
1213 } else { // Use a filter forged using the $search value
1214 $filter = '('.ldap_escape($useridentifier, '', LDAP_ESCAPE_FILTER).'='.ldap_escape($search, '', LDAP_ESCAPE_FILTER).')';
1215 }
1216
1217 if (is_array($attributeArray)) {
1218 // Return list with required fields
1219 $attributeArray = array_values($attributeArray); // This is to force to have index reordered from 0 (not make ldap_search fails)
1220 dol_syslog(get_class($this)."::getRecords connection=".$this->connectedServer.":".$this->serverPort." userDn=".$userDn." filter=".$filter." attributeArray=(".implode(',', $attributeArray).")");
1221 //var_dump($attributeArray);
1222 $this->result = @ldap_search($this->connection, $userDn, $filter, $attributeArray);
1223 } else {
1224 // Return list with fields selected by default
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);
1227 }
1228 if (!$this->result) {
1229 $this->error = 'LDAP search failed: '.ldap_errno($this->connection)." ".ldap_error($this->connection);
1230 return -1;
1231 }
1232
1233 $info = @ldap_get_entries($this->connection, $this->result);
1234
1235 // Warning: Dans info, les noms d'attributs sont en minuscule meme si passe
1236 // a ldap_search en majuscule !!!
1237 //print_r($info);
1238
1239 for ($i = 0; $i < $info["count"]; $i++) {
1240 $recordid = $this->convToOutputCharset($info[$i][strtolower($useridentifier)][0], $this->ldapcharset);
1241 if ($recordid) {
1242 //print "Found record with key $useridentifier=".$recordid."<br>\n";
1243 $fulllist[$recordid][$useridentifier] = $recordid;
1244
1245 // Add to the array for each attribute in my list
1246 $num = count($attributeArray);
1247 for ($j = 0; $j < $num; $j++) {
1248 $keyattributelower = strtolower($attributeArray[$j]);
1249 //print " Param ".$attributeArray[$j]."=".$info[$i][$keyattributelower][0]."<br>\n";
1250
1251 //permet de recuperer le SID avec Active Directory
1252 if ($this->serverType == "activedirectory" && $keyattributelower == "objectsid") {
1253 $objectsid = $this->getObjectSid($recordid);
1254 $fulllist[$recordid][$attributeArray[$j]] = $objectsid;
1255 } else {
1256 if (in_array($attributeArray[$j], $attributeAsArray) && is_array($info[$i][$keyattributelower])) {
1257 $valueTab = array();
1258 foreach ($info[$i][$keyattributelower] as $key => $value) {
1259 $valueTab[$key] = $this->convToOutputCharset($value, $this->ldapcharset);
1260 }
1261 $fulllist[$recordid][$attributeArray[$j]] = $valueTab;
1262 } else {
1263 $fulllist[$recordid][$attributeArray[$j]] = $this->convToOutputCharset($info[$i][$keyattributelower][0], $this->ldapcharset);
1264 }
1265 }
1266 }
1267 }
1268 }
1269
1270 asort($fulllist);
1271 return $fulllist;
1272 }
1273
1281 public function littleEndian($hex)
1282 {
1283 $result = '';
1284 for ($x = dol_strlen($hex) - 2; $x >= 0; $x -= 2) {
1285 $result .= substr($hex, $x, 2);
1286 }
1287 return $result;
1288 }
1289
1290
1298 public function getObjectSid($ldapUser)
1299 {
1300 $criteria = '('.$this->getUserIdentifier().'='.$ldapUser.')';
1301 $justthese = array("objectsid");
1302
1303 // if the directory is AD, then bind first with the search user first
1304 if ($this->serverType == "activedirectory") {
1305 $this->bindauth($this->searchUser, $this->searchPassword);
1306 }
1307
1308 $i = 0;
1309 $entry = null;
1310 $searchDN = $this->people;
1311
1312 while ($i <= 2) {
1313 $ldapSearchResult = @ldap_search($this->connection, $searchDN, $criteria, $justthese);
1314
1315 if (!$ldapSearchResult) {
1316 $this->error = ldap_errno($this->connection)." ".ldap_error($this->connection);
1317 return -1;
1318 }
1319
1320 $entry = ldap_first_entry($this->connection, $ldapSearchResult);
1321
1322 if (!$entry) {
1323 // Si pas de resultat on cherche dans le domaine
1324 $searchDN = $this->domain;
1325 $i++;
1326 } else {
1327 $i++;
1328 $i++;
1329 }
1330 }
1331
1332 if ($entry) {
1333 $ldapBinary = ldap_get_values_len($this->connection, $entry, "objectsid");
1334 $SIDText = $this->binSIDtoText($ldapBinary[0]);
1335 return $SIDText;
1336 } else {
1337 $this->error = ldap_errno($this->connection)." ".ldap_error($this->connection);
1338 return -1;
1339 }
1340 }
1341
1349 public function binSIDtoText($binsid)
1350 {
1351 $hex_sid = bin2hex($binsid);
1352 $rev = hexdec(substr($hex_sid, 0, 2)); // Get revision-part of SID
1353 $subcount = hexdec(substr($hex_sid, 2, 2)); // Get count of sub-auth entries
1354 $auth = hexdec(substr($hex_sid, 4, 12)); // SECURITY_NT_AUTHORITY
1355 $result = "$rev-$auth";
1356 for ($x = 0; $x < $subcount; $x++) {
1357 $result .= "-".hexdec($this->littleEndian(substr($hex_sid, 16 + ($x * 8), 8))); // get all SECURITY_NT_AUTHORITY
1358 }
1359 return $result;
1360 }
1361
1362
1376 public function search($checkDn, $filter)
1377 {
1378 dol_syslog(get_class($this)."::search checkDn=".$checkDn." filter=".$filter);
1379
1380 $checkDn = $this->convFromOutputCharset($checkDn, $this->ldapcharset);
1381 $filter = $this->convFromOutputCharset($filter, $this->ldapcharset);
1382
1383 // if the directory is AD, then bind first with the search user first
1384 if ($this->serverType == "activedirectory") {
1385 $this->bindauth($this->searchUser, $this->searchPassword);
1386 }
1387
1388 $this->result = @ldap_search($this->connection, $checkDn, $filter);
1389
1390 $result = @ldap_get_entries($this->connection, $this->result);
1391 if (!$result) {
1392 $this->error = ldap_errno($this->connection)." ".ldap_error($this->connection);
1393 return -1;
1394 } else {
1395 ldap_free_result($this->result);
1396 return $result;
1397 }
1398 }
1399
1400
1409 public function fetch($user, $filter)
1410 {
1411 // Perform the search and get the entry handles
1412
1413 // if the directory is AD, then bind first with the search user first
1414 if ($this->serverType == "activedirectory") {
1415 $this->bindauth($this->searchUser, $this->searchPassword);
1416 }
1417
1418 $searchDN = $this->people; // TODO Why searching in people then domain ?
1419
1420 $result = '';
1421 $i = 0;
1422 while ($i <= 2) {
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');
1429 } else {
1430 dol_syslog('Ldap::fetch search returns but found no records');
1431 }
1432 //var_dump($result);exit;
1433 } else {
1434 $this->error = ldap_errno($this->connection)." ".ldap_error($this->connection);
1435 dol_syslog(get_class($this)."::fetch search fails");
1436 return -1;
1437 }
1438
1439 if (!$result) {
1440 // Si pas de resultat on cherche dans le domaine
1441 $searchDN = $this->domain;
1442 $i++;
1443 } else {
1444 break;
1445 }
1446 }
1447
1448 if (!$result) {
1449 $this->error = ldap_errno($this->connection)." ".ldap_error($this->connection);
1450 return -1;
1451 } else {
1452 $this->name = $this->convToOutputCharset($result[0][$this->attr_name][0], $this->ldapcharset);
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);
1459
1460 $this->uacf = $this->parseUACF($this->convToOutputCharset($result[0]["useraccountcontrol"][0], $this->ldapcharset));
1461 if (isset($result[0]["pwdlastset"][0])) { // If expiration on password exists
1462 $this->pwdlastset = ($result[0]["pwdlastset"][0] != 0) ? $this->convertTime($this->convToOutputCharset($result[0]["pwdlastset"][0], $this->ldapcharset)) : 0;
1463 } else {
1464 $this->pwdlastset = -1;
1465 }
1466 if (!$this->name && !$this->login) {
1467 $this->pwdlastset = -1;
1468 }
1469 $this->badpwdtime = $this->convertTime($this->convToOutputCharset($result[0]["badpasswordtime"][0], $this->ldapcharset));
1470
1471 // FQDN domain
1472 $domain = str_replace('dc=', '', $this->domain);
1473 $domain = str_replace(',', '.', $domain);
1474 $this->domainFQDN = $domain;
1475
1476 // Set ldapUserDn (each user can have a different dn)
1477 //var_dump($result[0]);exit;
1478 $this->ldapUserDN = $result[0]['dn'];
1479
1480 ldap_free_result($this->result);
1481 return 1;
1482 }
1483 }
1484
1485
1486 // helper methods
1487
1493 public function getUserIdentifier()
1494 {
1495 if ($this->serverType == "activedirectory") {
1496 return $this->attr_sambalogin;
1497 } else {
1498 return $this->attr_login;
1499 }
1500 }
1501
1508 public function parseUACF($uacf)
1509 {
1510 //All flags array
1511 $flags = array(
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,
1529 "LOCKOUT" => 16,
1530 "HOMEDIR_REQUIRED" => 8,
1531 "ACCOUNTDISABLE" => 2,
1532 "SCRIPT" => 1
1533 );
1534
1535 //Parse flags to text
1536 $retval = array();
1537 //while (list($flag, $val) = each($flags)) {
1538 foreach ($flags as $flag => $val) {
1539 if ($uacf >= $val) {
1540 $uacf -= $val;
1541 $retval[$val] = $flag;
1542 }
1543 }
1544
1545 //Return human friendly flags
1546 return $retval;
1547 }
1548
1555 public function parseSAT($samtype)
1556 {
1557 $stypes = array(
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"
1565 );
1566
1567 $retval = "";
1568 foreach ($stypes as $sat => $val) {
1569 if ($samtype == $sat) {
1570 $retval = $val;
1571 break;
1572 }
1573 }
1574 if (empty($retval)) {
1575 $retval = "UNKNOWN_TYPE_".$samtype;
1576 }
1577
1578 return $retval;
1579 }
1580
1587 public function convertTime($value)
1588 {
1589 $dateLargeInt = $value; // nano secondes depuis 1601 !!!!
1590 if (PHP_INT_SIZE < 8) {
1591 // 32 bit platform
1592 $secsAfterADEpoch = (float) $dateLargeInt / (10000000.); // secondes depuis le 1 jan 1601
1593 } else {
1594 // At least 64 bit platform
1595 $secsAfterADEpoch = (int) $dateLargeInt / (10000000); // secondes depuis le 1 jan 1601
1596 }
1597 $ADToUnixConvertor = ((1970 - 1601) * 365.242190) * 86400; // UNIX start date - AD start date * jours * secondes
1598 $unixTimeStamp = intval($secsAfterADEpoch - $ADToUnixConvertor); // Unix time stamp
1599 return $unixTimeStamp;
1600 }
1601
1602
1610 private function convToOutputCharset($str, $pagecodefrom = 'UTF-8')
1611 {
1612 global $conf;
1613 if ($pagecodefrom == 'ISO-8859-1' && $conf->file->character_set_client == 'UTF-8') {
1614 $str = mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1');
1615 }
1616 if ($pagecodefrom == 'UTF-8' && $conf->file->character_set_client == 'ISO-8859-1') {
1617 $str = mb_convert_encoding($str, 'ISO-8859-1');
1618 }
1619 return $str;
1620 }
1621
1629 public function convFromOutputCharset($str, $pagecodeto = 'UTF-8')
1630 {
1631 global $conf;
1632 if ($pagecodeto == 'ISO-8859-1' && $conf->file->character_set_client == 'UTF-8') {
1633 $str = mb_convert_encoding($str, 'ISO-8859-1');
1634 }
1635 if ($pagecodeto == 'UTF-8' && $conf->file->character_set_client == 'ISO-8859-1') {
1636 $str = mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1');
1637 }
1638 return $str;
1639 }
1640
1641
1648 public function getNextGroupGid($keygroup = 'LDAP_KEY_GROUPS')
1649 {
1650
1651 if (empty($keygroup)) {
1652 $keygroup = 'LDAP_KEY_GROUPS';
1653 }
1654
1655 $search = '(' . getDolGlobalString($keygroup).'=*)';
1656 $result = $this->search($this->groups, $search);
1657 if ($result) {
1658 $c = $result['count'];
1659 $gids = array();
1660 for ($i = 0; $i < $c; $i++) {
1661 $gids[] = $result[$i]['gidnumber'][0];
1662 }
1663 rsort($gids);
1664
1665 return $gids[0] + 1;
1666 }
1667
1668 return 0;
1669 }
1670}
$c
Definition line.php:331
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.
Definition repair.php:128