Commit fb55c719 authored by Ad Schellevis's avatar Ad Schellevis

Merge pull request #288 from chrisch1974/hotfix/ldap

minor LDAP fixes
parents 1127338c daf9ba53
...@@ -168,6 +168,8 @@ class LDAP ...@@ -168,6 +168,8 @@ class LDAP
public function searchUsers($username, $userNameAttribute, $extendedQuery = null) public function searchUsers($username, $userNameAttribute, $extendedQuery = null)
{ {
if ($this->ldapHandle !== false) { if ($this->ldapHandle !== false) {
// on Active Directory sAMAccountName is returned as samaccountname
$userNameAttribute = strtolower($userNameAttribute);
// add $userNameAttribute to search results // add $userNameAttribute to search results
$this->addSearchAttribute($userNameAttribute); $this->addSearchAttribute($userNameAttribute);
$result = array(); $result = array();
...@@ -183,6 +185,7 @@ class LDAP ...@@ -183,6 +185,7 @@ class LDAP
foreach (array($userNameAttribute, "name") as $ldapAttr) { foreach (array($userNameAttribute, "name") as $ldapAttr) {
if (isset($searchResults[$i][$ldapAttr]) && $searchResults[$i][$ldapAttr]['count'] > 0) { if (isset($searchResults[$i][$ldapAttr]) && $searchResults[$i][$ldapAttr]['count'] > 0) {
$result[] = array("name" => $searchResults[$i][$ldapAttr][0] $result[] = array("name" => $searchResults[$i][$ldapAttr][0]
, "fullname" => $searchResults[$i]['name'][0]
, "dn" => $searchResults[$i]['dn']); , "dn" => $searchResults[$i]['dn']);
break; break;
} }
......
...@@ -629,6 +629,40 @@ endif; ?> ...@@ -629,6 +629,40 @@ endif; ?>
</select> </select>
</td> </td>
</tr> </tr>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Bind credentials");?></td>
<td width="78%" class="vtable">
<table border="0" cellspacing="0" cellpadding="2" summary="bind credentials">
<tr>
<td>
<input name="ldap_anon" type="checkbox" id="ldap_anon" value="yes" <?php if ($pconfig['ldap_anon']) {
echo "checked=\"checked\"";
} ?> onclick="ldap_bindchange()" />
</td>
<td>
<?=gettext("Use anonymous binds to resolve distinguished names");?>
</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" id="ldap_bind" summary="bind">
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td><?=gettext("User DN:");?> &nbsp;</td>
<td>
<input name="ldap_binddn" type="text" class="formfld unknown" id="ldap_binddn" size="40" value="<?=htmlspecialchars($pconfig['ldap_binddn']);?>"/><br />
</td>
</tr>
<tr>
<td><?=gettext("Password:");?> &nbsp;</td>
<td>
<input name="ldap_bindpw" type="password" class="formfld pwd" id="ldap_bindpw" size="20" value="<?=htmlspecialchars($pconfig['ldap_bindpw']);?>"/><br />
</td>
</tr>
</table>
</td>
</tr>
<tr> <tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Search scope");?></td> <td width="22%" valign="top" class="vncell"><?=gettext("Search scope");?></td>
<td width="78%" class="vtable"> <td width="78%" class="vtable">
...@@ -700,40 +734,6 @@ endif; ?> ...@@ -700,40 +734,6 @@ endif; ?>
</table> </table>
</td> </td>
</tr> </tr>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Bind credentials");?></td>
<td width="78%" class="vtable">
<table border="0" cellspacing="0" cellpadding="2" summary="bind credentials">
<tr>
<td>
<input name="ldap_anon" type="checkbox" id="ldap_anon" value="yes" <?php if ($pconfig['ldap_anon']) {
echo "checked=\"checked\"";
} ?> onclick="ldap_bindchange()" />
</td>
<td>
<?=gettext("Use anonymous binds to resolve distinguished names");?>
</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" id="ldap_bind" summary="bind">
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td><?=gettext("User DN:");?> &nbsp;</td>
<td>
<input name="ldap_binddn" type="text" class="formfld unknown" id="ldap_binddn" size="40" value="<?=htmlspecialchars($pconfig['ldap_binddn']);?>"/><br />
</td>
</tr>
<tr>
<td><?=gettext("Password:");?> &nbsp;</td>
<td>
<input name="ldap_bindpw" type="password" class="formfld pwd" id="ldap_bindpw" size="20" value="<?=htmlspecialchars($pconfig['ldap_bindpw']);?>"/><br />
</td>
</tr>
</table>
</td>
</tr>
<?php if (!isset($id)) : <?php if (!isset($id)) :
?> ?>
<tr> <tr>
......
...@@ -464,7 +464,7 @@ function sshkeyClicked(obj) { ...@@ -464,7 +464,7 @@ function sshkeyClicked(obj) {
function import_ldap_users() { function import_ldap_users() {
url="system_usermanager_import_ldap.php"; url="system_usermanager_import_ldap.php";
var oWin = window.open(url,"OPNsense","width=620,height=400,top=150,left=150"); var oWin = window.open(url,"OPNsense","width=620,height=400,top=150,left=150,scrollbars=yes");
if (oWin==null || typeof(oWin)=="undefined") { if (oWin==null || typeof(oWin)=="undefined") {
alert("<?=gettext('Popup blocker detected. Action aborted.');?>"); alert("<?=gettext('Popup blocker detected. Action aborted.');?>");
} }
...@@ -515,7 +515,7 @@ function import_ldap_users() { ...@@ -515,7 +515,7 @@ function import_ldap_users() {
<table class="table table-striped table-sort"> <table class="table table-striped table-sort">
<?php <?php
$ro = ""; $ro = "";
if ($pconfig['utype'] == "system") { if ($pconfig['utype'] == "system" || !empty($pconfig['user_dn'])) {
$ro = "readonly=\"readonly\""; $ro = "readonly=\"readonly\"";
} }
?> ?>
...@@ -550,7 +550,7 @@ function import_ldap_users() { ...@@ -550,7 +550,7 @@ function import_ldap_users() {
<input name="user_dn" type="text" class="formfld user" id="user_dn" size="20" maxlength="16" value="<?=htmlspecialchars($pconfig['user_dn']);?>"/ readonly> <input name="user_dn" type="text" class="formfld user" id="user_dn" size="20" maxlength="16" value="<?=htmlspecialchars($pconfig['user_dn']);?>"/ readonly>
</td> </td>
</tr> </tr>
<?php endif; <?php else:
?> ?>
<tr> <tr>
<td width="22%" valign="top" class="vncellreq" rowspan="2"><?=gettext("Password");?></td> <td width="22%" valign="top" class="vncellreq" rowspan="2"><?=gettext("Password");?></td>
...@@ -563,6 +563,8 @@ function import_ldap_users() { ...@@ -563,6 +563,8 @@ function import_ldap_users() {
<input name="passwordfld2" type="password" class="formfld pwd" id="passwordfld2" size="20" value="" />&nbsp;<?= gettext("(confirmation)"); ?> <input name="passwordfld2" type="password" class="formfld pwd" id="passwordfld2" size="20" value="" />&nbsp;<?= gettext("(confirmation)"); ?>
</td> </td>
</tr> </tr>
<?php endif;
?>
<tr> <tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Full name");?></td> <td width="22%" valign="top" class="vncell"><?=gettext("Full name");?></td>
<td width="78%" class="vtable"> <td width="78%" class="vtable">
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
require_once("guiconfig.inc"); require_once("guiconfig.inc");
require_once("auth.inc"); require_once("auth.inc");
function add_local_user($username, $userdn) { function add_local_user($username, $userdn, $userfullname) {
global $config; global $config;
foreach ($config['system']['user'] as &$user) { foreach ($config['system']['user'] as &$user) {
if ($user['name'] == $username && $user['name'] != 'root') { if ($user['name'] == $username && $user['name'] != 'root') {
...@@ -43,6 +43,7 @@ function add_local_user($username, $userdn) { ...@@ -43,6 +43,7 @@ function add_local_user($username, $userdn) {
$new_user['scope'] = 'user'; $new_user['scope'] = 'user';
$new_user['name'] = $username; $new_user['name'] = $username;
$new_user['user_dn'] = $userdn; $new_user['user_dn'] = $userdn;
$new_user['descr'] = $userfullname;
$new_user['uid'] = $config['system']['nextuid']++; $new_user['uid'] = $config['system']['nextuid']++;
$config['system']['user'][] = $new_user; $config['system']['user'][] = $new_user;
} }
...@@ -89,7 +90,7 @@ if ($authcfg['type'] == 'ldap') { ...@@ -89,7 +90,7 @@ if ($authcfg['type'] == 'ldap') {
foreach ($result as $ldap_user ) { foreach ($result as $ldap_user ) {
foreach ($_POST['user_dn'] as $userDN) { foreach ($_POST['user_dn'] as $userDN) {
if ($userDN == $ldap_user['dn'] && !in_array($ldap_user['dn'], $confDNs)) { if ($userDN == $ldap_user['dn'] && !in_array($ldap_user['dn'], $confDNs)) {
add_local_user($ldap_user['name'] , $ldap_user['dn']); add_local_user($ldap_user['name'] , $ldap_user['dn'], $ldap_user['fullname']);
$update_count++; $update_count++;
} }
} }
...@@ -106,6 +107,7 @@ if ($authcfg['type'] == 'ldap') { ...@@ -106,6 +107,7 @@ if ($authcfg['type'] == 'ldap') {
$ldap_users[$ldap_user['name']] = $ldap_user['dn']; $ldap_users[$ldap_user['name']] = $ldap_user['dn'];
} }
} }
ksort($ldap_users);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment