Project

General

Profile

Feature #3410 ยป auth.inc.diff

Daniel Hazelbaker, 01/23/2014 09:29 PM

View differences:

auth.inc 2014-01-23 19:25:30.000000000 -0800
914 914
                $ldapbindpw         = $authcfg['ldap_bindpw'];
915 915
                $ldapauthcont       = $authcfg['ldap_authcn'];
916 916
                $ldapnameattribute  = strtolower($authcfg['ldap_attr_user']);
917
                $ldapgroupattribute  = strtolower($authcfg['ldap_attr_member']);
918
                $ldapfilter         = "({$ldapnameattribute}={$username})";
917
		$ldapgroupattribute = strtolower($authcfg['ldap_attr_group']);
918
                $ldapmemberattribute  = strtolower($authcfg['ldap_attr_member']);
919
                $ldapfilter         = "(|(&(objectClass=inetOrgPerson)({$ldapnameattribute}={$username}))(&(objectClass=posixGroup)({$ldapmemberattribute}={$username})))";
919 920
                $ldaptype           = "";
920 921
                $ldapver            = $authcfg['ldap_protver'];
921 922
		if (empty($ldapbindun) || empty($ldapbindpw))
......
928 929
	} else
929 930
		return false;
930 931

  
931
	$ldapdn             = $_SESSION['ldapdn'];
932
	$ldapdn = $ldapbasedn;
932 933

  
933 934
	/*Convert attribute to lowercase.  php ldap arrays put everything in lowercase */
934
	$ldapgroupattribute = strtolower($ldapgroupattribute);
935 935
	$memberof = array();
936 936

  
937 937
        /* Setup CA environment if needed. */
......
969 969
	/* get groups from DN found */
970 970
	/* use ldap_read instead of search so we don't have to do a bunch of extra work */
971 971
	/* since we know the DN is in $_SESSION['ldapdn'] */
972
	//$search    = ldap_read($ldap, $ldapdn, "(objectclass=*)", array($ldapgroupattribute));
972
	//$search    = ldap_read($ldap, $ldapdn, "(objectclass=*)", array($ldapmemberattribute));
973 973
	if ($ldapscope == "one")
974 974
                $ldapfunc = "ldap_list";
975 975
        else
976 976
                $ldapfunc = "ldap_search";
977 977

  
978
	$search    = @$ldapfunc($ldap, $ldapdn, $ldapfilter, array($ldapgroupattribute));
978
	$search    = @$ldapfunc($ldap, $ldapdn, $ldapfilter, array($ldapmemberattribute, $ldapgroupattribute, 'objectClass'));
979 979
	$info      = @ldap_get_entries($ldap, $search);
980 980

  
981 981
	$countem = $info["count"];	
982
	
983
	if(is_array($info[0][$ldapgroupattribute])) {
984
		/* Iterate through the groups and throw them into an array */
985
		foreach ($info[0][$ldapgroupattribute] as $member) {
986
			if (stristr($member, "CN=") !== false) {
987
				$membersplit = explode(",", $member);
988
				$memberof[] = preg_replace("/CN=/i", "", $membersplit[0]);
982

  
983
	for ($g = 0; $g < $countem; $g++) {
984
		if(is_array($info[$g][$ldapmemberattribute]) && in_array('inetOrgPerson', $info[$g]['objectclass'])) {
985
			/* Iterate through the groups and throw them into an array */
986
			foreach ($info[$g][$ldapmemberattribute] as $member) {
987
				if (stristr($member, "CN=") !== false) {
988
					$membersplit = explode(",", $member);
989
					$memberof[] = preg_replace("/CN=/i", "", $membersplit[0]);
990
				}
989 991
			}
990 992
		}
993

  
994
		if(is_array($info[$g][$ldapgroupattribute]) && $info[$g][$ldapgroupattribute]['count'] > 0 && in_array('posixGroup', $info[$g]['objectclass'])) {
995
			$memberof[] = $info[$g][$ldapgroupattribute][0];
996
		}
991 997
	}
992 998
	
993 999
	/* Time to close LDAP connection */
    (1-1/1)