[New-bugs-announce] [issue18787] Misleading error from getspnam function of spwd module

Vajrasky Kok report at bugs.python.org
Tue Aug 20 06:13:01 CEST 2013


New submission from Vajrasky Kok:

As root:

$ sudo python3
[sudo] password for ethan: 
Python 3.2.3 (default, Apr 10 2013, 05:07:54) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import spwd
>>> spwd.getspnam("I_don't_exist")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'getspnam(): name not found'
>>> spwd.getspnam("bin")
spwd.struct_spwd(sp_nam='bin', sp_pwd='*', sp_lstchg=15259, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)

As normal user:

$ python3
Python 3.2.3 (default, Apr 10 2013, 05:07:54) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import spwd
>>> spwd.getspnam("I_don't_exist")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'getspnam(): name not found'
>>> spwd.getspnam("bin")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'getspnam(): name not found'

People can be confused. How could the name not found if the name actually exists?

Attached the patch to differentiate the error whether the error is really 'name not found' or 'permission denied'.

I use the error message from the getspnam manual:
http://man7.org/linux/man-pages/man3/getspnam.3.html

There is another error message from getspnam beside EACCES (permission denied), which is ERANGE, but I don't think we need to handle this.

----------
components: Extension Modules
files: fix_error_message_getspnam.patch
keywords: patch
messages: 195678
nosy: vajrasky
priority: normal
severity: normal
status: open
title: Misleading error from getspnam function of spwd module
type: behavior
versions: Python 3.4
Added file: http://bugs.python.org/file31380/fix_error_message_getspnam.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18787>
_______________________________________


More information about the New-bugs-announce mailing list