2
# ------------------------------------------------------------------
4
# Copyright (C) 2002-2005 Novell/SUSE
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of version 2 of the GNU General Public
8
# License published by the Free Software Foundation.
10
# ------------------------------------------------------------------
17
setlocale(LC_MESSAGES, "");
18
textdomain("yast2-apparmor");
21
################################################################################
28
print "Prog: $_->{'prog'}, Prof: $_->{'prof'}, PID: $_->{'pid'}, ";
29
print "State: $_->{'state'}, Type: $_->{'type'}\n";
38
return 0; # Shouldn't get here
47
my $host = `hostname`;
57
$ref->{'host'} = $host;
58
$ref->{'date'} = $date;
60
($ref->{'pid'}, $ref->{'prog'}, $all) = split(/\s+/, $_, 3);
61
$all = /\s*((not)*\s*confined\s*(by)*)/;
63
$ref->{'state'} =~ s/\s*by//g;
64
$ref->{'state'} =~ s/not\s+/not-/g;
65
($ref->{'prof'}, $ref->{'type'}) = split(/\s+/, $_);
70
if ( scalar(@cfDb) < 1 ) {
71
return "Error: parsing all messed up!!\n";
78
# Writes out file to allow for multiple pages in YaST form
79
# -For large number of entries in the array
84
my $pagingFile = "/var/log/apparmor/reports/events.rpt";
86
if ( open(PF, ">$pagingFile") ) {
92
print PF "Page $page\n";
97
# Order (for YaST): "host", "date", "prog", "prof", "pid", "state", "type"
98
print PF "$_->{'host'},$_->{'date'},$_->{'prog'},$_->{'prof'},$_->{'pid'},$_->{'state'},$_->{'type'}\n";
100
if ( ($i % 100) == 0 && $skip == 0) {
101
print PF "Page $page\n";
113
ycp::y2error(sprintf(gettext("ag_reports_confined: Couldn't open %s for writing."), $pagingFile));
119
sub readMultiAudLog {
125
my $dir = '/var/log/apparmor/reports-archived';
130
if ( $args->{'repPath'} ) { $dir = $args->{'repPath'}; }
132
# Get list of files in archived report directory
133
if ( opendir (RDIR, $dir) ) {
135
@repList = grep(/Applications.Audit/, readdir(RDIR));
139
$error = sprintf(gettext("Failure in readMultiAudLog() - couldn't open %s."), $dir);
140
return($error); # debug - exit instead?
147
next if $file =~ /$\.html/;
149
# Cycle through each $file in $dir
150
if (open (RPT, "<$dir/$file") ) {
154
$error = sprintf(gettext("Problem in readMultiAudLog\(\) - couldn't open %s\/%s."), $dir, $file);
155
#$error = "Problem in readMultiAudLog() - couldn't open $dir/$file.";
156
push(@errors, $error);
163
next if (! $_ || $_ eq "");
167
( $rec->{'host'}, $rec->{'date'}, $rec->{'prog'}, $rec->{'prof'}, $rec->{'pid'},
168
$rec->{'state'}, $rec->{'type'} ) = split(/\,/, $_);
181
my $dir = '/var/log/apparmor/reports-archived';
185
if ($args->{'file'}) {
186
$logFile = $args->{'file'};
188
$error = gettext("readAudLog() wasn't passed an input file.");
189
ycp::y2error($error);
193
if ( open(AUD, "<$dir/$logFile") ) {
203
( $rec->{'host'}, $rec->{'date'}, $rec->{'prog'}, $rec->{'prof'}, $rec->{'pid'},
204
$rec->{'state'}, $rec->{'type'} ) = split(/\,/, $_);
212
$error = sprintf(gettext("readAudLog\(\) couldn't open %s."), $logFile);
213
ycp::y2error($error);
225
my $cfApp = '/usr/sbin/unconfined';
227
if ( open (CF, "$cfApp |") ) {
229
my $host = `hostname`;
232
my $date = localtime;
239
$ref->{'host'} = $host;
240
$ref->{'date'} = $date;
243
($ref->{'pid'}, $ref->{'prog'}, $all) = split(/\s+/, $_, 3);
245
$all = /\s*((not)*\s*confined\s*(by)*)/;
246
$ref->{'state'} = $1;
247
$ref->{'state'} =~ s/\s*by//g;
248
$ref->{'state'} =~ s/not\s+/not-/g;
250
if ($ref->{'state'} =~ /not-confined/ ) {
251
$ref->{'prof'} = "-";
252
$ref->{'type'} = "-";
254
($info) = (split(/\'/, $info, 2))[1];
255
($ref->{'prof'}, $ref->{'type'}) = split(/\s+/, $info);
256
$ref->{'type'} =~ s/\(|\)|\'//g;
259
if ( $ref->{'prog'} eq "") { $ref->{'prog'} = "-"; }
260
if ( $ref->{'prof'} eq "") { $ref->{'prof'} = "-"; }
261
if ( $ref->{'pid'} eq "") { $ref->{'pid'} = "-"; }
262
if ( $ref->{'state'} eq "") { $ref->{'state'} = "-"; }
263
if ( $ref->{'type'} eq "") { $ref->{'type'} = "-"; }
270
my $error = sprintf(gettext("Can't run %s. Exiting."), $cfApp);
271
ycp::y2error($error);
279
################################################################################
284
my ($command, $path, $args) = ycp::ParseCommand ($_);
286
if ( $command && $path && $args ) {
290
if ($args->{'audArch'} && $args->{'audArch'} == 1) {
292
if (! $args->{'single'} || $args->{'single'} != 1 ) {
293
$db = readMultiAudLog($args);
295
$db = readAudLog($args);
302
writePagingFile($db);
306
my $error = gettext("ag_reports_confined: Missing instruction or argument!");
307
ycp::y2error($error);