Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{pwd} --- |
Fred Drake | f6863c1 | 1999-03-02 16:37:17 +0000 | [diff] [blame] | 2 | The password database} |
| 3 | |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 4 | \declaremodule{builtin}{pwd} |
Fred Drake | a54a887 | 1999-03-02 17:03:42 +0000 | [diff] [blame] | 5 | \platform{Unix} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 6 | \modulesynopsis{The password database (\function{getpwnam()} and friends).} |
| 7 | |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 8 | This module provides access to the \UNIX{} user account and password |
| 9 | database. It is available on all \UNIX{} versions. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 10 | |
Martin v. Löwis | 29001ff | 2002-03-01 10:47:37 +0000 | [diff] [blame] | 11 | Password database entries are reported as a tuple-like object, whose |
| 12 | attributes correspond to the members of the \code{passwd} structure |
| 13 | (Attribute field below, see \code{<pwd.h>}): |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 14 | |
Martin v. Löwis | 29001ff | 2002-03-01 10:47:37 +0000 | [diff] [blame] | 15 | \begin{tableiii}{r|l|l}{textrm}{Index}{Attribute}{Meaning} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 16 | \lineiii{0}{\code{pw_name}}{Login name} |
| 17 | \lineiii{1}{\code{pw_passwd}}{Optional encrypted password} |
| 18 | \lineiii{2}{\code{pw_uid}}{Numerical user ID} |
| 19 | \lineiii{3}{\code{pw_gid}}{Numerical group ID} |
| 20 | \lineiii{4}{\code{pw_gecos}}{User name or comment field} |
| 21 | \lineiii{5}{\code{pw_dir}}{User home directory} |
| 22 | \lineiii{6}{\code{pw_shell}}{User command interpreter} |
| 23 | \end{tableiii} |
| 24 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 25 | The uid and gid items are integers, all others are strings. |
Fred Drake | f6863c1 | 1999-03-02 16:37:17 +0000 | [diff] [blame] | 26 | \exception{KeyError} is raised if the entry asked for cannot be found. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 27 | |
Fred Drake | 0aa811c | 2001-10-20 04:24:09 +0000 | [diff] [blame] | 28 | \note{In traditional \UNIX{} the field \code{pw_passwd} usually |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 29 | contains a password encrypted with a DES derived algorithm (see module |
| 30 | \refmodule{crypt}\refbimodindex{crypt}). However most modern unices |
| 31 | use a so-called \emph{shadow password} system. On those unices the |
Skip Montanaro | c8c45c2 | 2005-03-02 04:29:23 +0000 | [diff] [blame^] | 32 | \var{pw_passwd} field only contains an asterisk (\code{'*'}) or the |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 33 | letter \character{x} where the encrypted password is stored in a file |
Skip Montanaro | c8c45c2 | 2005-03-02 04:29:23 +0000 | [diff] [blame^] | 34 | \file{/etc/shadow} which is not world readable. Whether the \var{pw_passwd} |
| 35 | field contains anything useful is system-dependent. If available, the |
| 36 | \module{spwd} module should be used where access to the encrypted password |
| 37 | is required.} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 38 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 39 | It defines the following items: |
| 40 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 41 | \begin{funcdesc}{getpwuid}{uid} |
| 42 | Return the password database entry for the given numeric user ID. |
| 43 | \end{funcdesc} |
| 44 | |
| 45 | \begin{funcdesc}{getpwnam}{name} |
| 46 | Return the password database entry for the given user name. |
| 47 | \end{funcdesc} |
| 48 | |
| 49 | \begin{funcdesc}{getpwall}{} |
| 50 | Return a list of all available password database entries, in arbitrary order. |
| 51 | \end{funcdesc} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 52 | |
| 53 | |
| 54 | \begin{seealso} |
| 55 | \seemodule{grp}{An interface to the group database, similar to this.} |
Martin v. Löwis | c300175 | 2005-01-23 09:27:24 +0000 | [diff] [blame] | 56 | \seemodule{spwd}{An interface to the shadow password database, similar to this.} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 57 | \end{seealso} |