|
|
|
|
@ -303,7 +303,7 @@ class Util {
|
|
|
|
|
* Find all files and their encryption status within a directory
|
|
|
|
|
* @param string $directory The path of the parent directory to search
|
|
|
|
|
* @param bool $found the founded files if called again
|
|
|
|
|
* @return mixed false if 0 found, array on success. Keys: name, path
|
|
|
|
|
* @return array keys: plain, encrypted, legacy, broken
|
|
|
|
|
* @note $directory needs to be a path relative to OC data dir. e.g.
|
|
|
|
|
* /admin/files NOT /backup OR /home/www/oc/data/admin/files
|
|
|
|
|
*/
|
|
|
|
|
@ -322,10 +322,7 @@ class Util {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
$this->view->is_dir($directory)
|
|
|
|
|
&& $handle = $this->view->opendir($directory)
|
|
|
|
|
) {
|
|
|
|
|
if ($this->view->is_dir($directory) && $handle = $this->view->opendir($directory)){
|
|
|
|
|
if (is_resource($handle)) {
|
|
|
|
|
while (false !== ($file = readdir($handle))) {
|
|
|
|
|
|
|
|
|
|
@ -390,34 +387,16 @@ class Util {
|
|
|
|
|
'name' => $file,
|
|
|
|
|
'path' => $relPath
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
\OC_FileProxy::$enabled = true;
|
|
|
|
|
|
|
|
|
|
if (empty($found)) {
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
return $found;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
\OC_FileProxy::$enabled = true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return $found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -571,28 +550,6 @@ class Util {
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $path
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isSharedPath($path) {
|
|
|
|
|
|
|
|
|
|
$trimmed = ltrim($path, '/');
|
|
|
|
|
$split = explode('/', $trimmed);
|
|
|
|
|
|
|
|
|
|
if (isset($split[2]) && $split[2] === 'Shared') {
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* encrypt versions from given file
|
|
|
|
|
* @param array $filelist list of encrypted files, relative to data/user/files
|
|
|
|
|
@ -808,9 +765,9 @@ class Util {
|
|
|
|
|
*/
|
|
|
|
|
public function encryptAll($dirPath, $legacyPassphrase = null, $newPassphrase = null) {
|
|
|
|
|
|
|
|
|
|
$found = $this->findEncFiles($dirPath);
|
|
|
|
|
$result = true;
|
|
|
|
|
|
|
|
|
|
if ($found) {
|
|
|
|
|
$found = $this->findEncFiles($dirPath);
|
|
|
|
|
|
|
|
|
|
// Disable proxy to prevent file being encrypted twice
|
|
|
|
|
\OC_FileProxy::$enabled = false;
|
|
|
|
|
@ -841,7 +798,7 @@ class Util {
|
|
|
|
|
// Open enc file handle for binary writing, with same filename as original plain file
|
|
|
|
|
$encHandle = fopen('crypt://' . $rawPath . '.part', 'wb');
|
|
|
|
|
|
|
|
|
|
if (is_resource($encHandle)) {
|
|
|
|
|
if (is_resource($encHandle) && is_resource($plainHandle)) {
|
|
|
|
|
// Move plain file to a temporary location
|
|
|
|
|
$size = stream_copy_to_stream($plainHandle, $encHandle);
|
|
|
|
|
|
|
|
|
|
@ -869,14 +826,14 @@ class Util {
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$encryptedFiles[] = $relPath;
|
|
|
|
|
} else {
|
|
|
|
|
\OCP\Util::writeLog('files_encryption', 'initial encryption: could not encrypt ' . $rawPath, \OCP\Util::FATAL);
|
|
|
|
|
$result = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Encrypt legacy encrypted files
|
|
|
|
|
if (
|
|
|
|
|
!empty($legacyPassphrase)
|
|
|
|
|
&& !empty($newPassphrase)
|
|
|
|
|
) {
|
|
|
|
|
if (!empty($legacyPassphrase) && !empty($newPassphrase)) {
|
|
|
|
|
|
|
|
|
|
foreach ($found['legacy'] as $legacyFile) {
|
|
|
|
|
|
|
|
|
|
@ -901,6 +858,9 @@ class Util {
|
|
|
|
|
|
|
|
|
|
// close stream
|
|
|
|
|
fclose($encHandle);
|
|
|
|
|
} else {
|
|
|
|
|
\OCP\Util::writeLog('files_encryption', 'initial encryption: could not encrypt legacy file ' . $rawPath, \OCP\Util::FATAL);
|
|
|
|
|
$result = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// disable proxy to prevent file being encrypted twice
|
|
|
|
|
@ -914,15 +874,10 @@ class Util {
|
|
|
|
|
\OC_App::enable('files_versions');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->encryptVersions($encryptedFiles);
|
|
|
|
|
$result = $result && $this->encryptVersions($encryptedFiles);
|
|
|
|
|
|
|
|
|
|
// If files were found, return true
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return $result;
|
|
|
|
|
|
|
|
|
|
// If no files were found, return false
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|