This leaks if ImpersonateLoggedOnUser fails and the environment block is non-null
-----Original Message-----
From: Ros-diffs [mailto:ros-diffs-bounces@reactos.org] On Behalf Of ekohl(a)svn.reactos.org
Sent: 06 December 2016 17:30
To: ros-diffs(a)reactos.org
Subject: [ros-diffs] [ekohl] 73433: [SERVICES] Create a new environment block when a
service process is started. Patch by Hermès BÉLUSCA - MAÏTO. CORE-12414
+ if (Service->lpImage->hToken)
+ {
+ /* User token: Run the service under the user account */
+
+ 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());
+ lpEnvironment = NULL;
+ }
+
+ /* Impersonate the new user */
+ if (!ImpersonateLoggedOnUser(Service->lpImage->hToken))
+ {
+ dwError = GetLastError();
+ DPRINT1("ImpersonateLoggedOnUser() failed with error %d\n",
GetLastError());
+ return dwError;
+ }