2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-09-01 23:05:11 +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,18 +12,21 @@
################################################################################
# ag_sd_config
#
# Version 0.51
################################################################################
use Immunix::Ycp;
use Immunix::Reports;
use strict;
use ycp;
use Immunix::Notify;
use Immunix::Reports;
use Data::Dumper;
use POSIX;
use Locale::gettext;
setlocale(LC_MESSAGES, "");
textdomain("apparmor-utils");
# Subroutines
################################################################################
sub setSubdomain {
my $action = shift;
@@ -99,71 +102,34 @@ sub setLearningMode {
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
################################################################################
while ( <STDIN> ) {
my ($command, $path, $argument) = Immunix::Ycp::ParseCommand ($_);
Immunix::Ycp::y2debug ("command: $command, path: $path");
my ($command, $path, $argument) = ycp::ParseCommand ($_);
my $result = undef;
my $action = undef;
if ( $command && $path && $argument ) {
if(ref($argument) eq "HASH" && $argument->{"sd-set-notify"}) {
setNotifySettings($argument);
Immunix::Ycp::Return("true");
if (ref($argument) eq "HASH" && $argument->{"set_notify"}) {
my ($ntSettings, $result) = Immunix::Notify::sanitize($argument);
if ($result ne "success") {
ycp::Return($result);
next;
} else {
$result = Immunix::Notify::setNotifySettings($ntSettings);
ycp::Return($result);
next;
}
}
($action) = (split(/:/, $argument))[1];
Immunix::Ycp::y2milestone ("ag_sd_config=> Arg: $argument, Action: $action");
if ( $argument =~ /subdomain/ ) {
$result = setSubdomain($action);
} elsif ( $argument =~ /learning/ ) {
@@ -171,11 +137,11 @@ while ( <STDIN> ) {
} elsif ( $argument eq 'sd-notify') {
setNotify($action);
}
Immunix::Ycp::y2milestone ("ag_sd_config=> DONE Arg: $argument, Action: $action");
if ( $result ) {
Immunix::Ycp::Return( $result );
ycp::Return( $result );
} else {
Immunix::Ycp::Return("true");
ycp::Return("true");
}
}
}

View File

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