os.path.expanduser ignores os.seteuid
Sean 'Shaleh' Perry
shalehperry at attbi.com
Tue Jun 4 20:38:33 CEST 2002
On 04-Jun-2002 Graham Guttocks wrote:
> Why doesn't os.path.expanduser pay attention to the fact that I've
> changed the process's effective user id?
> As root:
> Python 2.1.3 (#1, Apr 11 2002, 18:30:30)
> [GCC 2.95.3 20010315 (release) [FreeBSD]] on freebsd4
> Type "copyright", "credits" or "license" for more information.
>>>> import os
> Other functions like os.getlogin() don't have this problem.
"""Expand ~ and ~user constructions. If user or $HOME is unknown,
if path[:1] != '~':
i, n = 1, len(path)
while i < n and path[i] != '/':
i = i + 1
if i == 1:
if not os.environ.has_key('HOME'):
userhome = os.environ['HOME']
pwent = pwd.getpwnam(path[1:i])
userhome = pwent
if userhome[-1:] == '/': i = i + 1
return userhome + path[i:]
is from python 2.2. It uses short circuit eval for the '~' case and simply
reads the environment $HOME. If you could pass '~user/' it would give you the
answer you want.
More information about the Python-list