From bf6d5fc66b21a8b9a65121b3bd8dfa89c8e97acb Mon Sep 17 00:00:00 2001 From: Troy Rollo <wine@troy.rollo.name> Date: Sat, 5 Mar 2005 10:46:34 +0000 Subject: [PATCH] Make GetFileSecurityW return a standard SECURITY_DESCRIPTOR instead of an uninitialised (and invalid) one. --- dlls/advapi32/security.c | 78 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c index 6b12d94e5eb..11ccfbe738c 100644 --- a/dlls/advapi32/security.c +++ b/dlls/advapi32/security.c @@ -57,6 +57,8 @@ typedef struct _ACEFLAG DWORD value; } ACEFLAG, *LPACEFLAG; +static SID const sidWorld = { SID_REVISION, 1, { SECURITY_WORLD_SID_AUTHORITY} , { SECURITY_WORLD_RID } }; + /* * ACE access rights */ @@ -111,6 +113,25 @@ static void dumpLsaAttributes( PLSA_OBJECT_ATTRIBUTES oa ) } } +#define WINE_SIZE_OF_WORLD_ACCESS_ACL (sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD)) + +static void GetWorldAccessACL(PACL pACL) +{ + PACCESS_ALLOWED_ACE pACE = (PACCESS_ALLOWED_ACE) (pACL + 1); + + pACL->AclRevision = ACL_REVISION; + pACL->Sbz1 = 0; + pACL->AclSize = WINE_SIZE_OF_WORLD_ACCESS_ACL; + pACL->AceCount = 1; + pACL->Sbz2 = 0; + + pACE->Header.AceType = ACCESS_ALLOWED_ACE_TYPE; + pACE->Header.AceFlags = CONTAINER_INHERIT_ACE; + pACE->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD); + pACE->Mask = 0xf3ffffff; /* Everything except reserved bits */ + memcpy(&pACE->SidStart, &sidWorld, sizeof(sidWorld)); +} + /************************************************************ * ADVAPI_IsLocalComputer * @@ -1297,8 +1318,61 @@ GetFileSecurityW( LPCWSTR lpFileName, PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength, LPDWORD lpnLengthNeeded ) { - FIXME("(%s) : stub\n", debugstr_w(lpFileName) ); - return TRUE; + DWORD nNeeded; + LPBYTE pBuffer; + DWORD iLocNow; + SECURITY_DESCRIPTOR_RELATIVE *pSDRelative; + + FIXME("(%s) : returns fake SECURITY_DESCRIPTOR\n", debugstr_w(lpFileName) ); + + nNeeded = sizeof(SECURITY_DESCRIPTOR_RELATIVE); + if (RequestedInformation & OWNER_SECURITY_INFORMATION) + nNeeded += sizeof(sidWorld); + if (RequestedInformation & GROUP_SECURITY_INFORMATION) + nNeeded += sizeof(sidWorld); + if (RequestedInformation & DACL_SECURITY_INFORMATION) + nNeeded += WINE_SIZE_OF_WORLD_ACCESS_ACL; + if (RequestedInformation & SACL_SECURITY_INFORMATION) + nNeeded += WINE_SIZE_OF_WORLD_ACCESS_ACL; + + *lpnLengthNeeded = nNeeded; + + if (nNeeded > nLength) + return TRUE; + + if (!InitializeSecurityDescriptor(pSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION)) + return FALSE; + + pSDRelative = (PISECURITY_DESCRIPTOR_RELATIVE) pSecurityDescriptor; + pSDRelative->Control |= SE_SELF_RELATIVE; + pBuffer = (LPBYTE) pSDRelative; + iLocNow = sizeof(SECURITY_DESCRIPTOR_RELATIVE); + + if (RequestedInformation & OWNER_SECURITY_INFORMATION) + { + memcpy(pBuffer + iLocNow, &sidWorld, sizeof(sidWorld)); + pSDRelative->Owner = iLocNow; + iLocNow += sizeof(sidWorld); + } + if (RequestedInformation & GROUP_SECURITY_INFORMATION) + { + memcpy(pBuffer + iLocNow, &sidWorld, sizeof(sidWorld)); + pSDRelative->Group = iLocNow; + iLocNow += sizeof(sidWorld); + } + if (RequestedInformation & DACL_SECURITY_INFORMATION) + { + GetWorldAccessACL((PACL) (pBuffer + iLocNow)); + pSDRelative->Dacl = iLocNow; + iLocNow += WINE_SIZE_OF_WORLD_ACCESS_ACL; + } + if (RequestedInformation & SACL_SECURITY_INFORMATION) + { + GetWorldAccessACL((PACL) (pBuffer + iLocNow)); + pSDRelative->Sacl = iLocNow; + /* iLocNow += WINE_SIZE_OF_WORLD_ACCESS_ACL; */ + } + return TRUE; } -- 2.24.1