mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 17:23:59 -04:00
get/set key files, take shared files into account
This commit is contained in:
parent
e5704bf8bf
commit
23391b3694
2 changed files with 36 additions and 8 deletions
|
|
@ -60,9 +60,23 @@ class Keymanager {
|
|||
* @param string user name of the file owner
|
||||
* @return string file key or false
|
||||
*/
|
||||
public static function getFileKey($user, $file) {
|
||||
public static function getFileKey($userId, $path) {
|
||||
|
||||
$keypath = ltrim($path, '/');
|
||||
$user = $userId;
|
||||
|
||||
// update $keypath and $user if path point to a file shared by someone else
|
||||
$query = \OC_DB::prepare( "SELECT uid_owner, source, target FROM `*PREFIX*sharing` WHERE target = ? AND uid_shared_with = ?" );
|
||||
$result = $query->execute( array ('/'.$userId.'/files/'.$keypath, $userId));
|
||||
if ($row = $result->fetchRow()){
|
||||
$keypath = $row['source'];
|
||||
$keypath_parts=explode('/',$keypath);
|
||||
$user = $keypath_parts[1];
|
||||
$keypath = str_replace('/'.$user.'/files/', '', $keypath);
|
||||
}
|
||||
|
||||
$view = new \OC_FilesystemView('/'.$user.'/files_encryption/keyfiles/');
|
||||
return $view->file_get_contents($file.'.key');
|
||||
return $view->file_get_contents($keypath.'.key');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -115,13 +129,27 @@ class Keymanager {
|
|||
* @return bool true/false
|
||||
*/
|
||||
public static function setFileKey( $userId, $path, $key ) {
|
||||
|
||||
|
||||
\OC_FileProxy::$enabled = false;
|
||||
|
||||
$targetpath = ltrim($path, '/');
|
||||
$user = $userId;
|
||||
|
||||
// update $keytarget and $user if key belongs to a file shared by someone else
|
||||
$query = \OC_DB::prepare( "SELECT uid_owner, source, target FROM `*PREFIX*sharing` WHERE target = ? AND uid_shared_with = ?" );
|
||||
$result = $query->execute( array ('/'.$userId.'/files/'.$targetpath, $userId));
|
||||
if ($row = $result->fetchRow()){
|
||||
$targetpath = $row['source'];
|
||||
$targetpath_parts=explode('/',$targetpath);
|
||||
$user = $targetpath_parts[1];
|
||||
$targetpath = str_replace('/'.$user.'/files/', '', $targetpath);
|
||||
}
|
||||
|
||||
$view = new \OC_FilesystemView( '/' . $user . '/files_encryption/keyfiles' );
|
||||
$path_parts = pathinfo($targetpath);
|
||||
|
||||
$view = new \OC_FilesystemView( '/' . $userId . '/' . 'files_encryption/keyfiles' );
|
||||
$path_parts = pathinfo($path);
|
||||
if (!$view->file_exists($path_parts['dirname'])) $view->mkdir($path_parts['dirname']);
|
||||
$result = $view->file_put_contents( '/' . $path . '.key', $key );
|
||||
$result = $view->file_put_contents( '/' . $targetpath . '.key', $key );
|
||||
|
||||
\OC_FileProxy::$enabled = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -192,8 +192,8 @@ class OC_OCS {
|
|||
|
||||
// keygetfiles
|
||||
}elseif(($method=='get') and ($ex[$paracount-7] == 'v1.php') and ($ex[$paracount-6]=='cloud') and ($ex[$paracount-5] == 'user') and ($ex[$paracount-3] == 'filekey')){
|
||||
$user=$ex[$paracount-4];
|
||||
$file = urldecode($ex[$paracount-2]);
|
||||
$user=$ex[$paracount-4];
|
||||
$file = urldecode($ex[$paracount-2]);
|
||||
OC_OCS::fileKeyGet($format,$user, $file);
|
||||
|
||||
//keysetfiles
|
||||
|
|
|
|||
Loading…
Reference in a new issue