1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
//+---------------------------------------------------------------------------
//
// Microsoft Windows
// Copyright (C) Microsoft Corporation, 1992 - 1993.
//
// File: shell.c
//
// Contents: Microsoft Logon GUI DLL
//
// History: 7-14-94 RichardW Created
//
//----------------------------------------------------------------------------
#include "precomp.h"
#pragma hdrstop
BOOL
SetProcessQuotas(
PPROCESS_INFORMATION ProcessInformation,
PUSER_PROCESS_DATA UserProcessData
)
{
NTSTATUS Status = STATUS_SUCCESS;
BOOL Result;
QUOTA_LIMITS RequestedLimits;
RequestedLimits = UserProcessData->Quotas;
RequestedLimits.MinimumWorkingSetSize = 0;
RequestedLimits.MaximumWorkingSetSize = 0;
if (UserProcessData->Quotas.PagedPoolLimit != 0) {
Result = EnablePrivilege(SE_INCREASE_QUOTA_PRIVILEGE, TRUE);
if (!Result) {
DebugLog((DEB_ERROR, "failed to enable increase_quota privilege\n"));
return(FALSE);
}
Status = NtSetInformationProcess(
ProcessInformation->hProcess,
ProcessQuotaLimits,
(PVOID)&RequestedLimits,
(ULONG)sizeof(QUOTA_LIMITS)
);
Result = EnablePrivilege(SE_INCREASE_QUOTA_PRIVILEGE, FALSE);
if (!Result) {
DebugLog((DEB_ERROR, "failed to disable increase_quota privilege\n"));
}
}
#if DBG
if (!NT_SUCCESS(Status)) {
DebugLog((DEB_ERROR, "SetProcessQuotas failed. Status: 0x%lx\n", Status));
}
#endif //DBG
return (NT_SUCCESS(Status));
}
BOOL
ExecApplication(
IN LPTSTR pch,
IN LPTSTR Desktop,
IN PGLOBALS pGlobals,
IN PVOID pEnvironment,
IN DWORD Flags,
IN DWORD StartupFlags,
OUT PPROCESS_INFORMATION ProcessInformation
)
{
STARTUPINFO si;
BOOL Result, IgnoreResult;
HANDLE ImpersonationHandle;
//
// Initialize process startup info
//
si.cb = sizeof(STARTUPINFO);
si.lpReserved = pch;
si.lpTitle = pch;
si.dwX = si.dwY = si.dwXSize = si.dwYSize = 0L;
si.dwFlags = StartupFlags;
si.wShowWindow = SW_SHOW; // at least let the guy see it
si.lpReserved2 = NULL;
si.cbReserved2 = 0;
si.lpDesktop = Desktop;
//
// Impersonate the user so we get access checked correctly on
// the file we're trying to execute
//
ImpersonationHandle = ImpersonateUser(&pGlobals->UserProcessData, NULL);
if (ImpersonationHandle == NULL) {
DebugLog((DEB_ERROR, "ExecApplication failed to impersonate user\n"));
return(FALSE);
}
//
// Create the app suspended
//
DebugLog((DEB_TRACE, "About to create process of %ws, on desktop %ws\n", pch, Desktop));
Result = CreateProcessAsUser(
pGlobals->UserProcessData.UserToken,
NULL,
pch,
NULL,
NULL,
FALSE,
Flags | CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT,
pEnvironment,
NULL,
&si,
ProcessInformation);
IgnoreResult = StopImpersonating(ImpersonationHandle);
ASSERT(IgnoreResult);
return(Result);
}
BOOL
WINAPI
WlxStartApplication(
PVOID pWlxContext,
PWSTR pszDesktop,
PVOID pEnvironment,
PWSTR pszCmdLine
)
{
PROCESS_INFORMATION ProcessInformation;
BOOL bExec;
bExec = ExecApplication (pszCmdLine,
pszDesktop,
g_pGlobals,
pEnvironment,
0,
STARTF_USESHOWWINDOW,
&ProcessInformation);
if (!bExec) {
return(FALSE);
}
if (SetProcessQuotas(&ProcessInformation,
&g_pGlobals->UserProcessData)) {
ResumeThread(ProcessInformation.hThread);
} else {
TerminateProcess(ProcessInformation.hProcess,
ERROR_ACCESS_DENIED);
}
CloseHandle(ProcessInformation.hThread);
CloseHandle(ProcessInformation.hProcess);
return(TRUE);
}
|