From a236ccfa68ffd9efad0243fa61c5f025995be1c9 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Wed, 9 Jan 2008 17:56:19 +0000 Subject: [PATCH] fix bug: update known_clients at gosa-si/gosa-si-server git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8278 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 101 +++++++++++++++--------------- gosa-si/modules/DBsqlite.pm | 10 --- gosa-si/modules/GosaPackages.pm | 1 - gosa-si/modules/ServerPackages.pm | 33 ++++++---- gosa-si/tests/client.php | 4 +- 5 files changed, 73 insertions(+), 76 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 3993ca464..2d4b84d48 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -218,7 +218,7 @@ sub daemon_log { chomp($msg); if($level <= $verbose){ print LOG_HANDLE "$level $msg\n"; - if(defined $foreground) { print $msg."\n" } + if($foreground) { print $msg."\n" } } } # close( LOG_HANDLE ); @@ -601,25 +601,25 @@ sub read_from_socket { # RETURNS: nothing # DESCRIPTION: nomen est omen #=============================================================================== -sub print_known_daemons { - my ($tmp) = @_ ; - print "####################################\n"; - print "# status of known_daemons\n"; - $shmda->shlock(LOCK_EX); - my @hosts = keys %$known_daemons; - foreach my $host (@hosts) { - my $status = $known_daemons->{$host}->{status} ; - my $passwd = $known_daemons->{$host}->{passwd}; - my $timestamp = $known_daemons->{$host}->{timestamp}; - print "$host\n"; - print "\tstatus: $status\n"; - print "\tpasswd: $passwd\n"; - print "\ttimestamp: $timestamp\n"; - } - $shmda->shunlock(LOCK_EX); - print "####################################\n"; - return; -} +#sub print_known_daemons { +# my ($tmp) = @_ ; +# print "####################################\n"; +# print "# status of known_daemons\n"; +# $shmda->shlock(LOCK_EX); +# my @hosts = keys %$known_daemons; +# foreach my $host (@hosts) { +# my $status = $known_daemons->{$host}->{status} ; +# my $passwd = $known_daemons->{$host}->{passwd}; +# my $timestamp = $known_daemons->{$host}->{timestamp}; +# print "$host\n"; +# print "\tstatus: $status\n"; +# print "\tpasswd: $passwd\n"; +# print "\ttimestamp: $timestamp\n"; +# } +# $shmda->shunlock(LOCK_EX); +# print "####################################\n"; +# return; +#} #=== FUNCTION ================================================================ @@ -979,15 +979,20 @@ daemon_log(" ", 1); daemon_log("$0 started!", 1); # Just fork, if we"re not in foreground mode -if( ! $foreground ) { $pid = fork(); } -else { $pid = $$; } +if( ! $foreground ) { + $pid = fork(); +} else { + $pid = $$; +} # Do something useful - put our PID into the pid_file if( 0 != $pid ) { open( LOCK_FILE, ">$pid_file" ); print LOCK_FILE "$pid\n"; -close( LOCK_FILE ); - if( !$foreground ) { exit( 0 ) }; + close( LOCK_FILE ); + if( !$foreground ) { + exit( 0 ) + }; } # connect to gosa-si job queue @@ -1063,28 +1068,28 @@ while(1) { } - if($arp_activ eq "on" && vec($rout, fileno $arp_fifo, 1)) { - my $in_msg = <$arp_fifo>; - chomp($in_msg); - print "arp_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($arp_activ eq "on" && vec($rout, fileno $arp_fifo, 1)) { +# my $in_msg = <$arp_fifo>; +# chomp($in_msg); +# print "arp_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"; +# } # check input fhd of all modules @@ -1109,8 +1114,6 @@ while(1) { daemon_log("cannot read from $actual_ip", 5); } } - #close($client); - } } @@ -1194,13 +1197,11 @@ while(1) { } # add target - print "select: target: $target\n"; &add_content2xml_hash($out_msg_hash, "target", $target); # add new header my $out_header = $job_msg_hash->{header}[0]; $out_header =~ s/job_/gosa_/; - print "select: header: $out_header\n"; delete $out_msg_hash->{header}; &add_content2xml_hash($out_msg_hash, "header", $out_header); diff --git a/gosa-si/modules/DBsqlite.pm b/gosa-si/modules/DBsqlite.pm index 9f341ec5e..db717fa7d 100644 --- a/gosa-si/modules/DBsqlite.pm +++ b/gosa-si/modules/DBsqlite.pm @@ -71,20 +71,10 @@ sub add_dbentry { if (exists $arg->{$col_name}) { push(@add_list, $arg->{$col_name}); } - # use default values for column values -# } else { -# my $default_val = "none"; -# if ($col_name eq "timestamp") { -# $default_val = "19700101000000"; -# } -# push(@add_list, $default_val); -# } } my $sql_statement = " INSERT INTO $table VALUES ('".join("', '", @add_list)."')"; - print " INSERT INTO $table VALUES ('".join("', '", @add_list)."')\n"; my $db_res = $obj->{dbh}->do($sql_statement); - print " DB result: $db_res\n"; return 0; } diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index eea707322..255022e3d 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -444,7 +444,6 @@ sub update_status_jobdb_entry { return "<1>1"; } $update_hash->{update} = [ { status=>$msg_hash->{update}[0]->{status} } ]; - #$update_hash->{update} = $msg_hash->{update}; # execute db query my $db_res = $main::job_db->update_dbentry($update_hash); diff --git a/gosa-si/modules/ServerPackages.pm b/gosa-si/modules/ServerPackages.pm index 7797dc404..e3bee1793 100644 --- a/gosa-si/modules/ServerPackages.pm +++ b/gosa-si/modules/ServerPackages.pm @@ -487,17 +487,17 @@ sub here_i_am { timestamp=>&get_time, } ); if ($res == 3) { - $res = $main::known_clients_db->update_dbentry( {table=>'known_clients', - where=>'hostname', - hostname=>$source, - events=>$events, - macaddress=>$mac_address, - status=>'registered', - hostkey=>$new_passwd, - timestamp=>&get_time, - } ); + my $update_hash = { table=>'known_clients' }; + $update_hash->{where} = [ { hostname=>[$source] } ], + $update_hash->{update} = [ { events=>[$events], + macaddress=>[$mac_address], + status=>['registered'], + hostkey=>[$new_passwd], + timestamp=>[&get_time], + } ]; + $res = $main::known_clients_db->update_dbentry( $update_hash ); } - if ($res > 0) { + if ($res != 1) { &main::daemon_log("ERROR: cannot add entry to known_clients: $res"); return; } @@ -507,8 +507,11 @@ sub here_i_am { &send_msg_hash2address($out_hash, $source, $new_passwd); # notify registered client to bus - $out_hash = &create_xml_hash("new_client", $server_address, $bus_address, $source); - &send_msg_hash2address($out_hash, $bus_address); + if( $bus_activ eq "on") { + &main::daemon_log("send bus msg that client '$source' has registerd at server '$server_address'", 3); + $out_hash = &create_xml_hash("new_client", $server_address, $bus_address, $source); + &send_msg_hash2address($out_hash, $bus_address); + } # give the new client his ldap config &new_ldap_config($source); @@ -606,7 +609,11 @@ sub new_ldap_config { # Sanity check if ($mesg->count != 1) { - &main::daemon_log("WARNING: client mac address $macaddress not found/not unique", 1); + &main::daemon_log("WARNING: client mac address $macaddress not found/not unique in ldap search", 1); + &main::daemon_log("\tbase: $ldap_base", 1); + &main::daemon_log("\tscope: sub", 1); + &main::daemon_log("\tattrs: dn, gotoLdapServer", 1); + &main::daemon_log("\tfilter: (&(objectClass=GOhard)(macaddress=$macaddress))", 1); return; } diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index b52a4d8f3..0384e9535 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -15,7 +15,7 @@ if($sock->connected()){ #$data = "
gosa_ping
10.89.1.155:2008211:22:33:44:55
"; #$data = "
job_ping
10.89.1.155:2008300:1B:77:04:8A:6C 19700101000000
"; #$data = "
job_sayHello
10.89.1.155:2008300:1B:77:04:8A:6C 20130102133900
"; - $data = "
job_ping
10.89.1.155:2008300:1B:77:04:8A:6C 20130102133900
"; + #$data = "
job_ping
10.89.1.155:2008300:1B:77:04:8A:6C 20130102133900
"; # delete #$data = "
gosa_delete_jobdb_entry
headertag sayHello
"; @@ -29,7 +29,7 @@ if($sock->connected()){ #$data = "
gosa_query_jobdb
statuswaiting
"; # clear - #$data = "
gosa_clear_jobdb
"; + $data = "
gosa_clear_jobdb
"; $sock->write($data); -- 2.30.2