Skip to content

Commit

Permalink
Local patch to have auth_LDAP find the DN instead of assuming the OU.
Browse files Browse the repository at this point in the history
Instead of assuming all users are in the same OU, this patch changes
auth_LDAP so that it will find the ldap user and get their dn directly.
  • Loading branch information
mdhafen committed Feb 13, 2023
1 parent f462d14 commit 3f091a8
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions functions/classes/class.User.php
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ private function show_http_login () {
*/
private function directory_connect ($authparams) {
# adLDAP script
require(dirname(__FILE__) . "/../adLDAP/src/adLDAP.php");
require_once(dirname(__FILE__) . "/../adLDAP/src/adLDAP.php");
$dirparams = Array();
$dirparams['base_dn'] = @$authparams['base_dn'];
$dirparams['ad_port'] = @$authparams['ad_port'];
Expand All @@ -1033,7 +1033,7 @@ private function directory_connect ($authparams) {
// TODO: remove legacy support at some point
if ($authparams['ldap_security'] == 'tls' || $authparams['use_tls'] == 1) { $dirparams['use_tls'] = true; }
elseif ($authparams['ldap_security'] == 'ssl' || $authparams['use_ssl'] == 1) { $dirparams['use_ssl'] = true; }
if (isset($authparams['admin_username']) && isset($authparams['admin_password'])) {
if (isset($authparams['adminUsername']) && isset($authparams['adminPassword'])) {
$dirparams['admin_username'] = $authparams['adminUsername'];
$dirparams['admin_password'] = $authparams['adminPassword'];
}
Expand Down Expand Up @@ -1130,12 +1130,23 @@ private function auth_LDAP ($username, $password) {
$authparams = json_decode($this->authmethodparams, true);
$this->ldap = true; //set ldap flag

// set uid
if (!empty($authparams['uid_attr'])) { $udn = $authparams['uid_attr'] . '=' . $username; }
else { $udn = 'uid=' . $username; }
// set DN
if (!empty($authparams['users_base_dn'])) { $udn = $udn . "," . $authparams['users_base_dn']; }
else { $udn = $udn . "," . $authparams['base_dn']; }
// get DN from directory
$dn_authparams = $authparams;
if (!empty($authparams['users_base_dn'])) { $dn_authparams['base_dn'] = $authparams['users_base_dn']; }
$adldap = $this->directory_connect($dn_authparams);
$dn_user = $adldap->user()->info($username, array("cn"), false, 'LDAP');
if (!empty($dn_user[0]["dn"])) {
$udn = $dn_user[0]["dn"];
}

if (empty($udn)) {
// set uid
if (!empty($authparams['uid_attr'])) { $udn = $authparams['uid_attr'] . '=' . $username; }
else { $udn = 'uid=' . $username; }
// set DN
if (!empty($authparams['users_base_dn'])) { $udn = $udn . "," . $authparams['users_base_dn']; }
else { $udn = $udn . "," . $authparams['base_dn']; }
}
// authenticate
$this->directory_authenticate($authparams, $udn, $password);
}
Expand Down

0 comments on commit 3f091a8

Please sign in to comment.