~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/ftrace/test.d/00basic/test_ownership.tc

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/sh
  2 # SPDX-License-Identifier: GPL-2.0
  3 # description: Test file and directory ownership changes for eventfs
  4 # requires: "[gid=<gid>]":README
  5 
  6 original_group=`stat -c "%g" .`
  7 original_owner=`stat -c "%u" .`
  8 
  9 local mount_point=$(get_mount_point)
 10 
 11 mount_options=$(get_mnt_options "$mount_point")
 12 
 13 # find another owner and group that is not the original
 14 other_group=`tac /etc/group | grep -v ":$original_group:" | head -1 | cut -d: -f3`
 15 other_owner=`tac /etc/passwd | grep -v ":$original_owner:" | head -1 | cut -d: -f3`
 16 
 17 # Remove any group ownership already
 18 new_options=`echo "$mount_options" | sed -e "s/gid=[0-9]*/gid=$other_group/"`
 19 
 20 if [ "$new_options" = "$mount_options" ]; then
 21         new_options="$mount_options,gid=$other_group"
 22         mount_options="$mount_options,gid=$original_group"
 23 fi
 24 
 25 canary="events/timer events/timer/timer_cancel events/timer/timer_cancel/format"
 26 
 27 test() {
 28         file=$1
 29         test_group=$2
 30 
 31         owner=`stat -c "%u" $file`
 32         group=`stat -c "%g" $file`
 33 
 34         echo "testing $file $owner=$original_owner and $group=$test_group"
 35         if [ $owner -ne $original_owner ]; then
 36                 exit_fail
 37         fi
 38         if [ $group -ne $test_group ]; then
 39                 exit_fail
 40         fi
 41 
 42         # Note, the remount does not update ownership so test going to and from owner
 43         echo "test owner $file to $other_owner"
 44         chown $other_owner $file
 45         owner=`stat -c "%u" $file`
 46         if [ $owner -ne $other_owner ]; then
 47                 exit_fail
 48         fi
 49 
 50         chown $original_owner $file
 51         owner=`stat -c "%u" $file`
 52         if [ $owner -ne $original_owner ]; then
 53                 exit_fail
 54         fi
 55 
 56 }
 57 
 58 run_tests() {
 59         for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
 60                 test "$d" $other_group
 61         done
 62 
 63         chgrp $original_group events
 64         test "events" $original_group
 65         for d in "." "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
 66                 test "$d" $other_group
 67         done
 68 
 69         chgrp $original_group events/sched
 70         test "events/sched" $original_group
 71         for d in "." "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
 72                 test "$d" $other_group
 73         done
 74 
 75         chgrp $original_group events/sched/sched_switch
 76         test "events/sched/sched_switch" $original_group
 77         for d in "." "events/sched/sched_switch/enable" $canary; do
 78                 test "$d" $other_group
 79         done
 80 
 81         chgrp $original_group events/sched/sched_switch/enable
 82         test "events/sched/sched_switch/enable" $original_group
 83         for d in "." $canary; do
 84                 test "$d" $other_group
 85         done
 86 }
 87 
 88 # Run the tests twice as leftovers can cause issues
 89 for loop in 1 2 ; do
 90 
 91         echo "Running iteration $loop"
 92 
 93         mount -o remount,"$new_options" .
 94 
 95         run_tests
 96 
 97         mount -o remount,"$mount_options" .
 98 
 99         for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
100                 test "$d" $original_group
101         done
102 
103 # check instances as well
104 
105         chgrp $other_group instances
106 
107         instance="$(mktemp -u test-XXXXXX)"
108 
109         mkdir instances/$instance
110 
111         cd instances/$instance
112 
113         run_tests
114 
115         cd ../..
116 
117         rmdir instances/$instance
118 
119         chgrp $original_group instances
120 done
121 
122 exit 0

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php