ReactOS 0.4.15-dev-7788-g1ad9096
layer.c File Reference
#include "windef.h"
#include "winbase.h"
#include "strsafe.h"
#include <ntndk.h>
#include "apphelp.h"
Include dependency graph for layer.c:

Go to the source code of this file.

Classes

struct  SDB_TMP_STR
 

Macros

#define WIN32_NO_STATUS
 
#define GPLK_USER   1
 
#define GPLK_MACHINE   2
 
#define MAX_LAYER_LENGTH   256
 
#define LAYER_APPLY_TO_SYSTEM_EXES   1
 
#define LAYER_UNK_FLAG2   2
 
#define REG_SZ   1
 
#define APPCOMPAT_LAYER_KEY   L"\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"
 
#define REGISTRY_MACHINE   L"\\Registry\\Machine"
 
#define SPACE_ONLY   L" "
 
#define DISALLOWED_LAYER_CHARS   L" #!"
 
#define LAYER_SEPARATORS   L" \t"
 
#define SIGN_MEDIA_FMT   L"SIGN.MEDIA=%X %s"
 

Typedefs

typedef struct SDB_TMP_STR SDB_TMP_STR
 
typedef struct SDB_TMP_STRPSDB_TMP_STR
 

Functions

void SdbpInitTempStr (PSDB_TMP_STR String)
 
void SdbpFreeTempStr (PSDB_TMP_STR String)
 
void SdbpResizeTempStr (PSDB_TMP_STR String, WORD newLength)
 
BOOL SdbpGetLongPathName (PCWSTR wszPath, PSDB_TMP_STR Result)
 
BOOL SdbpIsPathOnRemovableMedia (PCWSTR Path)
 
BOOL SdbpBuildSignMediaId (PSDB_TMP_STR LongPath)
 
BOOL SdbpResolvePath (PSDB_TMP_STR LongPath, PCWSTR wszPath)
 
ACCESS_MASK Wow64QueryFlag (void)
 
NTSTATUS SdbpOpenKey (PUNICODE_STRING FullPath, BOOL bMachine, ACCESS_MASK Access, PHANDLE KeyHandle)
 
BOOL SdbpGetPermLayersInternal (PUNICODE_STRING FullPath, PWSTR pwszLayers, PDWORD pdwBytes, BOOL bMachine)
 
BOOL SdbDeletePermLayerKeys (PCWSTR wszPath, BOOL bMachine)
 
BOOL SdbpMatchLayer (PCWSTR start, PCWSTR end, PCWSTR compare)
 
BOOL SdbpAppendLayer (PWSTR target, DWORD len, PCWSTR layer, PCWSTR end)
 
BOOL WINAPI AllowPermLayer (PCWSTR Path)
 
BOOL WINAPI SdbGetPermLayerKeys (PCWSTR wszPath, PWSTR pwszLayers, PDWORD pdwBytes, DWORD dwFlags)
 
BOOL WINAPI SdbSetPermLayerKeys (PCWSTR wszPath, PCWSTR wszLayers, BOOL bMachine)
 
BOOL WINAPI SetPermLayerState (PCWSTR wszPath, PCWSTR wszLayer, DWORD dwFlags, BOOL bMachine, BOOL bEnable)
 

Variables

static ACCESS_MASK g_QueryFlag = 0xffffffff
 

Macro Definition Documentation

◆ APPCOMPAT_LAYER_KEY

#define APPCOMPAT_LAYER_KEY   L"\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"

Definition at line 34 of file layer.c.

◆ DISALLOWED_LAYER_CHARS

#define DISALLOWED_LAYER_CHARS   L" #!"

Definition at line 37 of file layer.c.

◆ GPLK_MACHINE

#define GPLK_MACHINE   2

Definition at line 16 of file layer.c.

◆ GPLK_USER

#define GPLK_USER   1

Definition at line 15 of file layer.c.

◆ LAYER_APPLY_TO_SYSTEM_EXES

#define LAYER_APPLY_TO_SYSTEM_EXES   1

Definition at line 18 of file layer.c.

◆ LAYER_SEPARATORS

