TacacsPlus/Packet/AuthorRequestBody.pm

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