Password File Module

This module makes handling password and group files easier. They are referred to here as "entry files," which are flat files consisting of colon (:) separated fields. The first field is the key field and all others are data.

The load(fname), loadpw(fname), and loadgrp(fname) functions are used to read these files. load() returns a mapping (OrdDict) of Ent objects, which have the following members:

  .seq() Returns the list of data values

loadpw() loads a password file (/etc/passwd by default) and returns an OrdDict of PWEnt objects, which have the following members:

  .passwd Encrypted Password
.uid Numeric User ID
.gid Numeric Group ID
.comment Comment (GECOS field)
.home Home Directory
.shell Command Shell
.seq() Returns the list of data values:
  [ passwd, uid, gid, comment, home, shell ]

loadgrp() loads a group file (/etc/group by default) and returns an OrdDict of GrpEnt objects, which have the following members:

  .passwd Encrypted Password
.gid Numeric Group ID
.users List of Member Users
.seq() Returns the list of data values:
  [ passwd, gid, users ]
  (users is converted to a comma-separated string)

save() saves the given mapping of Ent-like objects to the given file. The .seq() of each entry is called, the result joined with colons, and then written to the file as a line. save() can handle any string-keyed mapping of objects which have a proper .seq() method.

genpw() generates a new encrypted password (with a random salt) for use in creating new password entries.

ckpw() checks the given plaintext password against the given cyphertext password; returns true on a match, false otherwise.

 


Installation:

passwd.py contains an internal Distutils-based installer; just run:

python passwd.py install

(as root/Administrator if needed) and you're done.


Comments