[1/6] ntdll: refactor NTDLL_create_struct_sd and NTDLL_free_struct_sd so that other modules are able to use them

Joris van der Wel joris at jorisvanderwel.com
Sun Jul 6 13:15:45 CDT 2014


ntdll: refactor NTDLL_create_struct_sd and NTDLL_free_struct_sd so
 that other modules are able to use them (extern). New names are
 wine_server_create_struct_sd  and wine_server_free_struct_sd.

---
 dlls/ntdll/file.c       |  4 +--
 dlls/ntdll/ntdll.spec   |  2 ++
 dlls/ntdll/ntdll_misc.h |  5 ---
 dlls/ntdll/server.c     | 72 +++++++++++++++++++++++++++++++++++++++++
 dlls/ntdll/sync.c       | 86 +++++--------------------------------------------
 dlls/ntdll/virtual.c    |  4 +--
 include/wine/server.h   |  6 ++++
 7 files changed, 92 insertions(+), 87 deletions(-)
-------------- next part --------------
From 038aa937b44a75dba544cfd940d58b0010cd299b Mon Sep 17 00:00:00 2001
From: Joris van der Wel <joris at jorisvanderwel.com>
Date: Sat, 5 Jul 2014 22:37:00 +0200
Subject: ntdll: refactor NTDLL_create_struct_sd and NTDLL_free_struct_sd so
 that other modules are able to use them (extern). New names are
 wine_server_create_struct_sd  and wine_server_free_struct_sd.

---
 dlls/ntdll/file.c       |  4 +--
 dlls/ntdll/ntdll.spec   |  2 ++
 dlls/ntdll/ntdll_misc.h |  5 ---
 dlls/ntdll/server.c     | 72 +++++++++++++++++++++++++++++++++++++++++
 dlls/ntdll/sync.c       | 86 +++++--------------------------------------------
 dlls/ntdll/virtual.c    |  4 +--
 include/wine/server.h   |  6 ++++
 7 files changed, 92 insertions(+), 87 deletions(-)

diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index d2efcc1..613410e 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -164,7 +164,7 @@ static NTSTATUS FILE_CreateFile( PHANDLE handle, ACCESS_MASK access, POBJECT_ATT
 
         objattr.rootdir = wine_server_obj_handle( attr->RootDirectory );
         objattr.name_len = 0;
-        io->u.Status = NTDLL_create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
+        io->u.Status = wine_server_create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
         if (io->u.Status != STATUS_SUCCESS)
         {
             RtlFreeAnsiString( &unix_name );
@@ -186,7 +186,7 @@ static NTSTATUS FILE_CreateFile( PHANDLE handle, ACCESS_MASK access, POBJECT_ATT
             *handle = wine_server_ptr_handle( reply->handle );
         }
         SERVER_END_REQ;
-        NTDLL_free_struct_sd( sd );
+        wine_server_free_struct_sd( sd );
         RtlFreeAnsiString( &unix_name );
     }
     else WARN("%s not found (%x)\n", debugstr_us(attr->ObjectName), io->u.Status );
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index 5bac269..80cdea7 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -1416,6 +1416,8 @@
 @ cdecl wine_server_release_fd(long long)
 @ cdecl wine_server_send_fd(long)
 @ cdecl __wine_make_process_system()
+@ cdecl wine_server_create_struct_sd(ptr ptr ptr)
+@ cdecl wine_server_free_struct_sd(ptr)
 
 # Version
 @ cdecl wine_get_version() NTDLL_wine_get_version
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index 4370084..c66d7f2 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -97,11 +97,6 @@ extern int server_get_unix_fd( HANDLE handle, unsigned int access, int *unix_fd,
                                int *needs_close, enum server_fd_type *type, unsigned int *options ) DECLSPEC_HIDDEN;
 extern int server_pipe( int fd[2] ) DECLSPEC_HIDDEN;
 
-/* security descriptors */
-NTSTATUS NTDLL_create_struct_sd(PSECURITY_DESCRIPTOR nt_sd, struct security_descriptor **server_sd,
-                                data_size_t *server_sd_len) DECLSPEC_HIDDEN;
-void NTDLL_free_struct_sd(struct security_descriptor *server_sd) DECLSPEC_HIDDEN;
-
 /* module handling */
 extern LIST_ENTRY tls_links DECLSPEC_HIDDEN;
 extern NTSTATUS MODULE_DllThreadAttach( LPVOID lpReserved ) DECLSPEC_HIDDEN;
diff --git a/dlls/ntdll/server.c b/dlls/ntdll/server.c
index f3c6b38..099213f 100644
--- a/dlls/ntdll/server.c
+++ b/dlls/ntdll/server.c
@@ -1498,3 +1498,75 @@ size_t server_init_thread( void *entry_point )
         server_protocol_error( "init_thread failed with status %x\n", ret );
     }
 }
