Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enc] remember original fopen access type in pre-proxy #7454

Merged
merged 1 commit into from
Feb 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions apps/files_encryption/lib/proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Proxy extends \OC_FileProxy {

private static $blackList = null; //mimetypes blacklisted from encryption
private static $unencryptedSizes = array(); // remember unencrypted size
private static $fopenMode = array(); // remember the fopen mode

/**
* Check if a file requires encryption
Expand Down Expand Up @@ -213,6 +214,16 @@ public function postTouch($path) {
return true;
}

/**
* @brief remember initial fopen mode because sometimes it gets changed during the request
* @param string $path path
* @param string $mode type of access
*/
public function preFopen($path, $mode) {
self::$fopenMode[$path] = $mode;
}


/**
* @param $path
* @param $result
Expand Down Expand Up @@ -240,7 +251,15 @@ public function postFopen($path, &$result) {
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;

$meta = stream_get_meta_data($result);
// if we remember the mode from the pre proxy we re-use it
// oterwise we fall back to stream_get_meta_data()
if (isset(self::$fopenMode[$path])) {
$mode = self::$fopenMode[$path];
unset(self::$fopenMode[$path]);
} else {
$meta = stream_get_meta_data($result);
$mode = $meta['mode'];
}

$view = new \OC_FilesystemView('');

Expand All @@ -258,14 +277,15 @@ public function postFopen($path, &$result) {

// Open the file using the crypto stream wrapper
// protocol and let it do the decryption work instead
$result = fopen('crypt://' . $path, $meta['mode']);
$result = fopen('crypt://' . $path, $mode);

} elseif (
self::shouldEncrypt($path)
and $meta['mode'] !== 'r'
and $meta['mode'] !== 'rb'
self::shouldEncrypt($path)
and $mode !== 'r'
and $mode !== 'rb'

) {
$result = fopen('crypt://' . $path, $meta['mode']);
$result = fopen('crypt://' . $path, $mode);
}

// Re-enable the proxy
Expand Down
3 changes: 3 additions & 0 deletions apps/files_encryption/lib/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ public function stream_open($path, $mode, $options, &$opened_path) {
} else {

$this->meta = stream_get_meta_data($this->handle);
// sometimes fopen changes the mode, e.g. for a url "r" convert to "r+"
// but we need to remember the original access type
$this->meta['mode'] = $mode;

}

Expand Down