All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] generic/126: Test the permission to set file times
@ 2015-05-12 18:37 Andreas Gruenbacher
  2015-05-12 23:40 ` Dave Chinner
  0 siblings, 1 reply; 8+ messages in thread
From: Andreas Gruenbacher @ 2015-05-12 18:37 UTC (permalink / raw)
  To: fstests; +Cc: Christoph Hellwig

Check if setting the file access and modification times to the current time
and to a specific timestamp is allowed when expected.

Signed-off-by: Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
---
 src/fs_perms.c        | 14 +++++++++++++-
 tests/generic/126     | 22 ++++++++++++++++++++++
 tests/generic/126.out |  6 ++++++
 3 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/src/fs_perms.c b/src/fs_perms.c
index ea188c4..519db5b 100644
--- a/src/fs_perms.c
+++ b/src/fs_perms.c
@@ -37,6 +37,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/wait.h>
+#include <time.h>
+#include <utime.h>
 
 int testsetup(mode_t mode, int cuserId, int cgroupId);
 int testfperm(int userId, int groupId, char* fperm);
@@ -57,7 +59,7 @@ int main( int argc, char *argv[]) {
               exresult = atoi(argv[7]);
 	      break;
       default:
-	      printf("Usage: %s <mode of file> <UID of file> <GID of file> <UID of tester> <GID of tester> <permission to test r|w|x> <expected result as 0|1>\n",argv[0]); 
+	      printf("Usage: %s <mode of file> <UID of file> <GID of file> <UID of tester> <GID of tester> <permission to test r|w|x|t|T> <expected result as 0|1>\n",argv[0]);
 	      exit(0);
    }
 
@@ -113,6 +115,16 @@ int testfperm(int userId, int groupId, char* fperm) {
           seteuid(0);
           setegid(0);
 	  return(nuthertmpi);
+    } else if (!strcmp("t", fperm)) {
+	return utime("test.file", NULL) ? 0 : 1;
+    } else if (!strcmp("T", fperm)) {
+	time_t now = time(NULL);
+	struct utimbuf times = {
+		.actime = now - 1,
+		.modtime = now - 1
+	};
+
+	return utime("test.file", &times) ? 0 : 1;
     } else {
           if((testfile=fopen("test.file",fperm))){
             fclose(testfile);
diff --git a/tests/generic/126 b/tests/generic/126
index a22d587..45500af 100755
--- a/tests/generic/126
+++ b/tests/generic/126
@@ -70,5 +70,27 @@ $QA_FS_PERMS 200 99 99 200 99 w 1
 $QA_FS_PERMS 040 99 99 99 500 r 1
 $QA_FS_PERMS 400 99 99 200 99 r 1
 
+# Check if setting the file access and modification times to the current time
+# (t) and to a specific timestamp (T) is allowed when expected.
+#
+# From utime(2): Changing timestamps is permitted when: either the process has
+# appropriate privileges, or the effective user ID equals the user ID of the
+# file, or [the process is trying to set the timestamps to the current time]
+# and the process has write permission for the file.
+#
+# Note that the last of these tests will always wrongly succeed over NFSv2.
+# For NFSv3+, that test will wrongly succeed until kernel commit
+# "Disable NFSv2 timestamp workaround for NFSv3+".
+
+# The owner:
+$QA_FS_PERMS 600 99 99 99 99 t 1
+$QA_FS_PERMS 600 99 99 99 99 T 1
+
+# Other processes with and without write permission:
+$QA_FS_PERMS 600 99 99 100 99 t 0
+$QA_FS_PERMS 600 99 99 100 99 T 0
+$QA_FS_PERMS 660 99 99 100 99 t 1
+$QA_FS_PERMS 660 99 99 100 99 T 0
+
 status=0
 exit
diff --git a/tests/generic/126.out b/tests/generic/126.out
index 3347930..ad0e592 100644
--- a/tests/generic/126.out
+++ b/tests/generic/126.out
@@ -17,3 +17,9 @@ w a 020 file owned by (99/99) as user/group(99/500)  FAIL
 w a 200 file owned by (99/99) as user/group(200/99)  FAIL
 r a 040 file owned by (99/99) as user/group(99/500)  FAIL
 r a 400 file owned by (99/99) as user/group(200/99)  FAIL
+t a 600 file owned by (99/99) as user/group(99/99)  PASS
+T a 600 file owned by (99/99) as user/group(99/99)  PASS
+t a 600 file owned by (99/99) as user/group(100/99)  PASS
+T a 600 file owned by (99/99) as user/group(100/99)  PASS
+t a 660 file owned by (99/99) as user/group(100/99)  PASS
+T a 660 file owned by (99/99) as user/group(100/99)  PASS
-- 
2.4.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] generic/126: Test the permission to set file times
  2015-05-12 18:37 [PATCH] generic/126: Test the permission to set file times Andreas Gruenbacher
@ 2015-05-12 23:40 ` Dave Chinner
  2015-05-13  0:07   ` [PATCH] generic/326: " Andreas Gruenbacher
  0 siblings, 1 reply; 8+ messages in thread
From: Dave Chinner @ 2015-05-12 23:40 UTC (permalink / raw)
  To: Andreas Gruenbacher; +Cc: fstests, Christoph Hellwig

On Tue, May 12, 2015 at 08:37:11PM +0200, Andreas Gruenbacher wrote:
> Check if setting the file access and modification times to the current time
> and to a specific timestamp is allowed when expected.
> 
> Signed-off-by: Andreas Gruenbacher <andreas.gruenbacher@gmail.com>

I think I'd prefer to see this added as a new test, rather than
extending an existing test and potentially causing it to fail due to
the new things being tested....

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] generic/326: Test the permission to set file times
  2015-05-12 23:40 ` Dave Chinner
@ 2015-05-13  0:07   ` Andreas Gruenbacher
  2015-05-14  3:19     ` Dave Chinner
  0 siblings, 1 reply; 8+ messages in thread
From: Andreas Gruenbacher @ 2015-05-13  0:07 UTC (permalink / raw)
  To: fstests; +Cc: Christoph Hellwig

Check if setting the file access and modification times to the current time
and to a specific timestamp is allowed when expected.

Signed-off-by: Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
---
 src/fs_perms.c        | 14 +++++++++-
 tests/generic/326     | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/326.out |  7 +++++
 tests/generic/group   |  1 +
 4 files changed, 95 insertions(+), 1 deletion(-)
 create mode 100755 tests/generic/326
 create mode 100644 tests/generic/326.out

diff --git a/src/fs_perms.c b/src/fs_perms.c
index ea188c4..519db5b 100644
--- a/src/fs_perms.c
+++ b/src/fs_perms.c
@@ -37,6 +37,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/wait.h>
+#include <time.h>
+#include <utime.h>
 
 int testsetup(mode_t mode, int cuserId, int cgroupId);
 int testfperm(int userId, int groupId, char* fperm);
@@ -57,7 +59,7 @@ int main( int argc, char *argv[]) {
               exresult = atoi(argv[7]);
 	      break;
       default:
-	      printf("Usage: %s <mode of file> <UID of file> <GID of file> <UID of tester> <GID of tester> <permission to test r|w|x> <expected result as 0|1>\n",argv[0]); 
+	      printf("Usage: %s <mode of file> <UID of file> <GID of file> <UID of tester> <GID of tester> <permission to test r|w|x|t|T> <expected result as 0|1>\n",argv[0]);
 	      exit(0);
    }
 
