4 sysctl security.mac.portacl >/dev/null 2>&1
6 echo "1..0 # SKIP MAC_PORTACL is unavailable."
9 if [ $(id -u) -ne 0 ]; then
10 echo "1..0 # SKIP testcases must be run as root"
17 local host idtype name proto port udpflag
27 [ "${proto}" = "udp" ] && udpflag="-u"
32 ( echo -n | su -m ${name} -c "nc ${udpflag} -l -w ${timeout} $host $port" 2>&1 ) &
41 echo | nc ${udpflag} -w ${timeout} $host $port >/dev/null 2>&1
45 "nc: Permission denied"*|"nc: Operation not permitted"*)
58 local expect_without_rule expect_with_rule idtype name proto port
60 expect_without_rule=${1}
67 sysctl security.mac.portacl.rules= >/dev/null
68 out=$(check_bind ${idtype} ${name} ${proto} ${port})
69 if [ "${out}" = "${expect_without_rule}" ]; then
71 elif [ "${out}" = "ok" -o "${out}" = "fl" ]; then
72 echo "not ok ${ntest} # '${out}' != '${expect_without_rule}'"
74 echo "not ok ${ntest} # unexpected output: '${out}'"
78 if [ "${idtype}" = "uid" ]; then
79 idstr=$(id -u ${name})
80 elif [ "${idtype}" = "gid" ]; then
81 idstr=$(id -g ${name})
85 sysctl security.mac.portacl.rules=${idtype}:${idstr}:${proto}:${port} >/dev/null
86 out=$(check_bind ${idtype} ${name} ${proto} ${port})
87 if [ "${out}" = "${expect_with_rule}" ]; then
89 elif [ "${out}" = "ok" -o "${out}" = "fl" ]; then
90 echo "not ok ${ntest} # '${out}' != '${expect_with_rule}'"
92 echo "not ok ${ntest} # unexpected output: '${out}'"
96 sysctl security.mac.portacl.rules= >/dev/null
99 reserved_high=$(sysctl -n net.inet.ip.portrange.reservedhigh)
100 suser_exempt=$(sysctl -n security.mac.portacl.suser_exempt)
101 port_high=$(sysctl -n security.mac.portacl.port_high)
104 sysctl -n net.inet.ip.portrange.reservedhigh=${reserved_high} >/dev/null
105 sysctl -n security.mac.portacl.suser_exempt=${suser_exempt} >/dev/null
106 sysctl -n security.mac.portacl.port_high=${port_high} >/dev/null