xref: /freebsd/contrib/pjdfstest/tests/utimensat/07.t (revision ccb59683b98360afaf5b5bb641a68fea22c68d0b)
1#! /bin/sh
2# vim: filetype=sh noexpandtab ts=8 sw=8
3# $FreeBSD$
4
5desc="utimensat will work if the caller is the owner or root"
6
7dir=`dirname $0`
8. ${dir}/../misc.sh
9
10require "utimensat"
11
12echo "1..17"
13
14n0=`namegen`
15n1=`namegen`
16DATE1=1900000000 #Sun Mar 17 11:46:40 MDT 2030
17DATE2=1950000000 #Fri Oct 17 04:40:00 MDT 2031
18UID_NOBODY=`id -u nobody`
19GID_NOBODY=`id -g nobody`
20UID_ROOT=`id -u root`
21GID_ROOT=`id -g root`
22
23expect 0 mkdir ${n1} 0755
24cdir=`pwd`
25cd ${n1}
26
27create_file regular ${n0} 0644 $UID_ROOT $GID_ROOT
28# First check that nobody can't update the timestamps
29expect EPERM -u $UID_NOBODY open . O_RDONLY : utimensat 0 ${n0} 0 UTIME_OMIT $DATE2 0 0
30expect EPERM -u $UID_NOBODY open . O_RDONLY : utimensat 0 ${n0} $DATE1 0 0 UTIME_OMIT 0
31expect EPERM -u $UID_NOBODY open . O_RDONLY : utimensat 0 ${n0} $DATE1 0 $DATE2 0 0
32
33# Now check that a nonowner with write permission can't update the timestamps
34expect 0 chmod ${n0} 0666
35expect EPERM -u $UID_NOBODY open . O_RDONLY : utimensat 0 ${n0} 0 UTIME_OMIT $DATE2 0 0
36expect EPERM -u $UID_NOBODY open . O_RDONLY : utimensat 0 ${n0} $DATE1 0 0 UTIME_OMIT 0
37expect EPERM -u $UID_NOBODY open . O_RDONLY : utimensat 0 ${n0} $DATE1 0 $DATE2 0 0
38
39# Now check that the owner can update the timestamps
40expect 0 chown ${n0} $UID_NOBODY $GID_NOBODY
41expect 0 chmod ${n0} 0444
42expect 0 -u $UID_NOBODY open . O_RDONLY : utimensat 0 ${n0} $DATE1 0 $DATE2 0
43
44# Now check that the superuser can update the timestamps
45expect 0 -u $UID_ROOT open . O_RDONLY : utimensat 0 ${n0} $DATE1 0 $DATE2 0 0
46
47
48expect 0 unlink ${n0}
49
50cd ${cdir}
51expect 0 rmdir ${n1}
52