SYNOPSIS

  use Unix::PasswdFile;

  $pw = new Unix::PasswdFile "/etc/passwd";
  $pw->user("joeblow", $pw->encpass("secret"), $pw->maxuid + 1, 10,
            "Joe Blow", "/export/home/joeblow", "/bin/ksh");
  $pw->delete("deadguy");
  $pw->passwd("johndoe", $pw->encpass("newpass"));
  foreach $user ($pw->users) {
      print "Username: $user, Full Name: ", $pw->gecos($user), "\n";
  }
  $pw->commit();
  undef $pw;

DESCRIPTION

The Unix::PasswdFile module provides an abstract interface to /etc/passwd format files. It automatically handles file locking, getting colons in the right places, and all the other niggling details.

METHODS

commit( [\s-1BACKUPEXT\s0] )

See the Unix::ConfigFile documentation for a description of this method.

delete( \s-1USERNAME\s0 )

This method will delete the named user. It has no effect if the supplied user does not exist.

encpass( \s-1PASSWORD\s0 )

See the Unix::ConfigFile documentation for a description of this method.

gecos( \s-1USERNAME\s0 [,GECOS] )

Read or modify a user's \s-1GECOS\s0 string (typically their full name). Returns the \s-1GECOS\s0 string in either case.

gid( \s-1USERNAME\s0 [,GID] )

Read or modify a user's \s-1GID\s0. Returns the \s-1GID\s0 in either case.

home( \s-1USERNAME\s0 [,HOMEDIR] )

Read or modify a user's home directory. Returns the home directory in either case.

maxuid( [\s-1IGNORE\s0] )

This method returns the maximum \s-1UID\s0 in use by all users. If you pass in the optional \s-1IGNORE\s0 parameter, it will ignore all UIDs greater or equal to \s-1IGNORE\s0 when doing this calculation. This is useful for excluding accounts like nobody.

new( \s-1FILENAME\s0 [,OPTIONS] )

See the Unix::ConfigFile documentation for a description of this method.

passwd( \s-1USERNAME\s0 [,PASSWD] )

Read or modify a user's password. Returns the encrypted password in either case. If you have a plaintext password, use the encpass method to encrypt it before passing it to this method.

rename( \s-1OLDNAME\s0, \s-1NEWNAME\s0 )

This method changes the username for a user. If \s-1NEWNAME\s0 corresponds to an existing user, that user will be overwritten. It returns 0 on failure and 1 on success.

shell( \s-1USERNAME\s0 [,SHELL] )

Read or modify a user's shell. Returns the shell in either case.

uid( \s-1USERNAME\s0 [,UID] )

Read or modify a user's \s-1UID\s0. Returns the \s-1UID\s0 in either case.

user( \s-1USERNAME\s0 [,PASSWD, \s-1UID\s0, \s-1GID\s0, \s-1GECOS\s0, \s-1HOMEDIR\s0, \s-1SHELL\s0] )

This method can add, modify, or return information about a user. Supplied with a single username parameter, it will return a six element list consisting of (\s-1PASSWORD\s0, \s-1UID\s0, \s-1GID\s0, \s-1GECOS\s0, \s-1HOMEDIR\s0, \s-1SHELL\s0), or undef if no such user exists. If you supply all seven parameters, the named user will be created or modified if it already exists. The six element list is also returned to you in this case.

users( [\s-1SORTBY\s0] )

This method returns a list of all existing usernames. By default the list will be sorted in order of the UIDs of the users. You may also supply \*(L"name\*(R" as a parameter to the method to get the list sorted by username. In scalar context, this method returns the total number of users.

AUTHOR

Steve Snodgrass, [email protected]

RELATED TO Unix::PasswdFile…

Unix::AliasFile, Unix::AutomountFile, Unix::ConfigFile, Unix::GroupFile