Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DesiredAccess and FILE_ACCESS_FLAGS enums #1440

Closed
3 tasks
AArnott opened this issue Jan 24, 2023 · 3 comments
Closed
3 tasks

DesiredAccess and FILE_ACCESS_FLAGS enums #1440

AArnott opened this issue Jan 24, 2023 · 3 comments
Labels
broken api An API is inaccurate and could lead to runtime failure missing enum An enum is missing for constant parameters

Comments

@AArnott
Copy link
Member

AArnott commented Jan 24, 2023

These two enums are defined in the metadata, and they are nearly identical.

 [Flags]
-public enum DesiredAccess : uint
+public enum FILE_ACCESS_FLAGS : uint
 {
 	FILE_READ_DATA = 1u,
 	FILE_LIST_DIRECTORY = 1u,
 	FILE_WRITE_DATA = 2u,
 	FILE_ADD_FILE = 2u,
 	FILE_APPEND_DATA = 4u,
 	FILE_ADD_SUBDIRECTORY = 4u,
 	FILE_CREATE_PIPE_INSTANCE = 4u,
 	FILE_READ_EA = 8u,
 	FILE_WRITE_EA = 0x10u,
 	FILE_EXECUTE = 0x20u,
 	FILE_TRAVERSE = 0x20u,
 	FILE_DELETE_CHILD = 0x40u,
 	FILE_READ_ATTRIBUTES = 0x80u,
 	FILE_WRITE_ATTRIBUTES = 0x100u,
-	FILE_ALL_ACCESS = 0xF01FFu,
+	FILE_ALL_ACCESS = 0x1F01FFu,
 	DELETE = 0x10000u,
 	READ_CONTROL = 0x20000u,
 	WRITE_DAC = 0x40000u,
 	WRITE_OWNER = 0x80000u,
 	SYNCHRONIZE = 0x100000u,
+	STANDARD_RIGHTS_REQUIRED = 0xF0000u,
 	STANDARD_RIGHTS_READ = 0x20000u,
 	STANDARD_RIGHTS_WRITE = 0x20000u,
 	STANDARD_RIGHTS_EXECUTE = 0x20000u,
+	STANDARD_RIGHTS_ALL = 0x1F0000u,
+	SPECIFIC_RIGHTS_ALL = 0xFFFFu,
 	FILE_GENERIC_READ = 0x120089u,
 	FILE_GENERIC_WRITE = 0x120116u,
 	FILE_GENERIC_EXECUTE = 0x1200A0u
 }

These enums look worthy of consolidating. I believe FILE_ACCESS_FLAGS is the preferred name, and that one already has all the members.

Particularly interesting however is how FILE_ALL_ACCESS has different values between these enums. I'm guessing that's a bug. In the header files, this value is defined as:

#define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF)
#define SYNCHRONIZE                      (0x00100000L)

So it appears that one enum defines the FILE_ALL_ACCESS value with SYNCHRONIZE while the other leaves it out. I can't imagine why that would be intentional, as it appears that the header files consistently apply the SYNCHRONIZE flag.
So all the more reason to:

  • Delete DesiredAccess and redirect all users of it over to FILE_ACCESS_FLAGS.

And speaking of users of this enum, NtCreateFile could use some love:

  • DesiredAccess parameter is currently declared as uint, but it ought to be as this FILE_ACCESS_FLAGS enum.
  • FileAttributes parameter should be declared as FILE_FLAGS_AND_ATTRIBUTES.
@AArnott AArnott added broken api An API is inaccurate and could lead to runtime failure missing enum An enum is missing for constant parameters labels Jan 24, 2023
@mikebattista
Copy link
Contributor

Where do you see DesiredAccess in the metadata?

@KalleOlaviNiemitalo
Copy link

IIUC, the FileAttributes parameter of NtCreateFile is only file attributes, not file flags, which are instead mapped to the CreateOptions parameter (but with different values, e.g. FILE_DELETE_ON_CLOSE = 0x00001000 rather than
FILE_FLAG_DELETE_ON_CLOSE = 0x04000000). In this case, is it correct to use the FILE_FLAGS_AND_ATTRIBUTES enum?

CREATEFILE2_EXTENDED_PARAMETERS also distinguishes between dwFileAttributes, dwFileFlags, and dwSecurityQosFlags.

@AArnott
Copy link
Member Author

AArnott commented Jan 24, 2023

Where do you see DesiredAccess in the metadata?

Doh! That's ILSpy for you, which keeps loading other dlls and then showing those types and making me think they came from the metadata. Sorry about that.

@KalleOlaviNiemitalo may have a good point. Perhaps we need a unique enum type for the FileAttributes parameter. But at this point given my prior mistake about DesiredAccess, I'll close this issue and open a fresh one to discuss NtCreateFile enums.

@AArnott AArnott closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broken api An API is inaccurate and could lead to runtime failure missing enum An enum is missing for constant parameters
Projects
None yet
Development

No branches or pull requests

3 participants