Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update auth.php #1700

Merged
merged 1 commit into from
Nov 13, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 28 additions & 7 deletions lib/plugins/authldap/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ protected function _getUserData($user, $inbind = false) {

$info = array();
$info['user'] = $user;
$this->_debug('LDAP user to find: '.htmlspecialchars($info['user']), 0, __LINE__, __FILE__);

$info['server'] = $this->getConf('server');
$this->_debug('LDAP Server: '.htmlspecialchars($info['server']), 0, __LINE__, __FILE__);


//get info for given user
$base = $this->_makeFilter($this->getConf('usertree'), $info);
Expand All @@ -193,16 +197,33 @@ protected function _getUserData($user, $inbind = false) {
$filter = "(ObjectClass=*)";
}

$sr = $this->_ldapsearch($this->con, $base, $filter, $this->getConf('userscope'));
$result = @ldap_get_entries($this->con, $sr);
$this->_debug('LDAP Filter: '.htmlspecialchars($filter), 0, __LINE__, __FILE__);
$this->_debug('LDAP user search: '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__);
$this->_debug('LDAP search at: '.htmlspecialchars($base.' '.$filter), 0, __LINE__, __FILE__);

// Don't accept more or less than one response
if(!is_array($result) || $result['count'] != 1) {
return false; //user not found
$sr = $this->_ldapsearch($this->con, $base, $filter, $this->getConf('userscope'));

$result = @ldap_get_entries($this->con, $sr);

// if result is not an array
if(!is_array($result)) {
// no objects found
$this->_debug('LDAP search returned non-array result: '.htmlspecialchars(print($result)), -1, __LINE__, __FILE__);
return false;
}


// Don't accept more or less than one response
if ($result['count'] != 1) {
$this->_debug('LDAP search returned '.htmlspecialchars($result['count']).' results while it should return 1!', -1, __LINE__, __FILE__);
//for($i = 0; $i < $result["count"]; $i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having code in comments is not good practice. If it was supposed to not be there, better remove it. If it was supposed to be there for debugging purposes but only when actually debugging, remove the comment and add it only if $this->getConf('debug') or if if($this->getConf('debug')).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. do you want me to remove the code in comment? or you prefer to do it yourself?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove it in an additional commit.

Copy link
Contributor Author

@itsho itsho Mar 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be wrong but seems like someone else already did it.

edit:
I've compared this version with the one in master and it seems that someone indeed already did it.

//$this->_debug('result: '.htmlspecialchars(print_r($result[$i])), 0, __LINE__, __FILE__);
//}
return false;
}


$this->_debug('LDAP search found single result !', 0, __LINE__, __FILE__);

$user_result = $result[0];
ldap_free_result($sr);

Expand Down