Skip to content

Commit

Permalink
tests: add support for tty field in LOGIN message
Browse files Browse the repository at this point in the history
test: RFE: add a tty field to the AUDIT_LOGIN event #2
linux-audit/audit-kernel#2

v4: use a new filehandle for tty and test PID of LOGIN test command.
v3: escape "$" in LOGIN record provoking system command.
v2: provoke a LOGIN record if one wasn't triggered since the last boot
    by login

Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
  • Loading branch information
rgbriggs authored and pcmoore committed May 16, 2016
1 parent 5cf464c commit 17c58dd
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/login_tty/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TARGETS=$(patsubst %.c,%,$(wildcard *.c))

LDLIBS += -lpthread

all: $(TARGETS)
clean:
rm -f $(TARGETS)

68 changes: 68 additions & 0 deletions tests/login_tty/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/perl

use strict;

use Test;
BEGIN { plan tests => 2 }

use File::Temp qw/ tempdir tempfile /;

###
# functions

###
# setup

# reset audit
system("auditctl -D >& /dev/null");

# create stdout/stderr sinks
(my $fh_out, my $stdout) = tempfile(TEMPLATE => '/tmp/audit-testsuite-out-XXXX',
UNLINK => 1);
(my $fh_err, my $stderr) = tempfile(TEMPLATE => '/tmp/audit-testsuite-err-XXXX',
UNLINK => 1);
(my $fh_tty, my $ttyout) = tempfile(TEMPLATE => '/tmp/audit-testsuite-tmp-XXXX',
UNLINK => 1);
(my $fh_tmp, my $tmpout) = tempfile(TEMPLATE => '/tmp/audit-testsuite-tmp-XXXX',
UNLINK => 1);

###
# tests

# get the tty of this test shell
system("tty | sed 's_/dev/__' > $ttyout");
my $tty = <$fh_tty>;
chomp($tty);

# provoke a LOGIN record if one doesn't already exist since the last
# boot at login time.
system("echo \$\$ > $tmpout; exec echo \$(id -u) > /proc/self/loginuid");

# get the PID of the login process from the test session shell
# try to grab PID from the environment (NOTE: requires bash)
my $pid = <$fh_tmp>;
chomp($pid);

# test for the LOGIN message
my $result = system("ausearch -m LOGIN -p $pid -ts recent > $stdout 2> $stderr");
ok($result, 0);

# test if the LOGIN record was generated correctly for this test shell
my $line;
my $found_msg = 0;
while ($line = <$fh_out>) {
# test if we generate a LOGIN record with the correct pid and tty
if ($line =~ /^type=LOGIN /) {
if ($line =~ / pid=$pid / and
$line =~ / tty=$tty /) {
$found_msg = 1;
}
}
}
ok($found_msg);

###
# cleanup

system("auditctl -D >& /dev/null");

0 comments on commit 17c58dd

Please sign in to comment.