/** * returns the home directory of the user if specified by LDAP settings * @param string $valueFromLDAP * @return bool|string * @throws \Exception */ public function getHomePath($valueFromLDAP = null) { $path = $valueFromLDAP; $attr = null; if (is_null($path) && strpos($this->access->connection->homeFolderNamingRule, 'attr:') === 0 && $this->access->connection->homeFolderNamingRule !== 'attr:') { $attr = substr($this->access->connection->homeFolderNamingRule, strlen('attr:')); $homedir = $this->access->readAttribute($this->access->username2dn($this->getUsername()), $attr); if ($homedir && isset($homedir[0])) { $path = $homedir[0]; } } if (!empty($path)) { //if attribute's value is an absolute path take this, otherwise append it to data dir //check for / at the beginning or pattern c:\ resp. c:/ if ('/' !== $path[0] && !(3 < strlen($path) && ctype_alpha($path[0]) && $path[1] === ':' && ('\\' === $path[2] || '/' === $path[2]))) { $path = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $path; } //we need it to store it in the DB as well in case a user gets //deleted so we can clean up afterwards $this->config->setUserValue($this->getUsername(), 'user_ldap', 'homePath', $path); return $path; } if (!is_null($attr) && $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true)) { // a naming rule attribute is defined, but it doesn't exist for that LDAP user throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername()); } //false will apply default behaviour as defined and done by OC_User $this->config->setUserValue($this->getUsername(), 'user_ldap', 'homePath', ''); return false; }
/** * @brief returns a User object by it's DN or ownCloud username * @param string the DN or username of the user * @return \OCA\user_ldap\lib\User | null */ public function get($id) { $this->checkAccess(); if (isset($this->users['byDN'][$id])) { return $this->users['byDN'][$id]; } else { if (isset($this->users['byUid'][$id])) { return $this->users['byUid'][$id]; } } if (!$this->access->stringResemblesDN($id)) { //most likely a uid $dn = $this->access->username2dn($id); if ($dn !== false) { return $this->createAndCache($dn, $id); } } else { //so it's a DN $uid = $this->access->dn2username($id); if ($uid !== false) { return $this->createAndCache($id, $uid); } } //either funny uid or invalid. Assume funny to be on the safe side. $dn = $this->access->username2dn($id); if ($dn !== false) { return $this->createAndCache($dn, $id); } return null; }
/** * @brief returns a User object by it's DN or ownCloud username * @param string the DN or username of the user * @return \OCA\user_ldap\lib\User | null */ public function get($id) { $this->checkAccess(); if (isset($this->users['byDN'][$id])) { return $this->users['byDN'][$id]; } else { if (isset($this->users['byUid'][$id])) { return $this->users['byUid'][$id]; } } if (strpos(mb_strtolower($id, 'UTF-8'), 'dc=') === false && strpos(mb_strtolower($id, 'UTF-8'), 'uid=') === false) { //most likely a uid $dn = $this->access->username2dn($id); if ($dn !== false) { return $this->createAndCache($dn, $id); } } else { //so it's a DN $uid = $this->access->dn2username($id); if ($uid !== false) { return $this->createAndCache($id, $uid); } } //either funny uid or invalid. Assume funny to be on the safe side. $dn = $this->access->username2dn($id); if ($dn !== false) { return $this->createAndCache($dn, $id); } return null; }
/** * @brief returns a User object by it's ownCloud username * @param string the DN or username of the user * @return \OCA\user_ldap\lib\user\User|\OCA\user_ldap\lib\user\OfflineUser|null */ protected function createInstancyByUserName($id) { //most likely a uid. Check whether it is a deleted user if($this->isDeletedUser($id)) { return $this->getDeletedUser($id); } $dn = $this->access->username2dn($id); if($dn !== false) { return $this->createAndCache($dn, $id); } return null; }
protected function createInstancyByUserName($id) { //most likely a uid. Check whether it is a deleted user if ($this->isDeletedUser($id)) { return $this->getDeletedUser($id); } $dn = $this->access->username2dn($id); if ($dn !== false) { return $this->createAndCache($dn, $id); } throw new \Exception('Could not create User instance'); }