| 1 | #***************************************************************************** | ||||||||||||||||||||
| 2 | #* * | ||||||||||||||||||||
| 3 | #* Gellyfish Software * | ||||||||||||||||||||
| 4 | #* * | ||||||||||||||||||||
| 5 | #* * | ||||||||||||||||||||
| 6 | #***************************************************************************** | ||||||||||||||||||||
| 7 | #* * | ||||||||||||||||||||
| 8 | #* PROGRAM : Sys::Lastlog * | ||||||||||||||||||||
| 9 | #* * | ||||||||||||||||||||
| 10 | #* AUTHOR : JNS * | ||||||||||||||||||||
| 11 | #* * | ||||||||||||||||||||
| 12 | #* DESCRIPTION : Provide Object(ish) Interface to lastlog files * | ||||||||||||||||||||
| 13 | #* * | ||||||||||||||||||||
| 14 | #* * | ||||||||||||||||||||
| 15 | #***************************************************************************** | ||||||||||||||||||||
| 16 | #* * | ||||||||||||||||||||
| 17 | #* $Id$ | ||||||||||||||||||||
| 18 | #* * | ||||||||||||||||||||
| 19 | #***************************************************************************** | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | package Sys::Lastlog; | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | =head1 NAME | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | Sys::Lastlog - Provide a moderately Object Oriented Interface to lastlog | ||||||||||||||||||||
| 26 | files on some Unix-like systems. | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =head1 SYNOPSIS | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | use Sys::Lastlog; | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | my $ll = Sys::Lastlog->new(); | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | while(my $llent = $ll->getllent() ) | ||||||||||||||||||||
| 35 | { | ||||||||||||||||||||
| 36 | print $llent->ll_line(),"\n"; | ||||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | =head1 DESCRIPTION | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | The lastlog file provided on most Unix-like systems stores information about | ||||||||||||||||||||
| 42 | when each user on the system last logged in. The file is sequential and | ||||||||||||||||||||
| 43 | indexed on the UID (that is to say a user with UID 500 will have the 500th | ||||||||||||||||||||
| 44 | record in the file). Most systems do not provide a C API to access this | ||||||||||||||||||||
| 45 | file and programs such as 'lastlog' will provide their own methods of doing | ||||||||||||||||||||
| 46 | this. | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | This module provides an Object Oriented Perl API to access this file in order | ||||||||||||||||||||
| 49 | that programs like 'lastlog' can written in Perl (for example the 'plastlog' | ||||||||||||||||||||
| 50 | program in this distribution) or that programs can determine a users last | ||||||||||||||||||||
| 51 | login for their own purposes. | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | The module provides three methods for accessing lastlog sequentially, by | ||||||||||||||||||||
| 54 | UID or by login name. Each method returns an object of type Sys::Lastlog::Entry | ||||||||||||||||||||
| 55 | that itself provides methods for accessing the information for each record. | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | =head2 METHODS | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | =over 4 | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =item new | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | The constructor of the class. Returns a blessed object that the other methods | ||||||||||||||||||||
| 64 | can be called on. | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | =item lastlog_path | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | Returns the full path to the lcoation of the lastlog file as defined by the | ||||||||||||||||||||
| 69 | operating system. Possibly only useful for diagnostic purposes currently. | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =item getllent | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | This method will sequentially return each record in the lastlog each time it | ||||||||||||||||||||
| 74 | is called, returning a false value when there are no more records to return. | ||||||||||||||||||||
| 75 | Because the lastlog file is indexed on UID if there are gaps in the allocation | ||||||||||||||||||||
| 76 | of UIDs on a system will there will be as many empty records returned ( that | ||||||||||||||||||||
| 77 | is to say if for some reason there are no UIDs used between 200 and 500 this | ||||||||||||||||||||
| 78 | method will nonetheless return the 299 empty records .) | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | =item getlluid SCALAR $uid | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | This method will return a record for the $uid specified or a false value if | ||||||||||||||||||||
| 83 | the UID is out of range, it does however perform no check that the UID has | ||||||||||||||||||||
| 84 | actually been assigned it must simply be less than or equal to the maximum | ||||||||||||||||||||
| 85 | UID currently assigned on the system. | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =item getllnam SCALAR $logname | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | This will return the record corresponding to the user name $logname or | ||||||||||||||||||||
| 90 | false if it is not a valid user name. | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | =item setllent | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | Set the file pointer on the lastlog file back to the beginning of the file | ||||||||||||||||||||
| 95 | for repeated iteration over the file using getllent() . | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =back | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | =head2 PER RECORD METHODS | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | These are the methods of the class Sys::Lastlog::Entry that give access to | ||||||||||||||||||||
| 102 | the information for each record. | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | =over 4 | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | =item uid | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | The UID that corresponds to this record. | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | =item ll_time | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | The time in epoch seconds of this users last login. | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | =item ll_line | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | The line (e.g. terminal ) that this user logged in via. | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | =item ll_host | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | The host from which this user logged in from or the empty string if it was | ||||||||||||||||||||
| 121 | a local login. | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | =back | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =cut | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 2 | require DynaLoader; | |||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | 2 | ▶ | use vars qw( | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 132 | @ISA | ||||||||||||||||||||
| 133 | $VERSION | ||||||||||||||||||||
| 134 | $AUTOLOAD | ||||||||||||||||||||
| 135 | 2 | ); | |||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 2 | @ISA = qw( | |||||||||||||||||||
| 138 | DynaLoader | ||||||||||||||||||||
| 139 | ); | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | 2 | $VERSION = '1.7'; | |||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | 2 | bootstrap Sys::Lastlog $VERSION; | |||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | sub new | ||||||||||||||||||||
| 146 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||
| 147 | 1 | my ( $proto, $args ) = @_; | |||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | 1 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | 1 | my $self = {}; | |||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 1 | bless $self, $class; | |||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | 1 | return $self; | |||||||||||||||||||
| 156 | } | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | 2 | 1; | |||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | package Sys::Lastlog::Entry; | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | 2 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 163 | 2 | ▶ | use vars qw( | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 164 | $AUTOLOAD | ||||||||||||||||||||
| 165 | 2 | ); | |||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | sub AUTOLOAD | ||||||||||||||||||||
| 168 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=2 SCAR=14.0
| |||||||||||||||||||||
| 169 | 0 | my ( $self ) = @_; | |||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | 0 | ( my $methname = $AUTOLOAD ) =~ s/.*:://; | |||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | 0 | ▶ | if ( exists $self->{$methname} ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 176 | { | ||||||||||||||||||||
| 177 | 0 | ▶ | *{$AUTOLOAD} = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 178 | 0 | my ( $self ) = @_; | |||||||||||||||||||
| 179 | 0 | return $self->{$methname}; | |||||||||||||||||||
| 180 | 0 | }; | |||||||||||||||||||
| 181 | } | ||||||||||||||||||||
| 182 | else | ||||||||||||||||||||
| 183 | { | ||||||||||||||||||||
| 184 | 0 | croak "Method $methname is not defined"; | |||||||||||||||||||
| 185 | } | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | 0 | goto &{$AUTOLOAD}; | |||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | } | ||||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | 2 | 1; | |||||||||||||||||||
| 192 | __END__ | ||||||||||||||||||||