New submission from Peter Åstrand <[EMAIL PROTECTED]>: 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. ---------- components: Library (Lib) messages: 75516 nosy: astrand severity: normal status: open title: The pwd module doesn't distinguish between errors and no user type: behavior versions: Python 2.4 _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue4261> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com