Skip to content

Commit 4cae349

Browse files
committed
[ADVAPI32][SERVICES] Use the context handle to encrypt and decrypt service passwords
1 parent 3965c93 commit 4cae349

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

base/system/services/config.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ ScmDeleteRegKey(
699699

700700
DWORD
701701
ScmDecryptPassword(
702+
_In_ PVOID ContextHandle,
702703
_In_ PBYTE pPassword,
703704
_In_ DWORD dwPasswordSize,
704705
_Out_ PWSTR *pClearTextPassword)
@@ -709,7 +710,7 @@ ScmDecryptPassword(
709710
NTSTATUS Status;
710711

711712
/* Get the session key */
712-
Status = SystemFunction028(NULL,
713+
Status = SystemFunction028(ContextHandle,
713714
SessionKey);
714715
if (!NT_SUCCESS(Status))
715716
{

base/system/services/rpcserver.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* FILE: base/system/services/rpcserver.c
55
* PURPOSE: RPC server interface for the advapi32 calls
66
* COPYRIGHT: Copyright 2005-2006 Eric Kohl
7-
* Copyright 2006-2007 Hervé Poussineau <[email protected]>
7+
* Copyright 2006-2007 Hervé Poussineau <[email protected]>
88
* Copyright 2007 Ged Murphy <[email protected]>
99
*/
1010

@@ -2208,7 +2208,8 @@ RChangeServiceConfigW(
22082208
if (*(LPWSTR)lpPassword != 0)
22092209
{
22102210
/* Decrypt the password */
2211-
dwError = ScmDecryptPassword(lpPassword,
2211+
dwError = ScmDecryptPassword(hService,
2212+
lpPassword,
22122213
dwPwSize,
22132214
&lpClearTextPassword);
22142215
if (dwError != ERROR_SUCCESS)
@@ -2609,7 +2610,8 @@ RCreateServiceW(
26092610
if (lpPassword != NULL && *(LPWSTR)lpPassword != 0)
26102611
{
26112612
/* Decrypt the password */
2612-
dwError = ScmDecryptPassword(lpPassword,
2613+
dwError = ScmDecryptPassword(hSCManager,
2614+
lpPassword,
26132615
dwPwSize,
26142616
&lpClearTextPassword);
26152617
if (dwError != ERROR_SUCCESS)

base/system/services/services.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ ScmDeleteRegKey(
155155

156156
DWORD
157157
ScmDecryptPassword(
158+
_In_ PVOID ContextHandle,
158159
_In_ PBYTE pPassword,
159160
_In_ DWORD dwPasswordSize,
160161
_Out_ PWSTR *pDecryptedPassword);

dll/win32/advapi32/service/scm.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ ScmRpcStatusToWinError(RPC_STATUS Status)
171171
static
172172
DWORD
173173
ScmEncryptPassword(
174+
_In_ PVOID ContextHandle,
174175
_In_ PCWSTR pClearTextPassword,
175176
_Out_ PBYTE *pEncryptedPassword,
176177
_Out_ PDWORD pEncryptedPasswordSize)
@@ -181,7 +182,7 @@ ScmEncryptPassword(
181182
NTSTATUS Status;
182183

183184
/* Get the session key */
184-
Status = SystemFunction028(NULL,
185+
Status = SystemFunction028(ContextHandle,
185186
SessionKey);
186187
if (!NT_SUCCESS(Status))
187188
{
@@ -417,7 +418,8 @@ ChangeServiceConfigA(SC_HANDLE hService,
417418
(int)(strlen(lpPassword) + 1));
418419

419420
/* Encrypt the unicode password */
420-
dwError = ScmEncryptPassword(lpPasswordW,
421+
dwError = ScmEncryptPassword(hService,
422+
lpPasswordW,
421423
&lpEncryptedPassword,
422424
&dwPasswordSize);
423425
if (dwError != ERROR_SUCCESS)
@@ -517,7 +519,8 @@ ChangeServiceConfigW(SC_HANDLE hService,
517519

518520
if (lpPassword != NULL)
519521
{
520-
dwError = ScmEncryptPassword(lpPassword,
522+
dwError = ScmEncryptPassword(hService,
523+
lpPassword,
521524
&lpEncryptedPassword,
522525
&dwPasswordSize);
523526
if (dwError != ERROR_SUCCESS)
@@ -742,7 +745,8 @@ CreateServiceA(SC_HANDLE hSCManager,
742745
(int)(strlen(lpPassword) + 1));
743746

744747
/* Encrypt the password */
745-
dwError = ScmEncryptPassword(lpPasswordW,
748+
dwError = ScmEncryptPassword(hSCManager,
749+
lpPasswordW,
746750
&lpEncryptedPassword,
747751
&dwPasswordSize);
748752
if (dwError != ERROR_SUCCESS)
@@ -856,7 +860,8 @@ CreateServiceW(SC_HANDLE hSCManager,
856860
if (lpPassword != NULL)
857861
{
858862
/* Encrypt the password */
859-
dwError = ScmEncryptPassword(lpPassword,
863+
dwError = ScmEncryptPassword(hSCManager,
864+
lpPassword,
860865
&lpEncryptedPassword,
861866
&dwPasswordSize);
862867
if (dwError != ERROR_SUCCESS)

0 commit comments

Comments
 (0)