This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author astrand
Recipients astrand
Date 2008-11-05.08:19:19
SpamBayes Score 5.0071515e-07
Marked as misclassified No
Message-id <1225873162.85.0.693443096685.issue4261@psf.upfronthosting.co.za>
In-reply-to
Content
The getpwnam function in the pwd module does not correctly distinguish
between the case when the user does not exist and error
conditions. getpwnam() returns NULL in both cases, the the calling
code needs to check errno to determine if an error occured or not. 

This bug is problematic in conjunction with bug
https://bugzilla.redhat.com/show_bug.cgi?id=470003, since it means
that Pythons getpwnam() will sometimes raise KeyError even for valid
users. How to reproduce:

$ python
Python 2.4.3 (#1, Jan 14 2008, 18:32:40)
[GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pwd
>>> pwd.getpwnam("astrand")
('astrand', '*', 164, 20164, 'Peter Astrand', '/home/astrand', '/bin/bash')
>>>
>>> pwd.getpwnam("astrand")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
KeyError: 'getpwnam(): name not found: astrand'
>>>
>>> pwd.getpwnam("astrand")
('astrand', '*', 164, 20164, 'Peter Astrand', '/home/astrand', '/bin/bash')
>>>

I was restarting the OpenLDAP server between the first successful call
and the traceback one.
History
Date User Action Args
2008-11-05 08:19:23astrandsetrecipients: + astrand
2008-11-05 08:19:22astrandsetmessageid: <1225873162.85.0.693443096685.issue4261@psf.upfronthosting.co.za>
2008-11-05 08:19:21astrandlinkissue4261 messages
2008-11-05 08:19:19astrandcreate