@@ -113,6 +115,16 @@ int testfperm(int userId, int groupId, char* fperm) {
           seteuid(0);
           setegid(0);
 	  return(nuthertmpi);
+    } else if (!strcmp("t", fperm)) {
+	return utime("test.file", NULL) ? 0 : 1;
+    } else if (!strcmp("T", fperm)) {
+	time_t now = time(NULL);
+	struct utimbuf times = {
+		.actime = now - 1,
+		.modtime = now - 1
+	};
+
+	return utime("test.file", &times) ? 0 : 1;
     } else {
           if((testfile=fopen("test.file",fperm))){
             fclose(testfile);
diff --git a/tests/generic/326 b/tests/generic/326
new file mode 100755
index 0000000..16388c1
--- /dev/null
+++ b/tests/generic/326
@@ -0,0 +1,74 @@
+#! /bin/bash
+# FSQA Test No. 326
+#
+# Check if setting the file access and modification times to the current time
+# (t) and to a specific timestamp (T) is allowed when expected.
+#
+# From utime(2): Changing timestamps is permitted when: either the process has
+# appropriate privileges, or the effective user ID equals the user ID of the
+# file, or [the process is trying to set the timestamps to the current time]
+# and the process has write permission for the file.
+#
+# Note that the last of these tests will always wrongly succeed over NFSv2.
+# For NFSv3+, that test will wrongly succeed until kernel commit
+# "Disable NFSv2 timestamp workaround for NFSv3+".
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015 Red Hat, Inc.
+# Author: Andreas Gruenbacher <agruenba@redhat.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+    cd /
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_test
+
+QA_FS_PERMS=$here/src/fs_perms
+
+cd $TEST_DIR
+
+# The owner:
+$QA_FS_PERMS 600 99 99 99 99 t 1
+$QA_FS_PERMS 600 99 99 99 99 T 1
+
+# Other processes with and without write permission:
+$QA_FS_PERMS 600 99 99 100 99 t 0
+$QA_FS_PERMS 600 99 99 100 99 T 0
+$QA_FS_PERMS 660 99 99 100 99 t 1
+$QA_FS_PERMS 660 99 99 100 99 T 0
+
+status=0
+exit
diff --git a/tests/generic/326.out b/tests/generic/326.out
new file mode 100644
index 0000000..78f7543
--- /dev/null
+++ b/tests/generic/326.out
@@ -0,0 +1,7 @@
+QA output created by 326
+t a 600 file owned by (99/99) as user/group(99/99)  PASS
+T a 600 file owned by (99/99) as user/group(99/99)  PASS
+t a 600 file owned by (99/99) as user/group(100/99)  PASS
+T a 600 file owned by (99/99) as user/group(100/99)  PASS
+t a 660 file owned by (99/99) as user/group(100/99)  PASS
+T a 660 file owned by (99/99) as user/group(100/99)  PASS
diff --git a/tests/generic/group b/tests/generic/group
index b6f4b01..1f2f3d2 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -192,3 +192,4 @@
 323 auto aio stress
 324 auto fsr quick
 325 auto quick data log
+326 perms auto quick
-- 
2.4.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] generic/326: Test the permission to set file times
  2015-05-13  0:07   ` [PATCH] generic/326: " Andreas Gruenbacher
@ 2015-05-14  3:19     ` Dave Chinner
  2015-05-14  7:56       ` Andreas Grünbacher
  0 siblings, 1 reply; 8+ messages in thread
From: Dave Chinner @ 2015-05-14  3:19 UTC (permalink / raw)
  To: Andreas Gruenbacher; +Cc: fstests, Christoph Hellwig

On Wed, May 13, 2015 at 02:07:34AM +0200, Andreas Gruenbacher wrote:
> Check if setting the file access and modification times to the current time
> and to a specific timestamp is allowed when expected.
> 
> Signed-off-by: Andreas Gruenbacher <andreas.gruenbacher@gmail.com>

Fails on XFS.

/me looks at fs_perms and shudders at all the system() calls.

Looks like there is no testx.file created first.

    --- tests/generic/087.out   2015-05-14 12:22:32.000000000 +1000
    +++ /home/dave/src/xfstests-dev/results//xfs/generic/087.out.bad    2015-05-14 12:41:02.000000000 +1000
    @@ -1,7 +1,19 @@
     QA output created by 087
    -t a 600 file owned by (99/99) as user/group(99/99)  PASS
    -T a 600 file owned by (99/99) as user/group(99/99)  PASS
    +cp: cannot stat 'testx.file': No such file or directory
    +rm: cannot remove 'test.file': No such file or directory
    +t a 600 file owned by (99/99) as user/group(99/99)  FAIL
    +cp: cannot stat 'testx.file': No such file or directory


(yes, I renumbered it to 087)

> +QA_FS_PERMS=$here/src/fs_perms
> +
> +cd $TEST_DIR

Yup, it's missing this:

cd $TEST_DIR
cp $here/src/testx ./testx.file

from generic/126.

I fixed it, but now an rm (from one of those system() calls within
the test program) gets stuck waiting on something else:

[ 2540.235059] rm              S ffff8802e7d87be8 14488  9969   9968
0x00000000
[ 2540.236602]  ffff8802e7d87be8 ffff88042da98000 ffff88028b719850
ffff8802e7d87ce8
[ 2540.238206]  ffff8802e7d88000 ffff88042b4eb000 0000000000000000
ffffc900009f4000
[ 2540.239818]  7fffffffffffffff ffff8802e7d87c08 ffffffff81df05b7
ffff8802f80853b0
[ 2540.241474] Call Trace:
[ 2540.241988]  [<ffffffff81df05b7>] schedule+0x37/0x90
[ 2540.243000]  [<ffffffff81df4541>] schedule_timeout+0x1d1/0x230
[ 2540.244241]  [<ffffffff81df3939>] ? down_write+0x29/0x60
[ 2540.245355]  [<ffffffff811a777b>] ? vma_adjust+0x3db/0x6a0
[ 2540.246487]  [<ffffffff810dcc1e>] wait_woken+0x7e/0xa0
[ 2540.247562]  [<ffffffff818a697d>] n_tty_read+0x25d/0xb00
[ 2540.248703]  [<ffffffff811a7cbf>] ? vma_merge+0xbf/0x270
[ 2540.249819]  [<ffffffff810dcb80>] ? __wake_up_sync+0x20/0x20
[ 2540.250979]  [<ffffffff818a24cd>] tty_read+0x8d/0xf0
[ 2540.251995]  [<ffffffff811c7208>] __vfs_read+0x28/0xf0
[ 2540.253107]  [<ffffffff81788724>] ?
security_file_permission+0x84/0xa0
[ 2540.254458]  [<ffffffff811c7766>] ? rw_verify_area+0x56/0xe0
[ 2540.255619]  [<ffffffff811c7872>] vfs_read+0x82/0x120
[ 2540.256709]  [<ffffffff811c8699>] SyS_read+0x49/0xb0
[ 2540.257733]  [<ffffffff81df582e>] system_call_fastpath+0x12/0x71

# ps -ef
.....
root      9746  9350  0 13:12 pts/0    00:00:00 /bin/bash ./tests/generic/087
uuidd     9965  9746  0 13:12 pts/0    00:00:00 /home/dave/src/xfstests-dev/src/
uuidd     9968  9965  0 13:12 pts/0    00:00:00 sh -c rm test.file
uuidd     9969  9968  0 13:12 pts/0    00:00:00 rm test.file

Perhaps it's waiting for input? should this actually be doing "rm
-f"?

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] generic/326: Test the permission to set file times
  2015-05-14  3:19     ` Dave Chinner
@ 2015-05-14  7:56       ` Andreas Grünbacher
  2015-05-14 10:30         ` Dave Chinner
  0 siblings, 1 reply; 8+ messages in thread
From: Andreas Grünbacher @ 2015-05-14  7:56 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests, Christoph Hellwig

2015-05-14 5:19 GMT+02:00 Dave Chinner <david@fromorbit.com>:
> Fails on XFS.
>
> /me looks at fs_perms and shudders at all the system() calls.
>
> Looks like there is no testx.file created first.

Hmm, that file was lying around from a previous run here.
Leaky tests are fun.

> should this actually be doing "rm -f"?

That's better, indeed.

Thanks for fixing up my xfstests beginner's mistakes.

Andreas

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] generic/326: Test the permission to set file times
  2015-05-14  7:56       ` Andreas Grünbacher
@ 2015-05-14 10:30         ` Dave Chinner
  2015-05-14 13:50           ` Andreas Gruenbacher
  0 siblings, 1 reply; 8+ messages in thread
From: Dave Chinner @ 2015-05-14 10:30 UTC (permalink / raw)
  To: Andreas Grünbacher; +Cc: fstests, Christoph Hellwig

On Thu, May 14, 2015 at 09:56:50AM +0200, Andreas Grünbacher wrote:
> 2015-05-14 5:19 GMT+02:00 Dave Chinner <david@fromorbit.com>:
> > Fails on XFS.
> >
> > /me looks at fs_perms and shudders at all the system() calls.
> >
> > Looks like there is no testx.file created first.
> 
> Hmm, that file was lying around from a previous run here.
> Leaky tests are fun.
> 
> > should this actually be doing "rm -f"?
> 
> That's better, indeed.

Except it still doesn't work:

generic/087 1s ... - output mismatch (see /home/dave/src/xfstests-dev/results//xfs_v4/generic/087.out.bad)
    --- tests/generic/087.out   2015-05-14 20:25:13.000000000 +1000
    +++ /home/dave/src/xfstests-dev/results//xfs_v4/generic/087.out.bad 2015-05-14 20:28:13.000000000 +1000
    @@ -1,7 +1,13 @@
     QA output created by 087
    +rm: cannot remove 'test.file': Permission denied
     t a 600 file owned by (99/99) as user/group(99/99)  PASS
    +rm: cannot remove 'test.file': Permission denied
     T a 600 file owned by (99/99) as user/group(99/99)  PASS
    +rm: cannot remove 'test.file': Permission denied
     t a 600 file owned by (99/99) as user/group(100/99)  PASS
.....

So there's something else that needs to be done here to allow the
test file to be removed....

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* (no subject)
  2015-05-14 10:30         ` Dave Chinner
