Fwctl/Services/netbios.pm untested

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 83 CC 8 SCAR 23.9
CC
8
Cov
0%
accept_rules
20.0
account_rules
20.0
block_rules
6.0
CRAP 10.9
1 #
2 # netbios.pm: Fwctl service module to handle the NetBios protocols.
3 #
4 # This file is part of Fwctl.
5 #
6 # Author: Francis J. Lacoste <francis@iNsu.COM>
7 #
8 # Copyright (c) 1999,2000 iNsu Innovations Inc.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 package Fwctl::Services::netbios;
16  
17 use strict;
18  
19 use Fwctl::RuleSet qw(:tcp_rulesets :udp_rulesets :ip_rulesets :masq :ports);
20 use Net::IPv4Addr qw(ipv4_in_network);
21 use IPChains;
22  
23 sub new {
24 my $proto = shift;
25 my $class = ref $proto || $proto;
26 bless {}, $class;
27 }
28  
29 sub prototypes {
30 my ($self,$target,$options) = @_;
31  
32 # Build prototype rule
33 (
34 IPChains->new(
35 Rule => $target,
36 Prot => 'udp',
37 SourcePort => 'netbios-ns',
38 DestPort => 'netbios-ns',
39 %{$options->{ipchains}},
40 ),
41 IPChains->new(
42 Rule => $target,
43 Prot => 'udp',
44 SourcePort => 'netbios-dgm',
45 DestPort => 'netbios-dgm',
46 %{$options->{ipchains}},
47 ),
48 IPChains->new(
49 Rule => $target,
50 Prot => 'tcp',
51 SourcePort => UNPRIVILEGED_PORTS,
52 DestPort => 'netbios-ssn',
53 %{$options->{ipchains}},
54 ),
55 );
56 }
57  
58 sub block_rules {
59 my $self = shift;
60 my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_;
61  
62  
63 my ($name,$dgm,$ssn) = $self->prototypes( $target, $options );
64 if ( ipv4_in_network( $src, $dst ) ) {
65 block_ip_ruleset( $name, $src, $src_if, $src_if->{broadcast}, $dst_if );
66 }
67 block_udp_ruleset( $name, $src, $src_if, $dst, $dst_if );
68 block_udp_ruleset( $dgm, $src, $src_if, $dst, $dst_if );
69 block_tcp_ruleset( $ssn, $src, $src_if, $dst, $dst_if );
70 }
71  
72 sub accept_rules {
73 my $self = shift;
74 my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_;
75  
76 my ($name,$dgm,$ssn) = $self->prototypes( $target, $options );
77 my $masq = defined $options->{portfw} ? PORTFW :
78 $options->{masq} ? MASQ : NOMASQ;
79 if ( ipv4_in_network( $src, $dst ) ) {
80 accept_ip_ruleset( $name, $src, $src_if, $src_if->{broadcast}, $dst_if,
81 $masq, $options->{portfw} );
82 }
83  
84  
85 accept_udp_ruleset( $name, $src, $src_if, $dst, $dst_if,
86 $masq, $options->{portfw} );
87  
88 accept_udp_ruleset( $dgm, $src, $src_if, $dst, $dst_if,
89 $masq, $options->{portfw} );
90  
91 accept_tcp_ruleset( $ssn, $src, $src_if, $dst, $dst_if,
92 $masq, $options->{portfw} );
93  
94 }
95  
96 sub account_rules {
97 my $self = shift;
98 my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_;
99  
100 my ($name,$dgm,$ssn) = $self->prototypes( $target, $options );
101 my $masq = defined $options->{portfw} ? PORTFW :
102 $options->{masq} ? MASQ : NOMASQ;
103 if ( ipv4_in_network( $src, $dst ) ) {
104 accept_ip_ruleset( $name, $src, $src_if, $src_if->{broadcast}, $dst_if,
105 $masq );
106 }
107 acct_udp_ruleset( $name, $src, $src_if, $dst, $dst_if, $masq );
108 acct_udp_ruleset( $dgm, $src, $src_if, $dst, $dst_if, $masq );
109 acct_tcp_ruleset( $ssn, $src, $src_if, $dst, $dst_if, $masq );
110  
111 }
112  
113 sub valid_options {
114 my $self = shift;
115 ( );
116 }
117  
118 1;
119  
120 =pod
121  
122 =head1 NAME
123  
124 Fwctl::Services::netbios - Fwctl module to handle NetBIOS traffic.
125  
126 =head1 SYNOPSIS
127  
128 deny netbios -nolog --account
129  
130 =head1 DESCRIPTION
131  
132 This module handle the NetBios-NS, NetBios-DGM and NetBios-SSN part of
133 the NetBIOS protocols. Its primary use is to reduce log clutter when
134 servicing a Windows Internal Network.
135  
136 =head1 AUTHOR
137  
138 Francis J. Lacoste <francis.lacoste@iNsu.COM>
139  
140 =head1 COPYRIGHT
141  
142 Copyright (c) 1999,2000 iNsu Innovations Inc.
143 All rights reserved.
144  
145 This program is free software; you can redistribute it and/or modify
146 it under the terms of the GNU General Public License as published by
147 the Free Software Foundation; either version 2 of the License, or
148 (at your option) any later version.
149  
150 =head1 SEE ALSO
151  
152 fwctl(8) Fwctl(3) Fwctl::RuleSet(3)
153  
154 =cut
155