[ADVAPI32][SERVICES] Use the context handle to encrypt and decrypt service passwords

This commit is contained in:
Eric Kohl 2021-07-17 16:26:16 +02:00
parent 3965c93732
commit 4cae349811
4 changed files with 18 additions and 9 deletions

View File

@ -699,6 +699,7 @@ done:
DWORD
ScmDecryptPassword(
_In_ PVOID ContextHandle,
_In_ PBYTE pPassword,
_In_ DWORD dwPasswordSize,
_Out_ PWSTR *pClearTextPassword)
@ -709,7 +710,7 @@ ScmDecryptPassword(
NTSTATUS Status;
/* Get the session key */
Status = SystemFunction028(NULL,
Status = SystemFunction028(ContextHandle,
SessionKey);
if (!NT_SUCCESS(Status))
{

View File

@ -4,7 +4,7 @@
* FILE: base/system/services/rpcserver.c
* PURPOSE: RPC server interface for the advapi32 calls
* COPYRIGHT: Copyright 2005-2006 Eric Kohl
* Copyright 2006-2007 Hervé Poussineau <hpoussin@reactos.org>
* Copyright 2006-2007 Hervé Poussineau <hpoussin@reactos.org>
* Copyright 2007 Ged Murphy <gedmurphy@reactos.org>
*/
@ -2208,7 +2208,8 @@ RChangeServiceConfigW(
if (*(LPWSTR)lpPassword != 0)
{
/* Decrypt the password */
dwError = ScmDecryptPassword(lpPassword,
dwError = ScmDecryptPassword(hService,
lpPassword,
dwPwSize,
&lpClearTextPassword);
if (dwError != ERROR_SUCCESS)
@ -2609,7 +2610,8 @@ RCreateServiceW(
if (lpPassword != NULL && *(LPWSTR)lpPassword != 0)
{
/* Decrypt the password */
dwError = ScmDecryptPassword(lpPassword,
dwError = ScmDecryptPassword(hSCManager,
lpPassword,
dwPwSize,
&lpClearTextPassword);
if (dwError != ERROR_SUCCESS)

View File

@ -155,6 +155,7 @@ ScmDeleteRegKey(
DWORD
ScmDecryptPassword(
_In_ PVOID ContextHandle,
_In_ PBYTE pPassword,
_In_ DWORD dwPasswordSize,
_Out_ PWSTR *pDecryptedPassword);

View File

@ -171,6 +171,7 @@ ScmRpcStatusToWinError(RPC_STATUS Status)
static
DWORD
ScmEncryptPassword(
_In_ PVOID ContextHandle,
_In_ PCWSTR pClearTextPassword,
_Out_ PBYTE *pEncryptedPassword,
_Out_ PDWORD pEncryptedPasswordSize)
@ -181,7 +182,7 @@ ScmEncryptPassword(
NTSTATUS Status;
/* Get the session key */
Status = SystemFunction028(NULL,
Status = SystemFunction028(ContextHandle,
SessionKey);
if (!NT_SUCCESS(Status))
{
@ -417,7 +418,8 @@ ChangeServiceConfigA(SC_HANDLE hService,
(int)(strlen(lpPassword) + 1));
/* Encrypt the unicode password */
dwError = ScmEncryptPassword(lpPasswordW,
dwError = ScmEncryptPassword(hService,
lpPasswordW,
&lpEncryptedPassword,
&dwPasswordSize);
if (dwError != ERROR_SUCCESS)
@ -517,7 +519,8 @@ ChangeServiceConfigW(SC_HANDLE hService,
if (lpPassword != NULL)
{
dwError = ScmEncryptPassword(lpPassword,
dwError = ScmEncryptPassword(hService,
lpPassword,
&lpEncryptedPassword,
&dwPasswordSize);
if (dwError != ERROR_SUCCESS)
@ -742,7 +745,8 @@ CreateServiceA(SC_HANDLE hSCManager,
(int)(strlen(lpPassword) + 1));
/* Encrypt the password */
dwError = ScmEncryptPassword(lpPasswordW,
dwError = ScmEncryptPassword(hSCManager,
lpPasswordW,
&lpEncryptedPassword,
&dwPasswordSize);
if (dwError != ERROR_SUCCESS)
@ -856,7 +860,8 @@ CreateServiceW(SC_HANDLE hSCManager,
if (lpPassword != NULL)
{
/* Encrypt the password */
dwError = ScmEncryptPassword(lpPassword,
dwError = ScmEncryptPassword(hSCManager,
lpPassword,
&lpEncryptedPassword,
&dwPasswordSize);
if (dwError != ERROR_SUCCESS)