ReactOS  0.4.13-dev-73-gcfe54aa
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 "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 153 of file layerapi.c.

◆ expect_LayerValue2

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

Definition at line 154 of file layerapi.c.

◆ expect_Sdb

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

Definition at line 152 of file layerapi.c.

◆ GPLK_MACHINE

#define GPLK_MACHINE   2

Definition at line 26 of file layerapi.c.

◆ GPLK_USER

#define GPLK_USER   1

Definition at line 25 of file layerapi.c.

◆ LAYER_APPLY_TO_SYSTEM_EXES

#define LAYER_APPLY_TO_SYSTEM_EXES   1

Definition at line 28 of file layerapi.c.

◆ MAX_LAYER_LENGTH

#define MAX_LAYER_LENGTH   256

Definition at line 27 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 567 of file layerapi.c.

568 {
569  char target[MAX_PATH], *tmp;
570  HANDLE file;
572 
573  tmp = malloc(size);
574  memset(tmp, filler, size);
575 
578  return FALSE;
579 
580  WriteFile(file, tmp, size, &size, NULL);
581  CloseHandle(file);
582  free(tmp);
583  return TRUE;
584 }
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:398
#define free
Definition: debug_ros.c:5
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#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:36
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:399
#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 586 of file layerapi.c.

587 {
588  char target[MAX_PATH];
590  return DeleteFileA(target);
591 }
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:36
GLenum target
Definition: glext.h:7315

Referenced by test_Sign_Media().

◆ expect_files()

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

Definition at line 615 of file layerapi.c.

