Skip to content

git_user_id should returnt he EUID #1577

Closed as not planned
Closed as not planned
@b4ldr

Description

@b4ldr

i think that git.utils.get_user_id should return the Effective user and not the. currently the function uses getpass.getuser() which relies on environment variables and not getuid/geteuid functions, from the docs

checks the environment variables LOGNAME, USER, LNAME and USERNAME, in order, and returns the value of the first one which is set to a non-empty string. If none are set, the login name from the password database is returned on systems which support the pwd module, otherwise, an exception is raised.
with the following code

import git
import os
import pwd
import shutil
from git.util import get_user_id
from pathlib import Path

CHECKOUT = Path("/tmp/gist")
shutil.rmtree(CHECKOUT, ignore_errors=True)
ORIGIN_REPO = "https://gist.github.com/b4ldr/449d490b43fb3d2d01a74d28bc9a41e4"
os.seteuid(pwd.getpwnam('jbond').pw_uid)
euid = pwd.getpwuid(os.geteuid()).pw_name
print(f"git.utils.get_user_id: {get_user_id()}")
print(f"euid: {euid}")
repo = git.Repo.clone_from(ORIGIN_REPO, CHECKOUT)
print(f"directory owner: {CHECKOUT.owner()}")

When run as root we get the following output

$ sudo python -i git_test.py                                                                  
git user id: root@storage
euid: jbond
directory owner: jbond

i think it would be more useful if gitpython returned the user matching the EUID e.g. pwd.getpwuid(os.geteuid()).pw_name)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions