ReactOS 0.4.15-dev-7788-g1ad9096
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
47
48/* FUNCTIONS *****************************************************************/
49
50static VOID
52 _In_ DWORD dwState,
53 _In_ DWORD dwCheckPoint)
54{
59 ServiceStatus.dwCheckPoint = dwCheckPoint;
60
61 if (dwState == SERVICE_RUNNING)
63 else
65
66 if (dwState == SERVICE_START_PENDING ||
67 dwState == SERVICE_STOP_PENDING ||
68 dwState == SERVICE_PAUSE_PENDING ||
69 dwState == SERVICE_CONTINUE_PENDING)
71 else
73
76}
77
78
79static DWORD WINAPI
81 DWORD dwEventType,
82 LPVOID lpEventData,
83 LPVOID lpContext)
84{
85 DPRINT1("ServiceControlHandler() called\n");
86
87 switch (dwControl)
88 {
90 DPRINT1(" SERVICE_CONTROL_STOP received\n");
92 /* Stop listening to RPC Messages */
95 return ERROR_SUCCESS;
96
98 DPRINT1(" SERVICE_CONTROL_PAUSE received\n");
100 return ERROR_SUCCESS;
101
103 DPRINT1(" SERVICE_CONTROL_CONTINUE received\n");
105 return ERROR_SUCCESS;
106
108 DPRINT1(" SERVICE_CONTROL_INTERROGATE received\n");
111 return ERROR_SUCCESS;
112
114 DPRINT1(" SERVICE_CONTROL_SHUTDOWN received\n");
116 /* Stop listening to RPC Messages */
119 return ERROR_SUCCESS;
120
121 default :
122 DPRINT1(" Control %lu received\n", dwControl);
124 }
125}
126
127static DWORD
129 IN HKEY hKey,
130 IN PCWSTR lpSubKey,
131 IN PCWSTR lpValue,
133{
134 DWORD dwError, dwType, dwData;
135 DWORD cbData = sizeof(dwData);
136 HKEY hSubKey = NULL;
137
138 /* Default value */
139 *pValue = FALSE;
140
141 dwError = RegOpenKeyExW(hKey,
142 lpSubKey,
143 0,
144 KEY_READ,
145 &hSubKey);
146 if (dwError != ERROR_SUCCESS)
147 {
148 DPRINT("GetBooleanRegValue(): RegOpenKeyExW() has failed to open '%S' key! (Error: %lu)\n",
149 lpSubKey, dwError);
150 return dwError;
151 }
152
153 dwError = RegQueryValueExW(hSubKey,
154 lpValue,
155 0,
156 &dwType,
157 (PBYTE)&dwData,
158 &cbData);
159 if (dwError != ERROR_SUCCESS)
160 {
161 DPRINT("GetBooleanRegValue(): RegQueryValueExW() has failed to query '%S' value! (Error: %lu)\n",
162 lpValue, dwError);
163 goto Cleanup;
164 }
165 if (dwType != REG_DWORD)
166 {
167 DPRINT("GetBooleanRegValue(): The value is not of REG_DWORD type!\n");
168 goto Cleanup;
169 }
170
171 /* Return the value */
172 *pValue = (dwData == 1);
173
174Cleanup:
175 RegCloseKey(hSubKey);
176
177 return dwError;
178}
179
180BOOL
182{
183 BOOL bSuppressNewHWUI = FALSE;
184
185 /*
186 * Query the SuppressNewHWUI policy registry value. Don't cache it
187 * as we want to update our behaviour in consequence.
188 */
190 L"Software\\Policies\\Microsoft\\Windows\\DeviceInstall\\Settings",
191 L"SuppressNewHWUI",
192 &bSuppressNewHWUI);
193 if (bSuppressNewHWUI)
194 DPRINT("GetSuppressNewUIValue(): newdev.dll's wizard UI won't be shown!\n");
195
196 return bSuppressNewHWUI;
197}
198
201{
204
207
208 DPRINT("ServiceMain() called\n");
209
212 NULL);
214 {
215 DPRINT1("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
216 return;
217 }
218
220
222 0,
224 NULL,
225 0,
226 &dwThreadId);
227 if (hThread != NULL)
229
231
233 0,
235 NULL,
236 0,
237 &dwThreadId);
238 if (hThread != NULL)
240
242
244 0,
246 NULL,
247 0,
248 &dwThreadId);
249 if (hThread != NULL)
251
253
254 DPRINT("ServiceMain() done\n");
255}
256
257static DWORD
259{
260 BOOLEAN OldValue;
261 DWORD dwError;
262
263 DPRINT("UMPNPMGR: InitializePnPManager() started\n");
264
265 /* We need this privilege for using CreateProcessAsUserW */
267
269 if (hInstallEvent == NULL)
270 {
271 dwError = GetLastError();
272 DPRINT1("Could not create the Install Event! (Error %lu)\n", dwError);
273 return dwError;
274 }
275
277 TRUE,
278 FALSE,
279 L"Global\\PnP_No_Pending_Install_Events");
281 {
282 dwError = GetLastError();
283 DPRINT1("Could not create the Pending-Install Event! (Error %lu)\n", dwError);
284 return dwError;
285 }
286
287 /*
288 * Initialize the device-install event list
289 */
290
293 {
294 dwError = GetLastError();
295 DPRINT1("Could not create the List Event! (Error %lu)\n", dwError);
296 return dwError;
297 }
298
301 {
302 dwError = GetLastError();
303 DPRINT1("Could not create the List Mutex! (Error %lu)\n", dwError);
304 return dwError;
305 }
307
308 /* Query the SuppressUI registry value and cache it for our whole lifetime */
310 L"System\\CurrentControlSet\\Services\\PlugPlay\\Parameters",
311 L"SuppressUI",
314 DPRINT("UMPNPMGR: newdev.dll's wizard UI won't be shown!\n");
315
317 L"System\\CurrentControlSet\\Enum",
318 0,
320 &hEnumKey);
321 if (dwError != ERROR_SUCCESS)
322 {
323 DPRINT1("Could not open the Enum Key! (Error %lu)\n", dwError);
324 return dwError;
325 }
326
328 L"System\\CurrentControlSet\\Control\\Class",
329 0,
331 &hClassKey);
332 if (dwError != ERROR_SUCCESS)
333 {
334 DPRINT1("Could not open the Class Key! (Error %lu)\n", dwError);
335 return dwError;
336 }
337
338 DPRINT("UMPNPMGR: InitializePnPManager() done\n");
339
340 return 0;
341}
342
345 DWORD fdwReason,
347{
348 switch (fdwReason)
349 {
353 break;
354
356 break;
357 }
358
359 return TRUE;
360}
361
362/* 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:3362
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4132
#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
#define _In_
Definition: ms_sal.h:308
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
HANDLE hThread
Definition: wizard.c:28
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define KEY_READ
Definition: nt_native.h:1023
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#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:71
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:51
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
Definition: umpnpmgr.c:344
BOOL GetSuppressNewUIValue(VOID)
Definition: umpnpmgr.c:181
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: umpnpmgr.c:80
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: umpnpmgr.c:41
HKEY hEnumKey
Definition: umpnpmgr.c:44
BOOL g_IsUISuppressed
Definition: umpnpmgr.c:46
static DWORD InitializePnPManager(VOID)
Definition: umpnpmgr.c:258
VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
Definition: umpnpmgr.c:200
static DWORD GetBooleanRegValue(IN HKEY hKey, IN PCWSTR lpSubKey, IN PCWSTR lpValue, OUT PBOOL pValue)
Definition: umpnpmgr.c:128
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