|
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; |
@@ -211,13 +213,23 @@ public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECUR |
211 | 213 | } |
212 | 214 |
|
213 | 215 | // if the home storage isn't writable then the scanner is run as the wrong user |
214 | | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') and |
215 | | - (!$storage->isCreatable('') or !$storage->isCreatable('files')) |
216 | | - ) { |
217 | | - if ($storage->is_dir('files')) { |
218 | | - throw new ForbiddenException(); |
219 | | - } else {// if the root exists in neither the cache nor the storage the user isn't setup yet |
220 | | - break; |
| 216 | + if ($storage->instanceOfStorage(Home::class)) { |
| 217 | + /** @var Home $storage */ |
| 218 | + foreach (['', 'files'] as $path) { |
| 219 | + if (!$storage->isCreatable($path)) { |
| 220 | + $fullPath = $storage->getSourcePath($path); |
| 221 | + if (!$storage->is_dir($path) && $storage->getCache()->inCache($path)) { |
| 222 | + throw new NotFoundException("User folder $fullPath exists in cache but not on disk"); |
| 223 | + } elseif ($storage->is_dir($path)) { |
| 224 | + $ownerUid = fileowner($fullPath); |
| 225 | + $owner = posix_getpwuid($ownerUid); |
| 226 | + $owner = $owner ? $owner['name'] : $ownerUid; |
| 227 | + $permissions = decoct(fileperms($fullPath)); |
| 228 | + throw new ForbiddenException("User folder $fullPath is not writable, folders is owned by $owner and has mode $permissions"); |
| 229 | + } else {// if the root exists in neither the cache nor the storage the user isn't setup yet |
| 230 | + break 2; |
| 231 | + } |
| 232 | + } |
221 | 233 | } |
222 | 234 | } |
223 | 235 |
|
|
0 commit comments