aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/auth/auth_ldap.php
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2006-03-18 16:19:18 +0000
committerNils Adermann <naderman@naderman.de>2006-03-18 16:19:18 +0000
commit957502a28b1d2afec74cad30731dc2ee101cafe3 (patch)
tree7707c27358fd83138566fca91fe8577bbffdd06f /phpBB/includes/auth/auth_ldap.php
parent9f7bc931259522fe7ae1ea9d6b5f4b17b60c97ad (diff)
downloadforums-957502a28b1d2afec74cad30731dc2ee101cafe3.tar
forums-957502a28b1d2afec74cad30731dc2ee101cafe3.tar.gz
forums-957502a28b1d2afec74cad30731dc2ee101cafe3.tar.bz2
forums-957502a28b1d2afec74cad30731dc2ee101cafe3.tar.xz
forums-957502a28b1d2afec74cad30731dc2ee101cafe3.zip
- Added init_{$auth_plugin} function which can be used to test a connection to the authentication system before actually saving the new configuration. This will hopefully stop people from locking themselves out by using an authentication system that they cannot connect to.
git-svn-id: file:///svn/phpbb/trunk@5653 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/auth/auth_ldap.php')
-rw-r--r--phpBB/includes/auth/auth_ldap.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/phpBB/includes/auth/auth_ldap.php b/phpBB/includes/auth/auth_ldap.php
index 2eedd5a17b..17c29cc5e6 100644
--- a/phpBB/includes/auth/auth_ldap.php
+++ b/phpBB/includes/auth/auth_ldap.php
@@ -20,6 +20,48 @@
*/
/**
+* Only allow changing authentication to ldap if we can connect to the ldap server
+*/
+function init_ldap()
+{
+ global $config, $user;
+
+ if (!extension_loaded('ldap'))
+ {
+ return $user->lang['LDAP_NO_LDAP_EXTENSION'];
+ }
+
+ if (!($ldap = @ldap_connect($config['ldap_server'])))
+ {
+ return $user->lang['LDAP_NO_SERVER_CONNECTION'];
+ }
+
+ @ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
+
+ // We'll get a notice here that we don't want, if we cannot connect to the server.
+ // ldap_connect only checks whether the specified server is valid, so the connection might still fail
+ ob_start();
+
+ $search = @ldap_search($ldap, $config['ldap_base_dn'], $config['ldap_uid'] . '=' . $user->data['username'], array($config['ldap_uid']));
+
+ if (ob_get_clean())
+ {
+ return $user->lang['LDAP_NO_SERVER_CONNECTION'];
+ }
+
+ $result = @ldap_get_entries($ldap, $search);
+
+ @ldap_close($ldap);
+
+ if (is_array($result) && sizeof($result) > 1)
+ {
+ return false;
+ }
+
+ return sprintf($user->lang['LDAP_NO_IDENTITY'], $user->data['username']);
+}
+
+/**
* Login function
*/
function login_ldap(&$username, &$password)