+
+
+/* creates a struct security_descriptor and contained information in one contiguous piece of memory */
+NTSTATUS CDECL wine_server_create_struct_sd(PSECURITY_DESCRIPTOR nt_sd, 
+                                            struct security_descriptor **server_sd,
+                                            data_size_t *server_sd_len)
+{
+    unsigned int len;
+    PSID owner, group;
+    ACL *dacl, *sacl;
+    BOOLEAN owner_present, group_present, dacl_present, sacl_present;
+    BOOLEAN defaulted;
+    NTSTATUS status;
+    unsigned char *ptr;
+
+    if (!nt_sd)
+    {
+        *server_sd = NULL;
+        *server_sd_len = 0;
+        return STATUS_SUCCESS;
+    }
+
+    len = sizeof(struct security_descriptor);
+
+    status = RtlGetOwnerSecurityDescriptor(nt_sd, &owner, &owner_present);
+    if (status != STATUS_SUCCESS) return status;
+    status = RtlGetGroupSecurityDescriptor(nt_sd, &group, &group_present);
+    if (status != STATUS_SUCCESS) return status;
+    status = RtlGetSaclSecurityDescriptor(nt_sd, &sacl_present, &sacl, &defaulted);
+    if (status != STATUS_SUCCESS) return status;
+    status = RtlGetDaclSecurityDescriptor(nt_sd, &dacl_present, &dacl, &defaulted);
+    if (status != STATUS_SUCCESS) return status;
+
+    if (owner_present)
+        len += RtlLengthSid(owner);
+    if (group_present)
+        len += RtlLengthSid(group);
+    if (sacl_present && sacl)
+        len += sacl->AclSize;
+    if (dacl_present && dacl)
+        len += dacl->AclSize;
+
+    /* fix alignment for the Unicode name that follows the structure */
+    len = (len + sizeof(WCHAR) - 1) & ~(sizeof(WCHAR) - 1);
+    *server_sd = RtlAllocateHeap(GetProcessHeap(), 0, len);
+    if (!*server_sd) return STATUS_NO_MEMORY;
+
+    (*server_sd)->control = ((SECURITY_DESCRIPTOR *)nt_sd)->Control & ~SE_SELF_RELATIVE;
+    (*server_sd)->owner_len = owner_present ? RtlLengthSid(owner) : 0;
+    (*server_sd)->group_len = group_present ? RtlLengthSid(group) : 0;
+    (*server_sd)->sacl_len = (sacl_present && sacl) ? sacl->AclSize : 0;
+    (*server_sd)->dacl_len = (dacl_present && dacl) ? dacl->AclSize : 0;
+
+    ptr = (unsigned char *)(*server_sd + 1);
+    memcpy(ptr, owner, (*server_sd)->owner_len);
+    ptr += (*server_sd)->owner_len;
+    memcpy(ptr, group, (*server_sd)->group_len);
+    ptr += (*server_sd)->group_len;
+    memcpy(ptr, sacl, (*server_sd)->sacl_len);
+    ptr += (*server_sd)->sacl_len;
+    memcpy(ptr, dacl, (*server_sd)->dacl_len);
+
+    *server_sd_len = len;
+
+    return STATUS_SUCCESS;
+}
+
+/* frees a struct security_descriptor allocated by wine_server_create_struct_sd */
+void CDECL wine_server_free_struct_sd(struct security_descriptor *server_sd)
+{
+    RtlFreeHeap(GetProcessHeap(), 0, server_sd);
+}
diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c
index 7c9d5e8..93be438 100644
--- a/dlls/ntdll/sync.c
+++ b/dlls/ntdll/sync.c
@@ -74,76 +74,6 @@ static inline int interlocked_dec_if_nonzero( int *dest )
     return val;
 }
 
-/* creates a struct security_descriptor and contained information in one contiguous piece of memory */
-NTSTATUS NTDLL_create_struct_sd(PSECURITY_DESCRIPTOR nt_sd, struct security_descriptor **server_sd,
-                                data_size_t *server_sd_len)
-{
-    unsigned int len;
-    PSID owner, group;
-    ACL *dacl, *sacl;
-    BOOLEAN owner_present, group_present, dacl_present, sacl_present;
-    BOOLEAN defaulted;
-    NTSTATUS status;
-    unsigned char *ptr;
-
-    if (!nt_sd)
-    {
-        *server_sd = NULL;
-        *server_sd_len = 0;
-        return STATUS_SUCCESS;
-    }
-
-    len = sizeof(struct security_descriptor);
-
-    status = RtlGetOwnerSecurityDescriptor(nt_sd, &owner, &owner_present);
-    if (status != STATUS_SUCCESS) return status;
-    status = RtlGetGroupSecurityDescriptor(nt_sd, &group, &group_present);
-    if (status != STATUS_SUCCESS) return status;
-    status = RtlGetSaclSecurityDescriptor(nt_sd, &sacl_present, &sacl, &defaulted);
-    if (status != STATUS_SUCCESS) return status;
-    status = RtlGetDaclSecurityDescriptor(nt_sd, &dacl_present, &dacl, &defaulted);
-    if (status != STATUS_SUCCESS) return status;
-
-    if (owner_present)
-        len += RtlLengthSid(owner);
-    if (group_present)
-        len += RtlLengthSid(group);
-    if (sacl_present && sacl)
-        len += sacl->AclSize;
-    if (dacl_present && dacl)
-        len += dacl->AclSize;
-
-    /* fix alignment for the Unicode name that follows the structure */
-    len = (len + sizeof(WCHAR) - 1) & ~(sizeof(WCHAR) - 1);
-    *server_sd = RtlAllocateHeap(GetProcessHeap(), 0, len);
-    if (!*server_sd) return STATUS_NO_MEMORY;
-
-    (*server_sd)->control = ((SECURITY_DESCRIPTOR *)nt_sd)->Control & ~SE_SELF_RELATIVE;
-    (*server_sd)->owner_len = owner_present ? RtlLengthSid(owner) : 0;
-    (*server_sd)->group_len = group_present ? RtlLengthSid(group) : 0;
-    (*server_sd)->sacl_len = (sacl_present && sacl) ? sacl->AclSize : 0;
-    (*server_sd)->dacl_len = (dacl_present && dacl) ? dacl->AclSize : 0;
-
-    ptr = (unsigned char *)(*server_sd + 1);
-    memcpy(ptr, owner, (*server_sd)->owner_len);
-    ptr += (*server_sd)->owner_len;
-    memcpy(ptr, group, (*server_sd)->group_len);
-    ptr += (*server_sd)->group_len;
-    memcpy(ptr, sacl, (*server_sd)->sacl_len);
-    ptr += (*server_sd)->sacl_len;
-    memcpy(ptr, dacl, (*server_sd)->dacl_len);
-
-    *server_sd_len = len;
-
-    return STATUS_SUCCESS;
-}
-
-/* frees a struct security_descriptor allocated by NTDLL_create_struct_sd */
-void NTDLL_free_struct_sd(struct security_descriptor *server_sd)
-{
-    RtlFreeHeap(GetProcessHeap(), 0, server_sd);
-}
-
 /*
  *	Semaphores
  */
@@ -171,7 +101,7 @@ NTSTATUS WINAPI NtCreateSemaphore( OUT PHANDLE SemaphoreHandle,
     objattr.name_len = len;
     if (attr)
     {
-        ret = NTDLL_create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
+        ret = wine_server_create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
         if (ret != STATUS_SUCCESS) return ret;
     }
 
@@ -189,7 +119,7 @@ NTSTATUS WINAPI NtCreateSemaphore( OUT PHANDLE SemaphoreHandle,
     }
     SERVER_END_REQ;
 
-    NTDLL_free_struct_sd( sd );
+    wine_server_free_struct_sd( sd );
 
     return ret;
 }
