CfgTie

 view release on metacpan or  search on metacpan

lib/CfgTie/TieUser.pm  view on Meta::CPAN

=item C<ExpireDate>

The date the account expires on.
(Note: this can be set, but currently can't be fetched.)

=item C<Inactive>

The number of days after a password expires.
(Note: this can be set, but currently can't be fetched.)

=item C<Priority>

The scheduling priority for that user.
(Note: this requires that C<BSD::Resource> be installed.)

=item C<Quota>

=item C<RUsage>

The process resource consumption by the user.
Note: This requires that C<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]

=back


Plus two (probably) obsolete fields:

=over 1

=item C<Password>

This is the encrypted password, but will probably be obsolete.

=item C<GCOS>

I<General Electric Comprehensive Operating System> or
I<General Comprehensive Operating System>
field

This is now the user's full name under many Unix's, incl. Linux.

=back

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.

=head2 Configuration Variables

=head2 Additional Routines

=over 1

=item C<&CfgTie::TieUser'stat()>

=item C<&CfgTie::TieUser_id'stat()>

Will return C<stat>-like statistics information on the user database.

=back

=head2 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, 
C<CfgTie::TieUser::add_scalar(>I<$Name>,I<$Package>C<)>
Lets you add scalar keys to user records.  The I<Name> specifies the key name
to be used; it will be made case-insensitve.  The I<Package> specifies the name
of the package to be used when tie'ing the key to a value.  (The C<TIESCALAR>
is passed the user id as a parameter).

C<CfgTie::TieUser::add_hash(>I<$Name>,I<$Package>C<)>
Lets you add hash keys to user records.  The I<Name> specifies the key name
to be used; it will be made case insensitve.  The I<Package> specifies the name
of the package to be used when tie'ing the key to a value.  (The C<TIEHASH>
is passed the user id as a parameter).

=head2 Miscellaneous

C<$CfgTie::TieUser_rec'usermod> contains the path to the program F<usermod>.
This can be modified as required.

C<$CfgTie::TieUser_rec'useradd> contains the path to the program F<useradd>.
This can be modified as required.

C<$CfgTie::TieUser_rec'userdel> contains the path to the program F<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.

=head2 When the changes are reflected to /etc/passwd

=head1 Files

F</etc/passwd>
F</etc/group>
F</etc/shadow>

=head1 See Also

L<CfgTie::Cfgfile>, L<CfgTie::TieAliases>,  L<CfgTie::TieGeneric>,
L<CfgTie::TieGroup>,L<CfgTie::TieHost>,     L<CfgTie::TieMTab>,
L<CfgTie::TieNamed>,L<CfgTie::TieNet>,      L<CfgTie::TiePh>,
L<CfgTie::TieProto>,L<CfgTie::TieRCService>,L<CfgTie::TieRsrc>,
L<CfgTie::TieServ>, L<CfgTie::TieShadow>

L<group(5)>,
L<passwd(5)>,
L<shadow(5)>,
L<usermod(8)>,
L<useradd(8)>,
L<userdel(8)>

=head1 Caveats

The current version does cache some user information.

=head1 Author

Randall Maas (L<randym@acm.org>)

=cut

my $Chg_FS = 1; #By default we want to update the file system when the user
# Id changes

sub stat($)
{
  # the information for the /etc/passwd file
  stat '/etc/passwd';
}

sub TIEHASH
{
   my $self = shift;
   my $node = {};
   return bless $node, $self;
}

sub FIRSTKEY
{
   my $self = shift;

   #Rewind outselves to the beginning.
   setpwent;

   &NEXTKEY($self);
}

sub NEXTKEY
{
   my $self = shift;

   #Get the next user id in the database.
   # Get the information from the system and store it for later
   my @x = getpwent;
   if (!scalar @x) {return;}

   &CfgTie::TieUser_rec'TIEHASH(0,@x);
   return $x[0]; #Corresponds to the name
}

sub EXISTS
{
   my ($self,$name) = @_;
   my $lname =lc($name);
   if (exists $CfgTie::TieUser_rec'by_name{$lname}) {return 1;}

   # Get the information from the system and store it for later
   my @x = getpwnam $name;
   if (! scalar @x) {return 0;}

   tie %{$CfgTie::TieUser_rec'by_name{lc($x[0])}}, 'CfgTie::TieUser_rec',@x;
   return 1;
}

sub FETCH
{
   my ($self, $name) = @_;

   if (!defined $name) {return;}

   my $lname = lc($name);

   #check out our cache first
   if (EXISTS($self,$lname))
     {return $CfgTie::TieUser_rec'by_name{$lname};}



( run in 0.817 second using v1.01-cache-2.11-cpan-389fe586d7c )