#define LAYER_SEPARATORS   L" \t"

Definition at line 38 of file layer.c.

◆ LAYER_UNK_FLAG2

#define LAYER_UNK_FLAG2   2

Definition at line 19 of file layer.c.

◆ MAX_LAYER_LENGTH

#define MAX_LAYER_LENGTH   256

Definition at line 17 of file layer.c.

◆ REG_SZ

#define REG_SZ   1

Definition at line 22 of file layer.c.

◆ REGISTRY_MACHINE

#define REGISTRY_MACHINE   L"\\Registry\\Machine"

Definition at line 35 of file layer.c.

◆ SIGN_MEDIA_FMT

#define SIGN_MEDIA_FMT   L"SIGN.MEDIA=%X %s"

Definition at line 39 of file layer.c.

◆ SPACE_ONLY

#define SPACE_ONLY   L" "

Definition at line 36 of file layer.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 8 of file layer.c.

Typedef Documentation

◆ PSDB_TMP_STR

◆ SDB_TMP_STR

Function Documentation

◆ AllowPermLayer()

BOOL WINAPI AllowPermLayer ( PCWSTR  Path)

Determine if we allow permission layers to apply on this file.

Parameters
[in]PathFull pathname of the file, only the drive part is used.
Returns
TRUE if we allow permission layer, FALSE if not.

Definition at line 320 of file layer.c.

321{
322 WCHAR tmp[] = { 'A',':','\\', 0 };
323 ULONG type;
324 if (!Path)
325 {
326 SHIM_ERR("Invalid argument\n");
327 return FALSE;
328 }
329 switch (Path[1])
330 {
331 case L':':
332 break;
333 case L'\\':
334 SHIM_INFO("\"%S\" is a network path.\n", Path);
335 return FALSE;
336 default:
337 SHIM_INFO("\"%S\" not a full path we can operate on.\n", Path);
338 return FALSE;
339 }
340 tmp[0] = Path[0];
341 type = GetDriveTypeW(tmp);
342 if (type == DRIVE_REMOTE)
343 {
344 /* The logging here indicates that it does not like a CDROM or removable media, but it only
345 seems to bail out on a media that reports it is remote...
346 I have included correct logging, I doubt anyone would parse the logging, so this shouldnt break anything. */
347 SHIM_INFO("\"%S\" is on a remote drive.\n", Path);
348 return FALSE;
349 }
350 return TRUE;
351}
PRTL_UNICODE_STRING_BUFFER Path
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define L(x)
Definition: ntvdm.h:50
#define SHIM_INFO(fmt,...)
Definition: sdbpapi.h:78
#define SHIM_ERR(fmt,...)
Definition: sdbpapi.h:76
uint32_t ULONG
Definition: typedefs.h:59
#define DRIVE_REMOTE
Definition: winbase.h:253
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CLayerUIPropPage::InitFile().

◆ SdbDeletePermLayerKeys()

BOOL SdbDeletePermLayerKeys ( PCWSTR  wszPath,
BOOL  bMachine 
)

Definition at line 258 of file layer.c.

259{
260 UNICODE_STRING FullKey;
261 SDB_TMP_STR LongPath;
264
265 if (!SdbpResolvePath(&LongPath, wszPath))
266 return FALSE;
267
269 if (NT_SUCCESS(Status))
270 {
271 Status = NtDeleteValueKey(KeyHandle, &LongPath.Str);
272 if (!NT_SUCCESS(Status))
273 {
274 SHIM_INFO("Failed to delete value from Key \"%wZ\" Status 0x%lx\n", &FullKey, Status);
275 /* This is what we want, so if the key didnt exist, we should not fail :) */
278 }
280 SdbFree(FullKey.Buffer);
281 }
282 SdbpFreeTempStr(&LongPath);
283 return NT_SUCCESS(Status);
284}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
NTSTATUS SdbpOpenKey(PUNICODE_STRING FullPath, BOOL bMachine, ACCESS_MASK Access, PHANDLE KeyHandle)
Definition: layer.c:190
void SdbpFreeTempStr(PSDB_TMP_STR String)
Definition: layer.c:56
BOOL SdbpResolvePath(PSDB_TMP_STR LongPath, PCWSTR wszPath)
Definition: layer.c:163
static PCWSTR BOOL bMachine
Definition: layerapi.c:34
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
NTSYSAPI NTSTATUS NTAPI NtDeleteValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName)
Definition: ntapi.c:1014
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define SdbFree(mem)
Definition: sdbpapi.h:37
#define STATUS_SUCCESS
Definition: shellext.h:65
UNICODE_STRING Str
Definition: layer.c:45
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149

