* autoload.cc (CreateProfile): Import.

(LoadUserProfileW): Import.
	* registry.cc (get_registry_hive_path): Move to sec_auth.cc.
	(load_registry_hive): Remove.
	* registry.h (get_registry_hive_path): Drop declaration.
	(load_registry_hive): Ditto.
	* sec_auth.cc (get_user_profile_directory): Moved from registry.cc and
	renamed.  Take third parameter with buffer length.
	(load_user_profile): New function taking over for load_registry_hive.
	Use official functions to load profile.  If profile is missing, create
	it on Vista and later.
	* security.h (get_user_profile_directory): Declare.
	(load_user_profile): Declare.
	* syscalls.cc (seteuid32): Replace call to load_registry_hive with call
	to load_user_profile.
	* uinfo.cc (cygheap_user::env_userprofile): Replace call to
	get_registry_hive_path with call to get_user_profile_directory.
This commit is contained in:
Corinna Vinschen
2014-12-02 10:49:47 +00:00
parent 195a9205e5
commit 41f77e25f1
8 changed files with 145 additions and 109 deletions

View File

@ -1,7 +1,7 @@
/* registry.cc: registry interface
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
2007, 2008, 2009, 2010, 2011, 2012 Red Hat, Inc.
2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Red Hat, Inc.
This file is part of Cygwin.
@ -19,7 +19,6 @@ details. */
#include "tls_pbuf.h"
#include "ntdll.h"
#include <wchar.h>
#include <alloca.h>
/* Opens a key under the appropriate Cygwin key.
Do not use HKCU per MS KB 199190 */
@ -213,96 +212,3 @@ reg_key::~reg_key ()
NtClose (key);
key_is_invalid = 1;
}
/* The buffer path points to should be at least MAX_PATH bytes. */
PWCHAR
get_registry_hive_path (PCWSTR name, PWCHAR path)
{
if (!name || !path)
return NULL;
WCHAR key[256];
UNICODE_STRING buf;
tmp_pathbuf tp;
tp.u_get (&buf);
NTSTATUS status;
RTL_QUERY_REGISTRY_TABLE tab[2] = {
{ NULL, RTL_QUERY_REGISTRY_NOEXPAND | RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_REQUIRED,
L"ProfileImagePath", &buf, REG_NONE, NULL, 0 },
{ NULL, 0, NULL, NULL, 0, NULL, 0 }
};
wcpcpy (wcpcpy (key, L"ProfileList\\"), name);
status = RtlQueryRegistryValues (RTL_REGISTRY_WINDOWS_NT, key, tab,
NULL, NULL);
if (!NT_SUCCESS (status) || buf.Length == 0)
{
debug_printf ("ProfileImagePath for %W not found, status %y", name,
status);
return NULL;
}
ExpandEnvironmentStringsW (buf.Buffer, path, MAX_PATH);
debug_printf ("ProfileImagePath for %W: %W", name, path);
return path;
}
void
load_registry_hive (PCWSTR name)
{
if (!name)
return;
/* Fetch the path. Prepend native NT path prefix. */
tmp_pathbuf tp;
PWCHAR path = tp.w_get ();
if (!get_registry_hive_path (name, wcpcpy (path, L"\\??\\")))
return;
WCHAR key[256];
PWCHAR path_comp;
UNICODE_STRING ukey, upath;
OBJECT_ATTRIBUTES key_attr, path_attr;
NTSTATUS status;
/* Create keyname and path strings and object attributes. */
wcpcpy (wcpcpy (key, L"\\Registry\\User\\"), name);
RtlInitUnicodeString (&ukey, key);
InitializeObjectAttributes (&key_attr, &ukey, OBJ_CASE_INSENSITIVE,
NULL, NULL);
/* First try to load the "normal" registry hive, which is what the user
is supposed to see under HKEY_CURRENT_USER. */
path_comp = wcschr (path, L'\0');
wcpcpy (path_comp, L"\\ntuser.dat");
RtlInitUnicodeString (&upath, path);
InitializeObjectAttributes (&path_attr, &upath, OBJ_CASE_INSENSITIVE,
NULL, NULL);
status = NtLoadKey (&key_attr, &path_attr);
if (!NT_SUCCESS (status))
{
debug_printf ("Loading user registry hive %S into %S failed: %y",
&upath, &ukey, status);
return;
}
debug_printf ("Loading user registry hive %S into %S SUCCEEDED: %y",
&upath, &ukey, status);
/* If loading the normal hive worked, try to load the classes hive into
the sibling *_Classes subkey, which is what the user is supposed to
see under HKEY_CLASSES_ROOT, merged with the machine-wide classes. */
wcscat (key, L"_Classes");
RtlInitUnicodeString (&ukey, key);
/* Path to UsrClass.dat changed in Vista to
\\AppData\\Local\\Microsoft\\Windows\\UsrClass.dat
but old path is still available via symlinks. */
wcpcpy (path_comp, L"\\Local Settings\\Application Data\\Microsoft\\"
"Windows\\UsrClass.dat");
RtlInitUnicodeString (&upath, path);
/* Load UsrClass.dat file into key. */
status = NtLoadKey (&key_attr, &path_attr);
if (!NT_SUCCESS (status))
debug_printf ("Loading user classes hive %S into %S failed: %y",
&upath, &ukey, status);
else
debug_printf ("Loading user classes hive %S into %S SUCCEEDED: %y",
&upath, &ukey, status);
}