diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 4 | ||||
-rw-r--r-- | lib/private/files/view.php | 13 | ||||
-rw-r--r-- | lib/private/server.php | 3 | ||||
-rw-r--r-- | lib/private/user.php | 2 | ||||
-rw-r--r-- | lib/private/user/backend.php | 17 | ||||
-rw-r--r-- | lib/private/user/database.php | 15 | ||||
-rw-r--r-- | lib/private/user/dummy.php | 9 | ||||
-rw-r--r-- | lib/private/user/manager.php | 22 | ||||
-rw-r--r-- | lib/private/user/session.php | 14 |
9 files changed, 82 insertions, 17 deletions
diff --git a/lib/base.php b/lib/base.php index a8e9e901847..f30575c7b12 100644 --- a/lib/base.php +++ b/lib/base.php @@ -544,12 +544,12 @@ class OC { OC_User::useBackend(new OC_User_Database()); OC_Group::useBackend(new OC_Group_Database()); - if (isset($_SERVER['PHP_AUTH_USER']) && self::$session->exists('user_id') + if (isset($_SERVER['PHP_AUTH_USER']) && self::$session->exists('loginname') && $_SERVER['PHP_AUTH_USER'] !== self::$session->get('loginname')) { $sessionUser = self::$session->get('loginname'); $serverUser = $_SERVER['PHP_AUTH_USER']; OC_Log::write('core', - "Session user-id ($sessionUser) doesn't match SERVER[PHP_AUTH_USER] ($serverUser).", + "Session loginname ($sessionUser) doesn't match SERVER[PHP_AUTH_USER] ($serverUser).", OC_Log::WARN); OC_User::logout(); } diff --git a/lib/private/files/view.php b/lib/private/files/view.php index ac45a881331..8893911ed5d 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -336,6 +336,19 @@ class View { } public function unlink($path) { + if ($path === '' || $path === '/') { + // do not allow deleting the root + return false; + } + $postFix = (substr($path, -1, 1) === '/') ? '/' : ''; + $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); + list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix); + if (!$internalPath || $internalPath === '' || $internalPath === '/') { + // do not allow deleting the storage's root / the mount point + // because for some storages it might delete the whole contents + // but isn't supposed to work that way + return false; + } return $this->basicOperation('unlink', $path, array('delete')); } diff --git a/lib/private/server.php b/lib/private/server.php index 5977ee9b5a0..2cbd37a97d7 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -128,7 +128,8 @@ class Server extends SimpleContainer implements IServerContainer { return new \OC\L10N\Factory(); }); $this->registerService('URLGenerator', function($c) { - $config = $this->getConfig(); + /** @var $c SimpleContainer */ + $config = $c->query('AllConfig'); return new \OC\URLGenerator($config); }); $this->registerService('AppHelper', function($c) { diff --git a/lib/private/user.php b/lib/private/user.php index e0d6b9f3f51..98ebebbe5c1 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -246,6 +246,8 @@ class OC_User { session_regenerate_id(true); self::setUserId($uid); self::setDisplayName($uid); + self::getUserSession()->setLoginName($uid); + OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>'' )); return true; } diff --git a/lib/private/user/backend.php b/lib/private/user/backend.php index 02c93d13bdf..f4e5618e04a 100644 --- a/lib/private/user/backend.php +++ b/lib/private/user/backend.php @@ -31,13 +31,15 @@ define('OC_USER_BACKEND_NOT_IMPLEMENTED', -501); /** * actions that user backends can define */ -define('OC_USER_BACKEND_CREATE_USER', 0x0000001); -define('OC_USER_BACKEND_SET_PASSWORD', 0x0000010); -define('OC_USER_BACKEND_CHECK_PASSWORD', 0x0000100); -define('OC_USER_BACKEND_GET_HOME', 0x0001000); -define('OC_USER_BACKEND_GET_DISPLAYNAME', 0x0010000); -define('OC_USER_BACKEND_SET_DISPLAYNAME', 0x0100000); -define('OC_USER_BACKEND_PROVIDE_AVATAR', 0x1000000); +define('OC_USER_BACKEND_CREATE_USER', 0x00000001); +define('OC_USER_BACKEND_SET_PASSWORD', 0x00000010); +define('OC_USER_BACKEND_CHECK_PASSWORD', 0x00000100); +define('OC_USER_BACKEND_GET_HOME', 0x00001000); +define('OC_USER_BACKEND_GET_DISPLAYNAME', 0x00010000); +define('OC_USER_BACKEND_SET_DISPLAYNAME', 0x00100000); +define('OC_USER_BACKEND_PROVIDE_AVATAR', 0x01000000); +define('OC_USER_BACKEND_COUNT_USERS', 0x10000000); +//more actions cannot be defined without breaking 32bit platforms! /** * Abstract base class for user management. Provides methods for querying backend @@ -55,6 +57,7 @@ abstract class OC_User_Backend implements OC_User_Interface { OC_USER_BACKEND_GET_DISPLAYNAME => 'getDisplayName', OC_USER_BACKEND_SET_DISPLAYNAME => 'setDisplayName', OC_USER_BACKEND_PROVIDE_AVATAR => 'canChangeAvatar', + OC_USER_BACKEND_COUNT_USERS => 'countUsers', ); /** diff --git a/lib/private/user/database.php b/lib/private/user/database.php index c99db3b27ca..1a63755b980 100644 --- a/lib/private/user/database.php +++ b/lib/private/user/database.php @@ -253,4 +253,19 @@ class OC_User_Database extends OC_User_Backend { return true; } + /** + * counts the users in the database + * + * @return int | bool + */ + public function countUsers() { + $query = OC_DB::prepare('SELECT COUNT(*) FROM `*PREFIX*users`'); + $result = $query->execute(); + if (OC_DB::isError($result)) { + OC_Log::write('core', OC_DB::getErrorMessage($result), OC_Log::ERROR); + return false; + } + return $result->fetchOne(); + } + } diff --git a/lib/private/user/dummy.php b/lib/private/user/dummy.php index 52be7edfa75..fc15a630cf3 100644 --- a/lib/private/user/dummy.php +++ b/lib/private/user/dummy.php @@ -123,4 +123,13 @@ class OC_User_Dummy extends OC_User_Backend { public function hasUserListings() { return true; } + + /** + * counts the users in the database + * + * @return int | bool + */ + public function countUsers() { + return 0; + } } diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php index cf83a75ba25..90970ef9963 100644 --- a/lib/private/user/manager.php +++ b/lib/private/user/manager.php @@ -270,4 +270,26 @@ class Manager extends PublicEmitter { } return false; } + + /** + * returns how many users per backend exist (if supported by backend) + * + * @return array with backend class as key and count number as value + */ + public function countUsers() { + $userCountStatistics = array(); + foreach ($this->backends as $backend) { + if ($backend->implementsActions(\OC_USER_BACKEND_COUNT_USERS)) { + $backendusers = $backend->countUsers(); + if($backendusers !== false) { + if(isset($userCountStatistics[get_class($backend)])) { + $userCountStatistics[get_class($backend)] += $backendusers; + } else { + $userCountStatistics[get_class($backend)] = $backendusers; + } + } + } + } + return $userCountStatistics; + } } diff --git a/lib/private/user/session.php b/lib/private/user/session.php index c2885d00413..1e299416fb3 100644 --- a/lib/private/user/session.php +++ b/lib/private/user/session.php @@ -115,13 +115,13 @@ class Session implements Emitter, \OCP\IUserSession { /** * set the login name * - * @param string login name for the logged in user + * @param string $loginName for the logged in user */ - public function setLoginname($loginname) { - if (is_null($loginname)) { + public function setLoginName($loginName) { + if (is_null($loginName)) { $this->session->remove('loginname'); } else { - $this->session->set('loginname', $loginname); + $this->session->set('loginname', $loginName); } } @@ -130,7 +130,7 @@ class Session implements Emitter, \OCP\IUserSession { * * @return string */ - public function getLoginname() { + public function getLoginName() { if ($this->activeUser) { return $this->session->get('loginname'); } else { @@ -158,7 +158,7 @@ class Session implements Emitter, \OCP\IUserSession { if (!is_null($user)) { if ($user->isEnabled()) { $this->setUser($user); - $this->setLoginname($uid); + $this->setLoginName($uid); $this->manager->emit('\OC\User', 'postLogin', array($user, $password)); return true; } else { @@ -176,7 +176,7 @@ class Session implements Emitter, \OCP\IUserSession { public function logout() { $this->manager->emit('\OC\User', 'logout'); $this->setUser(null); - $this->setLoginname(null); + $this->setLoginName(null); $this->unsetMagicInCookie(); } |