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