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

« back to all changes in this revision

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