/** * @brief Get all groups a user belongs to * @param $uid Name of the user * @returns array with group names * * This function fetches all groups a user belongs to. It does not check * if the user exists at all. */ public function getUserGroups($uid) { if (!$this->configured) { return array(); } if (isset($this->_user_groups[$uid])) { return $this->_user_groups[$uid]; } $userDN = OC_LDAP::username2dn($uid); if (!$userDN) { $this->_user_groups[$uid] = array(); return array(); } //uniqueMember takes DN, memberuid the uid, so we need to distinguish if (strtolower($this->ldapGroupMemberAssocAttr) == 'uniquemember' || strtolower($this->ldapGroupMemberAssocAttr) == 'member') { $uid = $userDN; } else { if (strtolower($this->ldapGroupMemberAssocAttr) == 'memberuid') { $result = OC_LDAP::readAttribute($userDN, 'uid'); $uid = $result[0]; } else { // just in case $uid = $userDN; } } $filter = OC_LDAP::combineFilterWithAnd(array($this->ldapGroupFilter, $this->ldapGroupMemberAssocAttr . '=' . $uid)); $groups = OC_LDAP::fetchListOfGroups($filter, array(OC_LDAP::conf('ldapGroupDisplayName'), 'dn')); $this->_user_groups[$uid] = array_unique(OC_LDAP::ownCloudGroupNames($groups), SORT_LOCALE_STRING); return $this->_user_groups[$uid]; }
/** * @brief check if a user exists * @param string $uid the username * @return boolean */ public function userExists($uid) { //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking. $dn = OC_LDAP::username2dn($uid); if (!$dn) { return false; } //if user really still exists, we will be able to read his cn $cn = OC_LDAP::readAttribute($dn, 'cn'); if (!$cn || empty($cn)) { return false; } return true; }