diff options
Diffstat (limited to 'perl-install/security/msec.pm')
| -rw-r--r-- | perl-install/security/msec.pm | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/perl-install/security/msec.pm b/perl-install/security/msec.pm index c672d0cb1..4258653ef 100644 --- a/perl-install/security/msec.pm +++ b/perl-install/security/msec.pm @@ -1,7 +1,6 @@ package security::msec; use strict; -use MDK::Common::File; use MDK::Common; @@ -16,10 +15,10 @@ sub load_defaults { my ($msec, $category) = @_; my $separator = $msec->{$category}{def_separator}; map { - my ($opt, $val) = split /$separator/; + my ($opt, $val) = split(/$separator/, $_, 2); chop $val; if_($opt ne 'set_security_conf', $opt => $val); - } cat_($msec->{$category}{defaults_file}); + } cat_($msec->{$category}{defaults_file}), if_($category eq "checks", 'MAIL_USER'); } @@ -49,7 +48,7 @@ sub load_values { chop $val; $val =~ s/[()]//g; chop $opt if $separator eq '\('; # $opt =~ s/ //g if $separator eq '\('; - if_($val, $opt => $val); + if_(defined($val), $opt => $val); } cat_($msec->{$category}{values_file}); } @@ -60,7 +59,7 @@ sub load_values { sub get_function_value { my ($msec, $function) = @_; - $msec->{functions}{value}{$function} || "default"; + exists $msec->{functions}{value}{$function} ? $msec->{functions}{value}{$function} : "default"; } sub get_check_value { @@ -76,9 +75,14 @@ sub get_check_value { # list_(functions|checks) - # return a list of functions|checks handled by level.local|security.conf +sub raw_checks_list { + my ($msec) = @_; + keys %{$msec->{checks}{default}}; +} + sub list_checks { my ($msec) = @_; - map { if_(!member($_, qw(MAIL_WARN MAIL_USER)), $_) } keys %{$msec->{checks}{default}}; + difference2([ $msec->raw_checks_list ], [ qw(MAIL_WARN MAIL_USER) ]); } sub list_functions { @@ -93,7 +97,7 @@ sub list_functions { enable_dns_spoofing_protection enable_ip_spoofing_protection enable_log_strange_packets enable_promisc_check no_password_aging_for)], 'system' => [qw(allow_autologin allow_issues allow_reboot allow_remote_root_login - allow_root_login allow_user_list allow_x_connections allow_xserver_to_listen + allow_root_login allow_user_list allow_xauth_from_root allow_x_connections allow_xserver_to_listen authorize_services enable_at_crontab enable_console_log enable_msec_cron enable_pam_wheel_for_su enable_password enable_security_check enable_sulogin password_aging password_history password_length set_root_umask @@ -101,7 +105,7 @@ sub list_functions { # get all function names; filter out those which are in the ignore # list, return what lefts. - map { if_(!member($_, @ignore_list) && member($_, @{$options{$category}}), $_) } keys %{$msec->{functions}{default}}; + grep { !member($_, @ignore_list) && member($_, @{$options{$category}}) } keys %{$msec->{functions}{default}}; } @@ -127,43 +131,42 @@ sub set_check { sub apply_functions { my ($msec) = @_; - my @list = ($msec->list_functions('system'), $msec->list_functions('network')); + my @list = sort($msec->list_functions('system'), $msec->list_functions('network')); + touch($msec->{functions}{values_file}) if !-e $msec->{functions}{values_file}; substInFile { foreach my $function (@list) { s/^$function.*\n// } if (eof) { - print "\n", join("\n", map { + $_ .= join("\n", if_(!$_, ''), (map { my $value = $msec->get_function_value($_); if_($value ne 'default', "$_ ($value)"); - } @list); + } @list), ""); } } $msec->{functions}{values_file}; } sub apply_checks { my ($msec) = @_; - my @list = $msec->list_checks; - substInFile { - foreach my $check (@list) { s/^$check.*\n// } - if (eof) { - print "\n", join("\n", map { - my $value = $msec->get_check_value($_); - if_($value ne 'default', $_ . '=' . $value); - } @list), "\n"; - } - } $msec->{checks}{values_file}; + my @list = sort $msec->raw_checks_list; + setVarsInSh($msec->{checks}{values_file}, + { + map { + my $value = $msec->get_check_value($_); + if_($value ne 'default', $_ => $value); + } @list + } + ); } sub reload { my ($msec) = @_; - my $num_level = 0; require security::level; - $num_level ||= security::level::get(); - $msec->{functions}{defaults_file} = "$::prefix/usr/share/msec/level.".$num_level; + my $num_level = security::level::get(); + $msec->{functions}{defaults_file} = "$::prefix/usr/share/msec/level.$num_level"; $msec->{functions}{default} = { $msec->load_defaults('functions') }; } sub new { - my $type = shift; + my ($type) = @_; my $msec = bless {}, $type; $msec->{functions}{values_file} = "$::prefix/etc/security/msec/level.local"; @@ -173,7 +176,7 @@ sub new { $msec->{functions}{val_separator} = '\('; $msec->{checks}{def_separator} = '='; $msec->{functions}{def_separator} = ' '; - $msec->reload(); + $msec->reload; $msec->{checks}{default} = { $msec->load_defaults('checks') }; $msec->{functions}{value} = { $msec->load_values('functions') }; |
