blob: 2c17d9e03641e08cabc4e0db2b8f595d1dda6b27 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`pwd` --- The password database
2====================================
3
4.. module:: pwd
5 :platform: Unix
6 :synopsis: The password database (getpwnam() and friends).
7
8
9This module provides access to the Unix user account and password database. It
10is available on all Unix versions.
11
12Password database entries are reported as a tuple-like object, whose attributes
13correspond to the members of the ``passwd`` structure (Attribute field below,
14see ``<pwd.h>``):
15
16+-------+---------------+-----------------------------+
17| Index | Attribute | Meaning |
18+=======+===============+=============================+
19| 0 | ``pw_name`` | Login name |
20+-------+---------------+-----------------------------+
21| 1 | ``pw_passwd`` | Optional encrypted password |
22+-------+---------------+-----------------------------+
23| 2 | ``pw_uid`` | Numerical user ID |
24+-------+---------------+-----------------------------+
25| 3 | ``pw_gid`` | Numerical group ID |
26+-------+---------------+-----------------------------+
27| 4 | ``pw_gecos`` | User name or comment field |
28+-------+---------------+-----------------------------+
29| 5 | ``pw_dir`` | User home directory |
30+-------+---------------+-----------------------------+
31| 6 | ``pw_shell`` | User command interpreter |
32+-------+---------------+-----------------------------+
33
34The uid and gid items are integers, all others are strings. :exc:`KeyError` is
35raised if the entry asked for cannot be found.
36
37.. note::
38
39 .. index:: module: crypt
40
41 In traditional Unix the field ``pw_passwd`` usually contains a password
42 encrypted with a DES derived algorithm (see module :mod:`crypt`). However most
43 modern unices use a so-called *shadow password* system. On those unices the
44 *pw_passwd* field only contains an asterisk (``'*'``) or the letter ``'x'``
45 where the encrypted password is stored in a file :file:`/etc/shadow` which is
46 not world readable. Whether the *pw_passwd* field contains anything useful is
47 system-dependent. If available, the :mod:`spwd` module should be used where
48 access to the encrypted password is required.
49
50It defines the following items:
51
52
53.. function:: getpwuid(uid)
54
55 Return the password database entry for the given numeric user ID.
56
57
58.. function:: getpwnam(name)
59
60 Return the password database entry for the given user name.
61
62
63.. function:: getpwall()
64
65 Return a list of all available password database entries, in arbitrary order.
66
67
68.. seealso::
69
70 Module :mod:`grp`
71 An interface to the group database, similar to this.
72
73 Module :mod:`spwd`
74 An interface to the shadow password database, similar to this.
75