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 {
889889 var io: w.IO_STATUS_BLOCK = undefined;
890890 const rc = w.ntdll.NtCreateFile(
891891 &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,
893893 &attr,
894894 &io,
895895 null,
lib/std/os/windows/bits.zig+19-3
......@@ -412,7 +412,10 @@ pub const READ_CONTROL = 0x00020000;
412412pub const WRITE_DAC = 0x00040000;
413413pub const WRITE_OWNER = 0x00080000;
414414pub 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
417420// disposition for NtCreateFile
418421pub const FILE_SUPERSEDE = 0;
......@@ -424,6 +427,21 @@ pub const FILE_OVERWRITE_IF = 5;
424427pub const FILE_MAXIMUM_DISPOSITION = 5;
425428
426429// 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
427445pub const FILE_DIRECTORY_FILE = 0x00000001;
428446pub const FILE_WRITE_THROUGH = 0x00000002;
429447pub const FILE_SEQUENTIAL_ONLY = 0x00000004;
......@@ -755,8 +773,6 @@ pub const FILE_ACTION_RENAMED_NEW_NAME = 0x00000005;
755773
756774pub const LPOVERLAPPED_COMPLETION_ROUTINE = ?extern fn (DWORD, DWORD, *OVERLAPPED) void;
757775
758pub const FILE_LIST_DIRECTORY = 1;
759
760776pub const FILE_NOTIFY_CHANGE_CREATION = 64;
761777pub const FILE_NOTIFY_CHANGE_SIZE = 8;
762778pub const FILE_NOTIFY_CHANGE_SECURITY = 256;