Skip to content

Commit

Permalink
LDAP changes to for AD flexibility (#227)
Browse files Browse the repository at this point in the history
* custom filter for Active Directory support
* added custom port number support

* Removed the redundant line
  • Loading branch information
docwyatt2001 authored and ikkez committed Oct 23, 2017
1 parent f93eb49 commit b2e66eb
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,30 @@ protected function _sql($id,$pw,$realm) {
* @param $pw string
**/
protected function _ldap($id,$pw) {
$dc=@ldap_connect($this->args['dc']);
if ($dc &&
ldap_set_option($dc,LDAP_OPT_PROTOCOL_VERSION,3) &&
ldap_set_option($dc,LDAP_OPT_REFERRALS,0) &&
ldap_bind($dc,$this->args['rdn'],$this->args['pw']) &&
($result=ldap_search($dc,$this->args['base_dn'],
$this->args['uid'].'='.$id)) &&
ldap_count_entries($dc,$result) &&
($info=ldap_get_entries($dc,$result)) &&
@ldap_bind($dc,$info[0]['dn'],$pw) &&
@ldap_close($dc)) {
return $info[0][$this->args['uid']][0]==$id;
}
user_error(self::E_LDAP,E_USER_ERROR);
$port=intval($this->args['port']?:389)
$filter=$this->args['filter']=$this->args['filter']?:"uid=".$id;
$this->args['attr']=$this->args['attr']?:["uid"];
array_walk($this->args['attr'],
function($attr)use(&$filter,$id) {
$filter=str_ireplace($attr."=*",$attr."=".$id,$filter);});
$dc=@ldap_connect($this->args['dc'],$port);
if ($dc &&
ldap_set_option($dc,LDAP_OPT_PROTOCOL_VERSION,3) &&
ldap_set_option($dc,LDAP_OPT_REFERRALS,0) &&
ldap_bind($dc,$this->args['rdn'],$this->args['pw']) &&
($result=ldap_search($dc,$this->args['base_dn'],
$filter,$this->args['attr'])) &&
ldap_count_entries($dc,$result) &&
($info=ldap_get_entries($dc,$result)) &&
$info['count']==1 &&
@ldap_bind($dc,$info[0]['dn'],$pw) &&
@ldap_close($dc)) {
return in_array($id,(array_map(function($value){
return $value[0];},
array_intersect_key($info[0],
array_flip($this->args['attr'])))),TRUE);
}
user_error(self::E_LDAP,E_USER_ERROR);
}

/**
Expand Down

0 comments on commit b2e66eb

Please sign in to comment.