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 39 40 41 42
|
#!/bin/sh
# Test if randombytes() works in the chrooted env.
# E.g. randombytes devurandom variant must have
# /dev/urandom open before the chroot() call.
set -e
dir=`dirname "$0"`
# change directory to $AUTOPKGTEST_TMP
cd "${AUTOPKGTEST_TMP}"
cleanup() {
ex=$?
rm -f randombytes-info
exit "${ex}"
}
trap "cleanup" EXIT TERM INT
CC=cc
CFLAGS=`dpkg-buildflags --get CFLAGS`
CFLAGS="${CFLAGS} `dpkg-buildflags --get CPPFLAGS`"
LDFLAGS=`dpkg-buildflags --get LDFLAGS`
LDFLAGS="${LDFLAGS} -lrandombytes -lm -lrt"
echo 'librandombytes - chrooted:'
mkdir -p 'jail'
(
cat "${dir}/../../command/randombytes-info.c"
echo
echo '__attribute__((constructor))'
echo 'static void jail(void) {'
echo ' if (chroot("jail") == -1) {'
echo ' fprintf(stderr, "unable to chroot\\n");'
echo ' fflush(stderr);'
echo ' _exit(1);'
echo ' }'
echo '}'
) | ${CC} ${CFLAGS} -xc -o randombytes-info - ${LDFLAGS}
./randombytes-info
|