~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to utils/audit

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl
2
 
#
3
 
# $Id: audit 483 2007-03-23 19:52:22Z steve-beattie $
4
 
#
5
 
# ----------------------------------------------------------------------
6
 
#    Copyright (c) 2005 Novell, Inc. All Rights Reserved.
7
 
#
8
 
#    This program is free software; you can redistribute it and/or
9
 
#    modify it under the terms of version 2 of the GNU General Public
10
 
#    License as published by the Free Software Foundation.
11
 
#
12
 
#    This program is distributed in the hope that it will be useful,
13
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
#    GNU General Public License for more details.
16
 
#
17
 
#    You should have received a copy of the GNU General Public License
18
 
#    along with this program; if not, contact Novell, Inc.
19
 
#
20
 
#    To contact Novell about this file by physical or electronic mail,
21
 
#    you may find current contact information at www.novell.com.
22
 
# ----------------------------------------------------------------------
23
 
 
24
 
use strict;
25
 
use FindBin;
26
 
use Getopt::Long;
27
 
 
28
 
use Immunix::SubDomain;
29
 
 
30
 
use Data::Dumper;
31
 
 
32
 
use Locale::gettext;
33
 
use POSIX;
34
 
 
35
 
# initialize the local poo
36
 
setlocale(LC_MESSAGES, "");
37
 
textdomain("apparmor-utils");
38
 
 
39
 
$UI_Mode = "text";
40
 
 
41
 
# options variables
42
 
my $help = '';
43
 
 
44
 
GetOptions(
45
 
    'dir|d=s' => \$profiledir,
46
 
    'help|h'  => \$help,
47
 
);
48
 
 
49
 
# tell 'em how to use it...
50
 
&usage && exit if $help;
51
 
 
52
 
# let's convert it to full path...
53
 
$profiledir = get_full_path($profiledir);
54
 
 
55
 
unless (-d $profiledir) {
56
 
    UI_Important("Can't find subdomain profiles in $profiledir.");
57
 
    exit 1;
58
 
}
59
 
 
60
 
# read the settings in /etc/logprof.conf
61
 
readconfig();
62
 
 
63
 
# what are we profiling?
64
 
my @profiling = @ARGV;
65
 
 
66
 
unless (@profiling) {
67
 
    @profiling = (UI_GetString("Please enter the program to switch to audit mode: ", ""));
68
 
}
69
 
 
70
 
for my $profiling (@profiling) {
71
 
 
72
 
    next unless $profiling;
73
 
 
74
 
    my $fqdbin;
75
 
    if (-e $profiling) {
76
 
        $fqdbin = get_full_path($profiling);
77
 
        chomp($fqdbin);
78
 
    } else {
79
 
        if ($profiling !~ /\//) {
80
 
            my $which = which($profiling);
81
 
            if ($which) {
82
 
                $fqdbin = get_full_path($which);
83
 
            }
84
 
        }
85
 
    }
86
 
 
87
 
    if (-e $fqdbin) {
88
 
 
89
 
        my $filename;
90
 
        if ($fqdbin =~ /^$profiledir\//) {
91
 
            $filename = $fqdbin;
92
 
        } else {
93
 
            $filename = getprofilefilename($fqdbin);
94
 
        }
95
 
 
96
 
        # argh, skip directories
97
 
        next unless -f $filename;
98
 
 
99
 
        # skip rpm backup files
100
 
        next if isSkippableFile($filename);
101
 
 
102
 
        printf(gettext('Setting %s to audit mode.'), $fqdbin);
103
 
        print "\n";
104
 
        setprofileflags($filename, "audit");
105
 
 
106
 
        system("cat $filename | $parser -I$profiledir -r >/dev/null 2>&1")
107
 
          if check_for_subdomain();
108
 
    } else {
109
 
        if ($profiling =~ /^[^\/]+$/) {
110
 
            UI_Info(sprintf(gettext('Can\'t find %s in the system path list.  If the name of the application is correct, please run \'which %s\' as a user with the correct PATH environment set up in order to find the fully-qualified path.'), $profiling, $profiling));
111
 
            exit 1;
112
 
        } else {
113
 
            UI_Info(sprintf(gettext('%s does not exist, please double-check the path.') . $profiling));
114
 
            exit 1;
115
 
        }
116
 
    }
117
 
}
118
 
 
119
 
exit 0;
120
 
 
121
 
sub usage {
122
 
    UI_Info(sprintf(gettext("usage: \%s [ -d /path/to/profiles ] [ program to switch to audit mode ]"), $0));
123
 
    exit 0;
124
 
}
125