[Wine-patches] [eter-2.1 1/4] advapi: Don't use CreateFile when opening file with possibly empty DACL.

Dmitry Timoshkov dmitry на baikal.ru
Вт Июн 27 09:06:09 MSK 2017


From: Piotr Caban <piotr на codeweavers.com>

---
 dlls/advapi32/security.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c
index 935af8b72b..871b8afb65 100644
--- a/dlls/advapi32/security.c
+++ b/dlls/advapi32/security.c
@@ -402,7 +402,7 @@ static inline BOOL set_ntstatus( NTSTATUS status )
 }
 
 /* helper function for SE_FILE_OBJECT objects in [Get|Set]NamedSecurityInfo */
-static inline DWORD get_security_file( LPWSTR full_file_name, DWORD access, HANDLE *file )
+static inline DWORD get_security_file( LPCWSTR full_file_name, DWORD access, HANDLE *file )
 {
     UNICODE_STRING file_nameW;
     OBJECT_ATTRIBUTES attr;
@@ -2037,7 +2037,7 @@ GetFileSecurityW( LPCWSTR lpFileName,
 {
     HANDLE hfile;
     NTSTATUS status;
-    DWORD access = 0;
+    DWORD access = 0, err;
 
     TRACE("(%s,%d,%p,%d,%p)\n", debugstr_w(lpFileName),
           RequestedInformation, pSecurityDescriptor,
@@ -2049,10 +2049,12 @@ GetFileSecurityW( LPCWSTR lpFileName,
     if (RequestedInformation & SACL_SECURITY_INFORMATION)
         access |= ACCESS_SYSTEM_SECURITY;
 
-    hfile = CreateFileW( lpFileName, access, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
-                         NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
-    if ( hfile == INVALID_HANDLE_VALUE )
+    err = get_security_file( lpFileName, access, &hfile);
+    if (err)
+    {
+        SetLastError(err);
         return FALSE;
+    }
 
     status = NtQuerySecurityObject( hfile, RequestedInformation, pSecurityDescriptor,
                                     nLength, lpnLengthNeeded );
@@ -2334,7 +2336,7 @@ SetFileSecurityW( LPCWSTR lpFileName,
                     PSECURITY_DESCRIPTOR pSecurityDescriptor )
 {
     HANDLE file;
-    DWORD access = 0;
+    DWORD access = 0, err;
     NTSTATUS status;
 
     TRACE("(%s, 0x%x, %p)\n", debugstr_w(lpFileName), RequestedInformation,
@@ -2348,10 +2350,12 @@ SetFileSecurityW( LPCWSTR lpFileName,
     if (RequestedInformation & DACL_SECURITY_INFORMATION)
         access |= WRITE_DAC;
 
-    file = CreateFileW( lpFileName, access, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
-                        NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
-    if (file == INVALID_HANDLE_VALUE)
+    err = get_security_file( lpFileName, access, &file);
+    if (err)
+    {
+        SetLastError(err);
         return FALSE;
+    }
 
     status = NtSetSecurityObject( file, RequestedInformation, pSecurityDescriptor );
     CloseHandle( file );
-- 
2.13.2



Подробная информация о списке рассылки Wine-patches