From: janw Date: Mon, 11 Feb 2008 10:37:52 +0000 (+0000) Subject: Added the ip check from the server to the bus. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d2d3cf519c7f06913f2f4b50f0c38e8ebfe891c5;p=gosa.git Added the ip check from the server to the bus. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8821 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/gosa-si-bus b/gosa-si/gosa-si-bus index b7711101e..f920f5a5b 100755 --- a/gosa-si/gosa-si-bus +++ b/gosa-si/gosa-si-bus @@ -406,6 +406,50 @@ sub get_local_mac_for_remote_ip { return $result; } +sub bus_matches { + my $target = shift; + my $target_ip = sprintf("%s", $target =~ /^([0-9\.]*?):.*$/); + my $result = 0; + + if($bus_ip eq $target_ip) { + $result= 1; + } elsif ($bus_ip eq "0.0.0.0") { + if ($target_ip eq "127.0.0.1") { + $result= 1; + } else { + my $PROC_NET_ROUTE= ('/proc/net/route'); + + open(PROC_NET_ROUTE, "<$PROC_NET_ROUTE") + or die "Could not open $PROC_NET_ROUTE"; + + my @ifs = ; + + close(PROC_NET_ROUTE); + + # Eat header line + shift @ifs; + chomp @ifs; + foreach my $line(@ifs) { + my ($Iface,$Destination,$Gateway,$Flags,$RefCnt,$Use,$Metric,$Mask,$MTU,$Window,$IRTT)=split(/\s/, $line); + my $destination; + my $mask; + my ($d,$c,$b,$a)=unpack('a2 a2 a2 a2', $Destination); + $destination= sprintf("%d.%d.%d.%d", hex($a), hex($b), hex($c), hex($d)); + ($d,$c,$b,$a)=unpack('a2 a2 a2 a2', $Mask); + $mask= sprintf("%d.%d.%d.%d", hex($a), hex($b), hex($c), hex($d)); + if(new NetAddr::IP($target_ip)->within(new NetAddr::IP($destination, $mask))) { + # destination matches route, save mac and exit + $result= 1; + last; + } + } + } + } else { + &main::daemon_log("Target ip $target_ip does not match bus ip $bus_ip",1); + } + + return $result; +} #=== FUNCTION ================================================================ # NAME: create_passwd @@ -722,7 +766,7 @@ sub bus_input { my $target_string = join(",", @target_l); daemon_log("got msg '$header' with target '$target_string' from ".$heap->{'remote_ip'}, 3); - if( 1 == length(@target_l) && $target_l[0] eq $bus_address ) { + if( 1 == length(@target_l) && &bus_matches($target_l[0]) ) { # msg is for bus #print STDERR "msg is for bus\n"; $kernel->post('gosa_si_bus_session', $header, $msg, $msg_hash);