line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
1
|
|
|
1
|
|
963
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
require DynaLoader; |
130
|
|
|
|
|
|
|
|
131
|
1
|
|
|
|
|
182
|
use vars qw( |
132
|
|
|
|
|
|
|
@ISA |
133
|
|
|
|
|
|
|
$VERSION |
134
|
|
|
|
|
|
|
$AUTOLOAD |
135
|
1
|
|
|
1
|
|
6
|
); |
|
1
|
|
|
|
|
1
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
@ISA = qw( |
138
|
|
|
|
|
|
|
DynaLoader |
139
|
|
|
|
|
|
|
); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$VERSION = '1.7'; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
bootstrap Sys::Lastlog $VERSION; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub new |
146
|
|
|
|
|
|
|
{ |
147
|
1
|
|
|
1
|
1
|
938
|
my ( $proto, $args ) = @_; |
148
|
|
|
|
|
|
|
|
149
|
1
|
|
33
|
|
|
8
|
my $class = ref($proto) || $proto; |
150
|
|
|
|
|
|
|
|
151
|
1
|
|
|
|
|
2
|
my $self = {}; |
152
|
|
|
|
|
|
|
|
153
|
1
|
|
|
|
|
3
|
bless $self, $class; |
154
|
|
|
|
|
|
|
|
155
|
1
|
|
|
|
|
7
|
return $self; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
package Sys::Lastlog::Entry; |
161
|
|
|
|
|
|
|
|
162
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
85
|
|
163
|
1
|
|
|
|
|
58
|
use vars qw( |
164
|
|
|
|
|
|
|
$AUTOLOAD |
165
|
1
|
|
|
1
|
|
10
|
); |
|
1
|
|
|
|
|
2
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub AUTOLOAD |
168
|
|
|
|
|
|
|
{ |
169
|
2
|
|
|
2
|
|
6
|
my ( $self ) = @_; |
170
|
|
|
|
|
|
|
|
171
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
185
|
|
172
|
|
|
|
|
|
|
|
173
|
2
|
|
|
|
|
15
|
( my $methname = $AUTOLOAD ) =~ s/.*:://; |
174
|
|
|
|
|
|
|
|
175
|
2
|
50
|
|
|
|
11
|
if ( exists $self->{$methname} ) |
176
|
|
|
|
|
|
|
{ |
177
|
2
|
|
|
|
|
11
|
*{$AUTOLOAD} = sub { |
178
|
103
|
|
|
103
|
|
61476
|
my ( $self ) = @_; |
179
|
103
|
|
|
|
|
876
|
return $self->{$methname}; |
180
|
2
|
|
|
|
|
11
|
}; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
else |
183
|
|
|
|
|
|
|
{ |
184
|
0
|
|
|
|
|
0
|
croak "Method $methname is not defined"; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
2
|
|
|
|
|
4
|
goto &{$AUTOLOAD}; |
|
2
|
|
|
|
|
11
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; |
192
|
|
|
|
|
|
|
__END__ |