From 09623644ba85fe82ed983a43a36d38e65705a36d Mon Sep 17 00:00:00 2001 From: rettenbe Date: Tue, 4 Dec 2007 16:37:10 +0000 Subject: [PATCH] - splitting parts of gosad to modules - first running version of 'moduled' gosad - TODO: clean up of scripts from multiple debugging tags and comments - TODO: each module has to read config file at start git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8002 594d385d-05f5-0310-b6e9-bd551577e9d8 --- contrib/daemon/gosa-sc | 5 +- contrib/daemon/gosa-sd | 1123 ++++++++++++++++++++---------------- contrib/daemon/gosa-sd-bus | 7 +- contrib/daemon/gosa-sd.cfg | 8 +- 4 files changed, 653 insertions(+), 490 deletions(-) diff --git a/contrib/daemon/gosa-sc b/contrib/daemon/gosa-sc index d07edb6e2..767d0c80f 100755 --- a/contrib/daemon/gosa-sc +++ b/contrib/daemon/gosa-sc @@ -48,7 +48,6 @@ $foreground = 0 ; ("general" => {"log_file" => [\$log_file, "/var/run/".$0.".log"], "pid_file" => [\$pid_file, "/var/run/".$0.".pid"], - }, "client" => {"client_ip" => [\$client_ip, "10.89.1.155"], @@ -487,7 +486,7 @@ sub encrypt_msg { my $msg_length = length($msg); my $multiplier = int($msg_length / 16) + 1; my $extension = 16*$multiplier - $msg_length; - $msg = "a"x$extension.$msg; + $msg = $msg."\0"x$extension; my $crypted_msg = $my_cipher->encrypt($msg); #my $crypted_msg = $msg; return $crypted_msg; @@ -504,7 +503,7 @@ sub decrypt_msg { my ($crypted_msg, $my_cipher) =@_; my $msg = $my_cipher->decrypt($crypted_msg); #my $msg = $crypted_msg; - $msg =~ s/^a*//gi; + #$msg =~ s/^a*//gi; return $msg; } diff --git a/contrib/daemon/gosa-sd b/contrib/daemon/gosa-sd index e88e441c2..484111b25 100755 --- a/contrib/daemon/gosa-sd +++ b/contrib/daemon/gosa-sd @@ -37,16 +37,33 @@ use File::Spec; use IPC::Shareable qw( :lock); IPC::Shareable->clean_up_all; + +use lib "/etc/gosad/modules"; +my $modules_path = "/etc/gosad/modules"; + my ($cfg_file, %cfg_defaults, $foreground, $verbose, $ping_timeout); -my ($bus_activ, $bus_passwd, $bus_ip, $bus_port, $bus, $bus_address, $msg_to_bus, $bus_cipher); -my ($server_address, $server_activ, $server_port, $server, $server_ip, $server_passwd, $server_mac, $server_events); -my ($known_daemons, $shmda, $known_clients, $shmcl); +my ($bus, $msg_to_bus, $bus_cipher); +my ($server, $server_mac, $server_events); +my ($gosa_server); +my ($known_daemons, $shmda, $known_clients, $shmcl, $known_modules); my ($max_clients); my ($pid_file, $procid, $pid, $log_file); my (%free_child, %busy_child, $child_max, $child_min, %child_alive_time, $child_timeout); -my ($xml); my ($arp_activ, $arp_fifo, $arp_fifo_path); -my ($gosa_activ, $gosa_fifo_in, $gosa_fifo_out); + +# variables declared in config file are always set to 'our' +our (%cfg_defaults, $log_file, $pid_file, + $bus_activ, $bus_passwd, $bus_ip, $bus_port, + $server_activ, $server_ip, $server_port, $server_passwd, $max_clients, + $arp_activ, $arp_fifo_path, + $gosa_activ, $gosa_passwd, $gosa_ip, $gosa_port, $gosa_timeout, +); + +# additional variable which should be globaly accessable +our $xml; +our $server_address; +our $bus_address; +our $gosa_address; # specifies the verbosity of the daemon_log $verbose = 0 ; @@ -62,20 +79,21 @@ $ping_timeout = 5; my $ping_port = "12345"; # holds all other gosa-sd as well as the gosa-sd-bus -$known_daemons = {}; -$shmda = tie($known_daemons, 'IPC::Shareable', undef, {create => 1, +our $known_daemons = {}; +our $shmda = tie($known_daemons, 'IPC::Shareable', undef, {create => 1, exclusive => 1, mode => 0666, destroy => 1, }); # holds all registrated clients -$known_clients = {}; -$shmcl = tie($known_clients, 'IPC::Shareable', undef, {create => 1, +our $known_clients = {}; +our $shmcl = tie($known_clients, 'IPC::Shareable', undef, {create => 1, exclusive => 1, mode => 0666, destroy => 1, }); + %cfg_defaults = ("general" => {"log_file" => [\$log_file, "/var/run/".$0.".log"], @@ -105,8 +123,9 @@ $shmcl = tie($known_clients, 'IPC::Shareable', undef, {create => 1, }, "gosa" => {"gosa_activ" => [\$gosa_activ, "on"], - "gosa_fifo_in" => [\$gosa_fifo_in, "/etc/gosad/fifo/gosa_fifo_in"], - "gosa_fifo_out" => [\$gosa_fifo_out, "/etc/gosa/fifo/gosa_fifo_out"], + "gosa_ip" => [\$gosa_ip, "10.89.1.155"], + "gosa_port" => [\$gosa_port, "9999"], + "gosa_passwd" => [\$gosa_passwd, "none"], }, ); @@ -268,6 +287,60 @@ sub check_pid { } +#=== FUNCTION ================================================================ +# NAME: import_modules +# PARAMETERS: module_path - string - abs. path to the directory the modules are stored +# RETURNS: nothing +# DESCRIPTION: each file in module_path which ends with '.pm' is imported by "require 'file';" +#=============================================================================== +sub import_modules { + daemon_log(" ", 1); + + if (not -e $modules_path) { + daemon_log("ERROR: cannot find directory or directory is not readable: $modules_path", 1); + } + + opendir (DIR, $modules_path) or die "ERROR while loading modules from directory $modules_path : $!\n"; + while (defined (my $file = readdir (DIR))) { + if (not $file =~ /(\S*?).pm$/) { + next; + } + require $file; + my $mod_name = $1; + my $module_tag_hash = eval( $mod_name.'::get_module_tags()' ); + $known_modules->{$mod_name} = $module_tag_hash; + + daemon_log("load module $mod_name", 1); + } + + # for debugging + #while ( my ($module, $tag_hash) = each(%$known_modules)) { + # print "\tmodule: $module"."\n"; + # print "\ttags: ".join(", ", keys(%$tag_hash))."\n"; + #} + close (DIR); +} + + +#=== FUNCTION ================================================================ +# NAME: register_at_bus +# PARAMETERS: nothing +# RETURNS: nothing +# DESCRIPTION: creates an entry in known_daemons and send a 'here_i_am' msg to bus +#=============================================================================== +sub register_at_bus { + + # create known_daemons entry + &create_known_daemon($bus_address); + &add_content2known_daemons(hostname=>$bus_address, status=>"register_at_bus", passwd=>$bus_passwd); + daemon_log("register at bus: $bus_address", 1); + + my $msg_hash = &create_xml_hash("here_i_am", "$server_ip:$server_port", $bus_address); + &send_msg_hash2address($msg_hash, $bus_address); + return; +} + + #=== FUNCTION ================================================================ # NAME: sig_int_handler # PARAMETERS: signal - string - signal arose from system @@ -278,7 +351,7 @@ sub sig_int_handler { my ($signal) = @_; if($server){ close($server); - daemon_log("child closed", 1); + daemon_log("daemon server closed", 1); } if( -p $arp_fifo_path ) { close $arp_fifo ; @@ -286,20 +359,12 @@ sub sig_int_handler { daemon_log("ARP_FIFO closed", 1) ; } - if (-p $gosa_fifo_in) { - close GOSA_FIFO_IN; - unlink($gosa_fifo_in); - daemon_log("GOSA_FIFO_IN closed",1); - } - - if (-p $gosa_fifo_out) { - close GOSA_FIFO_OUT; - unlink($gosa_fifo_out); - daemon_log("GOSA_FIFO_OUT closed",1); + if($gosa_server){ + close($gosa_server); + daemon_log("gosa server closed", 1); } - - print "$signal\n"; + print STDERR "$signal\n"; exit(1); } @@ -314,13 +379,25 @@ $SIG{INT} = \&sig_int_handler; # DESCRIPTION: handels the distribution of incoming messages to working childs #=============================================================================== sub activating_child { - my ($msg, $host) = @_; + my ($msg, $host, $client) = @_; my $child = &get_processing_child(); my $pipe_wr = $$child{'pipe_wr'}; - + my $pipe_rd = $$child{'pipe_rd'}; + $$child{client_ref} = $client; daemon_log("activating: childpid:$$child{'pid'}", 5); print $pipe_wr $msg.".".$host."\n"; + +# if (defined $client) { +# my $rbits = ""; +# vec($rbits, fileno $client, 1) = 1; +# +# my ($rout); +# my $nf = select($rout=$rbits, undef, undef, $gosa_timeout); +# if($gosa_activ eq "on" && vec($rout, fileno $gosa_server, 1)) { +# +# } +# } return; } @@ -335,32 +412,31 @@ sub activating_child { sub get_processing_child { my $child; # checking %busy_child{pipe_wr} if msg is 'done', then set child from busy to free - while(my ($key, $val) = each(%busy_child)) { - # test ob prozess noch existiert - my $exitus_pid = waitpid($key, WNOHANG); - if($exitus_pid != 0) { - delete $busy_child{$key}; - print "prozess:$key wurde aus busy_child entfernt\n"; - next; - } - - # check wether process sitll works - my $fh = $$val{'pipe_rd'}; - $fh->blocking(0); - my $child_answer; - if(not $child_answer = <$fh>) { next } - chomp($child_answer); - if($child_answer eq "done") { - delete $busy_child{$key}; - $free_child{$key} = $val; - } - } +# while(my ($key, $val) = each(%busy_child)) { +# # test ob prozess noch existiert +# my $exitus_pid = waitpid($key, WNOHANG); +# if($exitus_pid != 0) { +# delete $busy_child{$key}; +# print "prozess:$key wurde aus busy_child entfernt\n"; +# next; +# } +# +# # check wether process sitll works +# my $fh = $$val{'pipe_rd'}; +# $fh->blocking(0); +# my $child_answer; +# if(not $child_answer = <$fh>) { next } +# chomp($child_answer); +# if($child_answer eq "done") { +# delete $busy_child{$key}; +# $free_child{$key} = $val; +# } +# } while(my ($key, $val) = each(%free_child)) { my $exitus_pid = waitpid($key, WNOHANG); if($exitus_pid != 0) { delete $free_child{$key}; - print "prozess:$key wurde aus free_child entfernt\n"; } daemon_log("free child:$key", 5); } @@ -430,10 +506,33 @@ sub get_processing_child { if(not defined $read) { last} $msg .= $read; } - &process_incoming_msg($msg); + + ###################################### + # forward msg to all imported modules + no strict "refs"; + my $answer; + while( my ($module, $tag_hash) = each(%$known_modules)) { + if(exists $known_modules->{$module}->{server_packages}) { + my $tmp = &{ $module."::process_incoming_msg" }($msg); + if (defined $tmp) { + $answer = $tmp; + } + } + } + + &print_known_daemons(); + &print_known_clients(); + daemon_log("processing of msg finished", 5); - daemon_log(" ", 5); - print $PARENT_wr "done"."\n"; + + if (defined $answer) { + print $PARENT_wr $answer."\n"; + daemon_log("\t$answer", 5); + daemon_log(" ", 5); + } else { + print $PARENT_wr "done"."\n"; + daemon_log(" ", 5); + } redo; } } @@ -452,6 +551,7 @@ sub get_processing_child { 'pid' => $child_pid, 'pipe_wr' => $CHILD_wr, 'pipe_rd' => $CHILD_rd, + 'client_ref' => "", ); $child = \%child_hash; @@ -478,8 +578,8 @@ sub process_incoming_msg { my $host = sprintf("%s.%s.%s.%s", $2, $3, $4, $5); daemon_log("msg from host:", 1); daemon_log("\t$host", 1); - daemon_log("crypted msg:", 7); - daemon_log("\t$crypted_msg", 7); + #daemon_log("crypted msg:", 7); + #daemon_log("\t$crypted_msg", 7); # collect addresses from possible incoming clients my @valid_keys; @@ -538,8 +638,8 @@ sub process_incoming_msg { daemon_log("header from msg:", 1); daemon_log("\t$header", 1); - daemon_log("msg to process:", 7); - daemon_log("\t$msg", 7); + daemon_log("msg to process:", 5); + daemon_log("\t$msg", 5); my @targets = @{$msg_hash->{target}}; my $len_targets = @targets; @@ -560,10 +660,11 @@ sub process_incoming_msg { elsif ($header eq 'who_has') { &who_has($msg_hash) } elsif ($header eq 'who_has_i_do') { &who_has_i_do($msg_hash)} elsif ($header eq 'update_status') { &update_status($msg_hash) } - elsif ($header eq 'got_ping') { &got_ping($msg_hash)} + #elsif ($header eq 'got_ping') { &got_ping($msg_hash)} elsif ($header eq 'get_load') { &execute_actions($msg_hash)} else { daemon_log("ERROR: no function assigned to this msg", 5) } + } elsif ($target eq "*") { # msg is for all clients @@ -610,10 +711,7 @@ sub process_incoming_msg { } - &print_known_daemons(); - &print_known_clients(); - daemon_log(" ", 1); - return; + return; } @@ -644,6 +742,24 @@ sub open_socket { } +#=== FUNCTION ================================================================ +# NAME: open_fifo +# PARAMETERS: $fifo_path +# RETURNS: 0: FIFO couldn"t be setup, 1: FIFO setup correctly +# DESCRIPTION: creates a FIFO at $fifo_path +#=============================================================================== +sub open_fifo { + my ($fifo_path) = @_ ; + if( -p $fifo_path ) { + daemon_log("FIFO at $fifo_path already exists! Is being deleted!", 1); + unlink($fifo_path); + } + POSIX::mkfifo($fifo_path, 0666) or die "can't mkfifo $fifo_path: $!"; + daemon_log( "FIFO started at $fifo_path", 1) ; + return 1; +} + + #=== FUNCTION ================================================================ # NAME: read_from_socket # PARAMETERS: socket fh - @@ -653,14 +769,23 @@ sub open_socket { sub read_from_socket { my ($socket) = @_; my $result = ""; - my $len = 16; - while($len == 16){ - my $char; - $len = sysread($socket, $char, 16); - if($len != 16) { last } - if($len != 16) { last } + + $socket->blocking(1); + $result = <$socket>; + + $socket->blocking(0); + while ( my $char = <$socket> ) { + if (not defined $char) { last } $result .= $char; } + +# my $len = 16; +# while($len == 16){ +# my $char; +# $len = sysread($socket, $char, 16); +# if($len != 16) { last } +# $result .= $char; +# } return $result; } @@ -698,9 +823,9 @@ sub create_xml_hash { sub create_xml_string { my ($xml_hash) = @_ ; my $xml_string = $xml->XMLout($xml_hash, RootName => 'xml'); - $xml_string =~ s/[\n]+//g; + #$xml_string =~ s/[\n]+//g; daemon_log("create_xml_string:",7); - daemon_log("\t$xml_string\n", 7); + daemon_log("$xml_string\n", 7); return $xml_string; } @@ -756,7 +881,7 @@ sub encrypt_msg { my $msg_length = length($msg); my $multiplier = int($msg_length / 16) + 1; my $extension = 16*$multiplier - $msg_length; - $msg = "a"x$extension.$msg; + $msg = $msg."\0"x$extension; my $crypted_msg = $my_cipher->encrypt($msg); #my $crypted_msg = $msg; return $crypted_msg; @@ -771,10 +896,10 @@ sub encrypt_msg { # DESCRIPTION: decrypts the incoming message with the Crypt::Rijndael module #=============================================================================== sub decrypt_msg { - my ($crypted_msg, $my_cipher) =@_; + my ($crypted_msg, $my_cipher) = @_ ; my $msg = $my_cipher->decrypt($crypted_msg); #my $msg = $crypted_msg; - $msg =~ s/^a*//gi; + #$msg =~ s/^a*//gi; return $msg; } @@ -838,14 +963,16 @@ sub send_msg_hash2address { if(not defined $socket){ daemon_log( "cannot send '$header'-msg to $address , server not reachable", 5); - if ($known_clients->{$address}->{status} eq "down") { - # if status of not reachable client is already 'down', then delete client from known_clients - &clean_up_known_clients($address); + if (exists $known_clients->{$address}) { + if ($known_clients->{$address}->{status} eq "down") { + # if status of not reachable client is already 'down', then delete client from known_clients + &clean_up_known_clients($address); - } else { - # update status to 'down' - &update_known_clients(hostname=>$address, status=>"down"); + } else { + # update status to 'down' + &update_known_clients(hostname=>$address, status=>"down"); + } } return; } @@ -855,9 +982,11 @@ sub send_msg_hash2address { close $socket; - daemon_log("send '$header'-msg to $address", 5); + daemon_log("send '$header'-msg to $address", 1); + + daemon_log("$msg_xml", 5); - #daemon_log("crypted_msg:",7); + #daemon_log("crypted message:",7); #daemon_log("\t$crypted_msg", 7); # update status of client in known_clients with last send msg @@ -884,7 +1013,7 @@ sub send_msg_hash2bus { my $header = &get_content_from_xml_hash($msg_hash, "header"); # generate xml string - my $msg_xml = $xml->XMLout($msg_hash, RootName => 'xml'); + my $msg_xml = &create_xml_string($msg_hash); # encrypt xml msg my $crypted_msg = &encrypt_msg($msg_xml, $bus_cipher); @@ -903,163 +1032,149 @@ sub send_msg_hash2bus { daemon_log("send '$header'-msg to bus", 1); - daemon_log("crypted msg:",7); - daemon_log("\t$crypted_msg", 7); - - return; -} - - - - -#=== FUNCTION ================================================================ -# NAME: register_at_bus -# PARAMETERS: nothing -# RETURNS: nothing -# DESCRIPTION: creates an entry in known_daemons and send a 'here_i_am' msg to bus -#=============================================================================== -sub register_at_bus { - - # create known_daemons entry - &create_known_daemon($bus_address); - &add_content2known_daemons(hostname=>$bus_address, status=>"register_at_bus", passwd=>$bus_passwd); - - my $msg_hash = &create_xml_hash("here_i_am", "$server_ip:$server_port", $bus_address); - &send_msg_hash2address($msg_hash, $bus_address); - return; -} - - -#=== FUNCTION ================================================================ -# NAME: new_passwd -# PARAMETERS: msg_hash - ref - hash from function create_xml_hash -# RETURNS: nothing -# DESCRIPTION: process this incoming message -#=============================================================================== -sub new_passwd { - my ($msg_hash) = @_; - - my $source = &get_content_from_xml_hash($msg_hash, "source"); - my $passwd = (&get_content_from_xml_hash($msg_hash, "new_passwd"))[0]; - - if (exists $known_daemons->{$source}) { - &add_content2known_daemons(hostname=>$source, status=>"new_passwd", passwd=>$passwd); - $bus_cipher = &create_ciphering($passwd); - my $hash = &create_xml_hash("confirm_new_passwd", "$server_ip:$server_port", "$source"); - &send_msg_hash2address($hash, $source); - - } elsif (exists $known_clients->{$source}) { - &add_content2known_clients(hostname=>$source, status=>"new_passwd", passwd=>$passwd); - - } else { - daemon_log("ERROR: $source not known, neither in known_daemons nor in known_clients", 1) - } - - return; -} - - -#=== FUNCTION ================================================================ -# NAME: make ping -# PARAMETERS: address - string - address which should be pinged -# RETURNS: nothing -# DESCRIPTION: send ping message to address -#=============================================================================== -sub make_ping { - my ($msg_hash) = @_; + daemon_log("$msg_xml", 5); + #daemon_log("crypted msg:",7); + #daemon_log("\t$crypted_msg", 7); - my $source = &get_content_from_xml_hash($msg_hash, "source"); - my $target = &get_content_from_xml_hash($msg_hash, "target"); - - print "make_ping:$source\n"; - my $out_hash = &create_xml_hash("ping", $target, $source); - &send_msg_hash2address($out_hash, $source); return; } -#=== FUNCTION ================================================================ -# NAME: got_ping -# PARAMETERS: msg_hash - hash - hash from function create_xml_hash -# RETURNS: nothing -# DESCRIPTION: process this incoming message -#=============================================================================== -sub got_ping { - my ($msg_hash) = @_; - - my $source = &get_content_from_xml_hash($msg_hash, 'source'); - my $target = &get_content_from_xml_hash($msg_hash, 'target'); - my $header = &get_content_from_xml_hash($msg_hash, 'header'); - - if(exists $known_daemons->{$source}) { - &add_content2known_daemons(hostname=>$source, status=>$header); - } else { - &add_content2known_clients(hostname=>$source, status=>$header); - } - - return; -} -#=== FUNCTION ================================================================ -# NAME: here_i_am -# PARAMETERS: msg_hash - hash - hash from function create_xml_hash -# RETURNS: nothing -# DESCRIPTION: process this incoming message -#=============================================================================== -sub here_i_am { - my ($msg_hash) = @_; - - my $source = &get_content_from_xml_hash($msg_hash, "source"); - my $mac_address = (&get_content_from_xml_hash($msg_hash, "mac_address"))[0]; - my $out_hash; - - # number of known clients - my $nu_clients = keys %$known_clients; - # check wether client address or mac address is already known - if (exists $known_clients->{$source}) { - daemon_log("WARNING: $source is already known as a client", 1); - daemon_log("WARNING: values for $source are being overwritten", 1); - $nu_clients --; - } - - # number of actual activ clients - my $act_nu_clients = $nu_clients; - - daemon_log("number of actual activ clients: $act_nu_clients", 5); - daemon_log("number of maximal allowed clients: $max_clients", 5); - if($max_clients <= $act_nu_clients) { - my $out_hash = &create_xml_hash("denied", $server_address, $source); - &add_content2xml_hash($out_hash, "denied", "I_cannot_take_any_more_clients!"); - my $passwd = (&get_content_from_xml_hash($msg_hash, "new_passwd"))[0]; - &send_msg_hash2address($out_hash, $source, $passwd); - return; - } - - # new client accepted - my $new_passwd = (&get_content_from_xml_hash($msg_hash, "new_passwd"))[0]; - # create known_daemons entry - my $events = (&get_content_from_xml_hash($msg_hash, "events"))[0]; - &create_known_client($source); - &add_content2known_clients(hostname=>$source, events=>$events, mac_address=>$mac_address, - status=>"registered", passwd=>$new_passwd); +##=== FUNCTION ================================================================ +## NAME: new_passwd +## PARAMETERS: msg_hash - ref - hash from function create_xml_hash +## RETURNS: nothing +## DESCRIPTION: process this incoming message +##=============================================================================== +#sub new_passwd { +# my ($msg_hash) = @_; +# +# my $source = &get_content_from_xml_hash($msg_hash, "source"); +# my $passwd = (&get_content_from_xml_hash($msg_hash, "new_passwd"))[0]; +# +# if (exists $known_daemons->{$source}) { +# &add_content2known_daemons(hostname=>$source, status=>"new_passwd", passwd=>$passwd); +# $bus_cipher = &create_ciphering($passwd); +# my $hash = &create_xml_hash("confirm_new_passwd", "$server_ip:$server_port", "$source"); +# &send_msg_hash2address($hash, $source); +# +# } elsif (exists $known_clients->{$source}) { +# &add_content2known_clients(hostname=>$source, status=>"new_passwd", passwd=>$passwd); +# +# } else { +# daemon_log("ERROR: $source not known, neither in known_daemons nor in known_clients", 1) +# } +# +# return; +#} - # return acknowledgement to client - $out_hash = &create_xml_hash("registered", $server_address, $source); - &send_msg_hash2address($out_hash, $source); - # notify registered client to bus - $out_hash = &create_xml_hash("new_client", $server_address, $bus_address, $source); - &send_msg_hash2bus($out_hash); +##=== FUNCTION ================================================================ +## NAME: make ping +## PARAMETERS: address - string - address which should be pinged +## RETURNS: nothing +## DESCRIPTION: send ping message to address +##=============================================================================== +#sub make_ping { +# my ($msg_hash) = @_; +# +# my $source = &get_content_from_xml_hash($msg_hash, "source"); +# my $target = &get_content_from_xml_hash($msg_hash, "target"); +# +# print "make_ping:$source\n"; +# my $out_hash = &create_xml_hash("ping", $target, $source); +# &send_msg_hash2address($out_hash, $source); +# return; +#} + + +##=== FUNCTION ================================================================ +## NAME: got_ping +## PARAMETERS: msg_hash - hash - hash from function create_xml_hash +## RETURNS: nothing +## DESCRIPTION: process this incoming message +##=============================================================================== +#sub got_ping { +# my ($msg_hash) = @_; +# +# my $source = &get_content_from_xml_hash($msg_hash, 'source'); +# my $target = &get_content_from_xml_hash($msg_hash, 'target'); +# my $header = &get_content_from_xml_hash($msg_hash, 'header'); +# +# if(exists $known_daemons->{$source}) { +# &add_content2known_daemons(hostname=>$source, status=>$header); +# } else { +# &add_content2known_clients(hostname=>$source, status=>$header); +# } +# +# return; +#} - # give the new client his ldap config - &new_ldap_config($source); - return; -} +##=== FUNCTION ================================================================ +## NAME: here_i_am +## PARAMETERS: msg_hash - hash - hash from function create_xml_hash +## RETURNS: nothing +## DESCRIPTION: process this incoming message +##=============================================================================== +#sub here_i_am { +# my ($msg_hash) = @_; +# +# my $source = &get_content_from_xml_hash($msg_hash, "source"); +# my $mac_address = (&get_content_from_xml_hash($msg_hash, "mac_address"))[0]; +# my $out_hash; +# +# # number of known clients +# my $nu_clients = keys %$known_clients; +# +# # check wether client address or mac address is already known +# if (exists $known_clients->{$source}) { +# daemon_log("WARNING: $source is already known as a client", 1); +# daemon_log("WARNING: values for $source are being overwritten", 1); +# $nu_clients --; +# } +# +# # number of actual activ clients +# my $act_nu_clients = $nu_clients; +# +# daemon_log("number of actual activ clients: $act_nu_clients", 5); +# daemon_log("number of maximal allowed clients: $max_clients", 5); +# +# if($max_clients <= $act_nu_clients) { +# my $out_hash = &create_xml_hash("denied", $server_address, $source); +# &add_content2xml_hash($out_hash, "denied", "I_cannot_take_any_more_clients!"); +# my $passwd = (&get_content_from_xml_hash($msg_hash, "new_passwd"))[0]; +# &send_msg_hash2address($out_hash, $source, $passwd); +# return; +# } +# +# # new client accepted +# my $new_passwd = (&get_content_from_xml_hash($msg_hash, "new_passwd"))[0]; +# +# # create known_daemons entry +# my $events = (&get_content_from_xml_hash($msg_hash, "events"))[0]; +# &create_known_client($source); +# &add_content2known_clients(hostname=>$source, events=>$events, mac_address=>$mac_address, +# status=>"registered", passwd=>$new_passwd); +# +# # return acknowledgement to client +# $out_hash = &create_xml_hash("registered", $server_address, $source); +# &send_msg_hash2address($out_hash, $source); +# +# # notify registered client to bus +# $out_hash = &create_xml_hash("new_client", $server_address, $bus_address, $source); +# &send_msg_hash2bus($out_hash); +# +# # give the new client his ldap config +# &new_ldap_config($source); +# +# return; +#} #=== FUNCTION ================================================================ @@ -1068,45 +1183,45 @@ sub here_i_am { # RETURNS: nothing # DESCRIPTION: process this incoming message #=============================================================================== -sub who_has { - my ($msg_hash) = @_ ; - - # what is your search pattern - my $search_pattern = (&get_content_from_xml_hash($msg_hash, "who_has"))[0]; - my $search_element = (&get_content_from_xml_hash($msg_hash, $search_pattern))[0]; - daemon_log("who_has-msg looking for $search_pattern $search_element", 7); - - # scanning known_clients for search_pattern - my @host_addresses = keys %$known_clients; - my $known_clients_entries = length @host_addresses; - my $host_address; - foreach my $host (@host_addresses) { - my $client_element = $known_clients->{$host}->{$search_pattern}; - if ($search_element eq $client_element) { - $host_address = $host; - last; - } - } - - # search was successful - if (defined $host_address) { - my $source = @{$msg_hash->{source}}[0]; - my $out_msg = &create_xml_hash("who_has_i_do", $server_address, $source, "mac_address"); - &add_content2xml_hash($out_msg, "mac_address", $search_element); - &send_msg_hash2address($out_msg, $bus_address); - } - return; -} +#sub who_has { +# my ($msg_hash) = @_ ; +# +# # what is your search pattern +# my $search_pattern = (&get_content_from_xml_hash($msg_hash, "who_has"))[0]; +# my $search_element = (&get_content_from_xml_hash($msg_hash, $search_pattern))[0]; +# daemon_log("who_has-msg looking for $search_pattern $search_element", 7); +# +# # scanning known_clients for search_pattern +# my @host_addresses = keys %$known_clients; +# my $known_clients_entries = length @host_addresses; +# my $host_address; +# foreach my $host (@host_addresses) { +# my $client_element = $known_clients->{$host}->{$search_pattern}; +# if ($search_element eq $client_element) { +# $host_address = $host; +# last; +# } +# } +# +# # search was successful +# if (defined $host_address) { +# my $source = @{$msg_hash->{source}}[0]; +# my $out_msg = &create_xml_hash("who_has_i_do", $server_address, $source, "mac_address"); +# &add_content2xml_hash($out_msg, "mac_address", $search_element); +# &send_msg_hash2address($out_msg, $bus_address); +# } +# return; +#} -sub who_has_i_do { - my ($msg_hash) = @_ ; - my $header = &get_content_from_xml_hash($msg_hash, "header"); - my $source = &get_content_from_xml_hash($msg_hash, "source"); - my $search_param = (&get_content_from_xml_hash($msg_hash, $header))[0]; - my $search_value = (&get_content_from_xml_hash($msg_hash, $search_param))[0]; - print "\ngot msg $header:\nserver $source has client with $search_param $search_value\n"; -} +#sub who_has_i_do { +# my ($msg_hash) = @_ ; +# my $header = &get_content_from_xml_hash($msg_hash, "header"); +# my $source = &get_content_from_xml_hash($msg_hash, "source"); +# my $search_param = (&get_content_from_xml_hash($msg_hash, $header))[0]; +# my $search_value = (&get_content_from_xml_hash($msg_hash, $search_param))[0]; +# print "\ngot msg $header:\nserver $source has client with $search_param $search_value\n"; +#} #=== FUNCTION ================================================================ @@ -1115,159 +1230,159 @@ sub who_has_i_do { # RETURNS: nothing # DESCRIPTION: process this incoming message #=============================================================================== -sub update_status { - my ($msg_hash) = @_; - my $header = &get_content_from_xml_hash($msg_hash, "header"); - my $source = &get_content_from_xml_hash($msg_hash, "source"); - my $new_status = (&get_content_from_xml_hash($msg_hash, "update_status"))[0]; - - # find the source - my $act_known_hash; - if (exists $known_daemons->{$source}) { - - &add_content2known_daemons(hostname=>$source, status=>$new_status); - } elsif (exists $known_clients->{$source}) { - &update_known_clients(hostname=>$source, status=>$new_status); - #&add_content2known_clients(hostname=>$source, status=>$new_status); - } else { - daemon_log("ERROR: got $header-msg, but cannot find $source in my hashes, unable to update status", 1); - return; - } - - return; -} - - -#=== FUNCTION ================================================================ -# NAME: new_ldap_config -# PARAMETERS: address - string - ip address and port of a host -# RETURNS: nothing -# DESCRIPTION: send to address the ldap configuration found for dn gotoLdapServer -#=============================================================================== -sub new_ldap_config { - my ($address) = @_ ; - - if (not exists $known_clients->{$address}) { - daemon_log("ERROR: $address does not exist in known_clients, cannot send him his ldap config", 1); - return; - } - - my $mac_address = $known_clients->{$address}->{"mac_address"}; - if (not defined $mac_address) { - daemon_log("ERROR: no mac address found for client $address", 1); - return; - } - - # fetch dn - my $goHard_cmd = "ldapsearch -x '(&(objectClass=goHard)(macAddress=00:11:22:33:44:57))' dn gotoLdapServer"; - my $dn; - my @gotoLdapServer; - open (PIPE, "$goHard_cmd 2>&1 |"); - while() { - chomp $_; - # If it's a comment, goto next - if ($_ =~ m/^[#]/) { next;} - if ($_ =~ m/^dn: ([\S]+?)$/) { - $dn = $1; - } elsif ($_ =~ m/^gotoLdapServer: ([\S]+?)$/) { - push(@gotoLdapServer, $1); - } - } - close(PIPE); - - # no dn found - if (not defined $dn) { - daemon_log("ERROR: no dn arose from command: $goHard_cmd", 1); - return; - } - - # no gotoLdapServer found - my $gosaGroupOfNames_cmd = "ldapsearch -x '(&(objectClass=gosaGroupOfNames)(member=$dn))' gotoLdapServer"; - if (@gotoLdapServer == 0) { - open (PIPE, "$gosaGroupOfNames_cmd 2>&1 |"); - while() { - chomp $_; - if ($_ =~ m/^[#]/) { next; } - if ($_ =~ m/^gotoLdapServer: ([\S]+?)$/) { - push(@gotoLdapServer, $1); - } - } - close(PIPE); - } - - # still no gotoLdapServer found - if (@gotoLdapServer == 0) { - daemon_log("ERROR: cannot find gotoLdapServer entry in command: $gosaGroupOfNames_cmd", 1); - return; - } - - # sort @gotoLdapServer and then split of ranking - my @sorted_gotoLdapServer = sort(@gotoLdapServer); - @gotoLdapServer = reverse(@sorted_gotoLdapServer); - foreach (@gotoLdapServer) { - $_ =~ s/^\d://; - } - - my $t = join(" ", @gotoLdapServer); - - my $out_hash = &create_xml_hash("new_ldap_config", $server_address, $address); - map(&add_content2xml_hash($out_hash, "new_ldap_config", $_), @gotoLdapServer); - &send_msg_hash2address($out_hash, $address); - - return; -} - - -#=== FUNCTION ================================================================ -# NAME: execute_actions -# PARAMETERS: msg_hash - hash - hash from function create_xml_hash -# RETURNS: nothing -# DESCRIPTION: invokes the script specified in msg_hash which is located under -# /etc/gosad/actions -#=============================================================================== -sub execute_actions { - my ($msg_hash) = @_ ; - my $configdir= '/etc/gosad/actions/'; - my $result; - - my $header = &get_content_from_xml_hash($msg_hash, 'header'); - my $source = &get_content_from_xml_hash($msg_hash, 'source'); - my $target = &get_content_from_xml_hash($msg_hash, 'target'); - - - if((not defined $source) - && (not defined $target) - && (not defined $header)) { - daemon_log("ERROR: Entries missing in XML msg for gosad actions under /etc/gosad/actions"); - } else { - my $parameters=""; - my @params = &get_content_from_xml_hash($msg_hash, $header); - my $params = join(", ", @params); - daemon_log("execute_actions: got parameters: $params", 5); - - if (@params) { - foreach my $param (@params) { - my $param_value = (&get_content_from_xml_hash($msg_hash, $param))[0]; - daemon_log("execute_actions: parameter -> value: $param -> $param_value", 7); - $parameters.= " ".$param_value; - } - } - - my $cmd= $configdir.$header."$parameters"; - daemon_log("execute_actions: executing cmd: $cmd", 7); - $result= ""; - open(PIPE, "$cmd 2>&1 |"); - while() { - $result.=$_; - } - close(PIPE); - } - - # process the event result - - - return; -} +#sub update_status { +# my ($msg_hash) = @_; +# my $header = &get_content_from_xml_hash($msg_hash, "header"); +# my $source = &get_content_from_xml_hash($msg_hash, "source"); +# my $new_status = (&get_content_from_xml_hash($msg_hash, "update_status"))[0]; +# +# # find the source +# my $act_known_hash; +# if (exists $known_daemons->{$source}) { +# +# &add_content2known_daemons(hostname=>$source, status=>$new_status); +# } elsif (exists $known_clients->{$source}) { +# &update_known_clients(hostname=>$source, status=>$new_status); +# #&add_content2known_clients(hostname=>$source, status=>$new_status); +# } else { +# daemon_log("ERROR: got $header-msg, but cannot find $source in my hashes, unable to update status", 1); +# return; +# } +# +# return; +#} + + +##=== FUNCTION ================================================================ +## NAME: new_ldap_config +## PARAMETERS: address - string - ip address and port of a host +## RETURNS: nothing +## DESCRIPTION: send to address the ldap configuration found for dn gotoLdapServer +##=============================================================================== +#sub new_ldap_config { +# my ($address) = @_ ; +# +# if (not exists $known_clients->{$address}) { +# daemon_log("ERROR: $address does not exist in known_clients, cannot send him his ldap config", 1); +# return; +# } +# +# my $mac_address = $known_clients->{$address}->{"mac_address"}; +# if (not defined $mac_address) { +# daemon_log("ERROR: no mac address found for client $address", 1); +# return; +# } +# +# # fetch dn +# my $goHard_cmd = "ldapsearch -x '(&(objectClass=goHard)(macAddress=00:11:22:33:44:57))' dn gotoLdapServer"; +# my $dn; +# my @gotoLdapServer; +# open (PIPE, "$goHard_cmd 2>&1 |"); +# while() { +# chomp $_; +# # If it's a comment, goto next +# if ($_ =~ m/^[#]/) { next;} +# if ($_ =~ m/^dn: ([\S]+?)$/) { +# $dn = $1; +# } elsif ($_ =~ m/^gotoLdapServer: ([\S]+?)$/) { +# push(@gotoLdapServer, $1); +# } +# } +# close(PIPE); +# +# # no dn found +# if (not defined $dn) { +# daemon_log("ERROR: no dn arose from command: $goHard_cmd", 1); +# return; +# } +# +# # no gotoLdapServer found +# my $gosaGroupOfNames_cmd = "ldapsearch -x '(&(objectClass=gosaGroupOfNames)(member=$dn))' gotoLdapServer"; +# if (@gotoLdapServer == 0) { +# open (PIPE, "$gosaGroupOfNames_cmd 2>&1 |"); +# while() { +# chomp $_; +# if ($_ =~ m/^[#]/) { next; } +# if ($_ =~ m/^gotoLdapServer: ([\S]+?)$/) { +# push(@gotoLdapServer, $1); +# } +# } +# close(PIPE); +# } +# +# # still no gotoLdapServer found +# if (@gotoLdapServer == 0) { +# daemon_log("ERROR: cannot find gotoLdapServer entry in command: $gosaGroupOfNames_cmd", 1); +# return; +# } +# +# # sort @gotoLdapServer and then split of ranking +# my @sorted_gotoLdapServer = sort(@gotoLdapServer); +# @gotoLdapServer = reverse(@sorted_gotoLdapServer); +# foreach (@gotoLdapServer) { +# $_ =~ s/^\d://; +# } +# +# my $t = join(" ", @gotoLdapServer); +# +# my $out_hash = &create_xml_hash("new_ldap_config", $server_address, $address); +# map(&add_content2xml_hash($out_hash, "new_ldap_config", $_), @gotoLdapServer); +# &send_msg_hash2address($out_hash, $address); +# +# return; +#} + + +##=== FUNCTION ================================================================ +## NAME: execute_actions +## PARAMETERS: msg_hash - hash - hash from function create_xml_hash +## RETURNS: nothing +## DESCRIPTION: invokes the script specified in msg_hash which is located under +## /etc/gosad/actions +##=============================================================================== +#sub execute_actions { +# my ($msg_hash) = @_ ; +# my $configdir= '/etc/gosad/actions/'; +# my $result; +# +# my $header = &get_content_from_xml_hash($msg_hash, 'header'); +# my $source = &get_content_from_xml_hash($msg_hash, 'source'); +# my $target = &get_content_from_xml_hash($msg_hash, 'target'); +# +# +# if((not defined $source) +# && (not defined $target) +# && (not defined $header)) { +# daemon_log("ERROR: Entries missing in XML msg for gosad actions under /etc/gosad/actions"); +# } else { +# my $parameters=""; +# my @params = &get_content_from_xml_hash($msg_hash, $header); +# my $params = join(", ", @params); +# daemon_log("execute_actions: got parameters: $params", 5); +# +# if (@params) { +# foreach my $param (@params) { +# my $param_value = (&get_content_from_xml_hash($msg_hash, $param))[0]; +# daemon_log("execute_actions: parameter -> value: $param -> $param_value", 7); +# $parameters.= " ".$param_value; +# } +# } +# +# my $cmd= $configdir.$header."$parameters"; +# daemon_log("execute_actions: executing cmd: $cmd", 7); +# $result= ""; +# open(PIPE, "$cmd 2>&1 |"); +# while() { +# $result.=$_; +# } +# close(PIPE); +# } +# +# # process the event result +# +# +# return; +#} #=== FUNCTION ================================================================ @@ -1277,15 +1392,12 @@ sub execute_actions { # DESCRIPTION: nomen est omen #=============================================================================== sub print_known_daemons { - #my ($hash) = @_; + my ($tmp) = @_ ; print "####################################\n"; print "# status of known_daemons\n"; - #my $hosts; - #my $host_hash; $shmda->shlock(LOCK_EX); my @hosts = keys %$known_daemons; foreach my $host (@hosts) { - #my @elements = keys %$known_daemons->{$host}; my $status = $known_daemons->{$host}->{status} ; my $passwd = $known_daemons->{$host}->{passwd}; my $timestamp = $known_daemons->{$host}->{timestamp}; @@ -1426,11 +1538,9 @@ sub update_known_daemons { # DESCRIPTION: nomen est omen #=============================================================================== sub print_known_clients { - #my ($hash) = @_; + print "####################################\n"; print "# status of known_clients\n"; - #my $hosts; - #my $host_hash; $shmcl->shlock(LOCK_EX); my @hosts = keys %$known_clients; if (@hosts) { @@ -1615,23 +1725,6 @@ sub update_known_clients { } -#=== FUNCTION ================================================================ -# NAME: open_fifo -# PARAMETERS: $fifo_path -# RETURNS: 0: FIFO couldn"t be setup, 1: FIFO setup correctly -# DESCRIPTION: creates a FIFO at $fifo_path -#=============================================================================== -sub open_fifo { - my ($fifo_path) = @_ ; - if( -p $fifo_path ) { - daemon_log("FIFO at $fifo_path already exists! Is being deleted!", 1); - unlink($fifo_path); - } - POSIX::mkfifo($fifo_path, 0666) or die "can't mkfifo $fifo_path: $!"; - daemon_log( "FIFO started at $fifo_path", 1) ; - return 1; -} - @@ -1651,12 +1744,14 @@ GetOptions("h|help" => \&usage, &check_cmdline_param ; &read_configfile; &check_pid; +&import_modules; $SIG{CHLD} = 'IGNORE'; # restart daemon log file if(-e $log_file ) { unlink $log_file } -daemon_log("started!"); +daemon_log(" ", 1); +daemon_log("gosad started!", 1); # Just fork, if we"re not in foreground mode if( ! $foreground ) { $pid = fork(); } @@ -1666,7 +1761,7 @@ else { $pid = $$; } if( 0 != $pid ) { open( LOCK_FILE, ">$pid_file" ); print LOCK_FILE "$pid\n"; - close( LOCK_FILE ); +close( LOCK_FILE ); if( !$foreground ) { exit( 0 ) }; } @@ -1683,6 +1778,7 @@ my $rbits = my $wbits = my $ebits = ""; # open server socket $server_address = "$server_ip:$server_port"; if($server_activ eq "on"){ + daemon_log(" ", 1); $server = IO::Socket::INET->new(LocalPort => $server_port, Type => SOCK_STREAM, Reuse => 1, @@ -1696,14 +1792,17 @@ if($server_activ eq "on"){ vec($rbits, fileno $server, 1) = 1; vec($wbits, fileno $server, 1) = 1; } - &print_known_clients() } # register at bus if($bus_activ eq "on") { + daemon_log(" ", 1); ®ister_at_bus(); } + +daemon_log(" ", 1); + # start arp fifo my $my_fifo; if($arp_activ eq "on") { @@ -1714,14 +1813,31 @@ if($arp_activ eq "on") { vec($rbits, fileno $arp_fifo, 1) = 1; } -# start gosa inferface fifo +$gosa_address = "$gosa_ip:$gosa_port"; +# start gosa inferface fifos if ($gosa_activ eq "on") { - &open_fifo($gosa_fifo_in); - sysopen(GOSA_FIFO_IN, $gosa_fifo_in, O_RDWR) or die "can't read from GOSA_FIFO_IN: $!" ; - vec($rbits, fileno GOSA_FIFO_IN, 1) = 1; + daemon_log(" ",1); + $gosa_server = IO::Socket::INET->new(LocalPort => $gosa_port, + Type => SOCK_STREAM, + Reuse => 1, + Listen => 1, + ); + if (not defined $gosa_server) { + daemon_log("cannot start tcp server at $gosa_port for communication to gosa: $@", 1); + } else { + daemon_log("start server at for communication to gosa", 1); + daemon_log("\t$server_ip:$gosa_port"); + vec($rbits, fileno $gosa_server, 1) = 1; + + } + + + #&open_fifo($gosa_fifo_in); + #sysopen(GOSA_FIFO_IN, $gosa_fifo_in, O_RDWR) or die "can't read from GOSA_FIFO_IN: $!" ; + #vec($rbits, fileno GOSA_FIFO_IN, 1) = 1; - &open_fifo($gosa_fifo_out); - sysopen(GOSA_FIFO_OUT, $gosa_fifo_out, O_RDWR) or die "can't read from GOSA_FIFO_IN: $!" ; + #&open_fifo($gosa_fifo_out); + #sysopen(GOSA_FIFO_OUT, $gosa_fifo_out, O_RDWR) or die "can't read from GOSA_FIFO_IN: $!" ; } @@ -1730,33 +1846,50 @@ if ($gosa_activ eq "on") { #everything ready, okay, lets start ################################### while(1) { + + # add all handles from the childs + while ( my ($pid, $child_hash) = each %busy_child ) { + + # check whether process still exists + my $exitus_pid = waitpid($pid, WNOHANG); + if($exitus_pid != 0) { + delete $busy_child{$pid}; + next; + } + + # add child fhd to the listener + my $fhd = $$child_hash{'pipe_rd'}; + vec($rbits, fileno $fhd, 1) = 1; + } + my ($rout, $wout); my $nf = select($rout=$rbits, $wout=$wbits, undef, undef); -# error handling + # error handling if($nf < 0 ) { } # something is coming in if($server_activ eq "on" && vec($rout, fileno $server, 1)) { - my $client = $server->accept(); - my $other_end = getpeername($client); - if(not defined $other_end) { - daemon_log("client cannot be identified: $!"); + daemon_log(" ", 1); + my $client = $server->accept(); + my $other_end = getpeername($client); + if(not defined $other_end) { + daemon_log("client cannot be identified: $!"); + } else { + my ($port, $iaddr) = unpack_sockaddr_in($other_end); + my $actual_ip = inet_ntoa($iaddr); + daemon_log("accept client from $actual_ip", 5); + my $in_msg = &read_from_socket($client); + if(defined $in_msg){ + chomp($in_msg); + &activating_child($in_msg, $actual_ip); } else { - my ($port, $iaddr) = unpack_sockaddr_in($other_end); - my $actual_ip = inet_ntoa($iaddr); - daemon_log("accept client from $actual_ip", 5); - my $in_msg = &read_from_socket($client); - if(defined $in_msg){ - chomp($in_msg); - &activating_child($in_msg, $actual_ip); - } else { - daemon_log("cannot read from $actual_ip", 5); - } + daemon_log("cannot read from $actual_ip", 5); } - close($client); } + close($client); + } if($arp_activ eq "on" && vec($rout, fileno $arp_fifo, 1)) { my $in_msg = <$arp_fifo>; @@ -1781,27 +1914,53 @@ while(1) { print "\n"; } - if($gosa_activ eq "on" && vec($rout, fileno GOSA_FIFO_IN, 1)) { - my $in_msg = ; - chomp($in_msg); - print "gosa_activ: msg: $in_msg\n"; -# my $act_passwd = $known_daemons->{$bus_address}->{passwd}; -# print "arp_activ: arp_passwd: $act_passwd\n"; -# -# my $in_msg_hash = $xml->XMLin($in_msg, ForceArray=>1); -# -# my $target = &get_content_from_xml_hash($in_msg_hash, 'target'); -# -# if ($target eq $server_address) { -# print "arp_activ: forward to server\n"; -# my $arp_cipher = &create_ciphering($act_passwd); -# my $crypted_msg = &encrypt_msg($in_msg, $arp_cipher); -# &activating_child($crypted_msg, $server_ip); -# } else { -# print "arp_activ: send to bus\n"; -# &send_msg_hash2address($in_msg_hash, $bus_address); -# } -# print "\n"; + if($gosa_activ eq "on" && vec($rout, fileno $gosa_server, 1)) { + daemon_log(" ", 1); + my $client = $gosa_server->accept(); + my $other_end = getpeername($client); + if(not defined $other_end) { + daemon_log("client cannot be identified: $!"); + } else { + my ($port, $iaddr) = unpack_sockaddr_in($other_end); + my $actual_ip = inet_ntoa($iaddr); + daemon_log("accept client from $actual_ip", 5); + my $in_msg = <$client>; + #my $in_msg = &read_from_socket($client); + if(defined $in_msg){ + chomp($in_msg); + &activating_child($in_msg, $actual_ip, $client); + } else { + daemon_log("cannot read from $actual_ip", 5); + } + } + #close($client); + } + + # check all processing childs whether they are finished ('done') or + while ( my ($pid, $child_hash) = each %busy_child ) { + my $fhd = $$child_hash{'pipe_rd'}; + + if (vec($rout, fileno $fhd, 1) ) { + daemon_log("process child $pid is ready to read", 5); + chomp( my $in_msg = <$fhd> ); + daemon_log("process child read: $in_msg\n", 5); + if (not defined $in_msg) { + next; + } elsif ($in_msg eq "done") { + delete $busy_child{$pid}; + $free_child{$pid} = $child_hash; + + } else { + my $act_client = $busy_child{$pid}{client_ref}; + print $act_client $in_msg."\n"; + my $act_pipe = $busy_child{$pid}{pipe_rd}; + close ($act_client); + delete $busy_child{$pid}; + $free_child{$pid} = $child_hash; + + } + } } + } diff --git a/contrib/daemon/gosa-sd-bus b/contrib/daemon/gosa-sd-bus index e3fd1a123..6035fb4a3 100755 --- a/contrib/daemon/gosa-sd-bus +++ b/contrib/daemon/gosa-sd-bus @@ -452,7 +452,7 @@ sub process_incoming_msg { my $target = &get_content_from_xml_hash($msg_hash, "target"); daemon_log("header from msg:\n\t$header", 1); - daemon_log("msg to process:\n\t$msg", 7); + daemon_log("msg to process:\n\t$msg", 5); daemon_log("msg is for: \n\t$target", 7); if($target eq $bus_address) { @@ -541,7 +541,7 @@ sub encrypt_msg { my $msg_length = length($msg); my $multiplier = int($msg_length / 16) + 1; my $extension = 16*$multiplier - $msg_length; - $msg = "a"x$extension.$msg; + $msg = $msg."\0"x$extension; my $crypted_msg = $my_cipher->encrypt($msg); #my $crypted_msg = $msg; return $crypted_msg; @@ -560,7 +560,7 @@ sub decrypt_msg { my $len = length $crypted_msg; my $msg = $my_cipher->decrypt($crypted_msg); #my $msg = $crypted_msg; - $msg =~ s/^a*//gi; + #$msg =~ s/^a*//gi; return $msg; } @@ -869,6 +869,7 @@ sub confirm_new_passwd { sub ping { my ($msg_hash) = @_ ; my $source = &get_content_from_xml_hash($msg_hash, "source"); + &update_known_daemons_entry(hostname=>$source, status=>"ping"); my $out_hash = &create_xml_hash("got_ping", $bus_address, $source); &send_msg_hash2address($out_hash, $source); return; diff --git a/contrib/daemon/gosa-sd.cfg b/contrib/daemon/gosa-sd.cfg index 5fa22df5a..0dbb8c552 100644 --- a/contrib/daemon/gosa-sd.cfg +++ b/contrib/daemon/gosa-sd.cfg @@ -24,6 +24,10 @@ arp_fifo_path = /etc/gosad/fifo/arp_fifo [gosa] gosa_activ = on -gosa_fifo_in = /etc/gosad/fifo/gosa_fifo_in -gosa_fifo_out = /etc/gosad/fifo/gosa_fifo_out +gosa_ip = 10.89.1.155 +gosa_port = 9999 + # passwd questions to gosad has to be crypted with +gosa_passwd = ferdinand_frost + # seconds to wait for an answer from gosad +gosa_timeout = 5 -- 2.30.2