First, sorry about the constant questions I've got the usual "not enough time, too much too do" problem.
I need to get the security object via a Windows handle. This is because I need to open files/folders with Unicode names, and to do this I'm using CreateFileW. However, I cannot get a handle to the file if I'm denied access, but if I use your FileSecurity() method and pass the filename it works.
I'm using CreateFileW like this:
CreateFileW(PWideChar(useFName), GENERIC_READ, 0, nil, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS or FILE_FLAG_POSIX_SEMANTICS, 0)
What is the correct way to get a file/folder handle to just read/change the security info? Or do I need to set a privelage first? I've a feeling you're going to say you are using the GetFileSecurity API...If so, any chance of adding support for widestring filenames?
Thanks
Opening files with CreateFile
-
- Posts: 28
- Joined: Mon Jan 03, 2005 3:03 pm
- Contact:
-
- Posts: 28
- Joined: Mon Jan 03, 2005 3:03 pm
- Contact:
After reading and searching the Win32 help files, I'll answer my own question
To open for reading (with SE_BACKUP_NAME):
CreateFileW(PWideChar(useFName), READ_CONTROL, 0, nil, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS or FILE_FLAG_POSIX_SEMANTICS, 0);
And to open for writing (with SE_RESTORE_NAME):
CreateFileW(PWideChar(useFName), GENERIC_WRITE or WRITE_OWNER or WRITE_DAC, 0, nil, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS or FILE_FLAG_POSIX_SEMANTICS, 0);
Are you using CreateFile to get the handle, or GetFileSecurity ?
Thanks
To open for reading (with SE_BACKUP_NAME):
CreateFileW(PWideChar(useFName), READ_CONTROL, 0, nil, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS or FILE_FLAG_POSIX_SEMANTICS, 0);
And to open for writing (with SE_RESTORE_NAME):
CreateFileW(PWideChar(useFName), GENERIC_WRITE or WRITE_OWNER or WRITE_DAC, 0, nil, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS or FILE_FLAG_POSIX_SEMANTICS, 0);
Are you using CreateFile to get the handle, or GetFileSecurity ?
Thanks
I'm not getting a handle. There are security APIs which are happy with the name. If you give me a handle, I'm using it. If you give me a name, I'm using it directly, too, without converting it to a handle first.
Adding wide string support to madSecurity makes sense, I guess. Will do that in the next build.
Adding wide string support to madSecurity makes sense, I guess. Will do that in the next build.
-
- Posts: 28
- Joined: Mon Jan 03, 2005 3:03 pm
- Contact: