From: rettenbe Date: Tue, 12 Feb 2008 14:59:45 +0000 (+0000) Subject: in case of --no-bus, server do not try to forward msg with unknown target address... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b46111ddcdc96b85b9a0e4f965e4a0114eb150a7;p=gosa.git in case of --no-bus, server do not try to forward msg with unknown target address to bus git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8874 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index bdc990bea..e4df616d2 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -46,7 +46,7 @@ my $modules_path = "/usr/lib/gosa-si/modules"; use lib "/usr/lib/gosa-si/modules"; my (%cfg_defaults, $foreground, $verbose, $ping_timeout); -my ($bus, $msg_to_bus, $bus_cipher); +my ($bus_activ, $bus, $msg_to_bus, $bus_cipher); my ($server, $server_mac_address); my ($gosa_server, $job_queue_timeout, $job_queue_table_name, $job_queue_file_name,$job_queue_loop_delay); my ($known_modules, $known_clients_file_name, $known_server_file_name); @@ -81,6 +81,7 @@ $foreground = 0 ; $ping_timeout = 5; $no_bus = 0; +$bus_activ = "true"; $no_arp = 0; @@ -99,6 +100,9 @@ our $known_clients_db; "log-file" => [\$log_file, "/var/run/".$0.".log"], "pid-file" => [\$pid_file, "/var/run/".$0.".pid"], }, +"bus" => { + "activ" => [\$bus_activ, "true"], + }, "server" => { # "ip" => [\$server_ip, "0.0.0.0"], "port" => [\$server_port, "20081"], @@ -857,106 +861,112 @@ 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(defined($answer)) { - 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; - } - } + my $error = 0; + # check answer if gosa-si envelope conform + if(defined($answer)) { + 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++; + } - # 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 =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i ) { - daemon_log("target is mac address '$answer_target', looking for host in known_clients", 3); - my $sql_statement = "SELECT * FROM known_clients WHERE macaddress='$answer_target'"; - my $query_res = $known_clients_db->select_dbentry( $sql_statement ); - my $found_ip_flag = 0; - while( my ($hit_num, $hit) = each %{ $query_res } ) { - my $host_name = $hit->{hostname}; - my $host_key = $hit->{hostkey}; - $answer =~ s/$answer_target/$host_name/g; - daemon_log("found host '$host_name', assoziated to '$answer_target'", 3); - &send_msg_to_target($answer, $host_name, $host_key, $answer_header); - $found_ip_flag++ ; - } - if( $found_ip_flag == 0) { - daemon_log("WARNING: no host found in known_clients with mac address '$answer_target', forward msg to bus", 1); - my $sql_statement = "SELECT * FROM known_server WHERE hostname='$bus_address'"; - my $query_res = $known_server_db->select_dbentry( $sql_statement ); - while( my ($hit_num, $hit) = each %{ $query_res } ) { - my $bus_address = $hit->{hostname}; - my $bus_key = $hit->{hostkey}; - &send_msg_to_target($answer, $bus_address, $bus_key, $answer_header); - last; - } + if( $error != 0 ) { + next; + } + } - } - } else { - # ... answer is for one specific host - - # get encrypt_key - my $encrypt_key = &get_encrypt_key($answer_target); - if( not defined $encrypt_key ) { - # unknown target, forward msg to bus - daemon_log("WARNING: unknown target '$answer_target', forward msg to bus", 3); - my $sql_statement = "SELECT * FROM known_server WHERE hostname='$bus_address'"; - my $query_res = $known_server_db->select_dbentry( $sql_statement ); - my $bus_key = $query_res->{1}->{hostkey}; - &send_msg_to_target($answer, $bus_address, $bus_key, $answer_header); - next; - } - # send_msg - &send_msg_to_target($answer, $answer_target, $encrypt_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 =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i ) { + daemon_log("target is mac address '$answer_target', looking for host in known_clients", 3); + my $sql_statement = "SELECT * FROM known_clients WHERE macaddress='$answer_target'"; + my $query_res = $known_clients_db->select_dbentry( $sql_statement ); + my $found_ip_flag = 0; + while( my ($hit_num, $hit) = each %{ $query_res } ) { + my $host_name = $hit->{hostname}; + my $host_key = $hit->{hostkey}; + $answer =~ s/$answer_target/$host_name/g; + daemon_log("found host '$host_name', assoziated to '$answer_target'", 3); + &send_msg_to_target($answer, $host_name, $host_key, $answer_header); + $found_ip_flag++ ; + } + if( $found_ip_flag == 0) { + daemon_log("WARNING: no host found in known_clients with mac address '$answer_target'", 3); + if( $bus_activ eq "true" ) { + daemon_log("INFO: try to forward msg '$answer_header' to bus '$bus_address'", 5); + my $sql_statement = "SELECT * FROM known_server WHERE hostname='$bus_address'"; + my $query_res = $known_server_db->select_dbentry( $sql_statement ); + while( my ($hit_num, $hit) = each %{ $query_res } ) { + my $bus_address = $hit->{hostname}; + my $bus_key = $hit->{hostkey}; + &send_msg_to_target($answer, $bus_address, $bus_key, $answer_header); + last; + } + } + + } + } else { + # ... answer is for one specific host + + # get encrypt_key + my $encrypt_key = &get_encrypt_key($answer_target); + if( not defined $encrypt_key ) { + # unknown target, forward msg to bus + daemon_log("WARNING: unknown target '$answer_target'", 3); + if( $bus_activ eq "true" ) { + daemon_log("INFO: try to forward msg '$answer_header' to bus '$bus_address'", 5); + my $sql_statement = "SELECT * FROM known_server WHERE hostname='$bus_address'"; + my $query_res = $known_server_db->select_dbentry( $sql_statement ); + my $bus_key = $query_res->{1}->{hostkey}; + &send_msg_to_target($answer, $bus_address, $bus_key, $answer_header); + } + next; + } + # send_msg + &send_msg_to_target($answer, $answer_target, $encrypt_key, $answer_header); + } + } + } } if( $client_answer ) { @@ -1091,6 +1101,12 @@ if( 0 != $pid ) { daemon_log(" ", 1); daemon_log("$0 started!", 1); +if ($no_bus > 0) { + $bus_activ = "false" +} + + + # delete old DBsqlite lock files #unlink('/tmp/gosa_si_lock*'); diff --git a/gosa-si/modules/ArpHandler.pm b/gosa-si/modules/ArpHandler.pm index f7ae23010..c190342b1 100644 --- a/gosa-si/modules/ArpHandler.pm +++ b/gosa-si/modules/ArpHandler.pm @@ -54,10 +54,10 @@ my %cfg_defaults = "interface" => [\$arp_interface, "all"], }, "server" => { - "ldap_uri" => [\$ldap_uri, ""], - "ldap_base" => [\$ldap_base, ""], - "ldap_admin_dn" => [\$ldap_admin_dn, ""], - "ldap_admin_password" => [\$ldap_admin_password, ""], + "ldap-uri" => [\$ldap_uri, ""], + "ldap-base" => [\$ldap_base, ""], + "ldap-admin-dn" => [\$ldap_admin_dn, ""], + "ldap-admin-password" => [\$ldap_admin_password, ""], }, ); diff --git a/gosa-si/modules/SIPackages.pm b/gosa-si/modules/SIPackages.pm index b36fa497e..bc1be2ff8 100644 --- a/gosa-si/modules/SIPackages.pm +++ b/gosa-si/modules/SIPackages.pm @@ -38,12 +38,12 @@ my %cfg_defaults = ( }, "server" => { "ip" => [\$server_ip, "0.0.0.0"], - "mac_address" => [\$server_mac_address, "00:00:00:00:00"], + "mac-address" => [\$server_mac_address, "00:00:00:00:00"], "port" => [\$server_port, "20081"], "ldap-uri" => [\$ldap_uri, ""], "ldap-base" => [\$ldap_base, ""], - "ldap-admin_dn" => [\$ldap_admin_dn, ""], - "ldap-admin_password" => [\$ldap_admin_password, ""], + "ldap-admin-dn" => [\$ldap_admin_dn, ""], + "ldap-admin-password" => [\$ldap_admin_password, ""], "max-clients" => [\$max_clients, 100], }, "SIPackages" => { diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index fd2f55668..4f07e4542 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -48,8 +48,8 @@ if($sock->connected()){ #$data = "
gosa_halt
10.89.1.31:20083 10.89.1.31:20081
"; #$data = "
gosa_new_key_for_client
00:01:6c:9d:b9:fa 10.89.1.31:20081
"; #$data = "
gosa_new_key_for_client
00:0c:29:bd:7b:e7 10.89.1.31:20081
"; -#$data = "
gosa_new_key_for_client
10.89.1.197:20083 10.89.1.31:20081
"; -$data = "
gosa_new_key_for_client
10.89.1.31:20083 10.89.1.31:20081
"; +$data = "
gosa_new_key_for_client
10.89.1.197:20083 10.89.1.31:20081
"; +#$data = "
gosa_new_key_for_client
10.89.1.31:20083 10.89.1.31:20081
"; $sock->write($data);