#! /bin/bash

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

require_runas
require_richacls
use_testdir

export LC_ALL=C

ncheck "touch a b c d e f"
ncheck "setrichacl --set 'owner@:rwp::allow' a"
ncheck "setrichacl --set 'owner@:rwp::allow u:99:w::allow' b"
ncheck "setrichacl --set 'owner@:rwp::allow u:99:p::allow' c"
ncheck "setrichacl --set 'owner@:rwp::allow u:99:wp::allow' d"
ncheck "setrichacl --set 'u:99:a::deny owner@:rwp::allow u:99:w::allow' e"
ncheck "setrichacl --set 'u:99:w::deny owner@:rwp::allow u:99:p::allow' f"

runas -u 99 -g 99
check "sh -c 'echo a > a' || :" <<EOF
sh: a: Permission denied
EOF
ncheck "sh -c 'echo b > b' || :"
check "sh -c 'echo c > c' || :" <<EOF
sh: c: Permission denied
EOF
ncheck "sh -c 'echo d > d' || :"
ncheck "sh -c 'echo e > e' || :"
check "sh -c 'echo f > f' || :" <<EOF
sh: f: Permission denied
EOF

check "sh -c 'echo A >> a' || :" <<EOF
sh: a: Permission denied
EOF
check "sh -c 'echo B >> b' || :" <<EOF
sh: b: Permission denied
EOF
ncheck "sh -c 'echo C >> c' || :"
ncheck "sh -c 'echo D >> d' || :"
check "sh -c 'echo E >> e' || :" <<EOF
sh: e: Permission denied
EOF
ncheck "sh -c 'echo F >> f' || :"

runas
check "cat a b c d e f" <<EOF
b
C
d
D
e
F
EOF
