Author: hbelusca
Date: Tue Dec 6 23:01:27 2016
New Revision: 73435
URL:
http://svn.reactos.org/svn/reactos?rev=73435&view=rev
Log:
[SERVICES]: Addendum to r73433 for ScmStartUserModeService:
- Use the correct capitalization for the desktop name (to be consistent with all the rest
of our code);
- Fix DPRINT1 order of arguments;
- Reorganize a bit the code to avoid the memory leak if ImpersonateLoggedOnUser fails and
the environment block was already allocated (caught by Ged Murphy).
CORE-12414
Modified:
trunk/reactos/base/system/services/database.c
Modified: trunk/reactos/base/system/services/database.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/datab…
==============================================================================
--- trunk/reactos/base/system/services/database.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/services/database.c [iso-8859-1] Tue Dec 6 23:01:27 2016
@@ -1700,8 +1700,11 @@
ZeroMemory(&ProcessInformation, sizeof(ProcessInformation));
/* Use the interactive desktop if the service is interactive */
+ // TODO: We should also check the value "NoInteractiveServices ":
+ // See
https://msdn.microsoft.com/en-us/library/windows/desktop/ms683502(v=vs.85).…
+ // for more details.
if (Service->Status.dwServiceType & SERVICE_INTERACTIVE_PROCESS)
- StartupInfo.lpDesktop = L"winsta0\\default";
+ StartupInfo.lpDesktop = L"WinSta0\\Default";
if (Service->lpImage->hToken)
{
@@ -1710,34 +1713,38 @@
if (!CreateEnvironmentBlock(&lpEnvironment, Service->lpImage->hToken,
FALSE))
{
/* We failed, run the service with the current environment */
- DPRINT1("CreateEnvironmentBlock() failed with error %d, service
'%S' will run with the current environment.\n",
- Service->lpServiceName, GetLastError());
+ DPRINT1("CreateEnvironmentBlock() failed with error %d; service
'%S' will run with the current environment.\n",
+ GetLastError(), Service->lpServiceName);
lpEnvironment = NULL;
}
/* Impersonate the new user */
- if (!ImpersonateLoggedOnUser(Service->lpImage->hToken))
+ Result = ImpersonateLoggedOnUser(Service->lpImage->hToken);
+ if (Result)
+ {
+ /* Launch the process in the user's logon session */
+ Result = CreateProcessAsUserW(Service->lpImage->hToken,
+ NULL,
+ Service->lpImage->pszImagePath,
+ NULL,
+ NULL,
+ FALSE,
+ CREATE_UNICODE_ENVIRONMENT | DETACHED_PROCESS |
CREATE_SUSPENDED,
+ lpEnvironment,
+ NULL,
+ &StartupInfo,
+ &ProcessInformation);
+ if (!Result)
+ dwError = GetLastError();
+
+ /* Revert the impersonation */
+ RevertToSelf();
+ }
+ else
{
dwError = GetLastError();
- DPRINT1("ImpersonateLoggedOnUser() failed with error %d\n",
GetLastError());
- return dwError;
- }
-
- /* Launch the process in the user's logon session */
- Result = CreateProcessAsUserW(Service->lpImage->hToken,
- NULL,
- Service->lpImage->pszImagePath,
- NULL,
- NULL,
- FALSE,
- CREATE_UNICODE_ENVIRONMENT | DETACHED_PROCESS |
CREATE_SUSPENDED,
- lpEnvironment,
- NULL,
- &StartupInfo,
- &ProcessInformation);
-
- /* Revert the impersonation */
- RevertToSelf();
+ DPRINT1("ImpersonateLoggedOnUser() failed with error %d\n",
dwError);
+ }
}
else
{
@@ -1746,8 +1753,8 @@
if (!CreateEnvironmentBlock(&lpEnvironment, NULL, TRUE))
{
/* We failed, run the service with the current environment */
- DPRINT1("CreateEnvironmentBlock() failed with error %d, service
'%S' will run with the current environment.\n",
- Service->lpServiceName, GetLastError());
+ DPRINT1("CreateEnvironmentBlock() failed with error %d; service
'%S' will run with the current environment.\n",
+ GetLastError(), Service->lpServiceName);
lpEnvironment = NULL;
}
@@ -1761,6 +1768,8 @@
NULL,
&StartupInfo,
&ProcessInformation);
+ if (!Result)
+ dwError = GetLastError();
}
if (lpEnvironment)
@@ -1768,8 +1777,8 @@
if (!Result)
{
- dwError = GetLastError();
- DPRINT1("Starting '%S' failed!\n", Service->lpServiceName);
+ DPRINT1("Starting '%S' failed with error %d\n",
+ Service->lpServiceName, dwError);
return dwError;
}