Referenced by SdbSetPermLayerKeys().

◆ SdbGetPermLayerKeys()

BOOL WINAPI SdbGetPermLayerKeys ( PCWSTR  wszPath,
PWSTR  pwszLayers,
PDWORD  pdwBytes,
DWORD  dwFlags 
)

Read the layers specified for the application.

Parameters
[in]wszPathFull pathname of the file.
[out]pwszLayersOn return, the layers set on the file.
pdwBytesThe size of the pwszLayers buffer in bytes, and on return the size of the data written (in bytes)
[in]dwFlagsThe flags, [GPLK_USER | GPLK_MACHINE].
Returns
TRUE if it succeeds, FALSE if it fails.

Definition at line 364 of file layer.c.

365{
366 BOOL Result = FALSE;
367 SDB_TMP_STR LongPath;
368 DWORD dwBytes, dwTotal = 0;
369 if (!wszPath || !pdwBytes)
370 {
371 SHIM_ERR("NULL parameter passed for wszPath or pdwBytes.\n");
372 return FALSE;
373 }
374
375 if (!SdbpResolvePath(&LongPath, wszPath))
376 return FALSE;
377 dwBytes = *pdwBytes;
378 if (dwFlags & GPLK_MACHINE)
379 {
380 if (SdbpGetPermLayersInternal(&LongPath.Str, pwszLayers, &dwBytes, TRUE))
381 {
382 Result = TRUE;
383 dwTotal = dwBytes - sizeof(WCHAR); /* Compensate for the nullterm. */
384 pwszLayers += dwTotal / sizeof(WCHAR);
385 dwBytes = *pdwBytes - dwBytes;
386 if (dwFlags & GPLK_USER)
387 {
388 *(pwszLayers++) = L' ';
389 *pwszLayers = L'\0';
390 dwBytes -= sizeof(WCHAR);
391 dwTotal += sizeof(WCHAR);
392 }
393 }
394 }
395 if (dwFlags & GPLK_USER)
396 {
397 if (SdbpGetPermLayersInternal(&LongPath.Str, pwszLayers, &dwBytes, FALSE))
398 {
399 Result = TRUE;
400 dwTotal += dwBytes - sizeof(WCHAR); /* Compensate for the nullterm. */
401 }
402 else if (dwTotal > 0 && pwszLayers[-1] == L' ')
403 {
404 pwszLayers[-1] = '\0';
405 dwTotal -= sizeof(WCHAR);
406 }
407 }
408 if (dwTotal)
409 dwTotal += sizeof(WCHAR);
410 *pdwBytes = dwTotal;
411 SdbpFreeTempStr(&LongPath);
412 return Result;
413}
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL SdbpGetPermLayersInternal(PUNICODE_STRING FullPath, PWSTR pwszLayers, PDWORD pdwBytes, BOOL bMachine)
Definition: layer.c:230
#define GPLK_USER
Definition: layer.c:15
#define GPLK_MACHINE
Definition: layer.c:16
static PWSTR PDWORD pdwBytes
Definition: layerapi.c:35
static PWSTR pwszLayers
Definition: layerapi.c:35
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by GetLayerInfo(), SdbGetMatchingExe(), and SetPermLayerState().

◆ SdbpAppendLayer()

BOOL SdbpAppendLayer ( PWSTR  target,
DWORD  len,
PCWSTR  layer,
PCWSTR  end 
)

Definition at line 295 of file layer.c.

