tests: Revert to grouping AF_UNIX tests into addr type specific scripts

It is too complicated, due to the number of corner cases, to write a
script that generates the rules for each AF_UNIX address type (pathname,
abstract, and unnamed) and socket type (stream, dgram, and seqpacket).

This patch moves the AF_UNIX pathname tests into their own file with the
intent of having each address type be tested in their own file.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
This commit is contained in:
Tyler Hicks 2014-09-22 18:16:15 -05:00
parent 3fb09b20f2
commit 5153701317
2 changed files with 12 additions and 54 deletions

View file

@ -183,7 +183,7 @@ TESTS=access \
syscall \ syscall \
tcp \ tcp \
unix_fd_server \ unix_fd_server \
unix_socket \ unix_socket_pathname \
unlink\ unlink\
xattrs\ xattrs\
longpath longpath

View file

@ -1,6 +1,6 @@
#! /bin/bash #! /bin/bash
# #
# Copyright (C) 2013 Canonical, Ltd. # Copyright (C) 2014 Canonical, Ltd.
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public # modify it under the terms of version 2 of the GNU General Public
@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, contact Canonical Ltd. # along with this program; if not, contact Canonical Ltd.
#=NAME unix_socket #=NAME unix_socket_pathname
#=DESCRIPTION #=DESCRIPTION
# This tests file access to unix domain sockets. The server opens a socket, # This tests file access to unix domain sockets. The server opens a socket,
# forks a client with it's own profile, sends a message to the client over the # forks a client with it's own profile, sends a message to the client over the
@ -29,9 +29,10 @@ bin=$pwd
. $bin/prologue.inc . $bin/prologue.inc
requires_features policy/versions/v6 requires_features policy/versions/v6
settest unix_socket
client=$bin/unix_socket_client client=$bin/unix_socket_client
sockpath_pathname=${tmpdir}/unix_socket.sock sockpath=${tmpdir}/unix_socket.sock
sockpath_abstract="@apparmor_unix_socket"
message=4a0c83d87aaa7afa2baab5df3ee4df630f0046d5bfb7a3080c550b721f401b3b\ message=4a0c83d87aaa7afa2baab5df3ee4df630f0046d5bfb7a3080c550b721f401b3b\
8a738e1435a3b77aa6482a70fb51c44f20007221b85541b0184de66344d46a4c 8a738e1435a3b77aa6482a70fb51c44f20007221b85541b0184de66344d46a4c
@ -48,23 +49,17 @@ okclient=rw
badclient1=r badclient1=r
badclient2=w badclient2=w
isabstract()
{
[ "${1:0:1}" == "@" ]
}
removesocket() removesocket()
{ {
if ! isabstract "$1"; then if [ -S "$1" ]; then
rm -f "$1" rm -f "$1"
fi fi
} }
testsocktype() testsocktype()
{ {
local testdesc=$1 # description (eg, "AF_UNIX abstract socket (dgram)") local socktype=$1 # stream, dgram, or seqpacket
local sockpath=$2 # fs path or "@NAME" for an abstract sock local testdesc="AF_UNIX pathname socket ($socktype)"
local socktype=$3 # stream, dgram, or seqpacket
local args="$sockpath $socktype $message $client" local args="$sockpath $socktype $message $client"
removesocket $sockpath removesocket $sockpath
@ -74,15 +69,6 @@ testsocktype()
runchecktest "$testdesc; unconfined" pass $args runchecktest "$testdesc; unconfined" pass $args
removesocket $sockpath removesocket $sockpath
# TODO: Make additional changes to test abstract sockets w/ confinement
#
# * Create variables to hold genprofile arguments for socket accesses
# and initialize them according to socket address type
# * Remove the following conditional
if isabstract $sockpath; then
return
fi
# PASS - server w/ access to the file # PASS - server w/ access to the file
genprofile $sockpath:$okserver $client:Ux genprofile $sockpath:$okserver $client:Ux
@ -138,34 +124,6 @@ testsocktype()
removeprofile removeprofile
} }
testsockpath()
{
local sockpath="$1" # $sockpath_pathname or $sockpath_abstract
local testdesc="AF_UNIX "
local socktype=
if [ "$sockpath" == "$sockpath_pathname" ]; then
testdesc+="pathname socket"
elif [ "$sockpath" == "$sockpath_abstract" ]; then
testdesc+="abstract socket"
else
fatalerror "Unknown sockpath addr type: $sockpath"
fi
for socktype in stream dgram seqpacket; do for socktype in stream dgram seqpacket; do
testsocktype "$testdesc ($socktype)" "$sockpath" "$socktype" testsocktype "$socktype"
done done
}
testsockpath "$sockpath_pathname"
testsockpath "$sockpath_abstract"
# TODO: testsockpath "$sockpath_unnamed"
#
# * Adjust unix_socket.c and unix_socket_client.c when the socket path is
# "UNNAMED"
# - Don't bind() the socket
# - Don't set SO_CLOEXEC so that the fd can be passed over exec()
# * Decide how to generate appropriate access rules (if any are needed)
# * Define sockpath_unnamed as "UNNAMED"
# * Update testsockpath() to handle sockpath_unnamed
# * Create isunnamed() and update removesocket() to call it