This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients barneygale, eryksun, serhiy.storchaka, steve.dower
Date 2021-04-08.08:01:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1617868900.31.0.288862209116.issue39899@roundup.psfhosted.org>
In-reply-to
Content
> 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).
History
Date User Action Args
2021-04-08 08:01:40eryksunsetrecipients: + eryksun, serhiy.storchaka, steve.dower, barneygale
2021-04-08 08:01:40eryksunsetmessageid: <1617868900.31.0.288862209116.issue39899@roundup.psfhosted.org>
2021-04-08 08:01:40eryksunlinkissue39899 messages
2021-04-08 08:01:40eryksuncreate