296{
298 if (target[0])
300
301 if (NT_SUCCESS(Status))
302 {
303 if (end)
304 Status = StringCbCatNW(target, len, layer, (end - layer) * sizeof(WCHAR));
305 else
307 }
308
309 return NT_SUCCESS(Status);
310}
GLuint GLuint end
Definition: gl.h:1545
GLenum GLuint GLint GLint layer
Definition: glext.h:7007
GLenum GLsizei len
Definition: glext.h:6722
GLenum target
Definition: glext.h:7315
#define SPACE_ONLY
Definition: layer.c:36
STRSAFEAPI StringCbCatNW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc, size_t cbToAppend)
Definition: strsafe.h:424
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342

Referenced by SetPermLayerState().

◆ SdbpBuildSignMediaId()

BOOL SdbpBuildSignMediaId ( PSDB_TMP_STR  LongPath)

Definition at line 124 of file layer.c.

125{
126 SDB_TMP_STR Scratch;
127 PWCHAR Ptr;
128
129 SdbpInitTempStr(&Scratch);
130 SdbpResizeTempStr(&Scratch, LongPath->Str.Length / sizeof(WCHAR) + 30);
131 StringCbCopyNW(Scratch.Str.Buffer, Scratch.Str.MaximumLength, LongPath->Str.Buffer, LongPath->Str.Length);
132 Ptr = wcsrchr(LongPath->Str.Buffer, '\\');
133 if (Ptr)
134 {
135 HANDLE FindHandle;
136 WIN32_FIND_DATAW FindData;
137 Ptr[1] = '*';
138 Ptr[2] = '\0';
139 FindHandle = FindFirstFileW(LongPath->Str.Buffer, &FindData);
140 if (FindHandle != INVALID_HANDLE_VALUE)
141 {
142 DWORD SignMedia = 0;
143 do
144 {
145 if (!(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && FindData.nFileSizeLow)
146 SignMedia = SignMedia << 1 ^ FindData.nFileSizeLow;
147 } while (FindNextFileW(FindHandle, &FindData));
148
149 FindClose(FindHandle);
150 SdbpResizeTempStr(LongPath, (LongPath->Str.Length >> 1) + 20);
151 StringCbPrintfW(LongPath->Str.Buffer, LongPath->Str.MaximumLength, SIGN_MEDIA_FMT, SignMedia, Scratch.Str.Buffer + 3);
152 LongPath->Str.Length = (USHORT)SdbpStrlen(LongPath->Str.Buffer) * sizeof(WCHAR);
153 SdbpFreeTempStr(&Scratch);
154 return TRUE;
155 }
156 }
157 SdbpFreeTempStr(&Scratch);
158 SdbpFreeTempStr(LongPath);
159 return FALSE;
160}
#define wcsrchr
Definition: compat.h:16
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
void SdbpResizeTempStr(PSDB_TMP_STR String, WORD newLength)
Definition: layer.c:64
#define SIGN_MEDIA_FMT
Definition: layer.c:39
void SdbpInitTempStr(PSDB_TMP_STR String)
Definition: layer.c:49
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
unsigned short USHORT
Definition: pedump.c:61
DWORD SdbpStrlen(PCWSTR string)
Definition: sdbapi.c:152
STRSAFEAPI StringCbCopyNW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc, size_t cbToCopy)
Definition: strsafe.h:255
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by SdbpResolvePath().

◆ SdbpFreeTempStr()

void SdbpFreeTempStr ( PSDB_TMP_STR  String)

Definition at line 56 of file layer.c.

57{
58 if (String->Str.Buffer != String->FixedBuffer)
59 {
60 SdbFree(String->Str.Buffer);
61 }
62}
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433

Referenced by SdbDeletePermLayerKeys(), SdbGetPermLayerKeys(), SdbpBuildSignMediaId(), SdbpResizeTempStr(), SdbpResolvePath(), and SdbSetPermLayerKeys().

◆ SdbpGetLongPathName()

BOOL SdbpGetLongPathName ( PCWSTR  wszPath,
PSDB_TMP_STR  Result 
)

Definition at line 75 of file layer.c.

