summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/Windows/SecurityUtils.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2023-12-06 07:58:49 +1100
committer Vas Crabb <vas@vastheman.com>2023-12-06 07:58:49 +1100
commit79bef1e23049fdac25f1fefd132e0b6c7d2cc3a1 (patch)
tree643e9313fe86f583c4022c338677cbc12b761df7 /3rdparty/lzma/CPP/Windows/SecurityUtils.cpp
parent512ccf0c7c9b4f08e41038b2ed2de220e140385b (diff)
3rdparty/lzma: Updated to version 23.01.
Diffstat (limited to '3rdparty/lzma/CPP/Windows/SecurityUtils.cpp')
-rw-r--r--3rdparty/lzma/CPP/Windows/SecurityUtils.cpp38
1 files changed, 18 insertions, 20 deletions
diff --git a/3rdparty/lzma/CPP/Windows/SecurityUtils.cpp b/3rdparty/lzma/CPP/Windows/SecurityUtils.cpp
index ede83faf565..d4282d070c2 100644
--- a/3rdparty/lzma/CPP/Windows/SecurityUtils.cpp
+++ b/3rdparty/lzma/CPP/Windows/SecurityUtils.cpp
@@ -4,9 +4,6 @@
#include "SecurityUtils.h"
-#define MY_CAST_FUNC (void(*)())
-// #define MY_CAST_FUNC
-
namespace NWindows {
namespace NSecurity {
@@ -35,7 +32,7 @@ bool MyLookupAccountSid(LPCTSTR systemName, PSID sid,
static void SetLsaString(LPWSTR src, PLSA_UNICODE_STRING dest)
{
- size_t len = (size_t)wcslen(src);
+ const size_t len = (size_t)wcslen(src);
dest->Length = (USHORT)(len * sizeof(WCHAR));
dest->MaximumLength = (USHORT)((len + 1) * sizeof(WCHAR));
dest->Buffer = src;
@@ -72,13 +69,14 @@ typedef BOOL (WINAPI * Func_LookupAccountNameW)(
static PSID GetSid(LPWSTR accountName)
{
#ifndef _UNICODE
- HMODULE hModule = GetModuleHandle(TEXT("Advapi32.dll"));
- if (hModule == NULL)
+ const HMODULE hModule = GetModuleHandle(TEXT("advapi32.dll"));
+ if (!hModule)
return NULL;
- Func_LookupAccountNameW lookupAccountNameW = (Func_LookupAccountNameW)
- MY_CAST_FUNC
- GetProcAddress(hModule, "LookupAccountNameW");
- if (lookupAccountNameW == NULL)
+ const
+ Func_LookupAccountNameW lookupAccountNameW = Z7_GET_PROC_ADDRESS(
+ Func_LookupAccountNameW, hModule,
+ "LookupAccountNameW");
+ if (!lookupAccountNameW)
return NULL;
#endif
@@ -88,21 +86,21 @@ static PSID GetSid(LPWSTR accountName)
#ifdef _UNICODE
::LookupAccountNameW
#else
- lookupAccountNameW
+ lookupAccountNameW
#endif
- (NULL, accountName, NULL, &sidLen, NULL, &domainLen, &sidNameUse))
+ (NULL, accountName, NULL, &sidLen, NULL, &domainLen, &sidNameUse))
{
if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
- PSID pSid = ::HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sidLen);
+ const PSID pSid = ::HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sidLen);
LPWSTR domainName = (LPWSTR)::HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (domainLen + 1) * sizeof(WCHAR));
- BOOL res =
+ const BOOL res =
#ifdef _UNICODE
::LookupAccountNameW
#else
- lookupAccountNameW
+ lookupAccountNameW
#endif
- (NULL, accountName, pSid, &sidLen, domainName, &domainLen, &sidNameUse);
+ (NULL, accountName, pSid, &sidLen, domainName, &domainLen, &sidNameUse);
::HeapFree(GetProcessHeap(), 0, domainName);
if (res)
return pSid;
@@ -111,7 +109,7 @@ static PSID GetSid(LPWSTR accountName)
return NULL;
}
-#define MY__SE_LOCK_MEMORY_NAME L"SeLockMemoryPrivilege"
+#define Z7_WIN_SE_LOCK_MEMORY_NAME L"SeLockMemoryPrivilege"
bool AddLockMemoryPrivilege()
{
@@ -131,13 +129,13 @@ bool AddLockMemoryPrivilege()
!= 0)
return false;
LSA_UNICODE_STRING userRights;
- wchar_t s[128] = MY__SE_LOCK_MEMORY_NAME;
+ wchar_t s[128] = Z7_WIN_SE_LOCK_MEMORY_NAME;
SetLsaString(s, &userRights);
WCHAR userName[256 + 2];
DWORD size = 256;
if (!GetUserNameW(userName, &size))
return false;
- PSID psid = GetSid(userName);
+ const PSID psid = GetSid(userName);
if (psid == NULL)
return false;
bool res = false;
@@ -176,7 +174,7 @@ bool AddLockMemoryPrivilege()
res = true;
}
*/
- NTSTATUS status = policy.AddAccountRights(psid, &userRights);
+ const NTSTATUS status = policy.AddAccountRights(psid, &userRights);
if (status == 0)
res = true;
// ULONG res = LsaNtStatusToWinError(status);