Sync with trunk head.
[reactos.git] / base / system / smss / initenv.c
1 /*
2 * PROJECT: ReactOS Session Manager
3 * LICENSE: GPL v2 or later - See COPYING in the top level directory
4 * FILE: base/system/smss/initenv.c
5 * PURPOSE: Environment initialization.
6 * PROGRAMMERS: ReactOS Development Team
7 */
8
9 /* INCLUDES ******************************************************************/
10 #include "smss.h"
11
12 #define NDEBUG
13 #include <debug.h>
14
15 /* GLOBALS */
16
17 PWSTR SmSystemEnvironment = NULL;
18
19
20 /* FUNCTIONS */
21
22 NTSTATUS
23 SmCreateEnvironment(VOID)
24 {
25 return RtlCreateEnvironment(FALSE, &SmSystemEnvironment);
26 }
27
28
29 static NTSTATUS
30 SmpSetEnvironmentVariable(IN PVOID Context,
31 IN PWSTR ValueName,
32 IN PVOID ValueData)
33 {
34 UNICODE_STRING EnvVariable;
35 UNICODE_STRING EnvValue;
36
37 RtlInitUnicodeString(&EnvVariable,
38 ValueName);
39 RtlInitUnicodeString(&EnvValue,
40 (PWSTR)ValueData);
41 return RtlSetEnvironmentVariable(Context,
42 &EnvVariable,
43 &EnvValue);
44 }
45
46
47 static NTSTATUS NTAPI
48 SmpEnvironmentQueryRoutine(IN PWSTR ValueName,
49 IN ULONG ValueType,
50 IN PVOID ValueData,
51 IN ULONG ValueLength,
52 IN PVOID Context,
53 IN PVOID EntryContext)
54 {
55 DPRINT("ValueName '%S' Type %lu Length %lu\n", ValueName, ValueType, ValueLength);
56
57 if (ValueType != REG_SZ && ValueType != REG_EXPAND_SZ)
58 return STATUS_SUCCESS;
59
60 DPRINT("ValueData '%S'\n", (PWSTR)ValueData);
61 return SmpSetEnvironmentVariable(Context,ValueName,ValueData);
62 }
63
64
65 NTSTATUS
66 SmSetEnvironmentVariables(VOID)
67 {
68 RTL_QUERY_REGISTRY_TABLE QueryTable[2];
69 WCHAR ValueBuffer[MAX_PATH];
70 NTSTATUS Status;
71
72 /*
73 * The following environment variables must be set prior to reading
74 * other variables from the registry.
75 *
76 * Variables (example):
77 * SystemRoot = "C:\reactos"
78 * SystemDrive = "C:"
79 */
80
81 /* Copy system root into value buffer */
82 wcscpy(ValueBuffer,
83 SharedUserData->NtSystemRoot);
84
85 /* Set SystemRoot = "C:\reactos" */
86 SmpSetEnvironmentVariable(&SmSystemEnvironment, L"SystemRoot", ValueBuffer);
87
88 /* Cut off trailing path */
89 ValueBuffer[2] = 0;
90
91 /* Set SystemDrive = "C:" */
92 SmpSetEnvironmentVariable(&SmSystemEnvironment, L"SystemDrive", ValueBuffer);
93
94 /* Read system environment from the registry. */
95 RtlZeroMemory(&QueryTable,
96 sizeof(QueryTable));
97
98 QueryTable[0].QueryRoutine = SmpEnvironmentQueryRoutine;
99
100 Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
101 L"Session Manager\\Environment",
102 QueryTable,
103 &SmSystemEnvironment,
104 SmSystemEnvironment);
105
106 return Status;
107 }
108
109 /**********************************************************************
110 * Set environment variables from registry
111 */
112 NTSTATUS
113 SmUpdateEnvironment(VOID)
114 {
115 /* TODO */
116 return STATUS_SUCCESS;
117 }
118
119 /* EOF */