76{
77 DWORD max = Result->Str.MaximumLength / 2;
78 DWORD ret = GetLongPathNameW(wszPath, Result->Str.Buffer, max);
79 if (ret)
80 {
81 if (ret >= max)
82 {
84 max = Result->Str.MaximumLength / 2;
85 ret = GetLongPathNameW(wszPath, Result->Str.Buffer, max);
86 }
87 if (ret && ret < max)
88 {
89 Result->Str.Length = ret * 2;
90 return TRUE;
91 }
92 }
93 SHIM_ERR("Failed to convert short path to long path error 0x%lx\n", GetLastError());
94 return FALSE;
95}
DWORD WINAPI GetLongPathNameW(IN LPCWSTR lpszShortPath, OUT LPWSTR lpszLongPath, IN DWORD cchBuffer)
Definition: path.c:1456
#define max(a, b)
Definition: svc.c:63
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by SdbpResolvePath().

◆ SdbpGetPermLayersInternal()

BOOL SdbpGetPermLayersInternal ( PUNICODE_STRING  FullPath,
PWSTR  pwszLayers,
PDWORD  pdwBytes,
BOOL  bMachine 
)

Definition at line 230 of file layer.c.

231{
232 UNICODE_STRING FullKey;
233 ULONG ValueBuffer[(MAX_LAYER_LENGTH * sizeof(WCHAR) + sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(ULONG) - 1) / sizeof(ULONG)];
234 PKEY_VALUE_PARTIAL_INFORMATION PartialInfo = (PVOID)ValueBuffer;
235 ULONG Length = 0;
238
240 if (NT_SUCCESS(Status))
241 {
242 Status = NtQueryValueKey(KeyHandle, FullPath, KeyValuePartialInformation, PartialInfo, sizeof(ValueBuffer), &Length);
243 if (NT_SUCCESS(Status))
244 {
245 StringCbCopyNW(pwszLayers, *pdwBytes, (PCWSTR)PartialInfo->Data, PartialInfo->DataLength);
246 *pdwBytes = PartialInfo->DataLength;
247 }
248 else
249 {
250 SHIM_INFO("Failed to read value info from Key \"%wZ\" Status 0x%lx\n", &FullKey, Status);
251 }
253 SdbFree(FullKey.Buffer);
254 }
255 return NT_SUCCESS(Status);
256}
#define MAX_LAYER_LENGTH
Definition: layer.c:17
@ KeyValuePartialInformation
Definition: nt_native.h:1182
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
const uint16_t * PCWSTR
Definition: typedefs.h:57
void * PVOID
Definition: typedefs.h:50

Referenced by SdbGetPermLayerKeys().

◆ SdbpInitTempStr()

void SdbpInitTempStr ( PSDB_TMP_STR  String)

Definition at line 49 of file layer.c.

50{
51 String->Str.Buffer = String->FixedBuffer;
52 String->Str.Length = 0;
53 String->Str.MaximumLength = sizeof(String->FixedBuffer);
54}

Referenced by SdbpBuildSignMediaId(), and SdbpResolvePath().

◆ SdbpIsPathOnRemovableMedia()

BOOL SdbpIsPathOnRemovableMedia ( PCWSTR  Path)

Definition at line 97 of file layer.c.

98{
99 WCHAR tmp[] = { 'A',':','\\',0 };
100 ULONG type;
101 if (!Path || Path[0] == UNICODE_NULL)
102 {
103 SHIM_ERR("Invalid argument\n");
104 return FALSE;
105 }
106 switch (Path[1])
107 {
108 case L':':
109 break;
110 case L'\\':
111 SHIM_INFO("\"%S\" is a network path.\n", Path);
112 return FALSE;
113 default:
114 SHIM_INFO("\"%S\" not a full path we can operate on.\n", Path);
115 return FALSE;
116 }
117 tmp[0] = Path[0];
118 type = GetDriveTypeW(tmp);
119
120 return type == DRIVE_REMOVABLE || type == DRIVE_CDROM;
121}
#define DRIVE_CDROM
Definition: machpc98.h:119
#define UNICODE_NULL
#define DRIVE_REMOVABLE
Definition: winbase.h:251

