示例#1
0
 /**
  * @brief delete all share keys of a given file
  * @param \OC_FilesystemView $view
  * @param string $userId owner of the file
  * @param string $filePath path to the file, relative to the owners file dir
  */
 public static function delAllShareKeys(\OC_FilesystemView $view, $userId, $filePath)
 {
     $util = new util($view, $userId);
     if ($util->isSystemWideMountPoint($filePath)) {
         $baseDir = '/files_encryption/share-keys/';
     } else {
         $baseDir = $userId . '/files_encryption/share-keys/';
     }
     if ($view->is_dir($userId . '/files/' . $filePath)) {
         $view->unlink($baseDir . $filePath);
     } else {
         $localKeyPath = $view->getLocalFile($baseDir . $filePath);
         $escapedPath = Helper::escapeGlobPattern($localKeyPath);
         $matches = glob($escapedPath . '*.shareKey');
         foreach ($matches as $ma) {
             $result = unlink($ma);
             if (!$result) {
                 \OCP\Util::writeLog('Encryption library', 'Keyfile or shareKey could not be deleted for file "' . $filePath . '"', \OCP\Util::ERROR);
             }
         }
     }
 }
示例#2
0
 /**
  * delete all share keys of a given file
  * @param \OC\Files\View $view
  * @param string $userId owner of the file
  * @param string $filePath path to the file, relative to the owners file dir
  */
 public static function delAllShareKeys($view, $userId, $filePath)
 {
     $filePath = ltrim($filePath, '/');
     if ($view->file_exists('/' . $userId . '/files/' . $filePath)) {
         \OCP\Util::writeLog('Encryption library', 'File still exists, stop deleting share keys!', \OCP\Util::ERROR);
         return false;
     }
     if ($filePath === '') {
         \OCP\Util::writeLog('Encryption library', 'Can\'t delete share-keys empty path given!', \OCP\Util::ERROR);
         return false;
     }
     $util = new util($view, $userId);
     if ($util->isSystemWideMountPoint($filePath)) {
         $baseDir = '/files_encryption/share-keys/';
     } else {
         $baseDir = $userId . '/files_encryption/share-keys/';
     }
     $result = true;
     if ($view->is_dir($baseDir . $filePath)) {
         \OCP\Util::writeLog('files_encryption', 'delAllShareKeys: delete share keys: ' . $baseDir . $filePath, \OCP\Util::DEBUG);
         $result = $view->unlink($baseDir . $filePath);
     } else {
         $parentDir = dirname($baseDir . $filePath);
         $filename = pathinfo($filePath, PATHINFO_BASENAME);
         foreach ($view->getDirectoryContent($parentDir) as $content) {
             $path = $content['path'];
             if (self::getFilenameFromShareKey($content['name']) === $filename) {
                 \OCP\Util::writeLog('files_encryption', 'dellAllShareKeys: delete share keys: ' . '/' . $userId . '/' . $path, \OCP\Util::DEBUG);
                 $result &= $view->unlink('/' . $userId . '/' . $path);
             }
         }
     }
     return (bool) $result;
 }
示例#3
0
 /**
  * @brief delete all share keys of a given file
  * @param \OC_FilesystemView $view
  * @param string $userId owner of the file
  * @param string $filePath path to the file, relative to the owners file dir
  */
 public static function delAllShareKeys($view, $userId, $filePath)
 {
     $filePath = ltrim($filePath, '/');
     if ($view->file_exists('/' . $userId . '/files/' . $filePath)) {
         \OCP\Util::writeLog('Encryption library', 'File still exists, stop deleting share keys!', \OCP\Util::ERROR);
         return false;
     }
     if ($filePath === '') {
         \OCP\Util::writeLog('Encryption library', 'Can\'t delete share-keys empty path given!', \OCP\Util::ERROR);
         return false;
     }
     $util = new util($view, $userId);
     if ($util->isSystemWideMountPoint($filePath)) {
         $baseDir = '/files_encryption/share-keys/';
     } else {
         $baseDir = $userId . '/files_encryption/share-keys/';
     }
     $result = true;
     if ($view->is_dir($baseDir . $filePath)) {
         \OCP\Util::writeLog('files_encryption', 'delAllShareKeys: delete share keys: ' . $baseDir . $filePath, \OCP\Util::DEBUG);
         $result = $view->unlink($baseDir . $filePath);
     } else {
         $sharingEnabled = \OCP\Share::isEnabled();
         $users = $util->getSharingUsersArray($sharingEnabled, $filePath);
         foreach ($users as $user) {
             $keyName = $baseDir . $filePath . '.' . $user . '.shareKey';
             if ($view->file_exists($keyName)) {
                 \OCP\Util::writeLog('files_encryption', 'dellAllShareKeys: delete share keys: "' . $keyName . '"', \OCP\Util::DEBUG);
                 $result &= $view->unlink($keyName);
             }
         }
     }
     return (bool) $result;
 }