TacacsPlus/Packet/AuthenStartBody.pm

filter: Statementstmt 100% 43 / 43 Branchbran 100% 12 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 100% 67 / 67 CC 7 SCAR 13.4
CC
7
Cov
100%
new
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.8
« TacacsPlus/Packet/AuthorRequestBody.pm ↑ Summary TacacsPlus/Packet/AuthenReplyBody.pm »
1 package Net::TacacsPlus::Packet::AuthenStartBody;
2  
3 =head1 NAME
4  
5 Net::TacacsPlus::Packet::AuthenStartBody - Tacacs+ authentication packet body
6  
7 =head1 DESCRIPTION
8  
9 The authentication START packet body
10  
11 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
12  
13 +----------------+----------------+----------------+----------------+
14 | action | priv_lvl | authen_type | service |
15 +----------------+----------------+----------------+----------------+
16 | user len | port len | rem_addr len | data len |
17 +----------------+----------------+----------------+----------------+
18 | user ...
19 +----------------+----------------+----------------+----------------+
20 | port ...
21 +----------------+----------------+----------------+----------------+
22 | rem_addr ...
23 +----------------+----------------+----------------+----------------+
24 | data...
25 +----------------+----------------+----------------+----------------+
26  
27 =cut
28  
29  
30 11 our $VERSION = '1.10';
31  
32 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 11 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 11 ▶use Net::TacacsPlus::Constants 1.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 11 ▶use Carp::Clan;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 11 ▶use base qw{ Class::Accessor::Fast };
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 11 __PACKAGE__->mk_accessors(qw{
42 action
43 priv_lvl
44 authen_type
45 service
46 user
47 data
48 port
49 rem_addr
50 });
51  
52 =head1 METHODS
53  
54 =over 4
55  
56 =item new( somekey => somevalue)
57  
58 Construct tacacs+ authentication START packet body object
59  
60 Parameters:
61  
62 action : TAC_PLUS_AUTHEN_[^_]+$
63 priv_lvl : TAC_PLUS_PRIV_LVL_* - default TAC_PLUS_PRIV_LVL_MIN
64 authen_type : TAC_PLUS_AUTHEN_TYPE_*
65 service : TAC_PLUS_AUTHEN_SVC_* - default TAC_PLUS_AUTHEN_SVC_LOGIN
66 user : username
67 data : data - default ''
68 port : port - default 'Virtual00'
69 rem_addr : our ip address - default '127.0.0.1'
70  
71 =cut
72  
73 3 ▶sub new {
Subroutine new: called CC=7 SCAR=19.5
Pod documented
74 3 my $class = shift;
75 3 my %params = @_;
76  
77 #let the class accessor contruct the object
78 3 my $self = $class->SUPER::new(\%params);
79  
80 3 ▶ if ($params{'raw_body'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"raw_body"}) 1 2 3
81 1 $self->decode($params{'raw_body'});
82 1 delete $self->{'raw_body'};
83 1 return $self;
84 }
85  
86 2 ▶ $self->priv_lvl(TAC_PLUS_PRIV_LVL_MIN) if not defined $self->priv_lvl();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->priv_lvl 1 1 2
87 2 ▶ $self->service(TAC_PLUS_AUTHEN_SVC_LOGIN) if not defined $self->service();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->service 1 1 2
88 2 ▶ $self->data('') if not defined $self->data();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->data 1 1 2
89 2 ▶ $self->port('Virtual00') if not defined $self->port();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->port 1 1 2
90 2 ▶ $self->rem_addr('127.0.0.1') if not defined $self->rem_addr();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->rem_addr 1 1 2
91  
92 2 return $self;
93 }
94  
95  
96 =item decode($raw_data)
97  
98 Construct object from raw packet.
99  
100 =cut
101  
102 1 ▶sub decode {
Subroutine decode: called CC=1 SCAR=0.0
Pod documented
103 1 my ($self, $raw_data) = @_;
104
105 1 my $length_user;
106 my $length_port;
107 1 my $length_rem_addr;
108 1 my $length_data;
109 1 my $payload;
110
111 (
112 $self->{'action'},
113 $self->{'priv_lvl'},
114 $self->{'authen_type'},
115 1 $self->{'service'},
116 $length_user,
117 $length_port,
118 $length_rem_addr,
119 $length_data,
120 $payload,
121 ) = unpack("C8a*", $raw_data);
122  
123 (
124 $self->{'user'},
125 $self->{'port'},
126 $self->{'rem_addr'},
127 1 $self->{'data'},
128 ) = unpack(
129 "a".$length_user
130 ."a".$length_port
131 ."a".$length_rem_addr
132 ."a".$length_data
133 ,
134 $payload
135 );
136 }
137  
138  
139 =item raw()
140  
141 Return binary data of packet body.
142  
143 =cut
144  
145 1 ▶sub raw {
Subroutine raw: called CC=1 SCAR=0.0
Pod documented
146 1 my $self = shift;
147  
148 my $body = pack("C8a*a*a*a*",
149 $self->{'action'},
150 $self->{'priv_lvl'},
151 $self->{'authen_type'},
152 $self->{'service'},
153 length($self->{'user'}),
154 length($self->{'port'}),
155 length($self->{'rem_addr'}),
156 length($self->{'data'}),
157 $self->{'user'},
158 $self->{'port'},
159 $self->{'rem_addr'},
160 1 $self->{'data'},
161 );
162  
163 1 return $body;
164 }
165  
166 11 1;
167  
168 =back
169  
170 =cut
« TacacsPlus/Packet/AuthorRequestBody.pm ↑ Summary TacacsPlus/Packet/AuthenReplyBody.pm »