| 1 | # | ||
| 2 | # pptp.pm: Fwctl service module to handle the PPTP service. | ||
| 3 | # | ||
| 4 | # This file is part of Fwctl. | ||
| 5 | # | ||
| 6 | # Author: Francis J. Lacoste <francis.lacoste@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::pptp; | ||
| 16 | |||
| 17 | use strict; | ||
| 18 | |||
| 19 | use Fwctl::RuleSet qw(:tcp_rulesets :ip_rulesets :masq :ports); | ||
| 20 | use IPChains; | ||
| 21 | use Carp; | ||
| 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 => 'tcp', | ||
| 37 | SourcePort => UNPRIVILEGED_PORTS, | ||
| 38 | DestPort => 1723, | ||
| 39 | %{$options->{ipchains}}, | ||
| 40 | ), | ||
| 41 | IPChains->new( | ||
| 42 | Rule => $target, | ||
| 43 | Prot => 47, # GRE | ||
| 44 | %{$options->{ipchains}}, | ||
| 45 | ), | ||
| 46 | ); | ||
| 47 | } | ||
| 48 | |||
| 49 | sub block_rules { | ||
| 50 | my $self = shift; | ||
| 51 | my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_; | ||
| 52 | |||
| 53 | my ($control,$gre) = $self->prototypes( $target, $options ); | ||
| 54 | |||
| 55 | block_tcp_ruleset( $control, $src, $src_if, $dst, $dst_if ); | ||
| 56 | block_ip_ruleset( $gre, $src, $src_if, $dst, $dst_if ); | ||
| 57 | block_ip_ruleset( $gre, $dst, $dst_if, $src, $src_if ); | ||
| 58 | } | ||
| 59 | |||
| 60 | sub accept_rules { | ||
| 61 | my $self = shift; | ||
| 62 | my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_; | ||
| 63 | |||
| 64 | my ($control, $gre ) = $self->prototypes( $target, $options ); | ||
| 65 | |||
| 66 | my $masq = defined $options->{portfw} ? PORTFW : | ||
| 67 | $options->{masq} ? MASQ : NOMASQ; | ||
| 68 | |||
| 69 | accept_tcp_ruleset( $control, $src, $src_if, $dst, $dst_if, | ||
| 70 | $masq, $options->{portfw} ); | ||
| 71 | accept_ip_ruleset( $gre, $src, $src_if, $dst, $dst_if, | ||
| 72 | $masq, $options->{portfw} ); | ||
| 73 | |||
| 74 | if ( $masq & MASQ ) { | ||
| 75 | $masq &= $masq ^ MASQ; | ||
| 76 | $masq |= UNMASQ; | ||
| 77 | } elsif ( $masq & PORTFW ) { | ||
| 78 | $masq &= $masq ^ PORTFW; | ||
| 79 | $masq |= UNPORTFW; | ||
| 80 | } | ||
| 81 | accept_ip_ruleset( $gre, $dst, $dst_if, $src, $src_if, | ||
| 82 | $masq, $options->{portfw} ); | ||
| 83 | |||
| 84 | if ($options->{masq} || $options->{portfw} ) { | ||
| 85 | system ( "/sbin/modprobe", "ip_masq_pptp" ) == 0 | ||
| 86 | or carp __PACKAGE__, ": couldn't load ip_masq_pptp: $?\n"; | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | sub account_rules { | ||
| 91 | my $self = shift; | ||
| 92 | my ( $target, $src, $src_if, $dst, $dst_if, $options ) = @_; | ||
| 93 | |||
| 94 | my ( $control, $gre ) = $self->prototypes( $target, $options ); | ||
| 95 | |||
| 96 | my $masq = defined $options->{portfw} ? PORTFW : | ||
| 97 | $options->{masq} ? MASQ : NOMASQ; | ||
| 98 | |||
| 99 | acct_tcp_ruleset( $control, $src, $src_if, $dst, $dst_if, | ||
| 100 | $masq, $options->{portfw} ); | ||
| 101 | acct_ip_ruleset( $gre, $src, $src_if, $dst, $dst_if, | ||
| 102 | $masq, $options->{portfw} ); | ||
| 103 | |||
| 104 | if ( $masq & MASQ ) { | ||
| 105 | $masq &= $masq ^ MASQ; | ||
| 106 | $masq |= UNMASQ; | ||
| 107 | } elsif ( $masq & PORTFW ) { | ||
| 108 | $masq &= $masq ^ PORTFW; | ||
| 109 | $masq |= UNPORTFW; | ||
| 110 | } | ||
| 111 | acct_ip_ruleset( $gre, $dst, $dst_if, $src, $src_if, | ||
| 112 | $masq, $options->{portfw} ); | ||
| 113 | |||
| 114 | } | ||
| 115 | |||
| 116 | sub valid_options { | ||
| 117 | my $self = shift; | ||
| 118 | ( ); | ||
| 119 | } | ||
| 120 | |||
| 121 | 1; | ||
| 122 | =pod | ||
| 123 | |||
| 124 | =head1 NAME | ||
| 125 | |||
| 126 | Fwctl::Services::pptp - Fwctl module to handle the PPTP service. | ||
| 127 | |||
| 128 | =head1 SYNOPSIS | ||
| 129 | |||
| 130 | accept pptp -src INT_NET -dst REMOTE_PPTP --masq | ||
| 131 | |||
| 132 | =head1 DESCRIPTION | ||
| 133 | |||
| 134 | This module will implements the rules to accept/block/account the PPTP | ||
| 135 | tunnelling protocol. In order to be able to masquerade that protocol, you | ||
| 136 | will need a kernel with the generic protocol masquerade patch applied. | ||
| 137 | |||
| 138 | See ftp://ftp.rubyriver.com/pub/jhardin/masquerade/ for informations. | ||
| 139 | |||
| 140 | If you want to generates rules for a server behind the firewall, you will | ||
| 141 | have to use the --portfw option and starts manually the ipfwd daemon. | ||
| 142 | |||
| 143 | =head1 AUTHOR | ||
| 144 | |||
| 145 | Francis J. Lacoste <francis.lacoste@iNsu.COM> | ||
| 146 | |||
| 147 | =head1 COPYRIGHT | ||
| 148 | |||
| 149 | Copyright (c) 1999,2000 iNsu Innovations Inc. | ||
| 150 | All rights reserved. | ||
| 151 | |||
| 152 | This program is free software; you can redistribute it and/or modify | ||
| 153 | it under the terms of the GNU General Public License as published by | ||
| 154 | the Free Software Foundation; either version 2 of the License, or | ||
| 155 | (at your option) any later version. | ||
| 156 | |||
| 157 | =head1 SEE ALSO | ||
| 158 | |||
| 159 | fwctl(8) Fwctl(3) Fwctl::RuleSet(3) | ||
| 160 | |||
| 161 | =cut | ||
| 162 |