@ 2015-05-14 13:50           ` Andreas Gruenbacher
  2015-05-14 13:50             ` [PATCH] generic/087,126: Test the permission to set file times Andreas Gruenbacher
  0 siblings, 1 reply; 8+ messages in thread
From: Andreas Gruenbacher @ 2015-05-14 13:50 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests, Christoph Hellwig

Here's an updated version that fixes some of the problems in the original test.
Both tests pass for me.

Andreas

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] generic/087,126: Test the permission to set file times
  2015-05-14 13:50           ` Andreas Gruenbacher
@ 2015-05-14 13:50             ` Andreas Gruenbacher
  0 siblings, 0 replies; 8+ messages in thread
From: Andreas Gruenbacher @ 2015-05-14 13:50 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests, Christoph Hellwig

Check if setting the file access and modification times to the current time
and to a specific timestamp is allowed when expected.

In generic/126, remove a left-over temporary file.

Signed-off-by: Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
---
 src/fs_perms.c        | 85 +++++++++++++++++++++++++++++----------------------
 tests/generic/087     | 77 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/087.out |  7 +++++
 tests/generic/126     |  2 ++
 tests/generic/group   |  1 +
 5 files changed, 135 insertions(+), 37 deletions(-)
 create mode 100755 tests/generic/087
 create mode 100644 tests/generic/087.out

