test: cmcontrl.c Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# cmcontrl.c

Go to the documentation of this file.

    00001 /*++
    00002
    00003 Copyright (c) 1992  Microsoft Corporation
    00004
    00005 Module Name:
    00006
    00007     cmcontrl.c
    00008
    00009 Abstract:
    00010
    00011     The module contains CmGetSystemControlValues, see cmdat.c for data.
    00012
    00013 Author:
    00014
    00015     Bryan M. Willman (bryanwi) 12-May-92
    00016
    00017 Revision History:
    00018
    00019 --*/
    00020
    00021 #include    "cmp.h"
    00022
    00023 extern WCHAR   CmDefaultLanguageId[];
    00024 extern ULONG   CmDefaultLanguageIdLength;
    00025 extern ULONG   CmDefaultLanguageIdType;
    00026
    00027 extern WCHAR   CmInstallUILanguageId[];
    00028 extern ULONG   CmInstallUILanguageIdLength;
    00029 extern ULONG   CmInstallUILanguageIdType;
    00030
    00031 HCELL_INDEX
    00032 CmpWalkPath(
    00033     PHHIVE      SystemHive,
    00034     HCELL_INDEX ParentCell,
    00035     PWSTR       Path
    00036     );
    00037
    00038 LANGID
    00039 CmpConvertLangId(
    00040     PWSTR LangIdString,
    00041     ULONG LangIdStringLength
    00042 );
    00043
    00044 #ifdef ALLOC_PRAGMA
    00045 #pragma alloc_text(INIT,CmGetSystemControlValues)
    00046 #pragma alloc_text(INIT,CmpWalkPath)
    00047 #endif
    00048
    00049 VOID
    00050 CmGetSystemControlValues(
    00051     PVOID                   SystemHiveBuffer,
    00052     PCM_SYSTEM_CONTROL_VECTOR  ControlVector
    00053     )
    00054 /*++
    00055
    00056 Routine Description:
    00057
    00058     Look for registry values in current control set, as specified
    00059     by entries in ControlVector.  Report data for value entries
    00060     (if any) to variables ControlVector points to.
    00061
    00062 Arguments:
    00063
    00064     SystemHiveBuffer - pointer to flat image of the system hive
    00065
    00066     ControlVector - pointer to structure that describes what values
    00067                     to suck out and store
    00068
    00069 Return Value:
    00070
    00071     NONE.
    00072
    00073 --*/
    00074 {
    00075     NTSTATUS        status;
    00076     PHHIVE          SystemHive;
    00077     CMHIVE          TempHive;
    00078     HCELL_INDEX     RootCell;
    00079     HCELL_INDEX     BaseCell;
    00080     UNICODE_STRING  Name;
    00081     PHCELL_INDEX    Index;
    00082     HCELL_INDEX     KeyCell;
    00083     HCELL_INDEX     ValueCell;
    00084     PCM_KEY_VALUE   ValueBody;
    00085     PVOID           ValueData;
    00086     ULONG           Length;
    00087     BOOLEAN         AutoSelect;
    00088     BOOLEAN         small;
    00089     ULONG           tmplength;
    00090
    00091
    00092     //
    00093     // set up to read flat system hive image loader passes us
    00094     //
    00095     RtlZeroMemory((PVOID)&TempHive, sizeof(TempHive));
    00096     SystemHive = &(TempHive.Hive);
    00097     status = HvInitializeHive(
    00098                 SystemHive,
    00099                 HINIT_FLAT,
    00100                 HIVE_VOLATILE,
    00101                 HFILE_TYPE_PRIMARY,
    00102                 SystemHiveBuffer,
    00103                 NULL,
    00104                 NULL,
    00105                 NULL,
    00106                 NULL,
    00107                 NULL,
    00108                 NULL,
    00109                 1,
    00110                 NULL
    00111                 );
    00112     if (!NT_SUCCESS(status)) {
    00113         KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO,1,1,0,0);
    00114     }
    00115
    00116     //
    00117     // get hive.cell of root of current control set
    00118     //
    00119     RootCell = ((PHBASE_BLOCK)SystemHiveBuffer)->RootCell;
    00120     RtlInitUnicodeString(&Name, L"current");
    00121     BaseCell = CmpFindControlSet(
    00122                     SystemHive,
    00123                     RootCell,
    00124                     &Name,
    00125                     &AutoSelect
    00126                     );
    00127     if (BaseCell == HCELL_NIL) {
    00128         KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO,1,2,0,0);
    00129     }
    00130
    00131     RtlInitUnicodeString(&Name, L"control");
    00132     BaseCell = CmpFindSubKeyByName(SystemHive,
    00133                                    (PCM_KEY_NODE)HvGetCell(SystemHive,BaseCell),
    00134                                    &Name);
    00135     if (BaseCell == HCELL_NIL) {
    00136         KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO,1,3,0,0);
    00137     }
    00138
    00139     //
    00140     // SystemHive.BaseCell = \registry\machine\system\currentcontrolset\control
    00141     //
    00142
    00143     //
    00144     // step through vector, trying to fetch each value
    00145     //
    00146     while (ControlVector->KeyPath != NULL) {
    00147
    00148         //
    00149         //  Assume we will fail to find the key or value.
    00150         //
    00151
    00152         Length = (ULONG)-1;
    00153
    00154         KeyCell = CmpWalkPath(SystemHive, BaseCell, ControlVector->KeyPath);
    00155
    00156         if (KeyCell != HCELL_NIL) {
    00157
    00158             //
    00159             // found the key, look for the value entry
    00160             //
    00161             RtlInitUnicodeString(&Name, ControlVector->ValueName);
    00162             ValueCell = CmpFindValueByName(SystemHive,
    00163                                            (PCM_KEY_NODE)HvGetCell(SystemHive,KeyCell),
    00164                                            &Name);
    00165             if (ValueCell != HCELL_NIL) {
    00166
    00167                 //
    00168                 // SystemHive.ValueCell is value entry body
    00169                 //
    00170
    00171                 if (ControlVector->BufferLength == NULL) {
    00172                     tmplength = sizeof(ULONG);
    00173                 } else {
    00174                     tmplength = *(ControlVector->BufferLength);
    00175                 }
    00176
    00177                 ValueBody = (PCM_KEY_VALUE)HvGetCell(SystemHive, ValueCell);
    00178
    00179                 small = CmpIsHKeyValueSmall(Length, ValueBody->DataLength);
    00180
    00181                 if (tmplength < Length) {
    00182                     Length = tmplength;
    00183                 }
    00184
    00185                 if (Length > 0) {
    00186
    00187                     if (small == TRUE) {
    00188                         ValueData = (PVOID)(&(ValueBody->Data));
    00189                     } else {
    00190                         ValueData = (PVOID)HvGetCell(SystemHive, ValueBody->Data);
    00191                     }
    00192
    00193                     ASSERT((small ? (Length <= CM_KEY_VALUE_SMALL) : TRUE));
    00194
    00195                     RtlMoveMemory(
    00196                         ControlVector->Buffer,
    00197                         ValueData,
    00198                         Length
    00199                         );
    00200                 }
    00201
    00202                 if (ControlVector->Type != NULL) {
    00203                     *(ControlVector->Type) = ValueBody->Type;
    00204                 }
    00205             }
    00206         }
    00207
    00208         //
    00209         // Stash the length of result (-1 if nothing was found)
    00210         //
    00211
    00212         if (ControlVector->BufferLength != NULL) {
    00213             *(ControlVector->BufferLength) = Length;
    00214         }
    00215
    00216         ControlVector++;
    00217     }
    00218
    00219     //
    00220     // Get the default locale ID for the system from the registry.
    00221     //
    00222
    00223     if (CmDefaultLanguageIdType == REG_SZ) {
    00224         PsDefaultSystemLocaleId = (LCID) CmpConvertLangId(
    00225                                                 CmDefaultLanguageId,
    00226                                                 CmDefaultLanguageIdLength);
    00227     } else {
    00228         PsDefaultSystemLocaleId = 0x00000409;
    00229     }
    00230
    00231     //
    00232     // Get the install (native UI) language ID for the system from the registry.
    00233     //
    00234
    00235     if (CmInstallUILanguageIdType == REG_SZ) {
    00236         PsInstallUILanguageId =  CmpConvertLangId(
    00237                                                 CmInstallUILanguageId,
    00238                                                 CmInstallUILanguageIdLength);
    00239     } else {
    00240         PsInstallUILanguageId = LANGIDFROMLCID(PsDefaultSystemLocaleId);
    00241     }
    00242
    00243     //
    00244     // Set the default thread locale to the default system locale
    00245     // for now.  This will get changed as soon as somebody logs in.
    00246     // Use the install (native) language id as our default UI language id.
    00247     // This also will get changed as soon as somebody logs in.
    00248     //
    00249
    00250     PsDefaultThreadLocaleId = PsDefaultSystemLocaleId;
    00251     PsDefaultUILanguageId = PsInstallUILanguageId;
    00252 }
    00253
    00254
    00255 HCELL_INDEX
    00256 CmpWalkPath(
    00257     PHHIVE      SystemHive,
    00258     HCELL_INDEX ParentCell,
    00259     PWSTR       Path
    00260     )
    00261 /*++
    00262
    00263 Routine Description:
    00264
    00265     Walk the path.
    00266
    00267 Arguments:
    00268
    00269     SystemHive - hive
    00270
    00271     ParentCell - where to start
    00272
    00273     Path - string to walk
    00274
    00275 Return Value:
    00276
    00277     HCELL_INDEX of found key cell, or HCELL_NIL for error
    00278
    00279 --*/
    00280 {
    00281     NTSTATUS        status;
    00282     UNICODE_STRING  PathString;
    00283     UNICODE_STRING  NextName;
    00284     BOOLEAN         Last;
    00285     PHCELL_INDEX    Index;
    00286     HCELL_INDEX     KeyCell;
    00287
    00288     KeyCell = ParentCell;
    00289     RtlInitUnicodeString(&PathString, Path);
    00290
    00291     while (TRUE) {
    00292
    00293         CmpGetNextName(&PathString, &NextName, &Last);
    00294
    00295         if (NextName.Length == 0) {
    00296             return KeyCell;
    00297         }
    00298
    00299         KeyCell = CmpFindSubKeyByName(SystemHive,
    00300                                       (PCM_KEY_NODE)HvGetCell(SystemHive,KeyCell),
    00301                                       &NextName);
    00302
    00303         if (KeyCell == HCELL_NIL) {
    00304             return HCELL_NIL;
    00305         }
    00306     }
    00307 }
    00308
    00309 LANGID
    00310 CmpConvertLangId(
    00311     PWSTR LangIdString,
    00312     ULONG LangIdStringLength
    00313 )
    00314 {
    00315
    00316
    00317     USHORT i, Digit;
    00318     WCHAR c;
    00319     LANGID LangId;
    00320
    00321     LangId = 0;
    00322     LangIdStringLength = LangIdStringLength / sizeof( WCHAR );
    00323     for (i=0; i < LangIdStringLength; i++) {
    00324         c = LangIdString[ i ];
    00325
    00326         if (c >= L'0' && c <= L'9') {
    00327             Digit = c - L'0';
    00328
    00329         } else if (c >= L'A' && c <= L'F') {
    00330             Digit = c - L'A' + 10;
    00331
    00332         } else if (c >= L'a' && c <= L'f') {
    00333             Digit = c - L'a' + 10;
    00334
    00335         } else {
    00336             break;
    00337         }
    00338
    00339         if (Digit >= 16) {
    00340             break;
    00341         }
    00342
    00343         LangId = (LangId << 4) | Digit;
    00344     }
    00345
    00346     return LangId;
    00347 }
    00348