* @note Where a method requires a view object, it's root must be '/'\r
*/\r
class Keymanager {\r
+\r
+ /**\r
+ * @brief get uid of the owners of the file and the path to the file\r
+ * @param $filename\r
+ * @return array\r
+ */\r
+ public static function getUidAndFilename($filename) {\r
+ $uid = \OC\Files\Filesystem::getOwner($filename);\r
+ \OC\Files\Filesystem::initMountPoints($uid);\r
+ if ( $uid != \OCP\User::getUser() ) {\r
+ $info = \OC\Files\Filesystem::getFileInfo($filename);\r
+ $ownerView = new \OC\Files\View('/'.$uid.'/files');\r
+ $filename = $ownerView->getPath($info['fileid']);\r
+ }\r
+ return array($uid, $filename);\r
+ }\r
\r
/**\r
* @brief retrieve the ENCRYPTED private key from a user\r
* asymmetrically encrypt the keyfile before passing it to this method\r
*/\r
public static function setShareKey( \OC_FilesystemView $view, $path, $userId, $shareKey ) {\r
+\r
+ list($owner, $filename) = self::getUidAndFilename($path);\r
+\r
+ $basePath = '/' . $owner . '/files_encryption/share-keys';\r
\r
- $basePath = '/' . $userId . '/files_encryption/share-keys';\r
- \r
- $shareKeyPath = self::keySetPreparation( $view, $path, $basePath, $userId );\r
+ $shareKeyPath = self::keySetPreparation( $view, $filename, $basePath, $owner );\r
\r
- $writePath = $basePath . '/' . $shareKeyPath . '.shareKey';\r
+ $writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey';\r
\r
\OC_FileProxy::$enabled = false;\r
- \r
+\r
$result = $view->file_put_contents( $writePath, $shareKey );\r
\r
if ( \r
* @return bool\r
*/\r
public static function setShareKeys( \OC_FilesystemView $view, $path, array $shareKeys ) {\r
- \r
+\r
// $shareKeys must be an array with the following format:\r
// [userId] => [encrypted key]\r
\r
isset( $path_parts['dirname'] )\r
&& ! $view->file_exists( $basePath . '/' . $path_parts['dirname'] ) \r
) {\r
- \r
- $view->mkdir( $basePath . '/' . $path_parts['dirname'] );\r
- \r
+ $sub_dirs = explode(DIRECTORY_SEPARATOR, $basePath . '/' . $path_parts['dirname']);\r
+ $dir = '';\r
+ foreach ($sub_dirs as $sub_dir) {\r
+ $dir .= '/' . $sub_dir;\r
+ if (!$view->is_dir($dir)) {\r
+ $view->mkdir($dir);\r
+ }\r
+ }\r
}\r
\r
return $targetPath;\r