ReactOS  0.4.14-dev-1314-gacf135d
SetupInstallServicesFromInfSectionEx.c File Reference
#include <apitest.h>
#include <stdio.h>
#include <assert.h>
#include <winuser.h>
#include <winreg.h>
#include <winsvc.h>
#include <setupapi.h>
#include <strsafe.h>
Include dependency graph for SetupInstallServicesFromInfSectionEx.c:

Go to the source code of this file.

Functions

static void create_inf_file (LPCSTR filename, const char *data)
 
static LRESULT CALLBACK cbt_hook_proc (int nCode, WPARAM wParam, LPARAM lParam)
 
static void test_SetupInstallServicesFromInfSectionExA (void)
 
static void test_SetupInstallServicesFromInfSectionExW (void)
 
 START_TEST (SetupInstallServicesFromInfSectionEx)
 

Variables

static const char inffile [] = "test.inf"
 
static char CURR_DIR [MAX_PATH]
 
static HHOOK hhook
 

Function Documentation

◆ cbt_hook_proc()

static LRESULT CALLBACK cbt_hook_proc ( int  nCode,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 49 of file SetupInstallServicesFromInfSectionEx.c.

50 {
51  return nCode == HCBT_CREATEWND ? 1: CallNextHookEx(hhook, nCode, wParam, lParam);
52 }
#define HCBT_CREATEWND
Definition: winuser.h:58
WPARAM wParam
Definition: combotst.c:138
LRESULT WINAPI CallNextHookEx(_In_opt_ HHOOK, _In_ int, _In_ WPARAM, _In_ LPARAM)
LPARAM lParam
Definition: combotst.c:139

Referenced by START_TEST().

◆ create_inf_file()

static void create_inf_file ( LPCSTR  filename,
const char data 
)
static

Definition at line 35 of file SetupInstallServicesFromInfSectionEx.c.

36 {
37  DWORD res;
38  BOOL ret;
43  assert(ret != 0);
45 }
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 CloseHandle
Definition: compat.h:406
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
#define assert(x)
Definition: debug.h:53
const char * filename
Definition: ioapi.h:135
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define CREATE_ALWAYS
Definition: disk.h:72
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
GLuint res
Definition: glext.h:9613
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:407

Referenced by test_SetupInstallServicesFromInfSectionExA(), and test_SetupInstallServicesFromInfSectionExW().

◆ START_TEST()

Definition at line 366 of file SetupInstallServicesFromInfSectionEx.c.

367 {
368  char temp_path[MAX_PATH], prev_path[MAX_PATH];
369 
370  GetCurrentDirectoryA(MAX_PATH, prev_path);
373 
375 
376  /* Set CBT hook to disallow MessageBox creation in current thread */
378  assert(hhook != 0);
379 
382 
384  SetCurrentDirectoryA(prev_path);
385 }
static void test_SetupInstallServicesFromInfSectionExW(void)
#define assert(x)
Definition: debug.h:53
HHOOK WINAPI SetWindowsHookExA(_In_ int, _In_ HOOKPROC, _In_opt_ HINSTANCE, _In_ DWORD)
static char CURR_DIR[MAX_PATH]
#define WH_CBT
Definition: winuser.h:35
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:458
static void test_SetupInstallServicesFromInfSectionExA(void)
static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
#define MAX_PATH
Definition: compat.h:26
BOOL WINAPI SetCurrentDirectoryA(IN LPCSTR lpPathName)
Definition: path.c:2205
BOOL WINAPI UnhookWindowsHookEx(_In_ HHOOK)
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
DWORD WINAPI GetCurrentDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2145
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
char temp_path[MAX_PATH]
Definition: mspatcha.c:123

◆ test_SetupInstallServicesFromInfSectionExA()

static void test_SetupInstallServicesFromInfSectionExA ( void  )
static

Definition at line 54 of file SetupInstallServicesFromInfSectionEx.c.

55 {
56  char inf[2048];
57  char path[MAX_PATH];
58  HINF infhandle;
59  BOOL ret;
60  SC_HANDLE scm_handle, svc_handle;
61 
62  /* Bail out if we are on win98 */
63  SetLastError(0xdeadbeef);
65 
67  {
68  win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
69  return;
70  }
72 
73  /* Basic inf file to satisfy SetupOpenInfFileA */
74  strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
76  StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
78 
79  /* Nothing but the Version section */
80  SetLastError(0xdeadbeef);
81  ret = SetupInstallServicesFromInfSectionExA(infhandle, "trolololo", 0, NULL, NULL, NULL,NULL);
82  ok(!ret, "Expected failure\n");
84  "Expected ERROR_SECTION_NOT_FOUND, got %08d\n", (int)GetLastError());
85  SetupCloseInfFile(infhandle);
87 
88 
89  /* Add the section */
90  strcat(inf, "[Winetest.Services]\n");
93  SetLastError(0xdeadbeef);
94  ret = SetupInstallServicesFromInfSectionExA(infhandle, "Winetest.Services", 0, NULL, NULL, NULL, NULL);
95  ok(!ret, "Expected failure\n");
97  "Expected ERROR_SECTION_NOT_FOUND, got %08d\n", (int)GetLastError());
98  SetupCloseInfFile(infhandle);
100 
101  /* Add a reference */
102  strcat(inf, "AddService=Winetest,,Winetest.Service\n");
103  create_inf_file(inffile, inf);
105  SetLastError(0xdeadbeef);
106  ret = SetupInstallServicesFromInfSectionExA(infhandle, "Winetest.Services", 0, NULL, NULL, NULL, NULL);
107  ok(!ret, "Expected failure\n");
109  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
110  SetupCloseInfFile(infhandle);
112 
113  /* Add the section */
114  strcat(inf, "[Winetest.Service]\n");
115  create_inf_file(inffile, inf);
117  SetLastError(0xdeadbeef);
118  ret = SetupInstallServicesFromInfSectionExA(infhandle, "Winetest.Services", 0, NULL, NULL, NULL, NULL);
119  ok(!ret, "Expected failure\n");
121  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
122  SetupCloseInfFile(infhandle);
124 
125  /* Just the ServiceBinary */
126  strcat(inf, "ServiceBinary=%12%\\winetest.sys\n");
127  create_inf_file(inffile, inf);
129  SetLastError(0xdeadbeef);
130  ret = SetupInstallServicesFromInfSectionExA(infhandle, "Winetest.Services", 0, NULL, NULL, NULL, NULL);
131  ok(!ret, "Expected failure\n");
133  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
134  SetupCloseInfFile(infhandle);
136 
137  /* Add the ServiceType */
138  strcat(inf, "ServiceType=1\n");
139  create_inf_file(inffile, inf);
141  SetLastError(0xdeadbeef);
142  ret = SetupInstallServicesFromInfSectionExA(infhandle, "Winetest.Services", 0, NULL, NULL, NULL, NULL);
143  ok(!ret, "Expected failure\n");
145  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
146  SetupCloseInfFile(infhandle);
148 
149  /* Add the StartType */
150  strcat(inf, "StartType=4\n");
151  create_inf_file(inffile, inf);
153  SetLastError(0xdeadbeef);
154  ret = SetupInstallServicesFromInfSectionExA(infhandle, "Winetest.Services", 0, NULL, NULL, NULL, NULL);
155  ok(!ret, "Expected failure\n");
157  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
158  SetupCloseInfFile(infhandle);
160 
161  /* This should be it, the minimal entries to install a service */
162  strcat(inf, "ErrorControl=1");
163  create_inf_file(inffile, inf);
165  SetLastError(0xdeadbeef);
166  ret = SetupInstallServicesFromInfSectionExA(infhandle, "Winetest.Services", 0, NULL, NULL, NULL, NULL);
167  if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
168  {
169  skip("Not enough rights to install the service\n");
170  SetupCloseInfFile(infhandle);
172  return;
173  }
174  ok(ret, "Expected success\n");
176  "Expected ERROR_SUCCESS, got %08d\n", (int)GetLastError());
177  SetupCloseInfFile(infhandle);
179 
181 
182  /* Open the service to see if it's really there */
183  svc_handle = OpenServiceA(scm_handle, "Winetest", DELETE);
184  ok(svc_handle != NULL, "Service was not created\n");
185 
186  SetLastError(0xdeadbeef);
187  ret = DeleteService(svc_handle);
188  ok(ret, "Service could not be deleted : %d\n", (int)GetLastError());
189 
190  CloseServiceHandle(svc_handle);
192 
193  strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
194  strcat(inf, "[XSP.InstallPerVer]\n");
195  strcat(inf, "AddReg=AspEventlogMsg.Reg,Perf.Reg,AspVersions.Reg,FreeADO.Reg,IndexServer.Reg\n");
196  create_inf_file(inffile, inf);
197  StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
199 
200  SetLastError(0xdeadbeef);
201  ret = SetupInstallServicesFromInfSectionExA(infhandle, "XSP.InstallPerVer", 0, NULL, NULL, NULL,NULL);
202  ok(ret, "Expected success\n");
203  ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %08d\n", (int)GetLastError());
204  SetupCloseInfFile(infhandle);
206 
207  /* TODO: Test the Flags */
208 }
#define GENERIC_ALL
Definition: nt_native.h:92
#define ERROR_SECTION_NOT_FOUND
Definition: setupapi.h:288
#define INF_STYLE_WIN4
Definition: infsupp.h:41
#define ERROR_SUCCESS
Definition: deptool.c:10
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
static SC_HANDLE scm_handle
Definition: ServiceArgs.c:20
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:916
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:43
SC_HANDLE WINAPI OpenSCManagerA(LPCSTR lpMachineName, LPCSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:1967
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
static char CURR_DIR[MAX_PATH]
static const char inffile[]
#define ERROR_BAD_SERVICE_INSTALLSECT
Definition: setupapi.h:314
STRSAFEAPI StringCbPrintfA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:547
#define MAX_PATH
Definition: compat.h:26
#define SetLastError(x)
Definition: compat.h:417
int ret
HINF WINAPI SetupOpenInfFileA(PCSTR name, PCSTR class, DWORD style, UINT *error)
Definition: parser.c:1139
#define ok(value,...)
Definition: atltest.h:57
SC_HANDLE WINAPI OpenServiceA(SC_HANDLE hSCManager, LPCSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2055
#define skip(...)
Definition: atltest.h:64
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
BOOL WINAPI SetupInstallServicesFromInfSectionExA(HINF hinf, PCSTR sectionname, DWORD flags, HDEVINFO devinfo, PSP_DEVINFO_DATA devinfo_data, PVOID reserved1, PVOID reserved2)
Definition: install.c:1630
#define win_skip
Definition: test.h:149
#define DELETE
Definition: nt_native.h:57
static void create_inf_file(LPCSTR filename, const char *data)

Referenced by START_TEST().

◆ test_SetupInstallServicesFromInfSectionExW()

static void test_SetupInstallServicesFromInfSectionExW ( void  )
static

Definition at line 209 of file SetupInstallServicesFromInfSectionEx.c.

210 {
211  char inf[2048];
212  char path[MAX_PATH];
213  HINF infhandle;
214  BOOL ret;
215  SC_HANDLE scm_handle, svc_handle;
216 
217  /* Bail out if we are on win98 */
218  SetLastError(0xdeadbeef);
220 
222  {
223  win_skip("OpenSCManagerW is not implemented, we are most likely on win9x\n");
224  return;
225  }
227 
228  /* Basic inf file to satisfy SetupOpenInfFileA */
229  strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
230  create_inf_file(inffile, inf);
231  StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
233 
234  /* Nothing but the Version section */
235  SetLastError(0xdeadbeef);
236  ret = SetupInstallServicesFromInfSectionExW(infhandle, L"trolololo", 0, NULL, NULL, NULL,NULL);
237  ok(!ret, "Expected failure\n");
239  "Expected ERROR_SECTION_NOT_FOUND, got %08d\n", (int)GetLastError());
240  SetupCloseInfFile(infhandle);
242 
243 
244  /* Add the section */
245  strcat(inf, "[Winetest.Services]\n");
246  create_inf_file(inffile, inf);
248  SetLastError(0xdeadbeef);
249  ret = SetupInstallServicesFromInfSectionExW(infhandle, L"Winetest.Services", 0, NULL, NULL, NULL, NULL);
250  ok(!ret, "Expected failure\n");
252  "Expected ERROR_SECTION_NOT_FOUND, got %08d\n", (int)GetLastError());
253  SetupCloseInfFile(infhandle);
255 
256  /* Add a reference */
257  strcat(inf, "AddService=Winetest,,Winetest.Service\n");
258  create_inf_file(inffile, inf);
260  SetLastError(0xdeadbeef);
261  ret = SetupInstallServicesFromInfSectionExW(infhandle, L"Winetest.Services", 0, NULL, NULL, NULL, NULL);
262  ok(!ret, "Expected failure\n");
264  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
265  SetupCloseInfFile(infhandle);
267 
268  /* Add the section */
269  strcat(inf, "[Winetest.Service]\n");
270  create_inf_file(inffile, inf);
272  SetLastError(0xdeadbeef);
273  ret = SetupInstallServicesFromInfSectionExW(infhandle, L"Winetest.Services", 0, NULL, NULL, NULL, NULL);
274  ok(!ret, "Expected failure\n");
276  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
277  SetupCloseInfFile(infhandle);
279 
280  /* Just the ServiceBinary */
281  strcat(inf, "ServiceBinary=%12%\\winetest.sys\n");
282  create_inf_file(inffile, inf);
284  SetLastError(0xdeadbeef);
285  ret = SetupInstallServicesFromInfSectionExW(infhandle, L"Winetest.Services", 0, NULL, NULL, NULL, NULL);
286  ok(!ret, "Expected failure\n");
288  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
289  SetupCloseInfFile(infhandle);
291 
292  /* Add the ServiceType */
293  strcat(inf, "ServiceType=1\n");
294  create_inf_file(inffile, inf);
296  SetLastError(0xdeadbeef);
297  ret = SetupInstallServicesFromInfSectionExW(infhandle, L"Winetest.Services", 0, NULL, NULL, NULL, NULL);
298  ok(!ret, "Expected failure\n");
300  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
301  SetupCloseInfFile(infhandle);
303 
304  /* Add the StartType */
305  strcat(inf, "StartType=4\n");
306  create_inf_file(inffile, inf);
308  SetLastError(0xdeadbeef);
309  ret = SetupInstallServicesFromInfSectionExW(infhandle, L"Winetest.Services", 0, NULL, NULL, NULL, NULL);
310  ok(!ret, "Expected failure\n");
312  "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
313  SetupCloseInfFile(infhandle);
315 
316  /* This should be it, the minimal entries to install a service */
317  strcat(inf, "ErrorControl=1");
318  create_inf_file(inffile, inf);
320  SetLastError(0xdeadbeef);
321  ret = SetupInstallServicesFromInfSectionExW(infhandle, L"Winetest.Services", 0, NULL, NULL, NULL, NULL);
322  if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
323  {
324  skip("Not enough rights to install the service\n");
325  SetupCloseInfFile(infhandle);
327  return;
328  }
329  ok(ret, "Expected success\n");
331  "Expected ERROR_SUCCESS, got %08d\n", (int)GetLastError());
332  SetupCloseInfFile(infhandle);
334 
336 
337  /* Open the service to see if it's really there */
338  svc_handle = OpenServiceW(scm_handle, L"Winetest", DELETE);
339  ok(svc_handle != NULL, "Service was not created\n");
340 
341  SetLastError(0xdeadbeef);
342  ret = DeleteService(svc_handle);
343  ok(ret, "Service could not be deleted : %d\n", (int)GetLastError());
344 
345  CloseServiceHandle(svc_handle);
347 
348  strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
349  strcat(inf, "[XSP.InstallPerVer]\n");
350  strcat(inf, "AddReg=AspEventlogMsg.Reg,Perf.Reg,AspVersions.Reg,FreeADO.Reg,IndexServer.Reg\n");
351  create_inf_file(inffile, inf);
352  StringCbPrintfA(path, sizeof(path), "%s\\%s", CURR_DIR, inffile);
354 
355  SetLastError(0xdeadbeef);
356  ret = SetupInstallServicesFromInfSectionExW(infhandle, L"XSP.InstallPerVer", 0, NULL, NULL, NULL, NULL);
357  ok(ret, "Expected success\n");
358  ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %08d\n", (int)GetLastError());
359  SetupCloseInfFile(infhandle);
361 
362  /* TODO: Test the Flags */
363 }
#define GENERIC_ALL
Definition: nt_native.h:92
#define ERROR_SECTION_NOT_FOUND
Definition: setupapi.h:288
#define INF_STYLE_WIN4
Definition: infsupp.h:41
#define ERROR_SUCCESS
Definition: deptool.c:10
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
BOOL WINAPI SetupInstallServicesFromInfSectionExW(HINF hinf, PCWSTR sectionname, DWORD flags, HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, PVOID reserved1, PVOID reserved2)
Definition: install.c:2078
static SC_HANDLE scm_handle
Definition: ServiceArgs.c:20
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:916
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:43
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
unsigned int BOOL
Definition: ntddk_ex.h:94
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2103
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
static char CURR_DIR[MAX_PATH]
static const char inffile[]
#define ERROR_BAD_SERVICE_INSTALLSECT
Definition: setupapi.h:314
STRSAFEAPI StringCbPrintfA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:547
#define MAX_PATH
Definition: compat.h:26
#define SetLastError(x)
Definition: compat.h:417
int ret
static const WCHAR L[]
Definition: oid.c:1250
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2011
HINF WINAPI SetupOpenInfFileA(PCSTR name, PCSTR class, DWORD style, UINT *error)
Definition: parser.c:1139
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
#define win_skip
Definition: test.h:149
#define DELETE
Definition: nt_native.h:57
static void create_inf_file(LPCSTR filename, const char *data)

Referenced by START_TEST().

Variable Documentation

◆ CURR_DIR

◆ hhook

HHOOK hhook
static

◆ inffile