diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 81940ed98bbfae20487b91c3a3977ac1c24a4da3..6d2c866d81e8a6128347383392f89760202761a3 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
our $global_kernel;
my ($foreground, $ping_timeout);
-my ($bus_activ, $bus, $msg_to_bus, $bus_cipher);
my ($server);
my ($gosa_server, $job_queue_timeout, $job_queue_loop_delay);
my ($messaging_db_loop_delay);
# additional variable which should be globaly accessable
our $server_address;
our $server_mac_address;
-our $bus_address;
our $gosa_address;
-our $no_bus;
our $no_arp;
our $verbose;
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 ;
# specifies the timeout seconds while checking the online status of a registrating client
$ping_timeout = 5;
-$no_bus = 0;
-$bus_activ = "true";
$no_arp = 0;
my $packages_list_under_construction = "/tmp/packages_list_creation_in_progress";
my @packages_list_statements;
"plainname DEFAULT 'none'",
);
-# holds all other gosa-sd as well as the gosa-sd-bus
+# holds all other gosa-si-server
our $known_server_db;
our $known_server_tn = "known_server";
my $known_server_file_name;
"log-file" => [\$log_file, "/var/run/".$prg.".log"],
"pid-file" => [\$pid_file, "/var/run/".$prg.".pid"],
},
-"bus" => {
- "activ" => [\$bus_activ, "true"],
- },
"server" => {
"port" => [\$server_port, "20081"],
"known-clients" => [\$known_clients_file_name, '/var/lib/gosa-si/clients.db' ],
"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"],
-c <file> : config file
-f : foreground, process will not be forked to background
-v : be verbose (multiple to increase verbosity)
- -no-bus : starts $prg without connection to bus
-no-arp : starts $prg without connection to arp module
EOF
# msg is from a new client or gosa
($msg, $msg_hash, $module) = &input_from_unknown_host($next_msg, $session_id);
- # msg is from a gosa-si-server or gosa-si-bus
+ # msg is from a gosa-si-server
if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
($msg, $msg_hash, $module) = &input_from_known_server($next_msg, $heap->{'remote_ip'}, $session_id);
}
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 ne "GOSA") {
- my $server_address = &get_local_ip_for_remote_ip($target_ip).":$server_port";
- }
+ if ($target =~ /^\d+\.\d+\.\d+\.\d+:\d+$/) {
+ $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=>$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;
my $client_answer = "";
# prepare all variables needed to process message
- my $msg = $task->{'xmlmessage'};
+ #my $msg = $task->{'xmlmessage'};
+ my $msg = &decode_base64($task->{'xmlmessage'});
my $incoming_id = $task->{'id'};
my $module = $task->{'module'};
my $header = $task->{'headertag'};
}
if( $found_ip_flag == 0) {
daemon_log("$session_id WARNING: no host found in known_clients with mac address '$answer_target'", 3);
- if( $bus_activ eq "true" ) {
- daemon_log("$session_id 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};
- my $error = &send_msg_to_target($answer, $bus_address, $bus_key, $answer_header, $session_id);
- &update_jobdb_status_for_send_msgs($answer, $error);
- last;
- }
- }
-
}
# 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
+ # unknown target
daemon_log("$session_id WARNING: unknown target '$answer_target'", 3);
- if( $bus_activ eq "true" ) {
- daemon_log("$session_id 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 $res_length = keys( %{$query_res} );
- if( $res_length == 0 ){
- daemon_log("$session_id WARNING: send '$answer_header' to '$bus_address' failed, ".
- "no bus found in known_server", 3);
- }
- else {
- while( my ($hit_num, $hit) = each %{ $query_res } ) {
- my $bus_key = $hit->{hostkey};
- my $error = &send_msg_to_target($answer, $bus_address, $bus_key, $answer_header,$session_id );
- &update_jobdb_status_for_send_msgs($answer, $error);
- }
- }
- }
next;
}
my $error = &send_msg_to_target($answer, $answer_target, $encrypt_key, $answer_header,$session_id);
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];
# fetch key to encrypt msg propperly for usr/host
my $sql = "SELECT * FROM $known_clients_tn WHERE (hostname='$receiver_host')";
&daemon_log("0 DEBUG: $sql", 7);
- my $res = $known_clients_db->select_dbentry($sql);
+ my $res = $known_clients_db->exec_statement($sql);
# host is already down
if (not ref(@$res[0]) eq "ARRAY") { next; }
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, apassword => $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;
#}
}
if ($mesg->count) {
my @entries = $mesg->entries;
+ if (0 == @entries) {
+ daemon_log("$session_id ERROR: ldap search failed: ldap_base=$ldap_base, filter=$search", 1);
+ }
+
foreach my $entry (@entries) {
# Only modify entry if it is not set to '$state'
if ($entry->get_value("FAIstate") ne "$state"){
daemon_log("$session_id DEBUG FAIstate at host '".$entry->dn."' already at state '$st'", 7);
}
}
+ } else {
+ daemon_log("$session_id ERROR: LDAP search failed: ldap_base=$ldap_base, filter=$search", 1);
}
+
# if no ldap handle defined
} else {
daemon_log("$session_id ERROR: no LDAP handle defined for update FAIstate", 1);
}
+ return;
}
}
}
- }
+ } else {
+ 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);
}
"c|config=s" => \$cfg_file,
"f|foreground" => \$foreground,
"v|verbose+" => \$verbose,
- "no-bus+" => \$no_bus,
"no-arp+" => \$no_arp,
);
daemon_log("status: $server_status", 1);
daemon_log($server_status_hash->{$server_status}.": $server_revision", 1);
-if ($no_bus > 0) {
- $bus_activ = "false"
-}
-
# connect to incoming_db
unlink($incoming_file_name);
$incoming_db = GOSA::DBsqlite->new($incoming_file_name);
@@ -2966,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,