From: rettenbe Date: Tue, 19 Aug 2008 15:43:44 +0000 (+0000) Subject: bugfix: new_ntp_config, correct handling of incoming message X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=18b2a975835acdce839cee833b3a0d38231f08d6;p=gosa.git bugfix: new_ntp_config, correct handling of incoming message git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12248 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/client/events/corefunctions.pm b/gosa-si/client/events/corefunctions.pm index 4f5bd3629..f74f595d7 100644 --- a/gosa-si/client/events/corefunctions.pm +++ b/gosa-si/client/events/corefunctions.pm @@ -159,7 +159,7 @@ sub server_leaving { # @param msg_hash - HASHREF - message information parsed into a hash sub new_ntp_config { my ($msg, $msg_hash) = @_ ; - + # Sanity check of incoming message if ((not exists $msg_hash->{'server'}) || (not @{$msg_hash->{'server'}} >= 1) ) { &main::daemon_log("ERROR: 'new_ntp_config'-message does not contain a ntp server: $msg", 1); @@ -167,13 +167,21 @@ sub new_ntp_config { } # Fetch the new ntp server from incoming message - my @ntp_servers = $msg_hash->{'server'}; - my $ntp_servers_string = "server\t".join("\nserver\t", @ntp_servers)."\n"; + my $ntp_servers = $msg_hash->{'server'}; + &main::daemon_log("INFO: found ntp server: ".join(", ", @$ntp_servers), 5); + my $ntp_servers_string = "server\t".join("\nserver\t", @$ntp_servers)."\n"; my $found_server_flag = 0; + # Sanity check of /etc/chrony/chrony.conf + if (not -f $chrony_file) { + &main::daemon_log("ERROR: file '$chrony_file' does not exist, cannot do ntp reconfiguration!", 1); + return; + } + # Substitute existing server with new ntp server - open (FILE, "+<$chrony_file"); + open (FILE, "<$chrony_file"); my @file = ; + close FILE; foreach my $line (@file) { if ($line =~ /^server /) { if ($found_server_flag) { @@ -192,6 +200,7 @@ sub new_ntp_config { } # Write changes to file and close it + open (FILE, "+>$chrony_file"); print FILE join("", @file); close FILE; &main::daemon_log("INFO: wrote new configuration file: $chrony_file", 5); diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index d4ec76321..270cda8ab 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -509,6 +509,7 @@ sub here_i_am { push(@out_msg_l, $new_ldap_config_out); } + # Send client hardware configuration my $hardware_config_out = &hardware_config($msg, $msg_hash, $session_id); if( $hardware_config_out ) { push(@out_msg_l, $hardware_config_out); @@ -516,7 +517,10 @@ sub here_i_am { # Send client ntp server - + my $ntp_config_out = &new_ntp_config($mac_address, $session_id); + if ($ntp_config_out) { + push(@out_msg_l, $ntp_config_out); + } # notify registered client to all other server my %mydata = ( 'client' => $source, 'macaddress' => $mac_address); @@ -610,7 +614,7 @@ sub new_ntp_config { } my $entry= $ldap_res->entry(0); - my $dn= $entry->dn; + my $dn = &Net::LDAP::Util::escape_dn_value($entry->dn); my @ntp_servers= $entry->get_value("gotoNtpServer"); # If no ntp server is specified at host, just have a look at the object group of the host @@ -737,11 +741,12 @@ sub new_ldap_config { } # Sanity check - if ($mesg->count == 0) { - &main::daemon_log("$session_id WARNING: no LDAP informations found for client with filter '(&(objectClass=gosaGroupOfNames)(member=$dn))'", 3); - return; - } elsif ($mesg->count >= 2) { - &main::daemon_log("$session_id ERROR: multiple LDAP informations found for client with filter '(&(objectClass=gosaGroupOfNames)(member=$dn))'", 1); + if ($mesg->count != 1) { + &main::daemon_log("$session_id ERROR: client with mac address $macaddress not found/unique/active - not sending ldap config". + "\n\tbase: $ldap_base". + "\n\tscope: sub". + "\n\tattrs: dn, gotoLdapServer, FAIclass". + "\n\tfilter: (&(objectClass=gosaGroupOfNames)(member=$escaped_dn))", 1); return; } @@ -761,7 +766,7 @@ sub new_ldap_config { # complain if no ldap information found if (@servers == 0) { - &main::daemon_log("$session_id ERROR: no gotoLdapServer information for LDAP entry with filter '(&(objectClass=gosaGroupOfNames)(member=$dn))'"); + &main::daemon_log("$session_id ERROR: no gotoLdapServer information for LDAP entry '$dn'", 1); } foreach $server (@servers){ diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 158da47ac..772cc39f6 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -189,8 +189,7 @@ for($count = 1; $count <= $zahl; $count++) ############################## # NTP reload - #$data = "
gosa_trigger_reload_ntp_config
GOSA GOSA 00:11:25:4B:8C:E5
"; - $data = "
gosa_trigger_reload_ntp_config
GOSA GOSA 00:01:6c:9d:b9:fa
"; + $data = "
gosa_trigger_reload_ntp_config
GOSA GOSA 00:11:25:4B:8C:E5
"; $sock->write($data); $answer = "nothing";