2 * PROJECT: ReactOS Spooler Router
3 * LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation
4 * PURPOSE: Functions related to switching between security contexts
5 * COPYRIGHT: Copyright 2015 Colin Finck <colin@reactos.org>
11 * @see RevertToPrinterSelf
14 ImpersonatePrinterClient(HANDLE hToken
)
18 SetLastError(ERROR_INVALID_HANDLE
);
22 if (!SetThreadToken(NULL
, hToken
))
24 ERR("SetThreadToken failed with error %lu!\n", GetLastError());
34 * RevertToPrinterSelf reverts the security context from the current user's context back to the process context.
35 * As spoolss.dll is used by spoolsv.exe, this is usually the SYSTEM security context.
37 * Unlike the traditional ImpersonateClient and then RevertToSelf approach, we do it the other way round here,
38 * because spoolss.dll is delay-loaded by spoolsv.exe in the current user's context. Use RevertToPrinterSelf then to
39 * return to the SYSTEM context for specific tasks.
46 // Retrieve our current impersonation token
47 if (!OpenThreadToken(GetCurrentThread(), TOKEN_IMPERSONATE
, TRUE
, &hToken
))
49 ERR("OpenThreadToken failed with error %lu!\n", GetLastError());
53 // Tell the thread to stop impersonating
54 if (!SetThreadToken(NULL
, NULL
))
56 ERR("SetThreadToken failed with error %lu!\n", GetLastError());
60 // Return the token required for reverting back to impersonation in ImpersonatePrinterClient