#include "windef.h"
#include "winbase.h"
#include "strsafe.h"
#include <ntndk.h>
#include "apphelp.h"
Go to the source code of this file.
|
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) |
|
◆ APPCOMPAT_LAYER_KEY
#define APPCOMPAT_LAYER_KEY L"\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers" |
◆ DISALLOWED_LAYER_CHARS
#define DISALLOWED_LAYER_CHARS L" #!" |
◆ GPLK_MACHINE
◆ GPLK_USER
◆ LAYER_APPLY_TO_SYSTEM_EXES
#define LAYER_APPLY_TO_SYSTEM_EXES 1 |
◆ LAYER_SEPARATORS
#define LAYER_SEPARATORS L" \t" |
◆ LAYER_UNK_FLAG2
◆ MAX_LAYER_LENGTH
◆ REG_SZ
◆ REGISTRY_MACHINE
#define REGISTRY_MACHINE L"\\Registry\\Machine" |
◆ SIGN_MEDIA_FMT
#define SIGN_MEDIA_FMT L"SIGN.MEDIA=%X %s" |
◆ SPACE_ONLY
◆ WIN32_NO_STATUS
◆ PSDB_TMP_STR
◆ SDB_TMP_STR
◆ AllowPermLayer()
Determine if we allow permission layers to apply on this file.
- Parameters
-
[in] | Path | Full 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 };
325 {
328 }
330 {
332 break;
336 default:
337 SHIM_INFO(
"\"%S\" not a full path we can operate on.\n",
Path);
339 }
343 {
344
345
346
349 }
351}
PRTL_UNICODE_STRING_BUFFER Path
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
GLuint GLuint GLsizei GLenum type
#define SHIM_INFO(fmt,...)
#define SHIM_ERR(fmt,...)
Referenced by CLayerUIPropPage::InitFile().
◆ SdbDeletePermLayerKeys()
Definition at line 258 of file layer.c.
259{
264
267
270 {
273 {
274 SHIM_INFO(
"Failed to delete value from Key \"%wZ\" Status 0x%lx\n", &FullKey,
Status);
275
278 }
281 }
284}
#define NT_SUCCESS(StatCode)
NTSTATUS SdbpOpenKey(PUNICODE_STRING FullPath, BOOL bMachine, ACCESS_MASK Access, PHANDLE KeyHandle)
void SdbpFreeTempStr(PSDB_TMP_STR String)
BOOL SdbpResolvePath(PSDB_TMP_STR LongPath, PCWSTR wszPath)
static PCWSTR BOOL bMachine
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
NTSYSAPI NTSTATUS NTAPI NtDeleteValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
#define STATUS_OBJECT_NAME_NOT_FOUND
Referenced by SdbSetPermLayerKeys().
◆ SdbGetPermLayerKeys()
Read the layers specified for the application.
- Parameters
-
[in] | wszPath | Full pathname of the file. |
[out] | pwszLayers | On return, the layers set on the file. |
| pdwBytes | The size of the pwszLayers buffer in bytes, and on return the size of the data written (in bytes) |
[in] | dwFlags | The flags, [GPLK_USER | GPLK_MACHINE]. |
- Returns
- TRUE if it succeeds, FALSE if it fails.
Definition at line 364 of file layer.c.
365{
368 DWORD dwBytes, dwTotal = 0;
370 {
371 SHIM_ERR(
"NULL parameter passed for wszPath or pdwBytes.\n");
373 }
374
379 {
381 {
383 dwTotal = dwBytes -
sizeof(
WCHAR);
387 {
390 dwBytes -=
sizeof(
WCHAR);
391 dwTotal +=
sizeof(
WCHAR);
392 }
393 }
394 }
396 {
398 {
400 dwTotal += dwBytes -
sizeof(
WCHAR);
401 }
403 {
405 dwTotal -=
sizeof(
WCHAR);
406 }
407 }
408 if (dwTotal)
409 dwTotal +=
sizeof(
WCHAR);
413}
BOOL SdbpGetPermLayersInternal(PUNICODE_STRING FullPath, PWSTR pwszLayers, PDWORD pdwBytes, BOOL bMachine)
static PWSTR PDWORD pdwBytes
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
_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
Referenced by GetLayerInfo(), SdbGetMatchingExe(), and SetPermLayerState().
◆ SdbpAppendLayer()
Definition at line 295 of file layer.c.
296{
300
302 {
305 else
307 }
308
310}
GLenum GLuint GLint GLint layer
STRSAFEAPI StringCbCatNW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc, size_t cbToAppend)
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Referenced by SetPermLayerState().
◆ SdbpBuildSignMediaId()
Definition at line 124 of file layer.c.
125{
128
134 {
141 {
143 do
144 {
146 SignMedia = SignMedia << 1 ^ FindData.nFileSizeLow;
148
155 }
156 }
160}
#define INVALID_HANDLE_VALUE
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
BOOL WINAPI FindClose(HANDLE hFindFile)
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
void SdbpResizeTempStr(PSDB_TMP_STR String, WORD newLength)
void SdbpInitTempStr(PSDB_TMP_STR String)
#define FILE_ATTRIBUTE_DIRECTORY
DWORD SdbpStrlen(PCWSTR string)
STRSAFEAPI StringCbCopyNW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc, size_t cbToCopy)
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Referenced by SdbpResolvePath().
◆ SdbpFreeTempStr()
◆ SdbpGetLongPathName()
Definition at line 75 of file layer.c.
76{
80 {
82 {
86 }
88 {
91 }
92 }
95}
DWORD WINAPI GetLongPathNameW(IN LPCWSTR lpszShortPath, OUT LPWSTR lpszLongPath, IN DWORD cchBuffer)
DWORD WINAPI GetLastError(void)
Referenced by SdbpResolvePath().
◆ SdbpGetPermLayersInternal()
Definition at line 230 of file layer.c.
231{
238
241 {
244 {
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 }
254 }
256}
@ KeyValuePartialInformation
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)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Referenced by SdbGetPermLayerKeys().
◆ SdbpInitTempStr()
◆ SdbpIsPathOnRemovableMedia()
Definition at line 97 of file layer.c.
98{
99 WCHAR tmp[] = {
'A',
':',
'\\',0 };
102 {
105 }
107 {
109 break;
113 default:
114 SHIM_INFO(
"\"%S\" not a full path we can operate on.\n",
Path);
116 }
119
121}
Referenced by SdbpResolvePath().
◆ SdbpMatchLayer()
Definition at line 286 of file layer.c.
287{
293}
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_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)
Referenced by SetPermLayerState().
◆ SdbpOpenKey()
Definition at line 190 of file layer.c.
191{
199 {
201 }
202 else
203 {
206 {
207 SHIM_ERR(
"Unable to acquire user registry key, Error: 0x%lx\n",
Status);
209 }
210 }
218
221 {
222 SHIM_ERR(
"Unable to open Key \"%wZ\" Status 0x%lx\n", FullPath,
Status);
225 }
227}
DWORD SdbpStrsize(PCWSTR string)
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
#define OBJ_CASE_INSENSITIVE
#define APPCOMPAT_LAYER_KEY
ACCESS_MASK Wow64QueryFlag(void)
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)
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)
Referenced by SdbDeletePermLayerKeys(), SdbpGetPermLayersInternal(), and SdbSetPermLayerKeys().
◆ SdbpResizeTempStr()
◆ SdbpResolvePath()
◆ SdbSetPermLayerKeys()
Set or clear the Layer key.
- Parameters
-
[in] | wszPath | Full pathname of the file. |
[in] | wszLayers | The layers to add (space separated), or an empty string / NULL to remove all layers. |
[in] | bMachine | TRUE to machine. |
- Returns
- TRUE if it succeeds, FALSE if it fails.
Definition at line 425 of file layer.c.
426{
431
434
437
440 {
443 {
444 SHIM_INFO(
"Failed to write a value to Key \"%wZ\" Status 0x%lx\n", &FullKey,
Status);
447 }
450 }
453}
BOOL SdbDeletePermLayerKeys(PCWSTR wszPath, BOOL bMachine)
NTSYSAPI NTSTATUS NTAPI NtSetValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN ULONG TitleIndex OPTIONAL, IN ULONG Type, IN PVOID Data, IN ULONG DataSize)
Referenced by SetPermLayerState().
◆ SetPermLayerState()
Adds or removes a single layer entry.
- Parameters
-
[in] | wszPath | Full pathname of the file. |
[in] | wszLayer | The layer to add or remove. |
[in] | dwFlags | Additional flags to add / remove [LAYER_APPLY_TO_SYSTEM_EXES | ???]. |
[in] | bMachine | When TRUE, the setting applies to all users, when FALSE only applies to the current user. |
[in] | bEnable | TRUE 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{
471 DWORD dwBytes =
sizeof(fullLayer), dwWriteFlags = 0;
473
475 {
478 }
480 {
483 }
486 {
488 {
489 case ' ':
490 SHIM_ERR(
"Only one layer can be passed in at a time.\n");
492 case '#':
493 case '!':
494 SHIM_ERR(
"Flags cannot be passed in with the layer name.\n");
496 }
497 }
499 {
500 fullLayer[0] = '\0';
501 dwBytes = sizeof(fullLayer);
502 }
503
506 {
509 else if (*
start ==
'!')
512 }
515 else
517
523
524 do
525 {
528
530 break;
533 {
535 }
538
540 {
542 }
543
545}
BOOL WINAPI SdbSetPermLayerKeys(PCWSTR wszPath, PCWSTR wszLayers, BOOL bMachine)
#define LAYER_APPLY_TO_SYSTEM_EXES
BOOL SdbpMatchLayer(PCWSTR start, PCWSTR end, PCWSTR compare)
BOOL SdbpAppendLayer(PWSTR target, DWORD len, PCWSTR layer, PCWSTR end)
BOOL WINAPI SdbGetPermLayerKeys(PCWSTR wszPath, PWSTR pwszLayers, PDWORD pdwBytes, DWORD dwFlags)
#define DISALLOWED_LAYER_CHARS
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcspbrk(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control)
Referenced by CLayerUIPropPage::OnApply().
◆ Wow64QueryFlag()
Definition at line 179 of file layer.c.
180{
182 {
186 }
188}
@ ProcessWow64Information
static ACCESS_MASK g_QueryFlag
#define NtCurrentProcess()
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Referenced by SdbpOpenKey(), SdbRegisterDatabaseEx(), and SdbUnregisterDatabase().
◆ g_QueryFlag