File Coverage

blib/lib/Sys/Utmp/Utent.pm
Criterion Covered Total %
statement 30 47 63.8
branch 0 8 0.0
condition n/a
subroutine 9 12 75.0
pod n/a
total 39 67 58.2


line stmt bran cond sub pod time code
1             package Sys::Utmp::Utent;
2              
3             =head1 NAME
4              
5             Sys::Utmp::Utent - represent a single utmp entry
6              
7             =head1 SYNOPSIS
8              
9              
10             use Sys::Utmp;
11              
12             my $utmp = Sys::Utmp->new();
13              
14             while ( my $utent = $utmp->getutent() )
15             {
16             if ( $utent->user_process )
17             {
18             print $utent->ut_user,"\n";
19             }
20             }
21              
22             $utmp->endutent;
23              
24             =head1 DESCRIPTION
25              
26             As described in the L documentation the getutent method
27             returns an object of the type Sys::Utmp::Utent which provides methods
28             for accessing the fields in the utmp record. There are also methods
29             for determining the type of the record.
30              
31             The access methods relate to the common names for the members of the C
32             struct utent - those provided are the superset from the Gnu implementation
33             and may not be available on all systems: where they are not they will
34             return the empty string.
35              
36             =over 4
37              
38             =item ut_user
39              
40             Returns the use this record was created for if this is a record for a user
41             process. Some systems may return other information depending on the record
42             type. If no user was set this will be the empty string. If tainting is
43             switched on with the '-T' switch to perl then this will be 'tainted' as it
44             is possible that the user name came from an untrusted source.
45              
46             =item ut_id
47              
48             The identifier for this record - it might be the inittab tag or some other
49             system dependent value.
50              
51             =item ut_line
52              
53             For user process records this will be the name of the terminalor line that the
54             user is connected on.
55              
56             =item ut_pid
57              
58             The process ID of the process that created this record.
59              
60             =item ut_type
61              
62             The type of the record this will have a value corresponding to one of the
63             constants (not all of these may be available on all systems and there may
64             well be others which should be described in the getutent manpage or in
65             /usr/include/utmp.h ) :
66              
67             =over 2
68              
69             =item ACCOUNTING - record was created for system accounting purposes.
70              
71             =item BOOT_TIME - the record was created at boot time.
72              
73             =item DEAD_PROCESS - The process that created this record has terminated.
74              
75             =item EMPTY - record probably contains no other useful information.
76              
77             =item INIT_PROCESS - this is a record for process created by init.
78              
79             =item LOGIN_PROCESS - this record was created for a login process (e.g. getty).
80              
81             =item NEW_TIME - record created when the system time has been set.
82              
83             =item OLD_TIME - record recording the old tme when the system time has been set.
84              
85             =item RUN_LVL - records the time at which the current run level was started.
86              
87             =item USER_PROCESS - record created for a user process (e.g. a login )
88              
89             =back
90              
91             for convenience Sys::Utmp::Utent provides methods which are lower case
92             versions of the constant names which return true if the record is of that
93             type.
94              
95             =item ut_host
96              
97             On systems which support this the method will return the hostname of the
98             host for which the process that created the record was started - for example
99             for a telnet login. If taint checking has been turned on (with the -T
100             switch to perl ) then this value will be tainted as it is possible that
101             a remote user will be in control of the DNS for the machine they have
102             logged in from. ( see L for more on tainting )
103              
104             =item ut_time
105              
106             The time in epoch seconds wt which the record was created.
107              
108             =back
109              
110             =cut
111              
112 6     6   46 use strict;
  6         15  
  6         203  
113 6     6   39 use warnings;
  6         13  
  6         188  
114              
115 6     6   39 use Carp;
  6         14  
  6         514  
116             require Exporter;
117              
118              
119 6         1010 use vars qw(
120             @methods
121             %meth2index
122             %const2meth
123             $AUTOLOAD
124             @ISA
125             @EXPORT
126 6     6   45 );
  6         15  
127              
128             @ISA = qw(Exporter);
129              
130             BEGIN
131             {
132 6     6   36 @methods = qw(
133             ut_user
134             ut_id
135             ut_line
136             ut_pid
137             ut_type
138             ut_host
139             ut_time
140             );
141              
142              
143 6         58 @meth2index{@methods} = ( 0 .. $#methods );
144            
145              
146 6     6   50 no strict 'refs';
  6         17  
  6         977  
147 6         23 foreach my $sub ( @methods )
148             {
149 42         103 my $usub = uc $sub;
150              
151 42     7   166 *{$usub} = sub { return $meth2index{$sub} };
  42         218  
  7         208  
152 42         137 push @EXPORT, $usub;
153              
154             }
155 6     6   48 use strict 'refs';
  6         21  
  6         369  
156              
157 6         852 $const2meth{lc $_ } = $_ foreach @Sys::Utmp::constants;
158              
159             }
160              
161             sub AUTOLOAD
162             {
163 0     0     my ( $self ) = @_;
164              
165 0 0         return if ( $AUTOLOAD =~ /DESTROY/ );
166              
167 0           (my $methname = $AUTOLOAD) =~ s/.*:://;
168              
169              
170             {
171 6     6   52 no strict 'refs';
  6         17  
  6         1549  
  0            
172              
173 0 0         if ( exists $meth2index{$methname} )
    0          
174             {
175 0           *{$AUTOLOAD} = sub {
176 0     0     my ($self) = @_;
177 0           return $self->[$meth2index{$methname}];
178 0           };
179             }
180             elsif ( exists $const2meth{$methname})
181             {
182 0           *{$AUTOLOAD} = sub {
183 0     0     my ( $self ) = @_;
184 0           return $self->ut_type == &{"Sys::Utmp::$const2meth{$methname}"};
  0            
185 0           };
186             }
187             else
188             {
189 0 0         croak "$methname not defined" unless exists $meth2index{$methname};
190             }
191              
192 0           goto &{$AUTOLOAD};
  0            
193             }
194             }
195              
196             1;
197              
198             __END__