3 # Ensure that rm gives the expected diagnostic when failing to remove a file
4 # owned by some other user in a directory with the sticky bit set.
6 # Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 if test "$VERBOSE" = yes; then
28 # FIXME-someday: when run as root we don't need all of the
29 # searching below. root can simply create the required
30 # dir/files and run the test as someone else.
32 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
37 $PERL -e 1 > /dev/null 2>&1 || {
38 echo 1>&2 "$0: configure didn't find a usable version of Perl," \
39 "so can't run this test"
46 exec $PERL -w -- - << \EOP
50 (my $ME = $ENV{ARGV_0}) =~ s|.*/||;
52 my $verbose = $ENV{VERBOSE} && $ENV{VERBOSE} eq 'yes';
54 # Ensure that the diagnostics are in English.
57 my @dir_list = qw(/tmp /var/tmp /usr/tmp);
59 # Find a directory with the sticky bit set.
62 foreach my $dir (@dir_list)
64 if (-d $dir && -k _ && -r _ && -w _ && -x _)
68 # Find a non-directory there that is owned by some other user.
69 opendir DIR_HANDLE, $dir
70 or die "$ME: couldn't open $dir: $!\n";
72 foreach my $f (readdir DIR_HANDLE)
74 my $target_file = "$dir/$f";
76 and warn "$ME: considering $target_file\n";
78 # Skip files owned by self, symlinks, and directories.
79 # It's not technically necessary to skip symlinks, but it's simpler.
80 # SVR4-like systems (e.g., Solaris 9) let you unlink files that
81 # you can write, so skip writable files too.
82 -l $target_file || -o _ || -d _ || -w _
87 # Invoke rm on this file and ensure that we get the
88 # expected exit code and diagnostic.
89 my $cmd = "rm -f $target_file";
90 open RM, "$cmd 2>&1 |"
91 or die "$ME: cannot execute `$cmd'\n";
98 or die "$ME: unexpected exit status from `$cmd';\n"
99 . " got $status, expected 1\n";
101 my $exp = "rm: cannot remove `$target_file':";
103 or die "$ME: no output from `$cmd';\n"
104 . "expected something like `$exp ...'\n";
106 my $regex = quotemeta $exp;
108 or die "$ME: unexpected dignostic from `$cmd';\n"
110 . " expected $exp ...\n";
123 warn "$ME: couldn't find a directory with the sticky bit set;"
124 . " skipping this test\n";
130 warn "$ME: couldn't find a file not owned by you\n"
131 . " in any of the following directories:\n @dir_list\n"
132 . "...so, skipping this test\n";