ReactOS 0.4.16-dev-1946-g52006dd
umpnpmgr.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for umpnpmgr.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static VOID UpdateServiceStatus (_In_ DWORD dwState, _In_ DWORD dwCheckPoint)
 
static DWORD WINAPI ServiceControlHandler (DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
 
static DWORD GetBooleanRegValue (IN HKEY hKey, IN PCWSTR lpSubKey, IN PCWSTR lpValue, OUT PBOOL pValue)
 
BOOL GetSuppressNewUIValue (VOID)
 
BOOL RunningOnLiveMedium (VOID)
 
VOID WINAPI ServiceMain (DWORD argc, LPTSTR *argv)
 
static DWORD InitializePnPManager (VOID)
 
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 

Variables

static WCHAR ServiceName [] = L"PlugPlay"
 
static SERVICE_STATUS_HANDLE ServiceStatusHandle
 
static SERVICE_STATUS ServiceStatus
 
HKEY hEnumKey = NULL
 
HKEY hClassKey = NULL
 
BOOL g_IsUISuppressed = FALSE
 
BOOL g_ShuttingDown = FALSE
 
BOOL g_IsLiveMedium = FALSE
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 33 of file umpnpmgr.c.

Function Documentation

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hinstDLL,
DWORD  fdwReason,
LPVOID  lpvReserved 
)

Definition at line 406 of file umpnpmgr.c.

409{
410 switch (fdwReason)
411 {
415 break;
416
418 break;
419 }
420
421 return TRUE;
422}
static DWORD const fdwReason
#define TRUE
Definition: types.h:120
#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
static DWORD InitializePnPManager(VOID)
Definition: umpnpmgr.c:320

◆ GetBooleanRegValue()

static DWORD GetBooleanRegValue ( IN HKEY  hKey,
IN PCWSTR  lpSubKey,
IN PCWSTR  lpValue,
OUT PBOOL  pValue 
)
static

Definition at line 133 of file umpnpmgr.c.

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}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#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
static const WCHAR Cleanup[]
Definition: register.c:80
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
PWCHAR pValue
static HANDLE ULONG_PTR dwData
Definition: file.c:35
#define KEY_READ
Definition: nt_native.h:1026
BYTE * PBYTE
Definition: pedump.c:66
_In_opt_ _In_opt_ _In_ _In_ DWORD cbData
Definition: shlwapi.h:761
#define REG_DWORD
Definition: sdbapi.c:615
#define DPRINT
Definition: sndvol32.h:73

Referenced by GetSuppressNewUIValue(), and InitializePnPManager().

◆ GetSuppressNewUIValue()

BOOL GetSuppressNewUIValue ( VOID  )

Definition at line 186 of file umpnpmgr.c.

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}
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
static DWORD GetBooleanRegValue(IN HKEY hKey, IN PCWSTR lpSubKey, IN PCWSTR lpValue, OUT PBOOL pValue)
Definition: umpnpmgr.c:133
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by IsUISuppressionAllowed().

◆ InitializePnPManager()

static DWORD InitializePnPManager ( VOID  )
static

Definition at line 320 of file umpnpmgr.c.

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}
unsigned char BOOLEAN
#define DPRINT1
Definition: precomp.h:8
static BOOL SetupIsActive(VOID)
Definition: setup.c:27
HANDLE hDeviceInstallListNotEmpty
Definition: install.c:46
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
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE
Definition: security.c:657
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
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
HKEY hEnumKey
Definition: umpnpmgr.c:44
BOOL g_IsUISuppressed
Definition: umpnpmgr.c:46
HKEY hClassKey
Definition: umpnpmgr.c:45
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by DllMain().

◆ RunningOnLiveMedium()

BOOL RunningOnLiveMedium ( VOID  )

Definition at line 205 of file umpnpmgr.c.

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}
#define wcschr
Definition: compat.h:17
#define MAX_PATH
Definition: compat.h:34
#define REG_SZ
Definition: layer.c:22
static char * NextOption(const char *const ostr)
Definition: getopt.c:31
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define KEY_QUERY_VALUE
Definition: nt_native.h:1019
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
uint16_t * PWSTR
Definition: typedefs.h:56
unsigned char * LPBYTE
Definition: typedefs.h:53
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3540
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by ServiceMain().

