diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 04063e6f320286aeca851f38587d2fa843824c3a..e3849b442ae309a6a56b12b402b7fffab0883c0a 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
use Sys::Syslog qw( :DEFAULT setlogsock);
use Cwd;
use File::Spec;
+use File::Basename;
use GOSA::DBsqlite;
use POE qw(Component::Server::TCP);
# holds all registrated clients
our $known_clients_db;
+our $prg= basename($0);
%cfg_defaults = (
"general" => {
- "log-file" => [\$log_file, "/var/run/".$0.".log"],
- "pid-file" => [\$pid_file, "/var/run/".$0.".pid"],
+ "log-file" => [\$log_file, "/var/run/".$prg.".log"],
+ "pid-file" => [\$pid_file, "/var/run/".$prg.".pid"],
},
"bus" => {
"activ" => [\$bus_activ, "true"],
#===============================================================================
sub usage {
print STDERR << "EOF" ;
-usage: $0 [-hvf] [-c config]
+usage: $prg [-hvf] [-c config]
-h : this (help) message
-c <file> : config file
-f : foreground, process will not be forked to background
-v : be verbose (multiple to increase verbosity)
- -no-bus : starts $0 without connection to bus
- -no-arp : starts $0 without connection to arp module
+ -no-bus : starts $prg without connection to bus
+ -no-arp : starts $prg without connection to arp module
EOF
print "\n" ;
$month = $monthnames[$month];
$monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
$year+=1900;
- my $name = $0;
- $name =~ s/\.\///;
+ my $name = $prg;
my $log_msg = "$month $monthday $hours:$minutes:$seconds $name $msg\n";
print LOG_HANDLE $log_msg;
}
+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;
}
# 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++;
# 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 ) {