Skip to content

Add necessary permissions for packaged applications (fixes #365) #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions application/DebugViewppLib/DBWinReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ DBWinReader::DBWinReader(Timer& timer, ILineBuffer& linebuffer, bool global) :
SetDescription(global ? L"Global Win32 Messages" : L"Win32 Messages");

//Option 1:
//Win32::AdjustObjectDACL(m_hBuffer.get());
//Win32::AdjustObjectDACL(m_dbWinBufferReady.get());
//Win32::AdjustObjectDACL(m_dbWinDataReady.get());
Win32::AdjustObjectDACL(m_hBuffer.get());
Win32::AdjustObjectDACL(m_dbWinBufferReady.get());
Win32::AdjustObjectDACL(m_dbWinDataReady.get());

//Option 2:
Win32::DeleteObjectDACL(m_hBuffer.get());
Win32::DeleteObjectDACL(m_dbWinBufferReady.get());
Win32::DeleteObjectDACL(m_dbWinDataReady.get());
//Win32::DeleteObjectDACL(m_hBuffer.get());
//Win32::DeleteObjectDACL(m_dbWinBufferReady.get());
//Win32::DeleteObjectDACL(m_dbWinDataReady.get());

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

Expand Down
38 changes: 30 additions & 8 deletions application/Win32Lib/Win32Lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ void DeleteObjectDACL(HANDLE hObject)
}

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

EXPLICIT_ACCESS ea = {};
ea.grfAccessMode = GRANT_ACCESS;
ea.grfAccessPermissions = GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE;
ea.grfInheritance = NO_INHERITANCE;
ea.Trustee.TrusteeType = TRUSTEE_IS_GROUP;
ea.Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea.Trustee.ptstrName = static_cast<LPTSTR>(pSid);
PSID pAnyPackageSid = nullptr;
SID_IDENTIFIER_AUTHORITY SIDAuthAppPackage = SECURITY_APP_PACKAGE_AUTHORITY;
AllocateAndInitializeSid(&SIDAuthAppPackage, SECURITY_BUILTIN_APP_PACKAGE_RID_COUNT,
SECURITY_APP_PACKAGE_BASE_RID, SECURITY_BUILTIN_PACKAGE_ANY_PACKAGE,
0, 0, 0, 0, 0, 0,
&pAnyPackageSid);

PSID pAnyRestrictedPackageSid = nullptr;
AllocateAndInitializeSid(&SIDAuthAppPackage, SECURITY_BUILTIN_APP_PACKAGE_RID_COUNT,
SECURITY_APP_PACKAGE_BASE_RID, SECURITY_BUILTIN_PACKAGE_ANY_RESTRICTED_PACKAGE,
0, 0, 0, 0, 0, 0,
&pAnyRestrictedPackageSid);

EXPLICIT_ACCESS ea[3] = {};
for (auto& item : ea)
{
item.grfAccessMode = GRANT_ACCESS;
item.grfAccessPermissions = GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE;
item.grfInheritance = NO_INHERITANCE;
item.Trustee.TrusteeType = TRUSTEE_IS_GROUP;
item.Trustee.TrusteeForm = TRUSTEE_IS_SID;
}

ea[0].Trustee.ptstrName = static_cast<LPTSTR>(pSid);
ea[1].Trustee.ptstrName = static_cast<LPTSTR>(pAnyPackageSid);
ea[2].Trustee.ptstrName = static_cast<LPTSTR>(pAnyRestrictedPackageSid);

ACL* pNewDACL = nullptr;
SetEntriesInAcl(1, &ea, pOldDACL, &pNewDACL);
SetEntriesInAcl(std::size(ea), ea, pOldDACL, &pNewDACL);

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

FreeSid(pSid);
FreeSid(pAnyPackageSid);
FreeSid(pAnyRestrictedPackageSid);
LocalFree(pNewDACL);
LocalFree(pSD);
}
Expand Down