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

Check trashbin perms before moving to trash #29820

Merged
merged 2 commits into from
Jan 22, 2018
Merged

Conversation

PVince81
Copy link
Contributor

Description

Check whether the target trashbin is writable (ex: guests).
In the case where a guest deletes a file as recipient, the owner would
get a copy in their trash. The logic here will detect that the guests'
trashbin is not writeable so it will fall back to simply moving directly
to the owner's trashbin.

Related Issue

owncloud/guests#31 approach 1

Motivation and Context

How Has This Been Tested?

Manually tested.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

TODOs:

  • add unit tests if we agree on the approach

@codecov
Copy link

codecov bot commented Dec 12, 2017

Codecov Report

Merging #29820 into master will increase coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #29820      +/-   ##
============================================
+ Coverage     58.21%   58.27%   +0.05%     
- Complexity    18517    18522       +5     
============================================
  Files          1095     1095              
  Lines         63715    63722       +7     
============================================
+ Hits          37093    37135      +42     
+ Misses        26622    26587      -35
Impacted Files Coverage Δ Complexity Δ
drone/src/lib/private/Files/Cache/Cache.php 96.63% <0%> (-0.58%) 102% <0%> (+2%)
drone/src/lib/private/Server.php 82.55% <0%> (-0.15%) 129% <0%> (ø)
drone/src/apps/files_trashbin/lib/Trashbin.php 76.19% <0%> (+0.1%) 137% <0%> (+3%) ⬆️
drone/src/lib/private/legacy/util.php 67.97% <0%> (+1.36%) 222% <0%> (ø) ⬇️
.../src/lib/private/Files/Storage/Wrapper/DirMask.php 48.52% <0%> (+4.41%) 34% <0%> (ø) ⬇️
drone/src/lib/private/Files/Cache/CacheEntry.php 94.73% <0%> (+5.26%) 20% <0%> (ø) ⬇️
...c/lib/private/Files/Cache/Wrapper/CacheWrapper.php 86.36% <0%> (+7.57%) 30% <0%> (ø) ⬇️
.../private/Files/Storage/Wrapper/PermissionsMask.php 93.02% <0%> (+9.3%) 39% <0%> (ø) ⬇️
...lib/private/Files/Storage/Wrapper/ReadOnlyJail.php 94.73% <0%> (+21.05%) 8% <0%> (ø) ⬇️
...les/Cache/Wrapper/ReadOnlyCachePermissionsMask.php 100% <0%> (+100%) 4% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 81153de...c7caea2. Read the comment docs.

@PVince81 PVince81 modified the milestones: development, planned Jan 12, 2018
@PVince81
Copy link
Contributor Author

decision clarified and we agreed on the approach: need to update unit tests

@PVince81
Copy link
Contributor Author

Unit test added. Needs review.

Copy link
Member

@IljaN IljaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PVince81
Copy link
Contributor Author

Grrrr... Oracle

1) OCA\Files_Trashbin\Tests\StorageTest::testDeleteFolderAsReadOnlyRecipient
OCP\Files\NotPermittedException: No create permission for folder /recipient_1Ky0E38xz5c26/files

/drone/src/lib/private/Files/Node/Folder.php:162
/drone/src/lib/private/Files/Node/Root.php:369
/drone/src/lib/private/Server.php:982
/drone/src/tests/lib/TestCase.php:373
/drone/src/apps/files_trashbin/tests/StorageTest.php:276

@PVince81
Copy link
Contributor Author

I did some debugging with MariaDB and I can see that the Folder::checkPermissions call for create permissions is done on "/recipient_xyz" which allows the creation of a "files" folder for a read-only user.
Not sure if that's intended. That aside, I don't understand why Oracle would have a different result there.

However the output with Oracle seems to imply that the check is done on "/recipient_xyz/files" instead, which disallows anything else than read.

@IljaN
Copy link
Member

IljaN commented Jan 17, 2018

The "ReadOnlyJail" is initialized before first-login directory structure creation, so it need to allow "/files" creation.

@PVince81
Copy link
Contributor Author

@IljaN thanks for the info.

Seems I'll need to boot up an Oracle docker to solve this mystery.

@PVince81
Copy link
Contributor Author

When running tests on Oracle: the individual test file works, but when running all the tests, some kind of side effect is causing the issue above.

@PVince81
Copy link
Contributor Author

Debug comparison: getFileInfo("/recipient_xyz") always reads the permissions from oc_filecache.
On Oracle the database contains the permissions 1 but on other DBs it contains 4. Go figure...

Maybe the read-only wrapper kicks in much earlier with Oracle, could be scan time (when?!) and reads the already masked value.

@PVince81
Copy link
Contributor Author

I checked the database and both Oracle and MariaDB have the same "permissions" value.

However the getFileInfo call still returns 1 for Oracle.

@PVince81
Copy link
Contributor Author

Remember that Oracle consider empty strings as null.
When reading the cache entry for "/recipient_xyz" this is actually the filecache entry with name === "" which is actually null on Oracle. So what happens is that $data['name'] is null instead of empty string.

I didn't yet reach the correct code but I suspect that there is a check against empty string somewhere that might not kick in when null. I remember @IljaN saying that the permissions on the root was more permissive than on "/files".

Let me fix that in the Cache and convert null to empty string... I'm sure this will somewhat solve a lot of other yet undiscovered Oracle problems...

@IljaN
Copy link
Member

IljaN commented Jan 17, 2018

@PVince81 The root folder is indeed more permissive because for example cache, avatars directories needs to be created in there.

@PVince81
Copy link
Contributor Author

Confirmed, it works with this fix c30c8ec

@PVince81
Copy link
Contributor Author

Please do review my last commit. I think it looks alright.

Vincent Petry added 2 commits January 18, 2018 09:22
Check whether the target trashbin is writable (ex: guests).
In the case where a guest deletes a file as recipient, the owner would
get a copy in their trash. The logic here will detect that the guests'
trashbin is not writeable so it will fall back to simply moving directly
to the owner's trashbin.
@PVince81
Copy link
Contributor Author

@ownclouders rebase

@ownclouders
Copy link
Contributor

Hey! I'm GitMate.io! This pull request is being rebased automatically. Please DO NOT push while rebase is in progress or your changes would be lost permanently ⚠️

@ownclouders
Copy link
Contributor

Automated rebase with GitMate.io was successful! 🎉

@PVince81
Copy link
Contributor Author

stable10: #30224

@PVince81
Copy link
Contributor Author

I missed the trash commit, backported here: #30240

@lock
Copy link

lock bot commented Aug 1, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants