Eryk Sun <eryk...@gmail.com> added the comment:

> os.path.expanduser() has many flaws, and it just "guess" the 
> home directory for other users.

I'm fine with not guessing another user's profile directory (or home directory) 
in some cases, or even always. But the code that got committed bails out even 
if the target user is the same as the current user, according to the USERNAME 
environment variable. It shouldn't do that.

---

If we want something better than guessing, it's not very hard to get the real 
profile directory or home directory for another user on the current system. The 
profile directory is configured as the "ProfileImagePath" value in a subkey of 
"HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList". The subkey 
name is the user SID in string form. The SID can be looked up with 
LookupAccountNameW(NULL, target_user, &sid, ...) and converted to string form 
with ConvertSidToStringSidW(&sid, string_sid). If there's no local profile 
directory, try looking up the user's configured home_dir and/or home_dir_drive 
(a mapped drive for a remote home directory) via NetUserGetInfo(NULL, 
target_user, 4, &info).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39899>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to