Fwctl/Services/name_service.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 99 CC 8 SCAR 24.4
CC
8
Cov
0%
accept_rules
20.0
account_rules
20.0
block_rules
6.0
CRAP 11.5
1 #
2 # name_service.pm: Fwctl service module to handle the DNS protocol.
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::name_service;
16  
17 use strict;
18  
19 use Fwctl::RuleSet qw(:tcp_rulesets :udp_rulesets :masq :ports);
20 use IPChains;
21  
22 sub new {
23 my $proto = shift;
24 my $class = ref $proto || $proto;
25 bless {
26 query_port => UNPRIVILEGED_PORTS,
27 }, $class;
28 }
29  
30 sub prototypes {
31 my ($self,$target,$options) = @_;
32  
33 # Build prototype rule
34 (
35 IPChains->new(
36 Rule => $target,
37 Prot => 'udp',
38 DestPort => 'domain',
39 %{$options->{ipchains}},
40 ),
41 IPChains->new(
42 Rule => $target,
43 Prot => 'tcp',
44 SourcePort => UNPRIVILEGED_PORTS,
45 DestPort => 'domain',
46 %{$options->{ipchains}},
47 ),
48 );
49 }
50  
51 sub block_rules {
52 my $self = shift;
53 my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_;
54  
55 my ($udp,$tcp) = $self->prototypes( $target, $options );
56  
57 my $query;
58 if ( $options->{server} ) {
59 $query = undef;
60 } else {
61 $query = $options->{"query-port"} || $self->{query_port};
62 }
63 $udp->attribute( SourcePort => $query );
64 block_udp_ruleset( $udp, $src, $src_if, $dst, $dst_if );
65 block_tcp_ruleset( $tcp, $src, $src_if, $dst, $dst_if );
66 }
67  
68 sub accept_rules {
69 my $self = shift;
70 my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_;
71  
72 my ($udp,$tcp) = $self->prototypes( $target, $options );
73  
74 my $masq = defined $options->{portfw} ? PORTFW :
75 $options->{masq} ? MASQ : NOMASQ;
76  
77 my $query;
78 if ( $options->{server} ) {
79 $query = undef;
80 } else {
81 $query = $options->{"query-port"} || $self->{query_port};
82 }
83 $udp->attribute( SourcePort => $query );
84 accept_udp_ruleset( $udp, $src, $src_if, $dst, $dst_if,
85 $masq, $options->{portfw} );
86 accept_tcp_ruleset( $tcp, $src, $src_if, $dst, $dst_if,
87 $masq, $options->{portfw} );
88 }
89  
90 sub account_rules {
91 my $self = shift;
92 my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_;
93  
94 my ($udp,$tcp) = $self->prototypes( $target, $options );
95 my $masq = defined $options->{portfw} ? PORTFW :
96 $options->{masq} ? MASQ : NOMASQ;
97  
98 my $query;
99 if ( $options->{server} ) {
100 $query = undef;
101 } else {
102 $query = $options->{"query-port"} || $self->{query_port};
103 }
104 $udp->attribute( SourcePort => $query );
105 acct_udp_ruleset( $udp, $src, $src_if, $dst, $dst_if, $masq );
106 acct_tcp_ruleset( $tcp, $src, $src_if, $dst, $dst_if, $masq );
107 }
108  
109 sub valid_options {
110 my $self = shift;
111 ( "query-port=s", "server" );
112 }
113  
114 1;
115  
116 =pod
117  
118 =head1 NAME
119  
120 Fwctl::Services::name_service - Fwctl module to handle the DNS protocol.
121  
122 =head1 SYNOPSIS
123  
124 accept name_service -src INTERNET -dst NAME_SERVER
125 accept name_service -src NAME_SERVER -dst INTERNET -query-port 5353
126  
127 =head1 DESCRIPTION
128  
129 The name_service module handles the DNS protocol. It can handle both
130 name server and resolver configuration. When using the I<server>
131 option, the query can be from any ports. You can use the I<query-port>
132 option to specify the client port.
133  
134 Default is to use only ports > 1023 as client port. (Usual resolver
135 situation.)
136  
137 =head1 AUTHOR
138  
139 Francis J. Lacoste <francis.lacoste@iNsu.COM>
140  
141 =head1 COPYRIGHT
142  
143 Copyright (c) 1999,2000 iNsu Innovations Inc.
144 All rights reserved.
145  
146 This program is free software; you can redistribute it and/or modify
147 it under the terms of the GNU General Public License as published by
148 the Free Software Foundation; either version 2 of the License, or
149 (at your option) any later version.
150  
151 =head1 SEE ALSO
152  
153 fwctl(8) Fwctl(3) Fwctl::RuleSet(3)
154  
155 =cut
156