| 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<Sys::Utmp> 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<perlsec> 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 | 7 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 113 | 7 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 114 | |||||||||||||||
| 115 | 7 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 116 | 7 | require Exporter; | |||||||||||||
| 117 | |||||||||||||||
| 118 | |||||||||||||||
| 119 | 7 | ▶ | use vars qw( | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 120 | @methods | ||||||||||||||
| 121 | %meth2index | ||||||||||||||
| 122 | %const2meth | ||||||||||||||
| 123 | $AUTOLOAD | ||||||||||||||
| 124 | @ISA | ||||||||||||||
| 125 | @EXPORT | ||||||||||||||
| 126 | 7 | ); | |||||||||||||
| 127 | |||||||||||||||
| 128 | 7 | @ISA = qw(Exporter); | |||||||||||||
| 129 | |||||||||||||||
| 130 | BEGIN | ||||||||||||||
| 131 | 7 | ▶ | { | ||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.0
| |||||||||||||||
| 132 | 7 | @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 | 7 | @meth2index{@methods} = ( 0 .. $#methods ); | |||||||||||||
| 144 | |||||||||||||||
| 145 | |||||||||||||||
| 146 | 7 | ▶ | no strict 'refs'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 147 | 7 | foreach my $sub ( @methods ) | |||||||||||||
| 148 | { | ||||||||||||||
| 149 | 49 | my $usub = uc $sub; | |||||||||||||
| 150 | |||||||||||||||
| 151 | 49 | ▶ | *{$usub} = sub { return $meth2index{$sub} }; | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 152 | 49 | push @EXPORT, $usub; | |||||||||||||
| 153 | |||||||||||||||
| 154 | } | ||||||||||||||
| 155 | 7 | ▶ | use strict 'refs'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 156 | |||||||||||||||
| 157 | 7 | $const2meth{lc $_ } = $_ foreach @Sys::Utmp::constants; | |||||||||||||
| 158 | |||||||||||||||
| 159 | } | ||||||||||||||
| 160 | |||||||||||||||
| 161 | sub AUTOLOAD | ||||||||||||||
| 162 | 0 | ▶ | { | ||||||||||||
|
Subroutine
AUTOLOAD: not called CC=5 SCAR=31.3
| |||||||||||||||
| 163 | 0 | my ( $self ) = @_; | |||||||||||||
| 164 | |||||||||||||||
| 165 | 0 | ▶ | return if ( $AUTOLOAD =~ /DESTROY/ ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 166 | |||||||||||||||
| 167 | 0 | (my $methname = $AUTOLOAD) =~ s/.*:://; | |||||||||||||
| 168 | |||||||||||||||
| 169 | |||||||||||||||
| 170 | { | ||||||||||||||
| 171 | 0 | ▶ | no strict 'refs'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||
| 172 | |||||||||||||||
| 173 | 0 | ▶ | if ( exists $meth2index{$methname} ) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 174 | { | ||||||||||||||
| 175 | 0 | ▶ | *{$AUTOLOAD} = sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 176 | 0 | my ($self) = @_; | |||||||||||||
| 177 | 0 | return $self->[$meth2index{$methname}]; | |||||||||||||
| 178 | 0 | }; | |||||||||||||
| 179 | } | ||||||||||||||
| 180 | elsif ( exists $const2meth{$methname}) | ||||||||||||||
| 181 | { | ||||||||||||||
| 182 | 0 | ▶ | *{$AUTOLOAD} = sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 183 | 0 | my ( $self ) = @_; | |||||||||||||
| 184 | 0 | return $self->ut_type == &{"Sys::Utmp::$const2meth{$methname}"}; | |||||||||||||
| 185 | 0 | }; | |||||||||||||
| 186 | } | ||||||||||||||
| 187 | else | ||||||||||||||
| 188 | { | ||||||||||||||
| 189 | 0 | ▶ | croak "$methname not defined" unless exists $meth2index{$methname}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 190 | } | ||||||||||||||
| 191 | |||||||||||||||
| 192 | 0 | goto &{$AUTOLOAD}; | |||||||||||||
| 193 | } | ||||||||||||||
| 194 | } | ||||||||||||||
| 195 | |||||||||||||||
| 196 | 7 | 1; | |||||||||||||
| 197 | |||||||||||||||
| 198 | __END__ | ||||||||||||||