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 6original_group=`stat -c "%g" .` 7original_owner=`stat -c "%u" .` 8 9local mount_point=$(get_mount_point) 10 11mount_options=$(get_mnt_options "$mount_point") 12 13# find another owner and group that is not the original 14other_group=`tac /etc/group | grep -v ":$original_group:" | head -1 | cut -d: -f3` 15other_owner=`tac /etc/passwd | grep -v ":$original_owner:" | head -1 | cut -d: -f3` 16 17# Remove any group ownership already 18new_options=`echo "$mount_options" | sed -e "s/gid=[0-9]*/gid=$other_group/"` 19 20if [ "$new_options" = "$mount_options" ]; then 21 new_options="$mount_options,gid=$other_group" 22 mount_options="$mount_options,gid=$original_group" 23fi 24 25canary="events/timer events/timer/timer_cancel events/timer/timer_cancel/format" 26 27test() { 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 58run_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 89for 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 120done 121 122exit 0 123