diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2002-08-22 22:42:56 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2002-08-22 22:42:56 +0000 |
commit | b61548ee174481b25e750be9f7d4c7484a0ebf96 (patch) | |
tree | 59ab4d150f6d8a72148f68763c8c61b714b7cb04 /perl-install | |
parent | fbde1a0bdc207d0be42e9c32ed0da6f1526ef927 (diff) | |
download | drakx-b61548ee174481b25e750be9f7d4c7484a0ebf96.tar drakx-b61548ee174481b25e750be9f7d4c7484a0ebf96.tar.gz drakx-b61548ee174481b25e750be9f7d4c7484a0ebf96.tar.bz2 drakx-b61548ee174481b25e750be9f7d4c7484a0ebf96.tar.xz drakx-b61548ee174481b25e750be9f7d4c7484a0ebf96.zip |
- add network::shorewall
- add tinyfirewall during install
Diffstat (limited to 'perl-install')
-rw-r--r-- | perl-install/network/netconnect.pm | 5 | ||||
-rw-r--r-- | perl-install/network/shorewall.pm | 136 | ||||
-rw-r--r-- | perl-install/network/tinyfirewall.pm (renamed from perl-install/tinyfirewall.pm) | 42 |
3 files changed, 168 insertions, 15 deletions
diff --git a/perl-install/network/netconnect.pm b/perl-install/network/netconnect.pm index ad7ee7082..0f6bb1d80 100644 --- a/perl-install/network/netconnect.pm +++ b/perl-install/network/netconnect.pm @@ -331,6 +331,11 @@ fi $netcnx->{type} =~ /adsl/ or system("/sbin/chkconfig --del adsl 2> /dev/null"); save_conf($netcnx, $netc, $intf); + if ($::isInstall && $::o->{security} >= 3) { + require network::tinyfirewall; + network::tinyfirewall::main($in, $::o->{security} <= 3); + } + #- if ($netc->{NET_DEVICE} and $netc->{NETWORKING} ne 'no' and $::isStandalone and $::expert) { #- exists $netc->{nb_cards} or do { #- any::load_category($in, 'network/main|usb', !$::expert, 1); diff --git a/perl-install/network/shorewall.pm b/perl-install/network/shorewall.pm new file mode 100644 index 000000000..a9f8ff384 --- /dev/null +++ b/perl-install/network/shorewall.pm @@ -0,0 +1,136 @@ +package network::shorewall; # $Id$ + +use diagnostics; +use strict; + +use detect_devices; +use network::netconnect; +use common; +use log; + +my @drakgw_ports = qw(domain bootps); + +sub check_iptables { + my ($in) = @_; + + my $existing_config = -f "$::prefix/etc/sysconfig/iptables"; + + $existing_config ||= $::isStandalone && do { + system('modprobe iptable_nat'); + -x '/sbin/iptables' && listlength(`/sbin/iptables -t nat -nL`) > 8; + }; + + !$existing_config || $in->ask_okcancel(_("Firewalling configuration detected!"), + _("Warning! An existing firewalling configuration has been detected. You may need some manual fix after installation.")); +} + +sub set_config_file { + my ($file, @l) = @_; + + my $done; + substInFile { + if (!$done && (/^#LAST LINE/ || eof)) { + $_ = join('', map { join("\t", @$_) . "\n" } @l) . $_; + $done = 1; + } else { + $_ = '' if /^[^#]/; + } + } "/etc/shorewall/$file"; +} + +sub get_config_file { + my ($file) = @_; + map { [ split ' ' ] } grep { !/^#/ } cat_("/etc/shorewall/$file"); +} + +sub default_interfaces { + my %conf; + + my @l = detect_devices::getNet() or return; + if (@l == 1) { + $conf{net_interface} = $l[0]; + $conf{loc_interface} = [ 'lo0' ]; + } else { + $conf{net_interface} = network::netconnect::get_net_device() or return; + $conf{loc_interface} = [ grep { $_ ne $conf{net_interface} } @l ]; + } + \%conf; +} + +sub read { + my %conf; + + $conf{disabled} = !glob_("$::prefix/etc/rc3.d/S*shorewall"); + + $conf{ports} = + join(' ', map { + my $e = $_; + map { "$_/$e->[3]" } split(',', $e->[4]); + } grep { $_->[0] eq 'ACCEPT' && $_->[1] eq 'net' } get_config_file('rules')); + + if (my ($e) = get_config_file('masq')) { + $conf{masquerade}{subnet} = $e->[1] if $e->[1]; + } + foreach (get_config_file('interfaces')) { + my ($name, $interface) = @$_; + if ($name eq 'net') { + $conf{net_interface} = $interface; + } elsif ($name eq 'masq') { + $conf{masquerade}{interface} = $interface; + } elsif ($name eq 'loc') { + push @{$conf{loc_interface}}, $interface; + } else { + log::l("unknown interface name $name"); + } + } + $conf{net_interface} && \%conf; +} + +sub write { + my ($conf) = @_; + + my %ports_by_proto; + foreach (split ' ', $conf->{ports}) { + m!^(\d+)/(udp|tcp)$! or die "bad port $_\n"; + push @{$ports_by_proto{$2}}, $1; + } + + set_config_file("zones", + [ 'net', 'Net', 'Internet zone' ], + if_($conf->{masquerade}, [ 'masq', 'Masquerade', 'Masquerade Local' ]), + if_($conf->{loc_interface}, [ 'loc', 'Local', 'Local' ]), + ); + set_config_file('interfaces', + [ 'net', $conf->{net_interface}, 'detect' ], + $conf->{masquerade} ? [ 'masq', $conf->{masquerade}{interface}, 'detect' ] : (), + (map { [ 'loc', $_, 'detect' ] } @{$conf->{loc_interface} || []}), + ); + set_config_file('policy', + if_($conf->{masquerade}, [ 'masq', 'net', 'ACCEPT' ]), + if_($conf->{loc_interface}, [ 'loc', 'net', 'ACCEPT' ]), + [ 'fw', 'net', 'ACCEPT' ], + [ 'net', 'all', 'DROP', 'info' ], + [ 'all', 'all', 'REJECT', 'info' ], + ); + set_config_file('rules', + (map + { map_each { [ 'ACCEPT', $_, 'fw', $::a, join(',', @$::b), '-' ] } %ports_by_proto } + ('net', if_($conf->{masquerade}, 'masq'), if_($conf->{loc_interface}, 'loc'))), + if_($conf->{masquerade}, map { [ 'ACCEPT', 'masq', 'fw', 'tcp', join(',', @drakgw_ports), '-' ] } 'tcp', 'udp'), + ); + set_config_file('masq', + $conf->{masquerade} ? [ $conf->{net_interface}, $conf->{masquerade}{subnet} ]: (), + ); + + if ($conf->{disabled}) { + run_program::rooted($::prefix, 'chkconfig', '--del', 'shorewall'); + run_program::run('service', 'shorewall', 'stop') if $::isStandalone; + run_program::run('service', 'shorewall', 'clear') if $::isStandalone; + } else { + run_program::rooted($::prefix, 'chkconfig', '--add', 'shorewall'); + run_program::run('service', 'shorewall', 'restart') if $::isStandalone; + } +} + +1; + diff --git a/perl-install/tinyfirewall.pm b/perl-install/network/tinyfirewall.pm index 422efd7b8..39df72521 100644 --- a/perl-install/tinyfirewall.pm +++ b/perl-install/network/tinyfirewall.pm @@ -1,8 +1,9 @@ -package tinyfirewall; # $Id$ +package network::tinyfirewall; # $Id$ use diagnostics; use strict; +use network::shorewall; use common; my @all_servers = @@ -99,21 +100,31 @@ sub default_from_pkgs { } sub get_ports { + my ($ports) = @_; + my $shorewall = network::shorewall::read() or return; + \$shorewall->{ports}; } sub set_ports { - my ($ports) = @_; - print "set_ports $$ports\n"; + my ($disabled, $ports) = @_; + + my $shorewall = network::shorewall::read() || network::shorewall::default_interfaces() or die ''; + $shorewall->{disabled} = $disabled; + $shorewall->{ports} = $$ports; + + network::shorewall::write($shorewall); } sub get_conf { - my ($in, $ports) = @_; + my ($in, $disabled, $ports) = @_; my $possible_servers = default_from_pkgs($in); $_->{hide} = 0 foreach @$possible_servers; - if ($ports ||= get_ports()) { - from_ports($ports); + if ($ports) { + $disabled, from_ports($ports); + } elsif (my $shorewall = network::shorewall::read()) { + $shorewall->{disabled}, from_ports(\$shorewall->{ports}); } else { $in->ask_okcancel('', _("tinyfirewall configurator @@ -121,12 +132,12 @@ This configures a personal firewall for this Mandrake Linux machine. For a powerful dedicated firewall solution, please look to the specialized MandrakeSecurity Firewall distribution."), 1) or return; - $possible_servers, ''; + $disabled, $possible_servers, ''; } } sub choose { - my ($in, $servers, $unlisted) = @_; + my ($in, $disabled, $servers, $unlisted) = @_; $_->{on} = 0 foreach @all_servers; $_->{on} = 1 foreach @$servers; @@ -148,21 +159,22 @@ where port is between 1 and 65535.", $invalid_port)); }, }}, [ - (map { { text => $_->{name}, val => \$_->{on}, type => 'bool' } } @l), - { label => _("Other ports"), val => \$unlisted, advanced => 1 } + { text => _("Everything (no firewall)"), val => \$disabled, type => 'bool' }, + (map { { text => $_->{name}, val => \$_->{on}, type => 'bool', disabled => sub { $disabled } } } @l), + { label => _("Other ports"), val => \$unlisted, advanced => 1, disabled => sub { $disabled } } ]) or return; - to_ports([ grep { $_->{on} } @l ], $unlisted); + $disabled, to_ports([ grep { $_->{on} } @l ], $unlisted); } sub main { - my ($in) = @_; + my ($in, $disabled) = @_; - my ($servers, $unlisted) = get_conf($in) or return; + ($disabled, my $servers, my $unlisted) = get_conf($in, $disabled) or return; $in->do_pkgs->ensure_is_installed('shorewall', '/sbin/shorewall', $::isInstall) or return; - my $ports = choose($in, $servers, $unlisted) or return; + ($disabled, my $ports) = choose($in, $disabled, $servers, $unlisted) or return; - set_ports($ports); + set_ports($disabled, $ports); } |