index 9a4b6657a07ea15af431a7288dedd4f1d7fc493a..1b0997dd2453e6273c89cb38df472860de192891 100644 (file)
use Net::DNS;
use Switch;
use Data::Dumper;
-use utf8;
+use Socket;
# Don't start if some of the modules are missing
my $start_service=1;
my ($timeout, $mailto, $mailfrom, $user, $group);
my ($arp_enabled, $arp_interface, $ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password);
my $hosts_database={};
-my $resolver=Net::DNS::Resolver->new;
my $ldap;
my %cfg_defaults =
#===============================================================================
sub read_configfile {
my $cfg;
- if( defined( $main::cfg_file) && ( length($main::cfg_file) > 0 )) {
+ if( defined( $main::cfg_file) && ( (-s $main::cfg_file) > 0 )) {
if( -r $main::cfg_file ) {
$cfg = Config::IniFiles->new( -file => $main::cfg_file );
} else {
&main::daemon_log("Loading OUI cache file suceeded!", 6);
}
}
- if(defined($ldap_uri) && length($ldap_uri)>0) {
- $ldap = Net::LDAP->new($ldap_uri);
- if (!$ldap) {
- &main::daemon_log("Could not connect to LDAP Server at $ldap_uri!\n$@", 1);
- } else {
- $ldap->bind($ldap_admin_dn, password => $ldap_admin_password);
- }
- } else {
- $ldap=undef;
- }
+ my $ldap_handle = &main::get_ldap_handle();
# When interface is not configured (or 'all'), start arpwatch on all possible interfaces
if ((!defined($arp_interface)) || $arp_interface eq 'all') {
&start(@_,$device);
},
_stop => sub {
- $ldap->unbind if (defined($ldap));
- $ldap->disconnect if (defined($ldap));
$_[KERNEL]->post( sprintf("arp_watch_$device") => 'shutdown' )
},
got_packet => \&got_packet,
&start(@_,$device);
},
_stop => sub {
- $ldap->unbind if (defined($ldap));
- $ldap->disconnect if (defined($ldap));
$_[KERNEL]->post( sprintf("arp_watch_$device") => 'shutdown' )
},
got_packet => \&got_packet,
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});
- my $dnsname= (defined($dnsresult))?$dnsresult->{answer}[0]->{ptrdname}:$packet->{source_ipaddr};
+ my $ldap_handle = &main::get_ldap_handle();
+ if(!exists($hosts_database->{$packet->{source_haddr}})) {
+ my $dnsname= gethostbyaddr(inet_aton($packet->{source_ipaddr}), AF_INET) || $packet->{source_ipaddr};
my $ldap_result=&get_host_from_ldap($packet->{source_haddr});
if(exists($ldap_result->{dn})) {
$hosts_database->{$packet->{source_haddr}}=$ldap_result;
": ".$hosts_database->{$packet->{source_haddr}}->{ipHostNumber}.
"/".$hosts_database->{$packet->{source_haddr}}->{macAddress},4);
&add_ldap_entry(
- $ldap,
+ $ldap_handle,
$ldap_base,
$hosts_database->{$packet->{source_haddr}}->{macAddress},
'new-system',
"->".$packet->{source_ipaddr}, 4);
$hosts_database->{$packet->{source_haddr}}->{ipHostNumber}= $packet->{source_ipaddr};
&change_ldap_entry(
- $ldap,
+ $ldap_handle,
$ldap_base,
$hosts_database->{$packet->{source_haddr}}->{macAddress},
'ip-changed',
my $mac=shift;
my $result={};
- if(defined($ldap)) {
+ my $ldap_handle = &main::get_ldap_handle();
+ if(defined($ldap_handle)) {
my $ldap_result= &search_ldap_entry(
- $ldap,
+ $ldap_handle,
$ldap_base,
"(|(macAddress=$mac)(dhcpHWAddress=ethernet $mac))"
);
if (defined($ip)) {
$replace->{'ipHostNumber'} = $ip;
}
- my $result = $ldap->modify( $dn, replace => $replace );
+ my $result = $ldap_tree->modify( $dn, replace => $replace );
# for $result->code constants please look at Net::LDAP::Constant
if($result->code == 32) { # entry doesnt exists