/usr/share/perl5/POE/Component/Client/Ident.pm is in libpoe-component-client-ident-perl 1.07-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | # Author: Chris "BinGOs" Williams
#
# This module may be used, modified, and distributed under the same
# terms as Perl itself. Please see the license that came with your Perl
# distribution for details.
#
package POE::Component::Client::Ident;
use 5.006;
use strict;
use warnings;
use Socket;
use POE qw(Component::Client::Ident::Agent);
use Carp;
use vars qw($VERSION);
$VERSION = '1.07';
sub spawn {
my ( $package, $alias ) = splice @_, 0, 2;
my $self = bless { alias => $alias }, $package;
$self->{session_id} = POE::Session->create (
object_states => [
$self => [qw(_start _child query)],
$self => { ident_agent_reply => '_ident_agent_reply',
ident_agent_error => '_ident_agent_error',
shutdown => '_shutdown',
},
],
)->ID();
return $self;
}
sub session_id {
$_[0]->{session_id};
}
sub shutdown {
my $self = shift;
$poe_kernel->call( $self->{session_id}, @_ );
}
sub _start {
my ($kernel,$self,$session) = @_[KERNEL,OBJECT,SESSION];
$self->{session_id} = $session->ID();
$kernel->alias_set( $self->{alias} ) if $self->{alias};
$kernel->refcount_increment( $self->{session_id}, __PACKAGE__ ) unless $self->{alias};
undef;
}
sub _child {
my ($kernel,$self,$what,$child) = @_[KERNEL,OBJECT,ARG0,ARG1];
if ( $what eq 'create' ) {
# Stuff here to match up to our query
$self->{children}->{ $child->ID() } = 1;
}
if ( $what eq 'lose' ) {
delete $self->{children}->{ $child->ID() };
}
undef;
}
sub _shutdown {
my ($kernel,$self) = @_[KERNEL,OBJECT];
$kernel->call( $_ => 'shutdown' ) for keys %{ $self->{children} };
$kernel->alias_remove($_) for $kernel->alias_list();
$kernel->refcount_decrement( $self->{session_id}, __PACKAGE__ ) unless $self->{alias};
undef;
}
sub query {
my ($kernel,$self,$sender) = @_[KERNEL,OBJECT,SENDER];
my $package = ref $self;
my ($peeraddr,$peerport,$sockaddr,$sockport,$socket) = _parse_arguments( @_[ARG0 .. $#_] );
unless ( $peeraddr and $peerport and $sockaddr and $sockport ) {
croak "Not enough arguments/items for $package->query";
}
$kernel->refcount_increment( $sender->ID() => __PACKAGE__ );
POE::Component::Client::Ident::Agent->spawn( @_[ARG0 .. $#_], Reference => $sender->ID() );
undef;
}
sub _ident_agent_reply {
my ($kernel,$self,$ref) = @_[KERNEL,OBJECT,ARG0];
my $requester = delete $ref->{Reference};
$kernel->post( $requester, 'ident_client_reply' , $ref, @_[ARG1 .. $#_] );
$kernel->refcount_decrement( $requester => __PACKAGE__ );
undef;
}
sub _ident_agent_error {
my ($kernel,$self,$ref) = @_[KERNEL,OBJECT,ARG0];
my $requester = delete $ref->{Reference};
$kernel->post( $requester, 'ident_client_error', $ref, @_[ARG1 .. $#_] );
$kernel->refcount_decrement( $requester => __PACKAGE__ );
undef;
}
sub _parse_arguments {
my %hash = @_;
my @returns;
# If we get a socket it takes precedence over any other arguments
SWITCH: {
if ( defined $hash{'Socket'} ) {
$returns[0] = inet_ntoa( (unpack_sockaddr_in( getpeername $hash{'Socket'} ))[1] );
$returns[1] = (unpack_sockaddr_in( getpeername $hash{'Socket'} ))[0];
$returns[2] = inet_ntoa( (unpack_sockaddr_in( getsockname $hash{'Socket'} ))[1] );
$returns[3] = (unpack_sockaddr_in( getsockname $hash{'Socket'} ))[0];
$returns[4] = $hash{'Socket'};
last SWITCH;
}
if ( defined $hash{'PeerAddr'} and defined $hash{'PeerPort'} and defined $hash{'SockAddr'} and defined $hash{'SockAddr'} ) {
$returns[0] = $hash{'PeerAddr'};
$returns[1] = $hash{'PeerPort'};
$returns[2] = $hash{'SockAddr'};
$returns[3] = $hash{'SockPort'};
last SWITCH;
}
}
return @returns;
}
=head1 NAME
POE::Component::Client::Ident - A component that provides non-blocking ident lookups to your sessions.
=head1 SYNOPSIS
use POE::Component::Client::Ident;
my $poco_obj = POE::Component::Client::Ident->spawn ( 'Ident-Client' );
$kernel->post ( 'Ident-Client' => query => Socket => $socket );
$kernel->post ( 'Ident-Client' => query => PeerAddr => '10.0.0.1',
PeerPort => 2345,
SockAddr => '192.168.1.254',
SockPort => 6669,
BuggyIdentd => 1,
TimeOut => 30 );
=head1 DESCRIPTION
POE::Component::Client::Ident is a POE component that provides non-blocking Ident lookup services to
other components and sessions. The Ident protocol is described in RFC 1413 L<http://www.faqs.org/rfcs/rfc1413.html>.
The component takes requests in the form of events, spawns L<POE::Component::Client::Ident::Agent|POE::Component::Client::Ident::Agent> sessions to
perform the Ident queries and returns the appropriate responses to the requesting session.
=head1 CONSTRUCTOR
=over
=item spawn
Takes one argument, a kernel alias to christen the new component with.
Returns an object.
=back
=head1 METHODS
These methods are available on the poco object returned by spawn().
=over
=item session_id
Returns the component's session ID.
=item shutdown
Takes no arguments. Causes the component to terminate gracefully. Any pending Ident::Agent components that are
running will be closed without returning events.
=back
=head1 INPUT
The component accepts the following events:
=over
=item query
Takes either the arguments:
"PeerAddr", the remote IP address where a TCP connection has originated;
"PeerPort", the port where the TCP has originated from;
"SockAddr", the address of our end of the connection;
"SockPort", the port of our end of the connection;
OR:
"Socket", the socket handle of the connection, the component will work out all
the details for you. If Socket is defined, it will override the settings of the
other arguments.
See the documentation for Ident-Agent for extra parameters you may pass.
=item shutdown
Takes no arguments. Causes the component to terminate gracefully. Any pending Ident::Agent components that are
running will be closed without returning events.
=back
=head1 OUTPUT
The events you can expect to receive having submitted a 'query'.
All the events returned by the component have a hashref as ARG0. This hashref contains the arguments that were passed to
the component. If a socket handle was passed, the hashref will contain the appropriate PeerAddr, PeerPort, SockAddr and Sock
Port.
=over
=item ident_client_reply
Returned when the component receives a USERID response from the identd. ARG0 is hashref, ARG1 is the opsys field and ARG2 is
the userid or something else depending on whether the opsys field is set to 'OTHER' ( Don't blame me, read the RFC ).
=item ident_client_error
Returned when the component receives an ERROR response from the identd, there was some sort of communication error with the
remote host ( ie. no identd running ) or it had some other problem with making the connection to the other host. No matter.
ARG0 is hashref, ARG1 is the type of error.
=back
=head1 AUTHOR
Chris Williams, E<lt>chris@bingosnet.co.uk<gt>
=head1 SEE ALSO
RFC 1413 L<http://www.faqs.org/rfcs/rfc1413.html>
L<POE::Component::Client::Ident::Agent|POE::Component::Client::Ident::Agent>
|