blob: c6cad2a3c32849fba0aef2c63d0c242809e06ae7 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`spwd` --- The shadow password database
2============================================
3
4.. module:: spwd
5 :platform: Unix
6 :synopsis: The shadow password database (getspnam() and friends).
7
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04008--------------
Georg Brandl116aa622007-08-15 14:28:22 +00009
Georg Brandl116aa622007-08-15 14:28:22 +000010This 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+=======+===============+=================================+
R David Murraybd90d092013-11-03 19:54:05 -050023| 0 | ``sp_namp`` | Login name |
Georg Brandl116aa622007-08-15 14:28:22 +000024+-------+---------------+---------------------------------+
R David Murraybd90d092013-11-03 19:54:05 -050025| 1 | ``sp_pwdp`` | Encrypted password |
Georg Brandl116aa622007-08-15 14:28:22 +000026+-------+---------------+---------------------------------+
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 |
R David Murraybd90d092013-11-03 19:54:05 -050040| | | disabled |
Georg Brandl116aa622007-08-15 14:28:22 +000041+-------+---------------+---------------------------------+
42| 7 | ``sp_expire`` | Number of days since 1970-01-01 |
R David Murraybd90d092013-11-03 19:54:05 -050043| | | when account expires |
Georg Brandl116aa622007-08-15 14:28:22 +000044+-------+---------------+---------------------------------+
45| 8 | ``sp_flag`` | Reserved |
46+-------+---------------+---------------------------------+
47
R David Murraybd90d092013-11-03 19:54:05 -050048The sp_namp and sp_pwdp items are strings, all others are integers.
Georg Brandl116aa622007-08-15 14:28:22 +000049:exc:`KeyError` is raised if the entry asked for cannot be found.
50
Georg Brandl7f01a132009-09-16 15:58:14 +000051The following functions are defined:
Georg Brandl116aa622007-08-15 14:28:22 +000052
53
54.. function:: getspnam(name)
55
56 Return the shadow password database entry for the given user name.
57
Berker Peksag3c3d7f42016-03-19 11:44:17 +020058 .. versionchanged:: 3.6
59 Raises a :exc:`PermissionError` instead of :exc:`KeyError` if the user
60 doesn't have privileges.
Georg Brandl116aa622007-08-15 14:28:22 +000061
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