mirror of
https://github.com/stefanberger/swtpm.git
synced 2026-01-09 14:19:33 +00:00
tests: Pass file ownership using uid and gid
Pass file ownership using the uid= and gid= parameters when run as root and check the result. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
parent
f487473cf6
commit
bb0aa2ad5a
13
tests/common
13
tests/common
@ -628,6 +628,19 @@ function get_filemode()
|
||||
fi
|
||||
}
|
||||
|
||||
# Get the file owner uid and gid
|
||||
#
|
||||
# @1: filename
|
||||
function get_fileowner()
|
||||
{
|
||||
if [[ "$(uname -s)" =~ (Linux|CYGWIN_NT-) ]]; then
|
||||
stat -c"%u %g" $1
|
||||
else
|
||||
# BSDs
|
||||
stat -f"%u %g" $1
|
||||
fi
|
||||
}
|
||||
|
||||
# Get the SHA1 of a file
|
||||
#
|
||||
# @1: filename
|
||||
|
||||
@ -31,6 +31,12 @@ source ${TESTDIR}/common
|
||||
|
||||
# Test 1: test the control channel on the socket tpm
|
||||
|
||||
# OS X would not allow nobody to access the $TPMDIR easily; skip it
|
||||
if [ $(id -u) -eq 0 ] && [ "$(uname -s)" != "Darwin" ]; then
|
||||
FOWNER=",uid=nobody,gid=$(id -Gn nobody | cut -d" " -f1)"
|
||||
FILEOWNER="$(id -u nobody) $(id -G nobody | cut -d" " -f1)"
|
||||
fi
|
||||
|
||||
if [[ "$(uname -s)" =~ CYGWIN_NT- ]]; then
|
||||
FILEMODE=661
|
||||
else
|
||||
@ -56,7 +62,7 @@ $SWTPM_EXE socket \
|
||||
--fd 100 \
|
||||
--tpmstate dir=$TPMDIR \
|
||||
--pid file=$PID_FILE \
|
||||
--ctrl type=unixio,path=$SWTPM_CTRL_UNIX_PATH,mode=$FILEMODE \
|
||||
--ctrl type=unixio,path=$SWTPM_CTRL_UNIX_PATH,mode=${FILEMODE}${FOWNER} \
|
||||
--log file=$LOG_FILE,level=20 &
|
||||
|
||||
exec 100>&-
|
||||
@ -90,6 +96,14 @@ if [ "$filemode" != "$FILEMODE" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
fileowner=$(get_fileowner $SWTPM_CTRL_UNIX_PATH)
|
||||
if [ -n "$FILEOWNER" ] && [ "$fileowner" != "$FILEOWNER" ]; then
|
||||
echo "File ownership is wrong"
|
||||
echo "Expected: $FILEOWNER"
|
||||
echo "Actual : $fileowner"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Send TPM_Init to the TPM: CMD_INIT = 0x00 00 00 02 + flags
|
||||
res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x02\x00\x00\x00\x00')"
|
||||
exp=" 00 00 00 00"
|
||||
|
||||
@ -30,6 +30,10 @@ function cleanup()
|
||||
}
|
||||
|
||||
# Test 1: test the control channel on the chardev tpm
|
||||
if [ $(id -u) -eq 0 ]; then
|
||||
FOWNER=",uid=$(id -u nobody),gid=$(id -G nobody | cut -d" " -f1)"
|
||||
FILEOWNER="$(id -u nobody) $(id -G nobody | cut -d" " -f1)"
|
||||
fi
|
||||
|
||||
FILEMODE=621
|
||||
# use a pseudo terminal
|
||||
@ -38,7 +42,7 @@ $SWTPM_EXE chardev \
|
||||
--fd 100 \
|
||||
--tpmstate dir=$TPMDIR \
|
||||
--pid file=$PID_FILE \
|
||||
--ctrl type=unixio,path=$SOCK_PATH,mode=$FILEMODE \
|
||||
--ctrl type=unixio,path=$SOCK_PATH,mode=${FILEMODE}${FOWNER} \
|
||||
--tpm2 &
|
||||
|
||||
if wait_for_file $PID_FILE 3; then
|
||||
@ -63,6 +67,14 @@ if [ "$filemode" != "$FILEMODE" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
fileowner=$(get_fileowner $SOCK_PATH)
|
||||
if [ -n "$FILEOWNER" ] && [ "$fileowner" != "$FILEOWNER" ]; then
|
||||
echo "File ownership is wrong"
|
||||
echo "Expected: $FILEOWNER"
|
||||
echo "Actual : $fileowner"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exp="ptm capability is 0x([[:xdigit:]]+)"
|
||||
if ! [[ "$act" =~ ^${exp}$ ]]; then
|
||||
echo "Error: Expected string following regular expression '$exp' from ioctl tool but got '$act'."
|
||||
|
||||
Loading…
Reference in New Issue
Block a user