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