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 if test "$VERBOSE" = yes; then
11 # FIXME-someday: when run as root we don't need all of the
12 # searching below. root can simply create the required
13 # dir/files and run the test as someone else.
15 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
20 $PERL -e 1 > /dev/null 2>&1 || {
21 echo 1>&2 "$0: configure didn't find a usable version of Perl," \
22 "so can't run this test"
29 exec $PERL -w -- - << \EOP
33 (my $ME = $ENV{ARGV_0}) =~ s|.*/||;
35 my $verbose = $ENV{VERBOSE} && $ENV{VERBOSE} eq 'yes';
37 # Ensure that the diagnostics are in English.
40 my @dir_list = qw(/tmp /var/tmp /usr/tmp);
42 # Find a directory with the sticky bit set.
45 foreach my $dir (@dir_list)
47 if (-d $dir && -k _ && -r _ && -w _ && -x _)
51 # Find a non-directory there that is owned by some other user.
52 opendir DIR_HANDLE, $dir
53 or die "$ME: couldn't open $dir: $!\n";
55 foreach my $f (readdir DIR_HANDLE)
57 my $target_file = "$dir/$f";
59 and warn "$ME: considering $target_file\n";
61 # Skip files owned by self, symlinks, and directories.
62 # It's not technically necessary to skip symlinks, but it's simpler.
63 # SVR4-like systems (e.g., Solaris 9) let you unlink files that
64 # you can write, so skip writable files too.
65 -l $target_file || -o _ || -d _ || -w _
70 # Invoke rm on this file and ensure that we get the
71 # expected exit code and diagnostic.
72 my $cmd = "rm -f $target_file";
73 open RM, "$cmd 2>&1 |"
74 or die "$ME: cannot execute `$cmd'\n";
81 or die "$ME: unexpected exit status from `$cmd';\n"
82 . " got $status, expected 1\n";
84 my $exp = "rm: cannot remove `$target_file':";
86 or die "$ME: no output from `$cmd';\n"
87 . "expected something like `$exp ...'\n";
89 my $regex = quotemeta $exp;
91 or die "$ME: unexpected dignostic from `$cmd';\n"
93 . " expected $exp ...\n";
106 warn "$ME: couldn't find a directory with the sticky bit set;"
107 . " skipping this test\n";
113 warn "$ME: couldn't find a file not owned by you\n"
114 . " in any of the following directories:\n @dir_list\n"
115 . "...so, skipping this test\n";