diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index c3d08010164bb723fc71938d107e0d0a91ff5e2b..6d2c866d81e8a6128347383392f89760202761a3 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
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 ;
"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"],
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+$/) {
- my $server_address = &get_local_ip_for_remote_ip($target_ip).":$server_port";
- }
+ $local_address = &get_local_ip_for_remote_ip($target_ip).":$server_port";
+ } else {
+ $local_address = $server_address;
+ }
# target and source is equal to GOSA -> process here
if (not $done) {
# target is own address without forward_to_gosa-tag -> process here
if (not $done) {
- if (($target eq $server_address) && (not exists $msg_hash->{'forward_to_gosa'})) {
+ if (($target eq $local_address) && (not exists $msg_hash->{'forward_to_gosa'})) {
$done = 1;
if ($source eq "GOSA") {
- $msg =~ s/<\/xml>/<forward_to_gosa>$server_address,$session_id<\/forward_to_gosa><\/xml>/;
+ $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];
my $gosa_at;
my $gosa_session_id;
- if (($target eq $server_address) && (defined $forward_to_gosa)){
+ if (($target eq $local_address) && (defined $forward_to_gosa)){
my ($gosa_at, $gosa_session_id) = split(/,/, $forward_to_gosa);
- if ($gosa_at ne $server_address) {
+ 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) {
my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
my $gosa_at;
my $gosa_session_id;
- if (($target eq $server_address) && (defined $forward_to_gosa)){
+ if (($target eq $local_address) && (defined $forward_to_gosa)){
my ($gosa_at, $gosa_session_id) = split(/,/, $forward_to_gosa);
- if ($gosa_at eq $server_address) {
+ if ($gosa_at eq $local_address) {
my $session_reference = $kernel->ID_id_to_session($gosa_session_id);
if( defined $session_reference ) {
$heap = $session_reference->get_heap();
$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";
}
}
my $res = $known_server_db->select_dbentry($sql);
if (keys(%$res) > 0) {
my $regserver_key = $res->{1}->{'hostkey'};
- $msg =~ s/<source>GOSA<\/source>/<source>$server_address<\/source>/;
+ $msg =~ s/<source>GOSA<\/source>/<source>$local_address<\/source>/;
$msg =~ s/<target>$target<\/target>/<target>$hostname<\/target>/;
if ($source eq "GOSA") {
- $msg =~ s/<\/xml>/<forward_to_gosa>$server_address,$session_id<\/forward_to_gosa><\/xml>/;
+ $msg =~ s/<\/xml>/<forward_to_gosa>$local_address,$session_id<\/forward_to_gosa><\/xml>/;
}
&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
my $hostkey = $res->{1}->{'hostkey'};
if ($source eq "GOSA") {
- $msg =~ s/<source>GOSA<\/source>/<source>$server_address<\/source>/;
- $msg =~ s/<\/xml>/<forward_to_gosa>$server_address,$session_id<\/forward_to_gosa><\/xml>/;
+ $msg =~ s/<source>GOSA<\/source>/<source>$local_address<\/source>/;
+ $msg =~ s/<\/xml>/<forward_to_gosa>$local_address,$session_id<\/forward_to_gosa><\/xml>/;
}
&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);
+ if ($source eq "GOSA") {
+ my %data = ('error_msg' => &encode_base64($msg), 'error_string' => "Do not know what to do with this message!");
+ my $error_msg = &build_msg("error", $local_address, "GOSA", \%data );
+
+ my $session_reference = $kernel->ID_id_to_session($session_id);
+ if( defined $session_reference ) {
+ $heap = $session_reference->get_heap();
+ }
+ if(exists $heap->{'client'}) {
+ $error_msg = &encrypt_msg($error_msg, $GosaPackages_key);
+ $heap->{'client'}->put($error_msg);
+ }
+ }
}
+
}
return;
sub session_start {
my ($kernel) = $_[KERNEL];
- &trigger_db_loop($kernel);
$global_kernel = $kernel;
$kernel->yield('register_at_foreign_servers');
$kernel->yield('create_fai_server_db', $fai_server_tn );
$kernel->yield('create_fai_release_db', $fai_release_tn );
$kernel->yield('watch_for_next_tasks');
$kernel->sig(USR1 => "sig_handler");
- $kernel->sig(USR2 => "create_packages_list_db");
+ $kernel->sig(USR2 => "recreate_packages_db");
$kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay);
$kernel->delay_set('watch_for_done_jobs', $job_queue_loop_delay);
$kernel->delay_set('watch_for_new_messages', $messaging_db_loop_delay);
}
-sub trigger_db_loop {
- my ($kernel) = @_ ;
-# $kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay);
-# $kernel->delay_set('watch_for_done_jobs', $job_queue_loop_delay);
-# $kernel->delay_set('watch_for_new_messages', $messaging_db_loop_delay);
-# $kernel->delay_set('watch_for_delivery_messages', $messaging_db_loop_delay);
-# $kernel->delay_set('watch_for_done_messages', $messaging_db_loop_delay);
-# $kernel->delay_set('watch_for_old_known_clients', $job_queue_loop_delay);
-}
-
sub watch_for_done_jobs {
my ($kernel,$heap) = @_[KERNEL, HEAP];
my $res = $incoming_db->exec_statement($sql);
}
- $kernel->delay_set('watch_for_next_tasks', 1);
+ $kernel->delay_set('watch_for_next_tasks', 0.1);
}
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);
# 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;
#}
}
}
}
} 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);
}
}
}
+sub run_recreate_packages_db {
+ my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
+ my $session_id = $session->ID;
+ &main::daemon_log("$session_id INFO: Recreating FAI Packages DB ('$fai_release_tn', '$fai_server_tn', '$packages_list_tn')", 4);
+ $kernel->yield('create_fai_release_db');
+ $kernel->yield('create_fai_server_db');
+ return;
+}
+
+
sub run_create_fai_server_db {
my ($kernel, $session, $heap, $table_name) = @_[KERNEL, SESSION, HEAP, ARG0];
my $session_id = $session->ID;
close( $PACKAGES );
unlink( "$path.in" );
- &main::daemon_log("$session_id DEBUG: unlink '$path.in'", 1);
}
@@ -2933,6 +2981,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,
create_packages_list_db => \&run_create_packages_list_db,
create_fai_server_db => \&run_create_fai_server_db,
create_fai_release_db => \&run_create_fai_release_db,
+ recreate_packages_db => \&run_recreate_packages_db,
session_run_result => \&session_run_result,
session_run_debug => \&session_run_debug,
session_run_done => \&session_run_done,