![]() |
![]() |
![]() |
||
|
|
||||
|
NAME
MATT::Passwd - Common Unix Passwd functions
SYNOPSISMATT::Passwd is a grouping of frequently used functions I've written for interacting with /etc/passwd entries.
DESCRIPTION
DEPENDENCIESCrypt::PasswdMD5 - /usr/ports/security/p5-Crypt-PasswdMD5
UserSanity
use MATT::Passwd;
$r = UserSanity($user, $denylist);
if ( $r->{'rc'} ) { print "success" }
else { print $r->{'error' };
$user is the username. Pass it along as a scalar (string). $denylist is a optional hashref. Define all usernames you want reserved (denied) and it'll check to make sure $user is not in the hashref. Checks:
* Usernames must be between 2 and 16 characters.
* Usernames must have only lower alpha and numeric chars
* Username must not be defined in $denylist hash
* If the file /usr/local/etc/passwd.reserved exists,
the username must not exist in that file.
The format of passwd.reserved is simply one username per line. A hashref ($r) gets returned that will contain at least rc, and error. $r->{'rc'} will contain a result code of 0 (failure) or 1 (success). $r->{'error'} will contain a string with a description of which test failed.
PasswordSanity
use MATT::Passwd;
$r = PasswordSanity($password, $username);
if ( $r->{'rc'} ) { print "success" }
else { print $r->{'error' };
$password is the password the user is attempting to use. $username is the username the user has selected. Checks:
Passwords must have at least 6 characters.
Passwords must have no more than 128 characters.
Passwords must not be the same as the username
Passwords must not be purely alpha or purely numeric
Passwords must not be in reserved list
(/usr/local/etc/passwd.badpass)
$r is a hashref that gets returned. $r->{'rc'} will contain a result code of 0 (failure) or 1 (success). $r->{'error'} will contain a string with a description of which test failed.
DoesSysUserExist
use MATT::Passwd;
if ( DoesSysUserExist($user) ) {
InstallUser($user);
};
$user is the username you are adding. This function merely checks to see if the user exists in the system password files. I use this before adding a new user (easy error trapping) and again after adding a user (to verify success).
Encrypt
Encrypt ($pass, $debug)
Encrypt (MD5) the plain text password that arrives at $pass.
BackupMasterPasswd
BackupMasterPasswd ($file)
Back up the /etc/master.passwd database. This copies $file to a new file named $file.nnnnnn with nnnnnn being a date/timestamp.
VerifyMasterPasswd
VerifyMasterPasswd ($passwd, $change, $debug)
Verify that new master.passwd is the right size. I found this necessary on some versions of FreeBSD as a race condition would cause the master.passwd file to get corrupted. Now I verify that after I'm finished making my changes, the new file is a small amount larger (or smaller) than the original. $passwd is the filename of your master.passwd file. $change is whether the file should ``shrink'' or ``grow''
InstallGroup
InstallGroup ($group, $gid)
Installs a system group. The $gid is optional.
InstallUser
InstallUser ($user, $shell, $homedir, $uid, $gid, $passwd)
Installs a system user. The $shell and $homedir variables are optional.
AUTHOR
Matt Simerson <matt@cadillac.net>
BUGS
None known. Report any to author.
TODODon't export any of the symbols by default. Move all symbols to EXPORT_OK and explicitely pull in the required ones in programs that need them.
SEE ALSO
http://www.tnpi.biz/internet/
http://www.tnpi.biz/computing/
MATT::Apache, MATT::DNS, MATT::FreeBSD, MATT::Mysql, MATT::Passwd, MATT::Perl, MATT::Qmail, MATT::Quota MATT::SSL, MATT::Utility
COPYRIGHTCopyright 2003, The Network People, Inc. All Rights Reserved. |
|
||||||||||||||||||||||||||||