WindowsFileSystemProvider checkAccess
Salter, Thomas A
Thomas.Salter at unisys.com
Tue Aug 9 12:43:46 PDT 2011
I've encountered a problem with WindowsFileSystemProvider checkAccess function. When I'm running as an administrator, everything is fine, but when I run as an ordinary user (member of the default Users group), the GetEffectiveRightsFromAcl function fails with an Access Denied (5) error result. I've tried giving the individual user as well as the Users group "full control", but the only thing that seems to work is running under an administrator account.
I'm proven that the user does have access to the file by reading from the file from the same program after isReadable() returns false. My test program is included below.
I'm running on Windows 7 with the FCS version of Java 7 downloaded from the public Java technology site: http://www.oracle.com/technetwork/java/index.html
Along the way, I noticed that WindowsNativeDispatcher.c does not test correctly for an error code. The actual error is returned as the result, not with GetLastError. My suggested change follows:
#if OLD CODE
if (GetEffectiveRightsFromAcl(pAcl, pTrustee, &access) != ERROR_SUCCESS) {
throwWindowsException(env, GetLastError());
}
#else //NEW CODE
DWORD result = GetEffectiveRightsFromAcl(pAcl, pTrustee, &access);
if( result != ERROR_SUCCESS) {
throwWindowsException(env, result );
}
#endif
import java.io.*;
import java.nio.charset.*;
import java.nio.file.*;
public class WinNIO
{
public static void main(String[] args) throws IOException
{
WinNIO nio = new WinNIO();
nio.testReadable( "C:\\Windows\\System32\\drivers\\etc\\hosts" );
nio.testReadable( "C:\\java\\jdk7_fcs\\jre\\readme.txt" );
}
void testReadable(String file) throws IOException
{
Path path = Paths.get( file );
boolean isReadable = Files.isReadable( path );
System.out.println(path + ": isReadable:" + isReadable );
BufferedReader br = Files.newBufferedReader( path, Charset.defaultCharset() );
LineNumberReader lr = new LineNumberReader(br);
String line = lr.readLine();
System.out.println(line);
}
}
Tom Salter | Software Engineer | Java & Middleware Development
Unisys | 476 Swedesford Road | Malvern, PA 19355 | 610-648-2568 | N385-2568
[cid:image001.gif at 01CC56A5.AEDEEEA0]
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20110809/7fac487b/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.gif
Type: image/gif
Size: 2511 bytes
Desc: image001.gif
Url : http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20110809/7fac487b/attachment-0001.gif
More information about the nio-dev
mailing list