ReactOS 0.4.16-dev-329-g9223134
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
48
49/* FUNCTIONS *****************************************************************/
50
51static VOID
53 _In_ DWORD dwState,
54 _In_ DWORD dwCheckPoint)
55{
56 if ((dwState == SERVICE_STOPPED) || (dwState == SERVICE_STOP_PENDING))
58
63 ServiceStatus.dwCheckPoint = dwCheckPoint;
64
65 if (dwState == SERVICE_RUNNING)
67 else
69
70 if (dwState == SERVICE_START_PENDING ||
71 dwState == SERVICE_STOP_PENDING ||
72 dwState == SERVICE_PAUSE_PENDING ||
73 dwState == SERVICE_CONTINUE_PENDING)
75 else
77
80}
81
82
83static DWORD WINAPI
85 DWORD dwEventType,
86 LPVOID lpEventData,
87 LPVOID lpContext)
88{
89 DPRINT1("ServiceControlHandler() called\n");
90
91 switch (dwControl)
92 {
94 DPRINT1(" SERVICE_CONTROL_STOP received\n");
96 /* Stop listening to RPC Messages */
99 return ERROR_SUCCESS;
100
102 DPRINT1(" SERVICE_CONTROL_PAUSE received\n");
104 return ERROR_SUCCESS;
105
107 DPRINT1(" SERVICE_CONTROL_CONTINUE received\n");
109 return ERROR_SUCCESS;
110
112 DPRINT1(" SERVICE_CONTROL_INTERROGATE received\n");
115 return ERROR_SUCCESS;
116
118 DPRINT1(" SERVICE_CONTROL_SHUTDOWN received\n");
120 /* Stop listening to RPC Messages */
123 return ERROR_SUCCESS;
124
125 default :
126 DPRINT1(" Control %lu received\n", dwControl);
128 }
129}
130
131static DWORD
133 IN HKEY hKey,
134 IN PCWSTR lpSubKey,
135 IN PCWSTR lpValue,
137{
138 DWORD dwError, dwType, dwData;
139 DWORD cbData = sizeof(dwData);
140 HKEY hSubKey = NULL;
141
142 /* Default value */
143 *pValue = FALSE;
144
145 dwError = RegOpenKeyExW(hKey,
146 lpSubKey,
147 0,
148 KEY_READ,
149 &hSubKey);
150 if (dwError != ERROR_SUCCESS)
151 {
152 DPRINT("GetBooleanRegValue(): RegOpenKeyExW() has failed to open '%S' key! (Error: %lu)\n",
153 lpSubKey, dwError);
154 return dwError;
155 }
156
157 dwError = RegQueryValueExW(hSubKey,
158 lpValue,
159 0,
160 &dwType,
161 (PBYTE)&dwData,
162 &cbData);
163 if (dwError != ERROR_SUCCESS)
164 {
165 DPRINT("GetBooleanRegValue(): RegQueryValueExW() has failed to query '%S' value! (Error: %lu)\n",
166 lpValue, dwError);
167 goto Cleanup;
168 }
169 if (dwType != REG_DWORD)
170 {
171 DPRINT("GetBooleanRegValue(): The value is not of REG_DWORD type!\n");
172 goto Cleanup;
173 }
174
175 /* Return the value */
176 *pValue = (dwData == 1);
177
178Cleanup:
179 RegCloseKey(hSubKey);
180
181 return dwError;
182}
183
184BOOL
186{
187 BOOL bSuppressNewHWUI = FALSE;
188
189 /*
190 * Query the SuppressNewHWUI policy registry value. Don't cache it
191 * as we want to update our behaviour in consequence.
192 */
194 L"Software\\Policies\\Microsoft\\Windows\\DeviceInstall\\Settings",
195 L"SuppressNewHWUI",
196 &bSuppressNewHWUI);
197 if (bSuppressNewHWUI)
198 DPRINT("GetSuppressNewUIValue(): newdev.dll's wizard UI won't be shown!\n");
199
200 return bSuppressNewHWUI;
201}
202
205{
208
211
212 DPRINT("ServiceMain() called\n");
213
216 NULL);
218 {
219 DPRINT1("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
220 return;
221 }
222
224
226 0,
228 NULL,
229 0,
230 &dwThreadId);
231 if (hThread != NULL)
233
235
237 0,
239 NULL,
240 0,
241 &dwThreadId);
242 if (hThread != NULL)
244
246
248 0,
250 NULL,
251 0,
252 &dwThreadId);
253 if (hThread != NULL)
255
257
258 DPRINT("ServiceMain() done\n");
259}
260
261static DWORD
263{
264 BOOLEAN OldValue;
265 DWORD dwError;
266
267 DPRINT("UMPNPMGR: InitializePnPManager() started\n");
268
269 /* We need this privilege for using CreateProcessAsUserW */
271
273 if (hInstallEvent == NULL)
274 {
275 dwError = GetLastError();
276 DPRINT1("Could not create the Install Event! (Error %lu)\n", dwError);
277 return dwError;
278 }
279
281 TRUE,
282 FALSE,
283 L"Global\\PnP_No_Pending_Install_Events");
285 {
286 dwError = GetLastError();
287 DPRINT1("Could not create the Pending-Install Event! (Error %lu)\n", dwError);
288 return dwError;
289 }
290
291 /*
292 * Initialize the device-install event list
293 */
294
297 {
298 dwError = GetLastError();
299 DPRINT1("Could not create the List Event! (Error %lu)\n", dwError);
300 return dwError;
301 }
302
305 {
306 dwError = GetLastError();
307 DPRINT1("Could not create the List Mutex! (Error %lu)\n", dwError);
308 return dwError;
309 }
311
312 /* Query the SuppressUI registry value and cache it for our whole lifetime */
314 L"System\\CurrentControlSet\\Services\\PlugPlay\\Parameters",
315 L"SuppressUI",
318 DPRINT("UMPNPMGR: newdev.dll's wizard UI won't be shown!\n");
319
321 L"System\\CurrentControlSet\\Enum",
322 0,
324 &hEnumKey);
325 if (dwError != ERROR_SUCCESS)
326 {
327 DPRINT1("Could not open the Enum Key! (Error %lu)\n", dwError);
328 return dwError;
329 }
330
332 L"System\\CurrentControlSet\\Control\\Class",
333 0,
335 &hClassKey);
336 if (dwError != ERROR_SUCCESS)
337 {
338 DPRINT1("Could not open the Class Key! (Error %lu)\n", dwError);
339 return dwError;
340 }
341
342 DPRINT("UMPNPMGR: InitializePnPManager() done\n");
343
344 return 0;
345}
346
349 DWORD fdwReason,
351{
352 switch (fdwReason)
353 {
357 break;
358
360 break;
361 }
362
363 return TRUE;
364}
365
366/* EOF */
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
unsigned char BOOLEAN
static int argc
Definition: ServiceArgs.c:12
#define DPRINT1
Definition: precomp.h:8
static BOOL SetupIsActive(VOID)
Definition: setup.c:27
DWORD WINAPI PnpEventThread(_In_ LPVOID lpParameter)
Definition: event.c:175
HANDLE hDeviceInstallListNotEmpty
Definition: install.c:46
DWORD WINAPI DeviceInstallThread(LPVOID lpParameter)
Definition: install.c:534
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:46
#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
static const WCHAR Cleanup[]
Definition: register.c:80
#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
#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:1041
#define KEY_READ
Definition: nt_native.h:1023
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
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:812
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:997
#define REG_DWORD
Definition: sdbapi.c:596
#define DPRINT
Definition: sndvol32.h:73
DWORD dwServiceType
Definition: winsvc.h:99
DWORD dwWin32ExitCode
Definition: winsvc.h:102
DWORD dwControlsAccepted
Definition: winsvc.h:101
DWORD dwWaitHint
Definition: winsvc.h:105
DWORD dwCurrentState
Definition: winsvc.h:100
DWORD dwCheckPoint
Definition: winsvc.h:104
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:103
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
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:52
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
Definition: umpnpmgr.c:348
BOOL GetSuppressNewUIValue(VOID)
Definition: umpnpmgr.c:185
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: umpnpmgr.c:84
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:262
VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
Definition: umpnpmgr.c:204
static DWORD GetBooleanRegValue(IN HKEY hKey, IN PCWSTR lpSubKey, IN PCWSTR lpValue, OUT PBOOL pValue)
Definition: umpnpmgr.c:132
static SERVICE_STATUS ServiceStatus
Definition: umpnpmgr.c:42
HKEY hClassKey
Definition: umpnpmgr.c:45
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
BOOL * PBOOL
Definition: windef.h:161
#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:40
#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:38
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
#define SERVICE_PAUSE_PENDING
Definition: winsvc.h:26
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
#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