Go to the source code of this file.
◆ ImpersonatePrinterClient()
- See also
- RevertToPrinterSelf
Definition at line 14 of file context.c.
15{
19
20
21 if (!hToken)
22 {
25 }
26
27
29 {
31 ERR(
"GetTokenInformation failed with error %lu!\n", dwErrorCode);
33 }
34
35
36
38 {
40 {
42 ERR(
"SetThreadToken failed with error %lu!\n", dwErrorCode);
44 }
45 }
46
48 if (hToken)
50
53}
BOOL WINAPI GetTokenInformation(HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, LPVOID TokenInformation, DWORD TokenInformationLength, PDWORD ReturnLength)
BOOL WINAPI SetThreadToken(IN PHANDLE ThreadHandle OPTIONAL, IN HANDLE TokenHandle)
#define ERROR_INVALID_HANDLE
static const WCHAR Cleanup[]
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ BOOLEAN _In_ TOKEN_TYPE TokenType
DWORD WINAPI GetLastError(void)
◆ RevertToPrinterSelf()
RevertToPrinterSelf reverts the security context from the current user's context back to the process context. As spoolss.dll is used by spoolsv.exe, this is usually the SYSTEM security context.
Unlike the traditional ImpersonateClient and then RevertToSelf approach, we do it the other way round here, because spoolss.dll is delay-loaded by spoolsv.exe in the current user's context. Use RevertToPrinterSelf then to return to the SYSTEM context for specific tasks.
Definition at line 64 of file context.c.
65{
69
70
71
72
73
75 {
76
78 {
80 ERR(
"SetThreadToken failed with error %lu!\n", dwErrorCode);
82 }
83 }
85 {
87 ERR(
"OpenProcessToken failed with error %lu!\n", dwErrorCode);
89 }
90
91
93 hReturnValue = hToken;
94
95
97
99 if (hToken)
101
103 return hReturnValue;
104}
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
BOOL WINAPI OpenThreadToken(HANDLE ThreadHandle, DWORD DesiredAccess, BOOL OpenAsSelf, HANDLE *TokenHandle)
#define GetCurrentProcess()
HANDLE WINAPI GetCurrentThread(void)
#define TOKEN_IMPERSONATE
Referenced by _CreateNonspooledPort(), _HandleAddPort(), _HandleConfigureLPTPortCommandOK(), _HandleDeletePort(), and _HandleSetDefaultCommConfig().