Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * @brief returns a User object by it's ownCloud username
  * @param string $id the DN or username of the user
  * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\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;
 }