mirror of
https://github.com/reactos/reactos
synced 2025-10-06 00:12:51 +02:00
[MSGINA] Move some utility functions to a separate utils.c file (#8370)
- Registry-value getters; string copy functions. - ReadRegSzValue(): Use a meaningful error value when the value type isn't the expected one. - Rename `DuplicationString` -> `DuplicateString`
This commit is contained in:
@@ -7,7 +7,8 @@ list(APPEND SOURCE
|
||||
msgina.c
|
||||
shutdown.c
|
||||
stubs.c
|
||||
tui.c)
|
||||
tui.c
|
||||
utils.c)
|
||||
|
||||
list(APPEND PCH_SKIP_SOURCE
|
||||
dimmedwindow.cpp
|
||||
|
@@ -56,64 +56,6 @@ WlxNegotiate(
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
LONG
|
||||
ReadRegSzValue(
|
||||
IN HKEY hKey,
|
||||
IN LPCWSTR pszValue,
|
||||
OUT LPWSTR* pValue)
|
||||
{
|
||||
LONG rc;
|
||||
DWORD dwType;
|
||||
DWORD cbData = 0;
|
||||
LPWSTR Value;
|
||||
|
||||
if (!pValue)
|
||||
return ERROR_INVALID_PARAMETER;
|
||||
|
||||
*pValue = NULL;
|
||||
rc = RegQueryValueExW(hKey, pszValue, NULL, &dwType, NULL, &cbData);
|
||||
if (rc != ERROR_SUCCESS)
|
||||
return rc;
|
||||
if (dwType != REG_SZ)
|
||||
return ERROR_FILE_NOT_FOUND;
|
||||
Value = HeapAlloc(GetProcessHeap(), 0, cbData + sizeof(WCHAR));
|
||||
if (!Value)
|
||||
return ERROR_NOT_ENOUGH_MEMORY;
|
||||
rc = RegQueryValueExW(hKey, pszValue, NULL, NULL, (LPBYTE)Value, &cbData);
|
||||
if (rc != ERROR_SUCCESS)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, Value);
|
||||
return rc;
|
||||
}
|
||||
/* NULL-terminate the string */
|
||||
Value[cbData / sizeof(WCHAR)] = '\0';
|
||||
|
||||
*pValue = Value;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
static LONG
|
||||
ReadRegDwordValue(
|
||||
IN HKEY hKey,
|
||||
IN LPCWSTR pszValue,
|
||||
OUT LPDWORD pValue)
|
||||
{
|
||||
LONG rc;
|
||||
DWORD dwType;
|
||||
DWORD cbData;
|
||||
DWORD dwValue;
|
||||
|
||||
if (!pValue)
|
||||
return ERROR_INVALID_PARAMETER;
|
||||
|
||||
cbData = sizeof(DWORD);
|
||||
rc = RegQueryValueExW(hKey, pszValue, NULL, &dwType, (LPBYTE)&dwValue, &cbData);
|
||||
if (rc == ERROR_SUCCESS && dwType == REG_DWORD)
|
||||
*pValue = dwValue;
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
static VOID
|
||||
ChooseGinaUI(VOID)
|
||||
{
|
||||
@@ -692,20 +634,6 @@ WlxRemoveStatusMessage(
|
||||
return pGinaUI->RemoveStatusMessage(pgContext);
|
||||
}
|
||||
|
||||
static PWSTR
|
||||
DuplicationString(PWSTR Str)
|
||||
{
|
||||
DWORD cb;
|
||||
PWSTR NewStr;
|
||||
|
||||
if (Str == NULL) return NULL;
|
||||
|
||||
cb = (wcslen(Str) + 1) * sizeof(WCHAR);
|
||||
if ((NewStr = LocalAlloc(LMEM_FIXED, cb)))
|
||||
memcpy(NewStr, Str, cb);
|
||||
return NewStr;
|
||||
}
|
||||
|
||||
|
||||
BOOL
|
||||
DoAdminUnlock(
|
||||
@@ -959,9 +887,9 @@ CreateProfile(
|
||||
}
|
||||
|
||||
*pgContext->pAuthenticationId = Stats.AuthenticationId;
|
||||
pgContext->pMprNotifyInfo->pszUserName = DuplicationString(UserName);
|
||||
pgContext->pMprNotifyInfo->pszDomain = DuplicationString(Domain);
|
||||
pgContext->pMprNotifyInfo->pszPassword = DuplicationString(Password);
|
||||
pgContext->pMprNotifyInfo->pszUserName = DuplicateString(UserName);
|
||||
pgContext->pMprNotifyInfo->pszDomain = DuplicateString(Domain);
|
||||
pgContext->pMprNotifyInfo->pszPassword = DuplicateString(Password);
|
||||
pgContext->pMprNotifyInfo->pszOldPassword = NULL;
|
||||
*pgContext->pdwOptions = 0;
|
||||
*pgContext->pProfile = pProfile;
|
||||
|
@@ -99,12 +99,6 @@ MyLogonUser(
|
||||
|
||||
/* msgina.c */
|
||||
|
||||
LONG
|
||||
ReadRegSzValue(
|
||||
IN HKEY hKey,
|
||||
IN LPCWSTR pszValue,
|
||||
OUT LPWSTR *pValue);
|
||||
|
||||
BOOL
|
||||
DoAdminUnlock(
|
||||
IN PGINA_CONTEXT pgContext,
|
||||
@@ -150,6 +144,24 @@ ShutdownDialog(
|
||||
IN DWORD ShutdownOptions,
|
||||
IN PGINA_CONTEXT pgContext);
|
||||
|
||||
/* utils.c */
|
||||
|
||||
LONG
|
||||
ReadRegSzValue(
|
||||
_In_ HKEY hKey,
|
||||
_In_ PCWSTR pszValue,
|
||||
_Out_ PWSTR* pValue);
|
||||
|
||||
LONG
|
||||
ReadRegDwordValue(
|
||||
_In_ HKEY hKey,
|
||||
_In_ PCWSTR pszValue,
|
||||
_Out_ PDWORD pValue);
|
||||
|
||||
PWSTR
|
||||
DuplicateString(
|
||||
_In_opt_ PCWSTR Str);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
79
dll/win32/msgina/utils.c
Normal file
79
dll/win32/msgina/utils.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* PROJECT: ReactOS Logon GINA DLL msgina.dll
|
||||
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
|
||||
* PURPOSE: Miscellaneous utility functions.
|
||||
* COPYRIGHT: Copyright 2006 Hervé Poussineau <hpoussin@reactos.org>
|
||||
* Copyright 2014 Eric Kohl <eric.kohl@reactos.org>
|
||||
* Copyright 2025 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
|
||||
*/
|
||||
|
||||
#include "msgina.h"
|
||||
|
||||
LONG
|
||||
ReadRegSzValue(
|
||||
_In_ HKEY hKey,
|
||||
_In_ PCWSTR pszValue,
|
||||
_Out_ PWSTR* pValue)
|
||||
{
|
||||
LONG rc;
|
||||
DWORD dwType;
|
||||
DWORD cbData = 0;
|
||||
PWSTR Value;
|
||||
|
||||
*pValue = NULL;
|
||||
rc = RegQueryValueExW(hKey, pszValue, NULL, &dwType, NULL, &cbData);
|
||||
if (rc != ERROR_SUCCESS)
|
||||
return rc;
|
||||
if (dwType != REG_SZ)
|
||||
return ERROR_UNSUPPORTED_TYPE;
|
||||
Value = HeapAlloc(GetProcessHeap(), 0, cbData + sizeof(WCHAR));
|
||||
if (!Value)
|
||||
return ERROR_NOT_ENOUGH_MEMORY;
|
||||
rc = RegQueryValueExW(hKey, pszValue, NULL, NULL, (PBYTE)Value, &cbData);
|
||||
if (rc != ERROR_SUCCESS)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, Value);
|
||||
return rc;
|
||||
}
|
||||
/* NULL-terminate the string */
|
||||
Value[cbData / sizeof(WCHAR)] = UNICODE_NULL;
|
||||
|
||||
*pValue = Value;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
LONG
|
||||
ReadRegDwordValue(
|
||||
_In_ HKEY hKey,
|
||||
_In_ PCWSTR pszValue,
|
||||
_Out_ PDWORD pValue)
|
||||
{
|
||||
LONG rc;
|
||||
DWORD dwValue, dwType, cbData;
|
||||
|
||||
cbData = sizeof(dwValue);
|
||||
rc = RegQueryValueExW(hKey, pszValue, NULL, &dwType, (PBYTE)&dwValue, &cbData);
|
||||
if ((rc == ERROR_SUCCESS) && (dwType == REG_DWORD) && (cbData == sizeof(dwValue)))
|
||||
{
|
||||
*pValue = dwValue;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
PWSTR
|
||||
DuplicateString(
|
||||
_In_opt_ PCWSTR Str)
|
||||
{
|
||||
PWSTR NewStr;
|
||||
SIZE_T cb;
|
||||
|
||||
if (!Str)
|
||||
return NULL;
|
||||
|
||||
cb = (wcslen(Str) + 1) * sizeof(WCHAR);
|
||||
if ((NewStr = LocalAlloc(LMEM_FIXED, cb)))
|
||||
memcpy(NewStr, Str, cb);
|
||||
return NewStr;
|
||||
}
|
Reference in New Issue
Block a user