Skip to content

Commit e7073d2

Browse files
committed
[MSGINA] Move some utility functions to a separate utils.c file (reactos#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`
1 parent c6fecdd commit e7073d2

File tree

4 files changed

+102
-82
lines changed

4 files changed

+102
-82
lines changed

dll/win32/msgina/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ list(APPEND SOURCE
77
msgina.c
88
shutdown.c
99
stubs.c
10-
tui.c)
10+
tui.c
11+
utils.c)
1112

1213
list(APPEND PCH_SKIP_SOURCE
1314
dimmedwindow.cpp

dll/win32/msgina/msgina.c

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -56,64 +56,6 @@ WlxNegotiate(
5656
return TRUE;
5757
}
5858

59-
LONG
60-
ReadRegSzValue(
61-
IN HKEY hKey,
62-
IN LPCWSTR pszValue,
63-
OUT LPWSTR* pValue)
64-
{
65-
LONG rc;
66-
DWORD dwType;
67-
DWORD cbData = 0;
68-
LPWSTR Value;
69-
70-
if (!pValue)
71-
return ERROR_INVALID_PARAMETER;
72-
73-
*pValue = NULL;
74-
rc = RegQueryValueExW(hKey, pszValue, NULL, &dwType, NULL, &cbData);
75-
if (rc != ERROR_SUCCESS)
76-
return rc;
77-
if (dwType != REG_SZ)
78-
return ERROR_FILE_NOT_FOUND;
79-
Value = HeapAlloc(GetProcessHeap(), 0, cbData + sizeof(WCHAR));
80-
if (!Value)
81-
return ERROR_NOT_ENOUGH_MEMORY;
82-
rc = RegQueryValueExW(hKey, pszValue, NULL, NULL, (LPBYTE)Value, &cbData);
83-
if (rc != ERROR_SUCCESS)
84-
{
85-
HeapFree(GetProcessHeap(), 0, Value);
86-
return rc;
87-
}
88-
/* NULL-terminate the string */
89-
Value[cbData / sizeof(WCHAR)] = '\0';
90-
91-
*pValue = Value;
92-
return ERROR_SUCCESS;
93-
}
94-
95-
static LONG
96-
ReadRegDwordValue(
97-
IN HKEY hKey,
98-
IN LPCWSTR pszValue,
99-
OUT LPDWORD pValue)
100-
{
101-
LONG rc;
102-
DWORD dwType;
103-
DWORD cbData;
104-
DWORD dwValue;
105-
106-
if (!pValue)
107-
return ERROR_INVALID_PARAMETER;
108-
109-
cbData = sizeof(DWORD);
110-
rc = RegQueryValueExW(hKey, pszValue, NULL, &dwType, (LPBYTE)&dwValue, &cbData);
111-
if (rc == ERROR_SUCCESS && dwType == REG_DWORD)
112-
*pValue = dwValue;
113-
114-
return ERROR_SUCCESS;
115-
}
116-
11759
static VOID
11860
ChooseGinaUI(VOID)
11961
{
@@ -692,20 +634,6 @@ WlxRemoveStatusMessage(
692634
return pGinaUI->RemoveStatusMessage(pgContext);
693635
}
694636

695-
static PWSTR
696-
DuplicationString(PWSTR Str)
697-
{
698-
DWORD cb;
699-
PWSTR NewStr;
700-
701-
if (Str == NULL) return NULL;
702-
703-
cb = (wcslen(Str) + 1) * sizeof(WCHAR);
704-
if ((NewStr = LocalAlloc(LMEM_FIXED, cb)))
705-
memcpy(NewStr, Str, cb);
706-
return NewStr;
707-
}
708-
709637

710638
BOOL
711639
DoAdminUnlock(
@@ -959,9 +887,9 @@ CreateProfile(
959887
}
960888

961889
*pgContext->pAuthenticationId = Stats.AuthenticationId;
962-
pgContext->pMprNotifyInfo->pszUserName = DuplicationString(UserName);
963-
pgContext->pMprNotifyInfo->pszDomain = DuplicationString(Domain);
964-
pgContext->pMprNotifyInfo->pszPassword = DuplicationString(Password);
890+
pgContext->pMprNotifyInfo->pszUserName = DuplicateString(UserName);
891+
pgContext->pMprNotifyInfo->pszDomain = DuplicateString(Domain);
892+
pgContext->pMprNotifyInfo->pszPassword = DuplicateString(Password);
965893
pgContext->pMprNotifyInfo->pszOldPassword = NULL;
966894
*pgContext->pdwOptions = 0;
967895
*pgContext->pProfile = pProfile;

dll/win32/msgina/msgina.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,6 @@ MyLogonUser(
9999

100100
/* msgina.c */
101101

102-
LONG
103-
ReadRegSzValue(
104-
IN HKEY hKey,
105-
IN LPCWSTR pszValue,
106-
OUT LPWSTR *pValue);
107-
108102
BOOL
109103
DoAdminUnlock(
110104
IN PGINA_CONTEXT pgContext,
@@ -150,6 +144,24 @@ ShutdownDialog(
150144
IN DWORD ShutdownOptions,
151145
IN PGINA_CONTEXT pgContext);
152146

147+
/* utils.c */
148+
149+
LONG
150+
ReadRegSzValue(
151+
_In_ HKEY hKey,
152+
_In_ PCWSTR pszValue,
153+
_Out_ PWSTR* pValue);
154+
155+
LONG
156+
ReadRegDwordValue(
157+
_In_ HKEY hKey,
158+
_In_ PCWSTR pszValue,
159+
_Out_ PDWORD pValue);
160+
161+
PWSTR
162+
DuplicateString(
163+
_In_opt_ PCWSTR Str);
164+
153165

154166
#ifdef __cplusplus
155167
} // extern "C"

dll/win32/msgina/utils.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* PROJECT: ReactOS Logon GINA DLL msgina.dll
3+
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4+
* PURPOSE: Miscellaneous utility functions.
5+
* COPYRIGHT: Copyright 2006 Hervé Poussineau <[email protected]>
6+
* Copyright 2014 Eric Kohl <[email protected]>
7+
* Copyright 2025 Hermès Bélusca-Maïto <[email protected]>
8+
*/
9+
10+
#include "msgina.h"
11+
12+
LONG
13+
ReadRegSzValue(
14+
_In_ HKEY hKey,
15+
_In_ PCWSTR pszValue,
16+
_Out_ PWSTR* pValue)
17+
{
18+
LONG rc;
19+
DWORD dwType;
20+
DWORD cbData = 0;
21+
PWSTR Value;
22+
23+
*pValue = NULL;
24+
rc = RegQueryValueExW(hKey, pszValue, NULL, &dwType, NULL, &cbData);
25+
if (rc != ERROR_SUCCESS)
26+
return rc;
27+
if (dwType != REG_SZ)
28+
return ERROR_UNSUPPORTED_TYPE;
29+
Value = HeapAlloc(GetProcessHeap(), 0, cbData + sizeof(WCHAR));
30+
if (!Value)
31+
return ERROR_NOT_ENOUGH_MEMORY;
32+
rc = RegQueryValueExW(hKey, pszValue, NULL, NULL, (PBYTE)Value, &cbData);
33+
if (rc != ERROR_SUCCESS)
34+
{
35+
HeapFree(GetProcessHeap(), 0, Value);
36+
return rc;
37+
}
38+
/* NULL-terminate the string */
39+
Value[cbData / sizeof(WCHAR)] = UNICODE_NULL;
40+
41+
*pValue = Value;
42+
return ERROR_SUCCESS;
43+
}
44+
45+
LONG
46+
ReadRegDwordValue(
47+
_In_ HKEY hKey,
48+
_In_ PCWSTR pszValue,
49+
_Out_ PDWORD pValue)
50+
{
51+
LONG rc;
52+
DWORD dwValue, dwType, cbData;
53+
54+
cbData = sizeof(dwValue);
55+
rc = RegQueryValueExW(hKey, pszValue, NULL, &dwType, (PBYTE)&dwValue, &cbData);
56+
if ((rc == ERROR_SUCCESS) && (dwType == REG_DWORD) && (cbData == sizeof(dwValue)))
57+
{
58+
*pValue = dwValue;
59+
return ERROR_SUCCESS;
60+
}
61+
62+
return rc;
63+
}
64+
65+
PWSTR
66+
DuplicateString(
67+
_In_opt_ PCWSTR Str)
68+
{
69+
PWSTR NewStr;
70+
SIZE_T cb;
71+
72+
if (!Str)
73+
return NULL;
74+
75+
cb = (wcslen(Str) + 1) * sizeof(WCHAR);
76+
if ((NewStr = LocalAlloc(LMEM_FIXED, cb)))
77+
memcpy(NewStr, Str, cb);
78+
return NewStr;
79+
}

0 commit comments

Comments
 (0)