1:mod:`spwd` --- The shadow password database
2============================================
3
4.. module:: spwd
5   :platform: Unix
6   :synopsis: The shadow password database (getspnam() and friends).
7
8--------------
9
10This module provides access to the Unix shadow password database. It is
11available on various Unix versions.
12
13You must have enough privileges to access the shadow password database (this
14usually means you have to be root).
15
16Shadow password database entries are reported as a tuple-like object, whose
17attributes correspond to the members of the ``spwd`` structure (Attribute field
18below, see ``<shadow.h>``):
19
20+-------+---------------+---------------------------------+
21| Index | Attribute     | Meaning                         |
22+=======+===============+=================================+
23| 0     | ``sp_namp``   | Login name                      |
24+-------+---------------+---------------------------------+
25| 1     | ``sp_pwdp``   | Encrypted password              |
26+-------+---------------+---------------------------------+
27| 2     | ``sp_lstchg`` | Date of last change             |
28+-------+---------------+---------------------------------+
29| 3     | ``sp_min``    | Minimal number of days between  |
30|       |               | changes                         |
31+-------+---------------+---------------------------------+
32| 4     | ``sp_max``    | Maximum number of days between  |
33|       |               | changes                         |
34+-------+---------------+---------------------------------+
35| 5     | ``sp_warn``   | Number of days before password  |
36|       |               | expires to warn user about it   |
37+-------+---------------+---------------------------------+
38| 6     | ``sp_inact``  | Number of days after password   |
39|       |               | expires until account is        |
40|       |               | disabled                        |
41+-------+---------------+---------------------------------+
42| 7     | ``sp_expire`` | Number of days since 1970-01-01 |
43|       |               | when account expires            |
44+-------+---------------+---------------------------------+
45| 8     | ``sp_flag``   | Reserved                        |
46+-------+---------------+---------------------------------+
47
48The sp_namp and sp_pwdp items are strings, all others are integers.
49:exc:`KeyError` is raised if the entry asked for cannot be found.
50
51The following functions are defined:
52
53
54.. function:: getspnam(name)
55
56   Return the shadow password database entry for the given user name.
57
58   .. versionchanged:: 3.6
59      Raises a :exc:`PermissionError` instead of :exc:`KeyError` if the user
60      doesn't have privileges.
61
62.. function:: getspall()
63
64   Return a list of all available shadow password database entries, in arbitrary
65   order.
66
67
68.. seealso::
69
70   Module :mod:`grp`
71      An interface to the group database, similar to this.
72
73   Module :mod:`pwd`
74      An interface to the normal password database, similar to this.
75
76