Referenced by SdbpResolvePath().

◆ SdbpMatchLayer()

BOOL SdbpMatchLayer ( PCWSTR  start,
PCWSTR  end,
PCWSTR  compare 
)

Definition at line 286 of file layer.c.

287{
288 size_t len;
289 if (!end)
290 return !wcsicmp(start, compare);
291 len = end - start;
292 return wcslen(compare) == len && !_wcsnicmp(start, compare, len);
293}
#define wcsicmp
Definition: compat.h:15
GLuint start
Definition: gl.h:1545
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
Definition: bug.cpp:8

Referenced by SetPermLayerState().

◆ SdbpOpenKey()

NTSTATUS SdbpOpenKey ( PUNICODE_STRING  FullPath,
BOOL  bMachine,
ACCESS_MASK  Access,
PHANDLE  KeyHandle 
)

Definition at line 190 of file layer.c.

191{
192 UNICODE_STRING BasePath;
193 const WCHAR* LayersKey = APPCOMPAT_LAYER_KEY;
196 FullPath->Buffer = NULL;
197 FullPath->Length = FullPath->MaximumLength = 0;
198 if (bMachine)
199 {
201 }
202 else
203 {
205 if (!NT_SUCCESS(Status))
206 {
207 SHIM_ERR("Unable to acquire user registry key, Error: 0x%lx\n", Status);
208 return Status;
209 }
210 }
211 FullPath->MaximumLength = (USHORT)(BasePath.Length + SdbpStrsize(LayersKey));
212 FullPath->Buffer = SdbAlloc(FullPath->MaximumLength);
213 FullPath->Length = 0;
214 RtlAppendUnicodeStringToString(FullPath, &BasePath);
215 if (!bMachine)
216 RtlFreeUnicodeString(&BasePath);
217 RtlAppendUnicodeToString(FullPath, LayersKey);
218
219 Status = NtOpenKey(KeyHandle, Access | Wow64QueryFlag(), &ObjectLayer);
220 if (!NT_SUCCESS(Status))
221 {
222 SHIM_ERR("Unable to open Key \"%wZ\" Status 0x%lx\n", FullPath, Status);
223 SdbFree(FullPath->Buffer);
224 FullPath->Buffer = NULL;
225 }
226 return Status;
227}
DWORD SdbpStrsize(PCWSTR string)
Definition: sdbapi.c:157
#define NULL
Definition: types.h:112
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define APPCOMPAT_LAYER_KEY
Definition: layer.c:34
#define REGISTRY_MACHINE
Definition: layer.c:35
ACCESS_MASK Wow64QueryFlag(void)
Definition: layer.c:179
NTSYSAPI NTSTATUS NTAPI RtlFormatCurrentUserKeyPath(_Out_ _At_(KeyPath->Buffer, __drv_allocatesMem(Mem) _Post_bytecap_(KeyPath->MaximumLength) _Post_bytecount_(KeyPath->Length)) PUNICODE_STRING KeyPath)
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define RTL_INIT_OBJECT_ATTRIBUTES(n, a)
#define SdbAlloc(size)
Definition: sdbpapi.h:35

Referenced by SdbDeletePermLayerKeys(), SdbpGetPermLayersInternal(), and SdbSetPermLayerKeys().

◆ SdbpResizeTempStr()

void SdbpResizeTempStr ( PSDB_TMP_STR  String,
WORD  newLength 
)

Definition at line 64 of file layer.c.

65{
66 if (newLength > String->Str.MaximumLength)
67 {
69 String->Str.MaximumLength = newLength * sizeof(WCHAR);
70 String->Str.Buffer = SdbAlloc(String->Str.MaximumLength);
71 String->Str.Length = 0;
72 }
73}

Referenced by SdbpBuildSignMediaId(), and SdbpGetLongPathName().

◆ SdbpResolvePath()

BOOL SdbpResolvePath ( PSDB_TMP_STR  LongPath,
PCWSTR  wszPath 
)

Definition at line 163 of file layer.c.

