diff --git a/include/class_config.inc b/include/class_config.inc index 881d1c45fe5bc71af6660cc9508e2dbfe0d14e31..47bb3ff79d07f6e1c0ad555884df45c1e5fd3ca0 100644 --- a/include/class_config.inc +++ b/include/class_config.inc @@ -304,13 +304,13 @@ class config * * \return ldapMultiplexer object */ - function get_ldap_link ($sizelimit = FALSE) + function get_ldap_link (bool $sizelimit = FALSE): ldapMultiplexer { global $ui; if ($this->ldapLink === NULL || !is_resource($this->ldapLink->cid)) { /* Build new connection */ - $this->ldapLink = ldap_init($this->current['SERVER'], $this->current['BASE'], + $this->ldapLink = LDAP::init($this->current['SERVER'], $this->current['BASE'], $this->current['ADMINDN'], $this->get_credentials($this->current['ADMINPASSWORD'])); /* Check for connection */ diff --git a/include/class_ldap.inc b/include/class_ldap.inc index 5d3b33f7af580d419bf0245dcc861076427522c1..6b9aec8aebad2ef21b45f49c4183f03239ba3def 100644 --- a/include/class_ldap.inc +++ b/include/class_ldap.inc @@ -97,6 +97,39 @@ class LDAP $this->connect(); } + /*! + * \brief Initialize a LDAP connection + * + * Initializes a LDAP connection. + * + * \param string $server The server we are connecting to + * + * \param string $base The base of our ldap tree + * + * \param string $binddn Default: empty + * + * \param string $pass Default: empty + * + * \return LDAP object + */ + public static function init (string $server, string $base, string $binddn = '', string $pass = ''): LDAP + { + global $config; + + $ldap = new LDAP($binddn, $pass, $server, + isset($config->current['LDAPFOLLOWREFERRALS']) && $config->current['LDAPFOLLOWREFERRALS'] == 'TRUE', + isset($config->current['LDAPTLS']) && $config->current['LDAPTLS'] == 'TRUE'); + + /* Sadly we've no proper return values here. Use the error message instead. */ + if (!$ldap->success()) { + throw new FatalError(htmlescape(sprintf(_('FATAL: Error when connecting the LDAP. Server said "%s".'), $ldap->get_error()))); + } + + /* Preset connection base to $base and return to caller */ + $ldap->cd($base); + return $ldap; + } + /*! * \brief Get the search ressource * diff --git a/include/class_objects.inc b/include/class_objects.inc index 9646b52f01850b3521d275fa142e3a38f38d6ab3..66ee6d23f82b2c5272ab8ee7d8749867f5c57806 100644 --- a/include/class_objects.inc +++ b/include/class_objects.inc @@ -43,7 +43,7 @@ class objects * * \return The list of objects as an associative array (keys are dns) */ - static function ls ($types, $attrs = NULL, $ou = NULL, $filter = '', $checkAcl = FALSE, $scope = 'subtree', $templateSearch = FALSE, $sizeLimit = FALSE) + static function ls ($types, $attrs = NULL, string $ou = NULL, string $filter = '', bool $checkAcl = FALSE, string $scope = 'subtree', bool $templateSearch = FALSE, bool $sizeLimit = FALSE): array { global $ui, $config; @@ -222,7 +222,7 @@ class objects * * \return The number of objects of type $type in $ou */ - static function count ($types, $ou = NULL, $filter = '', $checkAcl = FALSE, $templateSearch = FALSE) + static function count ($types, string $ou = NULL, string $filter = '', bool $checkAcl = FALSE, bool $templateSearch = FALSE): int { try { $ldap = static::search($types, ['dn'], $ou, $filter, $checkAcl, 'subtree', $templateSearch, $partialFilterAcls); @@ -237,7 +237,7 @@ class objects return $ldap->count(); } - private static function search ($types, $search_attrs, $ou = NULL, $filter = '', $checkAcl = FALSE, $scope = 'subtree', $templateSearch = FALSE, &$partialFilterAcls = [], $sizeLimit = FALSE) + private static function search ($types, $search_attrs, string $ou = NULL, string $filter = '', bool $checkAcl = FALSE, string $scope = 'subtree', bool $templateSearch = FALSE, &$partialFilterAcls = [], bool $sizeLimit = FALSE): ldapMultiplexer { global $config, $ui; @@ -337,7 +337,7 @@ class objects * * \return The created tab object */ - static function open ($dn, $type) + static function open (string $dn, string $type): simpleTabs { $infos = static::infos($type); $tabClass = $infos['tabClass']; @@ -348,7 +348,7 @@ class objects return $tabObject; } - static function link ($dn, $type, $subaction = '', $text = NULL, $icon = TRUE, $link = TRUE) + static function link (string $dn, string $type, string $subaction = '', string $text = NULL, bool $icon = TRUE, bool $link = TRUE): string { global $config; @@ -395,12 +395,12 @@ class objects return $text; } - static function create ($type) + static function create (string $type): simpleTabs { return static::open('new', $type); } - static function createTemplate ($type) + static function createTemplate (string $type): simpleTabs { $infos = static::infos($type); $tabClass = $infos['tabClass']; @@ -416,7 +416,7 @@ class objects return $tabObject; } - static function &infos ($type) + static function &infos (string $type): array { global $config; @@ -448,14 +448,14 @@ class objects return $infos; } - static function isOfType ($attrs, $type) + static function isOfType ($attrs, string $type): bool { $filter = static::getFilterObject($type); return $filter($attrs); } /* This method allows to cache parsed filter in filterObject key in objectTypes */ - static function getFilterObject ($type) + static function getFilterObject (string $type): ldapFilter { global $config; @@ -468,7 +468,7 @@ class objects } /* This method allows to cache searched attributes list in objectTypes */ - static function getSearchedAttributes ($type) + static function getSearchedAttributes (string $type): array { global $config; @@ -499,7 +499,7 @@ class objects return $infos['searchAttributes']; } - static function types () + static function types (): array { global $config; return array_keys($config->data['OBJECTS']); @@ -507,7 +507,7 @@ class objects /* !\brief This method returns a list of all available templates for the given type */ - static function getTemplates ($type, $requiredPermissions = 'r', $filter = '') + static function getTemplates (string $type, string $requiredPermissions = 'r', string $filter = ''): array { global $config, $ui; diff --git a/include/functions.inc b/include/functions.inc index e67fdece15f71d8f4b2e097d9d87e91e1be1bb9a..70160cf947dd734658914034e74fc09ed0c94972 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -317,40 +317,6 @@ function fusiondirectory_log ($message) syslog(LOG_INFO, "FusionDirectory $username: $message"); } - -/*! - * \brief Initialize a LDAP connection - * - * Initializes a LDAP connection. - * - * \param string $server The server we are connecting to - * - * \param string $base The base of our ldap tree - * - * \param string $binddn Default: empty - * - * \param string $pass Default: empty - * - * \return LDAP object - */ -function ldap_init ($server, $base, $binddn = '', $pass = '') -{ - global $config; - - $ldap = new LDAP($binddn, $pass, $server, - isset($config->current['LDAPFOLLOWREFERRALS']) && $config->current['LDAPFOLLOWREFERRALS'] == 'TRUE', - isset($config->current['LDAPTLS']) && $config->current['LDAPTLS'] == 'TRUE'); - - /* Sadly we've no proper return values here. Use the error message instead. */ - if (!$ldap->success()) { - throw new FatalError(htmlescape(sprintf(_('FATAL: Error when connecting the LDAP. Server said "%s".'), $ldap->get_error()))); - } - - /* Preset connection base to $base and return to caller */ - $ldap->cd($base); - return $ldap; -} - /*! * \brief Add a lock for object(s) * diff --git a/include/php_setup.inc b/include/php_setup.inc index ff769d66b52880b39e880f2f535d09fd80a100be..6e0ad8434e12ffffde81124c73c14d1e320fae06 100644 --- a/include/php_setup.inc +++ b/include/php_setup.inc @@ -45,7 +45,7 @@ function htmlunescape (string $html): string function html_trace ($errstr = "") { static $hideArgs = [ - 'ldap_init' => [3], + 'LDAP/init' => [3], 'userinfo/loginUser' => [1], 'change_password' => [1], 'cred_decrypt' => [0,1],