[New-bugs-announce] [issue18678] Wrong struct members name for spwd module

Vajrasky Kok report at bugs.python.org
Wed Aug 7 16:50:00 CEST 2013

New submission from Vajrasky Kok:

Both python2 and python3 have this behaviour.

>>> import os; os.getuid()
>>> 'I am root'
'I am root'
>>> import spwd
>>> spwd.getspnam('bin')
spwd.struct_spwd(sp_nam='bin', sp_pwd='*', sp_lstchg=15558, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
>>> spwd.getspnam.__doc__
'getspnam(name) -> (sp_namp, sp_pwdp, sp_lstchg, sp_min, sp_max,\n                    sp_warn, sp_inact, sp_expire, sp_flag)\nReturn the shadow password database entry for the given user name.\nSee spwd.__doc__ for more on shadow password database entries.'

The documentation tells the function getspnam will give struct which has member sp_namp and sp_pwdp. But as you can see, the function getspnam gives me a tuple with has member sp_nam (without p) and sp_pwd (without p).

If you "man spwd", you can see the documentation is correct:
       The shadow password structure is defined in <shadow.h> as follows:

           struct spwd {
               char *sp_namp;     /* Login name */
               char *sp_pwdp;     /* Encrypted password */
               long  sp_lstchg;   /* Date of last change (measured
                                     in days since 1970-01-01 00:00:00 +0000 (UTC)) */
               long  sp_min;      /* Min # of days between changes */
               long  sp_max;      /* Max # of days between changes */
               long  sp_warn;     /* # of days before password expires
                                     to warn user to change it */
               long  sp_inact;    /* # of days after password expires
                                     until account is disabled */
               long  sp_expire;   /* Date when account expires (measured
                                     in days since 1970-01-01 00:00:00 +0000 (UTC)) */
               unsigned long sp_flag;  /* Reserved */

For curious souls who do not have unix box:

I have contemplated about whether this behaviour is intended as it is, but I guess this is just a bug. Typo.

Attached the patch to fix this inconsistency. I also fixed some documentation about sp_inact and sp_expire.

I only marked this as Python 3.4 fix because I am not sure whether we should backport it to previous python versions. Some programs that expect sp_nam and sp_pwd names could break.

components: Extension Modules
files: spwd_struct_members_name_fix.patch
keywords: patch
messages: 194618
nosy: vajrasky
priority: normal
severity: normal
status: open
title: Wrong struct members name for spwd module
type: behavior
versions: Python 3.4
Added file: http://bugs.python.org/file31183/spwd_struct_members_name_fix.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list