◆ ServiceControlHandler()

static DWORD WINAPI ServiceControlHandler ( DWORD  dwControl,
DWORD  dwEventType,
LPVOID  lpEventData,
LPVOID  lpContext 
)
static

Definition at line 85 of file umpnpmgr.c.

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}
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
RPC_STATUS WINAPI RpcMgmtStopServerListening(RPC_BINDING_HANDLE Binding)
Definition: rpc_server.c:1596
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:1016
static VOID UpdateServiceStatus(_In_ DWORD dwState, _In_ DWORD dwCheckPoint)
Definition: umpnpmgr.c:53
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: umpnpmgr.c:41
static SERVICE_STATUS ServiceStatus
Definition: umpnpmgr.c:42
#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_RUNNING
Definition: winsvc.h:24
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:44
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:42
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:43
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:45

Referenced by ServiceMain().

◆ ServiceMain()

VOID WINAPI ServiceMain ( DWORD  argc,
LPTSTR argv 
)

Definition at line 260 of file umpnpmgr.c.

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}
static int argc
Definition: ServiceArgs.c:12
DWORD WINAPI PnpEventThread(_In_ LPVOID lpParameter)
Definition: event.c:238
DWORD WINAPI DeviceInstallThread(LPVOID lpParameter)
Definition: install.c:526
DWORD WINAPI RpcServerThread(LPVOID lpParameter)
Definition: rpcserver.c:48
#define CloseHandle
Definition: compat.h:739
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
DWORD dwThreadId
Definition: fdebug.c:31
#define argv
Definition: mplay32.c:18
HANDLE hThread
Definition: wizard.c:28
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:831
static WCHAR ServiceName[]
Definition: umpnpmgr.c:39
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: umpnpmgr.c:85
BOOL RunningOnLiveMedium(VOID)
Definition: umpnpmgr.c:205
BOOL g_IsLiveMedium
Definition: umpnpmgr.c:48
#define SERVICE_START_PENDING
Definition: winsvc.h:22

◆ UpdateServiceStatus()

static VOID UpdateServiceStatus ( _In_ DWORD  dwState,
_In_ DWORD  dwCheckPoint 
)
static

Definition at line 53 of file umpnpmgr.c.

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}
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
BOOL g_ShuttingDown
Definition: umpnpmgr.c:47
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
#define SERVICE_PAUSE_PENDING
Definition: winsvc.h:26
#define SERVICE_CONTINUE_PENDING
Definition: winsvc.h:25
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:962

Referenced by ServiceControlHandler(), and ServiceMain().

Variable Documentation

◆ g_IsLiveMedium

BOOL g_IsLiveMedium = FALSE

Definition at line 48 of file umpnpmgr.c.

Referenced by PNP_ReportLogOn(), and ServiceMain().

◆ g_IsUISuppressed

BOOL g_IsUISuppressed = FALSE

Definition at line 46 of file umpnpmgr.c.

Referenced by InitializePnPManager(), and IsUISuppressionAllowed().

◆ g_ShuttingDown

BOOL g_ShuttingDown = FALSE

Definition at line 47 of file umpnpmgr.c.

Referenced by PNP_GetGlobalState(), and UpdateServiceStatus().

◆ hClassKey

◆ hEnumKey

◆ ServiceName

WCHAR ServiceName[] = L"PlugPlay"
static

Definition at line 39 of file umpnpmgr.c.

Referenced by ServiceMain().

◆ ServiceStatus

SERVICE_STATUS ServiceStatus
static

Definition at line 42 of file umpnpmgr.c.

Referenced by ServiceControlHandler(), and UpdateServiceStatus().

◆ ServiceStatusHandle

SERVICE_STATUS_HANDLE ServiceStatusHandle
static

Definition at line 41 of file umpnpmgr.c.

Referenced by ServiceControlHandler(), ServiceMain(), and UpdateServiceStatus().