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
26 [ "${proto}" = "udp" ] && udpflag="-u"
31 ( echo -n | su -m ${name} -c "nc ${udpflag} -l -w 10 $host $port" 2>&1 ) &
40 echo | nc ${udpflag} -w 10 $host $port >/dev/null 2>&1
44 "nc: Permission denied"*|"nc: Operation not permitted"*)
57 local expect_without_rule expect_with_rule idtype name proto port
59 expect_without_rule=${1}
66 sysctl security.mac.portacl.rules= >/dev/null
67 out=$(check_bind ${idtype} ${name} ${proto} ${port})
68 if [ "${out}" = "${expect_without_rule}" ]; then
70 elif [ "${out}" = "ok" -o "${out}" = "fl" ]; then
71 echo "not ok ${ntest} # '${out}' != '${expect_without_rule}'"
73 echo "not ok ${ntest} # unexpected output: '${out}'"
77 if [ "${idtype}" = "uid" ]; then
78 idstr=$(id -u ${name})
79 elif [ "${idtype}" = "gid" ]; then
80 idstr=$(id -g ${name})
84 sysctl security.mac.portacl.rules=${idtype}:${idstr}:${proto}:${port} >/dev/null
85 out=$(check_bind ${idtype} ${name} ${proto} ${port})
86 if [ "${out}" = "${expect_with_rule}" ]; then
88 elif [ "${out}" = "ok" -o "${out}" = "fl" ]; then
89 echo "not ok ${ntest} # '${out}' != '${expect_with_rule}'"
91 echo "not ok ${ntest} # unexpected output: '${out}'"
95 sysctl security.mac.portacl.rules= >/dev/null
98 reserved_high=$(sysctl -n net.inet.ip.portrange.reservedhigh)
99 suser_exempt=$(sysctl -n security.mac.portacl.suser_exempt)
100 port_high=$(sysctl -n security.mac.portacl.port_high)
103 sysctl -n net.inet.ip.portrange.reservedhigh=${reserved_high} >/dev/null
104 sysctl -n security.mac.portacl.suser_exempt=${suser_exempt} >/dev/null
105 sysctl -n security.mac.portacl.port_high=${port_high} >/dev/null