164{
165 SdbpInitTempStr(LongPath);
166 if (!SdbpGetLongPathName(wszPath, LongPath))
167 {
168 SdbpFreeTempStr(LongPath);
169 return FALSE;
170 }
172 {
173 return SdbpBuildSignMediaId(LongPath);
174 }
175 return TRUE;
176}
BOOL SdbpIsPathOnRemovableMedia(PCWSTR Path)
Definition: layer.c:97
BOOL SdbpBuildSignMediaId(PSDB_TMP_STR LongPath)
Definition: layer.c:124
BOOL SdbpGetLongPathName(PCWSTR wszPath, PSDB_TMP_STR Result)
Definition: layer.c:75

Referenced by SdbDeletePermLayerKeys(), SdbGetPermLayerKeys(), and SdbSetPermLayerKeys().

◆ SdbSetPermLayerKeys()

BOOL WINAPI SdbSetPermLayerKeys ( PCWSTR  wszPath,
PCWSTR  wszLayers,
BOOL  bMachine 
)

Set or clear the Layer key.

Parameters
[in]wszPathFull pathname of the file.
[in]wszLayersThe layers to add (space separated), or an empty string / NULL to remove all layers.
[in]bMachineTRUE to machine.
Returns
TRUE if it succeeds, FALSE if it fails.

Definition at line 425 of file layer.c.

426{
427 UNICODE_STRING FullKey;
428 SDB_TMP_STR LongPath;
431
432 if (!wszLayers || *wszLayers == '\0')
433 return SdbDeletePermLayerKeys(wszPath, bMachine);
434
435 if (!SdbpResolvePath(&LongPath, wszPath))
436 return FALSE;
437
439 if (NT_SUCCESS(Status))
440 {
442 if (!NT_SUCCESS(Status))
443 {
444 SHIM_INFO("Failed to write a value to Key \"%wZ\" Status 0x%lx\n", &FullKey, Status);
447 }
449 SdbFree(FullKey.Buffer);
450 }
451 SdbpFreeTempStr(&LongPath);
452 return NT_SUCCESS(Status);
453}
BOOL SdbDeletePermLayerKeys(PCWSTR wszPath, BOOL bMachine)
Definition: layer.c:258
#define REG_SZ
Definition: layer.c:22
static PCWSTR wszLayers
Definition: layerapi.c:34
NTSYSAPI NTSTATUS NTAPI NtSetValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN ULONG TitleIndex OPTIONAL, IN ULONG Type, IN PVOID Data, IN ULONG DataSize)
Definition: ntapi.c:859

Referenced by SetPermLayerState().

◆ SetPermLayerState()

BOOL WINAPI SetPermLayerState ( PCWSTR  wszPath,
PCWSTR  wszLayer,
DWORD  dwFlags,
BOOL  bMachine,
BOOL  bEnable 
)

Adds or removes a single layer entry.

Parameters
[in]wszPathFull pathname of the file.
[in]wszLayerThe layer to add or remove.
[in]dwFlagsAdditional flags to add / remove [LAYER_APPLY_TO_SYSTEM_EXES | ???].
[in]bMachineWhen TRUE, the setting applies to all users, when FALSE only applies to the current user.
[in]bEnableTRUE to enable, FALSE to disable a layer / flag specified.
Returns
TRUE if it succeeds, FALSE if it fails.

Definition at line 467 of file layer.c.

