my $access_file = "test_file_access.txt";
my $whitelist_file = "file_access_whitelist.txt";
+my @known_actions = ("open", "fopen", "access", "stat", "lstat", "connect");
+
my @files;
my @whitelist;
open FILE, "<", $access_file or die "Unable to open $access_file: $!";
while (<FILE>) {
chomp;
- if (/^(\S*):\s*(\S*)(\s*:\s*(.*))?$/) {
+ if (/^(\S*):\s*(\S*):\s*(\S*)(\s*:\s*(.*))?$/) {
my %rec;
${rec}{path} = $1;
- ${rec}{progname} = $2;
- if (defined $4) {
- ${rec}{testname} = $4;
+ ${rec}{action} = $2;
+ ${rec}{progname} = $3;
+ if (defined $5) {
+ ${rec}{testname} = $5;
}
push (@files, \%rec);
} else {
chomp;
if (/^\s*#.*$/) {
# comment
+ } elsif (/^(\S*):\s*(\S*)(:\s*(\S*)(\s*:\s*(.*))?)?$/ and
+ grep /^$2$/, @known_actions) {
+ # $path: $action: $progname: $testname
+ my %rec;
+ ${rec}{path} = $1;
+ ${rec}{action} = $3;
+ if (defined $4) {
+ ${rec}{progname} = $4;
+ }
+ if (defined $6) {
+ ${rec}{testname} = $6;
+ }
+ push (@whitelist, \%rec);
} elsif (/^(\S*)(:\s*(\S*)(\s*:\s*(.*))?)?$/) {
+ # $path: $progname: $testname
my %rec;
${rec}{path} = $1;
if (defined $3) {
next;
}
+ if (defined %${rule}{action} and
+ not %${file}{action} =~ m/^$rule->{action}$/) {
+ next;
+ }
+
if (defined %${rule}{progname} and
not %${file}{progname} =~ m/^$rule->{progname}$/) {
next;
if (not $match) {
$error = 1;
- print "$file->{path}: $file->{progname}";
+ print "$file->{path}: $file->{action}: $file->{progname}";
print ": $file->{testname}" if defined %${file}{testname};
print "\n";
}
# This is a whitelist that allows accesses to files not in our
# build directory nor source directory. The records are in the
-# following format:
+# following formats:
#
# $path: $progname: $testname
+# $path: $action: $progname: $testname
#
-# All these three are evaluated as perl RE. So to allow /dev/sda
-# and /dev/sdb, you can just '/dev/sd[a-b]', or to allow
+# All these variables are evaluated as perl RE. So to allow
+# /dev/sda and /dev/sdb, you can just '/dev/sd[a-b]', or to allow
# /proc/$pid/status you can '/proc/\d+/status' and so on.
-# Moreover, $progname and $testname can be empty, in which which
-# case $path is allowed for all tests.
+# Moreover, $action, $progname and $testname can be empty, in which
+# which case $path is allowed for all tests. However, $action (if
+# specified) must be one of "open", "fopen", "access", "stat",
+# "lstat", "connect".
/bin/cat: sysinfotest
/bin/dirname: sysinfotest: x86 sysinfo
/etc/hosts
/proc/\d+/status
+/etc/passwd: fopen
+
# This is just a dummy example, DO NOT USE IT LIKE THAT!
.*: nonexistent-test-touching-everything