FULL PRODUCT VERSION :
1.8.0_77-b03
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.10240]
EXTRA RELEVANT SYSTEM CONFIGURATION :
Samba configuration is given in "Steps to Reproduce".
A DESCRIPTION OF THE PROBLEM :
Files.isWritable returns false negatives for certain NAS configurations.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Configure a samba server with this config:
[global]
workgroup = workgroup
security = user
map to guest = Bad User
public = yes
obey pam restrictions = Yes
pam password change = Yes
dns proxy = No
usershare allow guests = Yes
log level = 3
log file = /var/log/samba/samba.log
unix extensions = no
wide links = yes
printcap name = /etc/printcap
load printers = no
socket options = IPTOS_LOWDELAY TCP_NODELAY SO_KEEPALIVE
write cache size = 2097152
use sendfile = true
getwd cache = yes
oplocks = no
[bug]
comment = Read/Write file share
path = /path/to/share
browsable = Yes
guest ok = Yes
read only = No
create mask = 0755
directory mask = 0755
writable = Yes
map read only = no
force user = root
force group = root
Change your paths etc as you need.
Now have /path/to/share with all root ownership:
$ ls -la
total 45112
drwxr-xr-x 2 root root 4096 Apr 19 14:49 .
drwxr-xr-x 3 root root 46 Mar 31 14:30 ..
-rw-r--r-- 1 root root 3377767 Apr 19 12:21 01-Don't Be Light (Edit).mp3
...
Now open this up in Windows Explorer as a guest user (the Windows account you use should not have a corresponding account on the samba server); you can edit the MP3 file, add files to the folder and more. Samba treats your operations as if you were root on the server. That's because "force user = root".
However, try running the following Java application:
import java.nio.file.*;
import java.io.File;
public class IsWritableTest {
public static void main(String[] args) {
Path path = new File(args[0]).toPath();
System.out.println(Files.exists(path));
System.out.println(Files.isWritable(path));
}
}
java IsWritableTest "\\NAS\bug\01-Don't Be Light (Edit).mp3"
The output is:
true
false
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect either the Javadoc to state the limitations of the API (that ONLY ACLs appear to be considered).
Or I would expect it to return true in this case, because the file is writable.
ACTUAL -
Files.isWritable returns false.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
See steps to reproduce.
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I think a workaround is just to ignore the method and attempt to write to files, catching exceptions.
1.8.0_77-b03
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.10240]
EXTRA RELEVANT SYSTEM CONFIGURATION :
Samba configuration is given in "Steps to Reproduce".
A DESCRIPTION OF THE PROBLEM :
Files.isWritable returns false negatives for certain NAS configurations.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Configure a samba server with this config:
[global]
workgroup = workgroup
security = user
map to guest = Bad User
public = yes
obey pam restrictions = Yes
pam password change = Yes
dns proxy = No
usershare allow guests = Yes
log level = 3
log file = /var/log/samba/samba.log
unix extensions = no
wide links = yes
printcap name = /etc/printcap
load printers = no
socket options = IPTOS_LOWDELAY TCP_NODELAY SO_KEEPALIVE
write cache size = 2097152
use sendfile = true
getwd cache = yes
oplocks = no
[bug]
comment = Read/Write file share
path = /path/to/share
browsable = Yes
guest ok = Yes
read only = No
create mask = 0755
directory mask = 0755
writable = Yes
map read only = no
force user = root
force group = root
Change your paths etc as you need.
Now have /path/to/share with all root ownership:
$ ls -la
total 45112
drwxr-xr-x 2 root root 4096 Apr 19 14:49 .
drwxr-xr-x 3 root root 46 Mar 31 14:30 ..
-rw-r--r-- 1 root root 3377767 Apr 19 12:21 01-Don't Be Light (Edit).mp3
...
Now open this up in Windows Explorer as a guest user (the Windows account you use should not have a corresponding account on the samba server); you can edit the MP3 file, add files to the folder and more. Samba treats your operations as if you were root on the server. That's because "force user = root".
However, try running the following Java application:
import java.nio.file.*;
import java.io.File;
public class IsWritableTest {
public static void main(String[] args) {
Path path = new File(args[0]).toPath();
System.out.println(Files.exists(path));
System.out.println(Files.isWritable(path));
}
}
java IsWritableTest "\\NAS\bug\01-Don't Be Light (Edit).mp3"
The output is:
true
false
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect either the Javadoc to state the limitations of the API (that ONLY ACLs appear to be considered).
Or I would expect it to return true in this case, because the file is writable.
ACTUAL -
Files.isWritable returns false.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
See steps to reproduce.
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I think a workaround is just to ignore the method and attempt to write to files, catching exceptions.
- relates to
-
JDK-8282720 Wrong behavior of standard IO library when interacting with Samba
-
- Open
-