3 # Copyright (C) 2016 Red Hat, Inc.
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library. If not, see
17 # <http://www.gnu.org/licenses/>.
19 # This script is supposed to check test_file_access.txt file and
20 # warn about file accesses outside our working tree.
27 my $access_file = "test_file_access.txt";
28 my $whitelist_file = "file_access_whitelist.txt";
30 my @known_actions = ("open", "fopen", "access", "stat", "lstat", "connect");
35 open FILE
, "<", $access_file or die "Unable to open $access_file: $!";
38 if (/^(\S*):\s*(\S*):\s*(\S*)(\s*:\s*(.*))?$/) {
42 ${rec
}{progname
} = $3;
44 ${rec
}{testname
} = $5;
48 die "Malformed line $_";
53 open FILE
, "<", $whitelist_file or die "Unable to open $whitelist_file: $!";
58 } elsif (/^(\S*):\s*(\S*)(:\s*(\S*)(\s*:\s*(.*))?)?$/ and
59 grep /^$2$/, @known_actions) {
60 # $path: $action: $progname: $testname
65 ${rec
}{progname
} = $4;
68 ${rec
}{testname
} = $6;
70 push (@whitelist, \
%rec);
71 } elsif (/^(\S*)(:\s*(\S*)(\s*:\s*(.*))?)?$/) {
72 # $path: $progname: $testname
76 ${rec
}{progname
} = $3;
79 ${rec
}{testname
} = $5;
81 push (@whitelist, \
%rec);
83 die "Malformed line $_";
88 # Now we should check if %traces is included in $whitelist. For
89 # now checking just keys is sufficient
91 for my $file (@files) {
94 for my $rule (@whitelist) {
95 if (not %${file
}{path
} =~ m/^$rule->{path}$/) {
99 if (defined %${rule
}{action
} and
100 not %${file
}{action
} =~ m/^$rule->{action}$/) {
104 if (defined %${rule
}{progname
} and
105 not %${file
}{progname
} =~ m/^$rule->{progname}$/) {
109 if (defined %${rule
}{testname
} and
110 defined %${file
}{testname
} and
111 not %${file
}{testname
} =~ m/^$rule->{testname}$/) {
120 print "$file->{path}: $file->{action}: $file->{progname}";
121 print ": $file->{testname}" if defined %${file
}{testname
};