ReactOS  0.4.14-dev-1331-g167fa2c
NtApphelpCacheControl.c File Reference
#include "precomp.h"
#include <winsvc.h>
#include <versionhelpers.h>
Include dependency graph for NtApphelpCacheControl.c:

Go to the source code of this file.

Enumerations

enum  ServiceCommands { RegisterShimCacheWithHandle = 128, RegisterShimCacheWithoutHandle = 129 }
 

Functions

static NTSTATUS (NTAPI *pNtApphelpCacheControl)(APPHELPCACHESERVICECLASS
 
NTSTATUS CallCacheControl (UNICODE_STRING *PathName, BOOLEAN WithMapping, APPHELPCACHESERVICECLASS Service)
 
int InitEnv (UNICODE_STRING *PathName)
 
void CheckValidation (UNICODE_STRING *PathName)
 
static BOOLEAN RequestAddition (SC_HANDLE service_handle, BOOLEAN WithMapping)
 
static void RunApphelpCacheControlTests (SC_HANDLE service_handle)
 
static SERVICE_STATUS_HANDLE (WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
 
static BOOLEAN RegisterInShimCache (BOOLEAN WithMapping)
 
static DWORD WINAPI service_handler (DWORD ctrl, DWORD event_type, void *event_data, void *context)
 
static void WINAPI service_main (DWORD argc, char **argv)
 
static SC_HANDLE InstallService (SC_HANDLE scm_handle)
 
static void WaitService (SC_HANDLE service_handle, DWORD Status, SERVICE_STATUS_PROCESS *ssp)
 
static void RunTest ()
 
 START_TEST (NtApphelpCacheControl)
 

Variables

static PAPPHELP_CACHE_SERVICE_LOOKUP
 
static LPHANDLER_FUNCTION_EX
 
static LPVOID
 
static char service_name [100] = "apphelp_test_service"
 
static HANDLE service_stop_event
 
static SERVICE_STATUS_HANDLE service_status
 

Enumeration Type Documentation

◆ ServiceCommands

Enumerator
RegisterShimCacheWithHandle 
RegisterShimCacheWithoutHandle 

Definition at line 13 of file NtApphelpCacheControl.c.

Function Documentation

◆ CallCacheControl()

NTSTATUS CallCacheControl ( UNICODE_STRING PathName,
BOOLEAN  WithMapping,
APPHELPCACHESERVICECLASS  Service 
)

Definition at line 21 of file NtApphelpCacheControl.c.

22 {
23  APPHELP_CACHE_SERVICE_LOOKUP CacheEntry = { {0} };
25  CacheEntry.ImageName = *PathName;
26  if (WithMapping)
27  {
28  OBJECT_ATTRIBUTES LocalObjectAttributes;
30  InitializeObjectAttributes(&LocalObjectAttributes, PathName,
32  Status = NtOpenFile(&CacheEntry.ImageHandle,
34  &LocalObjectAttributes, &IoStatusBlock,
38  }
39  else
40  {
41  CacheEntry.ImageHandle = INVALID_HANDLE_VALUE;
42  }
43  Status = pNtApphelpCacheControl(Service, &CacheEntry);
44  if (CacheEntry.ImageHandle != INVALID_HANDLE_VALUE)
45  NtClose(CacheEntry.ImageHandle);
46  return Status;
47 }
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
#define FILE_SHARE_READ
Definition: compat.h:125
#define FILE_READ_DATA
Definition: nt_native.h:628
smooth NULL
Definition: ftsmooth.c:416
UNICODE_STRING ImageName
Definition: pstypes.h:934
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define FILE_EXECUTE
Definition: nt_native.h:642
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define SYNCHRONIZE
Definition: nt_native.h:61
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by InitEnv(), RegisterInShimCache(), and RunApphelpCacheControlTests().

◆ CheckValidation()

void CheckValidation ( UNICODE_STRING PathName)

Definition at line 63 of file NtApphelpCacheControl.c.

64 {
65  APPHELP_CACHE_SERVICE_LOOKUP CacheEntry = { {0} };
67 
68  /* Validate the handling of a NULL pointer */
69  Status = pNtApphelpCacheControl(ApphelpCacheServiceRemove, NULL);
71  Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, NULL);
73 
74  /* Validate the handling of a NULL pointer inside the struct */
75  Status = pNtApphelpCacheControl(ApphelpCacheServiceRemove, &CacheEntry);
77  Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
79 
80  /* Just call the dump function */
81  Status = pNtApphelpCacheControl(ApphelpCacheServiceDump, NULL);
83 
84  /* Validate the handling of an invalid handle inside the struct */
85  CacheEntry.ImageName = *PathName;
86  CacheEntry.ImageHandle = (HANDLE)2;
87  Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
89 
90  /* Validate the handling of an invalid service number */
91  Status = pNtApphelpCacheControl(999, NULL);
93  Status = pNtApphelpCacheControl(999, &CacheEntry);
95 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
UNICODE_STRING ImageName
Definition: pstypes.h:934
#define STATUS_NOT_FOUND
Definition: shellext.h:72
PVOID HANDLE
Definition: typedefs.h:72
Status
Definition: gdiplustypes.h:24
VERSIONHELPERAPI IsWindows7OrGreater()
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by RunApphelpCacheControlTests().

◆ InitEnv()

int InitEnv ( UNICODE_STRING PathName)

Definition at line 49 of file NtApphelpCacheControl.c.

50 {
53  {
54  /* Windows Vista+ has a different layout for APPHELP_CACHE_SERVICE_LOOKUP */
55  return 0;
56  }
58  "Wrong value for Status, expected: SUCCESS or NOT_FOUND, got: 0x%lx\n",
59  Status);
60  return 1;
61 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS CallCacheControl(UNICODE_STRING *PathName, BOOLEAN WithMapping, APPHELPCACHESERVICECLASS Service)
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_NOT_FOUND
Definition: shellext.h:72
Status
Definition: gdiplustypes.h:24
#define ok(value,...)
Definition: atltest.h:57
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by RunApphelpCacheControlTests().

◆ InstallService()

static SC_HANDLE InstallService ( SC_HANDLE  scm_handle)
static

Definition at line 275 of file NtApphelpCacheControl.c.

276 {
277  char service_cmd[MAX_PATH+150], *ptr;
278  SC_HANDLE service;
279 
280  ptr = service_cmd + GetModuleFileNameA(NULL, service_cmd, MAX_PATH);
281  strcpy(ptr, " NtApphelpCacheControl service");
282  ptr += strlen(ptr);
283 
286  service_cmd, NULL, NULL, NULL, NULL, NULL);
287  if (!service)
288  {
289  skip("Could not create helper service\n");
290  return NULL;
291  }
292  return service;
293 }
#define SERVICE_ERROR_IGNORE
Definition: cmtypes.h:979
#define GENERIC_ALL
Definition: nt_native.h:92
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static SC_HANDLE scm_handle
Definition: ServiceArgs.c:20
SC_HANDLE WINAPI CreateServiceA(SC_HANDLE hSCManager, LPCSTR lpServiceName, LPCSTR lpDisplayName, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCSTR lpBinaryPathName, LPCSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCSTR lpDependencies, LPCSTR lpServiceStartName, LPCSTR lpPassword)
Definition: scm.c:677
DWORD WINAPI GetModuleFileNameA(HINSTANCE hModule, LPSTR lpFilename, DWORD nSize)
Definition: loader.c:539
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:960
#define MAX_PATH
Definition: compat.h:26
static char service_name[100]
#define skip(...)
Definition: atltest.h:64
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define SERVICE_DEMAND_START
Definition: cmtypes.h:976

Referenced by RunTest().

◆ NTSTATUS()

static NTSTATUS ( NTAPI pNtApphelpCacheControl)
static

◆ RegisterInShimCache()

static BOOLEAN RegisterInShimCache ( BOOLEAN  WithMapping)
static

Definition at line 194 of file NtApphelpCacheControl.c.

195 {
197  UNICODE_STRING ntPath;
198  BOOLEAN Result;
200  GetModuleFileNameW(NULL, szPath, sizeof(szPath) / sizeof(szPath[0]));
202  if (!Result)
203  {
204  DbgPrint("RegisterInShimCache: RtlDosPathNameToNtPathName_U failed\n");
205  return FALSE;
206  }
207 
208  Status = CallCacheControl(&ntPath, WithMapping, ApphelpCacheServiceUpdate);
209  if (!NT_SUCCESS(Status))
210  {
211  DbgPrint("RegisterInShimCache: CallCacheControl failed\n");
212  RtlFreeHeap(RtlGetProcessHeap(), 0, ntPath.Buffer);
213  return FALSE;
214  }
215  RtlFreeHeap(RtlGetProcessHeap(), 0, ntPath.Buffer);
216  return TRUE;
217 }
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
#define TRUE
Definition: types.h:120
#define DbgPrint
Definition: loader.c:25
NTSTATUS CallCacheControl(UNICODE_STRING *PathName, BOOLEAN WithMapping, APPHELPCACHESERVICECLASS Service)
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_PATH
Definition: compat.h:26
Status
Definition: gdiplustypes.h:24
LPCWSTR szPath
Definition: env.c:35
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)

Referenced by service_handler().

◆ RequestAddition()

static BOOLEAN RequestAddition ( SC_HANDLE  service_handle,
BOOLEAN  WithMapping 
)
static

Definition at line 97 of file NtApphelpCacheControl.c.

98 {
102  /* TODO: how to get a return code from the service? */
103  return TRUE;
104 }
#define TRUE
Definition: types.h:120
static SERVICE_STATUS_HANDLE service_handle
Definition: rpcss_main.c:38
Status
Definition: gdiplustypes.h:24
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:619

Referenced by RunApphelpCacheControlTests().

◆ RunApphelpCacheControlTests()

static void RunApphelpCacheControlTests ( SC_HANDLE  service_handle)
static

Definition at line 106 of file NtApphelpCacheControl.c.

107 {
109  UNICODE_STRING ntPath;
110  BOOLEAN Result;
112  APPHELP_CACHE_SERVICE_LOOKUP CacheEntry;
113 
114  GetModuleFileNameW(NULL, szPath, sizeof(szPath) / sizeof(szPath[0]));
116  ok(Result == TRUE, "RtlDosPathNameToNtPathName_U\n");
117  if (!InitEnv(&ntPath))
118  {
119  skip("NtApphelpCacheControl expects a different structure layout\n");
120  return;
121  }
122  /* At this point we have made sure that our binary is not present in the cache,
123  and that the NtApphelpCacheControl function expects the struct layout we use. */
124  CheckValidation(&ntPath);
125 
126  /* We expect not to find it */
131 
132  /* First we add our process without a file handle (so it will be registered without file info) */
134 
135  /* now we try to find it without validating file info */
138  /* when validating file info the cache notices the file is wrong, so it is dropped from the cache */
141  /* making the second check without info also fail. */
144 
145 
146  /* Now we add the file with file info */
148 
149  /* so both checks should succeed */
154 
155  /* We know the file is in the cache now (assuming previous tests succeeded,
156  let's test invalid handle behavior */
157  CacheEntry.ImageName = ntPath;
158  CacheEntry.ImageHandle = 0;
159  Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
161 
162  /* re-add it for the next test */
166  CacheEntry.ImageHandle = (HANDLE)1;
167  Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
169 
170  /* and again */
174 #ifdef _WIN64
175  CacheEntry.ImageHandle = (HANDLE)0x8000000000000000ULL;
176 #else
177  CacheEntry.ImageHandle = (HANDLE)0x80000000;
178 #endif
179  Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
181 
182  RtlFreeHeap(RtlGetProcessHeap(), 0, ntPath.Buffer);
183 }
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
int InitEnv(UNICODE_STRING *PathName)
NTSTATUS CallCacheControl(UNICODE_STRING *PathName, BOOLEAN WithMapping, APPHELPCACHESERVICECLASS Service)
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
static SERVICE_STATUS_HANDLE service_handle
Definition: rpcss_main.c:38
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
UNICODE_STRING ImageName
Definition: pstypes.h:934
#define STATUS_NOT_FOUND
Definition: shellext.h:72
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
PVOID HANDLE
Definition: typedefs.h:72
Status
Definition: gdiplustypes.h:24
LPCWSTR szPath
Definition: env.c:35
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
VERSIONHELPERAPI IsWindows7OrGreater()
static BOOLEAN RequestAddition(SC_HANDLE service_handle, BOOLEAN WithMapping)
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
return STATUS_SUCCESS
Definition: btrfs.c:2938
void CheckValidation(UNICODE_STRING *PathName)
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)

Referenced by RunTest().

◆ RunTest()

static void RunTest ( )
static

Definition at line 317 of file NtApphelpCacheControl.c.

318 {
321  if (service_handle)
322  {
323  SERVICE_STATUS_PROCESS ssp = {0};
325  if (res)
326  {
331  }
332  else
333  {
334  skip("Could not start helper service\n");
335  }
337  }
339 }
static SC_HANDLE scm_handle
Definition: ServiceArgs.c:20
static SERVICE_STATUS_HANDLE service_handle
Definition: rpcss_main.c:38
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:916
#define SERVICE_STOPPED
Definition: winsvc.h:21
SC_HANDLE WINAPI OpenSCManagerA(LPCSTR lpMachineName, LPCSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:1967
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SERVICE_RUNNING
Definition: winsvc.h:24
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI StartServiceA(SC_HANDLE hService, DWORD dwNumServiceArgs, LPCSTR *lpServiceArgVectors)
Definition: scm.c:2885
static void WaitService(SC_HANDLE service_handle, DWORD Status, SERVICE_STATUS_PROCESS *ssp)
static void RunApphelpCacheControlTests(SC_HANDLE service_handle)
static SC_HANDLE InstallService(SC_HANDLE scm_handle)
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:619
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
#define skip(...)
Definition: atltest.h:64
GLuint res
Definition: glext.h:9613
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36

Referenced by START_TEST().

◆ service_handler()

static DWORD WINAPI service_handler ( DWORD  ctrl,
DWORD  event_type,
void event_data,
void context 
)
static

Definition at line 220 of file NtApphelpCacheControl.c.

221 {
222  SERVICE_STATUS status = {0};
223  status.dwServiceType = SERVICE_WIN32;
224  status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
225 
226  switch(ctrl)
227  {
230  status.dwCurrentState = SERVICE_STOP_PENDING;
231  status.dwControlsAccepted = 0;
234  return NO_ERROR;
237  {
238  /* TODO: how should we communicate a failure? */
239  }
240  break;
243  {
244  /* TODO: how should we communicate a failure? */
245  }
246  break;
247  default:
248  DbgPrint("Unhandled: %d\n", ctrl);
249  break;
250  }
251  status.dwCurrentState = SERVICE_RUNNING;
253  return NO_ERROR;
254 }
#define TRUE
Definition: types.h:120
#define DbgPrint
Definition: loader.c:25
static SERVICE_STATUS_HANDLE service_status
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
static HANDLE service_stop_event
#define NO_ERROR
Definition: dderror.h:5
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:995
static BOOLEAN RegisterInShimCache(BOOLEAN WithMapping)
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define ctrl
Definition: input.c:1757
#define SERVICE_WIN32
Definition: cmtypes.h:962
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40
Definition: ps.c:97

Referenced by service_main().

◆ service_main()

static void WINAPI service_main ( DWORD  argc,
char **  argv 
)
static

Definition at line 256 of file NtApphelpCacheControl.c.

257 {
258  SERVICE_STATUS status = {0};
259  service_status = pRegisterServiceCtrlHandlerExA(service_name, service_handler, NULL);
260  if(!service_status)
261  return;
262 
263  status.dwServiceType = SERVICE_WIN32;
264  status.dwCurrentState = SERVICE_RUNNING;
265  status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
267 
269 
270  status.dwCurrentState = SERVICE_STOPPED;
271  status.dwControlsAccepted = 0;
273 }
static DWORD WINAPI service_handler(DWORD ctrl, DWORD event_type, void *event_data, void *context)
static SERVICE_STATUS_HANDLE service_status
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
static HANDLE service_stop_event
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:995
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_RUNNING
Definition: winsvc.h:24
smooth NULL
Definition: ftsmooth.c:416
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
static char service_name[100]
#define SERVICE_WIN32
Definition: cmtypes.h:962
#define INFINITE
Definition: serial.h:102
Definition: ps.c:97

Referenced by START_TEST().

◆ SERVICE_STATUS_HANDLE()

◆ START_TEST()

START_TEST ( NtApphelpCacheControl  )

Definition at line 341 of file NtApphelpCacheControl.c.

342 {
343  char **argv;
344  int argc;
345 
346  pRegisterServiceCtrlHandlerExA = (void*)GetProcAddress(GetModuleHandleA("advapi32.dll"), "RegisterServiceCtrlHandlerExA");
347  if (!pRegisterServiceCtrlHandlerExA)
348  {
349  win_skip("RegisterServiceCtrlHandlerExA not available, skipping tests\n");
350  return;
351  }
352 
353  pNtApphelpCacheControl = (void*)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtApphelpCacheControl");
354  if (!pNtApphelpCacheControl)
355  {
356  win_skip("NtApphelpCacheControl not available, skipping tests\n");
357  return;
358  }
359 
361  if(argc < 3)
362  {
363  RunTest();
364  }
365  else
366  {
367  SERVICE_TABLE_ENTRYA servtbl[] = {
369  {NULL, NULL}
370  };
373  Sleep(50);
375  }
376 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
static HANDLE service_stop_event
#define argv
Definition: mplay32.c:18
BOOL WINAPI StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA *lpServiceStartTable)
Definition: sctrl.c:1033
static void WINAPI service_main(DWORD argc, char **argv)
smooth NULL
Definition: ftsmooth.c:416
static void RunTest()
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:637
static char service_name[100]
int winetest_get_mainargs(char ***pargv)
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
#define GetProcAddress(x, y)
Definition: compat.h:418
#define win_skip
Definition: test.h:149

◆ WaitService()

static void WaitService ( SC_HANDLE  service_handle,
DWORD  Status,
SERVICE_STATUS_PROCESS ssp 
)
static

Definition at line 295 of file NtApphelpCacheControl.c.

296 {
297  DWORD dwBytesNeeded;
298  DWORD dwStartTime = GetTickCount();
299  while (ssp->dwCurrentState != Status)
300  {
301  Sleep(40);
303  (LPBYTE)ssp, sizeof(SERVICE_STATUS_PROCESS), &dwBytesNeeded ))
304  {
305  ok(0, "QueryServiceStatusEx failed waiting for %lu\n", Status);
306  break;
307  }
308  if ((GetTickCount() - dwStartTime) > 1000)
309  {
310  ok(0, "Timeout waiting for (%lu) from service, is: %lu.\n",
311  Status, ssp->dwCurrentState);
312  break;
313  }
314  }
315 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
static SERVICE_STATUS_HANDLE service_handle
Definition: rpcss_main.c:38
BOOL WINAPI QueryServiceStatusEx(SC_HANDLE hService, SC_STATUS_TYPE InfoLevel, LPBYTE lpBuffer, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
Definition: scm.c:2830
unsigned char * LPBYTE
Definition: typedefs.h:53
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:24
#define ok(value,...)
Definition: atltest.h:57

Referenced by RunTest().

Variable Documentation

◆ LPHANDLER_FUNCTION_EX

LPHANDLER_FUNCTION_EX

Definition at line 189 of file NtApphelpCacheControl.c.

◆ LPVOID

Definition at line 189 of file NtApphelpCacheControl.c.

◆ PAPPHELP_CACHE_SERVICE_LOOKUP

◆ service_name

char service_name[100] = "apphelp_test_service"
static

◆ service_status

SERVICE_STATUS_HANDLE service_status
static

Definition at line 192 of file NtApphelpCacheControl.c.

Referenced by service_handler(), and service_main().

◆ service_stop_event

HANDLE service_stop_event
static

Definition at line 191 of file NtApphelpCacheControl.c.

Referenced by service_handler(), service_main(), and START_TEST().