ReactOS  0.4.15-dev-1201-gb2cf5a4
lookupss.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS system libraries
4  * FILE: lib/smlib/lookupss.c
5  */
6 
7 #include "precomp.h"
8 
9 #define NDEBUG
10 #include <debug.h>
11 
12 /**********************************************************************
13  * NAME EXPORTED
14  * SmLookupSubsystem/6
15  *
16  * DESCRIPTION
17  * Read from the registry key
18  * \Registry\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems
19  * the value which name is Name.
20  *
21  * ARGUMENTS
22  * Name: name of the program to run, that is a value's name in
23  * the SM registry key SubSystems;
24  * Data: what the registry gave back for Name;
25  * DataLength: how much Data the registry returns;
26  * DataType: what is Data?
27  * Environment: set it if you want this function to use it
28  * to possibly expand Data before giving it back; if set
29  * to NULL, no expansion will be performed.
30  */
33  IN OUT PWSTR Data,
37 {
39  UNICODE_STRING usKeyName = { 0, 0, NULL };
40  OBJECT_ATTRIBUTES Oa = {0};
41  HANDLE hKey = (HANDLE) 0;
42 
43  DPRINT("SM: %s(Name='%S') called\n", __FUNCTION__, Name);
44  /*
45  * Prepare the key name to scan and
46  * related object attributes.
47  */
48  RtlInitUnicodeString (& usKeyName,
49  L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\SubSystems");
50 
52  & usKeyName,
54  NULL,
55  NULL);
56  /*
57  * Open the key. This MUST NOT fail, if the
58  * request is for a legitimate subsystem.
59  */
60  Status = NtOpenKey (& hKey,
62  & Oa);
63  if(NT_SUCCESS(Status))
64  {
65  UNICODE_STRING usValueName = { 0, 0, NULL };
66  PWCHAR KeyValueInformation = NULL;
67  ULONG KeyValueInformationLength = 1024;
68  ULONG ResultLength = 0L;
70 
71  KeyValueInformation = RtlAllocateHeap (RtlGetProcessHeap(),
72  0,
73  KeyValueInformationLength);
74  if (NULL == KeyValueInformation)
75  {
76  return STATUS_NO_MEMORY;
77  }
78  kvpi = (PKEY_VALUE_PARTIAL_INFORMATION) KeyValueInformation;
79  RtlInitUnicodeString (& usValueName, Name);
80  Status = NtQueryValueKey (hKey,
81  & usValueName,
83  KeyValueInformation,
84  KeyValueInformationLength,
85  & ResultLength);
86  if(NT_SUCCESS(Status))
87  {
88  DPRINT("nkvpi.TitleIndex = %lu\n", kvpi->TitleIndex);
89  DPRINT("kvpi.Type = %lu\n", kvpi->Type);
90  DPRINT("kvpi.DataLength = %lu\n", kvpi->DataLength);
91 
92  if((NULL != Data) && (NULL != DataLength) && (NULL != DataType))
93  {
94  *DataType = kvpi->Type;
95  if((NULL != Environment) && (REG_EXPAND_SZ == *DataType))
96  {
98  PWCHAR DestinationBuffer = NULL;
100  ULONG Length = 0;
101 
102  DPRINT("SM: %s: value will be expanded\n", __FUNCTION__);
103 
104  DestinationBuffer = RtlAllocateHeap (RtlGetProcessHeap(),
105  0,
106  (2 * KeyValueInformationLength));
107  if (NULL == DestinationBuffer)
108  {
110  }
111  else
112  {
113  Source.Length = (USHORT)kvpi->DataLength;
114  Source.MaximumLength = (USHORT)kvpi->DataLength;
115  Source.Buffer = (PWCHAR) & kvpi->Data;
116 
117  Destination.Length = 0;
118  Destination.MaximumLength = (USHORT)(2 * KeyValueInformationLength);
119  Destination.Buffer = DestinationBuffer;
120 
122  & Source,
123  & Destination,
124  & Length);
125  if(NT_SUCCESS(Status))
126  {
129  }
130  RtlFreeHeap (RtlGetProcessHeap(), 0, DestinationBuffer);
131  }
132  }else{
133  DPRINT("SM: %s: value won't be expanded\n", __FUNCTION__);
134  *DataLength = min(*DataLength, kvpi->DataLength);
135  RtlCopyMemory (Data, & kvpi->Data, *DataLength);
136  }
137  *DataType = kvpi->Type;
138  }else{
139  DPRINT1("SM: %s: Data or DataLength or DataType is NULL!\n", __FUNCTION__);
141  }
142  }else{
143  DPRINT1("%s: NtQueryValueKey failed (Status=0x%08lx)\n", __FUNCTION__, Status);
144  }
145  RtlFreeHeap (RtlGetProcessHeap(), 0, KeyValueInformation);
146  NtClose (hKey);
147  }else{
148  DPRINT1("%s: NtOpenKey failed (Status=0x%08lx)\n", __FUNCTION__, Status);
149  }
150  return Status;
151 }
152 
153 /* EOF */
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
PVOID PVOID PWCHAR PVOID Environment
Definition: env.c:45
#define IN
Definition: typedefs.h:39
NTSYSAPI NTSTATUS WINAPI RtlExpandEnvironmentStrings_U(PCWSTR, const UNICODE_STRING *, UNICODE_STRING *, ULONG *)
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
uint16_t * PWSTR
Definition: typedefs.h:56
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
uint16_t * PWCHAR
Definition: typedefs.h:56
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_In_ ULONG _In_opt_ WDFREQUEST _In_opt_ PVOID _In_ size_t _In_ PVOID _In_ size_t _Out_ size_t * DataLength
Definition: cdrom.h:1437
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _KEY_VALUE_PARTIAL_INFORMATION * PKEY_VALUE_PARTIAL_INFORMATION
#define WINAPI
Definition: msvc.h:6
PVOID HANDLE
Definition: typedefs.h:73
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2937
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
unsigned short USHORT
Definition: pedump.c:61
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
unsigned int * PULONG
Definition: retypes.h:1
#define min(a, b)
Definition: monoChain.cc:55
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
#define OUT
Definition: typedefs.h:40
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
_In_ ULONG DataType
Definition: iotypes.h:803
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define __FUNCTION__
Definition: types.h:112
NTSTATUS WINAPI SmLookupSubsystem(IN PWSTR Name, IN OUT PWSTR Data, IN OUT PULONG DataLength, IN OUT PULONG DataType, IN PVOID Environment OPTIONAL)
Definition: lookupss.c:32
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68