Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.homedir() doesn't respect setuid #28281

Closed
neuroscr opened this issue Jun 18, 2019 · 5 comments
Closed

os.homedir() doesn't respect setuid #28281

neuroscr opened this issue Jun 18, 2019 · 5 comments
Labels
doc Issues and PRs related to the documentations. os Issues and PRs related to the os subsystem.

Comments

@neuroscr
Copy link

Expected os.homedir() to home directory of the current user as a string but when the current user changes via process.setuid() this directory still show the original user's home directory

@Trott
Copy link
Member

Trott commented Jun 18, 2019

Expected os.homedir() to home directory of the current user as a string but when the current user changes via process.setuid() this directory still show the original user's home directory

I understand the expectation, but at the same time, I would expect the opposite behavior--that changing the uid does not affect the home directory. Other languages seem to bear this out. Here's Python being run initially as root and then changing to an unprivileged user with a different home directory:

Python 2.7.10 (default, Feb 22 2019, 21:55:15) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> from os.path import expanduser
>>> expanduser("~")
'/var/root'
>>> os.setuid(501)
>>> expanduser("~")
'/var/root'

Perhaps relevant explanation about why sudo preserves the home directory by default rather than adopting the home directory of the privileged user: https://askubuntu.com/a/338449/112895

@neuroscr
Copy link
Author

if that's the case, at least the documentation on os.homedir() should be updated to be precise and reflect that; save some other coders some time

(why didn't I think of the ~username trick...)

@addaleax addaleax added doc Issues and PRs related to the documentations. os Issues and PRs related to the os subsystem. labels Jun 19, 2019
@juanarbol
Copy link
Member

Take a look to his PR #28401

@cclauss
Copy link
Contributor

cclauss commented Aug 14, 2019

Did this issue get resolved?

@bnoordhuis
Copy link
Member

The PR was merged so yes, this was indeed resolved. Closing, thanks for the ping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. os Issues and PRs related to the os subsystem.
Projects
None yet
Development

No branches or pull requests

6 participants