616 {
617  char finddir[MAX_PATH + 20];
618  va_list args;
619  WIN32_FIND_DATAA find = { 0 };
620  HANDLE hFind;
621  int cmp = 0;
622 
623  va_start(args, num);
624 
625  PathCombineA(finddir, dir, "*");
626  hFind = FindFirstFileA(finddir, &find);
627  if (hFind != INVALID_HANDLE_VALUE)
628  {
629  const char* file;
630  do
631  {
632  if (!(find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
633  {
634  if (--num < 0)
635  break;
636  file = va_arg(args, const char*);
637  cmp = strcmp(file, find.cFileName);
638  }
639  } while (cmp == 0 && FindNextFileA(hFind, &find));
640  FindClose(hFind);
641  }
642  va_end(args);
643  return cmp == 0 && num == 0;
644 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#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 72 of file layerapi.c.

73 {
74  HKEY key = NULL;
76  "Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers", 0, NULL, 0, QueryFlag() | KEY_QUERY_VALUE, NULL, &key, NULL);
77  winetest_ok(lstatus == ERROR_SUCCESS, "Expected to be able to open a registry key\n");
78  if (lstatus == ERROR_SUCCESS)
79  {
80  char data[512] = { 0 };
81  DWORD dwType = 0;
82  DWORD dwDataLen = sizeof(data);
83  lstatus = RegQueryValueExA(key, valueName, NULL, &dwType, (LPBYTE)data, &dwDataLen);
84  if (value)
85  {
86  winetest_ok(lstatus == ERROR_SUCCESS, "Expected to get a valid value, err: %u\n", lstatus);
87  if (lstatus == ERROR_SUCCESS)
88  {
89  winetest_ok(dwType == REG_SZ, "Expected the type to be REG_SZ, was: %u\n", dwType);
90  winetest_ok(!strcmp(data, value), "Expected the data to be: '%s', was: '%s'\n", value, data);
91  }
92  }
93  else
94  {
95  winetest_ok(lstatus == ERROR_FILE_NOT_FOUND, "Expected not to find the value %s\n", valueName);
96  }
98  }
99 }
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:4041
#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:40
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:1032
static PCWSTR BOOL bMachine
Definition: layerapi.c:33
Definition: path.c:42
#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 101 of file layerapi.c.

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

◆ expect_Sdb_imp()

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

Definition at line 107 of file layerapi.c.

108 {
109  WCHAR pathW[MAX_PATH], buffer[MAX_LAYER_LENGTH] = { 0 };
110  char resultBuffer[MAX_LAYER_LENGTH] = { 0 };
111  DWORD dwBufSize = sizeof(buffer);
112 
113  /* In case of a failure, the buffer size is sometimes set to 0, and sometimes not touched,
114  depending on the version. Either case is fine, since the function returns FALSE anyway. */
115 
116  MultiByteToWideChar(CP_ACP, 0, path, -1, pathW, MAX_PATH);
117 
118  winetest_ok(pSdbGetPermLayerKeys(pathW, buffer, &dwBufSize, type) == result, "Expected pSdbGetPermLayerKeys to %s\n", (result ? "succeed" : "fail"));
119  if (!result && lenResult == 0xffffffff)
120  winetest_ok(dwBufSize == 0 || dwBufSize == sizeof(buffer), "Expected dwBufSize to be 0 or %u, was %u\n", sizeof(buffer), dwBufSize);
121  else
122  winetest_ok(dwBufSize == lenResult ||
123  /* W2k3 is off by 2 when concatenating user / machine */
124  broken(g_WinVersion < WINVER_VISTA && type == (GPLK_MACHINE|GPLK_USER) && (lenResult + 2) == dwBufSize),
125  "Expected dwBufSize to be %u, was %u\n", lenResult, dwBufSize);
126  if (result)
127  {
128  winetest_ok(lstrlenW(buffer) * sizeof(WCHAR) + sizeof(WCHAR) == lenResult, "Expected lstrlenW(buffer)*2+2 to be %u, was %u\n",
129  lenResult, lstrlenW(buffer) * sizeof(WCHAR) + sizeof(WCHAR));
130  }
131  WideCharToMultiByte(CP_ACP, 0, buffer, -1, resultBuffer, sizeof(resultBuffer), NULL, NULL);
132  winetest_ok(!strcmp(stringResult, resultBuffer), "Expected the result to be '%s', was '%s'\n", stringResult, resultBuffer);
133 
134  if (result)
135  {
136  UNICODE_STRING pathNT;
137 
138  if (RtlDosPathNameToNtPathName_U(pathW, &pathNT, NULL, NULL))
139  {
140  memset(buffer, 0, sizeof(buffer));
141  dwBufSize = sizeof(buffer);
142  winetest_ok(pSdbGetPermLayerKeys(pathNT.Buffer, buffer, &dwBufSize, type) == FALSE, "Expected pSdbGetPermLayerKeys to fail for NT path\n");
143 
144  RtlFreeUnicodeString(&pathNT);
145  }
146  }
147 
148 }
#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:407
smooth NULL
Definition: ftsmooth.c:416
#define GPLK_USER
Definition: layerapi.c:25
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:27
#define WINVER_VISTA
Definition: services.c:325
#define MultiByteToWideChar
Definition: compat.h:100
#define GPLK_MACHINE
Definition: layerapi.c:26
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 596 of file layerapi.c.

597 {
598  UINT uRet = pGetDriveTypeW(target);
599  if(g_FakeDrive && target && (char)*target == g_FakeDrive)
600  return DRIVE_CDROM;
601  return uRet;
602 }
static char g_FakeDrive
Definition: layerapi.c:593
#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 40 of file layerapi.c.

41 {
42  if (g_QueryFlag == 0xffffffff)
43  {
44  ULONG_PTR wow64_ptr = 0;
46  g_QueryFlag = (NT_SUCCESS(status) && wow64_ptr != 0) ? KEY_WOW64_64KEY : 0;
47  }
48  return g_QueryFlag;
49 }
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:39
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 52 of file layerapi.c.

53 {
54  HKEY key = NULL;
56  "Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers", 0, NULL, 0, QueryFlag() | KEY_SET_VALUE, NULL, &key, NULL);
57  if (lstatus == ERROR_SUCCESS)
58  {
59  if (value)
60  lstatus = RegSetValueExA(key, valueName, 0, REG_SZ, (const BYTE*)value, (DWORD)strlen(value)+1);
61  else
62  {
63  lstatus = RegDeleteValueA(key, valueName);
64  lstatus = (lstatus == ERROR_FILE_NOT_FOUND ? ERROR_SUCCESS : lstatus);
65  }
67  }
68  return lstatus == ERROR_SUCCESS;
69 }
#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:2331
static DWORD QueryFlag(void)
Definition: layerapi.c:40
LONG WINAPI RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE *lpData, DWORD cbData)
Definition: reg.c:4831
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:1032
static PCWSTR BOOL bMachine
Definition: layerapi.c:33
Definition: path.c:42
#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 809 of file layerapi.c.

