CfgTie::TieUser -- an associative array of user names and ids to information
makes the user database available as a regular hash.
tie %user,'CfgTie::TieUser' print "randym's full name: ", $user{'randym'}->{gcos}, "\n";
This is a straightforward hash tie that allows us to access the user database sanely.
It cross ties with the groups packages and the mail packages
There are two ties available for programmers:
tie %user,'CfgTie::TieUser'
$user{$name} will return a hash reference of the named user information.
$user{$name}
tie %user_id,'CfgTie::TieUser_id'
$user_id{$id} will return a hash reference for the specified user.
$user_id{$id}
Any given user entry has the following information associated with it (the keys are case-insensitive):
Name
Login name
GroupId
The principle group the user belongs to.
Id
The user id number that they have been assigned. It is possible for many different user names to be given the same id. However, changing the id for the user (i.e., setting it to a new one) has one of two effects. If user'Chg_FS is set 1, then all the files in the system owned by that id will changed to the new id in addition to changing the id in the system table. Otherwise, only the system table will be modified.
user'Chg_FS
Comment
Home
The user's home folder
LOGIN_Last
This is the information from the last time the user logged in. It is an array reference to data like:
[$time, $line, $from_host]
Shell
The user's shell
AuthMethod
The authentication method if other than the default. (Note: This can be set, but currently can't get fetched.)
ExpireDate
The date the account expires on. (Note: this can be set, but currently can't be fetched.)
Inactive
The number of days after a password expires. (Note: this can be set, but currently can't be fetched.)
Priority
The scheduling priority for that user. (Note: this requires that BSD::Resource be installed.)
BSD::Resource
Quota
RUsage
The process resource consumption by the user. Note: This requires that BSD::Resource be installed.
Returns a list reference of the form:
[$usertime, $systemtime, $maxrss, $ixrss, $idrss, $isrss, $minflt, $majflt, $nswap, $inblock, $oublock, $msgsnd, $msgrcv, $nsignals, $nvcsw, $nivcsw]
Plus two (probably) obsolete fields:
Password
This is the encrypted password, but will probably be obsolete.
GCOS
General Electric Comprehensive Operating System or General Comprehensive Operating System field
This is now the user's full name under many Unix's, incl. Linux.
Each of these entries can be modified (even deleted), and they will be reflected in the overall system. Additionally, the programmer can set any other associated key, but this information will only be available to the running Perl script.
&CfgTie::TieUser'stat()
&CfgTie::TieUser_id'stat()
Will return stat-like statistics information on the user database.
stat
Lets say you wanted to change the default HTML handling to a different method. To do this you need only include code like the following:
package CfgTie::TieUser_rec; sub HTML($) { my $self=shift; "<h1>".$Self->{name}."</h1>\n". "<table border=0><tr><th align=right>\n". join("</td></tr>\n<tr><th align=right>", map {$_."</th><td>".$self->{$_}} (sort keys %{$self}) </td></tr><lt></table>C<\n>"; }
If, instead, you wanted to add your own keys to the user records, CfgTie::TieUser::add_scalar($Name,$Package) Lets you add scalar keys to user records. The Name specifies the key name to be used; it will be made case-insensitve. The Package specifies the name of the package to be used when tie'ing the key to a value. (The TIESCALAR is passed the user id as a parameter).
CfgTie::TieUser::add_scalar(
)
TIESCALAR
CfgTie::TieUser::add_hash($Name,$Package) Lets you add hash keys to user records. The Name specifies the key name to be used; it will be made case insensitve. The Package specifies the name of the package to be used when tie'ing the key to a value. (The TIEHASH is passed the user id as a parameter).
CfgTie::TieUser::add_hash(
TIEHASH
$CfgTie::TieUser_rec'usermod contains the path to the program usermod. This can be modified as required.
$CfgTie::TieUser_rec'usermod
$CfgTie::TieUser_rec'useradd contains the path to the program useradd. This can be modified as required.
$CfgTie::TieUser_rec'useradd
$CfgTie::TieUser_rec'userdel contains the path to the program userdel. This can be modified as required.
$CfgTie::TieUser_rec'userdel
Not all keys are supported on all systems.
This may transparently use a shadow tie in the future.
/etc/passwd /etc/group /etc/shadow
CfgTie::Cfgfile, CfgTie::TieAliases, CfgTie::TieGeneric, CfgTie::TieGroup,CfgTie::TieHost, CfgTie::TieMTab, CfgTie::TieNamed,CfgTie::TieNet, CfgTie::TiePh, CfgTie::TieProto,CfgTie::TieRCService,CfgTie::TieRsrc, CfgTie::TieServ, CfgTie::TieShadow
group(5), passwd(5), shadow(5), usermod(8), useradd(8), userdel(8)
The current version does cache some user information.
Randall Maas (randym@acm.org)
To install Secure::File, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Secure::File
CPAN shell
perl -MCPAN -e shell install Secure::File
For more information on module installation, please visit the detailed CPAN module installation guide.