2000-07-30 15:17:34 +00:00
|
|
|
#! /bin/sh
|
|
|
|
|
# Make sure all these programs work properly
|
|
|
|
|
# when invoked with --help or --version.
|
|
|
|
|
|
ls: Add support for SELinux and a slightly modified -Z option.
I started with the patches from Red Hat.
The entries below tell how the code evolved.
* src/ls.c (print_long_format, print_file_name_and_frills): When
there is no security context (due to getfilecon/lgetfilecon failing
with e.g. ENOTSUP), print it as "?", not "".
* src/ls.c (print_file_name_and_frills): Make -Z work without -l.
(length_of_file_name_and_frills): Likewise.
* src/ls.c: Remove the --lcontext and --scontext options.
Change the way -Z, --context work so that it no longer implies -l.
Thus, -Z -l will work like -lcontext and -Z without -l will work
like --scontext.
Adjust tests to reflect new 'ls -l' syntax -- affects only
systems with SELinux when operating on a file with no ACL.
These tests assumed that everything before the first space on
each line is the 10-byte mode string. But there may also be a "+"
in the 11th column, just before the space. However, note that this
is not new. The same thing would have happened even without the
change below, when listing a file with an ACL.
* tests/chmod/equals, tests/cp/cp-parents, tests/cp/fail-perm:
* tests/cp/link-preserve, tests/install/basic-1, tests/misc/mknod:
* tests/mkdir/parents, tests/mkdir/special-1, tests/mv/partition-perm:
Don't make compilation depend on USE_ACL. An SELinux security
context counts as an "alternate access control method", so ls
must output a "+" for each file with a security context.
* src/ls.c [struct fileinfo] (have_acl): Declare unconditionally.
(FILE_HAS_ACL): Remove macro definition. Use f->have_acl directly.
(gobble_file): Record whether a file has a security context, and
update the condition used to determine whether to print the "+".
(gobble_file): Call getfilecon/lgetfilecon also when
format == long_format, so that we get the "+".
* src/ls.c (gobble_file): Add a comment explaining why (with a
security context option) ls doesn't exit nonzero due to e.g.,
getfilecon failing with errno == ENOTSUP.
* src/ls.c (gobble_file): Ignore failure of getfilecon if it's due
to ENOTSUP.
* src/ls.c (gobble_file): Factor out three small blocks using
getfilecon and lgetfilecon.
Don't ignore return value from getfilecon and lgetfilecon.
* src/ls.c (print_long_format): Don't use ?: (empty 2nd arg with C
ternary operator).
(print_scontext_format): Likewise.
(print_scontext): Declare to be "bool", not int. Adjust uses.
* src/Makefile.am (dir_LDADD, ls_LDADD, vdir_LDADD): Add $(LIB_SELINUX).
* tests/misc/chcon: New file.
* tests/misc/chcon-fail: New file.
* tests/Makefile.am (check-root): Run new, root-only misc/chcon test.
* tests/misc/Makefile.am (TESTS): Add chcon and chcon-fail.
* tests/misc/Makefile.am (TESTS): Add selinux.
* tests/misc/selinux: New file.
* tests/help-version: Skip chcon.
2007-01-05 18:23:54 +01:00
|
|
|
# Copyright (C) 2000-2007 Free Software Foundation, Inc.
|
2006-08-17 19:58:17 +00:00
|
|
|
|
2007-07-23 14:35:58 +02:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2006-08-17 19:58:17 +00:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
2007-07-23 14:35:58 +02:00
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
2006-08-17 19:58:17 +00:00
|
|
|
# (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
|
2007-07-23 14:35:58 +02:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-08-17 19:58:17 +00:00
|
|
|
|
2000-07-30 15:17:34 +00:00
|
|
|
test "$VERBOSE" = yes && set -x
|
|
|
|
|
|
2006-08-19 18:30:04 +00:00
|
|
|
# Ensure that $SHELL is set to *some* value and exported.
|
2006-03-05 17:28:42 +00:00
|
|
|
# This is required for dircolors, which would fail e.g., when
|
|
|
|
|
# invoked via debuild (which removes SHELL from the environment).
|
2006-08-19 18:30:04 +00:00
|
|
|
test "x$SHELL" = x && SHELL=/bin/sh
|
|
|
|
|
export SHELL
|
2006-03-05 17:28:42 +00:00
|
|
|
|
2007-10-09 17:12:45 +02:00
|
|
|
. $srcdir/../envvar-check
|
|
|
|
|
. $srcdir/../test-lib.sh
|
2006-12-07 10:11:40 +01:00
|
|
|
|
2004-01-22 22:19:04 +00:00
|
|
|
expected_failure_status_nohup=127
|
2000-07-30 15:17:34 +00:00
|
|
|
expected_failure_status_printenv=2
|
|
|
|
|
expected_failure_status_tty=3
|
|
|
|
|
expected_failure_status_sort=2
|
2003-07-19 11:39:22 +00:00
|
|
|
expected_failure_status_expr=3
|
2003-07-26 06:48:40 +00:00
|
|
|
expected_failure_status_lbracket=2
|
2004-12-09 17:49:18 +00:00
|
|
|
expected_failure_status_dir=2
|
|
|
|
|
expected_failure_status_ls=2
|
|
|
|
|
expected_failure_status_vdir=2
|
2000-07-30 15:17:34 +00:00
|
|
|
|
2007-07-10 22:37:48 +02:00
|
|
|
case "$built_programs" in
|
2003-07-16 19:54:13 +00:00
|
|
|
*groups*)
|
2006-02-07 09:18:28 +00:00
|
|
|
if test -w /dev/full && test -c /dev/full \
|
|
|
|
|
&& echo > /dev/full 2>/dev/null; then
|
2000-07-30 15:17:34 +00:00
|
|
|
cat 1>&2 <<\EOF
|
|
|
|
|
************************************************
|
|
|
|
|
WARNING: On this system, the built-in echo function of /bin/sh
|
|
|
|
|
does not report failure when writing to a full device.
|
|
|
|
|
To demonstrate, run this command:
|
|
|
|
|
|
|
|
|
|
/bin/sh -c 'echo hello > /dev/full; echo status=$?'
|
|
|
|
|
|
|
|
|
|
Notice that the failing echo leaves its exit status set to zero
|
|
|
|
|
and does not produce a diagnostic.
|
|
|
|
|
|
2003-07-16 19:54:13 +00:00
|
|
|
That bug in /bin/sh would cause the test of the groups
|
|
|
|
|
scripts to fail, so it is being removed from the list of
|
2000-07-30 15:17:34 +00:00
|
|
|
programs checked by this test.
|
|
|
|
|
************************************************
|
|
|
|
|
EOF
|
2007-07-10 22:37:48 +02:00
|
|
|
built_programs=`echo $built_programs | tr ' ' '\n' | grep -v '^groups$'`
|
2000-07-30 15:17:34 +00:00
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
fail=0
|
|
|
|
|
|
2001-12-15 09:14:21 +00:00
|
|
|
for lang in C fr da; do
|
2007-07-10 22:37:48 +02:00
|
|
|
for i in $built_programs; do
|
2000-07-30 15:17:34 +00:00
|
|
|
|
2003-07-26 06:48:40 +00:00
|
|
|
# Skip `test'; it doesn't accept --help or --version.
|
|
|
|
|
test $i = test && continue;
|
ls: Add support for SELinux and a slightly modified -Z option.
I started with the patches from Red Hat.
The entries below tell how the code evolved.
* src/ls.c (print_long_format, print_file_name_and_frills): When
there is no security context (due to getfilecon/lgetfilecon failing
with e.g. ENOTSUP), print it as "?", not "".
* src/ls.c (print_file_name_and_frills): Make -Z work without -l.
(length_of_file_name_and_frills): Likewise.
* src/ls.c: Remove the --lcontext and --scontext options.
Change the way -Z, --context work so that it no longer implies -l.
Thus, -Z -l will work like -lcontext and -Z without -l will work
like --scontext.
Adjust tests to reflect new 'ls -l' syntax -- affects only
systems with SELinux when operating on a file with no ACL.
These tests assumed that everything before the first space on
each line is the 10-byte mode string. But there may also be a "+"
in the 11th column, just before the space. However, note that this
is not new. The same thing would have happened even without the
change below, when listing a file with an ACL.
* tests/chmod/equals, tests/cp/cp-parents, tests/cp/fail-perm:
* tests/cp/link-preserve, tests/install/basic-1, tests/misc/mknod:
* tests/mkdir/parents, tests/mkdir/special-1, tests/mv/partition-perm:
Don't make compilation depend on USE_ACL. An SELinux security
context counts as an "alternate access control method", so ls
must output a "+" for each file with a security context.
* src/ls.c [struct fileinfo] (have_acl): Declare unconditionally.
(FILE_HAS_ACL): Remove macro definition. Use f->have_acl directly.
(gobble_file): Record whether a file has a security context, and
update the condition used to determine whether to print the "+".
(gobble_file): Call getfilecon/lgetfilecon also when
format == long_format, so that we get the "+".
* src/ls.c (gobble_file): Add a comment explaining why (with a
security context option) ls doesn't exit nonzero due to e.g.,
getfilecon failing with errno == ENOTSUP.
* src/ls.c (gobble_file): Ignore failure of getfilecon if it's due
to ENOTSUP.
* src/ls.c (gobble_file): Factor out three small blocks using
getfilecon and lgetfilecon.
Don't ignore return value from getfilecon and lgetfilecon.
* src/ls.c (print_long_format): Don't use ?: (empty 2nd arg with C
ternary operator).
(print_scontext_format): Likewise.
(print_scontext): Declare to be "bool", not int. Adjust uses.
* src/Makefile.am (dir_LDADD, ls_LDADD, vdir_LDADD): Add $(LIB_SELINUX).
* tests/misc/chcon: New file.
* tests/misc/chcon-fail: New file.
* tests/Makefile.am (check-root): Run new, root-only misc/chcon test.
* tests/misc/Makefile.am (TESTS): Add chcon and chcon-fail.
* tests/misc/Makefile.am (TESTS): Add selinux.
* tests/misc/selinux: New file.
* tests/help-version: Skip chcon.
2007-01-05 18:23:54 +01:00
|
|
|
test $i = chcon && continue;
|
2007-02-02 18:58:41 +01:00
|
|
|
test $i = runcon && continue;
|
2003-07-26 06:48:40 +00:00
|
|
|
|
2001-12-15 09:14:21 +00:00
|
|
|
# false fails even when invoked with --help or --version.
|
|
|
|
|
if test $i = false; then
|
2007-10-09 17:12:45 +02:00
|
|
|
env LC_MESSAGES=$lang $abs_top_builddir/src/$i --help \
|
|
|
|
|
>/dev/null && fail=1
|
|
|
|
|
env LC_MESSAGES=$lang $abs_top_builddir/src/$i --version \
|
|
|
|
|
>/dev/null && fail=1
|
2001-12-15 09:14:21 +00:00
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# The just-built install executable is always named `ginstall'.
|
|
|
|
|
test $i = install && i=ginstall
|
2000-07-30 15:17:34 +00:00
|
|
|
|
2001-12-15 09:14:21 +00:00
|
|
|
# Make sure they exit successfully, under normal conditions.
|
2007-10-09 17:12:45 +02:00
|
|
|
$abs_top_builddir/src/$i --help > h-$i || fail=1
|
|
|
|
|
$abs_top_builddir/src/$i --version >/dev/null || fail=1
|
2000-07-30 15:17:34 +00:00
|
|
|
|
2003-11-20 08:08:24 +00:00
|
|
|
# Make sure they mention the bug-reporting address in --help output.
|
|
|
|
|
grep "$PACKAGE_BUGREPORT" h-$i > /dev/null || fail=1
|
2003-11-27 08:45:01 +00:00
|
|
|
rm -f h-$i
|
2003-11-20 08:08:24 +00:00
|
|
|
|
2001-12-15 09:14:21 +00:00
|
|
|
# Make sure they fail upon `disk full' error.
|
|
|
|
|
if test -w /dev/full && test -c /dev/full; then
|
2007-10-09 17:12:45 +02:00
|
|
|
$abs_top_builddir/src/$i --help >/dev/full 2>/dev/null && fail=1
|
|
|
|
|
$abs_top_builddir/src/$i --version >/dev/full 2>/dev/null && fail=1
|
2001-12-15 09:14:21 +00:00
|
|
|
status=$?
|
2003-07-18 08:11:55 +00:00
|
|
|
test $i = [ && prog=lbracket || prog=$i
|
|
|
|
|
eval "expected=\$expected_failure_status_$prog"
|
2001-12-15 09:14:21 +00:00
|
|
|
test x$expected = x && expected=1
|
|
|
|
|
if test $status = $expected; then
|
|
|
|
|
: # ok
|
|
|
|
|
else
|
|
|
|
|
fail=1
|
2003-07-26 06:48:40 +00:00
|
|
|
echo "*** $i: bad exit status \`$status' (expected $expected)," 1>&2
|
|
|
|
|
echo " with --help or --version output redirected to /dev/full" 1>&2
|
2001-12-15 09:14:21 +00:00
|
|
|
fi
|
2000-07-30 15:17:34 +00:00
|
|
|
fi
|
2001-12-15 09:14:21 +00:00
|
|
|
done
|
2000-07-30 15:17:34 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
|
|
tmp=tmp-$$
|
|
|
|
|
tmp_in=in-$$
|
|
|
|
|
tmp_in2=in2-$$
|
|
|
|
|
tmp_dir=dir-$$
|
|
|
|
|
tmp_out=out-$$
|
|
|
|
|
mkdir $tmp || fail=1
|
|
|
|
|
cd $tmp || fail=1
|
|
|
|
|
|
|
|
|
|
comm_args="$tmp_in $tmp_in"
|
|
|
|
|
csplit_args="$tmp_in //"
|
|
|
|
|
cut_args='-f 1'
|
|
|
|
|
join_args="$tmp_in $tmp_in"
|
|
|
|
|
tr_args='a a'
|
|
|
|
|
|
|
|
|
|
chmod_args="a+x $tmp_in"
|
|
|
|
|
# Punt on these.
|
|
|
|
|
chgrp_args=--version
|
|
|
|
|
chown_args=--version
|
|
|
|
|
mkfifo_args=--version
|
|
|
|
|
mknod_args=--version
|
2005-01-05 22:08:48 +00:00
|
|
|
# Punt on uptime, since it fails (e.g., failing to get boot time)
|
|
|
|
|
# on some systems, and we shouldn't let that stop `make check'.
|
|
|
|
|
uptime_args=--version
|
2000-07-30 15:17:34 +00:00
|
|
|
|
2007-10-20 08:26:57 +02:00
|
|
|
# Create a file in the current directory, not in $TMPDIR.
|
|
|
|
|
mktemp_args=mktemp.XXXX
|
|
|
|
|
|
2002-01-13 09:33:32 +00:00
|
|
|
cmp_args="$tmp_in $tmp_in2"
|
2006-11-23 09:02:36 +01:00
|
|
|
|
|
|
|
|
# Tell dd not to print the line with transfer rate and total.
|
|
|
|
|
# The transfer rate would vary between runs.
|
|
|
|
|
dd_args=status=noxfer
|
|
|
|
|
|
2002-01-13 09:33:32 +00:00
|
|
|
diff_args="$tmp_in $tmp_in2"
|
|
|
|
|
sdiff_args="$tmp_in $tmp_in2"
|
|
|
|
|
diff3_args="$tmp_in $tmp_in2 $tmp_in2"
|
2000-07-30 15:17:34 +00:00
|
|
|
cp_args="$tmp_in $tmp_in2"
|
2003-07-16 19:54:13 +00:00
|
|
|
ln_args="$tmp_in ln-target"
|
2000-07-30 15:17:34 +00:00
|
|
|
ginstall_args="$tmp_in $tmp_in2"
|
|
|
|
|
mv_args="$tmp_in $tmp_in2"
|
2003-07-16 19:54:13 +00:00
|
|
|
mkdir_args=$tmp_dir/subdir
|
2000-07-30 15:17:34 +00:00
|
|
|
rmdir_args=$tmp_dir
|
|
|
|
|
rm_args=$tmp_in
|
|
|
|
|
shred_args=$tmp_in
|
|
|
|
|
touch_args=$tmp_in2
|
|
|
|
|
|
|
|
|
|
basename_args=$tmp_in
|
|
|
|
|
dirname_args=$tmp_in
|
|
|
|
|
expr_args=foo
|
|
|
|
|
|
|
|
|
|
# Punt, in case GNU `id' hasn't been installed yet.
|
|
|
|
|
groups_args=--version
|
|
|
|
|
|
|
|
|
|
pathchk_args=$tmp_in
|
|
|
|
|
yes_args=--version
|
|
|
|
|
logname_args=--version
|
|
|
|
|
nohup_args=--version
|
|
|
|
|
printf_args=foo
|
|
|
|
|
seq_args=10
|
|
|
|
|
sleep_args=0
|
|
|
|
|
su_args=--version
|
2006-09-24 16:46:41 +00:00
|
|
|
|
|
|
|
|
# I'd rather not run sync, since it spins up disks that I've
|
|
|
|
|
# deliberately caused to spin down (but not unmounted).
|
|
|
|
|
sync_args=--version
|
|
|
|
|
|
2000-07-30 15:17:34 +00:00
|
|
|
test_args=foo
|
2004-02-17 14:42:47 +00:00
|
|
|
|
|
|
|
|
# This is necessary in the unusual event that there is
|
|
|
|
|
# no valid entry in /etc/mtab.
|
|
|
|
|
df_args=/
|
2000-07-30 15:17:34 +00:00
|
|
|
|
2004-02-17 16:05:34 +00:00
|
|
|
# This is necessary in the unusual event that getpwuid (getuid ()) fails.
|
|
|
|
|
id_args=-u
|
|
|
|
|
|
2003-07-16 19:54:13 +00:00
|
|
|
sleep 10m &
|
|
|
|
|
kill_args=$!
|
|
|
|
|
|
|
|
|
|
link_args="$tmp_in link-target"
|
|
|
|
|
unlink_args=$tmp_in
|
|
|
|
|
|
|
|
|
|
ln -s . slink
|
|
|
|
|
readlink_args=slink
|
|
|
|
|
|
|
|
|
|
stat_args=$tmp_in
|
|
|
|
|
unlink_args=$tmp_in
|
|
|
|
|
lbracket_args=": ]"
|
|
|
|
|
|
2007-10-20 21:50:43 +02:00
|
|
|
# Ensure that each program "works" (exits successfully) when doing
|
|
|
|
|
# something more than --help or --version.
|
2007-07-10 22:37:48 +02:00
|
|
|
for i in $built_programs; do
|
2000-07-30 15:17:34 +00:00
|
|
|
# Skip these.
|
2007-02-02 18:58:41 +01:00
|
|
|
case $i in chroot|stty|tty|false|chcon|runcon) continue;; esac
|
2000-07-30 15:17:34 +00:00
|
|
|
|
|
|
|
|
rm -rf $tmp_in $tmp_in2 $tmp_dir $tmp_out
|
|
|
|
|
echo > $tmp_in
|
2002-01-13 09:33:32 +00:00
|
|
|
echo > $tmp_in2
|
2000-07-30 15:17:34 +00:00
|
|
|
mkdir $tmp_dir
|
|
|
|
|
# echo ================== $i
|
2003-07-16 19:54:13 +00:00
|
|
|
test $i = [ && prog=lbracket || prog=$i
|
|
|
|
|
eval "args=\$${prog}_args"
|
2007-10-09 17:12:45 +02:00
|
|
|
if $abs_top_builddir/src/$i $args < $tmp_in > $tmp_out; then
|
2000-07-30 15:17:34 +00:00
|
|
|
: # ok
|
|
|
|
|
else
|
|
|
|
|
echo FAIL: $i
|
|
|
|
|
fail=1
|
|
|
|
|
fi
|
|
|
|
|
rm -rf $tmp_in $tmp_in2 $tmp_out $tmp_dir
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
exit $fail
|