NAME
CfgTie::TieUser -- an associative array of user names and ids to information
SYNOPSIS
makes the user database available as a regular hash.
tie %user,'CfgTie::TieUser'
print "randym's full name: ", $user{'randym'}->{gcos}, "\n";
DESCRIPTION
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
Ties
There are two ties available for programmers:
tie %user,'CfgTie::TieUser'
-
$user{$name}
will return a hash reference of the named user information. tie %user_id,'CfgTie::TieUser_id'
-
$user_id{$id}
will return a hash reference for the specified user.
Structure of hash
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. 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.) 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.
Configuration Variables
Additional Routines
&CfgTie::TieUser'stat()
&CfgTie::TieUser_id'stat()
-
Will return
stat
-like statistics information on the user database.
Adding or overiding methods for user records
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_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).
Miscellaneous
$CfgTie::TieUser_rec'usermod
contains the path to the program usermod. This can be modified as required.
$CfgTie::TieUser_rec'useradd
contains the path to the program useradd. This can be modified as required.
$CfgTie::TieUser_rec'userdel
contains the path to the program userdel. This can be modified as required.
Not all keys are supported on all systems.
This may transparently use a shadow tie in the future.
When the changes are reflected to /etc/passwd
Files
/etc/passwd /etc/group /etc/shadow
See Also
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)
Caveats
The current version does cache some user information.
Author
Randall Maas (randym@acm.org)