Skip to content

Commit df10c22

Browse files
author
Jean-Pierre André
committed
Added tests for utime(2)
Added tests for utime(2) which were missing so far
1 parent b03db98 commit df10c22

File tree

6 files changed

+266
-0
lines changed

6 files changed

+266
-0
lines changed

fstest.c

+21
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include <ctype.h>
4141
#include <errno.h>
4242
#include <assert.h>
43+
#include <sys/types.h>
44+
#include <utime.h>
4345
#ifdef HAS_ACL
4446
#include <sys/acl.h>
4547
#endif
@@ -81,6 +83,7 @@ enum action {
8183
ACTION_TRUNCATE,
8284
ACTION_STAT,
8385
ACTION_LSTAT,
86+
ACTION_UTIME,
8487
#ifdef HAS_ACL
8588
ACTION_GETFACL,
8689
ACTION_SETFACL,
@@ -126,6 +129,8 @@ static struct syscall_desc syscalls[] = {
126129
{ "truncate", ACTION_TRUNCATE, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
127130
{ "stat", ACTION_STAT, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
128131
{ "lstat", ACTION_LSTAT, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
132+
{ "utime", ACTION_UTIME, { TYPE_STRING, TYPE_NUMBER | TYPE_OPTIONAL,
133+
TYPE_NUMBER | TYPE_OPTIONAL, TYPE_NONE } },
129134
#ifdef HAS_ACL
130135
{ "getfacl", ACTION_GETFACL, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
131136
{ "setfacl", ACTION_SETFACL, { TYPE_STRING, TYPE_STRING,
@@ -517,6 +522,7 @@ static unsigned int
517522
call_syscall(struct syscall_desc *scall, char *argv[])
518523
{
519524
struct stat64 sb;
525+
struct utimbuf ut;
520526
long long flags;
521527
unsigned int i;
522528
char *endp;
@@ -649,6 +655,21 @@ call_syscall(struct syscall_desc *scall, char *argv[])
649655
return (i);
650656
}
651657
break;
658+
case ACTION_UTIME :
659+
switch (i) {
660+
case 1 :
661+
rval = utime(STR(0), (struct utimbuf*)NULL);
662+
break;
663+
case 3:
664+
ut.actime = NUM(1);
665+
ut.modtime = NUM(2);
666+
rval = utime(STR(0), &ut);
667+
break;
668+
default :
669+
fprintf(stderr,"utime() requires 1 or 3 arguments\n");
670+
exit(1);
671+
}
672+
break;
652673
#ifdef HAS_ACL
653674
case ACTION_GETFACL :
654675
rval = do_getfacl(STR(0), STR(1));

tests/utime/00.t

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/sh
2+
3+
desc="utime allowed when owner, or privileged, or current time and write access"
4+
5+
dir=`dirname $0`
6+
. ${dir}/../misc.sh
7+
8+
echo "1..40"
9+
10+
n0=`namegen`
11+
n1=`namegen`
12+
n2=`namegen`
13+
14+
expect 0 mkdir ${n0} 0777
15+
expect 0 chown ${n0} 65534 65534
16+
expect 0 -u 65534 -g 65534 create ${n0}/${n1} 0464
17+
expect 0 -u 65534 -g 65534 mkdir ${n0}/${n2} 0464
18+
now=`${fstest} stat ${n0} mtime`
19+
hourback=`echo $now-3600 | bc`
20+
halfhourback=`echo $now-1800 | bc`
21+
#
22+
# allowed to root
23+
#
24+
# 5
25+
expect 0 utime ${n0}/${n1} $hourback $halfhourback
26+
expect $hourback stat ${n0}/${n1} atime
27+
expect $halfhourback stat ${n0}/${n1} mtime
28+
expect 0 utime ${n0}/${n1}
29+
atime=`${fstest} stat ${n0}/${n1} atime`
30+
test_check $now -le $atime
31+
mtime=`${fstest} stat ${n0}/${n1} mtime`
32+
test_check $now -le $mtime
33+
34+
expect 0 utime ${n0}/${n2} $hourback $halfhourback
35+
expect $hourback stat ${n0}/${n2} atime
36+
expect $halfhourback stat ${n0}/${n2} mtime
37+
expect 0 utime ${n0}/${n2}
38+
atime=`${fstest} stat ${n0}/${n2} atime`
39+
test_check $now -le $atime
40+
mtime=`${fstest} stat ${n0}/${n2} mtime`
41+
test_check $now -le $mtime
42+
#
43+
# allowed to owner, though no write access
44+
#
45+
# 17
46+
expect 0 -u 65534 -g 65534 utime ${n0}/${n1} $hourback $halfhourback
47+
expect $hourback stat ${n0}/${n1} atime
48+
expect $halfhourback stat ${n0}/${n1} mtime
49+
expect 0 -u 65534 -g 65534 utime ${n0}/${n1}
50+
atime=`${fstest} stat ${n0}/${n1} atime`
51+
test_check $now -le $atime
52+
mtime=`${fstest} stat ${n0}/${n1} mtime`
53+
test_check $now -le $mtime
54+
55+
expect 0 -u 65534 -g 65534 utime ${n0}/${n2} $hourback $halfhourback
56+
expect $hourback stat ${n0}/${n2} atime
57+
expect $halfhourback stat ${n0}/${n2} mtime
58+
expect 0 -u 65534 -g 65534 utime ${n0}/${n2}
59+
atime=`${fstest} stat ${n0}/${n2} atime`
60+
test_check $now -le $atime
61+
mtime=`${fstest} stat ${n0}/${n2} mtime`
62+
test_check $now -le $mtime
63+
#
64+
# group has access to set to current time
65+
#
66+
# 29
67+
expect 0 utime ${n0}/${n1} $hourback $halfhourback
68+
expect 0 -u 65533 -g 65534 utime ${n0}/${n1}
69+
atime=`${fstest} stat ${n0}/${n1} atime`
70+
test_check $now -le $atime
71+
mtime=`${fstest} stat ${n0}/${n1} mtime`
72+
test_check $now -le $mtime
73+
74+
expect 0 utime ${n0}/${n2} $hourback $halfhourback
75+
expect 0 -u 65533 -g 65534 utime ${n0}/${n2}
76+
atime=`${fstest} stat ${n0}/${n2} atime`
77+
test_check $now -le $atime
78+
mtime=`${fstest} stat ${n0}/${n2} mtime`
79+
test_check $now -le $mtime
80+
#
81+
# cleanup
82+
#
83+
# 37
84+
expect 0 chmod ${n0} 0755
85+
expect 0 rmdir ${n0}/${n2}
86+
expect 0 unlink ${n0}/${n1}
87+
expect 0 rmdir ${n0}

tests/utime/01.t

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
desc="utime returns ENOENT if the filename does not exist"
4+
5+
dir=`dirname $0`
6+
. ${dir}/../misc.sh
7+
8+
echo "1..4"
9+
10+
n0=`namegen`
11+
n1=`namegen`
12+
13+
expect 0 mkdir ${n0} 0755
14+
expect ENOENT utime ${n0}/${n1}
15+
expect ENOENT utime ${n0}/${n1} 1234 5678
16+
expect 0 rmdir ${n0}

tests/utime/02.t

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/sh
2+
3+
desc="utime returns EACCES if Search permission is denied for one of the directories"
4+
5+
dir=`dirname $0`
6+
. ${dir}/../misc.sh
7+
8+
echo "1..30"
9+
10+
n0=`namegen`
11+
n1=`namegen`
12+
13+
expect 0 mkdir ${n0} 0755
14+
expect 0 chown ${n0} 65534 65534
15+
expect 0 -u 65534 -g 65534 create ${n0}/${n1} 0666
16+
now=`${fstest} stat ${n0} mtime`
17+
hourback=`echo $now-3600 | bc`
18+
halfhourback=`echo $now-1800 | bc`
19+
expect 0 chmod ${n0} 0676
20+
#
21+
# allowed for root
22+
#
23+
expect 0 utime ${n0}/${n1} $hourback $halfhourback
24+
expect $hourback stat ${n0}/${n1} atime
25+
expect $halfhourback stat ${n0}/${n1} mtime
26+
expect 0 utime ${n0}/${n1}
27+
atime=`${fstest} stat ${n0}/${n1} atime`
28+
test_check $now -le $atime
29+
mtime=`${fstest} stat ${n0}/${n1} mtime`
30+
test_check $now -le $mtime
31+
#
32+
# group has directory access to set to current time
33+
#
34+
# 11
35+
expect 0 utime ${n0}/${n1} $hourback $halfhourback
36+
expect 0 -u 65533 -g 65534 utime ${n0}/${n1}
37+
atime=`${fstest} stat ${n0}/${n1} atime`
38+
test_check $now -le $atime
39+
mtime=`${fstest} stat ${n0}/${n1} mtime`
40+
test_check $now -le $mtime
41+
#
42+
# not allowed for owner
43+
#
44+
# 15
45+
expect 0 utime ${n0}/${n1} $hourback $halfhourback
46+
expect EACCES -u 65534 -g 65534 utime ${n0}/${n1} $now $now
47+
expect $hourback stat ${n0}/${n1} atime
48+
expect $halfhourback stat ${n0}/${n1} mtime
49+
expect EACCES -u 65534 -g 65534 utime ${n0}/${n1}
50+
expect $hourback stat ${n0}/${n1} atime
51+
expect $halfhourback stat ${n0}/${n1} mtime
52+
#
53+
# not allowed for another user,
54+
# - either not current time, though group access
55+
# - or current time, though write access to file
56+
#
57+
# 22
58+
expect 'EACCES|EPERM' -u 65533 -g 65534 utime ${n0}/${n1} $now $now
59+
expect $hourback stat ${n0}/${n1} atime
60+
expect $halfhourback stat ${n0}/${n1} mtime
61+
expect EACCES -u 65533 -g 65533 utime ${n0}/${n1}
62+
expect $hourback stat ${n0}/${n1} atime
63+
expect $halfhourback stat ${n0}/${n1} mtime
64+
#
65+
# delete
66+
#
67+
# 28
68+
expect 0 chmod ${n0} 0755
69+
expect 0 unlink ${n0}/${n1}
70+
expect 0 rmdir ${n0}

tests/utime/03.t

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
3+
desc="utime returns EACCES if set current time, not owner and no write access"
4+
5+
dir=`dirname $0`
6+
. ${dir}/../misc.sh
7+
8+
echo "1..13"
9+
10+
n0=`namegen`
11+
n1=`namegen`
12+
13+
expect 0 mkdir ${n0} 0777
14+
expect 0 chown ${n0} 65534 65534
15+
expect 0 -u 65534 -g 65534 create ${n0}/${n1} 0755
16+
now=`${fstest} stat ${n0} mtime`
17+
hourback=`echo $now-3600 | bc`
18+
halfhourback=`echo $now-1800 | bc`
19+
expect 0 utime ${n0}/${n1} $hourback $halfhourback
20+
#
21+
# not allowed for another user
22+
#
23+
# 5
24+
expect EACCES -u 65533 -g 65533 utime ${n0}/${n1}
25+
expect $hourback stat ${n0}/${n1} atime
26+
expect $halfhourback stat ${n0}/${n1} mtime
27+
expect EACCES -u 65533 -g 65534 utime ${n0}/${n1}
28+
expect $hourback stat ${n0}/${n1} atime
29+
expect $halfhourback stat ${n0}/${n1} mtime
30+
#
31+
# delete
32+
#
33+
# 11
34+
expect 0 chmod ${n0} 0755
35+
expect 0 unlink ${n0}/${n1}
36+
expect 0 rmdir ${n0}

tests/utime/04.t

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
3+
desc="utime returns EPERM when setting non-current time by non-owner"
4+
5+
dir=`dirname $0`
6+
. ${dir}/../misc.sh
7+
8+
echo "1..13"
9+
10+
n0=`namegen`
11+
n1=`namegen`
12+
13+
expect 0 mkdir ${n0} 0777
14+
expect 0 chown ${n0} 65534 65534
15+
expect 0 -u 65534 -g 65534 create ${n0}/${n1} 0755
16+
now=`${fstest} stat ${n0} mtime`
17+
hourback=`echo $now-3600 | bc`
18+
halfhourback=`echo $now-1800 | bc`
19+
expect 0 utime ${n0}/${n1} $hourback $halfhourback
20+
#
21+
# not allowed for another user
22+
#
23+
# 5
24+
expect EPERM -u 65533 -g 65533 utime ${n0}/${n1} $now $now
25+
expect $hourback stat ${n0}/${n1} atime
26+
expect $halfhourback stat ${n0}/${n1} mtime
27+
expect EPERM -u 65533 -g 65534 utime ${n0}/${n1} $now $now
28+
expect $hourback stat ${n0}/${n1} atime
29+
expect $halfhourback stat ${n0}/${n1} mtime
30+
#
31+
# delete
32+
#
33+
# 11
34+
expect 0 chmod ${n0} 0755
35+
expect 0 unlink ${n0}/${n1}
36+
expect 0 rmdir ${n0}

0 commit comments

Comments
 (0)