]> source.dussan.org Git - nextcloud-server.git/commitdiff
only trigger hooks for the default filesystem view
authorRobin Appelman <icewind@owncloud.com>
Sun, 5 Feb 2012 20:49:22 +0000 (21:49 +0100)
committerRobin Appelman <icewind@owncloud.com>
Tue, 21 Feb 2012 19:48:48 +0000 (20:48 +0100)
apps/files_encryption/lib/crypt.php
lib/filesystemview.php
lib/user.php

index 4e7739b1d06e954f870295a7abf1e3046d12a467..0a593b98c4b366cf7e7442814296e70e8ef43ef4 100644 (file)
@@ -44,19 +44,20 @@ class OC_Crypt {
        }
 
        public static function init($login,$password) {
-               if(OC_User::isLoggedIn()){
-                       $view=new OC_FilesystemView('/'.$login);
-                       if(!$view->file_exists('/encryption.key')){// does key exist?
-                               OC_Crypt::createkey($password);
-                       }
-                       $key=$view->file_get_contents('/encryption.key');
-                       $_SESSION['enckey']=OC_Crypt::decrypt($key, $password);
+               $view=new OC_FilesystemView('/'.$login);
+               OC_FileProxy::$enabled=false;
+               if(!$view->file_exists('/encryption.key')){// does key exist?
+                       OC_Crypt::createkey($login,$password);
                }
+               $key=$view->file_get_contents('/encryption.key');
+               OC_FileProxy::$enabled=true;
+               $_SESSION['enckey']=OC_Crypt::decrypt($key, $password);
        }
 
        /**
         * get the blowfish encryption handeler for a key
         * @param string $key (optional)
+        * @return Crypt_Blowfish
         *
         * if the key is left out, the default handeler will be used
         */
@@ -74,21 +75,19 @@ class OC_Crypt {
                }
        }
 
-       public static function createkey($passcode) {
-               if(OC_User::isLoggedIn()){
-                       // generate a random key
-                       $key=mt_rand(10000,99999).mt_rand(10000,99999).mt_rand(10000,99999).mt_rand(10000,99999);
+       public static function createkey($username,$passcode) {
+               // generate a random key
+               $key=mt_rand(10000,99999).mt_rand(10000,99999).mt_rand(10000,99999).mt_rand(10000,99999);
 
-                       // encrypt the key with the passcode of the user
-                       $enckey=OC_Crypt::encrypt($key,$passcode);
+               // encrypt the key with the passcode of the user
+               $enckey=OC_Crypt::encrypt($key,$passcode);
 
-                       // Write the file
-                       $username=OC_USER::getUser();
-                       OC_FileProxy::$enabled=false;
-                       $view=new OC_FilesystemView('/'.$username);
-                       $view->file_put_contents('/encryption.key',$enckey);
-                       OC_FileProxy::$enabled=true;
-               }
+               // Write the file
+               $proxyEnabled=OC_FileProxy::$enabled;
+               OC_FileProxy::$enabled=false;
+               $view=new OC_FilesystemView('/'.$username);
+               $view->file_put_contents('/encryption.key',$enckey);
+               OC_FileProxy::$enabled=$proxyEnabled;
        }
 
        public static function changekeypasscode($oldPassword, $newPassword) {
@@ -133,7 +132,7 @@ class OC_Crypt {
        */
        public static function decrypt( $content, $key='') {
                $bf = self::getBlowfish($key);
-               return($bf->encrypt($contents));
+               return($bf->decrypt($content));
        }
 
        /**
index a7003e84f19e57d2a4779fd385f70cd482e5b95a..0ce803be2b1a5bce6863a54112a689af288de306 100644 (file)
@@ -303,11 +303,13 @@ class OC_FilesystemView {
                if(OC_FileProxy::runPreProxies($operation,$path, $extraParam) and OC_Filesystem::isValidPath($path) and $storage=$this->getStorage($path)){
                        $interalPath=$this->getInternalPath($path);
                        $run=true;
-                       foreach($hooks as $hook){
-                               if($hook!='read'){
-                                       OC_Hook::emit( OC_Filesystem::CLASSNAME, $hook, array( OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
-                               }else{
-                                       OC_Hook::emit( OC_Filesystem::CLASSNAME, $hook, array( OC_Filesystem::signal_param_path => $path));
+                       if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()){
+                               foreach($hooks as $hook){
+                                       if($hook!='read'){
+                                               OC_Hook::emit( OC_Filesystem::CLASSNAME, $hook, array( OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
+                                       }else{
+                                               OC_Hook::emit( OC_Filesystem::CLASSNAME, $hook, array( OC_Filesystem::signal_param_path => $path));
+                                       }
                                }
                        }
                        if($run){
@@ -317,10 +319,12 @@ class OC_FilesystemView {
                                        $result=$storage->$operation($interalPath);
                                }
                                $result=OC_FileProxy::runPostProxies($operation,$path,$result);
-                               if($operation!='fopen'){//no post hooks for fopen, the file stream is still open
-                                       foreach($hooks as $hook){
-                                               if($hook!='read'){
-                                                       OC_Hook::emit( OC_Filesystem::CLASSNAME, 'post_'.$hook, array( OC_Filesystem::signal_param_path => $path));
+                               if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()){
+                                       if($operation!='fopen'){//no post hooks for fopen, the file stream is still open
+                                               foreach($hooks as $hook){
+                                                       if($hook!='read'){
+                                                               OC_Hook::emit( OC_Filesystem::CLASSNAME, 'post_'.$hook, array( OC_Filesystem::signal_param_path => $path));
+                                                       }
                                                }
                                        }
                                }
index aa828de52f5a84bdd401ef85808b8c42d1bc022f..826215b2289ccf0efb926f1b3ad07cf692ee932b 100644 (file)
@@ -195,8 +195,9 @@ class OC_User {
                if( $run ){
                        $uid=self::checkPassword( $uid, $password );
                        if($uid){
-                               return self::setUserId($uid);
+                               self::setUserId($uid);
                                OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>$password ));
+                               return true;
                        }
                }
                return false;