From d9eeaa2981dd62dc189e9172339f3ef2ef0d58e6 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Wed, 6 Feb 2008 15:04:04 +0000 Subject: [PATCH] bugfix: bus - server - client communication git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8759 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-bus | 18 ++++-- gosa-si/gosa-si-client | 3 - gosa-si/gosa-si-server | 123 +++++++++++++++++++++-------------------- 3 files changed, 75 insertions(+), 69 deletions(-) diff --git a/gosa-si/gosa-si-bus b/gosa-si/gosa-si-bus index e69560e55..f07bf9e6a 100755 --- a/gosa-si/gosa-si-bus +++ b/gosa-si/gosa-si-bus @@ -108,7 +108,7 @@ sub daemon_log { chomp($msg); if($level && $verbose && $level <= $verbose){ print LOG_HANDLE $msg."\n"; - if(defined $foreground) { print $msg."\n" } + if(defined $foreground) { print STDERR $msg."\n" } } } close( LOG_HANDLE ); @@ -903,12 +903,18 @@ sub new_client { my $clients = $res->{1}->{clients}; # if host has alread more clients, than just append - if( length($clients) != 0 ) { - $clients .= ",$new_client"; - } else { - $clients = $new_client; + my @clients_l = split(',', $clients); + my @new_clients_l; + foreach my $act_client (@clients_l) { + if( $new_client eq $act_client ) { + # do nothing + next; + } + push(@new_clients_l, $act_client); } - + push(@new_clients_l, $new_client); + $clients = join(",", @new_clients_l); + $sql_statement= "UPDATE bus_known_server SET clients='$clients' WHERE hostname='$source'"; $bus_known_server_db->update_dbentry( $sql_statement ); return; diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index f89ef60b2..fd36a5bbf 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -1019,13 +1019,10 @@ sub server_input { } # postprocessing if( $answer =~ "
new_key
") { -print STDERR "old key: $server_key\n"; # set new key to global variable $answer =~ /(\S*?)<\/new_key>/; my $new_key = $1; $server_key = $new_key; -print STDERR "new key: $new_key\n"; - } } diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 777e5feee..a3764f4cd 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -744,72 +744,75 @@ sub client_input { # for each answer in answer list foreach my $answer ( @{$answer_l} ) { + + + + + my $error = 0; # check answer if gosa-si envelope conform - if( $error == 0 ) { - my $answer_hash = $xml->XMLin($answer, ForceArray=>1); - $answer_header = @{$answer_hash->{'header'}}[0]; - @answer_target_l = @{$answer_hash->{'target'}}; - $answer_source = @{$answer_hash->{'source'}}[0]; - if( !$answer_header ) { - daemon_log('ERROR: module answer is not gosa-si envelope conform: no header', 1); - daemon_log("\n$answer", 8); - $error++; - } - if( 0 == length @answer_target_l ) { - daemon_log('ERROR: module answer is not gosa-si envelope conform: no targets', 1); - daemon_log("\n$answer", 8); - $error++; - } - if( !$answer_source ) { - daemon_log('ERROR: module answer is not gosa-si envelope conform: no source', 1); - daemon_log("\n$answer", 8); - $error++; - } + my $answer_hash = $xml->XMLin($answer, ForceArray=>1); + $answer_header = @{$answer_hash->{'header'}}[0]; + @answer_target_l = @{$answer_hash->{'target'}}; + $answer_source = @{$answer_hash->{'source'}}[0]; + if( !$answer_header ) { + daemon_log('ERROR: module answer is not gosa-si envelope conform: no header', 1); + daemon_log("\n$answer", 8); + $error++; + } + if( 0 == length @answer_target_l ) { + daemon_log('ERROR: module answer is not gosa-si envelope conform: no targets', 1); + daemon_log("\n$answer", 8); + $error++; + } + if( !$answer_source ) { + daemon_log('ERROR: module answer is not gosa-si envelope conform: no source', 1); + daemon_log("\n$answer", 8); + $error++; + } - if( $error != 0 ) { - next; - } + if( $error != 0 ) { + next; + } - # deliver msg to all targets - foreach my $answer_target ( @answer_target_l ) { - if( $answer_target eq "*" ) { - # answer is for all clients - my $sql_statement= "SELECT * FROM known_clients"; - my $query_res = $known_clients_db->select_dbentry( $sql_statement ); - while( my ($hit_num, $hit) = each %{ $query_res } ) { - my $host_name = $hit->{hostname}; - my $host_key = $hit->{hostkey}; - &send_msg_to_target($answer, $host_name, $host_key, $answer_header); - } + # deliver msg to all targets + foreach my $answer_target ( @answer_target_l ) { + if( $answer_target eq "*" ) { + # answer is for all clients + my $sql_statement= "SELECT * FROM known_clients"; + my $query_res = $known_clients_db->select_dbentry( $sql_statement ); + while( my ($hit_num, $hit) = each %{ $query_res } ) { + my $host_name = $hit->{hostname}; + my $host_key = $hit->{hostkey}; + &send_msg_to_target($answer, $host_name, $host_key, $answer_header); } - elsif( $answer_target eq "GOSA" ) { - # answer is for GOSA and has to returned to connected client - my $gosa_answer = &encrypt_msg($answer, $GosaPackages_key); - $client_answer = $gosa_answer; - } - elsif( $answer_target eq "KNOWN_SERVER" ) { - # answer is for all server in known_server - my $sql_statement= "SELECT * FROM known_server"; - my $query_res = $known_server_db->select_dbentry( $sql_statement ); - while( my ($hit_num, $hit) = each %{ $query_res } ) { - my $host_name = $hit->{hostname}; - my $host_key = $hit->{hostkey}; - $answer =~ s/KNOWN_SERVER/$host_name/g; - &send_msg_to_target($answer, $host_name, $host_key, $answer_header); - } + } + elsif( $answer_target eq "GOSA" ) { + # answer is for GOSA and has to returned to connected client + my $gosa_answer = &encrypt_msg($answer, $GosaPackages_key); + $client_answer = $gosa_answer; + } + elsif( $answer_target eq "KNOWN_SERVER" ) { + # answer is for all server in known_server + my $sql_statement= "SELECT * FROM known_server"; + my $query_res = $known_server_db->select_dbentry( $sql_statement ); + while( my ($hit_num, $hit) = each %{ $query_res } ) { + my $host_name = $hit->{hostname}; + my $host_key = $hit->{hostkey}; + $answer =~ s/KNOWN_SERVER/$host_name/g; + &send_msg_to_target($answer, $host_name, $host_key, $answer_header); } - else { - # answer is for one specific host - # get encrypt_key - my $encrypt_key = &get_encrypt_key($answer_target); - if( !$encrypt_key ) { - daemon_log("ERROR: no encrypt key found for answer target '$answer_target'", 1); - daemon_log("\n$answer", 8); - next; - } - # send_msg - &send_msg_to_target($answer, $answer_target, $encrypt_key, $answer_header); + } + else { + # answer is for one specific host + # get encrypt_key + my $encrypt_key = &get_encrypt_key($answer_target); + if( !$encrypt_key ) { + daemon_log("ERROR: no encrypt key found for answer target '$answer_target'", 1); + daemon_log("\n$answer", 8); + next; } + # send_msg + &send_msg_to_target($answer, $answer_target, $encrypt_key, $answer_header); } } } -- 2.30.2