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

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.