mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-24 23:14:14 +00:00
Note that shtests simply does a 'grep -c err_exit' and substracts 1 to count the number of regression tests in a test script. Not all test scripts make temp dirs, so subtracting 2 instead won't do. src/cmd/ksh93/tests/*.sh: - Escape the err_exit call in the routine to create a temporary directory so that it is not counted as a regression test. That bypasses the alias, so we have to pass $LINENO manually.
96 lines
4.1 KiB
Bash
Executable file
96 lines
4.1 KiB
Bash
Executable file
########################################################################
|
|
# #
|
|
# This software is part of the ast package #
|
|
# Copyright (c) 1982-2011 AT&T Intellectual Property #
|
|
# and is licensed under the #
|
|
# Eclipse Public License, Version 1.0 #
|
|
# by AT&T Intellectual Property #
|
|
# #
|
|
# A copy of the License is available at #
|
|
# http://www.eclipse.org/org/documents/epl-v10.html #
|
|
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
|
|
# #
|
|
# Information and Software Systems Research #
|
|
# AT&T Research #
|
|
# Florham Park NJ #
|
|
# #
|
|
# David Korn <dgk@research.att.com> #
|
|
# #
|
|
########################################################################
|
|
function err_exit
|
|
{
|
|
print -u2 -n "\t"
|
|
print -u2 -r ${Command}[$1]: "${@:2}"
|
|
let Errors+=1
|
|
}
|
|
alias err_exit='err_exit $LINENO'
|
|
|
|
Command=${0##*/}
|
|
integer Errors=0
|
|
|
|
tmp=$(
|
|
d=${TMPDIR:-/tmp}/ksh93.restricted.$$.${RANDOM:-0}
|
|
mkdir -m700 -- "$d" && CDPATH= cd -P -- "$d" && pwd
|
|
) || {
|
|
err\_exit $LINENO 'mkdir failed'
|
|
exit 1
|
|
}
|
|
trap 'cd / && rm -rf "$tmp"' EXIT
|
|
binecho=$(whence -p echo)
|
|
|
|
# test restricted shell
|
|
pwd=$PWD
|
|
case $SHELL in
|
|
/*) ;;
|
|
*/*) SHELL=$pwd/$SHELL;;
|
|
*) SHELL=$(whence "$SHELL");;
|
|
esac
|
|
function check_restricted
|
|
{
|
|
rm -f out
|
|
LC_MESSAGES=C rksh -c "$@" 2> out > /dev/null
|
|
grep restricted out > /dev/null 2>&1
|
|
}
|
|
|
|
[[ $SHELL != /* ]] && SHELL=$pwd/$SHELL
|
|
cd $tmp || err_exit "cd $tmp failed"
|
|
ln -s $SHELL rksh
|
|
PATH=$PWD:$PATH
|
|
rksh -c '[[ -o restricted ]]' || err_exit 'restricted option not set'
|
|
[[ $(rksh -c 'print hello') == hello ]] || err_exit 'unable to run print'
|
|
check_restricted "$binecho" || err_exit "$binecho not restricted"
|
|
check_restricted ./echo || err_exit './echo not restricted'
|
|
check_restricted 'SHELL=ksh' || err_exit 'SHELL assignment not restricted'
|
|
check_restricted 'PATH=/bin' || err_exit 'PATH assignment not restricted'
|
|
check_restricted 'FPATH=/bin' || err_exit 'FPATH assignment not restricted'
|
|
check_restricted 'ENV=/bin' || err_exit 'ENV assignment not restricted'
|
|
check_restricted 'print > file' || err_exit '> file not restricted'
|
|
> empty
|
|
check_restricted 'print <> empty' || err_exit '<> file not restricted'
|
|
print 'echo hello' > script
|
|
chmod +x ./script
|
|
! check_restricted script || err_exit 'script without builtins should run in restricted mode'
|
|
check_restricted ./script || err_exit 'script with / in name should not run in restricted mode'
|
|
printf '%q hello\n' "$binecho" > script
|
|
! check_restricted script || err_exit 'script with pathnames should run in restricted mode'
|
|
print 'echo hello> file' > script
|
|
! check_restricted script || err_exit 'script with output redirection should run in restricted mode'
|
|
print 'PATH=/bin' > script
|
|
! check_restricted script || err_exit 'script with PATH assignment should run in restricted mode'
|
|
cat > script <<!
|
|
#! $SHELL
|
|
print hello
|
|
!
|
|
! check_restricted 'script;:' || err_exit 'script with #! pathname should run in restricted mode'
|
|
! check_restricted 'script' || err_exit 'script with #! pathname should run in restricted mode even if last command in script'
|
|
for i in PATH ENV FPATH
|
|
do check_restricted "function foo { typeset $i=foobar;};foo" || err_exit "$i can be changed in function by using typeset"
|
|
done
|
|
|
|
# ======
|
|
# `set +r` and `set +o restricted` should not unset the restricted option
|
|
check_restricted 'set +r' 2> /dev/null || err_exit '`set +r` unsets the restricted option'
|
|
check_restricted 'set +o restricted' 2> /dev/null || err_exit '`set +o restricted` unsets the restricted option'
|
|
|
|
# ======
|
|
exit $((Errors<125?Errors:125))
|