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
python shouldn't need username in passwd database #58446
Comments
I'm trying to run python from UID which doesn't have entry in passwd database. This fails with: Traceback (most recent call last):
File "/usr/share/python2.7/site.py", line 567, in <module>
File "/usr/share/python2.7/site.py", line 549, in main
File "/usr/share/python2.7/site.py", line 278, in addusersitepackages
File "/usr/share/python2.7/site.py", line 253, in getusersitepackages
File "/usr/share/python2.7/site.py", line 243, in getuserbase
File "/usr/share/python2.7/sysconfig.py", line 522, in get_config_var
File "/usr/share/python2.7/sysconfig.py", line 426, in get_config_vars
File "/usr/share/python2.7/sysconfig.py", line 184, in _getuserbase
File "/usr/share/python2.7/sysconfig.py", line 171, in joinuser
File "/usr/share/python2.7/posixpath.py", line 260, in expanduser
KeyError: 'getpwuid(): uid not found: 51' |
This looks similar to a sporadic failure on the debian bigmem buildbot:
Traceback (most recent call last):
File "/var/tmpfs/martin.vonloewis/3.x.loewis-parallel2/build/Lib/test/test_posixpath.py", line 305, in test_expanduser
home = pwd.getpwuid(os.getuid()).pw_dir
KeyError: 'getpwuid(): uid not found: 5025' |
I agree -- there should be a guard here that just doesn't add user site directories if the lookup fails. |
|
I have started to work on this. |
This patch fixes the issue but needs review. It is my first patch ever so be nice :) |
Thanks you for your contribution! I hope you’ll find fun bugs to make patches for. Your patch looks too simplistic; in the discussion, we agreed that if the lookup fails, the site module should not add user site directories (see http://docs.python.org/library/site#site.USER_SITE or PEP-370), and your patch does not seem to do that. Moreover, this bug has repercussions on the sysconfig module (see my previous message), which needs edits too. BTW, I don’t know how we can test a patch for this bug; arekm, how do you run Python from a UID without passwd entry? |
$ LC_ALL=C sudo -u '#9999' -g '#9999' /bin/sh -c 'unset HOME ; python -c ""'
Traceback (most recent call last):
File "/usr/share/python2.7/site.py", line 567, in <module>
main()
File "/usr/share/python2.7/site.py", line 549, in main
known_paths = addusersitepackages(known_paths)
File "/usr/share/python2.7/site.py", line 278, in addusersitepackages
user_site = getusersitepackages()
File "/usr/share/python2.7/site.py", line 253, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/share/python2.7/site.py", line 243, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/share/python2.7/sysconfig.py", line 522, in get_config_var
return get_config_vars().get(name)
File "/usr/share/python2.7/sysconfig.py", line 426, in get_config_vars
_CONFIG_VARS['userbase'] = _getuserbase()
File "/usr/share/python2.7/sysconfig.py", line 184, in _getuserbase
return env_base if env_base else joinuser("~", ".local")
File "/usr/share/python2.7/sysconfig.py", line 171, in joinuser
return os.path.expanduser(os.path.join(*args))
File "/usr/share/python2.7/posixpath.py", line 260, in expanduser
userhome = pwd.getpwuid(os.getuid()).pw_dir
KeyError: 'getpwuid(): uid not found: 9999' |
See also the issue bpo-10496. |
I would suggest that this issue is the same as http://bugs.python.org/issue10496 like Victor pointed out and would say close it because it is a duplicate. |
Indeed. |
Python should not decide what is the default home directory. The issue is in the site module: I proposed nonexistent_user.patch in the issue bpo-10496 to fix the issue in the site module instead. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: