123 lines · plain
1#!/bin/sh2# SPDX-License-Identifier: GPL-2.03# description: Test file and directory ownership changes for eventfs4# requires: "[gid=<gid>]":README5 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 original14other_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 already18new_options=`echo "$mount_options" | sed -e "s/gid=[0-9]*/gid=$other_group/"`19 20if [ "$new_options" = "$mount_options" ]; then21 new_options="$mount_options,gid=$other_group"22 mount_options="$mount_options,gid=$original_group"23fi24 25canary="events/timer events/timer/timer_cancel events/timer/timer_cancel/format"26 27test() {28 file=$129 test_group=$230 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 ]; then36 exit_fail37 fi38 if [ $group -ne $test_group ]; then39 exit_fail40 fi41 42 # Note, the remount does not update ownership so test going to and from owner43 echo "test owner $file to $other_owner"44 chown $other_owner $file45 owner=`stat -c "%u" $file`46 if [ $owner -ne $other_owner ]; then47 exit_fail48 fi49 50 chown $original_owner $file51 owner=`stat -c "%u" $file`52 if [ $owner -ne $original_owner ]; then53 exit_fail54 fi55 56}57 58run_tests() {59 for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do60 test "$d" $other_group61 done62 63 chgrp $original_group events64 test "events" $original_group65 for d in "." "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do66 test "$d" $other_group67 done68 69 chgrp $original_group events/sched70 test "events/sched" $original_group71 for d in "." "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do72 test "$d" $other_group73 done74 75 chgrp $original_group events/sched/sched_switch76 test "events/sched/sched_switch" $original_group77 for d in "." "events/sched/sched_switch/enable" $canary; do78 test "$d" $other_group79 done80 81 chgrp $original_group events/sched/sched_switch/enable82 test "events/sched/sched_switch/enable" $original_group83 for d in "." $canary; do84 test "$d" $other_group85 done86}87 88# Run the tests twice as leftovers can cause issues89for loop in 1 2 ; do90 91 echo "Running iteration $loop"92 93 mount -o remount,"$new_options" .94 95 run_tests96 97 mount -o remount,"$mount_options" .98 99 for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do100 test "$d" $original_group101 done102 103# check instances as well104 105 chgrp $other_group instances106 107 instance="$(mktemp -u test-XXXXXX)"108 109 mkdir instances/$instance110 111 cd instances/$instance112 113 run_tests114 115 cd ../..116 117 rmdir instances/$instance118 119 chgrp $original_group instances120done121 122exit 0123