diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 1 | ||||
-rw-r--r-- | lib/private/connector/sabre/auth.php | 16 | ||||
-rw-r--r-- | lib/private/mimetypes.list.php | 1 | ||||
-rw-r--r-- | lib/private/response.php | 4 | ||||
-rw-r--r-- | lib/private/session/internal.php | 14 | ||||
-rw-r--r-- | lib/private/session/memory.php | 20 | ||||
-rw-r--r-- | lib/private/session/session.php | 12 | ||||
-rw-r--r-- | lib/private/setup.php | 4 | ||||
-rw-r--r-- | lib/private/updater.php | 5 | ||||
-rwxr-xr-x | lib/private/util.php | 32 | ||||
-rw-r--r-- | lib/public/isession.php | 5 | ||||
-rw-r--r-- | lib/public/util.php | 7 |
12 files changed, 109 insertions, 12 deletions
diff --git a/lib/base.php b/lib/base.php index 73553ff6417..cc710fc7207 100644 --- a/lib/base.php +++ b/lib/base.php @@ -518,6 +518,7 @@ class OC { echo $error['hint'] . "\n\n"; } } else { + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); OC_Template::printGuestPage('', 'error', array('errors' => $errors)); } exit; diff --git a/lib/private/connector/sabre/auth.php b/lib/private/connector/sabre/auth.php index 0c84fa6b757..5577273df8c 100644 --- a/lib/private/connector/sabre/auth.php +++ b/lib/private/connector/sabre/auth.php @@ -73,6 +73,20 @@ class OC_Connector_Sabre_Auth extends Sabre_DAV_Auth_Backend_AbstractBasic { */ public function authenticate(Sabre_DAV_Server $server, $realm) { + $result = $this->auth($server, $realm); + + // close the session - right after authentication there is not need to write to the session any more + \OC::$session->close(); + + return $result; + } + + /** + * @param Sabre_DAV_Server $server + * @param $realm + * @return bool + */ + private function auth(Sabre_DAV_Server $server, $realm) { if (OC_User::handleApacheAuth() || OC_User::isLoggedIn()) { $user = OC_User::getUser(); OC_Util::setupFS($user); @@ -81,5 +95,5 @@ class OC_Connector_Sabre_Auth extends Sabre_DAV_Auth_Backend_AbstractBasic { } return parent::authenticate($server, $realm); - } + } } diff --git a/lib/private/mimetypes.list.php b/lib/private/mimetypes.list.php index a216414c9dd..91bcf584267 100644 --- a/lib/private/mimetypes.list.php +++ b/lib/private/mimetypes.list.php @@ -77,6 +77,7 @@ return array( 'md' => 'text/markdown', 'mdb' => 'application/msaccess', 'mdwn' => 'text/markdown', + 'mkv' => 'video/x-matroska', 'mobi' => 'application/x-mobipocket-ebook', 'mov' => 'video/quicktime', 'mp3' => 'audio/mpeg', diff --git a/lib/private/response.php b/lib/private/response.php index 71c538fb311..983c682bf3f 100644 --- a/lib/private/response.php +++ b/lib/private/response.php @@ -12,6 +12,7 @@ class OC_Response { const STATUS_TEMPORARY_REDIRECT = 307; const STATUS_NOT_FOUND = 404; const STATUS_INTERNAL_SERVER_ERROR = 500; + const STATUS_SERVICE_UNAVAILABLE = 503; /** * @brief Enable response caching by sending correct HTTP headers @@ -74,6 +75,9 @@ class OC_Response { case self::STATUS_INTERNAL_SERVER_ERROR; $status = $status . ' Internal Server Error'; break; + case self::STATUS_SERVICE_UNAVAILABLE; + $status = $status . ' Service Unavailable'; + break; } header($protocol.' '.$status); } diff --git a/lib/private/session/internal.php b/lib/private/session/internal.php index a7c9e2fdefd..42ec9606dc9 100644 --- a/lib/private/session/internal.php +++ b/lib/private/session/internal.php @@ -26,8 +26,7 @@ class Internal extends Memory { } public function __destruct() { - $_SESSION = array_merge($_SESSION, $this->data); - session_write_close(); + $this->close(); } /** @@ -47,4 +46,15 @@ class Internal extends Memory { @session_start(); $this->data = $_SESSION = array(); } + + public function close() { + $_SESSION = array_merge($_SESSION, $this->data); + session_write_close(); + + parent::close(); + } + + public function reopen() { + throw new \Exception('The session cannot be reopened - reopen() is ony to be used in unit testing.'); + } } diff --git a/lib/private/session/memory.php b/lib/private/session/memory.php index 1b9ac452575..1497c0f8928 100644 --- a/lib/private/session/memory.php +++ b/lib/private/session/memory.php @@ -28,6 +28,7 @@ class Memory extends Session { * @param integer $value */ public function set($key, $value) { + $this->validateSession(); $this->data[$key] = $value; } @@ -54,10 +55,29 @@ class Memory extends Session { * @param string $key */ public function remove($key) { + $this->validateSession(); unset($this->data[$key]); } public function clear() { $this->data = array(); } + + /** + * Helper function for PHPUnit execution - don't use in non-test code + */ + public function reopen() { + $this->sessionClosed = false; + } + + /** + * In case the session has already been locked an exception will be thrown + * + * @throws \Exception + */ + private function validateSession() { + if ($this->sessionClosed) { + throw new \Exception('Session has been closed - no further changes to the session as allowed'); + } + } } diff --git a/lib/private/session/session.php b/lib/private/session/session.php index fe160faa267..6f6c804f384 100644 --- a/lib/private/session/session.php +++ b/lib/private/session/session.php @@ -13,6 +13,11 @@ use OCP\ISession; abstract class Session implements \ArrayAccess, ISession { /** + * @var bool + */ + protected $sessionClosed = false; + + /** * $name serves as a namespace for the session keys * * @param string $name @@ -49,4 +54,11 @@ abstract class Session implements \ArrayAccess, ISession { public function offsetUnset($offset) { $this->remove($offset); } + + /** + * Close the session and release the lock + */ + public function close() { + $this->sessionClosed = true; + } } diff --git a/lib/private/setup.php b/lib/private/setup.php index 0d5bf424b33..b1061b3a25b 100644 --- a/lib/private/setup.php +++ b/lib/private/setup.php @@ -106,6 +106,10 @@ class OC_Setup { //guess what this does OC_Installer::installShippedApps(); + // create empty file in data dir, so we can later find + // out that this is indeed an ownCloud data directory + file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/.ocdata', ''); + //create htaccess files for apache hosts if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { self::createHtaccess(); diff --git a/lib/private/updater.php b/lib/private/updater.php index 1354f3fd2f8..18864c17ec9 100644 --- a/lib/private/updater.php +++ b/lib/private/updater.php @@ -102,6 +102,11 @@ class Updater extends BasicEmitter { } $this->emit('\OC\Updater', 'maintenanceStart'); + // create empty file in data dir, so we can later find + // out that this is indeed an ownCloud data directory + // (in case it didn't exist before) + file_put_contents(\OC_Config::getValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', ''); + /* * START CONFIG CHANGES FOR OLDER VERSIONS */ diff --git a/lib/private/util.php b/lib/private/util.php index fc78566e456..70dadb1befd 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -290,13 +290,19 @@ class OC_Util { * @return array arrays with error messages and hints */ public static function checkServer() { + $errors = array(); + $CONFIG_DATADIRECTORY = OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data'); + + if (!\OC::needUpgrade() && OC_Config::getValue('installed', false)) { + // this check needs to be done every time + $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); + } + // Assume that if checkServer() succeeded before in this session, then all is fine. if(\OC::$session->exists('checkServer_suceeded') && \OC::$session->get('checkServer_suceeded')) { - return array(); + return $errors; } - $errors = array(); - $defaults = new \OC_Defaults(); $webServerRestart = false; @@ -341,7 +347,6 @@ class OC_Util { ); } } - $CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); // Create root dir. if(!is_dir($CONFIG_DATADIRECTORY)) { $success=@mkdir($CONFIG_DATADIRECTORY); @@ -541,6 +546,25 @@ class OC_Util { } /** + * Check that the data directory exists and is valid by + * checking the existence of the ".ocdata" file. + * + * @param string $dataDirectory data directory path + * @return bool true if the data directory is valid, false otherwise + */ + public static function checkDataDirectoryValidity($dataDirectory) { + $errors = array(); + if (!file_exists($dataDirectory.'/.ocdata')) { + $errors[] = array( + 'error' => 'Data directory (' . $dataDirectory . ') is invalid', + 'hint' => 'Please check that the data directory contains a file' . + ' ".ocdata" in its root.' + ); + } + return $errors; + } + + /** * @return void */ public static function displayLoginPage($errors = array()) { diff --git a/lib/public/isession.php b/lib/public/isession.php index 20da712cda3..dc5719625cc 100644 --- a/lib/public/isession.php +++ b/lib/public/isession.php @@ -75,4 +75,9 @@ interface ISession { */ public function clear(); + /** + * Close the session and release the lock + */ + public function close(); + } diff --git a/lib/public/util.php b/lib/public/util.php index 585c5d22634..a159bf1423c 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -89,14 +89,11 @@ class Util { */ public static function logException( $app, \Exception $ex ) { $class = get_class($ex); - if ($class !== 'Exception') { - $message = $class . ': '; - } - $message .= $ex->getMessage(); + $message = $class . ': ' . $ex->getMessage(); if ($ex->getCode()) { $message .= ' [' . $ex->getCode() . ']'; } - \OCP\Util::writeLog($app, 'Exception: ' . $message, \OCP\Util::FATAL); + \OCP\Util::writeLog($app, $message, \OCP\Util::FATAL); if (defined('DEBUG') and DEBUG) { // also log stack trace $stack = explode("\n", $ex->getTraceAsString()); |