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.
Created on 2013年04月09日 13:28 by Alexqw, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg186402 - (view) | Author: Alex Waite (Alexqw) | Date: 2013年04月09日 13:28 | |
spwd uses -1 rather than '' for empty attributes. This is different from the behaviour in the pwd module, and makes it more difficult to generate a new, valid shadow entry.
In my opinion, simply doing a ':'.join(str(val) for val in rec) should result in a valid entry. With pwd this is currently possible. Not so with spwd.
pwd:
import pwd
rec = pwd.getpwnam('alex')
print ':'.join(str(val) for val in rec)
spwd:
import spwd
rec = spwd.getspnam('alex')
shdw = ''
for idx, val in enumerate(recs_shdw):
if idx != 0:
shdw += ':'
if val != -1:
shdw += str(val)
print shdw
|
|||
| msg186670 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2013年04月12日 19:39 | |
The docs for pwd and spwd modules specify that some items are strings and others are ints. Null strings should be '' and 'null' ints must be negative since 0 can be a valid item. It happens that all but 2 pwd items are strings and all but 2 spwd items are ints. The 2 pwd int items are uid and gid, which I believe are never missing, so you never encounter -1 for them. Similarly, the 2 spwd str items are nam and pwd, which I believe are not missing either, so you never encounter '' for them. Otherwise, your val != -1 test would not work. I believe the following expression will work for spwd (and even pwd) (I cannot test on Windows ;-). ':'.join((str(val) if val != -1 else '') for val in rec) |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:44 | admin | set | github: 61876 |
| 2013年04月12日 19:39:16 | terry.reedy | set | status: open -> closed nosy: + terry.reedy messages: + msg186670 resolution: not a bug |
| 2013年04月09日 13:28:48 | Alexqw | create | |