From 4747253f1f399b2718b08de320c726ab92b5cb38 Mon Sep 17 00:00:00 2001 From: psc Date: Tue, 13 Mar 2012 14:51:23 +0000 Subject: [PATCH] Fix #6643: Backport IP update from gosa-si 2.7 git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@21117 594d385d-05f5-0310-b6e9-bd551577e9d8 --- trunk/gosa-si/modules/ClientPackages.pm | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/trunk/gosa-si/modules/ClientPackages.pm b/trunk/gosa-si/modules/ClientPackages.pm index 622c8e427..65d36e9da 100644 --- a/trunk/gosa-si/modules/ClientPackages.pm +++ b/trunk/gosa-si/modules/ClientPackages.pm @@ -535,6 +535,44 @@ sub here_i_am { if ($syslog_config_out) { push(@out_msg_l, $syslog_config_out); } + + # Backported from GOsa SI 2.7: update ldap entry if exists + my $ldap_handle = &main::get_ldap_handle($session_id); + if( not defined $ldap_handle ) { + &main::daemon_log("$session_id ERROR: cannot connect to ldap: $ldap_uri", 1); + return; + } + + my $ldap_res= $ldap_handle->search( + base => $ldap_base, + scope => 'sub', + #attrs => ['ipHostNumber'], + filter => "(&(objectClass=GOhard)(macAddress=$mac_address))"); + if($ldap_res->code) { + &main::daemon_log("$session_id ERROR: LDAP Entry for client with mac address $mac_address not found: ".$ldap_res->error, 1); + } elsif ($ldap_res->count != 1) { + &main::daemon_log("$session_id WARNING: client with mac address $mac_address not found/unique/active - not updating ldap entry". + "\n\tbase: $ldap_base". + "\n\tscope: sub". + "\n\tattrs: ipHostNumber". + "\n\tfilter: (&(objectClass=GOhard)(macaddress=$mac_address))", 1); + } else { + my $entry= $ldap_res->pop_entry(); + my $ip_address= $entry->get_value('ipHostNumber'); + my $source_ip= ($1) if $source =~ /^([0-9\.]*?):[0-9]*$/; + if(not defined($ip_address) and defined($source_ip)) { + $entry->add( 'ipHostNumber' => $source_ip ); + my $mesg= $entry->update($ldap_handle); + $mesg->code && &main::daemon_log("$session_id ERROR: Updating IP Address for client with mac address $mac_address failed with '".$mesg->mesg()."'", 1); + } elsif(defined($source_ip) and not ($source_ip eq $ip_address)) { + $entry->replace( 'ipHostNumber' => $source_ip ); + my $mesg= $entry->update($ldap_handle); + $mesg->code && &main::daemon_log("$session_id ERROR: Updating IP Address for client with mac address $mac_address failed with '".$mesg->mesg()."'", 1); + } elsif (not defined($source_ip)) { + &main::daemon_log("ERROR: Could not parse source value '$source' perhaps not an ip address?", 1); + } + } + # notify registered client to all other server my %mydata = ( 'client' => $source, 'macaddress' => $mac_address); -- 2.30.2