Passwd::Unix
use Passwd::Unix; my $pu = Passwd::Unix->new(); my $err = $pu->user("example", $pu->encpass("my_secret"), $pu->maxuid + 1, 10, "My User", "/home/example", "/bin/bash" ); $pu->passwd("example", $pu->encpass("newsecret")); foreach my $user ($pu->users) { print "Username: $user\nFull Name: ", $pu->gecos($user), "\n\n"; } my $uid = $pu->uid('example'); $pu->del("example"); # or use Passwd::Unix qw(check_sanity reset encpass passwd_file shadow_file group_file backup warnings del del_user uid gid gecos home shell passwd rename maxgid maxuid exists_user exists_group user users users_from_shadow del_group group groups); my $err = user( "example", encpass("my_secret"), $pu->maxuid + 1, 10, "My User", "/home/example", "/bin/bash" ); passwd("example",encpass("newsecret")); foreach my $user (users()) { print "Username: $user\nFull Name: ", gecos($user), "\n\n"; } my $uid = uid('example'); del("example");
Passwd::Unix provides an abstract object-oriented and function interface to standard Unix files, such as /etc/passwd, /etc/shadow, /etc/group. Additionaly this module provides environment to testing new software, without using system critical files in /etc/dir.
The Passwd::Unix module provides an abstract interface to /etc/passwd, /etc/shadow and /etc/group format files. It is inspired by Unix::PasswdFile module (this one does not handle /etc/shadow file, what is necessary in modern systems like Sun Solaris 10 or Linux).
Constructor. Possible parameters are:
/etc/passwd
/etc/shadow
/etc/group
This method check if environment is sane. I.e. if users in shadow and in passwd are the same. This method is invoked in constructor.
This method is an alias for del_user. It's for transition only.
del_user
This method will delete the list of users. It has no effect if the supplied users do not exist.
This method will delete the list of groups. It has no effect if the supplied groups do not exist.
This method will encrypt plain text into unix style MD5 password.
Read or modify a user's GECOS string (typically their full name). Returns the result of operation (TRUE or FALSE) if GECOS was specified. Otherwhise returns the GECOS.
Read or modify a user's GID. Returns the result of operation (TRUE or FALSE) if GID was specified otherwhise returns the GID.
Read or modify a user's home directory. Returns the result of operation (TRUE or FALSE) if HOMEDIR was specified otherwhise returns the HOMEDIR.
This method returns the maximum UID in use by all users.
This method returns the maximum GID in use by all groups.
Read or modify a user's password. If you have a plaintext password, use the encpass method to encrypt it before passing it to this method. Returns the result of operation (TRUE or FALSE) if PASSWD was specified. Otherwhise returns the PASSWD.
This method changes the username for a user. If NEWNAME corresponds to an existing user, that user will be overwritten. It returns FALSE on failure and TRUE on success.
Read or modify a user's shell. Returns the result of operation (TRUE or FALSE) if SHELL was specified otherwhise returns the SHELL.
Read or modify a user's UID. Returns the result of operation (TRUE or FALSE) if UID was specified otherwhise returns the UID.
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.
This method can add, modify, or return information about a group. Supplied with a single groupname parameter, it will return a three element list consisting of (GID, ARRAYREF), where ARRAYREF is a ref to array consisting names of users in this GROUP, or undef if no such group exists. If you supply all three parameters, the named group will be created or modified if it already exists.
This method returns a list of all existing usernames.
This method returns a list of all existing groups.
This method checks if specified user exists. It returns TRUE or FALSE.
This method checks if specified group exists. It returns TRUE or FALSE.
This method, if called with an argument, sets path to the passwd file. Otherwise returns the current PATH.
This method, if called with an argument, sets path to the shadow file. Otherwise returns the current PATH.
This method, if called with an argument, sets path to the group file. Otherwise returns the current PATH.
This method sets paths to files passwd, shadow, group to the default values.
None known.
None. I hope.
BIG thanks to Artem Russakovskii for reporting a bug.
Strzelecki Łukasz <strzelec@rswsystems.com>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'Łukasz'. Assuming UTF-8
To install Passwd::Unix, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Passwd::Unix
CPAN shell
perl -MCPAN -e shell install Passwd::Unix
For more information on module installation, please visit the detailed CPAN module installation guide.