marschall / memoryfilesystem

An in memory implementation of a JSR-203 file system
282 stars 36 forks source link

Fail to detect Path type if user don't have read permissions #112

Closed valery1707 closed 5 years ago

valery1707 commented 5 years ago

On virtual FS current user must have read permission to access BasicFileAttributes at MemoryFileSystem#readAttributes(AbstractPath, Class<A>, LinkOption...) - is this correct behavior?

On real OS - I can detect type (dir/file/link) even current don't have read permissions.

File:

$ touch permission.test
$ chmod -v a-rwx permission.test
mode of `permission.test' changed to 0000 (---------)
$ ls -l
total 4
---------- 1 user user    0 Oct 22 18:18 permission.test
drwxr-xr-x 7 user user 4096 Jul 31  2017 server
$ rm -v permission.test
rm: remove write-protected regular empty file `permission.test'? y
removed `permission.test'

Directory

$ mkdir permission.test
$ chmod -v a-rwx permission.test
mode of `permission.test' changed to 0000 (---------)
$ ls -l
total 8
d--------- 2 user user 4096 Oct 22 18:13 permission.test
drwxr-xr-x 7 user user 4096 Jul 31  2017 server
$ rm -v -r permission.test
rm: descend into write-protected directory `permission.test'? y
rm: remove write-protected directory `permission.test'? y
removed directory: `permission.test'

Symbolic link:

$ ln -v -s server permission.test
`permission.test' -> `server'
$ chmod -v a-rwx permission.test
mode of `permission.test' changed to 0000 (---------)
$ ls -l
total 4
lrwxrwxrwx 1 user user    6 Oct 22 18:20 permission.test -> server
d--------- 7 user user 4096 Jul 31  2017 server
$ rm -v permission.test
removed `permission.test'

Demo code: https://jdoodle.com/a/KbC

exists(none) = true
isDirectory(none) = false
isRegularFile(none) = false
isSymbolicLink(none) = false

exists(read) = true
isDirectory(read) = false
isRegularFile(read) = true
isSymbolicLink(read) = false

exists(write) = true
isDirectory(write) = false
isRegularFile(write) = false
isSymbolicLink(write) = false

exists(exec) = true
isDirectory(exec) = false
isRegularFile(exec) = false
isSymbolicLink(exec) = false
marschall commented 5 years ago

Yes, we should check the permission on the directory, not on the directory entry.

marschall commented 5 years ago

Looking at the stat() documentation it seems we need to check for the execute permission of all the directories on the path to the file. http://man7.org/linux/man-pages/man2/stat.2.html

marschall commented 5 years ago

I just released 1.4.0 to Maven Central.