All of lore.kernel.org
 help / color / mirror / Atom feed
* simple Perl script to converse messages to access rules
@ 2001-12-04 13:57 Justin Smith
  2001-12-04 14:24 ` Stephen Smalley
  2001-12-04 14:36 ` [PATCH] AVC auditing changes Stephen Smalley
  0 siblings, 2 replies; 4+ messages in thread
From: Justin Smith @ 2001-12-04 13:57 UTC (permalink / raw)
  To: selinux

This will convert a sequence of access denied messages into
allow-commands.


One problem: even in permissive move, SELinux doesn't generate all
possible denied messages. After one enables access and reruns an
offending program, one gets more denied messages. It's as if the program
didn't completely run the previous time (although it should, in
permissive mode). 

Here's the perl script:
#------------------------------------cut here---------------------
#!/usr/bin/perl
open ERRFILE, "< messages";
open NEWRULES, "> newrules";

my %rules = ();

#
# format: $rules{ "$scontext|$tcontext|$tclass"}
#          = { '$accesstype1' => 1,'$accesstype2' => 1}, etc.,; 
#

while ($inline = <ERRFILE>)
  {
    next unless ($inline =~ /avc:\s*denied\s*\{\s*(\w+)\s*\}/);
    my $accesstype = $1;
    my $nextline = <ERRFILE>;
    $nextline =~ /:(\w+)\s*\Z/;
    my $scontext = $1;
    $nextline = <ERRFILE>;
    $nextline =~ /:(\w+)\s*\Z/;
    my $tcontext = $1;
    $nextline = <ERRFILE>;
    $nextline =~ /=(\w+)\s*\Z/;
    my $tclass = $1;
    $rules{"$scontext|$tcontext|$tclass" }{$accesstype}=1;
  }

# done  with the input file
# now generate the rules

foreach $k (sort keys %rules)
  {
    my ($scontext,$tcontext,$tclass) = split /\|/, $k;
    print NEWRULES "allow $scontext $tcontext:$tclass { ";
    my $access_types = $rules{$k};
    foreach $t (sort keys %$access_types)
      {
	print NEWRULES "$t ";
      }
    print NEWRULES "};\n";
  }


#-----------------end------------------------------------
-- 

--
You have received this message because you are subscribed to the selinux list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-12-04 14:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-12-04 13:57 simple Perl script to converse messages to access rules Justin Smith
2001-12-04 14:24 ` Stephen Smalley
2001-12-04 14:32   ` Justin Smith
2001-12-04 14:36 ` [PATCH] AVC auditing changes Stephen Smalley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.