Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
e4c45b5e
Commit
e4c45b5e
authored
10 years ago
by
Björn Schießle
Browse files
Options
Downloads
Patches
Plain Diff
check if file exists before deleting keys, and add debug output for every
delete operation
parent
b7d79a90
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/files_encryption/lib/keymanager.php
+40
-15
40 additions, 15 deletions
apps/files_encryption/lib/keymanager.php
with
40 additions
and
15 deletions
apps/files_encryption/lib/keymanager.php
+
40
−
15
View file @
e4c45b5e
...
...
@@ -229,16 +229,13 @@ class Keymanager {
$result
=
false
;
if
(
$view
->
is_dir
(
$keyPath
))
{
if
(
$view
->
is_dir
(
$keyPath
)
&&
!
$view
->
file_exists
(
'/'
.
$userId
.
'/files/'
.
$trimmed
)
)
{
\OCP\Util
::
writeLog
(
'files_encryption'
,
'deleteFileKey: delete file key: '
.
$keyPath
,
\OCP\Util
::
DEBUG
);
$result
=
$view
->
unlink
(
$keyPath
);
}
elseif
(
$view
->
file_exists
(
$keyPath
.
'.key'
)
&&
!
$view
->
file_exists
(
'/'
.
$userId
.
'/files/'
.
$trimmed
))
{
\OCP\Util
::
writeLog
(
'files_encryption'
,
'deleteFileKey: delete file key: '
.
$keyPath
,
\OCP\Util
::
DEBUG
);
$result
=
$view
->
unlink
(
$keyPath
.
'.key'
);
}
else
{
if
(
$view
->
file_exists
(
$keyPath
.
'.key'
))
{
$result
=
$view
->
unlink
(
$keyPath
.
'.key'
);
}
}
if
(
!
$result
)
{
...
...
@@ -403,6 +400,12 @@ class Keymanager {
$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
);
...
...
@@ -417,19 +420,24 @@ class Keymanager {
$baseDir
=
$userId
.
'/files_encryption/share-keys/'
;
}
$result
=
true
;
if
(
$view
->
is_dir
(
$baseDir
.
$filePath
))
{
$view
->
unlink
(
$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
)
{
$view
->
unlink
(
'/'
.
$userId
.
'/'
.
$path
);
\OCP\Util
::
writeLog
(
'files_encryption'
,
'dellAllShareKeys: delete share keys: '
.
'/'
.
$userId
.
'/'
.
$path
,
\OCP\Util
::
DEBUG
);
$result
&=
$view
->
unlink
(
'/'
.
$userId
.
'/'
.
$path
);
}
}
}
return
(
bool
)
$result
;
}
/**
...
...
@@ -454,18 +462,23 @@ class Keymanager {
if
(
$view
->
is_dir
(
$shareKeyPath
))
{
self
::
recursiveDelShareKeys
(
$shareKeyPath
,
$userIds
,
$view
);
self
::
recursiveDelShareKeys
(
$shareKeyPath
,
$userIds
,
$owner
,
$view
);
}
else
{
foreach
(
$userIds
as
$userId
)
{
if
(
!
$view
->
unlink
(
$shareKeyPath
.
'.'
.
$userId
.
'.shareKey'
))
{
if
(
$userId
===
$owner
&&
$view
->
file_exists
(
'/'
.
$owner
.
'/files/'
.
$filename
))
{
\OCP\Util
::
writeLog
(
'files_encryption'
,
'Tried to delete owner key, but the file still exists!'
,
\OCP\Util
::
FATAL
);
continue
;
}
$result
=
$view
->
unlink
(
$shareKeyPath
.
'.'
.
$userId
.
'.shareKey'
);
\OCP\Util
::
writeLog
(
'files_encryption'
,
'delShareKey: delete share key: '
.
$shareKeyPath
.
'.'
.
$userId
.
'.shareKey'
,
\OCP\Util
::
DEBUG
);
if
(
!
$result
)
{
\OCP\Util
::
writeLog
(
'Encryption library'
,
'Could not delete shareKey; does not exist: "'
.
$shareKeyPath
.
'.'
.
$userId
.
'.shareKey"'
,
\OCP\Util
::
ERROR
);
}
}
}
...
...
@@ -477,19 +490,31 @@ class Keymanager {
*
* @param string $dir directory
* @param array $userIds user ids for which the share keys should be deleted
* @param string $owner owner of the file
* @param \OC\Files\View $view view relative to data/
*/
private
static
function
recursiveDelShareKeys
(
$dir
,
$userIds
,
$view
)
{
private
static
function
recursiveDelShareKeys
(
$dir
,
$userIds
,
$owner
,
$view
)
{
$dirContent
=
$view
->
opendir
(
$dir
);
$dirSlices
=
explode
(
'/'
,
ltrim
(
$dir
,
'/'
));
$realFileDir
=
'/'
.
$owner
.
'/files/'
.
implode
(
'/'
,
array_slice
(
$dirSlices
,
3
))
.
'/'
;
if
(
is_resource
(
$dirContent
))
{
while
((
$file
=
readdir
(
$dirContent
))
!==
false
)
{
if
(
!
\OC\Files\Filesystem
::
isIgnoredDir
(
$file
))
{
if
(
$view
->
is_dir
(
$dir
.
'/'
.
$file
))
{
self
::
recursiveDelShareKeys
(
$dir
.
'/'
.
$file
,
$userIds
,
$view
);
self
::
recursiveDelShareKeys
(
$dir
.
'/'
.
$file
,
$userIds
,
$owner
,
$view
);
}
else
{
$realFile
=
$realFileDir
.
self
::
getFilenameFromShareKey
(
$file
);
foreach
(
$userIds
as
$userId
)
{
if
(
preg_match
(
"/(.*)."
.
$userId
.
".shareKey/"
,
$file
))
{
//TODO from $dir I need to strip /user/files_encryption/share-keys
if
(
$userId
===
$owner
&&
$view
->
file_exists
(
$realFile
))
{
\OCP\Util
::
writeLog
(
'files_encryption'
,
'original file still exists, keep owners share key!'
,
\OCP\Util
::
ERROR
);
continue
;
}
\OCP\Util
::
writeLog
(
'files_encryption'
,
'recursiveDelShareKey: delete share key: '
.
$file
,
\OCP\Util
::
DEBUG
);
$view
->
unlink
(
$dir
.
'/'
.
$file
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment