~ubuntu-branches/ubuntu/raring/apparmor/raring

« back to all changes in this revision

Viewing changes to utils/enforce

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-03-23 16:42:01 UTC
  • Revision ID: james.westby@ubuntu.com-20070323164201-jkax6f0oku087b7l
Tags: upstream-2.0.1+510.dfsg
ImportĀ upstreamĀ versionĀ 2.0.1+510.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
#
 
3
# $Id: enforce 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(gettext("Please enter the program to switch to enforce 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
        my $filename;
 
89
        if ($fqdbin =~ /^$profiledir\//) {
 
90
            $filename = $fqdbin;
 
91
        } else {
 
92
            $filename = getprofilefilename($fqdbin);
 
93
        }
 
94
 
 
95
        # argh, skip directories
 
96
        next unless -f $filename;
 
97
 
 
98
        # skip rpm backup files
 
99
        next if isSkippableFile($filename);
 
100
 
 
101
        printf(gettext('Setting %s to enforce mode.'), $fqdbin);
 
102
        print "\n";
 
103
        setprofileflags($filename, "");
 
104
 
 
105
        system("cat $filename | $parser -I$profiledir -r >/dev/null 2>&1")
 
106
          if check_for_subdomain();
 
107
    } else {
 
108
        if ($profiling =~ /^[^\/]+$/) {
 
109
            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));
 
110
            exit 1;
 
111
        } else {
 
112
            UI_Info(sprintf(gettext('%s does not exist, please double-check the path.') . $profiling));
 
113
            exit 1;
 
114
        }
 
115
    }
 
116
}
 
117
 
 
118
exit 0;
 
119
 
 
120
sub usage {
 
121
    UI_Info(sprintf(gettext("usage: \%s [ -d /path/to/profiles ] [ program to switch to enforce mode ]"), $0));
 
122
    exit 0;
 
123
}
 
124