Skip to content

Commit 94e418b

Browse files
committed
tests: add support for session ID user filter
test: RFE: add a session ID filter to the kernel's user filter linux-audit/audit-kernel#4 Signed-off-by: Richard Guy Briggs <[email protected]>
1 parent c644cf0 commit 94e418b

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

tests/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SUBDIRS := \
99
file_create \
1010
file_delete \
1111
file_rename \
12+
filter_sessionid \
1213
login_tty \
1314
syscalls_file \
1415
user_msg

tests/filter_sessionid/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
TARGETS=$(patsubst %.c,%,$(wildcard *.c))
2+
3+
LDLIBS += -lpthread
4+
5+
all: $(TARGETS)
6+
clean:
7+
rm -f $(TARGETS)
8+

tests/filter_sessionid/test

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
5+
use Test;
6+
BEGIN { plan tests => 3 }
7+
8+
use File::Temp qw/ tempdir tempfile /;
9+
10+
###
11+
# functions
12+
13+
sub key_gen {
14+
my @chars = ("A".."Z", "a".."z");
15+
my $key = "testsuite-" . time . "-";
16+
$key .= $chars[rand @chars] for 1..8;
17+
return $key;
18+
}
19+
20+
###
21+
# setup
22+
23+
# reset audit
24+
system("auditctl -D >& /dev/null");
25+
26+
# create stdout/stderr sinks
27+
(my $fh_out, my $stdout) = tempfile(TEMPLATE => '/tmp/audit-testsuite-out-XXXX',
28+
UNLINK => 1);
29+
(my $fh_err, my $stderr) = tempfile(TEMPLATE => '/tmp/audit-testsuite-err-XXXX',
30+
UNLINK => 1);
31+
(my $fh_ses, my $sesout) = tempfile(TEMPLATE => '/tmp/audit-testsuite-ses-XXXX',
32+
UNLINK => 1);
33+
(my $fh_pid, my $pidout) = tempfile(TEMPLATE => '/tmp/audit-testsuite-pid-XXXX',
34+
UNLINK => 1);
35+
36+
###
37+
# tests
38+
39+
my $result;
40+
41+
# discover our sesssion ID
42+
system("cat /proc/self/sessionid > $sesout");
43+
my $sessionid = <$fh_ses>;
44+
chomp($sessionid);
45+
46+
# create a key and rule
47+
my $key = key_gen();
48+
$result = system("auditctl -a always,exit -F arch=b64 -F path=/tmp/$key -F sessionid=$sessionid -k $key");
49+
ok($result, 0);
50+
51+
# send the userspace message (NOTE: requires bash)
52+
system("echo \$\$ > $pidout; exec touch /tmp/$key");
53+
my $pid = <$fh_pid>;
54+
chomp($pid);
55+
56+
# test for the SYSCALL message
57+
$result = system("ausearch -i -m SYSCALL -sc open -p $pid --session $sessionid -k $key > $stdout 2> $stderr");
58+
ok($result, 0);
59+
60+
# test if we generate the SYSCALL record correctly
61+
my $line;
62+
my $syscall_msg_match = 0;
63+
while ($line = <$fh_out>) {
64+
# test if SYSCALL record matches
65+
if ($line =~ m?^type=SYSCALL ? and
66+
$line =~ m? pid=$pid ? and
67+
$line =~ m? ses=$sessionid ? and
68+
$line =~ m? key=$key ?) {
69+
$syscall_msg_match = 1;
70+
last;
71+
}
72+
}
73+
ok($syscall_msg_match);
74+
75+
###
76+
# cleanup
77+
78+
system("auditctl -D >& /dev/null");
79+

0 commit comments

Comments
 (0)