From d00ed68a8d2735452cbd94344723d4e7e972e9be Mon Sep 17 00:00:00 2001 From: janw Date: Wed, 30 Jan 2008 11:39:05 +0000 Subject: [PATCH] Some more checks for valid input. Capture Device gets saved in ArpHandler hosts_database. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8658 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 29 ++++++++++++++++------------- gosa-si/modules/ArpHandler.pm | 28 +++++++++++++++++----------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 4f298ee03..515fe6ef2 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -332,23 +332,26 @@ sub import_modules { next; } - if( $no_arp > 0 ) { - if( $file =~ /ArpHandler.pm/ ) { - next; - } - } + if( $no_arp > 0 ) { + if( $file =~ /ArpHandler.pm/ ) { + next; + } + } eval { require $file; }; if ($@) { daemon_log("ERROR: gosa-si-server could not load module $file", 1); daemon_log("$@", 5); - } else { - my $mod_name = $1; - my $info = eval($mod_name.'::get_module_info()'); - my ($input_address, $input_key, $input, $input_active, $input_type) = @{$info}; - $known_modules->{$mod_name} = $info; - - daemon_log("module $mod_name loaded", 1); - } + } else { + my $mod_name = $1; + my $info = eval($mod_name.'::get_module_info()'); + + # Only load module if get_module_info() returns a non-null object + if(defined($info)) { + my ($input_address, $input_key, $input, $input_active, $input_type) = @{$info}; + $known_modules->{$mod_name} = $info; + daemon_log("module $mod_name loaded", 1); + } + } } # for debugging diff --git a/gosa-si/modules/ArpHandler.pm b/gosa-si/modules/ArpHandler.pm index d0cba1924..d4e70eaff 100644 --- a/gosa-si/modules/ArpHandler.pm +++ b/gosa-si/modules/ArpHandler.pm @@ -35,7 +35,7 @@ my $hosts_database={}; my $resolver=Net::DNS::Resolver->new; $ldap_base = "dc=gonicus,dc=de" ; -$interface = "all"; +$interface = "eth1"; sub get_module_info { my @info = (undef, @@ -63,6 +63,7 @@ sub get_module_info { } # If device has a valid mac address + # TODO: Check if this should be the right way if(not(&get_mac($device) eq "00:00:00:00:00:00")) { &main::daemon_log("Starting ArpWatch on $device", 1); POE::Session->create( @@ -115,13 +116,15 @@ sub start { } sub got_packet { - my $packet = $_[ARG0]; + my ($kernel, $heap, $sender, $packet) = @_[KERNEL, HEAP, SENDER, ARG0]; if( $packet->{source_haddr} eq "00:00:00:00:00:00" || $packet->{source_haddr} eq "ff:ff:ff:ff:ff:ff" || $packet->{source_ipaddr} eq "0.0.0.0") { return; } + + my $capture_device = sprintf "%s", $kernel->alias_list($sender) =~ /^arp_watch_(.*)$/; if(!exists($hosts_database->{$packet->{source_haddr}})) { my $dnsresult= $resolver->search($packet->{source_ipaddr}); @@ -153,6 +156,7 @@ sub got_packet { ": ".$hosts_database->{$packet->{source_haddr}}->{ipHostNumber}. "/".$hosts_database->{$packet->{source_haddr}}->{macAddress},4); } + $hosts_database->{$packet->{source_haddr}}->{device}= $capture_device; } else { if(!($hosts_database->{$packet->{source_haddr}}->{ipHostNumber} eq $packet->{source_ipaddr})) { &main::daemon_log( @@ -161,7 +165,7 @@ sub got_packet { "->".$packet->{source_ipaddr}, 4); $hosts_database->{$packet->{source_haddr}}->{ipHostNumber}= $packet->{source_ipaddr}; } - &main::daemon_log("Host already in cache (".($hosts_database->{$packet->{source_haddr}}->{dnsname}).")",6); + &main::daemon_log("Host already in cache (".($hosts_database->{$packet->{source_haddr}}->{device})."->".($hosts_database->{$packet->{source_haddr}}->{dnsname}).")",6); } } @@ -175,7 +179,7 @@ sub get_host_from_ldap { "(|(macAddress=$mac)(dhcpHWAddress=ethernet $mac))" ); - if($ldap_result->count==1) { + if(defined($ldap_result) && $ldap_result->count==1) { if(exists($ldap_result->{entries}[0]) && exists($ldap_result->{entries}[0]->{asn}->{objectName}) && exists($ldap_result->{entries}[0]->{asn}->{attributes})) { @@ -368,18 +372,20 @@ sub get_mac { # SEE ALSO: n/a #=============================================================================== sub search_ldap_entry { - my ($ldap_tree, $sub_tree, $search_string) = @_; - my $msg = $ldap_tree->search( # perform a search - base => $sub_tree, - filter => $search_string, - ) or daemon_log("cannot perform search at ldap: $@", 1); + my ($ldap_tree, $sub_tree, $search_string) = @_; + my $msg; + if(defined($ldap_tree)) { + my $msg = $ldap_tree->search( # perform a search + base => $sub_tree, + filter => $search_string, + ) or daemon_log("cannot perform search at ldap: $@", 1); # if(defined $msg) { # print $sub_tree."\t".$search_string."\t"; # print $msg->count."\n"; # foreach my $entry ($msg->entries) { $entry->dump; }; # } - - return $msg; + } + return $msg; } -- 2.30.2