private function updateEmail($dn) { $email = null; if (!empty($this->ldapEmailAttribute)) { $aEmail = OC_LDAP::readAttribute($dn, $this->ldapEmailAttribute); if ($aEmail && count($aEmail) > 0) { $email = $aEmail[0]; } if (!is_null($email)) { OCP\Config::setUserValue(OC_LDAP::dn2username($dn), 'settings', 'email', $email); } } }
/** * check if a group exists * @param string $gid * @return bool */ public function groupExists($gid) { //getting dn, if false the group does not exist. If dn, it may be mapped only, requires more checking. $dn = OC_LDAP::groupname2dn($gid); if (!$dn) { return false; } //if user really still exists, we will be able to read his cn $exists = OC_LDAP::readAttribute($dn, 'objectclass'); if (!$exists || empty($exists)) { return false; } return true; }
/** * @brief get a list of all users in a group * @returns array with user ids */ public function usersInGroup($gid) { if (!$this->configured) { return array(); } if (isset($this->_group_users[$gid])) { return $this->_group_users[$gid]; } $groupDN = OC_LDAP::groupname2dn($gid); if (!$groupDN) { $this->_group_users[$gid] = array(); return array(); } $members = OC_LDAP::readAttribute($groupDN, $this->ldapGroupMemberAssocAttr); if (!$members) { $this->_group_users[$gid] = array(); return array(); } $result = array(); $isMemberUid = strtolower($this->ldapGroupMemberAssocAttr) == 'memberuid'; foreach ($members as $member) { if ($isMemberUid) { $filter = str_replace('%uid', $member, OC_LDAP::conf('ldapLoginFilter')); $ldap_users = OC_LDAP::fetchListOfUsers($filter, 'dn'); if (count($ldap_users) < 1) { continue; } $result[] = OC_LDAP::dn2username($ldap_users[0]); continue; } else { $result[] = OC_LDAP::dn2username($member); } } if (!$isMemberUid) { $result = array_intersect($result, OCP\User::getUsers()); } $this->_group_users[$gid] = array_unique($result, SORT_LOCALE_STRING); return $this->_group_users[$gid]; }
/** * @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; }