Commit 51c5740879

Jonathan S <gereeter+code@gmail.com>
2019-11-22 23:14:39
Use a specific access mask in `Dir.openDirListW` instead of a generic one. Untested.
The actual desired access mask in this case seems quite confusing and badly documented. The previous combination of `GENERIC_READ` and `SYNCHRONIZE` seems both illegal and redundant according to the [`ntifs.h` documentation](https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-ntcreatefile), which specifies that `GENERIC_READ` should not be used for directories and includes `SYNCHRONIZE`. `winnt.h` contains a number of relevant-sounding flags such as `FILE_ADD_FILE`, `FILE_ADD_SUBDIRECTORY`, and `FILE_DELETE_CHILD` that do not show up in documentation at all. These are equal in value to file-specific flags that are documented as flags you should not specify when opening a directory.
1 parent 07120c8
Changed files (2)
lib
std
os
windows
lib/std/os/windows/bits.zig
@@ -412,7 +412,10 @@ pub const READ_CONTROL = 0x00020000;
 pub const WRITE_DAC = 0x00040000;
 pub const WRITE_OWNER = 0x00080000;
 pub const SYNCHRONIZE = 0x00100000;
-pub const STANDARD_RIGHTS_REQUIRED = 0x000f0000;
+pub const STANDARD_RIGHTS_READ = READ_CONTROL;
+pub const STANDARD_RIGHTS_WRITE = READ_CONTROL;
+pub const STANDARD_RIGHTS_EXECUTE = READ_CONTROL;
+pub const STANDARD_RIGHTS_REQUIRED = DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER;
 
 // disposition for NtCreateFile
 pub const FILE_SUPERSEDE = 0;
@@ -424,6 +427,21 @@ pub const FILE_OVERWRITE_IF = 5;
 pub const FILE_MAXIMUM_DISPOSITION = 5;
 
 // flags for NtCreateFile and NtOpenFile
+pub const FILE_READ_DATA = 0x00000001;
+pub const FILE_LIST_DIRECTORY = 0x00000001;
+pub const FILE_WRITE_DATA = 0x00000002;
+pub const FILE_ADD_FILE = 0x00000002;
+pub const FILE_APPEND_DATA = 0x00000004;
+pub const FILE_ADD_SUBDIRECTORY = 0x00000004;
+pub const FILE_CREATE_PIPE_INSTANCE = 0x00000004;
+pub const FILE_READ_EA = 0x00000008;
+pub const FILE_WRITE_EA = 0x00000010;
+pub const FILE_EXECUTE = 0x00000020;
+pub const FILE_TRAVERSE = 0x00000020;
+pub const FILE_DELETE_CHILD = 0x00000040;
+pub const FILE_READ_ATTRIBUTES = 0x00000080;
+pub const FILE_WRITE_ATTRIBUTES = 0x00000100;
+
 pub const FILE_DIRECTORY_FILE = 0x00000001;
 pub const FILE_WRITE_THROUGH = 0x00000002;
 pub const FILE_SEQUENTIAL_ONLY = 0x00000004;
@@ -755,8 +773,6 @@ pub const FILE_ACTION_RENAMED_NEW_NAME = 0x00000005;
 
 pub const LPOVERLAPPED_COMPLETION_ROUTINE = ?extern fn (DWORD, DWORD, *OVERLAPPED) void;
 
-pub const FILE_LIST_DIRECTORY = 1;
-
 pub const FILE_NOTIFY_CHANGE_CREATION = 64;
 pub const FILE_NOTIFY_CHANGE_SIZE = 8;
 pub const FILE_NOTIFY_CHANGE_SECURITY = 256;
lib/std/fs.zig
@@ -889,7 +889,7 @@ pub const Dir = struct {
         var io: w.IO_STATUS_BLOCK = undefined;
         const rc = w.ntdll.NtCreateFile(
             &result.fd,
-            w.GENERIC_READ | w.SYNCHRONIZE,
+            w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA | w.SYNCHRONIZE | w.FILE_TRAVERSE | w.FILE_LIST_DIRECTORY,
             &attr,
             &io,
             null,