/** * Connects and Binds to LDAP */ private static function establishConnection() { if (!self::$configured) { OCP\Util::writeLog('ldap', 'Configuration is invalid, cannot connect', OCP\Util::INFO); return false; } if (!self::$ldapConnectionRes) { self::$ldapConnectionRes = ldap_connect(self::$ldapHost, self::$ldapPort); if (ldap_set_option(self::$ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { if (ldap_set_option(self::$ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { if (self::$ldapTLS) { ldap_start_tls(self::$ldapConnectionRes); } } } $ldapLogin = @ldap_bind(self::$ldapConnectionRes, self::$ldapAgentName, self::$ldapAgentPassword); if (!$ldapLogin) { OCP\Util::writeLog('ldap', 'Bind failed: ' . ldap_errno(self::$ldapConnectionRes) . ': ' . ldap_error(self::$ldapConnectionRes), OCP\Util::ERROR); return false; } } }
/** * Connects and Binds to LDAP */ private static function establishConnection() { static $phpLDAPinstalled = true; if (!$phpLDAPinstalled) { return false; } if (!self::$configured) { OCP\Util::writeLog('ldap', 'Configuration is invalid, cannot connect', OCP\Util::INFO); return false; } if (!self::$ldapConnectionRes) { //check if php-ldap is installed if (!function_exists('ldap_connect')) { $phpLDAPinstalled = false; OCP\Util::writeLog('user_ldap', 'function ldap_connect is not available. Make sure that the PHP ldap module is installed.', OCP\Util::ERROR); return false; } self::$ldapConnectionRes = ldap_connect(self::$ldapHost, self::$ldapPort); if (ldap_set_option(self::$ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { if (ldap_set_option(self::$ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { if (self::$ldapTLS) { ldap_start_tls(self::$ldapConnectionRes); } } } $ldapLogin = @ldap_bind(self::$ldapConnectionRes, self::$ldapAgentName, self::$ldapAgentPassword); if (!$ldapLogin) { OCP\Util::writeLog('ldap', 'Bind failed: ' . ldap_errno(self::$ldapConnectionRes) . ': ' . ldap_error(self::$ldapConnectionRes), OCP\Util::ERROR); return false; } } }