ReactOS  0.4.14-dev-583-g2a1ba2c
layerapi.c File Reference
#include <ntstatus.h>
#include <windows.h>
#include <shlwapi.h>
#include <winnt.h>
#include <winternl.h>
#include <winerror.h>
#include <stdio.h>
#include <strsafe.h>
#include "wine/test.h"
#include "apitest_iathook.h"
#include "apphelp_apitest.h"
Include dependency graph for layerapi.c:

Go to the source code of this file.

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 expect_Sdb   (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_Sdb_imp
 
#define expect_LayerValue   (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_LayerValue_imp
 
#define expect_LayerValue2   (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_LayerValue_imp2
 

Functions

static BOOL (WINAPI *pAllowPermLayer)(PCWSTR path)
 
static DWORD QueryFlag (void)
 
static BOOL setLayerValue (BOOL bMachine, const char *valueName, const char *value)
 
static void expect_LayerValue_imp (BOOL bMachine, const char *valueName, const char *value)
 
static void expect_LayerValue_imp2 (BOOL bMachine, const char *valueName, const char *value, int use_alt, const char *alt_value)
 
void expect_Sdb_imp (PCSTR path, DWORD type, BOOL result, DWORD lenResult, PCSTR stringResult)
 
BOOL wrapAllowPermLayer (const char *str)
 
static void test_AllowPermLayer (void)
 
static BOOL wrapSdbSetPermLayerKeys (PCWSTR wszPath, PCSTR szLayers, BOOL bMachine)
 
static void test_SdbSetPermLayerKeysLevel (BOOL bMachine, const char *file)
 
static void test_SdbGetPermLayerKeys (void)
 
static BOOL wrapSetPermLayerState (PCWSTR wszPath, PCSTR szLayer, DWORD dwFlags, BOOL bMachine, BOOL bEnable)
 
static void test_SetPermLayerStateLevel (BOOL bMachine, const char *file)
 
static void test_SetPermLayer (void)
 
static BOOL create_file (LPCSTR dir, LPCSTR name, int filler, DWORD size)
 
static BOOL delete_file (LPCSTR dir, LPCSTR name)
 
 UINT (WINAPI *pGetDriveTypeW)(LPCWSTR target)
 
UINT WINAPI mGetDriveTypeW (LPCWSTR target)
 
static BOOL wrapSdbSetPermLayerKeys2 (LPCSTR dir, LPCSTR name, PCSTR szLayers, BOOL bMachine)
 
BOOL expect_files (const char *dir, int num,...)
 
static void test_Sign_Media (void)
 
 START_TEST (layerapi)
 

Variables

static HMODULE hdll
 
static PCWSTR wszLayers
 
static PCWSTR BOOL bMachine
 
static PWSTR pwszLayers
 
static PWSTR PDWORD pdwBytes
 
static PWSTR PDWORD DWORD dwFlags
 
static PCWSTR wszLayer
 
static PCWSTR DWORD BOOL BOOL bEnable
 
static DWORD g_QueryFlag = 0xffffffff
 
static char g_FakeDrive = 0
 

Macro Definition Documentation

◆ expect_LayerValue

#define expect_LayerValue   (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_LayerValue_imp

Definition at line 154 of file layerapi.c.

◆ expect_LayerValue2

#define expect_LayerValue2   (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_LayerValue_imp2

Definition at line 155 of file layerapi.c.

◆ expect_Sdb

#define expect_Sdb   (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_Sdb_imp

Definition at line 153 of file layerapi.c.

◆ GPLK_MACHINE

#define GPLK_MACHINE   2

Definition at line 27 of file layerapi.c.

◆ GPLK_USER

#define GPLK_USER   1

Definition at line 26 of file layerapi.c.

◆ LAYER_APPLY_TO_SYSTEM_EXES

#define LAYER_APPLY_TO_SYSTEM_EXES   1

Definition at line 29 of file layerapi.c.

◆ MAX_LAYER_LENGTH

#define MAX_LAYER_LENGTH   256

Definition at line 28 of file layerapi.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 9 of file layerapi.c.

Function Documentation

◆ BOOL()

static BOOL ( WINAPI pAllowPermLayer)
static

◆ create_file()

static BOOL create_file ( LPCSTR  dir,
LPCSTR  name,
int  filler,
DWORD  size 
)
static

Definition at line 568 of file layerapi.c.

569 {
570  char target[MAX_PATH], *tmp;
571  HANDLE file;
573 
574  tmp = malloc(size);
575  memset(tmp, filler, size);
576 
579  return FALSE;
580 
581  WriteFile(file, tmp, size, &size, NULL);
582  CloseHandle(file);
583  free(tmp);
584  return TRUE;
585 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define TRUE
Definition: types.h:120
static const char filler[0x1000]
Definition: loader.c:167
#define CloseHandle
Definition: compat.h:406
#define free
Definition: debug_ros.c:5
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
unsigned int dir
Definition: maze.c:112
GLsizeiptr size
Definition: glext.h:5919
#define MAX_PATH
Definition: compat.h:26
const char file[]
Definition: icontest.c:11
LPSTR WINAPI PathCombineA(LPSTR lpszDest, LPCSTR lpszDir, LPCSTR lpszFile)
Definition: path.c:154
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define CREATE_ALWAYS
Definition: disk.h:72
Definition: name.c:38
GLenum target
Definition: glext.h:7315
#define malloc
Definition: debug_ros.c:4
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:407
#define memset(x, y, z)
Definition: compat.h:39
Definition: fci.c:126

Referenced by test_Sign_Media().

◆ delete_file()

static BOOL delete_file ( LPCSTR  dir,
LPCSTR  name 
)
static

Definition at line 587 of file layerapi.c.

588 {
589  char target[MAX_PATH];
591  return DeleteFileA(target);
592 }
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
unsigned int dir
Definition: maze.c:112
#define MAX_PATH
Definition: compat.h:26
LPSTR WINAPI PathCombineA(LPSTR lpszDest, LPCSTR lpszDir, LPCSTR lpszFile)
Definition: path.c:154
Definition: name.c:38
GLenum target
Definition: glext.h:7315

Referenced by test_Sign_Media().

◆ expect_files()

BOOL expect_files ( const char dir,
int  num,
  ... 
)

Definition at line 616 of file layerapi.c.

617 {
618  char finddir[MAX_PATH + 20];
619  va_list args;
620  WIN32_FIND_DATAA find = { 0 };
621  HANDLE hFind;
622  int cmp = 0;
623 
624  va_start(args, num);
625 
626  PathCombineA(finddir, dir, "*");
627  hFind = FindFirstFileA(finddir, &find);
628  if (hFind != INVALID_HANDLE_VALUE)
629  {
630  const char* file;
631  do
632  {
633  if (!(find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
634  {
635  if (--num < 0)
636  break;
637  file = va_arg(args, const char*);
638  cmp = strcmp(file, find.cFileName);
639  }
640  } while (cmp == 0 && FindNextFileA(hFind, &find));
641  FindClose(hFind);
642  }
643  va_end(args);
644  return cmp == 0 && num == 0;
645 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
#define cmp(status, error)
Definition: error.c:114
BOOL WINAPI FindNextFileA(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAA lpFindFileData)
Definition: find.c:336
Definition: match.c:390
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
unsigned int dir
Definition: maze.c:112
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define MAX_PATH
Definition: compat.h:26
const char file[]
Definition: icontest.c:11
GLuint GLuint num
Definition: glext.h:9618
LPSTR WINAPI PathCombineA(LPSTR lpszDest, LPCSTR lpszDir, LPCSTR lpszFile)
Definition: path.c:154
#define va_arg(ap, T)
Definition: acmsvcex.h:89
#define va_start(ap, A)
Definition: acmsvcex.h:91
static TAGID TAGID find
Definition: db.cpp:153
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define args
Definition: format.c:66
HANDLE WINAPI FindFirstFileA(IN LPCSTR lpFileName, OUT LPWIN32_FIND_DATAA lpFindFileData)
Definition: find.c:263
Definition: fci.c:126
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

Referenced by test_Sign_Media().

◆ expect_LayerValue_imp()

static void expect_LayerValue_imp ( BOOL  bMachine,
const char valueName,
const char value 
)
static

Definition at line 73 of file layerapi.c.

74 {
75  HKEY key = NULL;
77  "Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers", 0, NULL, 0, QueryFlag() | KEY_QUERY_VALUE, NULL, &key, NULL);
78  winetest_ok(lstatus == ERROR_SUCCESS, "Expected to be able to open a registry key\n");
79  if (lstatus == ERROR_SUCCESS)
80  {
81  char data[512] = { 0 };
82  DWORD dwType = 0;
83  DWORD dwDataLen = sizeof(data);
84  lstatus = RegQueryValueExA(key, valueName, NULL, &dwType, (LPBYTE)data, &dwDataLen);
85  if (value)
86  {
87  winetest_ok(lstatus == ERROR_SUCCESS, "Expected to get a valid value, err: %u\n", lstatus);
88  if (lstatus == ERROR_SUCCESS)
89  {
90  winetest_ok(dwType == REG_SZ, "Expected the type to be REG_SZ, was: %u\n", dwType);
91  winetest_ok(!strcmp(data, value), "Expected the data to be: '%s', was: '%s'\n", value, data);
92  }
93  }
94  else
95  {
96  winetest_ok(lstatus == ERROR_FILE_NOT_FOUND, "Expected not to find the value %s\n", valueName);
97  }
99  }
100 }
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4023
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
void __winetest_cdecl winetest_ok(int condition, const char *msg,...)
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
static DWORD QueryFlag(void)
Definition: layerapi.c:41
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
LONG WINAPI RegCreateKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD Reserved, _In_ LPSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_ LPDWORD lpdwDisposition)
Definition: reg.c:1029
static PCWSTR BOOL bMachine
Definition: layerapi.c:34
Definition: path.c:41
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22

Referenced by expect_LayerValue_imp2().

◆ expect_LayerValue_imp2()

static void expect_LayerValue_imp2 ( BOOL  bMachine,
const char valueName,
const char value,
int  use_alt,
const char alt_value 
)
static

Definition at line 102 of file layerapi.c.

103 {
104  expect_LayerValue_imp(bMachine, valueName, use_alt ? alt_value : value);
105 }
static void expect_LayerValue_imp(BOOL bMachine, const char *valueName, const char *value)
Definition: layerapi.c:73
static PCWSTR BOOL bMachine
Definition: layerapi.c:34

◆ expect_Sdb_imp()

void expect_Sdb_imp ( PCSTR  path,
DWORD  type,
BOOL  result,
DWORD  lenResult,
PCSTR  stringResult 
)

Definition at line 108 of file layerapi.c.

109 {
110  WCHAR pathW[MAX_PATH], buffer[MAX_LAYER_LENGTH] = { 0 };
111  char resultBuffer[MAX_LAYER_LENGTH] = { 0 };
112  DWORD dwBufSize = sizeof(buffer);
113 
114  /* In case of a failure, the buffer size is sometimes set to 0, and sometimes not touched,
115  depending on the version. Either case is fine, since the function returns FALSE anyway. */
116 
117  MultiByteToWideChar(CP_ACP, 0, path, -1, pathW, MAX_PATH);
118 
119  winetest_ok(pSdbGetPermLayerKeys(pathW, buffer, &dwBufSize, type) == result, "Expected pSdbGetPermLayerKeys to %s\n", (result ? "succeed" : "fail"));
120  if (!result && lenResult == 0xffffffff)
121  winetest_ok(dwBufSize == 0 || dwBufSize == sizeof(buffer), "Expected dwBufSize to be 0 or %u, was %u\n", sizeof(buffer), dwBufSize);
122  else
123  winetest_ok(dwBufSize == lenResult ||
124  /* W2k3 is off by 2 when concatenating user / machine */
125  broken(g_WinVersion < WINVER_VISTA && type == (GPLK_MACHINE|GPLK_USER) && (lenResult + 2) == dwBufSize),
126  "Expected dwBufSize to be %u, was %u\n", lenResult, dwBufSize);
127  if (result)
128  {
129  winetest_ok(lstrlenW(buffer) * sizeof(WCHAR) + sizeof(WCHAR) == lenResult, "Expected lstrlenW(buffer)*2+2 to be %u, was %u\n",
130  lenResult, lstrlenW(buffer) * sizeof(WCHAR) + sizeof(WCHAR));
131  }
132  WideCharToMultiByte(CP_ACP, 0, buffer, -1, resultBuffer, sizeof(resultBuffer), NULL, NULL);
133  winetest_ok(!strcmp(stringResult, resultBuffer), "Expected the result to be '%s', was '%s'\n", stringResult, resultBuffer);
134 
135  if (result)
136  {
137  UNICODE_STRING pathNT;
138 
139  if (RtlDosPathNameToNtPathName_U(pathW, &pathNT, NULL, NULL))
140  {
141  memset(buffer, 0, sizeof(buffer));
142  dwBufSize = sizeof(buffer);
143  winetest_ok(pSdbGetPermLayerKeys(pathNT.Buffer, buffer, &dwBufSize, type) == FALSE, "Expected pSdbGetPermLayerKeys to fail for NT path\n");
144 
145  RtlFreeUnicodeString(&pathNT);
146  }
147  }
148 
149 }
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
#define lstrlenW
Definition: compat.h:415
smooth NULL
Definition: ftsmooth.c:416
#define GPLK_USER
Definition: layerapi.c:26
static DWORD g_WinVersion
__wchar_t WCHAR
Definition: xmlstorage.h:180
void __winetest_cdecl winetest_ok(int condition, const char *msg,...)
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define broken(x)
Definition: _sntprintf.h:21
#define MAX_LAYER_LENGTH
Definition: layerapi.c:28
#define WINVER_VISTA
#define MultiByteToWideChar
Definition: compat.h:100
#define GPLK_MACHINE
Definition: layerapi.c:27
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
GLuint64EXT * result
Definition: glext.h:11304
#define memset(x, y, z)
Definition: compat.h:39
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)

◆ mGetDriveTypeW()

UINT WINAPI mGetDriveTypeW ( LPCWSTR  target)

Definition at line 597 of file layerapi.c.

598 {
599  UINT uRet = pGetDriveTypeW(target);
600  if(g_FakeDrive && target && (char)*target == g_FakeDrive)
601  return DRIVE_CDROM;
602  return uRet;
603 }
static char g_FakeDrive
Definition: layerapi.c:594
#define DRIVE_CDROM
Definition: winbase.h:251
unsigned int UINT
Definition: ndis.h:50
GLenum target
Definition: glext.h:7315

Referenced by test_Sign_Media().

◆ QueryFlag()

static DWORD QueryFlag ( void  )
static

Definition at line 41 of file layerapi.c.

42 {
43  if (g_QueryFlag == 0xffffffff)
44  {
45  ULONG_PTR wow64_ptr = 0;
47  g_QueryFlag = (NT_SUCCESS(status) && wow64_ptr != 0) ? KEY_WOW64_64KEY : 0;
48  }
49  return g_QueryFlag;
50 }
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
static DWORD g_QueryFlag
Definition: layerapi.c:40
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define KEY_WOW64_64KEY
Definition: cmtypes.h:46
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Definition: ps.c:97

Referenced by expect_LayerValue_imp(), and setLayerValue().

◆ setLayerValue()

static BOOL setLayerValue ( BOOL  bMachine,
const char valueName,
const char value 
)
static

Definition at line 53 of file layerapi.c.

54 {
55  HKEY key = NULL;
57  "Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers", 0, NULL, 0, QueryFlag() | KEY_SET_VALUE, NULL, &key, NULL);
58  if (lstatus == ERROR_SUCCESS)
59  {
60  if (value)
61  lstatus = RegSetValueExA(key, valueName, 0, REG_SZ, (const BYTE*)value, (DWORD)strlen(value)+1);
62  else
63  {
64  lstatus = RegDeleteValueA(key, valueName);
65  lstatus = (lstatus == ERROR_FILE_NOT_FOUND ? ERROR_SUCCESS : lstatus);
66  }
68  }
69  return lstatus == ERROR_SUCCESS;
70 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_SET_VALUE
Definition: nt_native.h:1017
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
unsigned long DWORD
Definition: ntddk_ex.h:95
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
unsigned char BYTE
Definition: mem.h:68
LONG WINAPI RegDeleteValueA(HKEY hKey, LPCSTR lpValueName)
Definition: reg.c:2319
static DWORD QueryFlag(void)
Definition: layerapi.c:41
LONG WINAPI RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE *lpData, DWORD cbData)
Definition: reg.c:4812
LONG WINAPI RegCreateKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD Reserved, _In_ LPSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_ LPDWORD lpdwDisposition)
Definition: reg.c:1029
static PCWSTR BOOL bMachine
Definition: layerapi.c:34
Definition: path.c:41
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22

Referenced by test_SdbGetPermLayerKeys(), test_SetPermLayer(), and test_SetPermLayerStateLevel().

◆ START_TEST()

START_TEST ( layerapi  )

Definition at line 810 of file layerapi.c.

811 {
813  /*SetEnvironmentVariable("SHIM_DEBUG_LEVEL", "4");*/
814  hdll = LoadLibraryA("apphelp.dll");
815  pAllowPermLayer = (void *)GetProcAddress(hdll, "AllowPermLayer");
816  pSdbSetPermLayerKeys = (void *)GetProcAddress(hdll, "SdbSetPermLayerKeys");
817  pSdbGetPermLayerKeys = (void *)GetProcAddress(hdll, "SdbGetPermLayerKeys");
818  pSetPermLayerState = (void *)GetProcAddress(hdll, "SetPermLayerState");
820 
821  if (!pAllowPermLayer)
822  {
823  skip("Skipping tests with AllowPermLayer, function not found\n");
824  }
825  else
826  {
828  }
829 
830  if (!pSdbSetPermLayerKeys)
831  {
832  skip("Skipping tests with SdbSetPermLayerKeys, function not found\n");
833  }
834  else
835  {
836  if (!pSdbGetPermLayerKeys)
837  {
838  skip("Skipping tests with SdbGetPermLayerKeys, function not found\n");
839  }
840  else
841  {
843  }
844 
845  if (!pSetPermLayerState)
846  {
847  skip("Skipping tests with SetPermLayerState, function not found\n");
848  }
849  else
850  {
852  test_Sign_Media();
853  }
854  }
855 }
static void test_SetPermLayer(void)
Definition: layerapi.c:529
DWORD get_host_winver(void)
Definition: data.c:788
static void test_AllowPermLayer(void)
Definition: layerapi.c:170
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
static DWORD g_WinVersion
static void test_Sign_Media(void)
Definition: layerapi.c:648
void silence_debug_output(void)
Definition: data.c:833
static void test_SdbGetPermLayerKeys(void)
Definition: layerapi.c:238
static HMODULE hdll
Definition: layerapi.c:32
#define skip(...)
Definition: atltest.h:64
#define GetProcAddress(x, y)
Definition: compat.h:418

◆ test_AllowPermLayer()

static void test_AllowPermLayer ( void  )
static

Definition at line 170 of file layerapi.c.

171 {
172  char buf[20];
173  char drive_letter;
174  UINT drivetype = 0;
175  ok(pAllowPermLayer(NULL) == FALSE, "Expected AllowPermLayer to fail for NULL\n");
177  {
178  ok(wrapAllowPermLayer("-:"), "Expected AllowPermLayer to succeed\n");
179  ok(wrapAllowPermLayer("@:"), "Expected AllowPermLayer to succeed\n");
180  ok(wrapAllowPermLayer("4:"), "Expected AllowPermLayer to succeed\n");
181  ok(wrapAllowPermLayer("*:"), "Expected AllowPermLayer to succeed\n");
182  }
183  ok(wrapAllowPermLayer("*a") == FALSE, "Expected AllowPermLayer to fail\n");
184  ok(wrapAllowPermLayer("*\\") == FALSE, "Expected AllowPermLayer to fail\n");
185  for (drive_letter = 'a'; drive_letter <= 'z'; ++drive_letter)
186  {
187  sprintf(buf, "%c:\\", drive_letter);
188  drivetype = GetDriveTypeA(buf);
189  ok(wrapAllowPermLayer(buf) == (drivetype != DRIVE_REMOTE), "Expected AllowPermLayer to be %d for %c:\\\n", (drivetype != DRIVE_REMOTE), drive_letter);
190  }
191 }
UINT WINAPI GetDriveTypeA(IN LPCSTR lpRootPathName)
Definition: disk.c:468
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define DRIVE_REMOTE
Definition: winbase.h:250
smooth NULL
Definition: ftsmooth.c:416
static DWORD g_WinVersion
BOOL wrapAllowPermLayer(const char *str)
Definition: layerapi.c:158
#define WINVER_WIN8
#define ok(value,...)
Definition: atltest.h:57
unsigned int UINT
Definition: ndis.h:50

Referenced by START_TEST().

◆ test_SdbGetPermLayerKeys()

static void test_SdbGetPermLayerKeys ( void  )
static

Definition at line 238 of file layerapi.c.

239 {
240  WCHAR pathW[MAX_PATH], buffer[MAX_LAYER_LENGTH] = { 0 };
241  char file[MAX_PATH + 20], tmp[MAX_PATH + 20];
242  BOOL bUser, bMachine;
243  HANDLE hfile;
244  DWORD dwBufSize = sizeof(buffer);
245 
246  GetTempPathA(MAX_PATH, tmp);
247  GetLongPathNameA(tmp, file, sizeof(file));
248  PathCombineA(tmp, file, "notexist.exe");
249  PathAppendA(file, "test_file.exe");
250 
251  /* Check that we can access the keys */
252  bUser = setLayerValue(FALSE, file, "RUNASADMIN WINXPSP3");
253  expect_LayerValue(FALSE, file, "RUNASADMIN WINXPSP3");
254  ok(bUser, "Expected to be able to set atleast the flags for the user\n");
255  if (!bUser)
256  {
257  skip("Cannot do any tests if I cannot set some values\n");
258  return;
259  }
260  bMachine = setLayerValue(TRUE, file, "WINXPSP3 WINXPSP2");
261  if (bMachine)
262  {
263  expect_LayerValue(TRUE, file, "WINXPSP3 WINXPSP2");
264  }
265 
266 
268  ok(hfile != INVALID_HANDLE_VALUE, "CreateFile failed on '%s'..\n", file);
269  if (hfile == INVALID_HANDLE_VALUE)
270  {
271  skip("Running these tests is useless without a file present\n");
272  return;
273  }
274  CloseHandle(hfile);
275 
276  MultiByteToWideChar(CP_ACP, 0, file, -1, pathW, MAX_PATH);
277 
278  /* Parameter validation */
279  ok(pSdbGetPermLayerKeys(NULL, NULL, NULL, 0) == FALSE, "Expected pSdbGetPermLayerKeys to fail\n");
280  ok(pSdbGetPermLayerKeys(pathW, NULL, NULL, 0) == FALSE, "Expected pSdbGetPermLayerKeys to fail\n");
281  ok(pSdbGetPermLayerKeys(pathW, buffer, NULL, 0) == FALSE, "Expected pSdbGetPermLayerKeys to fail\n");
282  ok(pSdbGetPermLayerKeys(pathW, buffer, &dwBufSize, 0) == FALSE, "Expected pSdbGetPermLayerKeys to fail\n");
283  ok(dwBufSize == 0, "Expected dwBufSize to be %u, was %u\n", 0, dwBufSize);
284 
285  /* It fails on a nonexisting file */
286  expect_Sdb(tmp, GPLK_USER | GPLK_MACHINE, FALSE, 0xffffffff, "");
287  expect_Sdb(file, GPLK_USER, TRUE, 40, "RUNASADMIN WINXPSP3");
288  GetShortPathNameA(file, tmp, sizeof(tmp));
289  expect_Sdb(tmp, GPLK_USER, TRUE, 40, "RUNASADMIN WINXPSP3");
290 
291  if (bMachine)
292  {
293  /* Query from HKLM */
294  expect_Sdb(file, GPLK_MACHINE, TRUE, 36, "WINXPSP3 WINXPSP2");
295  /* Query from both, showing that duplicates are not removed */
296  expect_Sdb(file, GPLK_USER | GPLK_MACHINE, TRUE, 76, "WINXPSP3 WINXPSP2 RUNASADMIN WINXPSP3");
297 
298  /* Showing that no validation is done on the value read. */
299  ok(setLayerValue(TRUE, file, "!#!# WINXPSP3 WINXPSP3 !# WINXPSP2 "), "Expected setLayerValue not to fail\n");
300  expect_Sdb(file, GPLK_MACHINE, TRUE, 82, "!#!# WINXPSP3 WINXPSP3 !# WINXPSP2 ");
301  /* Showing that a space is inserted, even if the last char was already a space. */
302  expect_Sdb(file, GPLK_USER | GPLK_MACHINE, TRUE, 122, "!#!# WINXPSP3 WINXPSP3 !# WINXPSP2 RUNASADMIN WINXPSP3");
303  /* Now clear the user key */
305  /* Request both, to show that the last space (from the key) is not cut off. */
306  expect_Sdb(file, GPLK_USER | GPLK_MACHINE, TRUE, 82, "!#!# WINXPSP3 WINXPSP3 !# WINXPSP2 ");
307  setLayerValue(FALSE, file, "RUNASADMIN WINXPSP3");
308  }
309  else
310  {
311  skip("Skipping tests for HKLM, cannot alter the registry\n");
312  }
313  /* Fail from these paths */
314  StringCbPrintfA(tmp, sizeof(tmp), "\\?\\%s", file);
315  expect_Sdb(tmp, GPLK_USER, FALSE, 0xffffffff, "");
316  StringCbPrintfA(tmp, sizeof(tmp), "\\??\\%s", file);
317  expect_Sdb(tmp, GPLK_USER, FALSE, 0xffffffff, "");
318 
319  ok(setLayerValue(FALSE, file, "!#!# RUNASADMIN RUNASADMIN !# WINXPSP3 "), "Expected setLayerValue not to fail\n");
320  /* There is no validation on information read back. */
321  expect_Sdb(file, GPLK_USER, TRUE, 90, "!#!# RUNASADMIN RUNASADMIN !# WINXPSP3 ");
322 
323 
324  /* Cleanup */
325  ok(DeleteFileA(file), "DeleteFile failed....\n");
328 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
#define CP_ACP
Definition: compat.h:99
BOOL WINAPI PathAppendA(LPSTR lpszPath, LPCSTR lpszAppend)
Definition: path.c:101
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
GLuint buffer
Definition: glext.h:5915
#define expect_LayerValue
Definition: layerapi.c:154
DWORD WINAPI GetLongPathNameA(IN LPCSTR lpszShortPath, OUT LPSTR lpszLongPath, IN DWORD cchBuffer)
Definition: path.c:1670
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define GPLK_USER
Definition: layerapi.c:26
STRSAFEAPI StringCbPrintfA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:547
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD WINAPI GetShortPathNameA(IN LPCSTR lpszLongPath, OUT LPSTR lpszShortPath, IN DWORD cchBuffer)
Definition: path.c:1751
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
LPSTR WINAPI PathCombineA(LPSTR lpszDest, LPCSTR lpszDir, LPCSTR lpszFile)
Definition: path.c:154
#define expect_Sdb
Definition: layerapi.c:153
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define CREATE_ALWAYS
Definition: disk.h:72
#define MAX_LAYER_LENGTH
Definition: layerapi.c:28
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
#define ok(value,...)
Definition: atltest.h:57
#define MultiByteToWideChar
Definition: compat.h:100
#define GPLK_MACHINE
Definition: layerapi.c:27
#define skip(...)
Definition: atltest.h:64
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:407
static PCWSTR BOOL bMachine
Definition: layerapi.c:34
static BOOL setLayerValue(BOOL bMachine, const char *valueName, const char *value)
Definition: layerapi.c:53
Definition: fci.c:126

Referenced by START_TEST().

◆ test_SdbSetPermLayerKeysLevel()

static void test_SdbSetPermLayerKeysLevel ( BOOL  bMachine,
const char file 
)
static

Definition at line 200 of file layerapi.c.

201 {
202  WCHAR fileW[MAX_PATH+20];
203  WCHAR emptyString[1] = { 0 };
204 
206 
207  /* Test some parameter validation. */
208  ok(pSdbSetPermLayerKeys(NULL, NULL, bMachine) == FALSE, "Expected SdbSetPermLayerKeys to fail\n");
209  ok(pSdbSetPermLayerKeys(NULL, emptyString, bMachine) == FALSE, "Expected SdbSetPermLayerKeys to fail\n");
210  ok(pSdbSetPermLayerKeys(emptyString, emptyString, bMachine) == FALSE, "Expected SdbSetPermLayerKeys to fail\n");
211  ok(pSdbSetPermLayerKeys(fileW, NULL, bMachine) == TRUE, "Expected SdbSetPermLayerKeys to succeed\n");
212  ok(pSdbSetPermLayerKeys(fileW, emptyString, bMachine) == TRUE, "Expected SdbSetPermLayerKeys to fail\n");
213 
214  /* Basic tests */
215  ok(wrapSdbSetPermLayerKeys(fileW, "TEST1", bMachine), "Expected SdbSetPermLayerKeys to succeed\n");
216  expect_LayerValue(bMachine, file, "TEST1");
217 
218  ok(wrapSdbSetPermLayerKeys(fileW, "TEST1 TEST2", bMachine), "Expected SdbSetPermLayerKeys to succeed\n");
219  expect_LayerValue(bMachine, file, "TEST1 TEST2");
220 
221  /* SdbSetPermLayerKeys does not do any validation of the value passed in. */
222  ok(wrapSdbSetPermLayerKeys(fileW, "!#$% TEST1 TEST2", bMachine), "Expected SdbSetPermLayerKeys to succeed\n");
223  expect_LayerValue(bMachine, file, "!#$% TEST1 TEST2");
224 
225  ok(wrapSdbSetPermLayerKeys(fileW, "!#$% TEST1 TEST2", bMachine), "Expected SdbSetPermLayerKeys to succeed\n");
226  expect_LayerValue(bMachine, file, "!#$% TEST1 TEST2");
227 
228  ok(pSdbSetPermLayerKeys(fileW, NULL, bMachine) == TRUE, "Expected SdbSetPermLayerKeys to succeed\n");
230 
231  ok(wrapSdbSetPermLayerKeys(fileW, " ", bMachine), "Expected SdbSetPermLayerKeys to succeed\n");
233 
234  ok(pSdbSetPermLayerKeys(fileW, NULL, bMachine) == TRUE, "Expected SdbSetPermLayerKeys to fail\n");
236 }
#define TRUE
Definition: types.h:120
#define CP_ACP
Definition: compat.h:99
#define expect_LayerValue
Definition: layerapi.c:154
smooth NULL
Definition: ftsmooth.c:416
static BOOL wrapSdbSetPermLayerKeys(PCWSTR wszPath, PCSTR szLayers, BOOL bMachine)
Definition: layerapi.c:193
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
#define ok(value,...)
Definition: atltest.h:57
#define MultiByteToWideChar
Definition: compat.h:100
static const WCHAR fileW[]
Definition: url.c:111
static PCWSTR BOOL bMachine
Definition: layerapi.c:34
Definition: fci.c:126

Referenced by test_SetPermLayer().

◆ test_SetPermLayer()

static void test_SetPermLayer ( void  )
static

Definition at line 529 of file layerapi.c.

530 {
531  char file[MAX_PATH + 20], tmp[MAX_PATH + 20];
532  HANDLE hfile;
533 
534  GetTempPathA(MAX_PATH, tmp);
535  GetLongPathNameA(tmp, file, sizeof(file));
536  PathAppendA(file, "test_file.exe");
537 
539  ok(hfile != INVALID_HANDLE_VALUE, "CreateFile failed for '%s'\n", file);
540  if (hfile == INVALID_HANDLE_VALUE)
541  {
542  skip("Running these tests is useless without a file present\n");
543  return;
544  }
545  CloseHandle(hfile);
546 
547  if (setLayerValue(FALSE, file, NULL))
548  {
551  }
552  else
553  {
554  skip("Skipping SetPermLayerStateLevel tests for User, because I cannot prepare the environment\n");
555  }
556  if (setLayerValue(TRUE, file, NULL))
557  {
560  }
561  else
562  {
563  skip("Skipping SetPermLayerStateLevel tests for Machine (HKLM), because I cannot prepare the environment\n");
564  }
565  ok(DeleteFileA(file), "DeleteFile failed....\n");
566 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
BOOL WINAPI PathAppendA(LPSTR lpszPath, LPCSTR lpszAppend)
Definition: path.c:101
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD WINAPI GetLongPathNameA(IN LPCSTR lpszShortPath, OUT LPSTR lpszLongPath, IN DWORD cchBuffer)
Definition: path.c:1670
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define MAX_PATH
Definition: compat.h:26
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static void test_SetPermLayerStateLevel(BOOL bMachine, const char *file)
Definition: layerapi.c:338
#define CREATE_ALWAYS
Definition: disk.h:72
static void test_SdbSetPermLayerKeysLevel(BOOL bMachine, const char *file)
Definition: layerapi.c:200
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:407
static BOOL setLayerValue(BOOL bMachine, const char *valueName, const char *value)
Definition: layerapi.c:53
Definition: fci.c:126

Referenced by START_TEST().

◆ test_SetPermLayerStateLevel()

static void test_SetPermLayerStateLevel ( BOOL  bMachine,
const char file 
)
static

Definition at line 338 of file layerapi.c.

339 {
340  WCHAR fileW[MAX_PATH+20];
341  WCHAR emptyString[1] = { 0 };
342  DWORD dwFlag;
343 
345 
346  /* Test some parameter validation. */
347  ok(pSetPermLayerState(fileW, NULL, 0, bMachine, 0) == FALSE, "Expected SetPermLayerState to fail\n");
349 
350  ok(pSetPermLayerState(fileW, NULL, 0, bMachine, 1) == FALSE, "Expected SetPermLayerState to fail\n");
352 
353  ok(wrapSetPermLayerState(fileW, "", 0, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
355 
356  ok(wrapSetPermLayerState(fileW, "", 0, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
358 
359  ok(wrapSetPermLayerState(NULL, NULL, 0, bMachine, 0) == FALSE, "Expected SetPermLayerState to fail\n");
361 
362  ok(wrapSetPermLayerState(NULL, NULL, 0, bMachine, 1) == FALSE, "Expected SetPermLayerState to fail\n");
364 
365  ok(wrapSetPermLayerState(emptyString, "", 0, bMachine, 0) == FALSE, "Expected SetPermLayerState to fail\n");
367 
368  ok(wrapSetPermLayerState(emptyString, "", 0, bMachine, 1) == FALSE, "Expected SetPermLayerState to fail\n");
370 
371  ok(wrapSetPermLayerState(emptyString, "TEST", 0, bMachine, 0) == FALSE, "Expected SetPermLayerState to fail\n");
373 
374  if (g_WinVersion <= WINVER_WIN8)
375  {
376  ok(wrapSetPermLayerState(emptyString, "TEST", 0, bMachine, 1) == FALSE, "Expected SetPermLayerState to fail\n");
378  }
379 
380 
381  /* Now, on to the actual tests. */
383  ok(wrapSetPermLayerState(fileW, "TEST", 0, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
385 
386  ok(wrapSetPermLayerState(fileW, "TEST", 0, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
387  expect_LayerValue(bMachine, file, "TEST");
388 
389  ok(wrapSetPermLayerState(fileW, "", 0, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
390  expect_LayerValue(bMachine, file, "TEST");
391 
392  ok(wrapSetPermLayerState(fileW, "test", 0, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
393  expect_LayerValue(bMachine, file, "test");
394 
395  ok(wrapSetPermLayerState(fileW, "TEST", 0, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
397 
398  ok(wrapSetPermLayerState(fileW, "TEST", 0, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
399  expect_LayerValue(bMachine, file, "TEST");
400 
401  ok(wrapSetPermLayerState(fileW, "TEST1", 0, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
402  expect_LayerValue2(bMachine, file, "TEST TEST1", g_WinVersion >= WINVER_WIN8, "TEST1 TEST");
403 
404  ok(wrapSetPermLayerState(fileW, "TEST2", 0, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
405  expect_LayerValue2(bMachine, file, "TEST TEST1 TEST2", g_WinVersion >= WINVER_WIN8, "TEST2 TEST1 TEST");
406 
407  ok(wrapSetPermLayerState(fileW, "TEST1", 0, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
408  expect_LayerValue2(bMachine, file, "TEST TEST2", g_WinVersion >= WINVER_WIN8, "TEST2 TEST");
409 
410  ok(wrapSetPermLayerState(fileW, "TEST", 0, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
411  expect_LayerValue(bMachine, file, "TEST2");
412 
413  ok(wrapSetPermLayerState(fileW, "TEST2", 0, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
415 
416  /* Valid flags until win8: !# */
417  /* Key is empty, now play around with the flags. */
418  for (dwFlag = ((g_WinVersion >= WINVER_WIN8) ? 6 : 2); dwFlag < 32; ++dwFlag)
419  {
420  ok(wrapSetPermLayerState(fileW, "TEST", (1<<dwFlag), bMachine, 1) == FALSE, "Expected SetPermLayerState to fail on 0x%x\n", (1<<dwFlag));
421  }
423 
424  /* Add layer flags */
425  ok(wrapSetPermLayerState(fileW, "TEST", LAYER_APPLY_TO_SYSTEM_EXES, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
426  expect_LayerValue(bMachine, file, "# TEST");
427 
428  ok(wrapSetPermLayerState(fileW, "TEST2", 2, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
429  expect_LayerValue2(bMachine, file, "!# TEST TEST2", g_WinVersion >= WINVER_WIN8, "!# TEST2 TEST");
430 
431  ok(wrapSetPermLayerState(fileW, "TEST", 0, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
432  expect_LayerValue2(bMachine, file, "!# TEST2 TEST", g_WinVersion >= WINVER_WIN8, "!# TEST TEST2");
433 
434  ok(wrapSetPermLayerState(fileW, "TEST3", 0, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
435  expect_LayerValue2(bMachine, file, "!# TEST2 TEST TEST3", g_WinVersion >= WINVER_WIN8, "!# TEST3 TEST TEST2");
436 
437  /* Remove on a flag removes that flag from the start. */
438  ok(wrapSetPermLayerState(fileW, "TEST2", 2, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
439  expect_LayerValue2(bMachine, file, "# TEST TEST3", g_WinVersion >= WINVER_WIN8, "# TEST3 TEST");
440 
441  ok(wrapSetPermLayerState(fileW, "", LAYER_APPLY_TO_SYSTEM_EXES, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
442  expect_LayerValue2(bMachine, file, "TEST TEST3", g_WinVersion >= WINVER_WIN8, "TEST3 TEST");
443 
444  ok(wrapSetPermLayerState(fileW, "", LAYER_APPLY_TO_SYSTEM_EXES | 2, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
445  expect_LayerValue2(bMachine, file, "!# TEST TEST3", g_WinVersion >= WINVER_WIN8, "!# TEST3 TEST");
446 
447  ok(wrapSetPermLayerState(fileW, "TEST3", LAYER_APPLY_TO_SYSTEM_EXES, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
448  expect_LayerValue(bMachine, file, "! TEST");
449 
450  ok(wrapSetPermLayerState(fileW, "TEST", 2, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
452 
453  /* Try adding multiple layers: */
454  ok(wrapSetPermLayerState(fileW, "TEST TEST2", LAYER_APPLY_TO_SYSTEM_EXES | 2, bMachine, 1) == FALSE, "Expected SetPermLayerState to fail\n");
456 
457  ok(wrapSetPermLayerState(fileW, "TEST2", 0, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
458  expect_LayerValue(bMachine, file, "TEST2");
459 
460  /* Try adding flags in via layer string */
461  ok(wrapSetPermLayerState(fileW, "#", 0, bMachine, 1) == FALSE, "Expected SetPermLayerState to fail\n");
462  expect_LayerValue(bMachine, file, "TEST2");
463 
464  ok(wrapSetPermLayerState(fileW, "!", 0, bMachine, 1) == FALSE, "Expected SetPermLayerState to fail\n");
465  expect_LayerValue(bMachine, file, "TEST2");
466 
467  /* Now we prepare the registry with some crap to see how data is validated. */
468  setLayerValue(bMachine, file, "!#!# TEST2 TEST2 !# TEST ");
469 
470  ok(wrapSetPermLayerState(fileW, "TEST1", 0, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
471  expect_LayerValue2(bMachine, file, "!# TEST2 TEST2 !# TEST TEST1", g_WinVersion >= WINVER_WIN8, "!# TEST1 TEST2 TEST2 !# TEST");
472 
473  /* Removing a duplicate entry will remove all instances of it */
474  ok(wrapSetPermLayerState(fileW, "TEST2", 0, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
475  expect_LayerValue2(bMachine, file, "!# !# TEST TEST1", g_WinVersion >= WINVER_WIN8, "!# TEST1 !# TEST");
476 
477  /* Adding a flag cleans other flags (from the start) */
478  ok(wrapSetPermLayerState(fileW, "", LAYER_APPLY_TO_SYSTEM_EXES, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
479  expect_LayerValue2(bMachine, file, "!# TEST TEST1", g_WinVersion >= WINVER_WIN8, "!# TEST1 !# TEST");
480 
482  {
483  ok(wrapSetPermLayerState(fileW, "$%$%^^", 0, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
484  expect_LayerValue(bMachine, file, "!# TEST TEST1 $%$%^^");
485  }
486 
487  setLayerValue(bMachine, file, "!#!# TEST2 !# TEST ");
488  ok(wrapSetPermLayerState(fileW, "", LAYER_APPLY_TO_SYSTEM_EXES, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
489  expect_LayerValue(bMachine, file, "! TEST2 !# TEST");
490 
491  /* Tabs are treated as spaces */
492  setLayerValue(bMachine, file, "!#!# TEST2 \t TEST2 !# \t TEST ");
493  ok(wrapSetPermLayerState(fileW, "TEST2", 0, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
494  expect_LayerValue2(bMachine, file, "!# !# TEST TEST2", g_WinVersion >= WINVER_WIN8, "!# TEST2 !# TEST");
495 
496  /* Newlines are left as-is */
497  setLayerValue(bMachine, file, "!#!# TEST2 \n TEST2 !# \r\n TEST ");
498  ok(wrapSetPermLayerState(fileW, "TEST2", 0, bMachine, 1) == TRUE, "Expected SetPermLayerState to succeed\n");
499  expect_LayerValue2(bMachine, file, "!# \n !# \r\n TEST TEST2", g_WinVersion >= WINVER_WIN8, "!# TEST2 \n !# \r\n TEST");
500 
501  /* Whitespace and duplicate flags are eaten from the start */
502  setLayerValue(bMachine, file, " !#!# TEST2 \t TEST2 !# \t TEST ");
503  ok(wrapSetPermLayerState(fileW, "", LAYER_APPLY_TO_SYSTEM_EXES, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
504  expect_LayerValue(bMachine, file, "! TEST2 TEST2 !# TEST");
505 
506  setLayerValue(bMachine, file, "!# !# TEST2 !# TEST ");
507  ok(wrapSetPermLayerState(fileW, "", LAYER_APPLY_TO_SYSTEM_EXES, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
508  expect_LayerValue(bMachine, file, "! TEST2 !# TEST");
509 
510  ok(wrapSetPermLayerState(fileW, "", LAYER_APPLY_TO_SYSTEM_EXES, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
511  expect_LayerValue(bMachine, file, "! TEST2 !# TEST");
512 
513  ok(wrapSetPermLayerState(fileW, "", 2, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
514  expect_LayerValue(bMachine, file, "TEST2 !# TEST");
515 
516  /* First flags are cleaned, then a layer is removed. */
517  ok(wrapSetPermLayerState(fileW, "TEST2", 2, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
518  expect_LayerValue(bMachine, file, "!# TEST");
519 
520  /* Nothing is changed, still it succeeds. */
521  ok(wrapSetPermLayerState(fileW, "TEST2", 2, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
522  expect_LayerValue(bMachine, file, "# TEST");
523 
524  /* And remove the last bits. */
525  ok(wrapSetPermLayerState(fileW, "TEST", LAYER_APPLY_TO_SYSTEM_EXES, bMachine, 0) == TRUE, "Expected SetPermLayerState to succeed\n");
527 }
#define TRUE
Definition: types.h:120
#define expect_LayerValue2
Definition: layerapi.c:155
#define CP_ACP
Definition: compat.h:99
#define expect_LayerValue
Definition: layerapi.c:154
smooth NULL
Definition: ftsmooth.c:416
static DWORD g_WinVersion
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WINVER_WIN8
static BOOL wrapSetPermLayerState(PCWSTR wszPath, PCSTR szLayer, DWORD dwFlags, BOOL bMachine, BOOL bEnable)
Definition: layerapi.c:331
#define ok(value,...)
Definition: atltest.h:57
#define MultiByteToWideChar
Definition: compat.h:100
#define LAYER_APPLY_TO_SYSTEM_EXES
Definition: layerapi.c:29
static const WCHAR fileW[]
Definition: url.c:111
static PCWSTR BOOL bMachine
Definition: layerapi.c:34
static BOOL setLayerValue(BOOL bMachine, const char *valueName, const char *value)
Definition: layerapi.c:53
Definition: fci.c:126

Referenced by test_SetPermLayer().

◆ test_Sign_Media()

static void test_Sign_Media ( void  )
static

Definition at line 648 of file layerapi.c.

649 {
650  char workdir[MAX_PATH], subdir[MAX_PATH], drive[5] = "Z:";
651  BOOL ret;
652 
653  DWORD logical_drives = GetLogicalDrives();
654  g_FakeDrive = 0;
655  for (drive[0] = 'D'; drive[0] <= 'Z'; drive[0]++)
656  {
657  DWORD idx = 1 << (drive[0] - 'D' + 3);
658  if (!(logical_drives & idx))
659  {
660  g_FakeDrive = drive[0];
661  break;
662  }
663  }
664  if (!g_FakeDrive)
665  {
666  skip("Unable to find a free drive\n");
667  return;
668  }
669 
671  ok(ret, "GetTempPathA error: %d\n", GetLastError());
672  PathAppendA(workdir, "apphelp_test");
673 
675  ok(ret, "CreateDirectoryA error: %d\n", GetLastError());
676 
677  PathCombineA(subdir, workdir, "sub");
678  ret = CreateDirectoryA(subdir, NULL);
679  ok(ret, "CreateDirectoryA error: %d\n", GetLastError());
680 
682  ok(ret, "DefineDosDeviceA error: %d\n", GetLastError());
683  if(ret)
684  {
685  ret = RedirectIat(GetModuleHandleA("apphelp.dll"), "kernel32.dll", "GetDriveTypeW",
686  (ULONG_PTR)mGetDriveTypeW, (ULONG_PTR*)&pGetDriveTypeW);
688  ok(ret, "Expected redirect_iat to succeed\n");
689  if(ret)
690  {
691  ok(create_file(workdir, "test.exe", 'a', 4), "create_file error: %d\n", GetLastError());
692 
693  ok(wrapSdbSetPermLayerKeys2(drive, "test.exe", "TEST", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
694  /* 4 */
695  /* test.exe */
696  expect_LayerValue(0, "SIGN.MEDIA=4 test.exe", "TEST");
697  ok(wrapSdbSetPermLayerKeys2(drive, "test.exe", "", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
698 
699  ok(create_file(workdir, "test.txt", 'a', 1), "create_file error: %d\n", GetLastError());
700 
701  if (!expect_files(workdir, 2, "test.exe", "test.txt"))
702  {
703  skip("Skipping test, files are not returned in the expected order by the FS\n");
704  }
705  else
706  {
707  ok(wrapSdbSetPermLayerKeys2(drive, "test.exe", "TEST", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
708  /* (4 << 1) ^ 1 */
709  /* test.exe test.txt */
710  expect_LayerValue(0, "SIGN.MEDIA=9 test.exe", "TEST");
711  ok(wrapSdbSetPermLayerKeys2(drive, "test.exe", "", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
712  }
713 
714  ok(create_file(workdir, "test.zz", 'a', 0x1000), "create_file error: %d\n", GetLastError());
715 
716  if (!expect_files(workdir, 3, "test.exe", "test.txt", "test.zz"))
717  {
718  skip("Skipping test, files are not returned in the expected order by the FS\n");
719  }
720  else
721  {
722  ok(wrapSdbSetPermLayerKeys2(drive, "test.exe", "TEST", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
723  /* (((4 << 1) ^ 1) << 1) ^ 0x1000 */
724  /* test.exe test.txt test.zz */
725  expect_LayerValue(0, "SIGN.MEDIA=1012 test.exe", "TEST");
726  ok(wrapSdbSetPermLayerKeys2(drive, "test.exe", "", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
727  }
728 
729  ok(create_file(subdir, "test.exe", 'a', 0x10203), "create_file error: %d\n", GetLastError());
730 
731  if (!expect_files(subdir, 1, "test.exe"))
732  {
733  skip("Skipping test, files are not returned in the expected order by the FS\n");
734  }
735  else
736  {
737  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "TEST", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
738  /* 0x10203 */
739  /* test.exe */
740  expect_LayerValue(0, "SIGN.MEDIA=10203 sub\\test.exe", "TEST");
741  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
742  }
743 
744  ok(create_file(subdir, "test.bbb", 'a', 0), "create_file error: %d\n", GetLastError());
745 
746  if (!expect_files(subdir, 2, "test.bbb", "test.exe"))
747  {
748  skip("Skipping test, files are not returned in the expected order by the FS\n");
749  }
750  else
751  {
752  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "TEST", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
753  /* 0x10203 */
754  /* test.exe */
755  expect_LayerValue(0, "SIGN.MEDIA=10203 sub\\test.exe", "TEST");
756  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
757  }
758 
759  ok(create_file(subdir, "TEST.txt", 'a', 0x30201), "create_file error: %d\n", GetLastError());
760 
761  if (!expect_files(subdir, 3, "test.bbb", "test.exe", "TEST.txt"))
762  {
763  skip("Skipping test, files are not returned in the expected order by the FS\n");
764  }
765  else
766  {
767  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "TEST", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
768  /* (0x10203 << 1) ^ 0x30201 */
769  /* test.exe TEST.txt */
770  expect_LayerValue(0, "SIGN.MEDIA=10607 sub\\test.exe", "TEST");
771  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
772  }
773 
774  ok(create_file(subdir, "TEST.aaa", 'a', 0x3a2a1), "create_file error: %d\n", GetLastError());
775 
776  if (!expect_files(subdir, 4, "TEST.aaa", "test.bbb", "test.exe", "TEST.txt"))
777  {
778  skip("Skipping test, files are not returned in the expected order by the FS\n");
779  }
780  else
781  {
782  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "TEST", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
783  /* (((0x3a2a1 << 1) ^ 0x10203) << 1) ^ 0x30201 */
784  /* TEST.aaa test.exe TEST.txt */
785  expect_LayerValue(0, "SIGN.MEDIA=F8C83 sub\\test.exe", "TEST");
786  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
787  }
788 
789  ret = RestoreIat(GetModuleHandleA("apphelp.dll"), "kernel32.dll", "GetDriveTypeW", (ULONG_PTR)pGetDriveTypeW);
790  ok(ret, "Expected restore_iat to succeed\n");
791 
792  ok(delete_file(subdir, "test.bbb"), "delete_file error: %d\n", GetLastError());
793  ok(delete_file(subdir, "TEST.aaa"), "delete_file error: %d\n", GetLastError());
794  ok(delete_file(subdir, "TEST.txt"), "delete_file error: %d\n", GetLastError());
795  ok(delete_file(subdir, "test.exe"), "delete_file error: %d\n", GetLastError());
796  ok(delete_file(workdir, "test.zz"), "delete_file error: %d\n", GetLastError());
797  ok(delete_file(workdir, "test.txt"), "delete_file error: %d\n", GetLastError());
798  ok(delete_file(workdir, "test.exe"), "delete_file error: %d\n", GetLastError());
799  }
801  ok(ret, "DefineDosDeviceA error: %d\n", GetLastError());
802  }
803  ret = RemoveDirectoryA(subdir);
804  ok(ret, "RemoveDirectoryA error: %d\n", GetLastError());
806  ok(ret, "RemoveDirectoryA error: %d\n", GetLastError());
807 }
BOOL expect_files(const char *dir, int num,...)
Definition: layerapi.c:616
static BOOL wrapSdbSetPermLayerKeys2(LPCSTR dir, LPCSTR name, PCSTR szLayers, BOOL bMachine)
Definition: layerapi.c:605
#define DDD_REMOVE_DEFINITION
Definition: winbase.h:505
BOOL WINAPI PathAppendA(LPSTR lpszPath, LPCSTR lpszAppend)
Definition: path.c:101
#define DDD_NO_BROADCAST_SYSTEM
Definition: winbase.h:507
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define expect_LayerValue
Definition: layerapi.c:154
uint32_t ULONG_PTR
Definition: typedefs.h:63
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned int idx
Definition: utils.c:41
BOOL WINAPI CreateDirectoryA(IN LPCSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:37
smooth NULL
Definition: ftsmooth.c:416
static DWORD g_WinVersion
static BOOL RestoreIat(HMODULE TargetDll, PCSTR DllName, PCSTR FunctionName, ULONG_PTR OriginalFunction)
static BOOL create_file(LPCSTR dir, LPCSTR name, int filler, DWORD size)
Definition: layerapi.c:568
static char workdir[MAX_PATH]
Definition: batch.c:26
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
LPSTR WINAPI PathCombineA(LPSTR lpszDest, LPCSTR lpszDir, LPCSTR lpszFile)
Definition: path.c:154
int ret
static char g_FakeDrive
Definition: layerapi.c:594
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
#define WINVER_WIN8
DWORD WINAPI GetLogicalDrives(VOID)
Definition: disk.c:110
static BOOL RedirectIat(HMODULE TargetDll, PCSTR DllName, PCSTR FunctionName, ULONG_PTR NewFunction, ULONG_PTR *OriginalFunction)
BOOL WINAPI DefineDosDeviceA(DWORD dwFlags, LPCSTR lpDeviceName, LPCSTR lpTargetPath)
Definition: dosdev.c:162
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI RemoveDirectoryA(IN LPCSTR lpPathName)
Definition: dir.c:714
static BOOL delete_file(LPCSTR dir, LPCSTR name)
Definition: layerapi.c:587
#define skip(...)
Definition: atltest.h:64
UINT WINAPI mGetDriveTypeW(LPCWSTR target)
Definition: layerapi.c:597

Referenced by START_TEST().

◆ UINT()

UINT ( WINAPI pGetDriveTypeW)

◆ wrapAllowPermLayer()

BOOL wrapAllowPermLayer ( const char str)

Definition at line 158 of file layerapi.c.

159 {
160  WCHAR buf[100];
161  MultiByteToWideChar(CP_ACP, 0, str, -1, buf, 100);
162  return pAllowPermLayer(buf);
163 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define CP_ACP
Definition: compat.h:99
const WCHAR * str
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MultiByteToWideChar
Definition: compat.h:100

Referenced by test_AllowPermLayer().

◆ wrapSdbSetPermLayerKeys()

static BOOL wrapSdbSetPermLayerKeys ( PCWSTR  wszPath,
PCSTR  szLayers,
BOOL  bMachine 
)
static

Definition at line 193 of file layerapi.c.

194 {
197  return pSdbSetPermLayerKeys(wszPath, wszLayers, bMachine);
198 }
#define CP_ACP
Definition: compat.h:99
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_LAYER_LENGTH
Definition: layerapi.c:28
#define MultiByteToWideChar
Definition: compat.h:100
static PCWSTR wszLayers
Definition: layerapi.c:34
static PCWSTR BOOL bMachine
Definition: layerapi.c:34

Referenced by test_SdbSetPermLayerKeysLevel().

◆ wrapSdbSetPermLayerKeys2()

static BOOL wrapSdbSetPermLayerKeys2 ( LPCSTR  dir,
LPCSTR  name,
PCSTR  szLayers,
BOOL  bMachine 
)
static

Definition at line 605 of file layerapi.c.

606 {
607  char szPath[MAX_PATH];
611  MultiByteToWideChar(CP_ACP, 0, szPath, -1, wszPath, MAX_PATH);
612  return pSdbSetPermLayerKeys(wszPath, wszLayers, bMachine);
613 }
#define CP_ACP
Definition: compat.h:99
unsigned int dir
Definition: maze.c:112
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
LPSTR WINAPI PathCombineA(LPSTR lpszDest, LPCSTR lpszDir, LPCSTR lpszFile)
Definition: path.c:154
#define MAX_LAYER_LENGTH
Definition: layerapi.c:28
LPCWSTR szPath
Definition: env.c:35
#define MultiByteToWideChar
Definition: compat.h:100
Definition: name.c:38
static PCWSTR wszLayers
Definition: layerapi.c:34
static PCWSTR BOOL bMachine
Definition: layerapi.c:34

Referenced by test_Sign_Media().

◆ wrapSetPermLayerState()

static BOOL wrapSetPermLayerState ( PCWSTR  wszPath,
PCSTR  szLayer,
DWORD  dwFlags,
BOOL  bMachine,
BOOL  bEnable 
)
static

Definition at line 331 of file layerapi.c.

332 {
335  return pSetPermLayerState(wszPath, wszLayer, dwFlags, bMachine, bEnable);
336 }
#define CP_ACP
Definition: compat.h:99
static PCWSTR wszLayer
Definition: layerapi.c:36
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define MAX_LAYER_LENGTH
Definition: layerapi.c:28
_In_ BOOL bEnable
Definition: winddi.h:3426
#define MultiByteToWideChar
Definition: compat.h:100
static PCWSTR BOOL bMachine
Definition: layerapi.c:34

Referenced by test_SetPermLayerStateLevel().

Variable Documentation

◆ bEnable

Definition at line 36 of file layerapi.c.

◆ bMachine

◆ dwFlags

Definition at line 35 of file layerapi.c.

◆ g_FakeDrive

char g_FakeDrive = 0
static

Definition at line 594 of file layerapi.c.

Referenced by mGetDriveTypeW(), and test_Sign_Media().

◆ g_QueryFlag

DWORD g_QueryFlag = 0xffffffff
static

Definition at line 40 of file layerapi.c.

Referenced by QueryFlag().

◆ hdll

HMODULE hdll
static

Definition at line 32 of file layerapi.c.

Referenced by START_TEST().

◆ pdwBytes

◆ pwszLayers

PWSTR pwszLayers

Definition at line 35 of file layerapi.c.

Referenced by SdbGetPermLayerKeys(), SdbpAddLayerMatches(), and SdbpGetPermLayersInternal().

◆ wszLayer

PCWSTR wszLayer

Definition at line 36 of file layerapi.c.

Referenced by SeiSetLayerEnvVar(), SetPermLayerState(), and wrapSetPermLayerState().

◆ wszLayers