[FORMATTING]

No code changes.

svn path=/trunk/; revision=47107
This commit is contained in:
Eric Kohl 2010-05-05 22:53:01 +00:00
parent 51e6829b67
commit ac293dd5d6

View file

@ -32,7 +32,7 @@
static BOOL static BOOL
SetUserEnvironmentVariable (LPVOID *Environment, SetUserEnvironmentVariable(LPVOID *Environment,
LPWSTR lpName, LPWSTR lpName,
LPWSTR lpValue, LPWSTR lpValue,
BOOL bExpand) BOOL bExpand)
@ -43,7 +43,7 @@ SetUserEnvironmentVariable (LPVOID *Environment,
UNICODE_STRING DstValue; UNICODE_STRING DstValue;
ULONG Length; ULONG Length;
NTSTATUS Status; NTSTATUS Status;
PVOID Buffer=NULL; PVOID Buffer = NULL;
if (bExpand) if (bExpand)
{ {
@ -56,7 +56,6 @@ SetUserEnvironmentVariable (LPVOID *Environment,
DstValue.MaximumLength = Length; DstValue.MaximumLength = Length;
DstValue.Buffer = Buffer = LocalAlloc(LPTR, DstValue.Buffer = Buffer = LocalAlloc(LPTR,
Length); Length);
if (DstValue.Buffer == NULL) if (DstValue.Buffer == NULL)
{ {
DPRINT1("LocalAlloc() failed\n"); DPRINT1("LocalAlloc() failed\n");
@ -71,7 +70,8 @@ SetUserEnvironmentVariable (LPVOID *Environment,
{ {
DPRINT1("RtlExpandEnvironmentStrings_U() failed (Status %lx)\n", Status); DPRINT1("RtlExpandEnvironmentStrings_U() failed (Status %lx)\n", Status);
DPRINT1("Length %lu\n", Length); DPRINT1("Length %lu\n", Length);
if (Buffer) LocalFree(Buffer); if (Buffer)
LocalFree(Buffer);
return FALSE; return FALSE;
} }
} }
@ -81,12 +81,13 @@ SetUserEnvironmentVariable (LPVOID *Environment,
lpValue); lpValue);
} }
if (!_wcsicmp (lpName, L"temp") || !_wcsicmp (lpName, L"tmp")) if (!_wcsicmp(lpName, L"temp") || !_wcsicmp(lpName, L"tmp"))
{ {
if (!GetShortPathNameW(DstValue.Buffer, ShortName, MAX_PATH)) if (!GetShortPathNameW(DstValue.Buffer, ShortName, MAX_PATH))
{ {
DPRINT1("GetShortPathNameW() failed for %S (Error %lu)\n", DstValue.Buffer, GetLastError()); DPRINT1("GetShortPathNameW() failed for %S (Error %lu)\n", DstValue.Buffer, GetLastError());
if (Buffer) LocalFree(Buffer); if (Buffer)
LocalFree(Buffer);
return FALSE; return FALSE;
} }
@ -104,7 +105,8 @@ SetUserEnvironmentVariable (LPVOID *Environment,
&Name, &Name,
&DstValue); &DstValue);
if (Buffer) LocalFree(Buffer); if (Buffer)
LocalFree(Buffer);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -117,7 +119,7 @@ SetUserEnvironmentVariable (LPVOID *Environment,
static BOOL static BOOL
AppendUserEnvironmentVariable (LPVOID *Environment, AppendUserEnvironmentVariable(LPVOID *Environment,
LPWSTR lpName, LPWSTR lpName,
LPWSTR lpValue) LPWSTR lpValue)
{ {
@ -125,12 +127,12 @@ AppendUserEnvironmentVariable (LPVOID *Environment,
UNICODE_STRING Value; UNICODE_STRING Value;
NTSTATUS Status; NTSTATUS Status;
RtlInitUnicodeString (&Name, RtlInitUnicodeString(&Name,
lpName); lpName);
Value.Length = 0; Value.Length = 0;
Value.MaximumLength = 1024 * sizeof(WCHAR); Value.MaximumLength = 1024 * sizeof(WCHAR);
Value.Buffer = LocalAlloc (LPTR, Value.Buffer = LocalAlloc(LPTR,
1024 * sizeof(WCHAR)); 1024 * sizeof(WCHAR));
if (Value.Buffer == NULL) if (Value.Buffer == NULL)
{ {
@ -138,25 +140,25 @@ AppendUserEnvironmentVariable (LPVOID *Environment,
} }
Value.Buffer[0] = UNICODE_NULL; Value.Buffer[0] = UNICODE_NULL;
Status = RtlQueryEnvironmentVariable_U ((PWSTR)*Environment, Status = RtlQueryEnvironmentVariable_U((PWSTR)*Environment,
&Name, &Name,
&Value); &Value);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
RtlAppendUnicodeToString (&Value, RtlAppendUnicodeToString(&Value,
L";"); L";");
} }
RtlAppendUnicodeToString (&Value, RtlAppendUnicodeToString(&Value,
lpValue); lpValue);
Status = RtlSetEnvironmentVariable ((PWSTR*)Environment, Status = RtlSetEnvironmentVariable((PWSTR*)Environment,
&Name, &Name,
&Value); &Value);
LocalFree (Value.Buffer); LocalFree(Value.Buffer);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1 ("RtlSetEnvironmentVariable() failed (Status %lx)\n", Status); DPRINT1("RtlSetEnvironmentVariable() failed (Status %lx)\n", Status);
return FALSE; return FALSE;
} }
@ -165,40 +167,40 @@ AppendUserEnvironmentVariable (LPVOID *Environment,
static HKEY static HKEY
GetCurrentUserKey (HANDLE hToken) GetCurrentUserKey(HANDLE hToken)
{ {
UNICODE_STRING SidString; UNICODE_STRING SidString;
HKEY hKey; HKEY hKey;
LONG Error; LONG Error;
if (!GetUserSidFromToken (hToken, if (!GetUserSidFromToken(hToken,
&SidString)) &SidString))
{ {
DPRINT1 ("GetUserSidFromToken() failed\n"); DPRINT1("GetUserSidFromToken() failed\n");
return NULL; return NULL;
} }
Error = RegOpenKeyExW (HKEY_USERS, Error = RegOpenKeyExW(HKEY_USERS,
SidString.Buffer, SidString.Buffer,
0, 0,
MAXIMUM_ALLOWED, MAXIMUM_ALLOWED,
&hKey); &hKey);
if (Error != ERROR_SUCCESS) if (Error != ERROR_SUCCESS)
{ {
DPRINT1 ("RegOpenKeyExW() failed (Error %ld)\n", Error); DPRINT1("RegOpenKeyExW() failed (Error %ld)\n", Error);
RtlFreeUnicodeString (&SidString); RtlFreeUnicodeString(&SidString);
SetLastError((DWORD)Error); SetLastError((DWORD)Error);
return NULL; return NULL;
} }
RtlFreeUnicodeString (&SidString); RtlFreeUnicodeString(&SidString);
return hKey; return hKey;
} }
static BOOL static BOOL
SetUserEnvironment (LPVOID *lpEnvironment, SetUserEnvironment(LPVOID *lpEnvironment,
HKEY hKey, HKEY hKey,
LPWSTR lpSubKeyName) LPWSTR lpSubKeyName)
{ {
@ -214,19 +216,19 @@ SetUserEnvironment (LPVOID *lpEnvironment,
LPWSTR lpValueData; LPWSTR lpValueData;
LONG Error; LONG Error;
Error = RegOpenKeyExW (hKey, Error = RegOpenKeyExW(hKey,
lpSubKeyName, lpSubKeyName,
0, 0,
KEY_QUERY_VALUE, KEY_QUERY_VALUE,
&hEnvKey); &hEnvKey);
if (Error != ERROR_SUCCESS) if (Error != ERROR_SUCCESS)
{ {
DPRINT1 ("RegOpenKeyExW() failed (Error %ld)\n", Error); DPRINT1("RegOpenKeyExW() failed (Error %ld)\n", Error);
SetLastError((DWORD)Error); SetLastError((DWORD)Error);
return FALSE; return FALSE;
} }
Error = RegQueryInfoKey (hEnvKey, Error = RegQueryInfoKey(hEnvKey,
NULL, NULL,
NULL, NULL,
NULL, NULL,
@ -240,33 +242,33 @@ SetUserEnvironment (LPVOID *lpEnvironment,
NULL); NULL);
if (Error != ERROR_SUCCESS) if (Error != ERROR_SUCCESS)
{ {
DPRINT1 ("RegQueryInforKey() failed (Error %ld)\n", Error); DPRINT1("RegQueryInforKey() failed (Error %ld)\n", Error);
RegCloseKey (hEnvKey); RegCloseKey(hEnvKey);
SetLastError((DWORD)Error); SetLastError((DWORD)Error);
return FALSE; return FALSE;
} }
if (dwValues == 0) if (dwValues == 0)
{ {
RegCloseKey (hEnvKey); RegCloseKey(hEnvKey);
return TRUE; return TRUE;
} }
/* Allocate buffers */ /* Allocate buffers */
lpValueName = LocalAlloc (LPTR, lpValueName = LocalAlloc(LPTR,
dwMaxValueNameLength * sizeof(WCHAR)); dwMaxValueNameLength * sizeof(WCHAR));
if (lpValueName == NULL) if (lpValueName == NULL)
{ {
RegCloseKey (hEnvKey); RegCloseKey(hEnvKey);
return FALSE; return FALSE;
} }
lpValueData = LocalAlloc (LPTR, lpValueData = LocalAlloc(LPTR,
dwMaxValueDataLength); dwMaxValueDataLength);
if (lpValueData == NULL) if (lpValueData == NULL)
{ {
LocalFree (lpValueName); LocalFree(lpValueName);
RegCloseKey (hEnvKey); RegCloseKey(hEnvKey);
return FALSE; return FALSE;
} }
@ -275,7 +277,7 @@ SetUserEnvironment (LPVOID *lpEnvironment,
{ {
dwValueNameLength = dwMaxValueNameLength; dwValueNameLength = dwMaxValueNameLength;
dwValueDataLength = dwMaxValueDataLength; dwValueDataLength = dwMaxValueDataLength;
RegEnumValueW (hEnvKey, RegEnumValueW(hEnvKey,
i, i,
lpValueName, lpValueName,
&dwValueNameLength, &dwValueNameLength,
@ -287,30 +289,30 @@ SetUserEnvironment (LPVOID *lpEnvironment,
if (!_wcsicmp (lpValueName, L"path")) if (!_wcsicmp (lpValueName, L"path"))
{ {
/* Append 'Path' environment variable */ /* Append 'Path' environment variable */
AppendUserEnvironmentVariable (lpEnvironment, AppendUserEnvironmentVariable(lpEnvironment,
lpValueName, lpValueName,
lpValueData); lpValueData);
} }
else else
{ {
/* Set environment variable */ /* Set environment variable */
SetUserEnvironmentVariable (lpEnvironment, SetUserEnvironmentVariable(lpEnvironment,
lpValueName, lpValueName,
lpValueData, lpValueData,
(dwType == REG_EXPAND_SZ)); (dwType == REG_EXPAND_SZ));
} }
} }
LocalFree (lpValueData); LocalFree(lpValueData);
LocalFree (lpValueName); LocalFree(lpValueName);
RegCloseKey (hEnvKey); RegCloseKey(hEnvKey);
return TRUE; return TRUE;
} }
BOOL WINAPI BOOL WINAPI
CreateEnvironmentBlock (LPVOID *lpEnvironment, CreateEnvironmentBlock(LPVOID *lpEnvironment,
HANDLE hToken, HANDLE hToken,
BOOL bInherit) BOOL bInherit)
{ {
@ -327,18 +329,18 @@ CreateEnvironmentBlock (LPVOID *lpEnvironment,
return FALSE; return FALSE;
} }
Status = RtlCreateEnvironment ((BOOLEAN)bInherit, Status = RtlCreateEnvironment((BOOLEAN)bInherit,
(PWSTR*)lpEnvironment); (PWSTR*)lpEnvironment);
if (!NT_SUCCESS (Status)) if (!NT_SUCCESS (Status))
{ {
DPRINT1 ("RtlCreateEnvironment() failed (Status %lx)\n", Status); DPRINT1("RtlCreateEnvironment() failed (Status %lx)\n", Status);
SetLastError (RtlNtStatusToDosError (Status)); SetLastError(RtlNtStatusToDosError(Status));
return FALSE; return FALSE;
} }
/* Set 'COMPUTERNAME' variable */ /* Set 'COMPUTERNAME' variable */
Length = MAX_PATH; Length = MAX_PATH;
if (GetComputerNameW (Buffer, if (GetComputerNameW(Buffer,
&Length)) &Length))
{ {
SetUserEnvironmentVariable(lpEnvironment, SetUserEnvironmentVariable(lpEnvironment,
@ -350,17 +352,17 @@ CreateEnvironmentBlock (LPVOID *lpEnvironment,
if (hToken == NULL) if (hToken == NULL)
return TRUE; return TRUE;
hKeyUser = GetCurrentUserKey (hToken); hKeyUser = GetCurrentUserKey(hToken);
if (hKeyUser == NULL) if (hKeyUser == NULL)
{ {
DPRINT1 ("GetCurrentUserKey() failed\n"); DPRINT1("GetCurrentUserKey() failed\n");
RtlDestroyEnvironment (*lpEnvironment); RtlDestroyEnvironment(*lpEnvironment);
return FALSE; return FALSE;
} }
/* Set 'ALLUSERSPROFILE' variable */ /* Set 'ALLUSERSPROFILE' variable */
Length = MAX_PATH; Length = MAX_PATH;
if (GetAllUsersProfileDirectoryW (Buffer, if (GetAllUsersProfileDirectoryW(Buffer,
&Length)) &Length))
{ {
SetUserEnvironmentVariable(lpEnvironment, SetUserEnvironmentVariable(lpEnvironment,
@ -371,7 +373,7 @@ CreateEnvironmentBlock (LPVOID *lpEnvironment,
/* Set 'USERPROFILE' variable */ /* Set 'USERPROFILE' variable */
Length = MAX_PATH; Length = MAX_PATH;
if (GetUserProfileDirectoryW (hToken, if (GetUserProfileDirectoryW(hToken,
Buffer, Buffer,
&Length)) &Length))
{ {
@ -396,20 +398,20 @@ CreateEnvironmentBlock (LPVOID *lpEnvironment,
/* Set user environment variables */ /* Set user environment variables */
SetUserEnvironment (lpEnvironment, SetUserEnvironment(lpEnvironment,
hKeyUser, hKeyUser,
L"Environment"); L"Environment");
RegCloseKey (hKeyUser); RegCloseKey(hKeyUser);
return TRUE; return TRUE;
} }
BOOL WINAPI BOOL WINAPI
DestroyEnvironmentBlock (LPVOID lpEnvironment) DestroyEnvironmentBlock(LPVOID lpEnvironment)
{ {
DPRINT ("DestroyEnvironmentBlock() called\n"); DPRINT("DestroyEnvironmentBlock() called\n");
if (lpEnvironment == NULL) if (lpEnvironment == NULL)
{ {
@ -417,7 +419,7 @@ DestroyEnvironmentBlock (LPVOID lpEnvironment)
return FALSE; return FALSE;
} }
RtlDestroyEnvironment (lpEnvironment); RtlDestroyEnvironment(lpEnvironment);
return TRUE; return TRUE;
} }