ReactOS 0.4.15-dev-8146-gdc0ed6d
SetupInstallServicesFromInfSectionEx.c
Go to the documentation of this file.
1/*
2 * SetupAPI device class-related functions tests
3 *
4 * Copyright 2015 Víctor Martínez (victor.martinez@reactos.org)
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this library; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include <apitest.h>
22#include <stdio.h>
23#include <assert.h>
24#include <winuser.h>
25#include <winreg.h>
26#include <winsvc.h>
27#include <setupapi.h>
28#include <strsafe.h>
29
30static const char inffile[] = "test.inf";
31static char CURR_DIR[MAX_PATH];
32
33/* Helpers */
34
35static void create_inf_file(LPCSTR filename, const char *data)
36{
37 DWORD res;
38 BOOL ret;
43 assert(ret != 0);
45}
46
47/* CBT hook to ensure a window (e.g., MessageBox) cannot be created */
48static HHOOK hhook;
50{
51 return nCode == HCBT_CREATEWND ? 1: CallNextHookEx(hhook, nCode, wParam, lParam);
52}
53
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}
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}
364
365
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 SC_HANDLE scm_handle
Definition: ServiceArgs.c:20
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]
static const char inffile[]
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define MAX_PATH
Definition: compat.h:34
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define CALLBACK
Definition: compat.h:35
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
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
BOOL WINAPI SetupInstallServicesFromInfSectionExA(HINF hinf, PCSTR sectionname, DWORD flags, HDEVINFO devinfo, PSP_DEVINFO_DATA devinfo_data, PVOID reserved1, PVOID reserved2)
Definition: install.c:1630
BOOL WINAPI SetupInstallServicesFromInfSectionExW(HINF hinf, PCWSTR sectionname, DWORD flags, HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, PVOID reserved1, PVOID reserved2)
Definition: install.c:2078
HINF WINAPI SetupOpenInfFileA(PCSTR name, PCSTR class, DWORD style, UINT *error)
Definition: parser.c:1139
#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
#define INF_STYLE_WIN4
Definition: infsupp.h:41
const char * filename
Definition: ioapi.h:137
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define CREATE_ALWAYS
Definition: disk.h:72
static void create_inf_file(void)
Definition: advpack.c:202
char temp_path[MAX_PATH]
Definition: mspatcha.c:123
#define GENERIC_ALL
Definition: nt_native.h:92
#define DELETE
Definition: nt_native.h:57
#define GENERIC_WRITE
Definition: nt_native.h:90
#define L(x)
Definition: ntvdm.h:50
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:921
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2068
SC_HANDLE WINAPI OpenServiceA(SC_HANDLE hSCManager, LPCSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2112
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2160
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 SetupInstallServicesFromInfSectionEx
Definition: setupapi.h:2647
#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
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WH_CBT
Definition: winuser.h:35
#define HCBT_CREATEWND
Definition: winuser.h:58
HHOOK WINAPI SetWindowsHookExA(_In_ int, _In_ HOOKPROC, _In_opt_ HINSTANCE, _In_ DWORD)
BOOL WINAPI UnhookWindowsHookEx(_In_ HHOOK)
LRESULT WINAPI CallNextHookEx(_In_opt_ HHOOK, _In_ int, _In_ WPARAM, _In_ LPARAM)
const char * LPCSTR
Definition: xmlstorage.h:183