| 1 |
:mod:`!pwd` --- The password database |
| 2 |
===================================== |
| 3 |
|
| 4 |
.. module:: pwd |
| 5 |
:synopsis: The password database (getpwnam() and friends). |
| 6 |
|
| 7 |
-------------- |
| 8 |
|
| 9 |
This module provides access to the Unix user account and password database. It |
| 10 |
is available on all Unix versions. |
| 11 |
|
| 12 |
.. availability:: Unix, not WASI, not iOS. |
| 13 |
|
| 14 |
Password database entries are reported as a tuple-like object, whose attributes |
| 15 |
correspond to the members of the ``passwd`` structure (Attribute field below, |
| 16 |
see ``<pwd.h>``): |
| 17 |
|
| 18 |
+-------+---------------+-----------------------------+ |
| 19 |
| Index | Attribute | Meaning | |
| 20 |
+=======+===============+=============================+ |
| 21 |
| 0 | ``pw_name`` | Login name | |
| 22 |
+-------+---------------+-----------------------------+ |
| 23 |
| 1 | ``pw_passwd`` | Optional encrypted password | |
| 24 |
+-------+---------------+-----------------------------+ |
| 25 |
| 2 | ``pw_uid`` | Numerical user ID | |
| 26 |
+-------+---------------+-----------------------------+ |
| 27 |
| 3 | ``pw_gid`` | Numerical group ID | |
| 28 |
+-------+---------------+-----------------------------+ |
| 29 |
| 4 | ``pw_gecos`` | User name or comment field | |
| 30 |
+-------+---------------+-----------------------------+ |
| 31 |
| 5 | ``pw_dir`` | User home directory | |
| 32 |
+-------+---------------+-----------------------------+ |
| 33 |
| 6 | ``pw_shell`` | User command interpreter | |
| 34 |
+-------+---------------+-----------------------------+ |
| 35 |
|
| 36 |
The uid and gid items are integers, all others are strings. :exc:`KeyError` is |
| 37 |
raised if the entry asked for cannot be found. |
| 38 |
|
| 39 |
.. note:: |
| 40 |
|
| 41 |
In traditional Unix the field ``pw_passwd`` usually contains a password |
| 42 |
encrypted with a DES derived algorithm. 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. |
| 48 |
|
| 49 |
It defines the following items: |
| 50 |
|
| 51 |
|
| 52 |
.. function:: getpwuid(uid) |
| 53 |
|
| 54 |
Return the password database entry for the given numeric user ID. |
| 55 |
|
| 56 |
|
| 57 |
.. function:: getpwnam(name) |
| 58 |
|
| 59 |
Return the password database entry for the given user name. |
| 60 |
|
| 61 |
|
| 62 |
.. function:: getpwall() |
| 63 |
|
| 64 |
Return a list of all available password database entries, in arbitrary order. |
| 65 |
|
| 66 |
|
| 67 |
.. seealso:: |
| 68 |
|
| 69 |
Module :mod:`grp` |
| 70 |
An interface to the group database, similar to this. |