Code

Added first DAK method
[gosa.git] / gosa-si / gosa-si-server
index 75fec07b1a336106418d4457614e8709c0aa911a..262d1afd1ec962e081b6a4ed155ffdecd60d5c73 100755 (executable)
@@ -98,6 +98,11 @@ our $forground;
 our $cfg_file;
 our ($ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $ldap_server_dn);
 
+# dak variables
+our $dak_base_directory;
+our $dak_signing_keys_directory;
+our $dak_queue_directory;
+our $dak_user;
 
 # specifies the verbosity of the daemon_log
 $verbose = 0 ;
@@ -233,6 +238,10 @@ my $max_children = 2;
     "job-queue-loop-delay" => [\$job_queue_loop_delay, 3],
     "messaging-db-loop-delay" => [\$messaging_db_loop_delay, 3],
     "key" => [\$GosaPackages_key, "none"],
+       "dak-base" => [\$dak_base_directory, "/srv/archive"],
+       "dak-keyring" => [\$dak_signing_keys_directory, "/srv/archive/keyrings"],
+       "dak-queue" => [\$dak_queue_directory, "/srv/archive/queue"],
+       "dak-user" => [\$dak_user, "deb-dak"],
     },
 "ClientPackages" => {
     "key" => [\$ClientPackages_key, "none"],
@@ -1054,11 +1063,15 @@ sub msg_to_decrypt {
     my $done = 0;
     my $sql;
     my $res;
+
     # check whether this message should be processed here
     if ($error == 0) {
         $header = @{$msg_hash->{'header'}}[0];
         $target = @{$msg_hash->{'target'}}[0];
         $source = @{$msg_hash->{'source'}}[0];
+               my $not_found_in_known_clients_db = 0;
+               my $not_found_in_known_server_db = 0;
+               my $not_found_in_foreign_clients_db = 0;
         my $local_address;
         my ($target_ip, $target_port) = split(':', $target);
                if ($target =~ /^\d+\.\d+\.\d+\.\d+:\d+$/) {
@@ -1081,22 +1094,24 @@ sub msg_to_decrypt {
                 if ($source eq "GOSA") {
                     $msg =~ s/<\/xml>/<forward_to_gosa>$local_address,$session_id<\/forward_to_gosa><\/xml>/;
                 }
-                print STDERR "target is own address without forward_to_gosa-tag -> process here\n";
+                #print STDERR "target is own address without forward_to_gosa-tag -> process here\n";
             }
         }
 
         # target is a client address in known_clients -> process here
-        if (not $done) {
-            $sql = "SELECT * FROM $known_clients_tn WHERE (hostname='$target' OR macaddress LIKE '$target')"; 
-            $res = $known_clients_db->select_dbentry($sql);
-            if (keys(%$res) > 0) {
-                $done = 1; 
-                my $hostname = $res->{1}->{'hostname'};
-                $msg =~ s/<target>$target<\/target>/<target>$hostname<\/target>/;
-                print STDERR "target is a client address in known_clients -> process here\n";
-            }
-        }
-
+               if (not $done) {
+                               $sql = "SELECT * FROM $known_clients_tn WHERE (hostname='$target' OR macaddress LIKE '$target')"; 
+                               $res = $known_clients_db->select_dbentry($sql);
+                               if (keys(%$res) > 0) {
+                                               $done = 1; 
+                                               my $hostname = $res->{1}->{'hostname'};
+                                               $msg =~ s/<target>$target<\/target>/<target>$hostname<\/target>/;
+                                               #print STDERR "target is a client address in known_clients -> process here\n";
+                               } else {
+                                               $not_found_in_known_clients_db = 1;
+                               }
+               }
+       
         # target ist own address with forward_to_gosa-tag not pointing to myself -> process here
         if (not $done) {
             my $forward_to_gosa =  @{$msg_hash->{'forward_to_gosa'}}[0];
@@ -1106,31 +1121,29 @@ sub msg_to_decrypt {
                 my ($gosa_at, $gosa_session_id) = split(/,/, $forward_to_gosa);
                 if ($gosa_at ne $local_address) {
                     $done = 1;
-                    print STDERR "target is own address with forward_to_gosa-tag not pointing to myself -> process here\n"; 
+                    #print STDERR "target is own address with forward_to_gosa-tag not pointing to myself -> process here\n"; 
                 }
             }
         }
 
         # if message should be processed here -> add message to incoming_db
-        if ($done) {
-
-            # if a job or a gosa message comes from a foreign server, fake module to GosaPackages
-            # so gosa-si-server knows how to process this kind of messages
-            if ($header =~ /^gosa_/ || $header =~ /job_/) {
-                $module = "GosaPackages";
-            }
-
-            my $res = $incoming_db->add_dbentry( {table=>$incoming_tn,
-                    primkey=>[],
-                    headertag=>$header,
-                    targettag=>$target,
-                    xmlmessage=>&encode_base64($msg),
-                    timestamp=>&get_time,
-                    module=>$module,
-                    sessionid=>$session_id,
-                    } );
+               if ($done) {
+                               # if a job or a gosa message comes from a foreign server, fake module to GosaPackages
+                               # so gosa-si-server knows how to process this kind of messages
+                               if ($header =~ /^gosa_/ || $header =~ /job_/) {
+                                               $module = "GosaPackages";
+                               }
 
-        }
+                               my $res = $incoming_db->add_dbentry( {table=>$incoming_tn,
+                                                               primkey=>[],
+                                                               headertag=>$header,
+                                                               targettag=>$target,
+                                                               xmlmessage=>&encode_base64($msg),
+                                                               timestamp=>&get_time,
+                                                               module=>$module,
+                                                               sessionid=>$session_id,
+                                                               } );
+               }
 
         # target is own address with forward_to_gosa-tag pointing at myself -> forward to gosa
         if (not $done) {
@@ -1149,7 +1162,7 @@ sub msg_to_decrypt {
                         $heap->{'client'}->put($msg);
                     }
                     $done = 1;
-                    print STDERR "target is own address with forward_to_gosa-tag pointing at myself -> forward to gosa\n";
+                    #print STDERR "target is own address with forward_to_gosa-tag pointing at myself -> forward to gosa\n";
                 }
             }
 
@@ -1174,8 +1187,10 @@ sub msg_to_decrypt {
                     &send_msg_to_target($msg, $regserver, $regserver_key, $header, $session_id);
                 }
                 $done = 1;
-                print STDERR "target is a client address in foreign_clients -> forward to registration server\n";
-            }
+                #print STDERR "target is a client address in foreign_clients -> forward to registration server\n";
+            } else {
+                               $not_found_in_foreign_clients_db = 1;
+                       }
         }
 
         # target is a server address -> forward to server
