ReactOS  0.4.14-dev-358-gbef841c
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 
19 INIT_FUNCTION
20 LANGID
21 NTAPI
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 
70 INIT_FUNCTION
72 NTAPI
74  IN HCELL_INDEX ParentCell,
75  IN LPWSTR Path)
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 */
83  ASSERT(SystemHive->ReleaseCellRoutine == NULL);
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 
101 INIT_FUNCTION
102 VOID
103 NTAPI
105  IN PCM_SYSTEM_CONTROL_VECTOR ControlVector)
106 {
109  HCELL_INDEX RootCell, BaseCell, KeyCell, ValueCell;
114  BOOLEAN Auto, IsSmallKey;
115  PVOID Buffer;
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 */
127  HINIT_FLAT,
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 */
142  ASSERT(SystemHive->ReleaseCellRoutine == NULL);
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");
154  Node = (PCM_KEY_NODE)HvGetCell(SystemHive, BaseCell);
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);
170  Node = (PCM_KEY_NODE)HvGetCell(SystemHive, KeyCell);
171  ValueCell = CmpFindValueByName(SystemHive, Node, &KeyName);
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 */
193  if (DataSize < Length) Length = DataSize;
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 ?
212  (Length <= CM_KEY_VALUE_SMALL) : TRUE));
213 
214  /* Copy the data in the buffer */
215  RtlCopyMemory(ControlVector->Buffer, Buffer, Length);
216  }
217 
218  /* Check if we should return the data type */
219  if (ControlVector->Type)
220  {
221  /* Return the type that we read */
222  *ControlVector->Type = ValueData->Type;
223  }
224  }
225  }
226 
227  /* Return the size that we read */
228  if (ControlVector->BufferLength) *ControlVector->BufferLength = Length;
229 
230  /* Go to the next entry */
231  ControlVector++;
232  }
233 
234  /* Check if the ID is in the registry */
236  {
237  /* Read it */
241  }
242  else
243  {
244  /* Use EN_US by default */
245  PsDefaultSystemLocaleId = 0x409;
246  }
247 
248  /* Check if the ID Is in the registry */
250  {
251  /* Read it */
254  }
255  else
256  {
257  /* Otherwise, use the default */
259  }
260 
261  /* Set the defaults for the Thread UI */
264 }
265 
266 NTSTATUS
267 NTAPI
269 {
270  DPRINT1("CmpSaveBootControlSet(%lu)\n", ControlSet);
271  return STATUS_SUCCESS;
272 }
LANGID PsDefaultUILanguageId
Definition: locale.c:24
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
#define IN
Definition: typedefs.h:38
ULONG CmDefaultLanguageIdType
Definition: cmdata.c:24
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
WCHAR CmInstallUILanguageId[12]
Definition: cmdata.c:26
#define HIVE_VOLATILE
Definition: hivedata.h:23
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)
Definition: hiveinit.c:522
LONG NTSTATUS
Definition: precomp.h:26
#define HCELL_NIL
Definition: hivedata.h:85
LCID PsDefaultSystemLocaleId
Definition: locale.c:20
DWORD LCID
Definition: nls.h:13
WORD LANGID
Definition: typedefs.h:79
LCID PsDefaultThreadLocaleId
Definition: locale.c:25
LANGID PsInstallUILanguageId
Definition: locale.c:21
INIT_FUNCTION 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:268
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
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
struct _HBASE_BLOCK * PHBASE_BLOCK
union node Node
Definition: types.h:1255
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
VOID NTAPI CmpInitHiveViewList(IN PCMHIVE Hive)
Definition: cmmapvw.c:21
static BOOLEAN CmpIsKeyValueSmall(OUT PULONG RealLength, IN ULONG Length)
Definition: cmlib.h:323
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
struct _CM_KEY_NODE * PCM_KEY_NODE
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
#define HINIT_FLAT
Definition: hivedata.h:17
HCELL_INDEX NTAPI CmpFindValueByName(IN PHHIVE Hive, IN PCM_KEY_NODE KeyNode, IN PUNICODE_STRING Name)
Definition: cmvalue.c:99
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG HCELL_INDEX
Definition: hivedata.h:80
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:311
BOOLEAN NTAPI CmpGetNextName(IN OUT PUNICODE_STRING RemainingName, OUT PUNICODE_STRING NextName, OUT PBOOLEAN LastName)
Definition: cmparse.c:21
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
INIT_FUNCTION HCELL_INDEX NTAPI CmpFindControlSet(IN PHHIVE SystemHive, IN HCELL_INDEX RootCell, IN PUNICODE_STRING SelectKeyName, OUT PBOOLEAN AutoSelect)
Definition: cmboot.c:25
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CM_KEY_VALUE_SMALL
Definition: cm.h:71
static const WCHAR L[]
Definition: oid.c:1250
#define LANGIDFROMLCID(l)
Definition: nls.h:18
INIT_FUNCTION LANGID NTAPI CmpConvertLangId(IN LPWSTR Name, IN ULONG NameLength)
Definition: cmcontrl.c:22
Status
Definition: gdiplustypes.h:24
ULONG CmDefaultLanguageIdLength
Definition: cmdata.c:23
VOID NTAPI CmpInitSecurityCache(IN PCMHIVE Hive)
Definition: cmsecach.c:21
struct _HHIVE * PHHIVE
ULONG CmInstallUILanguageIdLength
Definition: cmdata.c:27
PRTL_UNICODE_STRING_BUFFER Path
WCHAR CmDefaultLanguageId[12]
Definition: cmdata.c:22
#define HFILE_TYPE_PRIMARY
Definition: hivedata.h:33
unsigned short USHORT
Definition: pedump.c:61
INIT_FUNCTION VOID NTAPI CmGetSystemControlValues(IN PVOID SystemHiveData, IN PCM_SYSTEM_CONTROL_VECTOR ControlVector)
Definition: cmcontrl.c:104
struct _CM_KEY_VALUE * PCM_KEY_VALUE
static CMHIVE SystemHive
Definition: registry.c:57
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2938
HCELL_INDEX NTAPI CmpFindSubKeyByName(IN PHHIVE Hive, IN PCM_KEY_NODE Parent, IN PCUNICODE_STRING SearchName)
Definition: cmindex.c:683
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751
CMHIVE CmControlHive
Definition: cmdata.c:34
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:107
Definition: cm.h:391
Definition: dlist.c:348
ULONG CmInstallUILanguageIdType
Definition: cmdata.c:28
#define REG_SZ
Definition: layer.c:22