2) { $rule = strtolower(trim($tmp[$size-1])); $rule = preg_match("/^(allow|deny)$/",$rule) ? $rule : $baserule; } else $rule = $baserule; ## check daemon list ## if($daemon && $daemon!='ALL') { list($dmatch,$dexcept) = tcpwrap::__get_matchlist(strtoupper($dlists)); if($dexcept && in_array($daemon,$dexcept)) continue; if(!in_array('ALL',$dmatch) && !in_array($daemon,$dmatch)) continue; } list($match,$except) = tcpwrap::__get_matchlist($clists); if($except && tcpwrap::__ipmatch($client,$except)) continue; if(tcpwrap::__ipmatch($client,$match)) { $r = $rule; break; } $pline = ''; } @fclose($fp); return $r ? $r : FALSE; } ## private, get daemon list ## function &__get_matchlist($str) { $rr = $ee = array(); $arr = explode(',',preg_replace('/[\s]+/',' ',$str)); foreach($arr AS $v) { list($u,$e) = explode('EXCEPT',trim($v)); $rr = array_merge($rr, explode(' ',trim($u))); if($e) $ee = array_merge($ee, explode(' ',trim($e))); } return array($rr,$ee); } function &__ipmatch($ip, $arr) { if(!is_array($arr)) $arr = array($arr); if(in_array($ip,$arr)) return TRUE; $ipbit = tcpwrap::inet_atob($ip); foreach($arr AS $v) { if($v == 'ALL') { return TRUE; break; } else if(preg_match(';/;',$v)) // network/netmask { list($net,$mask) = explode('/',$v); $mbit = tcpwrap::inet_atob($mask); $unet = ($ipbit & $mbit); $unet = tcpwrap::inet_btoa("$unet"); // required double quota " if($unet == $net) { return TRUE; break; } } else if(preg_match(';\.$;',$v)) { if(preg_match("/^$v/",$ip)) // $v = str_replace('.','\.',$v); { return TRUE; break; } } } return; // false } ## check /etc/hosts hosts ## such as getent ## function &__getent_hosts($ipaddr) { return; } function &inet_atob($ipaddr) { return sprintf('%032b',ip2long($ipaddr)); } function &inet_btoa($bits) { return long2ip(bindec("$bits")); } } // eof clss ## EOF ?>