ReactOS 0.4.16-dev-240-gdb5fa3b
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}
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define HCBT_CREATEWND
Definition: winuser.h:58
LRESULT WINAPI CallNextHookEx(_In_opt_ HHOOK, _In_ int, _In_ WPARAM, _In_ LPARAM)

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}
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
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 assert(x)
Definition: debug.h:53
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint res
Definition: glext.h:9613
const char * filename
Definition: ioapi.h:137
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define CREATE_ALWAYS
Definition: disk.h:72
#define GENERIC_WRITE
Definition: nt_native.h:90
int ret

◆ 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_SetupInstallServicesFromInfSectionExA(void)
static void test_SetupInstallServicesFromInfSectionExW(void)
static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
static char CURR_DIR[MAX_PATH]
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI GetCurrentDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2146
BOOL WINAPI SetCurrentDirectoryA(IN LPCSTR lpPathName)
Definition: path.c:2206
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2054
char temp_path[MAX_PATH]
Definition: mspatcha.c:123
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
#define WH_CBT
Definition: winuser.h:35
HHOOK WINAPI SetWindowsHookExA(_In_ int, _In_ HOOKPROC, _In_opt_ HINSTANCE, _In_ DWORD)
BOOL WINAPI UnhookWindowsHookEx(_In_ HHOOK)

◆ 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");
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");
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");
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");
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");
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");
165 SetLastError(0xdeadbeef);
166 ret = SetupInstallServicesFromInfSectionExA(infhandle, "Winetest.Services", 0, NULL, NULL, NULL, NULL);
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");
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}
static SC_HANDLE scm_handle
Definition: ServiceArgs.c:20
static const char inffile[]
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI SetupInstallServicesFromInfSectionExA(HINF hinf, PCSTR sectionname, DWORD flags, HDEVINFO devinfo, PSP_DEVINFO_DATA devinfo_data, PVOID reserved1, PVOID reserved2)
Definition: install.c:1633
HINF WINAPI SetupOpenInfFileA(PCSTR name, PCSTR class, DWORD style, UINT *error)
Definition: parser.c:1139
#define INF_STYLE_WIN4
Definition: infsupp.h:41
static void create_inf_file(void)
Definition: advpack.c:202
#define GENERIC_ALL
Definition: nt_native.h:92
#define DELETE
Definition: nt_native.h:57
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:921
SC_HANDLE WINAPI OpenServiceA(SC_HANDLE hSCManager, LPCSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2112
SC_HANDLE WINAPI OpenSCManagerA(LPCSTR lpMachineName, LPCSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2024
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
#define win_skip
Definition: test.h:163
#define ERROR_BAD_SERVICE_INSTALLSECT
Definition: setupapi.h:319
#define ERROR_SECTION_NOT_FOUND
Definition: setupapi.h:293
STRSAFEAPI StringCbPrintfA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:547
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:45
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

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");
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");
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");
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");
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");
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");
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");
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");
320 SetLastError(0xdeadbeef);
321 ret = SetupInstallServicesFromInfSectionExW(infhandle, L"Winetest.Services", 0, NULL, NULL, NULL, NULL);
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");
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}
BOOL WINAPI SetupInstallServicesFromInfSectionExW(HINF hinf, PCWSTR sectionname, DWORD flags, HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, PVOID reserved1, PVOID reserved2)
Definition: install.c:2081
#define L(x)
Definition: ntvdm.h:50
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2068
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2160

Referenced by START_TEST().

Variable Documentation

◆ CURR_DIR

◆ hhook

HHOOK hhook
static

◆ inffile