|
27 | 27 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
28 | 28 | * |
29 | 29 | */ |
| 30 | + |
30 | 31 | namespace OC\Files\Utils; |
31 | 32 |
|
32 | 33 | use OC\Files\Cache\Cache; |
33 | 34 | use OC\Files\Filesystem; |
34 | 35 | use OC\Files\Storage\FailedStorage; |
| 36 | +use OC\Files\Storage\Home; |
35 | 37 | use OC\ForbiddenException; |
36 | 38 | use OC\Hooks\PublicEmitter; |
37 | 39 | use OC\Lock\DBLockingProvider; |
@@ -214,13 +216,23 @@ public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECUR |
214 | 216 | } |
215 | 217 |
|
216 | 218 | // if the home storage isn't writable then the scanner is run as the wrong user |
217 | | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') and |
218 | | - (!$storage->isCreatable('') or !$storage->isCreatable('files')) |
219 | | - ) { |
220 | | - if ($storage->file_exists('') or $storage->getCache()->inCache('')) { |
221 | | - throw new ForbiddenException(); |
222 | | - } else {// if the root exists in neither the cache nor the storage the user isn't setup yet |
223 | | - break; |
| 219 | + if ($storage->instanceOfStorage(Home::class)) { |
| 220 | + /** @var Home $storage */ |
| 221 | + foreach (['', 'files'] as $path) { |
| 222 | + if (!$storage->isCreatable($path)) { |
| 223 | + $fullPath = $storage->getSourcePath($path); |
| 224 | + if (!$storage->file_exists($path) && $storage->getCache()->inCache($path)) { |
| 225 | + throw new NotFoundException("User folder $fullPath exists in cache but not on disk"); |
| 226 | + } elseif ($storage->file_exists($path) || $storage->getCache()->inCache($path)) { |
| 227 | + $ownerUid = fileowner($fullPath); |
| 228 | + $owner = posix_getpwuid($ownerUid); |
| 229 | + $owner = $owner ? $owner['name'] : $ownerUid; |
| 230 | + $permissions = decoct(fileperms($fullPath)); |
| 231 | + throw new ForbiddenException("User folder $fullPath is not writable, folders is owned by $owner and has mode $permissions"); |
| 232 | + } else {// if the root exists in neither the cache nor the storage the user isn't setup yet |
| 233 | + break 2; |
| 234 | + } |
| 235 | + } |
224 | 236 | } |
225 | 237 | } |
226 | 238 |
|
|
0 commit comments