Bring back ext2 code from branch
[reactos.git] / reactos / base / system / smss / initenv.c
1 /*
2 * initenv.c - Environment initialization
3 *
4 * ReactOS Operating System
5 *
6 * --------------------------------------------------------------------
7 *
8 * This software is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 * This software is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this software; see the file COPYING.LIB. If not, write
20 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
21 * MA 02139, USA.
22 *
23 * --------------------------------------------------------------------
24 */
25
26 #include "smss.h"
27
28 #define NDEBUG
29 #include <debug.h>
30
31 /* GLOBALS */
32
33 PWSTR SmSystemEnvironment = NULL;
34
35
36 /* FUNCTIONS */
37
38 NTSTATUS
39 SmCreateEnvironment(VOID)
40 {
41 return RtlCreateEnvironment(FALSE, &SmSystemEnvironment);
42 }
43
44
45 static NTSTATUS
46 SmpSetEnvironmentVariable(IN PVOID Context,
47 IN PWSTR ValueName,
48 IN PVOID ValueData)
49 {
50 UNICODE_STRING EnvVariable;
51 UNICODE_STRING EnvValue;
52
53 RtlInitUnicodeString(&EnvVariable,
54 ValueName);
55 RtlInitUnicodeString(&EnvValue,
56 (PWSTR)ValueData);
57 RtlSetEnvironmentVariable(Context,
58 &EnvVariable,
59 &EnvValue);
60
61 return STATUS_SUCCESS;
62 }
63
64
65 static NTSTATUS STDCALL
66 SmpEnvironmentQueryRoutine(IN PWSTR ValueName,
67 IN ULONG ValueType,
68 IN PVOID ValueData,
69 IN ULONG ValueLength,
70 IN PVOID Context,
71 IN PVOID EntryContext)
72 {
73 DPRINT("ValueName '%S' Type %lu Length %lu\n", ValueName, ValueType, ValueLength);
74
75 if (ValueType != REG_SZ && ValueType != REG_EXPAND_SZ)
76 return STATUS_SUCCESS;
77
78 DPRINT("ValueData '%S'\n", (PWSTR)ValueData);
79 return SmpSetEnvironmentVariable(Context,ValueName,ValueData);
80 }
81
82
83 NTSTATUS
84 SmSetEnvironmentVariables(VOID)
85 {
86 RTL_QUERY_REGISTRY_TABLE QueryTable[2];
87 WCHAR ValueBuffer[MAX_PATH];
88 NTSTATUS Status;
89
90 /*
91 * The following environment variables must be set prior to reading
92 * other variables from the registry.
93 *
94 * Variables (example):
95 * SystemRoot = "C:\reactos"
96 * SystemDrive = "C:"
97 */
98
99 /* Copy system root into value buffer */
100 wcscpy(ValueBuffer,
101 SharedUserData->NtSystemRoot);
102
103 /* Set SystemRoot = "C:\reactos" */
104 SmpSetEnvironmentVariable(&SmSystemEnvironment, L"SystemRoot", ValueBuffer);
105
106 /* Cut off trailing path */
107 ValueBuffer[2] = 0;
108
109 /* Set SystemDrive = "C:" */
110 SmpSetEnvironmentVariable(&SmSystemEnvironment, L"SystemDrive", ValueBuffer);
111
112 /* Read system environment from the registry. */
113 RtlZeroMemory(&QueryTable,
114 sizeof(QueryTable));
115
116 QueryTable[0].QueryRoutine = SmpEnvironmentQueryRoutine;
117
118 Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
119 L"Session Manager\\Environment",
120 QueryTable,
121 &SmSystemEnvironment,
122 SmSystemEnvironment);
123
124 return Status;
125 }
126
127 /**********************************************************************
128 * Set environment variables from registry
129 */
130 NTSTATUS
131 SmUpdateEnvironment(VOID)
132 {
133 /* TODO */
134 return STATUS_SUCCESS;
135 }
136
137 /* EOF */