Object/protocol.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 73 CC 7 SCAR 21.3
CC
7
Cov
0%
_init
20.0
add
6.0
protocols
6.0
CRAP 8.4
1 package PIX::Object::protocol;
2  
3 use strict;
4 use warnings;
5 use base qw( PIX::Object );
6 use Carp;
7  
8 our $VERSION = '1.10';
9  
10 =pod
11  
12 =head1 NAME
13  
14 PIX::Object::protocol - Class for "protocol" object-groups found in a PIX
15 config. A protocol group is used on access-lists to allow a line of an ACL to
16 have multiple protocols on it (ip, tcp, udp, gmp, ah, es, etc...).
17  
18 =head1 SYNOPSIS
19  
20 This is a subclass of PIX::Object that maintains a single object-group as read
21 from a firewall config. You can list and search for elements in the list.
22  
23 =head1 SEE ALSO
24  
25 B<PIX::Object>
26  
27 =head1 METHODS
28  
29 =over
30  
31 =cut
32  
33 sub _init {
34 my $self = shift;
35 $self->SUPER::_init;
36  
37 $self->{debug} = 1;
38  
39 $self->{protocols} = []; # protocols directly defined in this object group
40 $self->{groups} = []; # other groups that this object points to for protocols
41 $self->{desc} = '';
42  
43 $self->_nextline; # remove the first line 'object-group blah'
44 while (defined(my $line = $self->_nextline)) {
45 # print "$self->{name}: $line\n";
46 if ($line =~ /\s*protocol-object (\S*)/) {
47 $self->add($1);
48 } elsif ($line =~ /^\s*group-object (\S+)/) {
49 $self->add($1, 1);
50 } elsif ($line =~ /^\s+description (.+)/) {
51 $self->{desc} = $1;
52 } else {
53 carp "$self->{name}: Unknown protocol object line: $line\n";
54 }
55 }
56 }
57  
58 =item B<add($proto_or_grp, [$is_group])>
59  
60 =over
61  
62 Add a protocol or nested group to the object-group. If $is_group is true
63 then $proto_or_grp will be recorded as a nested hostgroup name, and not a
64 protocol name. Note: This logic is slightly different than the other
65 PIX::Object sub-classes.
66  
67 =back
68  
69 =cut
70 sub add {
71 my ($self, $p, $is_group) = @_;
72 if (!$is_group) {
73 push(@{$self->{protocols}}, $p);
74 } else {
75 push(@{$self->{groups}}, $p);
76 }
77 }
78  
79 =item B<list( )>
80  
81 =over
82  
83 Returns a list of protocols from the object group. A plain list of protocol
84 names are returned.
85  
86 =back
87  
88 =cut
89 sub list {
90 my $self = shift;
91 my @list = @{$self->{protocols}};
92 foreach my $name ($self->groups) {
93 my $grp = $self->{walker}->obj($name) || next;
94 push(@list, $grp->list);
95 }
96 return @list;
97 }
98  
99 sub protocols { return wantarray ? @{$_[0]->{protocols}} : $_[0]->{protocols} }
100 sub groups { return wantarray ? @{$_[0]->{groups}} : $_[0]->{groups} }
101  
102 1;
103  
104 =pod
105  
106 =head1 AUTHOR
107  
108 Jason Morriss <lifo 101 at - gmail dot com>
109  
110 =head1 BUGS
111  
112 Please report any bugs or feature requests to
113 C<bug-pix-walker at rt.cpan.org>, or through the web interface at
114 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PIX-Walker>.
115 I will be notified, and then you'll automatically be notified of progress on
116 your bug as I make changes.
117  
118 =head1 SUPPORT
119  
120 perldoc PIX::Walker
121  
122 perldoc PIX::Accesslist
123 perldoc PIX::Accesslist::Line
124  
125 perldoc PIX::Object
126 perldoc PIX::Object::network
127 perldoc PIX::Object::service
128 perldoc PIX::Object::protocol
129 perldoc PIX::Object::icmp_type
130  
131 =head1 COPYRIGHT & LICENSE
132  
133 Copyright 2006-2008 Jason Morriss, all rights reserved.
134  
135 This program is free software; you can redistribute it and/or modify it
136 under the same terms as Perl itself.
137  
138 =cut