generic/375: test both regular file and directory
authorEric Biggers <ebiggers@google.com>
Wed, 12 Oct 2016 22:03:07 +0000 (15:03 -0700)
committerEryu Guan <eguan@redhat.com>
Thu, 13 Oct 2016 07:53:46 +0000 (15:53 +0800)
generic/375 previously only tested SGID being cleared on a regular
file. It should test SGID being cleared on a directory too. Though
this is not required by POSIX, it is the Linux behavior.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
tests/generic/375
tests/generic/375.out

index f8c3260e564b53e7bc441eac27601c665ebebfa1..1d523e534049ccc3dffd1f66725e80d1e9afb347 100755 (executable)
@@ -52,30 +52,44 @@ _require_runas
 _require_acls
 
 cd $TEST_DIR
-testfile=testfile.$seq
-rm -f $testfile
 
-touch $testfile
-chown 100:100 $testfile
+# try with both regular file and directory
+for filetype in regular dir; do
 
-echo '*** SGID should remain set (twice)'
-chmod 2755 $testfile
-_runas -u 100 -g 100 -- chmod 2777 $testfile
-stat -c %A $testfile
-chmod 2755 $testfile
-_runas -u 100 -g 100 -- setfacl -m u::rwx,g::rwx,o::rwx $testfile
-stat -c %A $testfile
+       case $filetype in
+       regular)
+               testfile=testfile.$seq
+               rm -f $testfile
+               touch $testfile
+               ;;
+       *)
+               testfile=testdir.$seq
+               rm -rf $testfile
+               mkdir $testfile
+               ;;
+       esac
 
-echo '*** SGID should be cleared (twice)'
-chmod 2755 $testfile
-_runas -u 100 -g 101 -- chmod 2777 $testfile
-stat -c %A $testfile
-chmod 2755 $testfile
-_runas -u 100 -g 101 -- setfacl -m u::rwx,g::rwx,o::rwx $testfile
-stat -c %A $testfile
+       chown 100:100 $testfile
 
-echo '*** Expected failure'
-_runas -u 101 -g 101 -- chmod 2777 $testfile
+       echo '*** SGID should remain set (twice)'
+       chmod 2755 $testfile
+       _runas -u 100 -g 100 -- chmod 2777 $testfile
+       stat -c %A $testfile
+       chmod 2755 $testfile
+       _runas -u 100 -g 100 -- setfacl -m u::rwx,g::rwx,o::rwx $testfile
+       stat -c %A $testfile
+
+       echo '*** SGID should be cleared (twice)'
+       chmod 2755 $testfile
+       _runas -u 100 -g 101 -- chmod 2777 $testfile
+       stat -c %A $testfile
+       chmod 2755 $testfile
+       _runas -u 100 -g 101 -- setfacl -m u::rwx,g::rwx,o::rwx $testfile
+       stat -c %A $testfile
+
+       echo '*** Expected failure'
+       _runas -u 101 -g 101 -- chmod 2777 $testfile
+done
 
 status=0
 exit
index 478d0784ca955dbdbdf04c09e4ad40e7fa8d001e..bb9bc72c4bf71410ba7e2df85bfe2bc8789623ee 100644 (file)
@@ -7,3 +7,11 @@ QA output created by 375
 -rwxrwxrwx
 *** Expected failure
 chmod: changing permissions of 'testfile.375': Operation not permitted
+*** SGID should remain set (twice)
+drwxrwsrwx
+drwxrwsrwx
+*** SGID should be cleared (twice)
+drwxrwxrwx
+drwxrwxrwx
+*** Expected failure
+chmod: changing permissions of 'testdir.375': Operation not permitted