@@ -1193,11 +1208,29 @@ sub msg_to_decrypt {
 
                 &send_msg_to_target($msg, $target, $hostkey, $header, $session_id);
                 $done = 1;
-                print STDERR "target is a server address -> forward to server\n";
-            }
+                #print STDERR "target is a server address -> forward to server\n";
+            } else {
+                               $not_found_in_known_server_db = 1;
+                       }
+        }
 
+               
+               # target is not in foreign_clients_db, known_server_db or known_clients_db, maybe it is a complete new one -> process here
+               if ( $not_found_in_foreign_clients_db 
+                                               && $not_found_in_known_server_db
+                                               && $not_found_in_known_clients_db) {
+                               my $res = $incoming_db->add_dbentry( {table=>$incoming_tn,
+                                                               primkey=>[],
+                                                               headertag=>$header,
+                                                               targettag=>$target,
+                                                               xmlmessage=>&encode_base64($msg),
+                                                               timestamp=>&get_time,
+                                                               module=>$module,
+                                                               sessionid=>$session_id,
+                                                               } );
+                               $done = 1;
+               }
 
-        }
 
         if (not $done) {
             daemon_log("$session_id ERROR: do not know what to do with this message: $msg", 1);
@@ -1777,7 +1810,7 @@ sub watch_for_next_tasks {
         my $res = $incoming_db->exec_statement($sql);
     }
 
-    $kernel->delay_set('watch_for_next_tasks', 1); 
+    $kernel->delay_set('watch_for_next_tasks', 0.1); 
 }
 
 
@@ -1792,7 +1825,7 @@ sub get_ldap_handle {
        if ($session_id == 0) {
                daemon_log("$session_id DEBUG: get_ldap_handle invoked without a session_id, create a new ldap_handle", 7); 
                $ldap_handle = Net::LDAP->new( $ldap_uri );
-               $ldap_handle->bind($ldap_admin_dn, password => $ldap_admin_password); 
+               $ldap_handle->bind($ldap_admin_dn, password => $ldap_admin_password) or daemon_log("$session_id ERROR: Bind to LDAP $ldap_uri as $ldap_admin_dn failed!")
 
        } else {
                my $session_reference = $global_kernel->ID_id_to_session($session_id);
@@ -1809,7 +1842,7 @@ sub get_ldap_handle {
                 #       used handle is still valid - or if we've to reconnect...
                #if (not exists $heap->{ldap_handle}) {
                        $ldap_handle = Net::LDAP->new( $ldap_uri );
-                       $ldap_handle->bind($ldap_admin_dn, password => $ldap_admin_password); 
+                       $ldap_handle->bind($ldap_admin_dn, password => $ldap_admin_password) or daemon_log("$session_id ERROR: Bind to LDAP $ldap_uri as $ldap_admin_dn failed!")
                        $heap->{ldap_handle} = $ldap_handle;
                #}
        }
@@ -1962,7 +1995,7 @@ sub change_goto_state {
           }
         }
       } else {
-               daemon_log("$session_id ERROR: LDAP search failed: ldap_base=$ldap_base, filter=$search", 1);
+               daemon_log("$session_id ERROR: LDAP search failed in function change_goto_state: ldap_base=$ldap_base, filter=$search", 1);
          }
 
     }
@@ -2695,7 +2728,6 @@ sub parse_package {
 
     close( $PACKAGES );
     unlink( "$path.in" );
-    &main::daemon_log("$session_id DEBUG: unlink '$path.in'", 1); 
 }
 
 
@@ -2939,6 +2971,14 @@ daemon_log("0 INFO: found foreign server in config file and DNS: $all_foreign_se
 # add all found foreign servers to known_server
 my $act_timestamp = &get_time();
 foreach my $foreign_server (@foreign_server_list) {
+
+       #######################################
+       # TODO for jan
+       # do not add myself to known_server_db
+       # work around!!!
+       if ($foreign_server eq '172.16.2.89:20081') { next; }
+       ######################################
+
     my $res = $known_server_db->add_dbentry( {table=>$known_server_tn, 
             primkey=>['hostname'],
             hostname=>$foreign_server,