bde8c0d490099afd2ef23f91d8ba3b52364b84da
[reactos.git] / reactos / dll / win32 / kernel32 / client / appcache.c
1 /*
2 * PROJECT: ReactOS Win32 Base API
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/kernel32/client/appcache.c
5 * PURPOSE: Application Compatibility Cache
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <k32.h>
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* GLOBALS ********************************************************************/
17
18 ULONG g_ShimsEnabled;
19
20 /* FUNCTIONS ******************************************************************/
21
22 BOOLEAN
23 WINAPI
24 IsShimInfrastructureDisabled(VOID)
25 {
26 HANDLE KeyHandle;
27 NTSTATUS Status;
28 KEY_VALUE_PARTIAL_INFORMATION KeyInfo;
29 ULONG ResultLength;
30 UNICODE_STRING OptionKey = RTL_CONSTANT_STRING(L"\\Registry\\MACHINE\\System\\CurrentControlSet\\Control\\SafeBoot\\Option");
31 UNICODE_STRING AppCompatKey = RTL_CONSTANT_STRING(L"\\Registry\\MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\AppCompatibility");
32 UNICODE_STRING PolicyKey = RTL_CONSTANT_STRING(L"\\Registry\\MACHINE\\Software\\Policies\\Microsoft\\Windows\\AppCompat");
33 UNICODE_STRING OptionValue = RTL_CONSTANT_STRING(L"OptionValue");
34 UNICODE_STRING DisableAppCompat = RTL_CONSTANT_STRING(L"DisableAppCompat");
35 UNICODE_STRING DisableEngine = RTL_CONSTANT_STRING(L"DisableEngine");
36 OBJECT_ATTRIBUTES OptionKeyAttributes = RTL_CONSTANT_OBJECT_ATTRIBUTES(&OptionKey, OBJ_CASE_INSENSITIVE);
37 OBJECT_ATTRIBUTES AppCompatKeyAttributes = RTL_CONSTANT_OBJECT_ATTRIBUTES(&AppCompatKey, OBJ_CASE_INSENSITIVE);
38 OBJECT_ATTRIBUTES PolicyKeyAttributes = RTL_CONSTANT_OBJECT_ATTRIBUTES(&PolicyKey, OBJ_CASE_INSENSITIVE);
39
40 /*
41 * This is a TROOLEAN, -1 means we haven't yet figured it out.
42 * 0 means shims are enabled, and 1 means shims are disabled!
43 */
44 if (g_ShimsEnabled == -1)
45 {
46 /* Open the safe mode key */
47 Status = NtOpenKey(&KeyHandle, KEY_QUERY_VALUE, &OptionKeyAttributes);
48 if (NT_SUCCESS(Status))
49 {
50 /* Check if this is safemode */
51 Status = NtQueryValueKey(KeyHandle,
52 &OptionValue,
53 KeyValuePartialInformation,
54 &KeyInfo,
55 sizeof(KeyInfo),
56 &ResultLength);
57 NtClose(KeyHandle);
58 if ((NT_SUCCESS(Status)) &&
59 (KeyInfo.Type == REG_DWORD) &&
60 (KeyInfo.DataLength == sizeof(ULONG)) &&
61 (KeyInfo.Data[0] == TRUE))
62 {
63 /* It is, so disable shims! */
64 g_ShimsEnabled = TRUE;
65 }
66 else
67 {
68 /* Open the app compatibility engine settings key */
69 Status = NtOpenKey(&KeyHandle, KEY_QUERY_VALUE, &AppCompatKeyAttributes);
70 if (NT_SUCCESS(Status))
71 {
72 /* Check if the app compat engine is turned off */
73 Status = NtQueryValueKey(KeyHandle,
74 &DisableAppCompat,
75 KeyValuePartialInformation,
76 &KeyInfo,
77 sizeof(KeyInfo),
78 &ResultLength);
79 NtClose(KeyHandle);
80 if ((NT_SUCCESS(Status)) &&
81 (KeyInfo.Type == REG_DWORD) &&
82 (KeyInfo.DataLength == sizeof(ULONG)) &&
83 (KeyInfo.Data[0] == TRUE))
84 {
85 /* It is, so disable shims! */
86 g_ShimsEnabled = TRUE;
87 }
88 else
89 {
90 /* Finally, open the app compatibility policy key */
91 Status = NtOpenKey(&KeyHandle, KEY_QUERY_VALUE, &PolicyKeyAttributes);
92 if (NT_SUCCESS(Status))
93 {
94 /* Check if the system policy disables app compat */
95 Status = NtQueryValueKey(KeyHandle,
96 &DisableEngine,
97 KeyValuePartialInformation,
98 &KeyInfo,
99 sizeof(KeyInfo),
100 &ResultLength);
101 NtClose(KeyHandle);
102 if ((NT_SUCCESS(Status)) &&
103 (KeyInfo.Type == REG_DWORD) &&
104 (KeyInfo.DataLength == sizeof(ULONG)) &&
105 (KeyInfo.Data[0] == TRUE))
106 {
107 /* It does, so disable shims! */
108 g_ShimsEnabled = TRUE;
109 }
110 else
111 {
112 /* No keys are set, so enable shims! */
113 g_ShimsEnabled = FALSE;
114 }
115 }
116 }
117 }
118 }
119 }
120 }
121
122 /* Return if shims are disabled or not ("Enabled == 1" means disabled!) */
123 return g_ShimsEnabled ? TRUE : FALSE;
124 }
125
126 /*
127 * @unimplemented
128 */
129 BOOL
130 WINAPI
131 BaseCheckAppcompatCache(IN PWCHAR ApplicationName,
132 IN HANDLE FileHandle,
133 IN PWCHAR Environment,
134 OUT PULONG Reason)
135 {
136 DPRINT("BaseCheckAppcompatCache is UNIMPLEMENTED\n");
137
138 if (Reason) *Reason = 0;
139 return TRUE;
140 }
141
142 /*
143 * @implemented
144 */
145 NTSTATUS
146 WINAPI
147 BasepCheckBadapp(IN HANDLE FileHandle,
148 IN PWCHAR ApplicationName,
149 IN PWCHAR Environment,
150 IN USHORT ExeType,
151 IN PVOID* SdbQueryAppCompatData,
152 IN PULONG SdbQueryAppCompatDataSize,
153 IN PVOID* SxsData,
154 IN PULONG SxsDataSize,
155 OUT PULONG FusionFlags)
156 {
157 NTSTATUS Status = STATUS_SUCCESS;
158 ULONG Reason = 0;
159
160 /* Is shimming enabled by group policy? */
161 if (IsShimInfrastructureDisabled())
162 {
163 /* Nothing to worry about */
164 Status = STATUS_SUCCESS;
165 }
166 else
167 {
168 /* It is, check if we know about this app */
169 if (!BaseCheckAppcompatCache(ApplicationName,
170 FileHandle,
171 Environment,
172 &Reason))
173 {
174 /* We don't support this yet */
175 UNIMPLEMENTED;
176 Status = STATUS_ACCESS_DENIED;
177 }
178 }
179
180 /* Return caller the status */
181 return Status;
182 }
183
184 /*
185 * @unimplemented
186 */
187 VOID
188 WINAPI
189 BaseDumpAppcompatCache(VOID)
190 {
191 STUB;
192 }
193
194 /*
195 * @unimplemented
196 */
197 VOID
198 WINAPI
199 BaseFlushAppcompatCache(VOID)
200 {
201 STUB;
202 }
203
204 /*
205 * @implemented
206 */
207 VOID
208 WINAPI
209 BasepFreeAppCompatData(IN PVOID AppCompatData,
210 IN PVOID AppCompatSxsData)
211 {
212 /* Free the input pointers if present */
213 if (AppCompatData) RtlFreeHeap(RtlGetProcessHeap(), 0, AppCompatData);
214 if (AppCompatSxsData) RtlFreeHeap(RtlGetProcessHeap(), 0, AppCompatSxsData);
215 }
216
217 /*
218 * @unimplemented
219 */
220 VOID
221 WINAPI
222 BaseUpdateAppcompatCache(ULONG Unknown1,
223 ULONG Unknown2,
224 ULONG Unknown3)
225 {
226 STUB;
227 }
228
229 /*
230 * @unimplemented
231 */
232 NTSTATUS
233 WINAPI
234 BaseCleanupAppcompatCache(VOID)
235 {
236 STUB;
237 return STATUS_NOT_IMPLEMENTED;
238 }
239
240 /*
241 * @unimplemented
242 */
243 NTSTATUS
244 WINAPI
245 BaseCleanupAppcompatCacheSupport(PVOID pUnknown)
246 {
247 STUB;
248 return STATUS_NOT_IMPLEMENTED;
249 }
250
251 /*
252 * @unimplemented
253 */
254 BOOL
255 WINAPI
256 BaseInitAppcompatCache(VOID)
257 {
258 STUB;
259 return FALSE;
260 }
261
262 /*
263 * @unimplemented
264 */
265 BOOL
266 WINAPI
267 BaseInitAppcompatCacheSupport(VOID)
268 {
269 STUB;
270 return FALSE;
271 }
272
273 /*
274 * @unimplemented
275 */
276 PVOID
277 WINAPI
278 GetComPlusPackageInstallStatus(VOID)
279 {
280 STUB;
281 return NULL;
282 }
283
284 /*
285 * @unimplemented
286 */
287 BOOL
288 WINAPI
289 SetComPlusPackageInstallStatus(LPVOID lpInfo)
290 {
291 STUB;
292 return FALSE;
293 }
294
295 /*
296 * @unimplemented
297 */
298 VOID
299 WINAPI
300 SetTermsrvAppInstallMode(IN BOOL bInstallMode)
301 {
302 STUB;
303 }
304
305 /*
306 * @unimplemented
307 */
308 BOOL
309 WINAPI
310 TermsrvAppInstallMode(VOID)
311 {
312 STUB;
313 return FALSE;
314 }