Author: ekohl
Date: Mon May 23 15:02:37 2016
New Revision: 71386
URL:
http://svn.reactos.org/svn/reactos?rev=71386&view=rev
Log:
[SERVICES]
RCreateServiceW: Store a given password as a secret.
Modified:
trunk/reactos/base/system/services/config.c
trunk/reactos/base/system/services/rpcserver.c
trunk/reactos/base/system/services/services.h
Modified: trunk/reactos/base/system/services/config.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/confi…
==============================================================================
--- trunk/reactos/base/system/services/config.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/services/config.c [iso-8859-1] Mon May 23 15:02:37 2016
@@ -10,6 +10,7 @@
/* INCLUDES *****************************************************************/
#include "services.h"
+#include <ntsecapi.h>
#define NDEBUG
#include <debug.h>
@@ -443,4 +444,58 @@
return ERROR_SUCCESS;
}
+
+DWORD
+ScmSetServicePassword(
+ IN PCWSTR pszServiceName,
+ IN PCWSTR pszPassword)
+{
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ LSA_HANDLE PolicyHandle = NULL;
+ UNICODE_STRING ServiceName = {0, 0, NULL};
+ UNICODE_STRING Password;
+ NTSTATUS Status;
+ DWORD dwError = ERROR_SUCCESS;
+
+ RtlZeroMemory(&ObjectAttributes, sizeof(OBJECT_ATTRIBUTES));
+
+ Status = LsaOpenPolicy(NULL,
+ &ObjectAttributes,
+ POLICY_CREATE_SECRET,
+ &PolicyHandle);
+ if (!NT_SUCCESS(Status))
+ return RtlNtStatusToDosError(Status);
+
+ ServiceName.Length = (wcslen(pszServiceName) + 4) * sizeof(WCHAR);
+ ServiceName.MaximumLength = ServiceName.Length + sizeof(WCHAR);
+ ServiceName.Buffer = HeapAlloc(GetProcessHeap(),
+ HEAP_ZERO_MEMORY,
+ ServiceName.MaximumLength);
+ if (ServiceName.Buffer == NULL)
+ return ERROR_NOT_ENOUGH_MEMORY;
+
+ wcscpy(ServiceName.Buffer, L"_SC_");
+ wcscat(ServiceName.Buffer, pszServiceName);
+
+ RtlInitUnicodeString(&Password, pszPassword);
+
+ Status = LsaStorePrivateData(PolicyHandle,
+ &ServiceName,
+ &Password);
+ if (!NT_SUCCESS(Status))
+ {
+ dwError = RtlNtStatusToDosError(Status);
+ goto done;
+ }
+
+done:
+ if (ServiceName.Buffer != NULL)
+ HeapFree(GetProcessHeap(), 0, ServiceName.Buffer);
+
+ if (PolicyHandle != NULL)
+ LsaClose(PolicyHandle);
+
+ return dwError;
+}
+
/* EOF */
Modified: trunk/reactos/base/system/services/rpcserver.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/rpcse…
==============================================================================
--- trunk/reactos/base/system/services/rpcserver.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/services/rpcserver.c [iso-8859-1] Mon May 23 15:02:37 2016
@@ -2323,6 +2323,7 @@
goto done;
}
+ /* Set the service tag */
if (lpdwTagId != NULL)
{
dwError = RegSetValueExW(hServiceKey,
@@ -2345,9 +2346,10 @@
goto done;
}
- /* Write service start name */
+ /* Start name and password are only used by Win32 services */
if (dwServiceType & SERVICE_WIN32)
{
+ /* Write service start name */
lpObjectName = (lpServiceStartName != NULL) ? (LPWSTR)lpServiceStartName :
L"LocalSystem";
dwError = RegSetValueExW(hServiceKey,
L"ObjectName",
@@ -2357,11 +2359,17 @@
(DWORD)((wcslen(lpObjectName) + 1) * sizeof(WCHAR)));
if (dwError != ERROR_SUCCESS)
goto done;
- }
-
- if (lpPassword != NULL)
- {
- /* FIXME: Decrypt and write password */
+
+ if (lpPassword != NULL && wcslen((LPWSTR)lpPassword) != 0)
+ {
+ /* FIXME: Decrypt the password */
+
+ /* Write the password */
+ dwError = ScmSetServicePassword(lpServiceName,
+ (LPCWSTR)lpPassword);
+ if (dwError != ERROR_SUCCESS)
+ goto done;
+ }
}
dwError = ScmCreateServiceHandle(lpService,
Modified: trunk/reactos/base/system/services/services.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/servi…
==============================================================================
--- trunk/reactos/base/system/services/services.h [iso-8859-1] (original)
+++ trunk/reactos/base/system/services/services.h [iso-8859-1] Mon May 23 15:02:37 2016
@@ -126,6 +126,10 @@
LPWSTR *lpDependencies,
DWORD *lpdwDependenciesLength);
+DWORD
+ScmSetServicePassword(
+ IN PCWSTR pszServiceName,
+ IN PCWSTR pszPassword);
/* controlset.c */