diff options
author | Robin Appelman <robin@icewind.nl> | 2021-06-17 13:53:11 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2023-04-05 13:21:30 +0200 |
commit | 54f61352f074f9c4698eb2b94e019ab101518b4c (patch) | |
tree | 83b1d7f18dbcdf4d74630fd484fb86360d5bb751 /lib | |
parent | a1b7f132c8a495fbf8fcce4612a9cd6b86d511d4 (diff) | |
download | nextcloud-server-54f61352f074f9c4698eb2b94e019ab101518b4c.tar.gz nextcloud-server-54f61352f074f9c4698eb2b94e019ab101518b4c.zip |
better error messages if the users home is not writable during scanning
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Utils/Scanner.php | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/lib/private/Files/Utils/Scanner.php b/lib/private/Files/Utils/Scanner.php index dc220bc710d..277ce38175f 100644 --- a/lib/private/Files/Utils/Scanner.php +++ b/lib/private/Files/Utils/Scanner.php @@ -27,11 +27,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ + namespace OC\Files\Utils; use OC\Files\Cache\Cache; use OC\Files\Filesystem; use OC\Files\Storage\FailedStorage; +use OC\Files\Storage\Home; use OC\ForbiddenException; use OC\Hooks\PublicEmitter; use OC\Lock\DBLockingProvider; @@ -211,13 +213,24 @@ class Scanner extends PublicEmitter { } // if the home storage isn't writable then the scanner is run as the wrong user - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') and - (!$storage->isCreatable('') or !$storage->isCreatable('files')) - ) { - if ($storage->is_dir('files')) { - throw new ForbiddenException(); - } else {// if the root exists in neither the cache nor the storage the user isn't setup yet - break; + if ($storage->instanceOfStorage(Home::class)) { + /** @var Home $storage */ + foreach (['', 'files'] as $path) { + if (!$storage->isCreatable($path)) { + $fullPath = $storage->getSourcePath($path); + if (!$storage->is_dir($path) && $storage->getCache()->inCache($path)) { + throw new NotFoundException("User folder $fullPath exists in cache but not on disk"); + } elseif ($storage->is_dir($path)) { + $ownerUid = fileowner($fullPath); + $owner = posix_getpwuid($ownerUid); + $owner = $owner['name'] ?? $ownerUid; + $permissions = decoct(fileperms($fullPath)); + throw new ForbiddenException("User folder $fullPath is not writable, folders is owned by $owner and has mode $permissions"); + } else { + // if the root exists in neither the cache nor the storage the user isn't setup yet + break 2; + } + } } } |