Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenlookupss.c
Go to the documentation of this file.
00001 /* $Id: lookupss.c 37828 2008-12-03 17:32:36Z dgorbachev $ 00002 * 00003 * COPYRIGHT: See COPYING in the top level directory 00004 * PROJECT: ReactOS system libraries 00005 * FILE: lib/smlib/lookupss.c 00006 */ 00007 #include "precomp.h" 00008 00009 #define NDEBUG 00010 #include <debug.h> 00011 00012 /********************************************************************** 00013 * NAME EXPORTED 00014 * SmLookupSubsystem/6 00015 * 00016 * DESCRIPTION 00017 * Read from the registry key 00018 * \Registry\SYSTEM\CurrentControlSet\Control\Session Manager\Subsystems 00019 * the value which name is Name. 00020 * 00021 * ARGUMENTS 00022 * Name: name of the program to run, that is a value's name in 00023 * the SM registry key Subsystems; 00024 * Data: what the registry gave back for Name; 00025 * DataLength: how much Data the registry returns; 00026 * DataType: what is Data? 00027 * Environment: set it if you want this function to use it 00028 * to possibly expand Data before giving it back; if set 00029 * to NULL, no expansion will be performed. 00030 */ 00031 NTSTATUS WINAPI 00032 SmLookupSubsystem (IN PWSTR Name, 00033 IN OUT PWSTR Data, 00034 IN OUT PULONG DataLength, 00035 IN OUT PULONG DataType, 00036 IN PVOID Environment OPTIONAL) 00037 { 00038 NTSTATUS Status = STATUS_SUCCESS; 00039 UNICODE_STRING usKeyName = { 0, 0, NULL }; 00040 OBJECT_ATTRIBUTES Oa = {0}; 00041 HANDLE hKey = (HANDLE) 0; 00042 00043 DPRINT("SM: %s(Name='%S') called\n", __FUNCTION__, Name); 00044 /* 00045 * Prepare the key name to scan and 00046 * related object attributes. 00047 */ 00048 RtlInitUnicodeString (& usKeyName, 00049 L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\SubSystems"); 00050 00051 InitializeObjectAttributes (& Oa, 00052 & usKeyName, 00053 OBJ_CASE_INSENSITIVE, 00054 NULL, 00055 NULL); 00056 /* 00057 * Open the key. This MUST NOT fail, if the 00058 * request is for a legitimate subsystem. 00059 */ 00060 Status = NtOpenKey (& hKey, 00061 MAXIMUM_ALLOWED, 00062 & Oa); 00063 if(NT_SUCCESS(Status)) 00064 { 00065 UNICODE_STRING usValueName = { 0, 0, NULL }; 00066 PWCHAR KeyValueInformation = NULL; 00067 ULONG KeyValueInformationLength = 1024; 00068 ULONG ResultLength = 0L; 00069 PKEY_VALUE_PARTIAL_INFORMATION kvpi = NULL; 00070 00071 KeyValueInformation = RtlAllocateHeap (RtlGetProcessHeap(), 00072 0, 00073 KeyValueInformationLength); 00074 if (NULL == KeyValueInformation) 00075 { 00076 return STATUS_NO_MEMORY; 00077 } 00078 kvpi = (PKEY_VALUE_PARTIAL_INFORMATION) KeyValueInformation; 00079 RtlInitUnicodeString (& usValueName, Name); 00080 Status = NtQueryValueKey (hKey, 00081 & usValueName, 00082 KeyValuePartialInformation, 00083 KeyValueInformation, 00084 KeyValueInformationLength, 00085 & ResultLength); 00086 if(NT_SUCCESS(Status)) 00087 { 00088 DPRINT("nkvpi.TitleIndex = %ld\n", kvpi->TitleIndex); 00089 DPRINT("kvpi.Type = %ld\n", kvpi->Type); 00090 DPRINT("kvpi.DataLength = %ld\n", kvpi->DataLength); 00091 00092 if((NULL != Data) && (NULL != DataLength) && (NULL != DataType)) 00093 { 00094 *DataType = kvpi->Type; 00095 if((NULL != Environment) && (REG_EXPAND_SZ == *DataType)) 00096 { 00097 UNICODE_STRING Source; 00098 PWCHAR DestinationBuffer = NULL; 00099 UNICODE_STRING Destination; 00100 ULONG Length = 0; 00101 00102 DPRINT("SM: %s: value will be expanded\n", __FUNCTION__); 00103 00104 DestinationBuffer = RtlAllocateHeap (RtlGetProcessHeap(), 00105 0, 00106 (2 * KeyValueInformationLength)); 00107 if (NULL == DestinationBuffer) 00108 { 00109 Status = STATUS_NO_MEMORY; 00110 } 00111 else 00112 { 00113 Source.Length = kvpi->DataLength; 00114 Source.MaximumLength = kvpi->DataLength; 00115 Source.Buffer = (PWCHAR) & kvpi->Data; 00116 00117 Destination.Length = 0; 00118 Destination.MaximumLength = (2 * KeyValueInformationLength); 00119 Destination.Buffer = DestinationBuffer; 00120 00121 Status = RtlExpandEnvironmentStrings_U (Environment, 00122 & Source, 00123 & Destination, 00124 & Length); 00125 if(NT_SUCCESS(Status)) 00126 { 00127 *DataLength = min(*DataLength, Destination.Length); 00128 RtlCopyMemory (Data, Destination.Buffer, *DataLength); 00129 } 00130 RtlFreeHeap (RtlGetProcessHeap(), 0, DestinationBuffer); 00131 } 00132 }else{ 00133 DPRINT("SM: %s: value won't be expanded\n", __FUNCTION__); 00134 *DataLength = min(*DataLength, kvpi->DataLength); 00135 RtlCopyMemory (Data, & kvpi->Data, *DataLength); 00136 } 00137 *DataType = kvpi->Type; 00138 }else{ 00139 DPRINT1("SM: %s: Data or DataLength or DataType is NULL!\n", __FUNCTION__); 00140 Status = STATUS_INVALID_PARAMETER; 00141 } 00142 }else{ 00143 DPRINT1("%s: NtQueryValueKey failed (Status=0x%08lx)\n", __FUNCTION__, Status); 00144 } 00145 RtlFreeHeap (RtlGetProcessHeap(), 0, KeyValueInformation); 00146 NtClose (hKey); 00147 }else{ 00148 DPRINT1("%s: NtOpenKey failed (Status=0x%08lx)\n", __FUNCTION__, Status); 00149 } 00150 return Status; 00151 } 00152 00153 /* EOF */ Generated on Sun May 27 2012 04:37:03 for ReactOS by
1.7.6.1
|