From: janw Date: Wed, 24 Jun 2009 15:04:40 +0000 (+0000) Subject: Update ipHostNumber of client if needed. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=39819b3e7a87ff23a3da8aaf66478bb2c8fe9132;p=gosa.git Update ipHostNumber of client if needed. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13788 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index 1db6d0193..100e0281b 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -513,7 +513,6 @@ sub here_i_am { # return acknowledgement to client $out_hash = &create_xml_hash("registered", $server_address, $source); - # give the new client his ldap config # Workaround: Send within the registration response, if the client will get an ldap config later my $new_ldap_config_out = &new_ldap_config($source, $session_id); @@ -554,6 +553,39 @@ sub here_i_am { push(@out_msg_l, $syslog_config_out); } + # update ldap entry if exists + my $ldap_handle= &main::get_ldap_handle(); + 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 ERROR: 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); + } + } + &main::release_ldap_handle($ldap_handle); + # notify registered client to all other server my %mydata = ( 'client' => $source, 'macaddress' => $mac_address); my $mymsg = &build_msg('new_foreign_client', $main::server_address, "KNOWN_SERVER", \%mydata);