Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencmcontrl.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Kernel 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: ntoskrnl/config/cmcontrl.c 00005 * PURPOSE: Configuration Manager - Control Set Management 00006 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) 00007 */ 00008 00009 /* INCLUDES ******************************************************************/ 00010 00011 #include "ntoskrnl.h" 00012 #define NDEBUG 00013 #include "debug.h" 00014 00015 /* GLOBALS *******************************************************************/ 00016 00017 /* FUNCTIONS *****************************************************************/ 00018 00019 LANGID 00020 NTAPI 00021 INIT_FUNCTION 00022 CmpConvertLangId(IN LPWSTR Name, 00023 IN ULONG NameLength) 00024 { 00025 ULONG i; 00026 WCHAR p; 00027 LANGID LangId = 0; 00028 ULONG IdCode; 00029 00030 /* Convert the length in chars and loop */ 00031 NameLength = NameLength / sizeof(WCHAR); 00032 for (i = 0; i < NameLength; i++) 00033 { 00034 /* Get the character */ 00035 p = Name[i]; 00036 00037 /* Handle each case */ 00038 if ((p >= L'0') && (p <= L'9')) 00039 { 00040 /* Handle digits*/ 00041 IdCode = p - L'0'; 00042 } 00043 else if ((p >= L'A') && (p <= L'F')) 00044 { 00045 /* Handle upper-case letters */ 00046 IdCode = p - L'A' + 10; 00047 } 00048 else if ((p >= L'a') && (p <= L'f')) 00049 { 00050 /* Handle lower-case letters */ 00051 IdCode = p - L'a' + 10; 00052 } 00053 else 00054 { 00055 /* Unhandled case, return what we have till now */ 00056 break; 00057 } 00058 00059 /* If the ID Code is >= 16, then we're done */ 00060 if (IdCode >= 16) break; 00061 00062 /* Build the Language ID */ 00063 LangId = (LangId << 4) | (LANGID)IdCode; 00064 } 00065 00066 /* Return the Language ID */ 00067 return LangId; 00068 } 00069 00070 HCELL_INDEX 00071 NTAPI 00072 INIT_FUNCTION 00073 CmpWalkPath(IN PHHIVE SystemHive, 00074 IN HCELL_INDEX ParentCell, 00075 IN LPWSTR Path) 00076 { 00077 UNICODE_STRING UnicodePath, NextName; 00078 BOOLEAN LastName; 00079 HCELL_INDEX CurrentCell = ParentCell; 00080 PCM_KEY_NODE Node; 00081 00082 /* We shouldn't have a release routine at this point */ 00083 ASSERT(SystemHive->ReleaseCellRoutine == NULL); 00084 00085 /* Initialize the Unicode path and start looping */ 00086 RtlInitUnicodeString(&UnicodePath, Path); 00087 while (TRUE) 00088 { 00089 /* Get the next name */ 00090 CmpGetNextName(&UnicodePath, &NextName, &LastName); 00091 if (!NextName.Length) return CurrentCell; 00092 00093 /* Get the subkey */ 00094 Node = (PCM_KEY_NODE)HvGetCell(SystemHive, CurrentCell); 00095 if (!Node) return HCELL_NIL; 00096 CurrentCell = CmpFindSubKeyByName(SystemHive, Node, &NextName); 00097 if (CurrentCell == HCELL_NIL) return CurrentCell; 00098 } 00099 } 00100 00101 VOID 00102 NTAPI 00103 INIT_FUNCTION 00104 CmGetSystemControlValues(IN PVOID SystemHiveData, 00105 IN PCM_SYSTEM_CONTROL_VECTOR ControlVector) 00106 { 00107 PHHIVE SystemHive = (PHHIVE)&CmControlHive; 00108 NTSTATUS Status; 00109 HCELL_INDEX RootCell, BaseCell, KeyCell, ValueCell; 00110 ULONG Length, DataSize; 00111 PCM_KEY_NODE Node; 00112 PCM_KEY_VALUE ValueData; 00113 UNICODE_STRING KeyName; 00114 BOOLEAN Auto, IsSmallKey; 00115 PVOID Buffer; 00116 00117 /* LUDDDIIIICRROOOUUSSSS KI^H^H HACKKKK */ 00118 if (!SystemHiveData) return; 00119 00120 /* Initialize the Hive View List and the security cache */ 00121 RtlZeroMemory(SystemHive, sizeof(*SystemHive)); 00122 CmpInitHiveViewList((PCMHIVE)SystemHive); 00123 CmpInitSecurityCache((PCMHIVE)SystemHive); 00124 00125 /* Initialize the Hive */ 00126 Status = HvInitialize(SystemHive, 00127 HINIT_FLAT, 00128 HIVE_VOLATILE, 00129 HFILE_TYPE_PRIMARY, 00130 SystemHiveData, 00131 NULL, 00132 NULL, 00133 NULL, 00134 NULL, 00135 NULL, 00136 NULL, 00137 1, 00138 NULL); 00139 if (!NT_SUCCESS(Status)) KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO, 1, 1, 0, 0); 00140 00141 /* Sanity check, flat hives don't have release routines */ 00142 ASSERT(SystemHive->ReleaseCellRoutine == NULL); 00143 00144 /* Set the Root Cell */ 00145 RootCell = ((PHBASE_BLOCK)SystemHiveData)->RootCell; 00146 00147 /* Find the current control set */ 00148 RtlInitUnicodeString(&KeyName, L"current"); 00149 BaseCell = CmpFindControlSet(SystemHive, RootCell, &KeyName, &Auto); 00150 if (BaseCell == HCELL_NIL) KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO, 1, 2, 0, 0); 00151 00152 /* Find the control subkey */ 00153 RtlInitUnicodeString(&KeyName, L"control"); 00154 Node = (PCM_KEY_NODE)HvGetCell(SystemHive, BaseCell); 00155 BaseCell = CmpFindSubKeyByName(SystemHive, Node, &KeyName); 00156 if (BaseCell == HCELL_NIL) KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO,1 , 3, 0, 0); 00157 00158 /* Loop each key */ 00159 while (ControlVector->KeyPath) 00160 { 00161 /* Assume failure */ 00162 Length = -1; 00163 00164 /* Get the cell for this key */ 00165 KeyCell = CmpWalkPath(SystemHive, BaseCell, ControlVector->KeyPath); 00166 if (KeyCell != HCELL_NIL) 00167 { 00168 /* Now get the cell for the value */ 00169 RtlInitUnicodeString(&KeyName, ControlVector->ValueName); 00170 Node = (PCM_KEY_NODE)HvGetCell(SystemHive, KeyCell); 00171 ValueCell = CmpFindValueByName(SystemHive, Node, &KeyName); 00172 if (ValueCell != HCELL_NIL) 00173 { 00174 /* Check if there's any data */ 00175 if (!ControlVector->BufferLength) 00176 { 00177 /* No, the buffer will only be large enough for a ULONG */ 00178 DataSize = sizeof(ULONG); 00179 } 00180 else 00181 { 00182 /* Yes, save the data size */ 00183 DataSize = *ControlVector->BufferLength; 00184 } 00185 00186 /* Get the actual data */ 00187 ValueData = (PCM_KEY_VALUE)HvGetCell(SystemHive, ValueCell); 00188 00189 /* Check if this is a small key */ 00190 IsSmallKey = CmpIsKeyValueSmall(&Length, ValueData->DataLength); 00191 00192 /* If the length is bigger then our buffer, normalize it */ 00193 if (DataSize < Length) Length = DataSize; 00194 00195 /* Make sure we have some data */ 00196 if (Length > 0) 00197 { 00198 /* Check if this was a small key */ 00199 if (IsSmallKey) 00200 { 00201 /* The buffer is directly safe to read */ 00202 Buffer = (PVOID)(&(ValueData->Data)); 00203 } 00204 else 00205 { 00206 /* Use the longer path */ 00207 Buffer = (PVOID)HvGetCell(SystemHive, ValueData->Data); 00208 } 00209 00210 /* Sanity check if this is a small key */ 00211 ASSERT((IsSmallKey ? 00212 (Length <= CM_KEY_VALUE_SMALL) : TRUE)); 00213 00214 /* Copy the data in the buffer */ 00215 RtlCopyMemory(ControlVector->Buffer, Buffer, Length); 00216 } 00217 00218 /* Check if we should return the data type */ 00219 if (ControlVector->Type) 00220 { 00221 /* Return the type that we read */ 00222 *ControlVector->Type = ValueData->Type; 00223 } 00224 } 00225 } 00226 00227 /* Return the size that we read */ 00228 if (ControlVector->BufferLength) *ControlVector->BufferLength = Length; 00229 00230 /* Go to the next entry */ 00231 ControlVector++; 00232 } 00233 00234 /* Check if the ID is in the registry */ 00235 if (CmDefaultLanguageIdType == REG_SZ) 00236 { 00237 /* Read it */ 00238 PsDefaultSystemLocaleId = 00239 (LCID)CmpConvertLangId(CmDefaultLanguageId, 00240 CmDefaultLanguageIdLength); 00241 } 00242 else 00243 { 00244 /* Use EN_US by default */ 00245 PsDefaultSystemLocaleId = 0x409; 00246 } 00247 00248 /* Check if the ID Is in the registry */ 00249 if (CmInstallUILanguageIdType == REG_SZ) 00250 { 00251 /* Read it */ 00252 PsInstallUILanguageId = CmpConvertLangId(CmInstallUILanguageId, 00253 CmInstallUILanguageIdLength); 00254 } 00255 else 00256 { 00257 /* Otherwise, use the default */ 00258 PsInstallUILanguageId = LANGIDFROMLCID(PsDefaultSystemLocaleId); 00259 } 00260 00261 /* Set the defaults for the Thread UI */ 00262 PsDefaultThreadLocaleId = PsDefaultSystemLocaleId; 00263 PsDefaultUILanguageId = PsInstallUILanguageId; 00264 } Generated on Sun May 27 2012 04:37:07 for ReactOS by
1.7.6.1
|