diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 127d8b65ea6d0b28c4ace28db4e9932c01abf466..590d9668e4a5a62e2d38a884aa684464a417ecdc 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
}
+sub check_outgoing_xml_validity {
+ my ($msg) = @_;
+
+ my $msg_hash;
+ eval{
+ $msg_hash = $xml->XMLin($msg, ForceArray=>1);
+
+ ##############
+ # check header
+ my $header_l = $msg_hash->{'header'};
+ if( 1 != @{$header_l} ) {
+ die 'no or more than one headers specified';
+ }
+ my $header = @{$header_l}[0];
+ if( 0 == length $header) {
+ die 'header has length 0';
+ }
+
+ ##############
+ # check source
+ my $source_l = $msg_hash->{'source'};
+ if( 1 != @{$source_l} ) {
+ die 'no or more than 1 sources specified';
+ }
+ my $source = @{$source_l}[0];
+ if( 0 == length $source) {
+ die 'source has length 0';
+ }
+ unless( $source =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$/ ||
+ $source =~ /^GOSA$/i ) {
+ die "source '$source' is neither a complete ip-address with port nor 'GOSA'";
+ }
+
+ ##############
+ # check target
+ my $target_l = $msg_hash->{'target'};
+ if( 0 == @{$target_l} ) {
+ die "no targets specified";
+ }
+ foreach my $target (@$target_l) {
+ if( 0 == length $target) {
+ die "target has length 0";
+ }
+ unless( $target =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$/ ||
+ $target =~ /^GOSA$/i ||
+ $target =~ /^\*$/ ||
+ $target =~ /KNOWN_SERVER/i ||
+ $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 ){
+ die "target '$target' is not a complete ip-address with port or a valid target name or a mac-address";
+ }
+ }
+ };
+ if($@) {
+ daemon_log("WARNING: outgoing msg is not gosa-si envelope conform", 5);
+ daemon_log("$@ $msg", 8);
+ $msg_hash = undef;
+ }
+
+ return ($msg_hash);
+}
+
+
sub input_from_known_server {
my ($input, $remote_ip) = @_ ;
my ($msg, $msg_hash, $module);
# check a key exists for this module
my $module_key = ${$mod."_key"};
if( ! $module_key ) {
+ if( $mod eq 'ArpHandler' ) {
+ next;
+ }
daemon_log("ERROR: no key specified in config file for $mod", 1);
next;
}
sub client_input {
no strict "refs";
- my ($heap,$input,$wheel) = @_[HEAP, ARG0, ARG1];
+ my ($kernel, $session, $heap,$input,$wheel) = @_[KERNEL, SESSION, HEAP, ARG0, ARG1];
+ my $session_id = $session->ID;
my ($msg, $msg_hash, $module);
my $error = 0;
my $answer_l;
daemon_log("Incoming msg from '".$heap->{'remote_ip'}."'", 7);
daemon_log("\n$input", 8);
+ ####################
+ # check incoming msg
# msg is from a new client or gosa
($msg, $msg_hash, $module) = &input_from_unknown_host($input);
-
# msg is from a gosa-si-server or gosa-si-bus
if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
($msg, $msg_hash, $module) = &input_from_known_server($input, $heap->{'remote_ip'});
}
-
# msg is from a gosa-si-client
if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
($msg, $msg_hash, $module) = &input_from_known_client($input, $heap->{'remote_ip'});
}
-
# an error occurred
if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
$error++;
# process incoming msg
if( $error == 0) {
daemon_log("Processing module ".$module, 5);
- $answer_l = &{ $module."::process_incoming_msg" }($msg, $msg_hash, $heap->{'remote_ip'});
+ $answer_l = &{ $module."::process_incoming_msg" }($msg, $msg_hash, $session_id);
if ( 0 > @{$answer_l} ) {
my $answer_str = join("\n", @{$answer_l});
# answer
if( $error == 0 ) {
- # 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;
- }
+ # for each answer in answer list
+
+ # check outgoing msg to xml validity
+ my $answer_hash = &check_outgoing_xml_validity($answer);
+ if( not defined $answer_hash ) {
+ next;
}
+
+ $answer_header = @{$answer_hash->{'header'}}[0];
+ @answer_target_l = @{$answer_hash->{'target'}};
+ $answer_source = @{$answer_hash->{'source'}}[0];
# deliver msg to all targets
foreach my $answer_target ( @answer_target_l ) {
}
}
elsif( $answer_target eq "GOSA" ) {
+ $answer =~ /<session_id>(\d)<\/session_id>/;
+
# answer is for GOSA and has to returned to connected client
my $gosa_answer = &encrypt_msg($answer, $GosaPackages_key);
- $client_answer = $gosa_answer;
+ $client_answer = $gosa_answer."session_id=$1";
}
elsif( $answer_target eq "KNOWN_SERVER" ) {
# answer is for all server in known_server
}
if( $client_answer ) {
- $heap->{client}->put($client_answer);
+
+ if( $client_answer =~ /session_id=(\d+)/ ) {
+ my $session_id = $1;
+ my $session_reference = $kernel->ID_id_to_session($1);
+ my $session_heap = $session_reference->get_heap();
+ $session_heap->{client}->put( $client_answer );
+ }
+ else {
+ $heap->{client}->put($client_answer);
+ }
+
}
return;