authorgravatar for gereeter+code@gmail.comJonathan S <gereeter+code@gmail.com> 2019-11-22 16:14:39-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-25 23:46:47-05:00
log51c57408794ae4411a0059d7f9d30b47d83a534e
tree621db53675761a044714e5138a34bc1b099ea2c3
parent07120c87451636f65d2917f0355b4493034a2c0f

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.

2 files changed, 20 insertions(+), 4 deletions(-)

lib/std/fs.zig+1-1
...@@ -889,7 +889,7 @@ pub const Dir = struct {...@@ -889,7 +889,7 @@ pub const Dir = struct {
889 var io: w.IO_STATUS_BLOCK = undefined;889 var io: w.IO_STATUS_BLOCK = undefined;
890 const rc = w.ntdll.NtCreateFile(890 const rc = w.ntdll.NtCreateFile(
891 &result.fd,891 &result.fd,
892 w.GENERIC_READ | w.SYNCHRONIZE,892 w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA | w.SYNCHRONIZE | w.FILE_TRAVERSE | w.FILE_LIST_DIRECTORY,
893 &attr,893 &attr,
894 &io,894 &io,
895 null,895 null,
lib/std/os/windows/bits.zig+19-3
...@@ -412,7 +412,10 @@ pub const READ_CONTROL = 0x00020000;...@@ -412,7 +412,10 @@ pub const READ_CONTROL = 0x00020000;
412pub const WRITE_DAC = 0x00040000;412pub const WRITE_DAC = 0x00040000;
413pub const WRITE_OWNER = 0x00080000;413pub const WRITE_OWNER = 0x00080000;
414pub const SYNCHRONIZE = 0x00100000;414pub const SYNCHRONIZE = 0x00100000;
415pub const STANDARD_RIGHTS_REQUIRED = 0x000f0000;415pub const STANDARD_RIGHTS_READ = READ_CONTROL;
416pub const STANDARD_RIGHTS_WRITE = READ_CONTROL;
417pub const STANDARD_RIGHTS_EXECUTE = READ_CONTROL;
418pub const STANDARD_RIGHTS_REQUIRED = DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER;
416419
417// disposition for NtCreateFile420// disposition for NtCreateFile
418pub const FILE_SUPERSEDE = 0;421pub const FILE_SUPERSEDE = 0;
...@@ -424,6 +427,21 @@ pub const FILE_OVERWRITE_IF = 5;...@@ -424,6 +427,21 @@ pub const FILE_OVERWRITE_IF = 5;
424pub const FILE_MAXIMUM_DISPOSITION = 5;427pub const FILE_MAXIMUM_DISPOSITION = 5;
425428
426// flags for NtCreateFile and NtOpenFile429// flags for NtCreateFile and NtOpenFile
430pub const FILE_READ_DATA = 0x00000001;
431pub const FILE_LIST_DIRECTORY = 0x00000001;
432pub const FILE_WRITE_DATA = 0x00000002;
433pub const FILE_ADD_FILE = 0x00000002;
434pub const FILE_APPEND_DATA = 0x00000004;
435pub const FILE_ADD_SUBDIRECTORY = 0x00000004;
436pub const FILE_CREATE_PIPE_INSTANCE = 0x00000004;
437pub const FILE_READ_EA = 0x00000008;
438pub const FILE_WRITE_EA = 0x00000010;
439pub const FILE_EXECUTE = 0x00000020;
440pub const FILE_TRAVERSE = 0x00000020;
441pub const FILE_DELETE_CHILD = 0x00000040;
442pub const FILE_READ_ATTRIBUTES = 0x00000080;
443pub const FILE_WRITE_ATTRIBUTES = 0x00000100;
444
427pub const FILE_DIRECTORY_FILE = 0x00000001;445pub const FILE_DIRECTORY_FILE = 0x00000001;
428pub const FILE_WRITE_THROUGH = 0x00000002;446pub const FILE_WRITE_THROUGH = 0x00000002;
429pub const FILE_SEQUENTIAL_ONLY = 0x00000004;447pub const FILE_SEQUENTIAL_ONLY = 0x00000004;
...@@ -755,8 +773,6 @@ pub const FILE_ACTION_RENAMED_NEW_NAME = 0x00000005;...@@ -755,8 +773,6 @@ pub const FILE_ACTION_RENAMED_NEW_NAME = 0x00000005;
755773
756pub const LPOVERLAPPED_COMPLETION_ROUTINE = ?extern fn (DWORD, DWORD, *OVERLAPPED) void;774pub const LPOVERLAPPED_COMPLETION_ROUTINE = ?extern fn (DWORD, DWORD, *OVERLAPPED) void;
757775
758pub const FILE_LIST_DIRECTORY = 1;
759
760pub const FILE_NOTIFY_CHANGE_CREATION = 64;776pub const FILE_NOTIFY_CHANGE_CREATION = 64;
761pub const FILE_NOTIFY_CHANGE_SIZE = 8;777pub const FILE_NOTIFY_CHANGE_SIZE = 8;
762pub const FILE_NOTIFY_CHANGE_SECURITY = 256;778pub const FILE_NOTIFY_CHANGE_SECURITY = 256;