468{
469 WCHAR fullLayer[MAX_LAYER_LENGTH] = { 0 };
470 WCHAR newLayer[MAX_LAYER_LENGTH] = { 0 };
471 DWORD dwBytes = sizeof(fullLayer), dwWriteFlags = 0;
472 PWSTR start, p;
473
474 if (!wszLayer)
475 {
476 SHIM_ERR("Invalid argument\n");
477 return FALSE;
478 }
480 {
481 SHIM_ERR("Invalid flags\n");
482 return FALSE;
483 }
485 if (p)
486 {
487 switch (*p)
488 {
489 case ' ':
490 SHIM_ERR("Only one layer can be passed in at a time.\n");
491 return FALSE;
492 case '#':
493 case '!':
494 SHIM_ERR("Flags cannot be passed in with the layer name.\n");
495 return FALSE;
496 }
497 }
498 if (!SdbGetPermLayerKeys(wszPath, fullLayer, &dwBytes, bMachine ? GPLK_MACHINE : GPLK_USER))
499 {
500 fullLayer[0] = '\0';
501 dwBytes = sizeof(fullLayer);
502 }
503
504 start = fullLayer;
505 while (*start == '!' || *start == '#' || *start == ' ' || *start == '\t')
506 {
507 if (*start == '#')
508 dwWriteFlags |= LAYER_APPLY_TO_SYSTEM_EXES;
509 else if (*start == '!')
510 dwWriteFlags |= LAYER_UNK_FLAG2;
511 start++;
512 }
513 if (bEnable)
514 dwWriteFlags |= dwFlags;
515 else
516 dwWriteFlags &= ~dwFlags;
517
518 p = newLayer;
519 if (dwWriteFlags & LAYER_UNK_FLAG2)
520 *(p++) = '!';
521 if (dwWriteFlags & LAYER_APPLY_TO_SYSTEM_EXES)
522 *(p++) = '#';
523
524 do
525 {
526 while (*start == ' ' || *start == '\t')
527 ++start;
528
529 if (*start == '\0')
530 break;
533 {
534 SdbpAppendLayer(newLayer, sizeof(newLayer), start, p);
535 }
536 start = p + 1;
537 } while (p);
538
539 if (bEnable && wszLayer[0])
540 {
541 SdbpAppendLayer(newLayer, sizeof(newLayer), wszLayer, NULL);
542 }
543
544 return SdbSetPermLayerKeys(wszPath, newLayer, bMachine);
545}
GLfloat GLfloat p
Definition: glext.h:8902
BOOL WINAPI SdbSetPermLayerKeys(PCWSTR wszPath, PCWSTR wszLayers, BOOL bMachine)
Definition: layer.c:425
#define LAYER_UNK_FLAG2
Definition: layer.c:19
#define LAYER_APPLY_TO_SYSTEM_EXES
Definition: layer.c:18
BOOL SdbpMatchLayer(PCWSTR start, PCWSTR end, PCWSTR compare)
Definition: layer.c:286
#define LAYER_SEPARATORS
Definition: layer.c:38
BOOL SdbpAppendLayer(PWSTR target, DWORD len, PCWSTR layer, PCWSTR end)
Definition: layer.c:295
BOOL WINAPI SdbGetPermLayerKeys(PCWSTR wszPath, PWSTR pwszLayers, PDWORD pdwBytes, DWORD dwFlags)
Definition: layer.c:364
#define DISALLOWED_LAYER_CHARS
Definition: layer.c:37
static PCWSTR wszLayer
Definition: layerapi.c:36
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcspbrk(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control)
uint16_t * PWSTR
Definition: typedefs.h:56
_In_ BOOL bEnable
Definition: winddi.h:3426

Referenced by CLayerUIPropPage::OnApply().

◆ Wow64QueryFlag()

ACCESS_MASK Wow64QueryFlag ( void  )

Definition at line 179 of file layer.c.

180{
181 if (g_QueryFlag == 0xffffffff)
182 {
183 ULONG_PTR wow64_ptr = 0;
185 g_QueryFlag = (NT_SUCCESS(Status) && wow64_ptr != 0) ? KEY_WOW64_64KEY : 0;
186 }
187 return g_QueryFlag;
188}
@ ProcessWow64Information
Definition: winternl.h:396
static ACCESS_MASK g_QueryFlag
Definition: layer.c:178
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define KEY_WOW64_64KEY
Definition: cmtypes.h:46

Referenced by SdbpOpenKey(), SdbRegisterDatabaseEx(), and SdbUnregisterDatabase().

Variable Documentation

◆ g_QueryFlag

ACCESS_MASK g_QueryFlag = 0xffffffff
static

Definition at line 178 of file layer.c.

Referenced by Wow64QueryFlag().