ReactOS 0.4.17-dev-577-ge3e58ac
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
207static BOOL
209{
210 HKEY hKey;
211 LONG rc;
212
213 /* Check for the presence of the "MiniNT" registry key */
215 L"SYSTEM\\CurrentControlSet\\Control\\MiniNT",
216 0,
218 &hKey);
219 if (rc == ERROR_SUCCESS)
221
222 return (rc == ERROR_SUCCESS);
223}
224
227{
230
233
234 DPRINT("ServiceMain() called\n");
235
237
240 NULL);
242 {
243 DPRINT1("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
244 return;
245 }
246
248
250 0,
252 NULL,
253 0,
254 &dwThreadId);
255 if (hThread != NULL)
257
259
261 0,
263 NULL,
264 0,
265 &dwThreadId);
266 if (hThread != NULL)
268
270
272 0,
274 NULL,
275 0,
276 &dwThreadId);
277 if (hThread != NULL)
279
281
282 DPRINT("ServiceMain() done\n");
283}
284
285static DWORD
287{
288 BOOLEAN OldValue;
289 DWORD dwError;
290
291 DPRINT("UMPNPMGR: InitializePnPManager() started\n");
292
293 /* We need this privilege for using CreateProcessAsUserW */
295
297 if (hInstallEvent == NULL)
298 {
299 dwError = GetLastError();
300 DPRINT1("Could not create the Install Event! (Error %lu)\n", dwError);
301 return dwError;
302 }
303
305 TRUE,
306 FALSE,
307 L"Global\\PnP_No_Pending_Install_Events");
309 {
310 dwError = GetLastError();
311 DPRINT1("Could not create the Pending-Install Event! (Error %lu)\n", dwError);
312 return dwError;
313 }
314
315 /*
316 * Initialize the device-install event list
317 */
318
321 {
322 dwError = GetLastError();
323 DPRINT1("Could not create the List Event! (Error %lu)\n", dwError);
324 return dwError;
325 }
326
329 {
330 dwError = GetLastError();
331 DPRINT1("Could not create the List Mutex! (Error %lu)\n", dwError);
332 return dwError;
333 }
335
336 /* Query the SuppressUI registry value and cache it for our whole lifetime */
338 L"System\\CurrentControlSet\\Services\\PlugPlay\\Parameters",
339 L"SuppressUI",
342 DPRINT("UMPNPMGR: newdev.dll's wizard UI won't be shown!\n");
343
345 L"System\\CurrentControlSet\\Enum",
346 0,
348 &hEnumKey);
349 if (dwError != ERROR_SUCCESS)
350 {
351 DPRINT1("Could not open the Enum Key! (Error %lu)\n", dwError);
352 return dwError;
353 }
354
356 L"System\\CurrentControlSet\\Control\\Class",
357 0,
359 &hClassKey);
360 if (dwError != ERROR_SUCCESS)
361 {
362 DPRINT1("Could not open the Class Key! (Error %lu)\n", dwError);
363 return dwError;
364 }
365
366 DPRINT("UMPNPMGR: InitializePnPManager() done\n");
367
368 return 0;
369}
370
375{
376 switch (fdwReason)
377 {
381 break;
382
384 break;
385 }
386
387 return TRUE;
388}
389
390/* EOF */
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
unsigned char BOOLEAN
Definition: actypes.h:127
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:527
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 ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
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
MonoAssembly int argc
Definition: metahost.c:107
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
static IN DWORD IN LPVOID lpvReserved
BOOL * PBOOL
Definition: minwindef.h:137
#define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE
Definition: security.c:557
#define argv
Definition: mplay32.c:18
LPSTR LPTSTR
Definition: ms-dtyp.idl:131
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
static HANDLE ULONG_PTR dwData
Definition: pipe.c:111
BYTE * PBYTE
Definition: pedump.c:66
short WCHAR
Definition: pedump.c:58
long LONG
Definition: pedump.c:60
_In_opt_ _In_opt_ _In_ _In_ DWORD cbData
Definition: shlwapi.h:761
#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
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
#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:525
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:587
const uint16_t * PCWSTR
Definition: typedefs.h:57
#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:372
static BOOL IsMiniNT(VOID)
Check whether we are running in MiniNT mode (e.g. live medium).
Definition: umpnpmgr.c:208
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:286
VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
Definition: umpnpmgr.c:226
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 g_IsMiniNT
Definition: umpnpmgr.c:48
HKEY hClassKey
Definition: umpnpmgr.c:45
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:962