@@ -293,7 +223,7 @@ NTSTATUS WINAPI NtCreateEvent( PHANDLE EventHandle, ACCESS_MASK DesiredAccess,
     objattr.name_len = len;
     if (attr)
     {
-        ret = NTDLL_create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
+        ret = wine_server_create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
         if (ret != STATUS_SUCCESS) return ret;
     }
 
@@ -311,7 +241,7 @@ NTSTATUS WINAPI NtCreateEvent( PHANDLE EventHandle, ACCESS_MASK DesiredAccess,
     }
     SERVER_END_REQ;
 
-    NTDLL_free_struct_sd( sd );
+    wine_server_free_struct_sd( sd );
 
     return ret;
 }
@@ -476,7 +406,7 @@ NTSTATUS WINAPI NtCreateMutant(OUT HANDLE* MutantHandle,
     objattr.name_len = len;
     if (attr)
     {
-        status = NTDLL_create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
+        status = wine_server_create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
         if (status != STATUS_SUCCESS) return status;
     }
 
@@ -493,7 +423,7 @@ NTSTATUS WINAPI NtCreateMutant(OUT HANDLE* MutantHandle,
     }
     SERVER_END_REQ;
 
-    NTDLL_free_struct_sd( sd );
+    wine_server_free_struct_sd( sd );
 
     return status;
 }
@@ -967,7 +897,7 @@ NTSTATUS WINAPI NtCreateKeyedEvent( HANDLE *handle, ACCESS_MASK access,
     objattr.name_len = len;
     if (attr)
     {
-        ret = NTDLL_create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
+        ret = wine_server_create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
         if (ret != STATUS_SUCCESS) return ret;
     }
 
@@ -983,7 +913,7 @@ NTSTATUS WINAPI NtCreateKeyedEvent( HANDLE *handle, ACCESS_MASK access,
     }
     SERVER_END_REQ;
 
-    NTDLL_free_struct_sd( sd );
+    wine_server_free_struct_sd( sd );
     return ret;
 }
 
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 4819d2d..7983a7a 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -2409,7 +2409,7 @@ NTSTATUS WINAPI NtCreateSection( HANDLE *handle, ACCESS_MASK access, const OBJEC
     objattr.name_len = len;
     if (attr)
     {
-        ret = NTDLL_create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
+        ret = wine_server_create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
         if (ret != STATUS_SUCCESS) return ret;
     }
 
@@ -2434,7 +2434,7 @@ NTSTATUS WINAPI NtCreateSection( HANDLE *handle, ACCESS_MASK access, const OBJEC
     }
     SERVER_END_REQ;
 
-    NTDLL_free_struct_sd( sd );
+    wine_server_free_struct_sd( sd );
 
     return ret;
 }
diff --git a/include/wine/server.h b/include/wine/server.h
index d573d1f..d84cd67 100644
--- a/include/wine/server.h
+++ b/include/wine/server.h
@@ -54,6 +54,12 @@ extern void CDECL wine_server_send_fd( int fd );
 extern int CDECL wine_server_fd_to_handle( int fd, unsigned int access, unsigned int attributes, HANDLE *handle );
 extern int CDECL wine_server_handle_to_fd( HANDLE handle, unsigned int access, int *unix_fd, unsigned int *options );
 extern void CDECL wine_server_release_fd( HANDLE handle, int unix_fd );
+/* security descriptors */
+extern NTSTATUS CDECL wine_server_create_struct_sd(PSECURITY_DESCRIPTOR nt_sd,
+                                                   struct security_descriptor **server_sd,
+                                                   data_size_t *server_sd_len);
+extern void CDECL wine_server_free_struct_sd(struct security_descriptor *server_sd);
+
 
 /* do a server call and set the last error code */
 static inline unsigned int wine_server_call_err( void *req_ptr )
-- 
1.8.1.msysgit.1



More information about the wine-patches mailing list