1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#!/bin/bash
set -eu
THIS="$(readlink -f "$0")"
THISDIR="$(dirname "${THIS}")"
SUT="$(dirname "${THISDIR}")/makeself.sh"
testSuidDoesntGetBroken() {
# Create a directory with a file on it
local archive_dir="$(mktemp -dt archive_dir.XXXXXX)"
(
cd "${archive_dir}"
touch deployedfile
)
# Create the self extracting that should extract deployedfile
local file_name="$(mktemp -t file_name.XXXXXX)"
"${SUT}" --target "${archive_dir}" "${archive_dir}" "${file_name}" "suid test"
assertEquals $? 0
# Target directory now has another file with sudo permissions
# This will get broken because of chown -R
(
cd "${archive_dir}"
touch suidfile.bin
chmod +xs suidfile.bin
)
permissionsBefore=$(stat -c %A "${archive_dir}"/suidfile.bin)
# We extract deployedfile, in hopes that it will not reset suid bit
# from suidfile.bin
"${file_name}"
assertEquals $? 0
permissionsAfter=$(stat -c %A "${archive_dir}"/suidfile.bin)
# And we check that permissions match
assertEquals "${permissionsBefore}" "${permissionsAfter}"
rm -rf "${archive_dir}" "${file_name}"
}
# Load and run shUnit2.
source "./shunit2/shunit2"
|