* dcrt0.cc: Add load statements for `GetSidIdentifierAuthority'
and `RegLoadKeyA'. * registry.cc (get_registry_hive_path): New function. (load_registry_hive): Ditto. * security.cc (convert_sid_to_string_sid): New function. (get_ssid): Renamed to `convert_string_sid_to_sid'. (get_pw_sid): Call `convert_string_sid_to_sid' instead of `get_ssid'. (get_gr_sid): Ditto. (get_admin_sid): Ditto. (get_system_sid): Ditto. (get_creator_owner_sid): Ditto. (get_world_sid): Ditto. * shared.h: New prototypes for `get_registry_hive_path' and `load_registry_hive'. * spawn.cc (spawn_guts): Set child->psid to NULL to force calling `internal_getlogin' from child process in case of changing user context. Call `load_registry_hive' in case of changing user context. (_spawnve): Copy user infos only if user context remains the same. * uinfo.cc: Add load statement for `NetUserGetInfo'. Remove load statement for `NetGetDCName'. (internal_getlogin): Rewrite to speed up process startup and to correct user environment in case user context changes. (uinfo_init): Call internal_getlogin only if myself->psid is NULL, that is user context changes. * winsup.h: Add prototypes for `convert_sid_to_string_sid', `convert_string_sid_to_sid' and `get_pw_sid'.
This commit is contained in:
@@ -177,3 +177,57 @@ reg_key::~reg_key ()
|
||||
RegCloseKey (key);
|
||||
key_is_invalid = 1;
|
||||
}
|
||||
|
||||
char *
|
||||
get_registry_hive_path (const PSID psid, char *path)
|
||||
{
|
||||
char sid[256];
|
||||
char key[256];
|
||||
HKEY hkey;
|
||||
|
||||
if (!psid || !path)
|
||||
return NULL;
|
||||
convert_sid_to_string_sid (psid, sid);
|
||||
strcpy (key,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\");
|
||||
strcat (key, sid);
|
||||
if (!RegOpenKeyExA (HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hkey))
|
||||
{
|
||||
char buf[256];
|
||||
DWORD type, siz;
|
||||
|
||||
key[0] = '\0';
|
||||
if (!RegQueryValueExA (hkey, "ProfileImagePath", 0, &type,
|
||||
(BYTE *)buf, (siz = 256, &siz)))
|
||||
ExpandEnvironmentStringsA (buf, key, 256);
|
||||
RegCloseKey (hkey);
|
||||
if (key[0])
|
||||
return strcpy (path, key);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
load_registry_hive (PSID psid)
|
||||
{
|
||||
char sid[256];
|
||||
char path[256];
|
||||
HKEY hkey;
|
||||
|
||||
if (!psid)
|
||||
return;
|
||||
/* Check if user hive already exists */
|
||||
if (!RegOpenKeyExA (HKEY_LOCAL_MACHINE, convert_sid_to_string_sid (psid, sid),
|
||||
0, KEY_READ, &hkey))
|
||||
{
|
||||
debug_printf ("User registry hive for %s already exists", sid);
|
||||
RegCloseKey (hkey);
|
||||
return;
|
||||
}
|
||||
if (get_registry_hive_path (psid, path))
|
||||
{
|
||||
strcat (path, "\\NTUSER.DAT");
|
||||
if (RegLoadKeyA (HKEY_USERS, sid, path))
|
||||
debug_printf ("Loading user registry hive for %s failed: %E", sid);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user