#! /bin/bash

. ${0%/*}/test-lib.sh

require_runas
require_richacls
use_testdir

export LC_ALL=C

# Create file as root
ncheck "touch a"

# We cannot set the acl as another user
runas -u 99 -g 99
check "setrichacl --set 'u:99:rwc::allow' a || echo status: \$?" <<EOF
a: Operation not permitted
status: 1
EOF

# We cannot chmod as another user
check "chmod 666 a || echo status: \$?" <<EOF
chmod: changing permissions of 'a': Operation not permitted
status: 1
EOF

# Give user 99 the write_acl permission
runas
ncheck "setrichacl --set 'u:99:rwpC::allow' a"

# Now user 99 can setrichacl and chmod ...
runas -u 99 -g 99
ncheck "setrichacl --set 'u:99:rwpC::allow' a"
ncheck "chmod 666 a"

# ... but chmod disables the write_acl permission
check "setrichacl --set 'u:99:rwpC::allow' a || echo status: \$?" <<EOF
a: Operation not permitted
status: 1
EOF
