ReactOS  0.4.12-dev-409-g9f418243
NtApphelpCacheControl.c File Reference
#include "precomp.h"
#include <winsvc.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 12 of file NtApphelpCacheControl.c.

Function Documentation

◆ CallCacheControl()

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

Definition at line 20 of file NtApphelpCacheControl.c.

21 {
22  APPHELP_CACHE_SERVICE_LOOKUP CacheEntry = { {0} };
24  CacheEntry.ImageName = *PathName;
25  if (WithMapping)
26  {
27  OBJECT_ATTRIBUTES LocalObjectAttributes;
29  InitializeObjectAttributes(&LocalObjectAttributes, PathName,
31  Status = NtOpenFile(&CacheEntry.ImageHandle,
33  &LocalObjectAttributes, &IoStatusBlock,
37  }
38  else
39  {
40  CacheEntry.ImageHandle = INVALID_HANDLE_VALUE;
41  }
42  Status = pNtApphelpCacheControl(Service, &CacheEntry);
43  if (CacheEntry.ImageHandle != INVALID_HANDLE_VALUE)
44  NtClose(CacheEntry.ImageHandle);
45  return Status;
46 }
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define FILE_SHARE_READ
Definition: compat.h:125
#define FILE_READ_DATA
Definition: nt_native.h:628
smooth NULL
Definition: ftsmooth.c:416
#define ok_ntstatus(status, expected)
Definition: test.h:800
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:3393
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#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 InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
return STATUS_SUCCESS
Definition: btrfs.c:2725

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

◆ CheckValidation()

void CheckValidation ( UNICODE_STRING PathName)

Definition at line 62 of file NtApphelpCacheControl.c.

63 {
64  APPHELP_CACHE_SERVICE_LOOKUP CacheEntry = { {0} };
66 
67  /* Validate the handling of a NULL pointer */
68  Status = pNtApphelpCacheControl(ApphelpCacheServiceRemove, NULL);
70  Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, NULL);
72 
73  /* Validate the handling of a NULL pointer inside the struct */
74  Status = pNtApphelpCacheControl(ApphelpCacheServiceRemove, &CacheEntry);
76  Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
78 
79  /* Just call the dump function */
80  Status = pNtApphelpCacheControl(ApphelpCacheServiceDump, NULL);
82 
83  /* Validate the handling of an invalid handle inside the struct */
84  CacheEntry.ImageName = *PathName;
85  CacheEntry.ImageHandle = (HANDLE)2;
86  Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
88 
89  /* Validate the handling of an invalid service number */
90  Status = pNtApphelpCacheControl(999, NULL);
92  Status = pNtApphelpCacheControl(999, &CacheEntry);
94 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
#define ok_ntstatus(status, expected)
Definition: test.h:800
UNICODE_STRING ImageName
Definition: pstypes.h:934
#define STATUS_NOT_FOUND
Definition: shellext.h:67
PVOID HANDLE
Definition: typedefs.h:71
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by RunApphelpCacheControlTests().

◆ InitEnv()

int InitEnv ( UNICODE_STRING PathName)

Definition at line 48 of file NtApphelpCacheControl.c.

49 {
52  {
53  /* Windows Vista+ has a different layout for APPHELP_CACHE_SERVICE_LOOKUP */
54  return 0;
55  }
57  "Wrong value for Status, expected: SUCCESS or NOT_FOUND, got: 0x%lx\n",
58  Status);
59  return 1;
60 }
#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 ok(value,...)
Definition: CComObject.cpp:34
#define STATUS_NOT_FOUND
Definition: shellext.h:67
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by RunApphelpCacheControlTests().

◆ InstallService()

static SC_HANDLE InstallService ( SC_HANDLE  scm_handle)
static

Definition at line 274 of file NtApphelpCacheControl.c.

275 {
276  char service_cmd[MAX_PATH+150], *ptr;
277  SC_HANDLE service;
278 
279  ptr = service_cmd + GetModuleFileNameA(NULL, service_cmd, MAX_PATH);
280  strcpy(ptr, " NtApphelpCacheControl service");
281  ptr += strlen(ptr);
282 
285  service_cmd, NULL, NULL, NULL, NULL, NULL);
286  if (!service)
287  {
288  skip("Could not create helper service\n");
289  return NULL;
290  }
291  return service;
292 }
#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:546
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: CString.cpp:57
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 193 of file NtApphelpCacheControl.c.

