Issue 18787: Misleading error from getspnam function of spwd module (original) (raw)
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 "", line 1, in 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 "", line 1, in KeyError: 'getspnam(): name not found' spwd.getspnam("bin") Traceback (most recent call last): File "", line 1, in 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.