Skip to content

Commit 0de5b98

Browse files
m417zjanwilmans
authored andcommitted
Add necessary permissions for packaged applications
1 parent 8a80229 commit 0de5b98

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

application/DebugViewppLib/DBWinReader.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ DBWinReader::DBWinReader(Timer& timer, ILineBuffer& linebuffer, bool global) :
4343
SetDescription(global ? L"Global Win32 Messages" : L"Win32 Messages");
4444

4545
//Option 1:
46-
//Win32::AdjustObjectDACL(m_hBuffer.get());
47-
//Win32::AdjustObjectDACL(m_dbWinBufferReady.get());
48-
//Win32::AdjustObjectDACL(m_dbWinDataReady.get());
46+
Win32::AdjustObjectDACL(m_hBuffer.get());
47+
Win32::AdjustObjectDACL(m_dbWinBufferReady.get());
48+
Win32::AdjustObjectDACL(m_dbWinDataReady.get());
4949

5050
//Option 2:
51-
Win32::DeleteObjectDACL(m_hBuffer.get());
52-
Win32::DeleteObjectDACL(m_dbWinBufferReady.get());
53-
Win32::DeleteObjectDACL(m_dbWinDataReady.get());
51+
//Win32::DeleteObjectDACL(m_hBuffer.get());
52+
//Win32::DeleteObjectDACL(m_dbWinBufferReady.get());
53+
//Win32::DeleteObjectDACL(m_dbWinDataReady.get());
5454

5555
// TODO(jan): Please test this and choose one
5656

application/Win32Lib/Win32Lib.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ void DeleteObjectDACL(HANDLE hObject)
307307
}
308308

309309
//add necessary permissions for "Authenticated Users" group (all non-anonymous users)
310+
//and for "All Application Packages", "All Restricted Application Packages" for UWP support
310311
void AdjustObjectDACL(HANDLE hObject)
311312
{
312313
ACL* pOldDACL;
@@ -317,20 +318,41 @@ void AdjustObjectDACL(HANDLE hObject)
317318
SID_IDENTIFIER_AUTHORITY authNt = SECURITY_NT_AUTHORITY;
318319
AllocateAndInitializeSid(&authNt, 1, SECURITY_AUTHENTICATED_USER_RID, 0, 0, 0, 0, 0, 0, 0, &pSid);
319320

320-
EXPLICIT_ACCESS ea = {};
321-
ea.grfAccessMode = GRANT_ACCESS;
322-
ea.grfAccessPermissions = GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE;
323-
ea.grfInheritance = NO_INHERITANCE;
324-
ea.Trustee.TrusteeType = TRUSTEE_IS_GROUP;
325-
ea.Trustee.TrusteeForm = TRUSTEE_IS_SID;
326-
ea.Trustee.ptstrName = static_cast<LPTSTR>(pSid);
321+
PSID pAnyPackageSid = nullptr;
322+
SID_IDENTIFIER_AUTHORITY SIDAuthAppPackage = SECURITY_APP_PACKAGE_AUTHORITY;
323+
AllocateAndInitializeSid(&SIDAuthAppPackage, SECURITY_BUILTIN_APP_PACKAGE_RID_COUNT,
324+
SECURITY_APP_PACKAGE_BASE_RID, SECURITY_BUILTIN_PACKAGE_ANY_PACKAGE,
325+
0, 0, 0, 0, 0, 0,
326+
&pAnyPackageSid);
327+
328+
PSID pAnyRestrictedPackageSid = nullptr;
329+
AllocateAndInitializeSid(&SIDAuthAppPackage, SECURITY_BUILTIN_APP_PACKAGE_RID_COUNT,
330+
SECURITY_APP_PACKAGE_BASE_RID, SECURITY_BUILTIN_PACKAGE_ANY_RESTRICTED_PACKAGE,
331+
0, 0, 0, 0, 0, 0,
332+
&pAnyRestrictedPackageSid);
333+
334+
EXPLICIT_ACCESS ea[3] = {};
335+
for (auto& item : ea)
336+
{
337+
item.grfAccessMode = GRANT_ACCESS;
338+
item.grfAccessPermissions = GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE;
339+
item.grfInheritance = NO_INHERITANCE;
340+
item.Trustee.TrusteeType = TRUSTEE_IS_GROUP;
341+
item.Trustee.TrusteeForm = TRUSTEE_IS_SID;
342+
}
343+
344+
ea[0].Trustee.ptstrName = static_cast<LPTSTR>(pSid);
345+
ea[1].Trustee.ptstrName = static_cast<LPTSTR>(pAnyPackageSid);
346+
ea[2].Trustee.ptstrName = static_cast<LPTSTR>(pAnyRestrictedPackageSid);
327347

328348
ACL* pNewDACL = nullptr;
329-
SetEntriesInAcl(1, &ea, pOldDACL, &pNewDACL);
349+
SetEntriesInAcl(std::size(ea), ea, pOldDACL, &pNewDACL);
330350

331351
Win32::SetSecurityInfo(hObject, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, nullptr, nullptr, pNewDACL, nullptr);
332352

333353
FreeSid(pSid);
354+
FreeSid(pAnyPackageSid);
355+
FreeSid(pAnyRestrictedPackageSid);
334356
LocalFree(pNewDACL);
335357
LocalFree(pSD);
336358
}

0 commit comments

Comments
 (0)