810 {
812  /*SetEnvironmentVariable("SHIM_DEBUG_LEVEL", "4");*/
813  hdll = LoadLibraryA("apphelp.dll");
814  pAllowPermLayer = (void *)GetProcAddress(hdll, "AllowPermLayer");
815  pSdbSetPermLayerKeys = (void *)GetProcAddress(hdll, "SdbSetPermLayerKeys");
816  pSdbGetPermLayerKeys = (void *)GetProcAddress(hdll, "SdbGetPermLayerKeys");
817  pSetPermLayerState = (void *)GetProcAddress(hdll, "SetPermLayerState");
819 
820  if (!pAllowPermLayer)
821  {
822  skip("Skipping tests with AllowPermLayer, function not found\n");
823  }
824  else
825  {
827  }
828 
829  if (!pSdbSetPermLayerKeys)
830  {
831  skip("Skipping tests with SdbSetPermLayerKeys, function not found\n");
832  }
833  else
834  {
835  if (!pSdbGetPermLayerKeys)
836  {
837  skip("Skipping tests with SdbGetPermLayerKeys, function not found\n");
838  }
839  else
840  {
842  }
843 
844  if (!pSetPermLayerState)
845  {
846  skip("Skipping tests with SetPermLayerState, function not found\n");
847  }
848  else
849  {
851  test_Sign_Media();
852  }
853  }
854 }
static void test_SetPermLayer(void)
Definition: layerapi.c:528
DWORD get_host_winver(void)
Definition: data.c:788
static void test_AllowPermLayer(void)
Definition: layerapi.c:169
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
static DWORD g_WinVersion
static void test_Sign_Media(void)
Definition: layerapi.c:647
void silence_debug_output(void)
Definition: data.c:833
static void test_SdbGetPermLayerKeys(void)
Definition: layerapi.c:237
static HMODULE hdll
Definition: layerapi.c:31
#define skip(...)
#define GetProcAddress(x, y)
Definition: compat.h:410

◆ test_AllowPermLayer()

static void test_AllowPermLayer ( void  )
static

Definition at line 169 of file layerapi.c.

170 {
171  char buf[20];
172  char drive_letter;
173  UINT drivetype = 0;
174  ok(pAllowPermLayer(NULL) == FALSE, "Expected AllowPermLayer to fail for NULL\n");
176  {
177  ok(wrapAllowPermLayer("-:"), "Expected AllowPermLayer to succeed\n");
178  ok(wrapAllowPermLayer("@:"), "Expected AllowPermLayer to succeed\n");
179  ok(wrapAllowPermLayer("4:"), "Expected AllowPermLayer to succeed\n");
180  ok(wrapAllowPermLayer("*:"), "Expected AllowPermLayer to succeed\n");
181  }
182  ok(wrapAllowPermLayer("*a") == FALSE, "Expected AllowPermLayer to fail\n");
183  ok(wrapAllowPermLayer("*\\") == FALSE, "Expected AllowPermLayer to fail\n");
184  for (drive_letter = 'a'; drive_letter <= 'z'; ++drive_letter)
185  {
186  sprintf(buf, "%c:\\", drive_letter);
187  drivetype = GetDriveTypeA(buf);
188  ok(wrapAllowPermLayer(buf) == (drivetype != DRIVE_REMOTE), "Expected AllowPermLayer to be %d for %c:\\\n", (drivetype != DRIVE_REMOTE), drive_letter);
189  }
190 }
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
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
static DWORD g_WinVersion
BOOL wrapAllowPermLayer(const char *str)
Definition: layerapi.c:157
#define WINVER_WIN8
unsigned int UINT
Definition: ndis.h:50

Referenced by START_TEST().

◆ test_SdbGetPermLayerKeys()

static void test_SdbGetPermLayerKeys ( void  )
static

Definition at line 237 of file layerapi.c.

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

Referenced by START_TEST().

◆ test_SdbSetPermLayerKeysLevel()

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

Definition at line 199 of file layerapi.c.

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

Referenced by test_SetPermLayer().

