Fix SmpSetEnvironmentVariable return status
[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 return RtlSetEnvironmentVariable(Context,
58 &EnvVariable,
59 &EnvValue);
60 }
61
62
63 static NTSTATUS STDCALL
64 SmpEnvironmentQueryRoutine(IN PWSTR ValueName,
65 IN ULONG ValueType,
66 IN PVOID ValueData,
67 IN ULONG ValueLength,
68 IN PVOID Context,
69 IN PVOID EntryContext)
70 {
71 DPRINT("ValueName '%S' Type %lu Length %lu\n", ValueName, ValueType, ValueLength);
72
73 if (ValueType != REG_SZ && ValueType != REG_EXPAND_SZ)
74 return STATUS_SUCCESS;
75
76 DPRINT("ValueData '%S'\n", (PWSTR)ValueData);
77 return SmpSetEnvironmentVariable(Context,ValueName,ValueData);
78 }
79
80
81 NTSTATUS
82 SmSetEnvironmentVariables(VOID)
83 {
84 RTL_QUERY_REGISTRY_TABLE QueryTable[2];
85 WCHAR ValueBuffer[MAX_PATH];
86 NTSTATUS Status;
87
88 /*
89 * The following environment variables must be set prior to reading
90 * other variables from the registry.
91 *
92 * Variables (example):
93 * SystemRoot = "C:\reactos"
94 * SystemDrive = "C:"
95 */
96
97 /* Copy system root into value buffer */
98 wcscpy(ValueBuffer,
99 SharedUserData->NtSystemRoot);
100
101 /* Set SystemRoot = "C:\reactos" */
102 SmpSetEnvironmentVariable(&SmSystemEnvironment, L"SystemRoot", ValueBuffer);
103
104 /* Cut off trailing path */
105 ValueBuffer[2] = 0;
106
107 /* Set SystemDrive = "C:" */
108 SmpSetEnvironmentVariable(&SmSystemEnvironment, L"SystemDrive", ValueBuffer);
109
110 /* Read system environment from the registry. */
111 RtlZeroMemory(&QueryTable,
112 sizeof(QueryTable));
113
114 QueryTable[0].QueryRoutine = SmpEnvironmentQueryRoutine;
115
116 Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
117 L"Session Manager\\Environment",
118 QueryTable,
119 &SmSystemEnvironment,
120 SmSystemEnvironment);
121
122 return Status;
123 }
124
125 /**********************************************************************
126 * Set environment variables from registry
127 */
128 NTSTATUS
129 SmUpdateEnvironment(VOID)
130 {
131 /* TODO */
132 return STATUS_SUCCESS;
133 }
134
135 /* EOF */