194 {
196  UNICODE_STRING ntPath;
197  BOOLEAN Result;
199  GetModuleFileNameW(NULL, szPath, sizeof(szPath) / sizeof(szPath[0]));
201  if (!Result)
202  {
203  DbgPrint("RegisterInShimCache: RtlDosPathNameToNtPathName_U failed\n");
204  return FALSE;
205  }
206 
207  Status = CallCacheControl(&ntPath, WithMapping, ApphelpCacheServiceUpdate);
208  if (!NT_SUCCESS(Status))
209  {
210  DbgPrint("RegisterInShimCache: CallCacheControl failed\n");
211  RtlFreeHeap(RtlGetProcessHeap(), 0, ntPath.Buffer);
212  return FALSE;
213  }
214  RtlFreeHeap(RtlGetProcessHeap(), 0, ntPath.Buffer);
215  return TRUE;
216 }
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:607
#define TRUE
Definition: types.h:120
#define DbgPrint
Definition: loader.c:25
__wchar_t WCHAR
Definition: xmlstorage.h:180
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:603
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
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#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 96 of file NtApphelpCacheControl.c.

97 {
101  /* TODO: how to get a return code from the service? */
102  return TRUE;
103 }
#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 105 of file NtApphelpCacheControl.c.

106 {
108  UNICODE_STRING ntPath;
109  BOOLEAN Result;
111  APPHELP_CACHE_SERVICE_LOOKUP CacheEntry;
112 
113  GetModuleFileNameW(NULL, szPath, sizeof(szPath) / sizeof(szPath[0]));
115  ok(Result == TRUE, "RtlDosPathNameToNtPathName_U\n");
116  if (!InitEnv(&ntPath))
117  {
118  skip("NtApphelpCacheControl expects a different structure layout\n");
119  return;
120  }
121  /* At this point we have made sure that our binary is not present in the cache,
122  and that the NtApphelpCacheControl function expects the struct layout we use. */
123  CheckValidation(&ntPath);
124 
125  /* We expect not to find it */
130 
131  /* First we add our process without a file handle (so it will be registered without file info) */
133 
134  /* now we try to find it without validating file info */
137  /* when validating file info the cache notices the file is wrong, so it is dropped from the cache */
140  /* making the second check without info also fail. */
143 
144 
145  /* Now we add the file with file info */
147 
148  /* so both checks should succeed */
153 
154  /* We know the file is in the cache now (assuming previous tests succeeded,
155  let's test invalid handle behavior */
156  CacheEntry.ImageName = ntPath;
157  CacheEntry.ImageHandle = 0;
158  Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
160 
161  /* re-add it for the next test */
165  CacheEntry.ImageHandle = (HANDLE)1;
166  Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
168 
169  /* and again */
173 #ifdef _WIN64
174  CacheEntry.ImageHandle = (HANDLE)0x8000000000000000ULL;
175 #else
176  CacheEntry.ImageHandle = (HANDLE)0x80000000;
177 #endif
178  Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
180 
181  RtlFreeHeap(RtlGetProcessHeap(), 0, ntPath.Buffer);
182 }
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:607
#define TRUE
Definition: types.h:120
__wchar_t WCHAR
Definition: xmlstorage.h:180
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:603
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
#define ok_ntstatus(status, expected)
Definition: test.h:800
#define ok(value,...)
Definition: CComObject.cpp:34
UNICODE_STRING ImageName
Definition: pstypes.h:934
#define STATUS_NOT_FOUND
Definition: shellext.h:67
#define MAX_PATH
Definition: compat.h:26
PVOID HANDLE
Definition: typedefs.h:71
Status
Definition: gdiplustypes.h:24
LPCWSTR szPath
Definition: env.c:35
#define skip(...)
Definition: CString.cpp:57
static BOOLEAN RequestAddition(SC_HANDLE service_handle, BOOLEAN WithMapping)
return STATUS_SUCCESS
Definition: btrfs.c:2725
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 316 of file NtApphelpCacheControl.c.

317 {
320  if (service_handle)
321  {
322  SERVICE_STATUS_PROCESS ssp = {0};
324  if (res)
325  {
330  }
331  else
332  {
333  skip("Could not start helper service\n");
334  }
336  }
338 }
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
#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
unsigned int BOOL
Definition: ntddk_ex.h:94
static void WaitService(SC_HANDLE service_handle, DWORD Status, SERVICE_STATUS_PROCESS *ssp)
static void RunApphelpCacheControlTests(SC_HANDLE service_handle)
#define skip(...)
Definition: CString.cpp:57
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
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 219 of file NtApphelpCacheControl.c.

