Unix::PasswdFile - Perl interface to /etc/passwd format files 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; 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.

commit( [BACKUPEXT] )
See the Unix::ConfigFile documentation for a description of this method.

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

encpass( PASSWORD )
See the Unix::ConfigFile documentation for a description of this method.

gecos( USERNAME [,GECOS] )
Read or modify a user's GECOS string (typically their full name). Returns the GECOS string in either case.

gid( USERNAME [,GID] )
Read or modify a user's GID. Returns the GID in either case.

home( USERNAME [,HOMEDIR] )
Read or modify a user's home directory. Returns the home directory in either case.

maxuid( [IGNORE] )
This method returns the maximum UID in use by all users. If you pass in the optional IGNORE parameter, it will ignore all UIDs greater or equal to IGNORE when doing this calculation. This is useful for excluding accounts like nobody.

new( FILENAME [,OPTIONS] )
See the Unix::ConfigFile documentation for a description of this method.

passwd( USERNAME [,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( OLDNAME, NEWNAME )
This method changes the username for a user. If NEWNAME corresponds to an existing user, that user will be overwritten. It returns 0 on failure and 1 on success.

shell( USERNAME [,SHELL] )
Read or modify a user's shell. Returns the shell in either case.

uid( USERNAME [,UID] )
Read or modify a user's UID. Returns the UID in either case.

user( USERNAME [,PASSWD, UID, GID, GECOS, HOMEDIR, SHELL] )
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 (PASSWORD, UID, GID, GECOS, HOMEDIR, SHELL), 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( [SORTBY] )
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 "name" as a parameter to the method to get the list sorted by username. In scalar context, this method returns the total number of users. Steve Snodgrass, ssnodgra@fore.com Unix::AliasFile, Unix::AutomountFile, Unix::ConfigFile, Unix::GroupFile