diff --git a/src/fs_perms.c b/src/fs_perms.c
index ea188c4..5780016 100644
--- a/src/fs_perms.c
+++ b/src/fs_perms.c
@@ -37,6 +37,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/wait.h>
+#include <time.h>
+#include <utime.h>
 
 int testsetup(mode_t mode, int cuserId, int cgroupId);
 int testfperm(int userId, int groupId, char* fperm);
@@ -57,13 +59,13 @@ int main( int argc, char *argv[]) {
               exresult = atoi(argv[7]);
 	      break;
       default:
-	      printf("Usage: %s <mode of file> <UID of file> <GID of file> <UID of tester> <GID of tester> <permission to test r|w|x> <expected result as 0|1>\n",argv[0]); 
+	      printf("Usage: %s <mode of file> <UID of file> <GID of file> <UID of tester> <GID of tester> <permission to test r|w|x|t|T> <expected result as 0|1>\n",argv[0]);
 	      exit(0);
    }
 
    testsetup(mode,cuserId,cgroupId);
    result=testfperm(userId,groupId,fperm);
-   system("rm test.file");
+   system("rm -f test.file");
    printf("%s a %03o file owned by (%d/%d) as user/group(%d/%d)  ",fperm,mode,cuserId,cgroupId,userId,groupId);
    if (result == exresult) {
       printf("PASS\n");
@@ -84,46 +86,55 @@ int testsetup(mode_t mode, int cuserId, int cgroupId) {
 
 int testfperm(int userId, int groupId, char* fperm) {
 
-    FILE *testfile;
-    pid_t PID;
-    int tmpi,nuthertmpi;
+    int ret;
 
-/*  SET CURRENT USER/GROUP PERMISSIONS */
+    /*  SET CURRENT USER/GROUP PERMISSIONS */
+    ret = -1;
     if(setegid(groupId)) {
-        printf("could not setegid to %d.\n",groupId);
-           seteuid(0);
-           setegid(0);
-           return(-1);
-        }   
+	printf("could not setegid to %d.\n",groupId);
+	goto out;
+    }
     if(seteuid(userId)) {
-        printf("could not seteuid to %d.\n",userId);
-           seteuid(0);
-           setegid(0);
-           return(-1);
-        }
+	printf("could not seteuid to %d.\n",userId);
+	goto out;
+    }
 
     if (!strcmp("x", fperm)) {
-          PID = fork();
-	  if (PID == 0) {
-             execlp("./test.file","test.file",NULL); 
-	     exit(0);
-	  }
-	  wait(&tmpi);
-	  nuthertmpi=WEXITSTATUS(tmpi); 
-          seteuid(0);
-          setegid(0);
-	  return(nuthertmpi);
+	int status;
+	pid_t pid;
+
+	pid = fork();
+	if (pid == 0) {
+	    execlp("./test.file","test.file",NULL);
+	    exit(0);
+	}
+	wait(&status);
+	ret = WEXITSTATUS(status);
+    } else if (!strcmp("t", fperm)) {
+	ret = utime("test.file", NULL) ? 0 : 1;
+    } else if (!strcmp("T", fperm)) {
+	time_t now = time(NULL);
+	struct utimbuf times = {
+		.actime = now - 1,
+		.modtime = now - 1
+	};
+
+	ret = utime("test.file", &times) ? 0 : 1;
     } else {
-          if((testfile=fopen("test.file",fperm))){
-            fclose(testfile);
-            seteuid(0);
-            setegid(0);
-            return (1);
-	  }
-          else {
-            seteuid(0);
-            setegid(0);
-            return (0);
-	  }
+	FILE *file;
+
+	if((file = fopen("test.file",fperm))){
+	    fclose(file);
+	    ret = 1;
+	    goto out;
+	} else {
+	    ret = 0;
+	    goto out;
+	}
     }
+
+out:
+    seteuid(0);
+    setegid(0);
+    return ret;
 }
