/[suikacvs]/messaging/manakai/lib/Message/Util/HostPermit.pm
Suika

Diff of /messaging/manakai/lib/Message/Util/HostPermit.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by wakaba, Sat Sep 27 07:59:11 2003 UTC revision 1.3 by wakaba, Fri Oct 31 08:39:50 2003 UTC
# Line 46  sub add_rule ($$) { Line 46  sub add_rule ($$) {
46    
47  sub check ($$;$) {  sub check ($$;$) {
48    my ($self, $name, $port) = @_;    my ($self, $name, $port) = @_;
49    my ($name, undef, undef, undef, $addr) = gethostbyname ($name);    return 0 unless defined $name;
50      my $addr;
51      ($name, undef, undef, undef, $addr) = gethostbyname ($name);
52    return 0 if !$name && !$addr;    return 0 if !$name && !$addr;
53    for my $rule (@{$self->{rule}}) {    for my $rule (@{$self->{rule}}) {
54      if ($rule->{-host}) {      if ($rule->{-host}) {
# Line 94  sub match_host ($$$) { Line 96  sub match_host ($$$) {
96  sub match_ipv4 ($$$) {  sub match_ipv4 ($$$) {
97    my ($self, $pattern, $addr) = @_;    my ($self, $pattern, $addr) = @_;
98    if (length ($addr) != 4) {    if (length ($addr) != 4) {
99      $addr =~ /([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/;      $addr =~ /([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/ or return 0;
100      $addr = pack 'C4', $1, $2, $3, $4;      $addr = pack 'C4', $1, $2, $3, $4;
101    }    }
102    my $mask = pack 'C4', 255, 255, 255, 255;    my $mask = pack 'C4', 255, 255, 255, 255;
103    if (length ($pattern) != 4) {    if (length ($pattern) != 4) {
104      $pattern =~ m!([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)(?:/([0-9]+))?!;      $pattern =~ m!([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)(?:/([0-9]+))?!
105          or return 0;
106      $pattern = pack 'C4', $1, $2, $3, $4;      $pattern = pack 'C4', $1, $2, $3, $4;
107      my $m = $5; $m = 32 if $m > 32;      my $m = $5;
108      if (defined $m) {      if (defined $m) {
109          $m = $m > 32 ? 32 : $m + 0;
110        $mask = pack 'C4', (($m > 24) ? (255, 255, 255, (2**($m-24)-1) << (32-$m)) :        $mask = pack 'C4', (($m > 24) ? (255, 255, 255, (2**($m-24)-1) << (32-$m)) :
111                            ($m > 16) ? (255, 255, (2**($m-16)-1) << (24-$m), 0) :                            ($m > 16) ? (255, 255, (2**($m-16)-1) << (24-$m), 0) :
112                            ($m >  8) ? (255, (2**($m-8)-1) << (16-$m), 0, 0) :                            ($m >  8) ? (255, (2**($m-8)-1) << (16-$m), 0, 0) :

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24