From 7a12ce5e3ec781ac7bd0ce9c4fed8c3e8cb883cc Mon Sep 17 00:00:00 2001 From: janw Date: Tue, 5 May 2009 13:53:24 +0000 Subject: [PATCH] Removed unneeded use of ldap handles. Fixed typos. Fixed sql statements. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13606 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/modules/ArpHandler.pm | 1 - gosa-si/modules/ClientPackages.pm | 64 +++++++++++++++++--------- gosa-si/modules/GosaPackages.pm | 16 ++++--- gosa-si/server/events/clMessages.pm | 17 ++++--- gosa-si/server/events/gosaTriggered.pm | 27 +++++++---- gosa-si/server/events/siTriggered.pm | 5 +- 6 files changed, 83 insertions(+), 47 deletions(-) diff --git a/gosa-si/modules/ArpHandler.pm b/gosa-si/modules/ArpHandler.pm index 03a55ec9a..7780d2adc 100644 --- a/gosa-si/modules/ArpHandler.pm +++ b/gosa-si/modules/ArpHandler.pm @@ -78,7 +78,6 @@ sub local_read_configfile { } sub get_module_info { - my ($ldap_handle) = @_; my @info = (undef, undef); &local_read_configfile(); diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index b746316cb..62662fa3b 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -262,7 +262,7 @@ sub get_mac { # DESCRIPTION: handels the proceeded distribution to the appropriated functions #=============================================================================== sub process_incoming_msg { - my ($msg, $msg_hash, $session_id, $ldap_handle) = @_ ; + my ($msg, $msg_hash, $session_id) = @_ ; my $error = 0; my $host_name; my $host_key; @@ -282,21 +282,19 @@ sub process_incoming_msg { if( 0 == length @target_l){ &main::daemon_log("$session_id ERROR: no target specified for msg $header", 1); $error++; - } - - if( 1 == length @target_l) { + } elsif( 1 == length @target_l) { my $target = $target_l[0]; if(&server_matches($target)) { if ($header eq 'new_key') { @out_msg_l = &new_key($msg_hash) } elsif ($header eq 'here_i_am') { - @out_msg_l = &here_i_am($msg, $msg_hash, $session_id, $ldap_handle) + @out_msg_l = &here_i_am($msg, $msg_hash, $session_id) } else { # a event exists with the header as name if( exists $event2module_hash->{$header} ) { &main::daemon_log("$session_id INFO: found event '$header' at event-module '".$event2module_hash->{$header}."'", 5); no strict 'refs'; - @out_msg_l = &{$event2module_hash->{$header}."::$header"}($msg, $msg_hash, $session_id, $ldap_handle); + @out_msg_l = &{$event2module_hash->{$header}."::$header"}($msg, $msg_hash, $session_id); # if no event handler is implemented } else { @@ -344,12 +342,7 @@ sub process_incoming_msg { &main::daemon_log("$session_id ERROR: client '$target' is not registered for event '$header', processing is aborted", 1); @out_msg_l = (); } - - - - - } - else { + } else { &main::daemon_log("INFO: msg is not for gosa-si-server '$server_address', deliver it to target '$target'", 5); push(@out_msg_l, $msg); } @@ -417,7 +410,7 @@ sub new_key { # DESCRIPTION: process this incoming message #=============================================================================== sub here_i_am { - my ($msg, $msg_hash, $session_id, $ldap_handle) = @_; + my ($msg, $msg_hash, $session_id) = @_; my @out_msg_l; my $out_hash; my $source = @{$msg_hash->{source}}[0]; @@ -497,7 +490,7 @@ sub here_i_am { # give the new client his ldap config # Workaround: Send within the registration response, if the client will get an ldap config later - my $new_ldap_config_out = &new_ldap_config($source, $session_id, $ldap_handle); + my $new_ldap_config_out = &new_ldap_config($source, $session_id); if($new_ldap_config_out && (!($new_ldap_config_out =~ /error/))) { &add_content2xml_hash($out_hash, "ldap_available", "true"); } elsif($new_ldap_config_out && $new_ldap_config_out =~ /error/){ @@ -518,19 +511,19 @@ sub here_i_am { } # Send client hardware configuration - my $hardware_config_out = &hardware_config($msg, $msg_hash, $session_id, $ldap_handle); + my $hardware_config_out = &hardware_config($msg, $msg_hash, $session_id); if( $hardware_config_out ) { push(@out_msg_l, $hardware_config_out); } # Send client ntp server - my $ntp_config_out = &new_ntp_config($mac_address, $session_id, $ldap_handle); + my $ntp_config_out = &new_ntp_config($mac_address, $session_id); if ($ntp_config_out) { push(@out_msg_l, $ntp_config_out); } # Send client syslog server - my $syslog_config_out = &new_syslog_config($mac_address, $session_id, $ldap_handle); + my $syslog_config_out = &new_syslog_config($mac_address, $session_id); if ($syslog_config_out) { push(@out_msg_l, $syslog_config_out); } @@ -596,8 +589,9 @@ sub who_has_i_do { sub new_syslog_config { - my ($mac_address, $session_id, $ldap_handle) = @_; + my ($mac_address, $session_id) = @_; my $syslog_msg; + my $ldap_handle=&main::get_ldap_handle(); # Perform search my $ldap_res = $ldap_handle->search( base => $ldap_base, @@ -606,6 +600,7 @@ sub new_syslog_config { filter => "(&(objectClass=GOhard)(macaddress=$mac_address))"); if($ldap_res->code) { &main::daemon_log("$session_id ".$ldap_res->error, 1); + &main::release_ldap_handle($ldap_handle); return; } @@ -616,6 +611,7 @@ sub new_syslog_config { "\n\tscope: sub". "\n\tattrs: gotoSyslogServer". "\n\tfilter: (&(objectClass=GOhard)(macaddress=$mac_address))", 1); + &main::release_ldap_handle($ldap_handle); return; } @@ -632,6 +628,7 @@ sub new_syslog_config { filter => "(&(objectClass=gosaGroupOfNames)(member=$filter_dn))"); if($ldap_res->code) { &main::daemon_log("$session_id ".$ldap_res->error, 1); + &main::release_ldap_handle($ldap_handle); return; } @@ -642,6 +639,7 @@ sub new_syslog_config { "\n\tscope: sub". "\n\tattrs: gotoSyslogServer". "\n\tfilter: (&(objectClass=gosaGroupOfNames)(member=$filter_dn))", 1); + &main::release_ldap_handle($ldap_handle); return; } @@ -652,6 +650,7 @@ sub new_syslog_config { # Return if no syslog server specified if (not defined $syslog_server) { &main::daemon_log("$session_id WARNING: no syslog server specified for this host '$mac_address'", 3); + &main::release_ldap_handle($ldap_handle); return; } @@ -660,13 +659,15 @@ sub new_syslog_config { my $syslog_msg_hash = &create_xml_hash("new_syslog_config", $server_address, $mac_address); &add_content2xml_hash($syslog_msg_hash, "server", $syslog_server); + &main::release_ldap_handle($ldap_handle); return &create_xml_string($syslog_msg_hash); } sub new_ntp_config { - my ($address, $session_id, $ldap_handle) = @_; + my ($address, $session_id) = @_; my $ntp_msg; + my $ldap_handle=&main::get_ldap_handle(); # Perform search my $ldap_res = $ldap_handle->search( base => $ldap_base, @@ -675,6 +676,7 @@ sub new_ntp_config { filter => "(&(objectClass=GOhard)(macaddress=$address))"); if($ldap_res->code) { &main::daemon_log("$session_id ".$ldap_res->error, 1); + &main::release_ldap_handle($ldap_handle); return; } @@ -685,6 +687,7 @@ sub new_ntp_config { "\n\tscope: sub". "\n\tattrs: gotoNtpServer". "\n\tfilter: (&(objectClass=GOhard)(macaddress=$address))", 1); + &main::release_ldap_handle($ldap_handle); return; } @@ -701,6 +704,7 @@ sub new_ntp_config { filter => "(&(objectClass=gosaGroupOfNames)(member=$filter_dn))"); if($ldap_res->code) { &main::daemon_log("$session_id ".$ldap_res->error, 1); + &main::release_ldap_handle($ldap_handle); return; } @@ -711,6 +715,7 @@ sub new_ntp_config { "\n\tscope: sub". "\n\tattrs: gotoNtpServer". "\n\tfilter: (&(objectClass=gosaGroupOfNames)(member=$filter_dn))", 1); + &main::release_ldap_handle($ldap_handle); return; } @@ -721,6 +726,7 @@ sub new_ntp_config { # Return if no ntp server specified if ((not @ntp_servers) || (@ntp_servers == 0)) { &main::daemon_log("$session_id WARNING: no ntp server specified for this host '$address'", 3); + &main::release_ldap_handle($ldap_handle); return; } @@ -730,6 +736,7 @@ sub new_ntp_config { &add_content2xml_hash($ntp_msg_hash, "server", $ntp_server); } + &main::release_ldap_handle($ldap_handle); return &create_xml_string($ntp_msg_hash); } @@ -741,7 +748,7 @@ sub new_ntp_config { # DESCRIPTION: send to address the ldap configuration found for dn gotoLdapServer #=============================================================================== sub new_ldap_config { - my ($address, $session_id, $ldap_handle) = @_ ; + my ($address, $session_id) = @_ ; my $sql_statement= "SELECT * FROM known_clients WHERE hostname='$address' OR macaddress LIKE '$address'"; my $res = $main::known_clients_db->select_dbentry( $sql_statement ); @@ -750,24 +757,27 @@ sub new_ldap_config { my $hit_counter = keys %{$res}; if( not $hit_counter == 1 ) { &main::daemon_log("$session_id ERROR: more or no hit found in known_clients_db by query '$sql_statement'", 1); + return; } $address = $res->{1}->{hostname}; my $macaddress = $res->{1}->{macaddress}; my $hostkey = $res->{1}->{hostkey}; - + if (not defined $macaddress) { &main::daemon_log("$session_id ERROR: no mac address found for client $address", 1); return; } # Perform search + my $ldap_handle=&main::get_ldap_handle(); $mesg = $ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['dn', 'gotoLdapServer', 'gosaUnitTag', 'FAIclass'], filter => "(&(objectClass=GOhard)(macaddress=$macaddress))"); if($mesg->code) { &main::daemon_log("$session_id ".$mesg->error, 1); + &main::release_ldap_handle($ldap_handle); return; } @@ -778,6 +788,7 @@ sub new_ldap_config { "\n\tscope: sub". "\n\tattrs: dn, gotoLdapServer". "\n\tfilter: (&(objectClass=GOhard)(macaddress=$macaddress))", 1); + &main::release_ldap_handle($ldap_handle); return; } @@ -805,6 +816,7 @@ sub new_ldap_config { filter => "(&(objectClass=gosaGroupOfNames)(member=$filter_dn))"); if($mesg->code) { &main::daemon_log("$session_id ERROR: unable to search for '(&(objectClass=gosaGroupOfNames)(member=$filter_dn))': ".$mesg->error, 1); + &main::release_ldap_handle($ldap_handle); return; } @@ -815,6 +827,7 @@ sub new_ldap_config { "\n\tscope: sub". "\n\tattrs: dn, gotoLdapServer, FAIclass". "\n\tfilter: (&(objectClass=gosaGroupOfNames)(member=$filter_dn))", 1); + &main::release_ldap_handle($ldap_handle); return; } @@ -877,12 +890,14 @@ sub new_ldap_config { #$mesg->code && die $mesg->error; if($mesg->code) { &main::daemon_log($mesg->error, 1); + &main::release_ldap_handle($ldap_handle); return "error-unit-tag-count-0"; } # Sanity check if ($mesg->count != 1) { &main::daemon_log("WARNING: cannot find administrative unit for client with tag $unit_tag", 1); + &main::release_ldap_handle($ldap_handle); return "error-unit-tag-count-".$mesg->count; } @@ -893,6 +908,7 @@ sub new_ldap_config { # Append unit Tag $data{'unit_tag'}= $unit_tag; } + &main::release_ldap_handle($ldap_handle); # Send information return &build_msg("new_ldap_config", $server_address, $address, \%data); @@ -906,7 +922,7 @@ sub new_ldap_config { # DESCRIPTION: #=============================================================================== sub hardware_config { - my ($msg, $msg_hash, $session_id, $ldap_handle) = @_ ; + my ($msg, $msg_hash, $session_id) = @_ ; my $address = @{$msg_hash->{source}}[0]; my $header = @{$msg_hash->{header}}[0]; my $gotoHardwareChecksum = @{$msg_hash->{gotoHardwareChecksum}}[0]; @@ -928,6 +944,7 @@ sub hardware_config { } # Perform search + my $ldap_handle=&main::get_ldap_handle(); $mesg = $ldap_handle->search( base => $ldap_base, scope => 'sub', @@ -967,6 +984,7 @@ sub hardware_config { } } else { # Nothing to do + &main::release_ldap_handle($ldap_handle); return; } } @@ -981,6 +999,8 @@ sub hardware_config { $data{'goto_secret'}= $goto_secret; } + &main::release_ldap_handle($ldap_handle); + # Send information return &build_msg("detect_hardware", $server_address, $address, \%data); } diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index 1677bf942..4a7e8ce88 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -109,7 +109,7 @@ sub get_mac { # DESCRIPTION: handels the proceeded distribution to the appropriated functions #=============================================================================== sub process_incoming_msg { - my ($msg, $msg_hash, $session_id, $ldap_handle) = @_ ; + my ($msg, $msg_hash, $session_id) = @_ ; my $header = @{$msg_hash->{header}}[0]; my @msg_l; my @out_msg_l; @@ -117,10 +117,10 @@ sub process_incoming_msg { &main::daemon_log("$session_id DEBUG: GosaPackages: msg to process '$header'", 7); if ($header =~ /^job_/) { - @msg_l = &process_job_msg($msg, $msg_hash, $session_id, $ldap_handle); + @msg_l = &process_job_msg($msg, $msg_hash, $session_id); } elsif ($header =~ /^gosa_/) { - @msg_l = &process_gosa_msg($msg, $msg_hash, $session_id, $ldap_handle); + @msg_l = &process_gosa_msg($msg, $msg_hash, $session_id); } else { &main::daemon_log("$session_id ERROR: $header is not a valid GosaPackage-header, need a 'job_' or a 'gosa_' prefix", 1); @@ -152,7 +152,7 @@ sub process_incoming_msg { sub process_gosa_msg { - my ($msg, $msg_hash, $session_id, $ldap_handle) = @_ ; + my ($msg, $msg_hash, $session_id) = @_ ; my $out_msg; my @out_msg_l = ('nohandler'); my $sql_events; @@ -169,7 +169,7 @@ sub process_gosa_msg { # a event exists with the header as name &main::daemon_log("$session_id INFO: found event '$header' at event-module '".$event2module_hash->{$header}."'", 5); no strict 'refs'; - @out_msg_l = &{$event2module_hash->{$header}."::$header"}( $msg, $msg_hash, $session_id, $ldap_handle ); + @out_msg_l = &{$event2module_hash->{$header}."::$header"}( $msg, $msg_hash, $session_id ); # check client registered events } else { @@ -217,7 +217,7 @@ sub process_gosa_msg { sub process_job_msg { - my ($msg, $msg_hash, $session_id, $ldap_handle)= @_ ; + my ($msg, $msg_hash, $session_id)= @_ ; my $out_msg; my $error = 0; @@ -259,7 +259,8 @@ sub process_job_msg { $header = "trigger_action_reinstall" } - } else { # Try to determine plain_name via ladp search + } else { # Try to determine plain_name via ldap search + my $ldap_handle=&main::get_ldap_handle(); my $mesg = $ldap_handle->search( base => $main::ldap_base, scope => 'sub', @@ -272,6 +273,7 @@ sub process_job_msg { my $entry= $mesg->entry(0); $plain_name = $entry->get_value("cn"); } + &main::release_ldap_handle($ldap_handle); } # Add job to job queue diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index 6fa3d1c33..a535c5adb 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -117,7 +117,7 @@ sub save_fai_log { # @param msg_hash - HASHREF - message information parsed into a hash # @param session_id - INTEGER - POE session id of the processing of this message sub LOGIN { - my ($msg, $msg_hash, $session_id, $ldap_handle) = @_; + my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $login = @{$msg_hash->{$header}}[0]; @@ -125,7 +125,7 @@ sub LOGIN { my $error_str; # Invoke set_last_system; message sets ldap attributes 'gotoLastSystemLogin' and 'gotoLastSystem' - $res = &set_last_system($msg, $msg_hash, $session_id, $ldap_handle); + $res = &set_last_system($msg, $msg_hash, $session_id); # Add user to login_users_db my %add_hash = ( table=>$main::login_users_tn, @@ -174,7 +174,7 @@ sub LOGOUT { # @param msg_hash - HASHREF - message information parsed into a hash # @param session_id - INTEGER - POE session id of the processing of this message sub CURRENTLY_LOGGED_IN { - my ($msg, $msg_hash, $session_id, $ldap_handle) = @_; + my ($msg, $msg_hash, $session_id) = @_; my ($sql_statement, $db_res); my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; @@ -186,7 +186,7 @@ sub CURRENTLY_LOGGED_IN { } # Invoke set_last_system; message sets ldap attributes 'gotoLastSystemLogin' and 'gotoLastSystem' - my $res = &set_last_system($msg, $msg_hash, $session_id, $ldap_handle); + my $res = &set_last_system($msg, $msg_hash, $session_id); # fetch all user currently assigned to the client at login_users_db my %currently_logged_in_user = (); @@ -261,7 +261,7 @@ sub CURRENTLY_LOGGED_IN { # @param msg_hash - HASHREF - message information parsed into a hash # @param session_id - INTEGER - POE session id of the processing of this message sub set_last_system { - my ($msg, $msg_hash, $session_id, $ldap_handle) = @_; + my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $login = @{$msg_hash->{$header}}[0]; @@ -307,6 +307,7 @@ sub set_last_system { } # Get system info + my $ldap_handle=&main::get_ldap_handle($session_id); my $ldap_mesg= $ldap_handle->search( base => $main::ldap_base, scope => 'sub', @@ -315,6 +316,7 @@ sub set_last_system { if ($ldap_mesg->count == 0) { &main::daemon_log("$session_id ERROR: no system with mac address='$mac' was found in base '". $main::ldap_base."', setting of 'gotoLastSystem' and 'gotoLastSystemLogin' stopped!", 1); + &main::release_ldap_handle($ldap_handle); return; } @@ -381,6 +383,7 @@ sub set_last_system { } } } + &main::release_ldap_handle($ldap_handle); return; } @@ -507,7 +510,7 @@ sub TASKSKIP { # @param msg_hash - HASHREF - message information parsed into a hash # @param session_id - INTEGER - POE session id of the processing of this message sub TASKBEGIN { - my ($msg, $msg_hash, $session_id, $ldap_handle) = @_; + my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; @@ -580,6 +583,7 @@ sub TASKBEGIN { # in case of no and more than one running jobs in queue, add one single job # resolve plain name for host $macaddress my $plain_name; + my $ldap_handle=&main::get_ldap_handle($session_id); my $mesg = $ldap_handle->search( base => $main::ldap_base, scope => 'sub', @@ -592,6 +596,7 @@ sub TASKBEGIN { &main::daemon_log($mesg->error, 1); $plain_name = "none"; } + &main::release_ldap_handle($ldap_handle); # In any case add a new job to job queue &main::daemon_log("$session_id DEBUG: add job to queue for host '$macaddress'", 7); diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 1c3287eb0..9cf0852c7 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -814,7 +814,7 @@ sub get_available_kernel { } sub trigger_activate_new { - my ($msg, $msg_hash, $session_id, $ldap_handle) = @_; + my ($msg, $msg_hash, $session_id) = @_; my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; @@ -852,6 +852,7 @@ sub trigger_activate_new { my $changed_attributes_counter = 0; my $activate_client = 0; + my $ldap_handle=&main::get_ldap_handle(); if(defined($ogroup)) { my $ldap_mesg= $ldap_handle->search( @@ -864,13 +865,13 @@ sub trigger_activate_new { &main::daemon_log("$session_id DEBUG: A GosaGroupOfNames with cn '$ogroup' was found in base '".$main::ldap_base."'!", 5); } elsif ($ldap_mesg->count == 0) { &main::daemon_log("$session_id ERROR: A GosaGroupOfNames with cn '$ogroup' was not found in base '".$main::ldap_base."'!", 1); - $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET status = 'waiting' WHERE id = $jobdb_id"); - $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET timestamp = '".(&calc_timestamp(&get_time(), 'plus', 10))."' WHERE id = $jobdb_id"); + $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET status = 'waiting', timestamp = '".(&calc_timestamp(&get_time(), 'plus', 60))."' WHERE id = $jobdb_id"); + &main::release_ldap_handle($ldap_handle); return undef; } else { &main::daemon_log("$session_id ERROR: More than one ObjectGroups with cn '$ogroup' was found in base '".$main::ldap_base."'!", 1); - $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET status = 'waiting' WHERE id = $jobdb_id"); - $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET timestamp = '".(&calc_timestamp(&get_time(), 'plus', 10))."' WHERE id = $jobdb_id"); + $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET status = 'waiting', timestamp = '".(&calc_timestamp(&get_time(), 'plus', 60))."' WHERE id = $jobdb_id"); + &main::release_ldap_handle($ldap_handle); return undef; } @@ -909,13 +910,15 @@ sub trigger_activate_new { # To prevent replication problems just re-queue the job with 10 seconds in the future my $moddn_result = $ldap_entry->update($ldap_handle); if ($moddn_result->code() != 0) { - my $error_string = "Moving the system with mac address '$mac' to new base '$base' failed (code '".$moddn_result->code()."') with '".$moddn_result->{'errorMessage'}."'!"; - &main::daemon_log("$session_id ERROR: $error_string", 1); - my $sql = "UPDATE $main::job_queue_tn SET status='error', result='$error_string' WHERE id=$jobdb_id"; - return undef; + my $error_string = "Moving the system with mac address '$mac' to new base '$base' failed (code '".$moddn_result->code()."') with '".$moddn_result->{'errorMessage'}."'!"; + &main::daemon_log("$session_id ERROR: $error_string", 1); + my $sql = "UPDATE $main::job_queue_tn SET status='error', result='$error_string' WHERE id=$jobdb_id"; + &main::release_ldap_handle($ldap_handle); + return undef; } else { &main::daemon_log("$session_id INFO: System with mac address '$mac' was moved to base '".$main::ldap_base."'! Re-queuing job.", 4); $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET status = 'waiting', timestamp = '".(&calc_timestamp(&get_time(), 'plus', 10))."' WHERE id = $jobdb_id"); + &main::release_ldap_handle($ldap_handle); return undef; } } @@ -926,6 +929,7 @@ sub trigger_activate_new { " SET status='waiting', timestamp = '".(&calc_timestamp(&get_time(), 'plus', 60))."' ". " WHERE id = $jobdb_id"; $main::job_db->exec_statement($sql_statement); + &main::release_ldap_handle($ldap_handle); return undef; } @@ -987,6 +991,7 @@ sub trigger_activate_new { # $ldap_entry->dn("cn=$mac,$base"); &main::daemon_log("$session_id WARNING: No System with mac address '$mac' was found in base '".$main::ldap_base."'! Re-queuing job.", 4); $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET status = 'waiting', timestamp = '".(&calc_timestamp(&get_time(), 'plus', 60))."' WHERE id = $jobdb_id"); + &main::release_ldap_handle($ldap_handle); return undef; } else { &main::daemon_log("$session_id ERROR: More than one system with mac address '$mac' was found in base '".$main::ldap_base."'!", 1); @@ -1041,7 +1046,7 @@ sub trigger_activate_new { } if($activate_client == 1) { - &main::daemon_log("$session_id DEBIG: Activating system with mac address '$mac'!", 5); + &main::daemon_log("$session_id DEBUG: Activating system with mac address '$mac'!", 5); # Create delivery list my @out_msg_l; @@ -1055,12 +1060,14 @@ sub trigger_activate_new { push(@out_msg_l, $out_msg); # Return delivery list of messages + &main::release_ldap_handle($ldap_handle); return @out_msg_l; } else { &main::daemon_log("$session_id WARNING: Activating system with mac address '$mac' failed! Re-queuing job.", 4); $main::job_db->exec_statement("UPDATE ".$main::job_queue_tn." SET status = 'waiting', timestamp = '".(&calc_timestamp(&get_time(), 'plus', 60))."' WHERE id = $jobdb_id"); } + &main::release_ldap_handle($ldap_handle); return undef; } diff --git a/gosa-si/server/events/siTriggered.pm b/gosa-si/server/events/siTriggered.pm index d13ec6fa0..e4493282d 100644 --- a/gosa-si/server/events/siTriggered.pm +++ b/gosa-si/server/events/siTriggered.pm @@ -123,7 +123,7 @@ sub got_ping { sub detected_hardware { - my ($msg, $msg_hash, $session_id, $ldap_handle) = @_; + my ($msg, $msg_hash, $session_id) = @_; my $address = $msg_hash->{source}[0]; my $header = $msg_hash->{header}[0]; my $gotoHardwareChecksum= $msg_hash->{detected_hardware}[0]->{gotoHardwareChecksum}; @@ -147,6 +147,7 @@ sub detected_hardware { } # Perform search + my $ldap_handle = &main::get_ldap_handle(); $mesg = $ldap_handle->search( base => $ldap_base, scope => 'sub', @@ -189,6 +190,7 @@ sub detected_hardware { if(defined($res->{'errorMessage'}) && length($res->{'errorMessage'}) >0) { &main::daemon_log("ERROR: can not add entries to LDAP: ".$res->{'errorMessage'}, 1); + &main::release_ldap_handle($ldap_handle); return; } else { # Fill $mesg again @@ -241,6 +243,7 @@ sub detected_hardware { # if there is a job in job queue for this host and this macaddress, delete it, cause its no longer used my $del_sql = "DELETE FROM $main::job_queue_tn WHERE (macaddress LIKE '$macaddress' AND headertag='$header')"; my $del_res = $main::job_db->exec_statement($del_sql); + &main::release_ldap_handle($ldap_handle); return ; } -- 2.30.2