diff --git a/tests/generic/087 b/tests/generic/087
new file mode 100755
index 0000000..9653230
--- /dev/null
+++ b/tests/generic/087
@@ -0,0 +1,77 @@
+#! /bin/bash
+# FSQA Test No. 087
+#
+# Check if setting the file access and modification times to the current time
+# (t) and to a specific timestamp (T) is allowed when expected.
+#
+# From utime(2): Changing timestamps is permitted when: either the process has
+# appropriate privileges, or the effective user ID equals the user ID of the
+# file, or [the process is trying to set the timestamps to the current time]
+# and the process has write permission for the file.
+#
+# Note that the last of these tests will always wrongly succeed over NFSv2.
+# For NFSv3+, that test will wrongly succeed until kernel commit
+# "Disable NFSv2 timestamp workaround for NFSv3+".
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015 Red Hat, Inc.
+# Author: Andreas Gruenbacher <agruenba@redhat.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+    cd /
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_test
+
+QA_FS_PERMS=$here/src/fs_perms
+
+cd $TEST_DIR
+cp $here/src/testx ./testx.file
+
+# The owner:
+$QA_FS_PERMS 600 99 99 99 99 t 1
+$QA_FS_PERMS 600 99 99 99 99 T 1
+
+# Other processes with and without write permission:
+$QA_FS_PERMS 600 99 99 100 99 t 0
+$QA_FS_PERMS 600 99 99 100 99 T 0
+$QA_FS_PERMS 660 99 99 100 99 t 1
+$QA_FS_PERMS 660 99 99 100 99 T 0
+
+rm -f ./testx.file
+
+status=0
+exit
diff --git a/tests/generic/087.out b/tests/generic/087.out
new file mode 100644
index 0000000..d74cc32
--- /dev/null
+++ b/tests/generic/087.out
@@ -0,0 +1,7 @@
+QA output created by 087
+t a 600 file owned by (99/99) as user/group(99/99)  PASS
+T a 600 file owned by (99/99) as user/group(99/99)  PASS
+t a 600 file owned by (99/99) as user/group(100/99)  PASS
+T a 600 file owned by (99/99) as user/group(100/99)  PASS
+t a 660 file owned by (99/99) as user/group(100/99)  PASS
+T a 660 file owned by (99/99) as user/group(100/99)  PASS
diff --git a/tests/generic/126 b/tests/generic/126
index a22d587..bb3a566 100755
--- a/tests/generic/126
+++ b/tests/generic/126
@@ -70,5 +70,7 @@ $QA_FS_PERMS 200 99 99 200 99 w 1
 $QA_FS_PERMS 040 99 99 99 500 r 1
 $QA_FS_PERMS 400 99 99 200 99 r 1
 
+rm -f ./testx.file
+
 status=0
 exit
diff --git a/tests/generic/group b/tests/generic/group
index b6f4b01..5308c37 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -89,6 +89,7 @@
 084 auto metadata quick
 085 auto freeze mount
 086 auto prealloc preallocrw quick
+087 perms auto quick
 088 perms auto quick
 089 metadata auto
 091 rw auto quick
-- 
2.4.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-05-14 13:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-12 18:37 [PATCH] generic/126: Test the permission to set file times Andreas Gruenbacher
2015-05-12 23:40 ` Dave Chinner
2015-05-13  0:07   ` [PATCH] generic/326: " Andreas Gruenbacher
2015-05-14  3:19     ` Dave Chinner
2015-05-14  7:56       ` Andreas Grünbacher
2015-05-14 10:30         ` Dave Chinner
2015-05-14 13:50           ` Andreas Gruenbacher
2015-05-14 13:50             ` [PATCH] generic/087,126: Test the permission to set file times Andreas Gruenbacher

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.