Code

--- complete --- bus mac address handling
authorrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 8 Feb 2008 10:06:32 +0000 (10:06 +0000)
committerrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 8 Feb 2008 10:06:32 +0000 (10:06 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8775 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-si/gosa-si-bus
gosa-si/gosa-si-server
gosa-si/tests/client.php

index c37d14b7eb0dbde7c0e699c85f3cfc8dac1d212e..29e31ff3754786ef86f3ce8a0014c8cf5d10cf7e 100755 (executable)
@@ -677,33 +677,74 @@ sub bus_input {
         my $source = @{$msg_hash->{'source'}}[0];
         my $header = @{$msg_hash->{header}}[0];
 
+        my $target_string = join(",", @target_l);
+        daemon_log("got msg '$header' with target '$target_string' from ".$heap->{'remote_ip'}, 3);
+
         if( 1 == length(@target_l) && $target_l[0] eq $bus_address ) {
             # msg is for bus
+#print STDERR "msg is for bus\n";
             $kernel->post('gosa_si_bus_session', $header, $msg, $msg_hash);
         }
         else {
             # msg is for someone else, deliver it
 
-            print STDERR "msg is for someone else\n";
+#print STDERR "msg is for someone else\n";
             foreach my $target (@target_l) {
-                print STDERR "target: $target\n";
-                if( $target =~ /(\d{3}\.\d{3}\.\d{3}\.\d{3}:\d+)/ ) {
+                if( $target =~ /(\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3}:\d+)/ ) {
                     # target is a ip address
-
-                    my $sql_statement = "SELECT * FROM bus_known_server WHERE hostname='$target'";
-                    my $sql_statement = "SELECT * FROM bus_known_clients WHERE hostname='$target'";
+                    my ($sql_statement, $query_res);
+
+                    $sql_statement = "SELECT * FROM bus_known_server WHERE hostname='$target'";
+                    $query_res = $bus_known_server_db->select_dbentry( $sql_statement );
+                    if( 1 == keys(%$query_res) ) {
+                        my $host_name = $query_res->{1}->{'hostname'};
+                        my $host_key = $query_res->{1}->{'hostkey'};
+                        &send_msg_to_target($msg, $host_name, $host_key, $header);
+                        next;
+                    } 
+
+                    $sql_statement = "SELECT * FROM bus_known_clients WHERE hostname='$target'";
+                    $query_res = $bus_known_clients_db->select_dbentry( $sql_statement );
+                    if( 1 == keys(%$query_res) ) {
+                        my $host_name = $query_res->{1}->{'hostname'};
+                        my $server_name = $query_res->{1}->{'registered'};
+                        # fetch correct key for server
+                        my $sql_statement = "SELECT * FROM bus_known_server WHERE hostname='$server_name'";
+                        my $query_res = $bus_known_server_db->select_dbentry( $sql_statement );
+                        my $server_key = $query_res->{1}->{'hostkey'};
+                        &send_msg_to_target($msg, $server_name, $server_key, $header);
+                        next;
+                    } 
+
+                    daemon_log("ERROR:unknown host, can not process message '$header'", 1);
                 }
                 elsif( $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})/ ) {
                     # target is a mac address
-
-                    my $sql_statement = "SELECT registerd FROM bus_known_clients WHERE macaddress='$target'";
+                    my $sql_statement = "SELECT * FROM bus_known_clients WHERE macaddress='$target'";
                     my $query_res = $bus_known_clients_db->select_dbentry( $sql_statement );
-                    print Dumper $query_res;
-
-                    
+                    if( 1 > keys(%{$query_res})) {
+                        daemon_log("ERROR: there are more than one hosts in bus_known_clients_db with mac address '$target'", 1);
+                    }
+                    elsif( 0 == keys(%{$query_res})) {
+                        daemon_log("WARNING: no host found in bus_known_clients_db with mac address '$target'", 3);
+                    }
+                    else {
+                        my $host_name = $query_res->{1}->{'hostname'};
+                        my $server_name = $query_res->{1}->{'registered'};
+                        my $out_msg = $msg;
+                        $out_msg =~ s/<target>$target<\/target>/<target>$host_name<\/target>/;
+
+                        # fetch correct key for server
+                        my $sql_statement = "SELECT * FROM bus_known_server WHERE hostname='$server_name'";
+                        my $query_res = $bus_known_server_db->select_dbentry( $sql_statement );
+                        my $server_key = $query_res->{1}->{'hostkey'};
+
+                        &send_msg_to_target($out_msg, $server_name, $server_key, $header);
+                    }
                 }
                 else {
-
+                    daemon_log("ERROR: target address '$target' does not match neiter ".
+                        "to ip address nor to mac address, can not process msg", 1);
                 }
 
             }
@@ -766,6 +807,7 @@ sub new_client {
         timestamp=>$act_timestamp,
     };
     $bus_known_clients_db->add_dbentry($add_hash);
+    daemon_log("add new client '$new_client' to bus_known_clients_db", 3);
 }
 
 
index 3dbb629bb0194f490551ba614c21797a03a57c1c..bc7d4f52f3576d1f2ce6305491252ac8e8015f43 100755 (executable)
@@ -831,8 +831,13 @@ sub client_input {
                     # get encrypt_key
                     my $encrypt_key = &get_encrypt_key($answer_target);
                     if( !$encrypt_key ) {
-                        daemon_log("ERROR: no encrypt key found in known_clients or known_server for target '$answer_target'", 1);
-                        daemon_log("\n$answer", 8);
+                        # 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 status='bus'";
+                        my $query_res = $known_server_db->select_dbentry( $sql_statement );
+                        my $bus_address = $query_res->{1}->{hostname};
+                        my $bus_key = $query_res->{1}->{hostkey};
+                        &send_msg_to_target($answer, $bus_address, $bus_key, $answer_header);
                         next;
                     }
                     # send_msg
index fba6de2aebcfa02db12d896f6b731e7337d8f21c..f2a6ed4ca8504e6fd1ab3f373186bd68e7768e41 100755 (executable)
@@ -47,7 +47,8 @@ if($sock->connected()){
 #$data = "<xml> <header>gosa_softupdate</header> <target>10.89.1.31:20083</target> <source>10.89.1.31:20081</source> </xml>";
 #$data = "<xml> <header>gosa_halt</header> <target>10.89.1.31:20083</target> <source>10.89.1.31:20081</source> </xml>";
 #$data = "<xml> <header>gosa_new_key_for_client</header> <target>00:01:6c:9d:b9:fa</target> <source>10.89.1.31:20081</source> </xml>";
-$data = "<xml> <header>gosa_new_key_for_client</header> <target>00:01:6c:9d:b9:fb</target> <source>10.89.1.31:20081</source> </xml>";
+#$data = "<xml> <header>gosa_new_key_for_client</header> <target>00:0c:29:bd:7b:e7</target> <source>10.89.1.31:20081</source> </xml>";
+$data = "<xml> <header>gosa_new_key_for_client</header> <target>10.89.1.197:20083</target> <source>10.89.1.31:20081</source> </xml>";
 
 
     $sock->write($data);