2009-10-23 11:01:25 -06:00
|
|
|
#!/bin/sh
|
|
|
|
|
# Verify that internal failure in chroot gives exact status.
|
|
|
|
|
|
2015-01-01 04:49:02 +00:00
|
|
|
# Copyright (C) 2009-2015 Free Software Foundation, Inc.
|
2009-10-23 11:01:25 -06:00
|
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
2012-09-02 21:55:12 +02:00
|
|
|
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
|
2010-11-17 21:35:31 +01:00
|
|
|
print_ver_ chroot
|
2009-10-23 11:01:25 -06:00
|
|
|
|
2014-05-19 18:21:57 +01:00
|
|
|
require_built_ chroot
|
2009-10-23 11:01:25 -06:00
|
|
|
|
|
|
|
|
# These tests verify exact status of internal failure; since none of
|
|
|
|
|
# them actually run a command, we don't need root privileges
|
|
|
|
|
chroot # missing argument
|
|
|
|
|
test $? = 125 || fail=1
|
|
|
|
|
chroot --- / true # unknown option
|
|
|
|
|
test $? = 125 || fail=1
|
|
|
|
|
|
2014-10-15 18:08:42 +01:00
|
|
|
# chroot("/") succeeds for non-root users on some systems, but not all.
|
|
|
|
|
if chroot / true ; then
|
|
|
|
|
can_chroot_root=1
|
|
|
|
|
chroot / sh -c 'exit 2' # exit status propagation
|
|
|
|
|
test $? = 2 || fail=1
|
|
|
|
|
chroot / . # invalid command
|
|
|
|
|
test $? = 126 || fail=1
|
|
|
|
|
chroot / no_such # no such command
|
|
|
|
|
test $? = 127 || fail=1
|
|
|
|
|
else
|
|
|
|
|
test $? = 125 || fail=1
|
2014-10-29 14:32:01 +00:00
|
|
|
can_chroot_root=0
|
2014-10-15 18:08:42 +01:00
|
|
|
fi
|
2014-05-13 15:56:34 +01:00
|
|
|
|
2014-08-01 02:07:33 +02:00
|
|
|
# Ensure that --skip-chdir fails with a non-"/" argument.
|
|
|
|
|
cat <<\EOF > exp || framework_failure_
|
|
|
|
|
chroot: option --skip-chdir only permitted if NEWROOT is old '/'
|
|
|
|
|
Try 'chroot --help' for more information.
|
|
|
|
|
EOF
|
|
|
|
|
chroot --skip-chdir . env pwd >out 2>err && fail=1
|
|
|
|
|
compare /dev/null out || fail=1
|
|
|
|
|
compare exp err || fail=1
|
|
|
|
|
|
2014-10-15 18:08:42 +01:00
|
|
|
# Ensure we chdir("/") appropriately when NEWROOT is old "/".
|
2014-10-29 14:32:01 +00:00
|
|
|
if test $can_chroot_root = 1; then
|
2014-10-15 18:08:42 +01:00
|
|
|
ln -s / isroot || framework_failure_
|
|
|
|
|
for dir in '/' '/.' '/../' isroot; do
|
|
|
|
|
# Verify that chroot(1) succeeds and performs chdir("/")
|
|
|
|
|
# (chroot(1) of coreutils-8.23 failed to run the latter).
|
|
|
|
|
curdir=$(chroot "$dir" env pwd) || fail=1
|
|
|
|
|
test "$curdir" = '/' || fail=1
|
|
|
|
|
|
|
|
|
|
# Test the "--skip-chdir" option.
|
|
|
|
|
curdir=$(chroot --skip-chdir "$dir" env pwd) || fail=1
|
|
|
|
|
test "$curdir" = '/' && fail=1
|
|
|
|
|
done
|
|
|
|
|
fi
|
2009-10-23 11:01:25 -06:00
|
|
|
|
|
|
|
|
Exit $fail
|