2002-08-06 16:56:14 +00:00
|
|
|
<?php
|
|
|
|
|
2003-03-24 18:15:26 +00:00
|
|
|
// LDAP auth plug-in for phpBB 2.2
|
|
|
|
// $Id$
|
|
|
|
//
|
2003-03-09 16:09:37 +00:00
|
|
|
// Authentication plug-ins is largely down to Sergey Kanareykin, our thanks to him.
|
2002-08-06 16:56:14 +00:00
|
|
|
//
|
2003-03-09 16:09:37 +00:00
|
|
|
// This is for initial authentication via an LDAP server, user information is then
|
|
|
|
// obtained from the integrated user table
|
2002-08-06 16:56:14 +00:00
|
|
|
//
|
2003-03-09 16:09:37 +00:00
|
|
|
// You can do any kind of checking you like here ... the return data format is
|
|
|
|
// either the resulting row of user information, an integer zero (indicating an
|
|
|
|
// inactive user) or some error string
|
2002-08-06 16:56:14 +00:00
|
|
|
function login_ldap(&$username, &$password)
|
|
|
|
{
|
2003-03-09 16:09:37 +00:00
|
|
|
global $db, $config;
|
2002-08-06 16:56:14 +00:00
|
|
|
|
2003-03-09 16:09:37 +00:00
|
|
|
if (!extension_loaded('ldap'))
|
2002-08-06 16:56:14 +00:00
|
|
|
{
|
|
|
|
return 'LDAP extension not available';
|
|
|
|
}
|
|
|
|
|
2003-03-09 16:09:37 +00:00
|
|
|
if (!($ldap = @ldap_connect($config['ldap_server'])))
|
2002-08-06 16:56:14 +00:00
|
|
|
{
|
|
|
|
return 'Could not connect to LDAP server';
|
|
|
|
}
|
|
|
|
|
2003-03-09 16:09:37 +00:00
|
|
|
$search = @ldap_search($ldap, $config['ldap_base_dn'], $config['ldap_uid'] . '=' . $username, array($config['ldap_uid']));
|
2002-08-06 16:56:14 +00:00
|
|
|
$result = @ldap_get_entries($ldap, $search);
|
|
|
|
|
2003-03-09 16:09:37 +00:00
|
|
|
if (is_array($result) && count($result) > 1)
|
2002-08-06 16:56:14 +00:00
|
|
|
{
|
2003-03-09 16:09:37 +00:00
|
|
|
if (@ldap_bind($ldap, $result[0]['dn'], $password))
|
2002-08-06 16:56:14 +00:00
|
|
|
{
|
|
|
|
@ldap_close($ldap);
|
|
|
|
|
2003-10-12 15:29:18 +00:00
|
|
|
$sql ='SELECT user_id, username, user_password, user_passchg, user_email, user_active
|
|
|
|
FROM ' . USERS_TABLE . "
|
2003-03-09 16:09:37 +00:00
|
|
|
WHERE username = '" . $db->sql_escape($username) . "'";
|
2002-08-06 16:56:14 +00:00
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
|
2003-03-09 16:09:37 +00:00
|
|
|
if ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
return (empty($row['user_active'])) ? 0 : $row;
|
|
|
|
}
|
2002-08-06 16:56:14 +00:00
|
|
|
}
|
2002-10-04 13:09:10 +00:00
|
|
|
}
|
|
|
|
|
2002-08-06 16:56:14 +00:00
|
|
|
@ldap_close($ldap);
|
2002-10-04 13:09:10 +00:00
|
|
|
|
2002-08-06 16:56:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-10-04 13:09:10 +00:00
|
|
|
// This function is used to output any required fields in the authentication
|
|
|
|
// admin panel. It also defines any required configuration table fields.
|
2002-08-07 01:11:38 +00:00
|
|
|
function admin_ldap(&$new)
|
|
|
|
{
|
2002-10-20 19:19:07 +00:00
|
|
|
global $user;
|
2002-08-07 01:11:38 +00:00
|
|
|
|
|
|
|
?>
|
|
|
|
<tr>
|
2003-03-24 18:13:22 +00:00
|
|
|
<td class="row1"><?php echo $user->lang['LDAP_SERVER']; ?>:<br /><span class="gensmall"><?php echo $user->lang['LDAP_SERVER_EXPLAIN']; ?></span></td>
|
2002-08-07 01:11:38 +00:00
|
|
|
<td class="row2"><input type="text" size="40" name="ldap_server" value="<?php echo $new['ldap_server']; ?>" /></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2003-03-24 18:13:22 +00:00
|
|
|
<td class="row1"><?php echo $user->lang['LDAP_DN']; ?>:<br /><span class="gensmall"><?php echo $user->lang['LDAP_DN_EXPLAIN']; ?></span></td>
|
2002-08-07 01:11:38 +00:00
|
|
|
<td class="row2"><input type="text" size="40" name="ldap_base_dn" value="<?php echo $new['ldap_base_dn']; ?>" /></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2003-03-24 18:13:22 +00:00
|
|
|
<td class="row1"><?php echo $user->lang['LDAP_UID']; ?>:<br /><span class="gensmall"><?php echo $user->lang['LDAP_UID_EXPLAIN']; ?></span></td>
|
2002-08-07 01:11:38 +00:00
|
|
|
<td class="row2"><input type="text" size="40" name="ldap_uid" value="<?php echo $new['ldap_uid']; ?>" /></td>
|
|
|
|
</tr>
|
|
|
|
<?php
|
2002-10-04 13:09:10 +00:00
|
|
|
|
2002-08-07 13:02:48 +00:00
|
|
|
// These are fields required in the config table
|
|
|
|
return array('ldap_server', 'ldap_base_dn', 'ldap_uid');
|
2002-08-07 01:11:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-10-04 13:09:10 +00:00
|
|
|
// Would be nice to allow syncing of 'appropriate' data when user updates
|
|
|
|
// their username, password, etc. ... should be up to the plugin what data
|
|
|
|
// is updated.
|
|
|
|
//
|
|
|
|
// $mode perhaps being one of NEW, UPDATE, DELETE
|
|
|
|
function usercp_ldap($mode)
|
|
|
|
{
|
2003-03-09 16:09:37 +00:00
|
|
|
global $db, $config;
|
2002-10-04 13:09:10 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-08-06 16:56:14 +00:00
|
|
|
?>
|