ReactOS  0.4.14-dev-297-g23e575c
init.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS User API Server DLL
4  * FILE: win32ss/user/winsrv/init.c
5  * PURPOSE: Initialization
6  * PROGRAMMERS: Dmitry Philippov (shedon@mail.ru)
7  * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8  */
9 
10 /* INCLUDES *******************************************************************/
11 
12 #include "winsrv.h"
13 
14 #define NDEBUG
15 #include <debug.h>
16 
17 /* GLOBALS ********************************************************************/
18 
19 #define DEFAULT_AUTO_END_TASKS FALSE
20 #define DEFAULT_HUNG_APP_TIMEOUT 5000
21 #define DEFAULT_WAIT_TO_KILL_APP_TIMEOUT 20000
22 #define DEFAULT_PROCESS_TERMINATE_TIMEOUT 90000
23 
25 {
31 };
32 
33 /* FUNCTIONS ******************************************************************/
34 
35 static ULONG
38  IN ULONG DefaultValue)
39 {
40  UNICODE_STRING ValueString;
41  ULONG Length;
42  UCHAR Buffer[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 32 * sizeof(WCHAR)];
45  ULONG Value;
46 
47  /* Open the key */
48  RtlInitUnicodeString(&ValueString, ValueName);
50  &ValueString,
52  PartialInfo,
53  sizeof(Buffer),
54  &Length);
55  if (NT_SUCCESS(Status))
56  {
57  if (PartialInfo->Type == REG_SZ)
58  {
59  /* Convert to integer */
60  RtlInitUnicodeString(&ValueString, (PWCHAR)PartialInfo->Data);
61  Status = RtlUnicodeStringToInteger(&ValueString, 10, &Value);
62  }
63  else if (PartialInfo->Type == REG_DWORD)
64  {
65  /* Directly retrieve the data */
66  Value = *(PULONG)PartialInfo->Data;
68  }
69  else
70  {
71  DPRINT1("Unexpected registry type %d for setting %S\n", PartialInfo->Type, ValueName);
73  }
74  }
75 
76  if (!NT_SUCCESS(Status))
77  {
78  /* Use default value instead */
79  Value = DefaultValue;
80  }
81 
82  /* Return the value */
83  return Value;
84 }
85 
88 {
90  UNICODE_STRING RegistryString;
92  HANDLE CurrentUserKeyHandle;
94 
95  /* Initialize with defaults first */
101 
102  /* Open the per-user desktop key */
103  Status = RtlOpenCurrentUser(MAXIMUM_ALLOWED, &CurrentUserKeyHandle);
104  if (NT_SUCCESS(Status))
105  {
106  RtlInitUnicodeString(&RegistryString,
107  L"Control Panel\\Desktop");
109  &RegistryString,
111  CurrentUserKeyHandle,
112  NULL);
114  if (NT_SUCCESS(Status))
115  {
116  /* Read timeouts */
118  L"HungAppTimeout",
121  L"WaitToKillAppTimeout",
124  L"AutoEndTasks",
126  /* Done */
128  }
129 
130  /* Done */
131  NtClose(CurrentUserKeyHandle);
132  }
133 
134  /* Now open the control key */
135  RtlInitUnicodeString(&RegistryString,
136  L"\\Registry\\Machine\\System\\CurrentControlSet\\Control");
138  &RegistryString,
140  NULL, NULL);
142  if (NT_SUCCESS(Status))
143  {
144  /* Read the services timeout */
146  L"WaitToKillServiceTimeout",
148 
149  /*
150  * Retrieve the process terminate timeout.
151  * See ftp://ftp.microsoft.com/MISC1/BUSSYS/WINNT/KB/Q234/6/06.TXT
152  * and https://web.archive.org/web/20050216235758/http://support.microsoft.com/kb/234606/EN-US/
153  * for more details.
154  *
155  * NOTE: Unused at the moment...
156  */
158  L"ProcessTerminateTimeout",
162 
163  /* Done */
165  }
166 }
167 
168 /* ENTRY-POINT ****************************************************************/
169 
170 BOOL
171 WINAPI
172 DllMain(IN HINSTANCE hInstanceDll,
173  IN DWORD dwReason,
174  IN LPVOID lpReserved)
175 {
176  UNREFERENCED_PARAMETER(hInstanceDll);
178  UNREFERENCED_PARAMETER(lpReserved);
179 
180  return TRUE;
181 }
182 
183 /* EOF */
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define DEFAULT_AUTO_END_TASKS
Definition: init.c:19
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
ULONG HungAppTimeout
Definition: winsrv.h:49
#define KEY_READ
Definition: nt_native.h:1023
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTSTATUS
Definition: precomp.h:26
#define DEFAULT_PROCESS_TERMINATE_TIMEOUT
Definition: init.c:22
uint16_t * PWCHAR
Definition: typedefs.h:54
#define FASTCALL
Definition: nt_native.h:50
DWORD dwReason
Definition: misc.cpp:154
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
ULONG WaitToKillServiceTimeout
Definition: winsrv.h:51
unsigned int BOOL
Definition: ntddk_ex.h:94
#define DEFAULT_HUNG_APP_TIMEOUT
Definition: init.c:20
ULONG ProcessTerminateTimeout
Definition: winsrv.h:52
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
__wchar_t WCHAR
Definition: xmlstorage.h:180
VOID FASTCALL GetTimeouts(IN PSHUTDOWN_SETTINGS ShutdownSettings)
Definition: init.c:87
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
#define DEFAULT_WAIT_TO_KILL_APP_TIMEOUT
Definition: init.c:21
ULONG WaitToKillAppTimeout
Definition: winsrv.h:50
NTSYSAPI NTSTATUS NTAPI RtlOpenCurrentUser(_In_ ACCESS_MASK DesiredAccess, _Out_ PHANDLE KeyHandle)
Status
Definition: gdiplustypes.h:24
SHUTDOWN_SETTINGS ShutdownSettings
Definition: init.c:24
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
unsigned int * PULONG
Definition: retypes.h:1
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
static ULONG GetRegIntFromID(IN HANDLE KeyHandle, IN PWCHAR ValueName, IN ULONG DefaultValue)
Definition: init.c:36
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToInteger(PUNICODE_STRING String, ULONG Base, PULONG Value)
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define REG_DWORD
Definition: sdbapi.c:596
BOOLEAN WINAPI DllMain(HINSTANCE Instance, DWORD Reason, LPVOID Reserved)
Definition: init.c:14
#define REG_SZ
Definition: layer.c:22