#1146560 Confused in minimal environment lacking $USER and $LOGNAME

#1146560#5
Date:
2026-09-03 01:48:01 UTC
From:
To:
I happened to do pastebinit in a minimal container and was surprised it tried to len(None).
Here is a minimal recipe:

    bash5$ mmdebstrap forky /dev/null --quiet --include=pastebinit \
             --customize-hook='echo hello | chroot $1 env -i PATH=/bin pastebinit'
    Traceback (most recent call last):
      File "/bin/pastebinit", line 442, in <module>
        if len(user) > user_length:
           ~~~^^^^^^
    TypeError: object of type 'NoneType' has no len()

This is happening here:

            'user'      : os.environ.get('USER', os.environ.get('LOGNAME')),

Is it reasonable to do an NSS lookup as well, or instead?

            'user'      : os.environ.get('USER', os.environ.get('LOGNAME', pwd.getpwuid(os.geteuid()).pw_name)),

    bash5$ mmdebstrap forky /dev/null http://localhost:3142/debian --quiet --include=pastebinit --customize-hook='echo hello | chroot $1 env -i PATH=/bin python3 -c "import os, pwd; print(pwd.getpwuid(os.geteuid()).pw_name)"'
    root

    >>> import os, pwd
    >>> for k in os.environ: del os.environ[k]
    ...
    >>> os.environ.get('USER', os.environ.get('LOGNAME', pwd.getpwuid(os.geteuid()).pw_name))
    'twb'

If you strongly dislike this idea, just close this ticket.
I use pastebinit all the time, and this is the first time I've run into this, and
I can always use "-a Outis" as a workaround.