◆ test_SetPermLayer()

static void test_SetPermLayer ( void  )
static

Definition at line 528 of file layerapi.c.

529 {
530  char file[MAX_PATH + 20], tmp[MAX_PATH + 20];
531  HANDLE hfile;
532 
533  GetTempPathA(MAX_PATH, tmp);
534  GetLongPathNameA(tmp, file, sizeof(file));
535  PathAppendA(file, "test_file.exe");
536 
538  ok(hfile != INVALID_HANDLE_VALUE, "CreateFile failed for '%s'\n", file);
539  if (hfile == INVALID_HANDLE_VALUE)
540  {
541  skip("Running these tests is useless without a file present\n");
542  return;
543  }
544  CloseHandle(hfile);
545 
546  if (setLayerValue(FALSE, file, NULL))
547  {
550  }
551  else
552  {
553  skip("Skipping SetPermLayerStateLevel tests for User, because I cannot prepare the environment\n");
554  }
555  if (setLayerValue(TRUE, file, NULL))
556  {
559  }
560  else
561  {
562  skip("Skipping SetPermLayerStateLevel tests for Machine (HKLM), because I cannot prepare the environment\n");
563  }
564  ok(DeleteFileA(file), "DeleteFile failed....\n");
565 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
BOOL WINAPI PathAppendA(LPSTR lpszPath, LPCSTR lpszAppend)
Definition: path.c:101
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLongPathNameA(IN LPCSTR lpszShortPath, OUT LPSTR lpszLongPath, IN DWORD cchBuffer)
Definition: path.c:1670
#define GENERIC_WRITE
Definition: nt_native.h:90
#define ok(value,...)
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:337
#define CREATE_ALWAYS
Definition: disk.h:72
static void test_SdbSetPermLayerKeysLevel(BOOL bMachine, const char *file)
Definition: layerapi.c:199
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
#define skip(...)
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
static BOOL setLayerValue(BOOL bMachine, const char *valueName, const char *value)
Definition: layerapi.c:52
Definition: fci.c:126

Referenced by START_TEST().

◆ test_SetPermLayerStateLevel()

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

Definition at line 337 of file layerapi.c.

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

Referenced by test_SetPermLayer().

◆ test_Sign_Media()

static void test_Sign_Media ( void  )
static

Definition at line 647 of file layerapi.c.

648 {
649  char workdir[MAX_PATH], subdir[MAX_PATH], drive[5] = "Z:";
650  BOOL ret;
651 
652  DWORD logical_drives = GetLogicalDrives();
653  g_FakeDrive = 0;
654  for (drive[0] = 'D'; drive[0] <= 'Z'; drive[0]++)
655  {
656  DWORD idx = 1 << (drive[0] - 'D' + 3);
657  if (!(logical_drives & idx))
658  {
659  g_FakeDrive = drive[0];
660  break;
661  }
662  }
663  if (!g_FakeDrive)
664  {
665  skip("Unable to find a free drive\n");
666  return;
667  }
668 
670  ok(ret, "GetTempPathA error: %d\n", GetLastError());
671  PathAppendA(workdir, "apphelp_test");
672 
674  ok(ret, "CreateDirectoryA error: %d\n", GetLastError());
675 
676  PathCombineA(subdir, workdir, "sub");
677  ret = CreateDirectoryA(subdir, NULL);
678  ok(ret, "CreateDirectoryA error: %d\n", GetLastError());
679 
681  ok(ret, "DefineDosDeviceA error: %d\n", GetLastError());
682  if(ret)
683  {
684  ret = RedirectIat(GetModuleHandleA("apphelp.dll"), "kernel32.dll", "GetDriveTypeW",
685  (ULONG_PTR)mGetDriveTypeW, (ULONG_PTR*)&pGetDriveTypeW);
687  ok(ret, "Expected redirect_iat to succeed\n");
688  if(ret)
689  {
690  ok(create_file(workdir, "test.exe", 'a', 4), "create_file error: %d\n", GetLastError());
691 
692  ok(wrapSdbSetPermLayerKeys2(drive, "test.exe", "TEST", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
693  /* 4 */
694  /* test.exe */
695  expect_LayerValue(0, "SIGN.MEDIA=4 test.exe", "TEST");
696  ok(wrapSdbSetPermLayerKeys2(drive, "test.exe", "", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
697 
698  ok(create_file(workdir, "test.txt", 'a', 1), "create_file error: %d\n", GetLastError());
699 
700  if (!expect_files(workdir, 2, "test.exe", "test.txt"))
701  {
702  skip("Skipping test, files are not returned in the expected order by the FS\n");
703  }
704  else
705  {
706  ok(wrapSdbSetPermLayerKeys2(drive, "test.exe", "TEST", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
707  /* (4 << 1) ^ 1 */
708  /* test.exe test.txt */
709  expect_LayerValue(0, "SIGN.MEDIA=9 test.exe", "TEST");
710  ok(wrapSdbSetPermLayerKeys2(drive, "test.exe", "", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
711  }
712 
713  ok(create_file(workdir, "test.zz", 'a', 0x1000), "create_file error: %d\n", GetLastError());
714 
715  if (!expect_files(workdir, 3, "test.exe", "test.txt", "test.zz"))
716  {
717  skip("Skipping test, files are not returned in the expected order by the FS\n");
718  }
719  else
720  {
721  ok(wrapSdbSetPermLayerKeys2(drive, "test.exe", "TEST", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
722  /* (((4 << 1) ^ 1) << 1) ^ 0x1000 */
723  /* test.exe test.txt test.zz */
724  expect_LayerValue(0, "SIGN.MEDIA=1012 test.exe", "TEST");
725  ok(wrapSdbSetPermLayerKeys2(drive, "test.exe", "", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
726  }
727 
728  ok(create_file(subdir, "test.exe", 'a', 0x10203), "create_file error: %d\n", GetLastError());
729 
730  if (!expect_files(subdir, 1, "test.exe"))
731  {
732  skip("Skipping test, files are not returned in the expected order by the FS\n");
733  }
734  else
735  {
736  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "TEST", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
737  /* 0x10203 */
738  /* test.exe */
739  expect_LayerValue(0, "SIGN.MEDIA=10203 sub\\test.exe", "TEST");
740  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
741  }
742 
743  ok(create_file(subdir, "test.bbb", 'a', 0), "create_file error: %d\n", GetLastError());
744 
745  if (!expect_files(subdir, 2, "test.bbb", "test.exe"))
746  {
747  skip("Skipping test, files are not returned in the expected order by the FS\n");
748  }
749  else
750  {
751  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "TEST", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
752  /* 0x10203 */
753  /* test.exe */
754  expect_LayerValue(0, "SIGN.MEDIA=10203 sub\\test.exe", "TEST");
755  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
756  }
757 
758  ok(create_file(subdir, "TEST.txt", 'a', 0x30201), "create_file error: %d\n", GetLastError());
759 
760  if (!expect_files(subdir, 3, "test.bbb", "test.exe", "TEST.txt"))
761  {
762  skip("Skipping test, files are not returned in the expected order by the FS\n");
763  }
764  else
765  {
766  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "TEST", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
767  /* (0x10203 << 1) ^ 0x30201 */
768  /* test.exe TEST.txt */
769  expect_LayerValue(0, "SIGN.MEDIA=10607 sub\\test.exe", "TEST");
770  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
771  }
772 
773  ok(create_file(subdir, "TEST.aaa", 'a', 0x3a2a1), "create_file error: %d\n", GetLastError());
774 
775  if (!expect_files(subdir, 4, "TEST.aaa", "test.bbb", "test.exe", "TEST.txt"))
776  {
777  skip("Skipping test, files are not returned in the expected order by the FS\n");
778  }
779  else
780  {
781  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "TEST", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
782  /* (((0x3a2a1 << 1) ^ 0x10203) << 1) ^ 0x30201 */
783  /* TEST.aaa test.exe TEST.txt */
784  expect_LayerValue(0, "SIGN.MEDIA=F8C83 sub\\test.exe", "TEST");
785  ok(wrapSdbSetPermLayerKeys2(drive, "sub\\test.exe", "", 0), "Expected wrapSdbSetPermLayerKeys2 to succeed\n");
786  }
787 
788  ret = RestoreIat(GetModuleHandleA("apphelp.dll"), "kernel32.dll", "GetDriveTypeW", (ULONG_PTR)pGetDriveTypeW);
789  ok(ret, "Expected restore_iat to succeed\n");
790 
791  ok(delete_file(subdir, "test.bbb"), "delete_file error: %d\n", GetLastError());
792  ok(delete_file(subdir, "TEST.aaa"), "delete_file error: %d\n", GetLastError());
793  ok(delete_file(subdir, "TEST.txt"), "delete_file error: %d\n", GetLastError());
794  ok(delete_file(subdir, "test.exe"), "delete_file error: %d\n", GetLastError());
795  ok(delete_file(workdir, "test.zz"), "delete_file error: %d\n", GetLastError());
796  ok(delete_file(workdir, "test.txt"), "delete_file error: %d\n", GetLastError());
797  ok(delete_file(workdir, "test.exe"), "delete_file error: %d\n", GetLastError());
798  }
800  ok(ret, "DefineDosDeviceA error: %d\n", GetLastError());
801  }
802  ret = RemoveDirectoryA(subdir);
803  ok(ret, "RemoveDirectoryA error: %d\n", GetLastError());
805  ok(ret, "RemoveDirectoryA error: %d\n", GetLastError());
806 }
BOOL expect_files(const char *dir, int num,...)
Definition: layerapi.c:615
static BOOL wrapSdbSetPermLayerKeys2(LPCSTR dir, LPCSTR name, PCSTR szLayers, BOOL bMachine)
Definition: layerapi.c:604
#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:153
uint32_t ULONG_PTR
Definition: typedefs.h:63
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
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:567
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:593
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
#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:27
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
BOOL WINAPI RemoveDirectoryA(IN LPCSTR lpPathName)
Definition: dir.c:714
static BOOL delete_file(LPCSTR dir, LPCSTR name)
Definition: layerapi.c:586
#define skip(...)
UINT WINAPI mGetDriveTypeW(LPCWSTR target)
Definition: layerapi.c:596

Referenced by START_TEST().

◆ UINT()

UINT ( WINAPI pGetDriveTypeW)

◆ wrapAllowPermLayer()

BOOL wrapAllowPermLayer ( const char str)

Definition at line 157 of file layerapi.c.

158 {
159  WCHAR buf[100];
160  MultiByteToWideChar(CP_ACP, 0, str, -1, buf, 100);
161  return pAllowPermLayer(buf);
162 }
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 192 of file layerapi.c.

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

Referenced by test_SdbSetPermLayerKeysLevel().

◆ wrapSdbSetPermLayerKeys2()

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

Definition at line 604 of file layerapi.c.

605 {
606  char szPath[MAX_PATH];
610  MultiByteToWideChar(CP_ACP, 0, szPath, -1, wszPath, MAX_PATH);
611  return pSdbSetPermLayerKeys(wszPath, wszLayers, bMachine);
612 }
#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:27
LPCWSTR szPath
Definition: env.c:35
#define MultiByteToWideChar
Definition: compat.h:100
Definition: name.c:36
static PCWSTR wszLayers
Definition: layerapi.c:33
static PCWSTR BOOL bMachine
Definition: layerapi.c:33

Referenced by test_Sign_Media().

◆ wrapSetPermLayerState()

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

Definition at line 330 of file layerapi.c.

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

Referenced by test_SetPermLayerStateLevel().

Variable Documentation

◆ bEnable

Definition at line 35 of file layerapi.c.

◆ bMachine

◆ dwFlags

Definition at line 34 of file layerapi.c.

◆ g_FakeDrive

char g_FakeDrive = 0
static

Definition at line 593 of file layerapi.c.

Referenced by mGetDriveTypeW(), and test_Sign_Media().

◆ g_QueryFlag

DWORD g_QueryFlag = 0xffffffff
static

Definition at line 39 of file layerapi.c.

Referenced by QueryFlag().

◆ hdll

HMODULE hdll
static

Definition at line 31 of file layerapi.c.

Referenced by START_TEST().

◆ pdwBytes

◆ pwszLayers

PWSTR pwszLayers

Definition at line 34 of file layerapi.c.

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

◆ wszLayer

PCWSTR wszLayer

Definition at line 35 of file layerapi.c.

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

◆ wszLayers