mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-22 08:33:12 -05:00
Merge pull request #6173 from PYTHONRETARDE/fix/kqueue-test-deny-sid
test(libkernel): deny the kqueue parent listing to the token user's SID
This commit is contained in:
1 file changed
+11
-5
@@ -9,6 +9,7 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#ifdef _WIN32
|
||||
#include <aclapi.h>
|
||||
#include <windows.h>
|
||||
@@ -539,9 +540,14 @@ static std::string Utf8(const std::wstring& text) {
|
||||
}
|
||||
|
||||
static PACL DenyListing(const std::wstring& directory, PSECURITY_DESCRIPTOR& owner) {
|
||||
wchar_t account[256]{};
|
||||
DWORD count = static_cast<DWORD>(sizeof(account) / sizeof(account[0]));
|
||||
Require(::GetUserNameW(account, &count) != FALSE);
|
||||
HANDLE token = nullptr;
|
||||
Require(::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token) != FALSE);
|
||||
DWORD size = 0;
|
||||
::GetTokenInformation(token, TokenUser, nullptr, 0, &size);
|
||||
std::vector<unsigned char> user(size);
|
||||
const BOOL queried = ::GetTokenInformation(token, TokenUser, user.data(), size, &size);
|
||||
::CloseHandle(token);
|
||||
Require(queried != FALSE);
|
||||
PACL original = nullptr;
|
||||
Require(::GetNamedSecurityInfoW(directory.c_str(), SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,
|
||||
nullptr, nullptr, &original, nullptr, &owner) == ERROR_SUCCESS);
|
||||
@@ -549,9 +555,9 @@ static PACL DenyListing(const std::wstring& directory, PSECURITY_DESCRIPTOR& own
|
||||
denied.grfAccessPermissions = FILE_LIST_DIRECTORY;
|
||||
denied.grfAccessMode = DENY_ACCESS;
|
||||
denied.grfInheritance = NO_INHERITANCE;
|
||||
denied.Trustee.TrusteeForm = TRUSTEE_IS_NAME;
|
||||
denied.Trustee.TrusteeForm = TRUSTEE_IS_SID;
|
||||
denied.Trustee.TrusteeType = TRUSTEE_IS_USER;
|
||||
denied.Trustee.ptstrName = account;
|
||||
denied.Trustee.ptstrName = static_cast<LPWSTR>(reinterpret_cast<TOKEN_USER*>(user.data())->User.Sid);
|
||||
PACL blocked = nullptr;
|
||||
Require(::SetEntriesInAclW(1, &denied, original, &blocked) == ERROR_SUCCESS);
|
||||
const DWORD applied = ::SetNamedSecurityInfoW(const_cast<LPWSTR>(directory.c_str()), SE_FILE_OBJECT,
|
||||
|
||||
Reference in new issue
Block a user