2007-08-15 11:28:22 -03:00
|
|
|
:mod:`pwd` --- The password database
|
|
|
|
====================================
|
|
|
|
|
|
|
|
.. module:: pwd
|
|
|
|
:platform: Unix
|
|
|
|
:synopsis: The password database (getpwnam() and friends).
|
|
|
|
|
2016-06-11 16:02:54 -03:00
|
|
|
--------------
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
This module provides access to the Unix user account and password database. It
|
|
|
|
is available on all Unix versions.
|
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. include:: ../includes/wasm-notavail.rst
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
Password database entries are reported as a tuple-like object, whose attributes
|
|
|
|
correspond to the members of the ``passwd`` structure (Attribute field below,
|
|
|
|
see ``<pwd.h>``):
|
|
|
|
|
|
|
|
+-------+---------------+-----------------------------+
|
|
|
|
| Index | Attribute | Meaning |
|
|
|
|
+=======+===============+=============================+
|
|
|
|
| 0 | ``pw_name`` | Login name |
|
|
|
|
+-------+---------------+-----------------------------+
|
|
|
|
| 1 | ``pw_passwd`` | Optional encrypted password |
|
|
|
|
+-------+---------------+-----------------------------+
|
|
|
|
| 2 | ``pw_uid`` | Numerical user ID |
|
|
|
|
+-------+---------------+-----------------------------+
|
|
|
|
| 3 | ``pw_gid`` | Numerical group ID |
|
|
|
|
+-------+---------------+-----------------------------+
|
|
|
|
| 4 | ``pw_gecos`` | User name or comment field |
|
|
|
|
+-------+---------------+-----------------------------+
|
|
|
|
| 5 | ``pw_dir`` | User home directory |
|
|
|
|
+-------+---------------+-----------------------------+
|
|
|
|
| 6 | ``pw_shell`` | User command interpreter |
|
|
|
|
+-------+---------------+-----------------------------+
|
|
|
|
|
|
|
|
The uid and gid items are integers, all others are strings. :exc:`KeyError` is
|
|
|
|
raised if the entry asked for cannot be found.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
In traditional Unix the field ``pw_passwd`` usually contains a password
|
2023-05-25 10:45:46 -03:00
|
|
|
encrypted with a DES derived algorithm. However most
|
2007-08-15 11:28:22 -03:00
|
|
|
modern unices use a so-called *shadow password* system. On those unices the
|
|
|
|
*pw_passwd* field only contains an asterisk (``'*'``) or the letter ``'x'``
|
|
|
|
where the encrypted password is stored in a file :file:`/etc/shadow` which is
|
|
|
|
not world readable. Whether the *pw_passwd* field contains anything useful is
|
2023-05-24 17:34:41 -03:00
|
|
|
system-dependent.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
It defines the following items:
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: getpwuid(uid)
|
|
|
|
|
|
|
|
Return the password database entry for the given numeric user ID.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: getpwnam(name)
|
|
|
|
|
|
|
|
Return the password database entry for the given user name.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: getpwall()
|
|
|
|
|
|
|
|
Return a list of all available password database entries, in arbitrary order.
|
|
|
|
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
Module :mod:`grp`
|
|
|
|
An interface to the group database, similar to this.
|