ReactOS 0.4.16-dev-1946-g52006dd
umpnpmgr.c
Go to the documentation of this file.
1/*
2 * ReactOS kernel
3 * Copyright (C) 2005 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19/*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
22 * FILE: base/services/umpnpmgr/umpnpmgr.c
23 * PURPOSE: User-mode Plug and Play manager
24 * PROGRAMMER: Eric Kohl (eric.kohl@reactos.org)
25 * Hervé Poussineau (hpoussin@reactos.org)
26 * Colin Finck (colin@reactos.org)
27 */
28
29/* INCLUDES *****************************************************************/
30
31#include "precomp.h"
32
33#define NDEBUG
34#include <debug.h>
35
36
37/* GLOBALS ******************************************************************/
38
39static WCHAR ServiceName[] = L"PlugPlay";
40
43
49
50/* FUNCTIONS *****************************************************************/
51
52static VOID
54 _In_ DWORD dwState,
55 _In_ DWORD dwCheckPoint)
56{
57 if ((dwState == SERVICE_STOPPED) || (dwState == SERVICE_STOP_PENDING))
59
64 ServiceStatus.dwCheckPoint = dwCheckPoint;
65
66 if (dwState == SERVICE_RUNNING)
68 else
70
71 if (dwState == SERVICE_START_PENDING ||
72 dwState == SERVICE_STOP_PENDING ||
73 dwState == SERVICE_PAUSE_PENDING ||
74 dwState == SERVICE_CONTINUE_PENDING)
76 else
78
81}
82
83
84static DWORD WINAPI
86 DWORD dwEventType,
87 LPVOID lpEventData,
88 LPVOID lpContext)
89{
90 DPRINT1("ServiceControlHandler() called\n");
91
92 switch (dwControl)
93 {
95 DPRINT1(" SERVICE_CONTROL_STOP received\n");
97 /* Stop listening to RPC Messages */
100 return ERROR_SUCCESS;
101
103 DPRINT1(" SERVICE_CONTROL_PAUSE received\n");
105 return ERROR_SUCCESS;
106
108 DPRINT1(" SERVICE_CONTROL_CONTINUE received\n");
110 return ERROR_SUCCESS;
111
113 DPRINT1(" SERVICE_CONTROL_INTERROGATE received\n");
116 return ERROR_SUCCESS;
117
119 DPRINT1(" SERVICE_CONTROL_SHUTDOWN received\n");
121 /* Stop listening to RPC Messages */
124 return ERROR_SUCCESS;
125
126 default :
127 DPRINT1(" Control %lu received\n", dwControl);
129 }
130}
131
132static DWORD
134 IN HKEY hKey,
135 IN PCWSTR lpSubKey,
136 IN PCWSTR lpValue,
138{
139 DWORD dwError, dwType, dwData;
140 DWORD cbData = sizeof(dwData);
141 HKEY hSubKey = NULL;
142
143 /* Default value */
144 *pValue = FALSE;
145
146 dwError = RegOpenKeyExW(hKey,
147 lpSubKey,
148 0,
149 KEY_READ,
150 &hSubKey);
151 if (dwError != ERROR_SUCCESS)
152 {
153 DPRINT("GetBooleanRegValue(): RegOpenKeyExW() has failed to open '%S' key! (Error: %lu)\n",
154 lpSubKey, dwError);
155 return dwError;
156 }
157
158 dwError = RegQueryValueExW(hSubKey,
159 lpValue,
160 0,
161 &dwType,
162 (PBYTE)&dwData,
163 &cbData);
164 if (dwError != ERROR_SUCCESS)
165 {
166 DPRINT("GetBooleanRegValue(): RegQueryValueExW() has failed to query '%S' value! (Error: %lu)\n",
167 lpValue, dwError);
168 goto Cleanup;
169 }
170 if (dwType != REG_DWORD)
171 {
172 DPRINT("GetBooleanRegValue(): The value is not of REG_DWORD type!\n");
173 goto Cleanup;
174 }
175
176 /* Return the value */
177 *pValue = (dwData == 1);
178
179Cleanup:
180 RegCloseKey(hSubKey);
181
182 return dwError;
183}
184
185BOOL
187{
188 BOOL bSuppressNewHWUI = FALSE;
189
190 /*
191 * Query the SuppressNewHWUI policy registry value. Don't cache it
192 * as we want to update our behaviour in consequence.
193 */
195 L"Software\\Policies\\Microsoft\\Windows\\DeviceInstall\\Settings",
196 L"SuppressNewHWUI",
197 &bSuppressNewHWUI);
198 if (bSuppressNewHWUI)
199 DPRINT("GetSuppressNewUIValue(): newdev.dll's wizard UI won't be shown!\n");
200
201 return bSuppressNewHWUI;
202}
203
204BOOL
206{
208 PWSTR CurrentOption, NextOption;
209 HKEY hControlKey;
210 DWORD dwType;
212 DWORD dwError;
213 BOOL LiveMedium = FALSE;
214
215 DPRINT("RunningOnLiveMedium()\n");
216
217 /* Open the Setup key */
219 L"SYSTEM\\CurrentControlSet\\Control",
220 0,
222 &hControlKey);
223 if (dwError != ERROR_SUCCESS)
224 goto done;
225
226 /* Read the CmdLine value */
227 dwSize = sizeof(Options);
228 dwError = RegQueryValueExW(hControlKey,
229 L"SystemStartOptions",
230 NULL,
231 &dwType,
233 &dwSize);
234 if ((dwError != ERROR_SUCCESS) || (dwType != REG_SZ))
235 goto done;
236
237 /* Check for the '-mini' option */
238 CurrentOption = Options;
239 while (CurrentOption)
240 {
241 NextOption = wcschr(CurrentOption, L' ');
242 if (NextOption)
243 *NextOption = L'\0';
244 if (_wcsicmp(CurrentOption, L"MININT") == 0)
245 {
246 DPRINT("Found 'MININT' boot option\n");
247 LiveMedium = TRUE;
248 goto done;
249 }
250 CurrentOption = NextOption ? NextOption + 1 : NULL;
251 }
252
253done:
254 RegCloseKey(hControlKey);
255
256 return LiveMedium;
257}
258
261{
264
267
268 DPRINT("ServiceMain() called\n");
269
271
274 NULL);
276 {
277 DPRINT1("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
278 return;
279 }
280
282
284 0,
286 NULL,
287 0,
288 &dwThreadId);
289 if (hThread != NULL)
291
293
295 0,
297 NULL,
298 0,
299 &dwThreadId);
300 if (hThread != NULL)
302
304
306 0,
308 NULL,
309 0,
310 &dwThreadId);
311 if (hThread != NULL)
313
315
316 DPRINT("ServiceMain() done\n");
317}
318
319static DWORD
321{
322 BOOLEAN OldValue;
323 DWORD dwError;
324
325 DPRINT("UMPNPMGR: InitializePnPManager() started\n");
326
327 /* We need this privilege for using CreateProcessAsUserW */
329
331 if (hInstallEvent == NULL)
332 {
333 dwError = GetLastError();
334 DPRINT1("Could not create the Install Event! (Error %lu)\n", dwError);
335 return dwError;
336 }
337
339 TRUE,
340 FALSE,
341 L"Global\\PnP_No_Pending_Install_Events");
343 {
344 dwError = GetLastError();
345 DPRINT1("Could not create the Pending-Install Event! (Error %lu)\n", dwError);
346 return dwError;
347 }
348
349 /*
350 * Initialize the device-install event list
351 */
352
355 {
356 dwError = GetLastError();
357 DPRINT1("Could not create the List Event! (Error %lu)\n", dwError);
358 return dwError;
359 }
360
363 {
364 dwError = GetLastError();
365 DPRINT1("Could not create the List Mutex! (Error %lu)\n", dwError);
366 return dwError;
367 }
369
370 /* Query the SuppressUI registry value and cache it for our whole lifetime */
372 L"System\\CurrentControlSet\\Services\\PlugPlay\\Parameters",
373 L"SuppressUI",
376 DPRINT("UMPNPMGR: newdev.dll's wizard UI won't be shown!\n");
377
379 L"System\\CurrentControlSet\\Enum",
380 0,
382 &hEnumKey);
383 if (dwError != ERROR_SUCCESS)
384 {
385 DPRINT1("Could not open the Enum Key! (Error %lu)\n", dwError);
386 return dwError;
387 }
388
390 L"System\\CurrentControlSet\\Control\\Class",
391 0,
393 &hClassKey);
394 if (dwError != ERROR_SUCCESS)
395 {
396 DPRINT1("Could not open the Class Key! (Error %lu)\n", dwError);
397 return dwError;
398 }
399
400 DPRINT("UMPNPMGR: InitializePnPManager() done\n");
401
402 return 0;
403}
404
409{
410 switch (fdwReason)
411 {
415 break;
416
418 break;
419 }
420
421 return TRUE;
422}
423
424/* EOF */
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
unsigned char BOOLEAN
static int argc
Definition: ServiceArgs.c:12
static DWORD const fdwReason
#define DPRINT1
Definition: precomp.h:8
static BOOL SetupIsActive(VOID)
Definition: setup.c:27
DWORD WINAPI PnpEventThread(_In_ LPVOID lpParameter)
Definition: event.c:238
HANDLE hDeviceInstallListNotEmpty
Definition: install.c:46
DWORD WINAPI DeviceInstallThread(LPVOID lpParameter)
Definition: install.c:526
HANDLE hInstallEvent
Definition: install.c:40
HANDLE hDeviceInstallListMutex
Definition: install.c:44
HANDLE hNoPendingInstalls
Definition: install.c:41
LIST_ENTRY DeviceInstallListHead
Definition: install.c:45
DWORD WINAPI RpcServerThread(LPVOID lpParameter)
Definition: rpcserver.c:48
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define CloseHandle
Definition: compat.h:739
#define wcschr
Definition: compat.h:17
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
static const WCHAR Cleanup[]
Definition: register.c:80
#define L(x)
Definition: resources.c:13
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
DWORD dwThreadId
Definition: fdebug.c:31
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
PWCHAR pValue
#define REG_SZ
Definition: layer.c:22
static IN DWORD IN LPVOID lpvReserved
BOOL * PBOOL
Definition: minwindef.h:137
static char * NextOption(const char *const ostr)
Definition: getopt.c:31
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE
Definition: security.c:657
static HANDLE ULONG_PTR dwData
Definition: file.c:35
#define argv
Definition: mplay32.c:18
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
HANDLE hThread
Definition: wizard.c:28
#define _In_
Definition: no_sal2.h:158
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
#define KEY_READ
Definition: nt_native.h:1026
#define KEY_QUERY_VALUE
Definition: nt_native.h:1019
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
BYTE * PBYTE
Definition: pedump.c:66
_In_opt_ _In_opt_ _In_ _In_ DWORD cbData
Definition: shlwapi.h:761
RPC_STATUS WINAPI RpcMgmtStopServerListening(RPC_BINDING_HANDLE Binding)
Definition: rpc_server.c:1596
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:831
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:1016
#define REG_DWORD
Definition: sdbapi.c:615
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define DPRINT
Definition: sndvol32.h:73
DWORD dwServiceType
Definition: winsvc.h:105
DWORD dwWin32ExitCode
Definition: winsvc.h:108
DWORD dwControlsAccepted
Definition: winsvc.h:107
DWORD dwWaitHint
Definition: winsvc.h:111
DWORD dwCurrentState
Definition: winsvc.h:106
DWORD dwCheckPoint
Definition: winsvc.h:110
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:109
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:576
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
unsigned char * LPBYTE
Definition: typedefs.h:53
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
static WCHAR ServiceName[]
Definition: umpnpmgr.c:39
static VOID UpdateServiceStatus(_In_ DWORD dwState, _In_ DWORD dwCheckPoint)
Definition: umpnpmgr.c:53
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
Definition: umpnpmgr.c:406
BOOL GetSuppressNewUIValue(VOID)
Definition: umpnpmgr.c:186
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: umpnpmgr.c:85
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: umpnpmgr.c:41
HKEY hEnumKey
Definition: umpnpmgr.c:44
BOOL g_ShuttingDown
Definition: umpnpmgr.c:47
BOOL g_IsUISuppressed
Definition: umpnpmgr.c:46
static DWORD InitializePnPManager(VOID)
Definition: umpnpmgr.c:320
VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
Definition: umpnpmgr.c:260
static DWORD GetBooleanRegValue(IN HKEY hKey, IN PCWSTR lpSubKey, IN PCWSTR lpValue, OUT PBOOL pValue)
Definition: umpnpmgr.c:133
static SERVICE_STATUS ServiceStatus
Definition: umpnpmgr.c:42
BOOL RunningOnLiveMedium(VOID)
Definition: umpnpmgr.c:205
HKEY hClassKey
Definition: umpnpmgr.c:45
BOOL g_IsLiveMedium
Definition: umpnpmgr.c:48
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3540
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:46
#define SERVICE_PAUSED
Definition: winsvc.h:27
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:44
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:42
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
#define SERVICE_PAUSE_PENDING
Definition: winsvc.h:26
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:43
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:45
#define SERVICE_CONTINUE_PENDING
Definition: winsvc.h:25
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:962
__wchar_t WCHAR
Definition: xmlstorage.h:180
CHAR * LPTSTR
Definition: xmlstorage.h:192