ReactOS 0.4.16-dev-340-g0540c21
cmcontrl.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/config/cmcontrl.c
5 * PURPOSE: Configuration Manager - Control Set Management
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include "ntoskrnl.h"
12#define NDEBUG
13#include "debug.h"
14
15/* GLOBALS *******************************************************************/
16
17/* FUNCTIONS *****************************************************************/
18
19CODE_SEG("INIT")
23 IN ULONG NameLength)
24{
25 ULONG i;
26 WCHAR p;
27 LANGID LangId = 0;
28 ULONG IdCode;
29
30 /* Convert the length in chars and loop */
31 NameLength = NameLength / sizeof(WCHAR);
32 for (i = 0; i < NameLength; i++)
33 {
34 /* Get the character */
35 p = Name[i];
36
37 /* Handle each case */
38 if ((p >= L'0') && (p <= L'9'))
39 {
40 /* Handle digits*/
41 IdCode = p - L'0';
42 }
43 else if ((p >= L'A') && (p <= L'F'))
44 {
45 /* Handle upper-case letters */
46 IdCode = p - L'A' + 10;
47 }
48 else if ((p >= L'a') && (p <= L'f'))
49 {
50 /* Handle lower-case letters */
51 IdCode = p - L'a' + 10;
52 }
53 else
54 {
55 /* Unhandled case, return what we have till now */
56 break;
57 }
58
59 /* If the ID Code is >= 16, then we're done */
60 if (IdCode >= 16) break;
61
62 /* Build the Language ID */
63 LangId = (LangId << 4) | (LANGID)IdCode;
64 }
65
66 /* Return the Language ID */
67 return LangId;
68}
69
70CODE_SEG("INIT")
74 IN HCELL_INDEX ParentCell,
76{
77 UNICODE_STRING UnicodePath, NextName;
78 BOOLEAN LastName;
79 HCELL_INDEX CurrentCell = ParentCell;
81
82 /* We shouldn't have a release routine at this point */
84
85 /* Initialize the Unicode path and start looping */
86 RtlInitUnicodeString(&UnicodePath, Path);
87 while (TRUE)
88 {
89 /* Get the next name */
90 CmpGetNextName(&UnicodePath, &NextName, &LastName);
91 if (!NextName.Length) return CurrentCell;
92
93 /* Get the subkey */
94 Node = (PCM_KEY_NODE)HvGetCell(SystemHive, CurrentCell);
95 if (!Node) return HCELL_NIL;
96 CurrentCell = CmpFindSubKeyByName(SystemHive, Node, &NextName);
97 if (CurrentCell == HCELL_NIL) return CurrentCell;
98 }
99}
100
101CODE_SEG("INIT")
102VOID
103NTAPI
105 IN PCM_SYSTEM_CONTROL_VECTOR ControlVector)
106{
109 HCELL_INDEX RootCell, BaseCell, KeyCell, ValueCell;
114 BOOLEAN Auto, IsSmallKey;
116
117 /* LUDDDIIIICRROOOUUSSSS KI^H^H HACKKKK */
118 if (!SystemHiveData) return;
119
120 /* Initialize the Hive View List and the security cache */
124
125 /* Initialize the Hive */
130 SystemHiveData,
131 NULL,
132 NULL,
133 NULL,
134 NULL,
135 NULL,
136 NULL,
137 1,
138 NULL);
139 if (!NT_SUCCESS(Status)) KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO, 1, 1, 0, 0);
140
141 /* Sanity check, flat hives don't have release routines */
143
144 /* Set the Root Cell */
145 RootCell = ((PHBASE_BLOCK)SystemHiveData)->RootCell;
146
147 /* Find the current control set */
148 RtlInitUnicodeString(&KeyName, L"current");
149 BaseCell = CmpFindControlSet(SystemHive, RootCell, &KeyName, &Auto);
150 if (BaseCell == HCELL_NIL) KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO, 1, 2, 0, 0);
151
152 /* Find the control subkey */
153 RtlInitUnicodeString(&KeyName, L"control");
156 if (BaseCell == HCELL_NIL) KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO,1 , 3, 0, 0);
157
158 /* Loop each key */
159 while (ControlVector->KeyPath)
160 {
161 /* Assume failure */
162 Length = -1;
163
164 /* Get the cell for this key */
165 KeyCell = CmpWalkPath(SystemHive, BaseCell, ControlVector->KeyPath);
166 if (KeyCell != HCELL_NIL)
167 {
168 /* Now get the cell for the value */
169 RtlInitUnicodeString(&KeyName, ControlVector->ValueName);
172 if (ValueCell != HCELL_NIL)
173 {
174 /* Check if there's any data */
175 if (!ControlVector->BufferLength)
176 {
177 /* No, the buffer will only be large enough for a ULONG */
178 DataSize = sizeof(ULONG);
179 }
180 else
181 {
182 /* Yes, save the data size */
183 DataSize = *ControlVector->BufferLength;
184 }
185
186 /* Get the actual data */
188
189 /* Check if this is a small key */
190 IsSmallKey = CmpIsKeyValueSmall(&Length, ValueData->DataLength);
191
192 /* If the length is bigger then our buffer, normalize it */
194
195 /* Make sure we have some data */
196 if (Length > 0)
197 {
198 /* Check if this was a small key */
199 if (IsSmallKey)
200 {
201 /* The buffer is directly safe to read */
202 Buffer = (PVOID)(&(ValueData->Data));
203 }
204 else
205 {
206 /* Use the longer path */
208 }
209
210 /* Sanity check if this is a small key */
211 ASSERT(IsSmallKey ? (Length <= CM_KEY_VALUE_SMALL) : TRUE);
212
213 /* Copy the data in the buffer */
214 RtlCopyMemory(ControlVector->Buffer, Buffer, Length);
215 }
216
217 /* Check if we should return the data type */
218 if (ControlVector->Type)
219 {
220 /* Return the type that we read */
221 *ControlVector->Type = ValueData->Type;
222 }
223 }
224 }
225
226 /* Return the size that we read */
227 if (ControlVector->BufferLength) *ControlVector->BufferLength = Length;
228
229 /* Go to the next entry */
230 ControlVector++;
231 }
232
233 /* Check if the ID is in the registry */
235 {
236 /* Read it */
240 }
241 else
242 {
243 /* Use EN_US by default */
245 }
246
247 /* Check if the ID Is in the registry */
249 {
250 /* Read it */
253 }
254 else
255 {
256 /* Otherwise, use the default */
258 }
259
260 /* Set the defaults for the Thread UI */
263}
264
266NTAPI
268{
269 DPRINT1("CmpSaveBootControlSet(%lu)\n", ControlSet);
270 return STATUS_SUCCESS;
271}
#define CODE_SEG(...)
unsigned char BOOLEAN
PRTL_UNICODE_STRING_BUFFER Path
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
PHHIVE SystemHive
Definition: registry.c:33
Definition: bufpool.h:45
HCELL_INDEX NTAPI CmpFindControlSet(_In_ PHHIVE SystemHive, _In_ HCELL_INDEX RootCell, _In_ PCUNICODE_STRING SelectKeyName, _Out_ PBOOLEAN AutoSelect)
Finds the corresponding "HKLM\SYSTEM\ControlSetXXX" system control set registry key,...
Definition: cmboot.c:84
LANGID NTAPI CmpConvertLangId(IN LPWSTR Name, IN ULONG NameLength)
Definition: cmcontrl.c:22
VOID NTAPI CmGetSystemControlValues(IN PVOID SystemHiveData, IN PCM_SYSTEM_CONTROL_VECTOR ControlVector)
Definition: cmcontrl.c:104
HCELL_INDEX NTAPI CmpWalkPath(IN PHHIVE SystemHive, IN HCELL_INDEX ParentCell, IN LPWSTR Path)
Definition: cmcontrl.c:73
NTSTATUS NTAPI CmpSaveBootControlSet(IN USHORT ControlSet)
Definition: cmcontrl.c:267
WCHAR CmInstallUILanguageId[12]
Definition: cmdata.c:26
ULONG CmDefaultLanguageIdLength
Definition: cmdata.c:23
ULONG CmDefaultLanguageIdType
Definition: cmdata.c:24
WCHAR CmDefaultLanguageId[12]
Definition: cmdata.c:22
ULONG CmInstallUILanguageIdLength
Definition: cmdata.c:27
CMHIVE CmControlHive
Definition: cmdata.c:34
ULONG CmInstallUILanguageIdType
Definition: cmdata.c:28
struct _CM_KEY_NODE * PCM_KEY_NODE
struct _CM_KEY_VALUE * PCM_KEY_VALUE
#define CM_KEY_VALUE_SMALL
Definition: cmdata.h:49
HCELL_INDEX NTAPI CmpFindSubKeyByName(IN PHHIVE Hive, IN PCM_KEY_NODE Parent, IN PCUNICODE_STRING SearchName)
Definition: cmindex.c:683
NTSTATUS CMAPI HvInitialize(PHHIVE RegistryHive, ULONG OperationType, ULONG HiveFlags, ULONG FileType, PVOID HiveData OPTIONAL, PALLOCATE_ROUTINE Allocate, PFREE_ROUTINE Free, PFILE_SET_SIZE_ROUTINE FileSetSize, PFILE_WRITE_ROUTINE FileWrite, PFILE_READ_ROUTINE FileRead, PFILE_FLUSH_ROUTINE FileFlush, ULONG Cluster OPTIONAL, PCUNICODE_STRING FileName OPTIONAL)
HCELL_INDEX NTAPI CmpFindValueByName(IN PHHIVE Hive, IN PCM_KEY_NODE KeyNode, IN PCUNICODE_STRING Name)
Definition: cmvalue.c:99
static BOOLEAN CmpIsKeyValueSmall(OUT PULONG RealLength, IN ULONG Length)
Definition: cmlib.h:395
#define HvGetCell(Hive, Cell)
Definition: cmlib.h:457
VOID NTAPI CmpInitHiveViewList(IN PCMHIVE Hive)
Definition: cmmapvw.c:21
BOOLEAN NTAPI CmpGetNextName(IN OUT PUNICODE_STRING RemainingName, OUT PUNICODE_STRING NextName, OUT PBOOLEAN LastName)
Definition: cmparse.c:21
VOID NTAPI CmpInitSecurityCache(IN PCMHIVE Hive)
Definition: cmsecach.c:21
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
union node Node
Definition: types.h:1255
Status
Definition: gdiplustypes.h:25
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define HINIT_FLAT
Definition: hivedata.h:17
#define HIVE_VOLATILE
Definition: hivedata.h:23
#define HFILE_TYPE_PRIMARY
Definition: hivedata.h:33
#define HCELL_NIL
Definition: hivedata.h:110
ULONG HCELL_INDEX
Definition: hivedata.h:105
struct _HBASE_BLOCK * PHBASE_BLOCK
struct _HHIVE * PHHIVE
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:312
#define REG_SZ
Definition: layer.c:22
USHORT LANGID
Definition: mui.h:9
#define ASSERT(a)
Definition: mode.c:44
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
LANGID PsDefaultUILanguageId
Definition: locale.c:25
LANGID PsInstallUILanguageId
Definition: locale.c:21
LCID PsDefaultSystemLocaleId
Definition: locale.c:20
LCID PsDefaultThreadLocaleId
Definition: locale.c:24
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
#define LANGIDFROMLCID(l)
Definition: nls.h:18
DWORD LCID
Definition: nls.h:13
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: cmlib.h:316
PRELEASE_CELL_ROUTINE ReleaseCellRoutine
Definition: hivedata.h:317
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
Definition: dlist.c:348
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184