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

python shouldn't need username in passwd database #58446

Closed
arekm mannequin opened this issue Mar 9, 2012 · 12 comments
Closed

python shouldn't need username in passwd database #58446

arekm mannequin opened this issue Mar 9, 2012 · 12 comments
Labels
easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@arekm
Copy link
Mannequin

arekm mannequin commented Mar 9, 2012

BPO 14238
Nosy @loewis, @birkenfeld, @arekm, @vstinner, @merwok
Superseder
  • bpo-10496: Python startup should not require passwd entry
  • Files
  • issue14238.patch
  • 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:

    assignee = None
    closed_at = <Date 2012-03-13.00:04:10.160>
    created_at = <Date 2012-03-09.09:21:59.509>
    labels = ['easy', 'type-bug', 'library']
    title = "python shouldn't need username in passwd database"
    updated_at = <Date 2012-03-13.00:07:40.829>
    user = 'https://github.com/arekm'

    bugs.python.org fields:

    activity = <Date 2012-03-13.00:07:40.829>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-03-13.00:04:10.160>
    closer = 'eric.araujo'
    components = ['Library (Lib)']
    creation = <Date 2012-03-09.09:21:59.509>
    creator = 'arekm'
    dependencies = []
    files = ['24800']
    hgrepos = []
    issue_num = 14238
    keywords = ['patch', 'easy', 'buildbot']
    message_count = 12.0
    messages = ['155215', '155216', '155218', '155279', '155465', '155486', '155488', '155493', '155494', '155499', '155529', '155531']
    nosy_count = 7.0
    nosy_names = ['loewis', 'georg.brandl', 'arekm', 'vstinner', 'nadeem.vawda', 'eric.araujo', 'aikinci']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '10496'
    type = 'behavior'
    url = 'https://bugs.python.org/issue14238'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

    @arekm
    Copy link
    Mannequin Author

    arekm mannequin commented Mar 9, 2012

    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'

    @arekm arekm mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Mar 9, 2012
    @nadeemvawda
    Copy link
    Mannequin

    nadeemvawda mannequin commented Mar 9, 2012

    This looks similar to a sporadic failure on the debian bigmem buildbot:

    http://www.python.org/dev/buildbot/all/builders/AMD64%20debian%20bigmem%203.x/builds/168/steps/test/logs/stdio

    ERROR: test_expanduser (test.test_posixpath.PosixPathTest)
    \----------------------------------------------------------------------
    
        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'

    @nadeemvawda nadeemvawda mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error and removed interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Mar 9, 2012
    @birkenfeld
    Copy link
    Member

    I agree -- there should be a guard here that just doesn't add user site directories if the lookup fails.

    @pitrou pitrou added the easy label Mar 9, 2012
    @merwok
    Copy link
    Member

    merwok commented Mar 10, 2012

    there should be a guard here that just doesn't add user site directories if the lookup fails.
    Agreed too. site is easy to fix (I can do it or review a patch), but we also need to fix sysconfig; I think the right thing to do would be not to have a config var named 'userbase' when run from a UID without passwd entry. This implies that the functions listed under http://docs.python.org/library/sysconfig#installation-paths would also need to omit *user schemes.

    @aikinci
    Copy link
    Mannequin

    aikinci mannequin commented Mar 12, 2012

    I have started to work on this.

    @aikinci
    Copy link
    Mannequin

    aikinci mannequin commented Mar 12, 2012

    This patch fixes the issue but needs review. It is my first patch ever so be nice :)

    @merwok
    Copy link
    Member

    merwok commented Mar 12, 2012

    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?

    @arekm
    Copy link
    Mannequin Author

    arekm mannequin commented Mar 12, 2012

    $  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'

    @vstinner
    Copy link
    Member

    See also the issue bpo-10496.

    @aikinci
    Copy link
    Mannequin

    aikinci mannequin commented Mar 12, 2012

    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.

    @merwok
    Copy link
    Member

    merwok commented Mar 13, 2012

    Indeed.

    @merwok merwok closed this as completed Mar 13, 2012
    @vstinner
    Copy link
    Member

    This patch fixes the issue but needs review.
    It is my first patch ever so be nice :)

    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants