2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-09-01 14:55:10 +00:00

fixes for bugs 177039 1980891 198359

This commit is contained in:
David J Drewelow
2006-11-10 09:43:04 +00:00
parent e44e921e4f
commit 5cb58d5430
2 changed files with 92 additions and 152 deletions

View File

@@ -1,4 +1,4 @@
#!/usr/bin/perl -w #!/usr/bin/perl
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# #
@@ -12,172 +12,138 @@
################################################################################ ################################################################################
# ag_sd_config # ag_sd_config
#
# Version 0.51
################################################################################ ################################################################################
use Immunix::Ycp;
use Immunix::Reports;
use strict; use strict;
use ycp;
use Immunix::Notify;
use Immunix::Reports;
use Data::Dumper; use Data::Dumper;
use POSIX;
use Locale::gettext;
setlocale(LC_MESSAGES, "");
textdomain("apparmor-utils");
# Subroutines # Subroutines
################################################################################ ################################################################################
sub setSubdomain { sub setSubdomain {
my $action = shift; my $action = shift;
my $errmsg = ""; my $errmsg = "";
my $lines = 0; my $lines = 0;
if ($action eq "enable") { if ($action eq "enable") {
if (-e "/sbin/rcapparmor") { if (-e "/sbin/rcapparmor") {
open(RUN, "/sbin/rcapparmor start 2>&1 |"); open(RUN, "/sbin/rcapparmor start 2>&1 |");
} else { } else {
open(RUN, "/sbin/rcsubdomain start 2>&1 |"); open(RUN, "/sbin/rcsubdomain start 2>&1 |");
} }
while (<RUN>) { while (<RUN>) {
if (/FATAL:(.*)/) { if (/FATAL:(.*)/) {
$errmsg = $1; $errmsg = $1;
} }
} }
close(RUN); close(RUN);
if (-f "/etc/init.d/boot.apparmor") { if (-f "/etc/init.d/boot.apparmor") {
system("/sbin/insserv boot.apparmor"); system("/sbin/insserv boot.apparmor");
} else { } else {
system("/sbin/insserv boot.subdomain"); system("/sbin/insserv boot.subdomain");
} }
if (-f "/etc/init.d/aaeventd") { if (-f "/etc/init.d/aaeventd") {
system("/sbin/rcaaeventd start"); system("/sbin/rcaaeventd start");
system("/sbin/insserv aaeventd"); system("/sbin/insserv aaeventd");
} }
} else { } else {
if (-e "/sbin/rcapparmor") { if (-e "/sbin/rcapparmor") {
open(RUN, "/sbin/rcapparmor stop 2>&1 |"); open(RUN, "/sbin/rcapparmor stop 2>&1 |");
} else { } else {
open(RUN, "/sbin/rcsubdomain stop 2>&1 |"); open(RUN, "/sbin/rcsubdomain stop 2>&1 |");
} }
while (<RUN>) { while (<RUN>) {
if (/FATAL:(.*)/) { if (/FATAL:(.*)/) {
$errmsg = $1; $errmsg = $1;
} }
} }
close(RUN); close(RUN);
if (-f "/etc/init.d/boot.apparmor") { if (-f "/etc/init.d/boot.apparmor") {
system("/sbin/insserv -r boot.apparmor"); system("/sbin/insserv -r boot.apparmor");
} else { } else {
system("/sbin/insserv -r boot.subdomain"); system("/sbin/insserv -r boot.subdomain");
} }
if (-f "/etc/init.d/aaeventd") { if (-f "/etc/init.d/aaeventd") {
system("/sbin/rcaaeventd stop"); system("/sbin/rcaaeventd stop");
system("/sbin/insserv -e aaeventd"); system("/sbin/insserv -e aaeventd");
} }
} }
return $errmsg; return $errmsg;
} }
sub setNotify { sub setNotify {
my $action = shift; my $action = shift;
return 0; return 0;
} }
sub setLearningMode { sub setLearningMode {
my $action = shift; my $action = shift;
my $rcscript = -f "/sbin/rcapparmor" ? "/sbin/rcapparmor" my $rcscript = -f "/sbin/rcapparmor" ? "/sbin/rcapparmor"
: "/sbin/rcsubdomain"; : "/sbin/rcsubdomain";
if ($action eq "enable") { if ($action eq "enable") {
system("$rcscript", "stop"); system("$rcscript", "stop");
system("$rcscript", "complain"); system("$rcscript", "complain");
} else { } else {
system("$rcscript". "stop"); system("$rcscript". "stop");
system("$rcscript", "start"); system("$rcscript", "start");
} }
return 0; return 0;
} }
sub setNotifySettings {
my $config = shift;
Immunix::Reports::enableEventD();
open(CFG, "> /etc/apparmor/notify.cfg") or die "can't write config info: $!";
if($config->{enable_terse} eq "yes") {
# if we didn't get passed a valid frequency, default to off
$config->{terse_freq} ||= 0;
$config->{terse_level} ||= 0;
# default to including unknown events if we didn't get passed that setting
$config->{terse_unknown} = 1 unless defined $config->{terse_unknown};
print CFG "terse_freq $config->{terse_freq}\n";
print CFG "terse_email $config->{terse_email}\n";
print CFG "terse_level $config->{terse_level}\n";
print CFG "terse_unknown $config->{terse_unknown}\n";
}
if($config->{enable_summary} eq "yes") {
# if we didn't get passed a valid frequency, default to off
$config->{summary_freq} ||= 0;
$config->{summary_level} ||= 0;
# default to including unknown events if we didn't get passed that setting
$config->{summary_unknown} = 1 unless defined $config->{summary_unknown};
print CFG "summary_freq $config->{summary_freq}\n";
print CFG "summary_email $config->{summary_email}\n";
print CFG "summary_level $config->{summary_level}\n";
print CFG "summary_unknown $config->{summary_unknown}\n";
}
if($config->{enable_verbose} eq "yes") {
# if we didn't get passed a valid frequency, default to off
$config->{verbose_freq} ||= 0;
$config->{verbose_level} ||= 0;
# default to including unknown events if we didn't get passed that setting
$config->{verbose_unknown} = 1 unless defined $config->{verbose_unknown};
print CFG "verbose_freq $config->{verbose_freq}\n";
print CFG "verbose_email $config->{verbose_email}\n";
print CFG "verbose_level $config->{verbose_level}\n";
print CFG "verbose_unknown $config->{verbose_unknown}\n";
}
close(CFG);
}
# Main # Main
################################################################################ ################################################################################
while ( <STDIN> ) { while ( <STDIN> ) {
my ($command, $path, $argument) = Immunix::Ycp::ParseCommand ($_); my ($command, $path, $argument) = ycp::ParseCommand ($_);
Immunix::Ycp::y2debug ("command: $command, path: $path");
my $result = undef; my $result = undef;
my $action = undef; my $action = undef;
if ( $command && $path && $argument ) { if ( $command && $path && $argument ) {
if(ref($argument) eq "HASH" && $argument->{"sd-set-notify"}) { if (ref($argument) eq "HASH" && $argument->{"set_notify"}) {
setNotifySettings($argument); my ($ntSettings, $result) = Immunix::Notify::sanitize($argument);
Immunix::Ycp::Return("true");
next;
}
($action) = (split(/:/, $argument))[1]; if ($result ne "success") {
ycp::Return($result);
next;
} else {
$result = Immunix::Notify::setNotifySettings($ntSettings);
ycp::Return($result);
next;
}
}
Immunix::Ycp::y2milestone ("ag_sd_config=> Arg: $argument, Action: $action"); ($action) = (split(/:/, $argument))[1];
if ( $argument =~ /subdomain/ ) { if ( $argument =~ /subdomain/ ) {
$result = setSubdomain($action); $result = setSubdomain($action);
} elsif ( $argument =~ /learning/ ) { } elsif ( $argument =~ /learning/ ) {
setLearningMode($action); setLearningMode($action);
} elsif ( $argument eq 'sd-notify') { } elsif ( $argument eq 'sd-notify') {
setNotify($action); setNotify($action);
} }
Immunix::Ycp::y2milestone ("ag_sd_config=> DONE Arg: $argument, Action: $action");
if ( $result ) { if ( $result ) {
Immunix::Ycp::Return( $result ); ycp::Return( $result );
} else { } else {
Immunix::Ycp::Return("true"); ycp::Return("true");
} }
} }
} }
exit 0; exit 0;

View File

@@ -18,9 +18,16 @@
################################################################################ ################################################################################
use strict; use strict;
use Immunix::Ycp; use ycp;
use Immunix::Notify;
use Immunix::SubDomain; use Immunix::SubDomain;
use Data::Dumper; use Data::Dumper;
#use POSIX;
#use Locale::gettext;
#setlocale(LC_MESSAGES, "");
#textdomain("apparmor-utils");
# Subroutines # Subroutines
################################################################################ ################################################################################
@@ -47,38 +54,6 @@ sub getSubdomainStatus {
return $sdStatus; return $sdStatus;
} }
sub getNotifySettings {
my $config = { };
if(open(CFG, "/etc/apparmor/notify.cfg")) {
while(<CFG>) {
chomp;
$config->{$1} = $2 if /^(\S+)\s+(.+)\s*$/;
}
close(CFG);
}
return $config;
}
sub getNotifyStatus {
my $config = getNotifySettings();
my $noteStatus = "disabled";
if($config->{terse_freq} && $config->{terse_freq} != 0) {
$noteStatus = "enabled";
} elsif($config->{summary_freq} && $config->{summary_freq} != 0) {
$noteStatus = "enabled";
} elsif($config->{verbose_freq} && $config->{verbose_freq} != 0) {
$noteStatus = "enabled";
}
return $noteStatus;
}
sub profileSyntaxCheck { sub profileSyntaxCheck {
my $errlist = []; my $errlist = [];
Immunix::SubDomain::checkIncludeSyntax($errlist); Immunix::SubDomain::checkIncludeSyntax($errlist);
@@ -91,10 +66,8 @@ sub profileSyntaxCheck {
# Main # Main
################################################################################ ################################################################################
while ( <STDIN> ) { while ( <STDIN> ) {
my ($command, $path, $argument) = Immunix::Ycp::ParseCommand($_); my ($command, $path, $argument) = ycp::ParseCommand($_);
my $result = undef; my $result = undef;
my $donereturn = 0; my $donereturn = 0;
@@ -102,32 +75,33 @@ while ( <STDIN> ) {
if ( $argument eq 'sd-all') { if ( $argument eq 'sd-all') {
my %hResult = ''; # hashed result, duh my %hResult = ''; # hashed result, duh
$hResult{'sd-status'} = getSubdomainStatus(); $hResult{'sd-status'} = getSubdomainStatus();
$hResult{'sd-notify'} = getNotifyStatus(); $hResult{'sd-notify'} = Immunix::Notify::getNotifyStatus();
Immunix::Ycp::ycpReturnHashAsMap( %hResult ); #ycp::ycpReturnHashAsMap( %hResult );
ycp::Return( %hResult );
$donereturn = 1; $donereturn = 1;
} elsif ( $argument eq 'sd-status') { } elsif ( $argument eq 'sd-status') {
$result = getSubdomainStatus(); $result = getSubdomainStatus();
} elsif ( $argument eq 'sd-notify') { } elsif ( $argument eq 'sd-notify') {
$result = getNotifyStatus(); $result = Immunix::Notify::getNotifyStatus();
} elsif ( $command eq "Read" and $argument eq 'custom-includes') { } elsif ( $command eq "Read" and $argument eq 'custom-includes') {
Immunix::SubDomain::readconfig(); Immunix::SubDomain::readconfig();
Immunix::Ycp::ycpReturn(\@Immunix::SubDomain::custom_includes); ycp::ycpReturn(\@Immunix::SubDomain::custom_includes);
$donereturn = 1; $donereturn = 1;
} elsif ( $command eq "Execute" and $argument eq 'profile-syntax-check') { } elsif ( $command eq "Execute" and $argument eq 'profile-syntax-check') {
$result = profileSyntaxCheck(); $result = profileSyntaxCheck();
Immunix::Ycp::ycpReturn($result); ycp::ycpReturn($result);
$donereturn = 1; $donereturn = 1;
} elsif ( $argument eq 'sd-notify-settings') { } elsif ( $argument eq 'sd-notify-settings') {
$result = getNotifySettings(); $result = Immunix::Notify::getNotifySettings();
Immunix::Ycp::ycpReturn($result); ycp::Return($result);
$donereturn = 1; $donereturn = 1;
} }
Immunix::Ycp::ycpReturnSkalarAsString( $result ) if ( ! $donereturn ); ycp::ycpReturnSkalarAsString( $result ) if ( ! $donereturn );
} else { } else {
my $ycpCmd = ycpGetCommand() || ""; my $ycpCmd = ycpGetCommand() || "";
my $ycpArg = ycpGetArgType() || ""; my $ycpArg = ycpGetArgType() || "";
$result = "Unknown instruction $ycpCmd or argument: $ycpArg\n"; $result = "Unknown instruction $ycpCmd or argument: $ycpArg\n";
Immunix::Ycp::ycpReturnSkalarAsString( $result ); ycp::ycpReturnSkalarAsString( $result );
} }
print "\n"; print "\n";
} }