220 {
221  SERVICE_STATUS status = {0};
222  status.dwServiceType = SERVICE_WIN32;
223  status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
224 
225  switch(ctrl)
226  {
229  status.dwCurrentState = SERVICE_STOP_PENDING;
230  status.dwControlsAccepted = 0;
233  return NO_ERROR;
236  {
237  /* TODO: how should we communicate a failure? */
238  }
239  break;
242  {
243  /* TODO: how should we communicate a failure? */
244  }
245  break;
246  default:
247  DbgPrint("Unhandled: %d\n", ctrl);
248  break;
249  }
250  status.dwCurrentState = SERVICE_RUNNING;
252  return NO_ERROR;
253 }
#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:679
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:986
static BOOLEAN RegisterInShimCache(BOOLEAN WithMapping)
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define ctrl
Definition: input.c:1669
#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 255 of file NtApphelpCacheControl.c.

256 {
257  SERVICE_STATUS status = {0};
258  service_status = pRegisterServiceCtrlHandlerExA(service_name, service_handler, NULL);
259  if(!service_status)
260  return;
261 
262  status.dwServiceType = SERVICE_WIN32;
263  status.dwCurrentState = SERVICE_RUNNING;
264  status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
266 
268 
269  status.dwCurrentState = SERVICE_STOPPED;
270  status.dwControlsAccepted = 0;
272 }
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:986
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 340 of file NtApphelpCacheControl.c.

341 {
342  char **argv;
343  int argc;
344 
345  pRegisterServiceCtrlHandlerExA = (void*)GetProcAddress(GetModuleHandleA("advapi32.dll"), "RegisterServiceCtrlHandlerExA");
346  if (!pRegisterServiceCtrlHandlerExA)
347  {
348  win_skip("RegisterServiceCtrlHandlerExA not available, skipping tests\n");
349  return;
350  }
351 
352  pNtApphelpCacheControl = (void*)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtApphelpCacheControl");
353  if (!pNtApphelpCacheControl)
354  {
355  win_skip("NtApphelpCacheControl not available, skipping tests\n");
356  return;
357  }
358 
360  if(argc < 3)
361  {
362  RunTest();
363  }
364  else
365  {
366  SERVICE_TABLE_ENTRYA servtbl[] = {
368  {NULL, NULL}
369  };
372  Sleep(50);
374  }
375 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
static HANDLE service_stop_event
#define argv
Definition: mplay32.c:18
BOOL WINAPI StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA *lpServiceStartTable)
Definition: sctrl.c:1024
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:583
static char service_name[100]
int winetest_get_mainargs(char ***pargv)
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
#define GetProcAddress(x, y)
Definition: compat.h:410
#define win_skip
Definition: test.h:141

◆ WaitService()

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

Definition at line 294 of file NtApphelpCacheControl.c.

295 {
296  DWORD dwBytesNeeded;
297  DWORD dwStartTime = GetTickCount();
298  while (ssp->dwCurrentState != Status)
299  {
300  Sleep(40);
302  (LPBYTE)ssp, sizeof(SERVICE_STATUS_PROCESS), &dwBytesNeeded ))
303  {
304  ok(0, "QueryServiceStatusEx failed waiting for %lu\n", Status);
305  break;
306  }
307  if ((GetTickCount() - dwStartTime) > 1000)
308  {
309  ok(0, "Timeout waiting for (%lu) from service, is: %lu.\n",
310  Status, ssp->dwCurrentState);
311  break;
312  }
313  }
314 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:445
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:52
#define ok(value,...)
Definition: CComObject.cpp:34
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:24

Referenced by RunTest().

Variable Documentation

◆ LPHANDLER_FUNCTION_EX

LPHANDLER_FUNCTION_EX

Definition at line 188 of file NtApphelpCacheControl.c.

◆ LPVOID

Definition at line 188 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 191 of file NtApphelpCacheControl.c.

Referenced by service_handler(), and service_main().

◆ service_stop_event

HANDLE service_stop_event
static

Definition at line 190 of file NtApphelpCacheControl.c.

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