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