From d88621a8e07b969b9d214262eae3b5b6c570180b Mon Sep 17 00:00:00 2001 From: rettenbe Date: Wed, 11 Mar 2009 13:45:58 +0000 Subject: [PATCH] new ldap handling, a handle is taken out of a pool of ldap handles and given back if it's no longer needed git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13528 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 165 +++++++++++++++---------- gosa-si/modules/ArpHandler.pm | 6 +- gosa-si/modules/ClientPackages.pm | 55 ++------- gosa-si/modules/GosaPackages.pm | 38 +++--- gosa-si/modules/GosaSupportDaemon.pm | 2 +- gosa-si/server/events/clMessages.pm | 43 +++---- gosa-si/server/events/gosaTriggered.pm | 3 +- gosa-si/server/events/siTriggered.pm | 8 +- 8 files changed, 148 insertions(+), 172 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 2b0c4c1a4..17483bb69 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -39,6 +39,7 @@ use Digest::MD5 qw(md5 md5_hex md5_base64); use XML::Simple; use Data::Dumper; use Sys::Syslog qw( :DEFAULT setlogsock); +use Time::HiRes qw( usleep); use Cwd; use File::Spec; use File::Basename; @@ -49,7 +50,8 @@ use GOSA::GosaSupportDaemon; use POE qw(Component::Server::TCP Wheel::Run Filter::Reference); use Net::LDAP; use Net::LDAP::Util qw(:escape); -use Time::HiRes qw( usleep); +use ResourcePool; +use ResourcePool::Factory::Net::LDAP; # revision number of server and program name my $server_headURL; @@ -74,7 +76,7 @@ my ($server); my ($gosa_server, $job_queue_timeout, $job_queue_loop_delay); my ($messaging_db_loop_delay); my ($procid, $pid); -my ($arp_fifo); +my ($arp_fifo, $ldap_pool, $ldap_factory); my ($xml); my $sources_list; my $max_clients; @@ -102,7 +104,7 @@ our $no_arp; our $verbose; our $forground; our $cfg_file; -our ($ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $ldap_server_dn); +our ($ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $ldap_server_dn, $ldap_version); our ($mysql_username, $mysql_password, $mysql_database, $mysql_host); our $known_modules; our $root_uid; @@ -247,13 +249,14 @@ our $logged_in_user_date_of_expiry = 600; "ldap-base" => [\$ldap_base, ""], "ldap-admin-dn" => [\$ldap_admin_dn, ""], "ldap-admin-password" => [\$ldap_admin_password, ""], + "ldap-version" => [\$ldap_version, 3], "gosa-unit-tag" => [\$gosa_unit_tag, ""], "max-clients" => [\$max_clients, 10], "wol-password" => [\$wake_on_lan_passwd, ""], - "mysql-username" => [\$mysql_username, "gosa_si"], - "mysql-password" => [\$mysql_password, ""], - "mysql-database" => [\$mysql_database, "gosa_si"], - "mysql-host" => [\$mysql_host, "127.0.0.1"], + "mysql-username" => [\$mysql_username, "gosa_si"], + "mysql-password" => [\$mysql_password, ""], + "mysql-database" => [\$mysql_database, "gosa_si"], + "mysql-host" => [\$mysql_host, "127.0.0.1"], }, "GOsaPackages" => { "job-queue" => [\$job_queue_file_name, '/var/lib/gosa-si/jobs.db'], @@ -453,6 +456,8 @@ sub import_modules { } opendir (DIR, $modules_path) or die "ERROR while loading modules from directory $modules_path : $!\n"; + + my $ldap_handle = &get_ldap_handle; while (defined (my $file = readdir (DIR))) { if (not $file =~ /(\S*?).pm$/) { next; @@ -470,7 +475,7 @@ sub import_modules { daemon_log("$@", 1); exit; } else { - my $info = eval($mod_name.'::get_module_info()'); + my $info = eval($mod_name.'::get_module_info($ldap_handle)'); # Only load module if get_module_info() returns a non-null object if( $info ) { my ($input_address, $input_key, $event_hash) = @{$info}; @@ -479,7 +484,7 @@ sub import_modules { } } } - + &release_ldap_handle($ldap_handle); close (DIR); } @@ -1321,14 +1326,16 @@ sub msg_to_decrypt { sub next_task { my ($session, $heap, $task) = @_[SESSION, HEAP, ARG0]; + my $ldap_handle = &get_ldap_handle(); my $running_task = POE::Wheel::Run->new( - Program => sub { process_task($session, $heap, $task) }, + Program => sub { process_task($session, $heap, $task, $ldap_handle) }, StdioFilter => POE::Filter::Reference->new(), StdoutEvent => "task_result", StderrEvent => "task_debug", CloseEvent => "task_done", ); $heap->{task}->{ $running_task->ID } = $running_task; + $heap->{ldap_handle}->{$running_task->ID} = $ldap_handle; } sub handle_task_result { @@ -1358,12 +1365,15 @@ sub handle_task_debug { sub handle_task_done { my ( $kernel, $heap, $task_id ) = @_[ KERNEL, HEAP, ARG0 ]; delete $heap->{task}->{$task_id}; + if (exists $heap->{ldap_handle}->{$task_id}) { + &release_ldap_handle($heap->{ldap_handle}->{$task_id}); + } } sub process_task { no strict "refs"; #CHECK: Not @_[...]? - my ($session, $heap, $task) = @_; + my ($session, $heap, $task, $ldap_handle) = @_; my $error = 0; my $answer_l; my ($answer_header, @answer_target_l, $answer_source); @@ -1394,7 +1404,7 @@ sub process_task { if( $error == 0) { daemon_log("$session_id INFO: Incoming msg (session_id=$session_id) with header '".@{$msg_hash->{'header'}}[0]."'", 5); daemon_log("$session_id DEBUG: Processing module ".$module, 7); - $answer_l = &{ $module."::process_incoming_msg" }($msg, $msg_hash, $session_id); + $answer_l = &{ $module."::process_incoming_msg" }($msg, $msg_hash, $session_id, $ldap_handle); if ( 0 < @{$answer_l} ) { my $answer_str = join("\n", @{$answer_l}); @@ -1875,6 +1885,7 @@ sub watch_for_new_messages { attrs => ['memberUid'], filter => "cn=$group_name", ); + &release_ldap_handle($ldap_handle); if ($mesg->count) { my @entries = $mesg->entries; foreach my $entry (@entries) { @@ -2127,42 +2138,33 @@ sub watch_for_next_tasks { sub get_ldap_handle { my ($session_id) = @_; my $heap; - my $ldap_handle; if (not defined $session_id ) { $session_id = 0 }; if ($session_id =~ /[^0-9]*/) { $session_id = 0 }; - if ($session_id == 0) { - daemon_log("$session_id DEBUG: get_ldap_handle invoked without a session_id, create a new ldap_handle", 7); - $ldap_handle = Net::LDAP->new( $ldap_uri ); - if (defined $ldap_handle) { - $ldap_handle->bind($ldap_admin_dn, password => $ldap_admin_password) or daemon_log("$session_id ERROR: Bind to LDAP $ldap_uri as $ldap_admin_dn failed!"); - } else { - daemon_log("$session_id ERROR: creation of a new LDAP handle failed (ldap_uri '$ldap_uri')"); - } - - } else { - my $session_reference = $global_kernel->ID_id_to_session($session_id); - if( defined $session_reference ) { - $heap = $session_reference->get_heap(); - } - - if (not defined $heap) { - daemon_log("$session_id DEBUG: cannot get heap for session_id '$session_id'", 7); - return; - } + (my $package, my $file, my $row, my $subroutine, my $hasArgs, my $wantArray, my $evalText, my $isRequire) = caller(1); + my $caller_text = "subroutin $subroutine"; + if ($subroutine eq "(eval)") { + $caller_text = "eval block within file '$file' for '$evalText'"; + } + daemon_log("$session_id INFO: new ldap handle for $caller_text required"); - # TODO: This "if" is nonsense, because it doesn't prove that the - # used handle is still valid - or if we've to reconnect... - #if (not exists $heap->{ldap_handle}) { - $ldap_handle = Net::LDAP->new( $ldap_uri ); - $ldap_handle->bind($ldap_admin_dn, password => $ldap_admin_password) or daemon_log("$session_id ERROR: Bind to LDAP $ldap_uri as $ldap_admin_dn failed!"); - $heap->{ldap_handle} = $ldap_handle; - #} + my $ldap_handle = $ldap_pool->get(); + + if (not defined $ldap_handle) { + daemon_log("$session_id INFO: ldap handle for $caller_text not available"); } + daemon_log("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); return $ldap_handle; } +sub release_ldap_handle { + my ($ldap_handle) = @_ ; + $ldap_pool->free($ldap_handle); + daemon_log("0 INFO: ldap handle released!\n-------------------------------------------------------------------------------"); + return; +} + sub change_fai_state { my ($st, $targets, $session_id) = @_; @@ -2188,8 +2190,7 @@ sub change_fai_state { my $state= $mapActions{ $st }; - my $ldap_handle = &get_ldap_handle($session_id); - if( defined($ldap_handle) ) { + #if( defined($ldap_handle) ) { # Build search filter for hosts my $search= "(&(objectClass=GOhard)"; @@ -2204,6 +2205,7 @@ sub change_fai_state { return; } + my $ldap_handle = &get_ldap_handle($session_id); # Perform search for Unit Tag my $mesg = $ldap_handle->search( base => $ldap_base, @@ -2245,11 +2247,12 @@ sub change_fai_state { } else { daemon_log("$session_id ERROR: LDAP search failed: ldap_base=$ldap_base, filter=$search", 1); } + &release_ldap_handle($ldap_handle); # if no ldap handle defined - } else { - daemon_log("$session_id ERROR: no LDAP handle defined for update FAIstate", 1); - } + #} else { + # daemon_log("$session_id ERROR: no LDAP handle defined for update FAIstate", 1); + #} return; } @@ -2308,6 +2311,8 @@ sub change_goto_state { } } + &release_ldap_handle($ldap_handle); + return; } @@ -2324,24 +2329,29 @@ sub run_recreate_packages_db { sub run_create_fai_server_db { my ($kernel, $session, $heap, $table_name) = @_[KERNEL, SESSION, HEAP, ARG0]; my $session_id = $session->ID; + my $ldap_handle = &get_ldap_handle(); + if (not defined $ldap_handle) { + $kernel->delay_set('create_fai_server_db', 1, $table_name); + return; + } my $task = POE::Wheel::Run->new( - Program => sub { &create_fai_server_db($table_name,$kernel, undef, $session_id) }, + Program => sub { &create_fai_server_db($table_name,$kernel, undef, $session_id, $ldap_handle) }, StdoutEvent => "session_run_result", StderrEvent => "session_run_debug", CloseEvent => "session_run_done", ); $heap->{task}->{ $task->ID } = $task; + $heap->{ldap_handle}->{$task->ID} = $ldap_handle; return; } sub create_fai_server_db { - my ($table_name, $kernel, $dont_create_packages_list, $session_id) = @_; + my ($table_name, $kernel, $dont_create_packages_list, $session_id, $ldap_handle) = @_; my $result; if (not defined $session_id) { $session_id = 0; } - my $ldap_handle = &get_ldap_handle(); if(defined($ldap_handle)) { daemon_log("$session_id INFO: create_fai_server_db: start", 5); my $mesg= $ldap_handle->search( @@ -2374,38 +2384,43 @@ sub create_fai_server_db { # TODO: Find a way to post the 'create_packages_list_db' event if(not defined($dont_create_packages_list)) { - &create_packages_list_db(undef, undef, $session_id); + &create_packages_list_db(undef, $session_id); } } - $ldap_handle->disconnect; return $result; } sub run_create_fai_release_db { - my ($session, $heap, $table_name) = @_[SESSION, HEAP, ARG0]; + my ($kernel, $session, $heap, $table_name) = @_[KERNEL, SESSION, HEAP, ARG0]; my $session_id = $session->ID; + my $ldap_handle = &get_ldap_handle(); + if (not defined $ldap_handle) { + $kernel->delay_set('create_fai_release_db', 1, $table_name); + return; + } my $task = POE::Wheel::Run->new( - Program => sub { &create_fai_release_db($table_name, $session_id) }, + Program => sub { &create_fai_release_db($table_name, $session_id, $ldap_handle) }, StdoutEvent => "session_run_result", StderrEvent => "session_run_debug", CloseEvent => "session_run_done", ); $heap->{task}->{ $task->ID } = $task; + $heap->{ldap_handle}->{$task->ID} = $ldap_handle; return; } sub create_fai_release_db { - my ($table_name, $session_id) = @_; + my ($table_name, $session_id, $ldap_handle) = @_; my $result; # used for logging if (not defined $session_id) { $session_id = 0; } - my $ldap_handle = &get_ldap_handle(); + #my $ldap_handle = &get_ldap_handle(); if(defined($ldap_handle)) { daemon_log("$session_id INFO: create_fai_release_db: start",5); my $mesg= $ldap_handle->search( @@ -2455,7 +2470,7 @@ sub create_fai_release_db { } daemon_log("$session_id INFO: create_fai_release_db: finished",5); } - $ldap_handle->disconnect; + #&release_ldap_handle($ldap_handle); return $result; } @@ -2700,12 +2715,15 @@ sub session_run_debug { sub session_run_done { my ( $kernel, $heap, $task_id ) = @_[ KERNEL, HEAP, ARG0 ]; delete $heap->{task}->{$task_id}; + if (exists $heap->{ldap_handle}->{$task_id}) { + &release_ldap_handle($heap->{ldap_handle}->{$task_id}); + } + delete $heap->{ldap_handle}->{$task_id}; } sub create_sources_list { my $session_id = shift; - my $ldap_handle = &main::get_ldap_handle; my $result="/tmp/gosa_si_tmp_sources_list"; # Remove old file @@ -2721,12 +2739,14 @@ sub create_sources_list { return undef; } if(defined($main::ldap_server_dn) and length($main::ldap_server_dn) > 0) { + my $ldap_handle = &get_ldap_handle(); my $mesg=$ldap_handle->search( base => $main::ldap_server_dn, scope => 'base', attrs => 'FAIrepository', filter => 'objectClass=FAIrepositoryServer' ); + &release_ldap_handle($ldap_handle); if($mesg->count) { foreach my $entry(@{$mesg->{'entries'}}) { foreach my $value(@{$entry->get_value('FAIrepository', asref => 1)}) { @@ -2754,10 +2774,9 @@ sub create_sources_list { sub run_create_packages_list_db { my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP]; my $session_id = $session->ID; - my $task = POE::Wheel::Run->new( Priority => +20, - Program => sub {&create_packages_list_db(undef, undef, $session_id)}, + Program => sub {&create_packages_list_db(undef, $session_id)}, StdoutEvent => "session_run_result", StderrEvent => "session_run_debug", CloseEvent => "session_run_done", @@ -2767,7 +2786,7 @@ sub run_create_packages_list_db { sub create_packages_list_db { - my ($ldap_handle, $sources_file, $session_id) = @_; + my ($sources_file, $session_id) = @_; # it should not be possible to trigger a recreation of packages_list_db # while packages_list_db is under construction, so set flag packages_list_under_construction @@ -2783,15 +2802,15 @@ sub create_packages_list_db { } if (not defined $session_id) { $session_id = 0; } - if (not defined $ldap_handle) { - $ldap_handle= &get_ldap_handle(); - - if (not defined $ldap_handle) { - daemon_log("$session_id ERROR: no ldap_handle available to create_packages_list_db", 1); - unlink($packages_list_under_construction); - return; - } - } +# if (not defined $ldap_handle) { +# $ldap_handle= &get_ldap_handle(); +# +# if (not defined $ldap_handle) { +# daemon_log("$session_id ERROR: no ldap_handle available to create_packages_list_db", 1); +# unlink($packages_list_under_construction); +# return; +# } +# } if (not defined $sources_file) { &main::daemon_log("$session_id INFO: no sources_file given for creating packages list so trigger creation of it", 5); $sources_file = &create_sources_list($session_id); @@ -3261,6 +3280,18 @@ daemon_log("$0 started!", 1); daemon_log("status: $server_status", 1); daemon_log($server_status_hash->{$server_status}.": $server_revision", 1); +# Create a pool of LDAP handles +$ldap_factory = ResourcePool::Factory::Net::LDAP->new($ldap_uri, version => $ldap_version); +$ldap_factory->bind($ldap_admin_dn, password=>$ldap_admin_password); +$ldap_pool = ResourcePool->new($ldap_factory, + Max => 10, + #MaxTry => 1, + #SleepOnFail => [0, 0, 1, 1], + PreCreate => 5, +); + + +# Buildup data bases { no strict "refs"; diff --git a/gosa-si/modules/ArpHandler.pm b/gosa-si/modules/ArpHandler.pm index f44d72976..03a55ec9a 100644 --- a/gosa-si/modules/ArpHandler.pm +++ b/gosa-si/modules/ArpHandler.pm @@ -78,9 +78,8 @@ sub local_read_configfile { } sub get_module_info { - my @info = (undef, - undef, - ); + my ($ldap_handle) = @_; + my @info = (undef, undef); &local_read_configfile(); # Don't start if some of the modules are missing @@ -94,7 +93,6 @@ sub get_module_info { &main::daemon_log("Loading OUI cache file suceeded!", 6); } } - my $ldap_handle = &main::get_ldap_handle(); # When interface is not configured (or 'all'), start arpwatch on all possible interfaces if ((!defined($arp_interface)) || $arp_interface eq 'all') { diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index 7ae02e44d..b746316cb 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -24,10 +24,8 @@ BEGIN{} END {} my ($server_ip, $server_port, $ClientPackages_key, $max_clients, $ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $server_interface); -#my ($bus_activ, $bus_key, $bus_ip, $bus_port); my $server; my $network_interface; -#my $no_bus; my (@ldap_cfg, @pam_cfg, @nss_cfg, $goto_admin, $goto_secret); my $mesg; @@ -147,6 +145,7 @@ if((not defined($main::gosa_unit_tag)) || length($main::gosa_unit_tag) == 0) { } else { &main::daemon_log("0 INFO: Using gosaUnitTag from config-file: $main::gosa_unit_tag",5); } + &main::release_ldap_handle($ldap_handle); } @@ -263,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) = @_ ; + my ($msg, $msg_hash, $session_id, $ldap_handle) = @_ ; my $error = 0; my $host_name; my $host_key; @@ -291,13 +290,13 @@ sub process_incoming_msg { 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) + @out_msg_l = &here_i_am($msg, $msg_hash, $session_id, $ldap_handle) } 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); + @out_msg_l = &{$event2module_hash->{$header}."::$header"}($msg, $msg_hash, $session_id, $ldap_handle); # if no event handler is implemented } else { @@ -418,7 +417,7 @@ sub new_key { # DESCRIPTION: process this incoming message #=============================================================================== sub here_i_am { - my ($msg, $msg_hash, $session_id) = @_; + my ($msg, $msg_hash, $session_id, $ldap_handle) = @_; my @out_msg_l; my $out_hash; my $source = @{$msg_hash->{source}}[0]; @@ -498,7 +497,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); + my $new_ldap_config_out = &new_ldap_config($source, $session_id, $ldap_handle); 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/){ @@ -519,19 +518,19 @@ sub here_i_am { } # Send client hardware configuration - my $hardware_config_out = &hardware_config($msg, $msg_hash, $session_id); + my $hardware_config_out = &hardware_config($msg, $msg_hash, $session_id, $ldap_handle); 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); + my $ntp_config_out = &new_ntp_config($mac_address, $session_id, $ldap_handle); 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); + my $syslog_config_out = &new_syslog_config($mac_address, $session_id, $ldap_handle); if ($syslog_config_out) { push(@out_msg_l, $syslog_config_out); } @@ -597,16 +596,9 @@ sub who_has_i_do { sub new_syslog_config { - my ($mac_address, $session_id) = @_; + my ($mac_address, $session_id, $ldap_handle) = @_; my $syslog_msg; - # Build LDAP connection - my $ldap_handle = &main::get_ldap_handle($session_id); - if( not defined $ldap_handle ) { - &main::daemon_log("$session_id ERROR: cannot connect to ldap: $ldap_uri", 1); - return; - } - # Perform search my $ldap_res = $ldap_handle->search( base => $ldap_base, scope => 'sub', @@ -673,16 +665,9 @@ sub new_syslog_config { sub new_ntp_config { - my ($address, $session_id) = @_; + my ($address, $session_id, $ldap_handle) = @_; my $ntp_msg; - # Build LDAP connection - my $ldap_handle = &main::get_ldap_handle($session_id); - if( not defined $ldap_handle ) { - &main::daemon_log("$session_id ERROR: cannot connect to ldap: $ldap_uri", 1); - return; - } - # Perform search my $ldap_res = $ldap_handle->search( base => $ldap_base, scope => 'sub', @@ -756,7 +741,7 @@ sub new_ntp_config { # DESCRIPTION: send to address the ldap configuration found for dn gotoLdapServer #=============================================================================== sub new_ldap_config { - my ($address, $session_id) = @_ ; + my ($address, $session_id, $ldap_handle) = @_ ; my $sql_statement= "SELECT * FROM known_clients WHERE hostname='$address' OR macaddress LIKE '$address'"; my $res = $main::known_clients_db->select_dbentry( $sql_statement ); @@ -776,13 +761,6 @@ sub new_ldap_config { return; } - # Build LDAP connection - my $ldap_handle = &main::get_ldap_handle($session_id); - if( not defined $ldap_handle ) { - &main::daemon_log("$session_id ERROR: cannot connect to ldap: $ldap_uri", 1); - return; - } - # Perform search $mesg = $ldap_handle->search( base => $ldap_base, scope => 'sub', @@ -928,7 +906,7 @@ sub new_ldap_config { # DESCRIPTION: #=============================================================================== sub hardware_config { - my ($msg, $msg_hash, $session_id) = @_ ; + my ($msg, $msg_hash, $session_id, $ldap_handle) = @_ ; my $address = @{$msg_hash->{source}}[0]; my $header = @{$msg_hash->{header}}[0]; my $gotoHardwareChecksum = @{$msg_hash->{gotoHardwareChecksum}}[0]; @@ -949,13 +927,6 @@ sub hardware_config { return; } - # Build LDAP connection - my $ldap_handle = &main::get_ldap_handle($session_id); - if( not defined $ldap_handle ) { - &main::daemon_log("$session_id ERROR: cannot connect to ldap: $ldap_uri", 1); - return; - } - # Perform search $mesg = $ldap_handle->search( base => $ldap_base, diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index 3e1b0745c..1677bf942 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) = @_ ; + my ($msg, $msg_hash, $session_id, $ldap_handle) = @_ ; 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); + @msg_l = &process_job_msg($msg, $msg_hash, $session_id, $ldap_handle); } elsif ($header =~ /^gosa_/) { - @msg_l = &process_gosa_msg($msg, $msg_hash, $session_id); + @msg_l = &process_gosa_msg($msg, $msg_hash, $session_id, $ldap_handle); } 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) = @_ ; + my ($msg, $msg_hash, $session_id, $ldap_handle) = @_ ; 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 ); + @out_msg_l = &{$event2module_hash->{$header}."::$header"}( $msg, $msg_hash, $session_id, $ldap_handle ); # check client registered events } else { @@ -217,7 +217,7 @@ sub process_gosa_msg { sub process_job_msg { - my ($msg, $msg_hash, $session_id)= @_ ; + my ($msg, $msg_hash, $session_id, $ldap_handle)= @_ ; my $out_msg; my $error = 0; @@ -260,23 +260,17 @@ sub process_job_msg { } } else { # Try to determine plain_name via ladp search - my $ldap_handle = &main::get_ldap_handle($session_id); - if( not defined $ldap_handle ) { - &main::daemon_log("$session_id ERROR: cannot connect to ldap", 1); - $plain_name = "none"; + my $mesg = $ldap_handle->search( + base => $main::ldap_base, + scope => 'sub', + attrs => ['cn'], + filter => "(macAddress=$macaddress)"); + if($mesg->code || ($mesg->count!=1)) { + &main::daemon_log($mesg->error, 1); + $plain_name = "none"; } else { - my $mesg = $ldap_handle->search( - base => $main::ldap_base, - scope => 'sub', - attrs => ['cn'], - filter => "(macAddress=$macaddress)"); - if($mesg->code || ($mesg->count!=1)) { - &main::daemon_log($mesg->error, 1); - $plain_name = "none"; - } else { - my $entry= $mesg->entry(0); - $plain_name = $entry->get_value("cn"); - } + my $entry= $mesg->entry(0); + $plain_name = $entry->get_value("cn"); } } diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index d6aafa43f..9b156820c 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -524,7 +524,7 @@ sub import_events { if ($error == 0) { while (defined (my $event = readdir ($DIR))) { - if( $event eq "." || $event eq ".." ) { next; } + if( $event eq "." || $event eq ".." || ($event =~ /^\.pm$/)) { next; } # Check config file to exclude disabled event plugins (i.e. Opsi) if ($event eq "opsi_com.pm" && $main::opsi_enabled ne "true") { diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index 8e2301738..15120393f 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) = @_; + my ($msg, $msg_hash, $session_id, $ldap_handle) = @_; 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); + $res = &set_last_system($msg, $msg_hash, $session_id, $ldap_handle); # 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) = @_; + my ($msg, $msg_hash, $session_id, $ldap_handle) = @_; 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); + my $res = &set_last_system($msg, $msg_hash, $session_id, $ldap_handle); # 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) = @_; + my ($msg, $msg_hash, $session_id, $ldap_handle) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $login = @{$msg_hash->{$header}}[0]; @@ -306,9 +306,6 @@ sub set_last_system { return; } - # Fetch ldap handle - my $ldap_handle = &main::get_ldap_handle(); - # Get system info my $ldap_mesg= $ldap_handle->search( base => $main::ldap_base, @@ -510,7 +507,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) = @_; + my ($msg, $msg_hash, $session_id, $ldap_handle) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; @@ -583,25 +580,17 @@ 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); - if( not defined $ldap_handle ) { - &main::daemon_log("$session_id ERROR: cannot connect to ldap", 1); - $plain_name = "none"; - - # try to fetch a 'real name' + my $mesg = $ldap_handle->search( + base => $main::ldap_base, + scope => 'sub', + attrs => ['cn'], + filter => "(macAddress=$macaddress)"); + if(not $mesg->code) { + my $entry= $mesg->entry(0); + $plain_name = $entry->get_value("cn"); } else { - my $mesg = $ldap_handle->search( - base => $main::ldap_base, - scope => 'sub', - attrs => ['cn'], - filter => "(macAddress=$macaddress)"); - if($mesg->code) { - &main::daemon_log($mesg->error, 1); - $plain_name = "none"; - } else { - my $entry= $mesg->entry(0); - $plain_name = $entry->get_value("cn"); - } + &main::daemon_log($mesg->error, 1); + $plain_name = "none"; } # In any case add a new job to job queue diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 8742aec16..50ff10f89 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -800,7 +800,7 @@ sub get_available_kernel { } sub trigger_activate_new { - my ($msg, $msg_hash, $session_id) = @_; + my ($msg, $msg_hash, $session_id, $ldap_handle) = @_; my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; @@ -833,7 +833,6 @@ sub trigger_activate_new { my $error = &main::send_msg_to_target($wake_msg, $host_name, $host_key, $header, $session_id); } - my $ldap_handle = &main::get_ldap_handle(); my $ldap_entry; my $ogroup_entry; my $changed_attributes_counter = 0; diff --git a/gosa-si/server/events/siTriggered.pm b/gosa-si/server/events/siTriggered.pm index 7de3c5a7c..d4ec0c668 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) = @_; + my ($msg, $msg_hash, $session_id, $ldap_handle) = @_; my $address = $msg_hash->{source}[0]; my $header = $msg_hash->{header}[0]; my $gotoHardwareChecksum= $msg_hash->{detected_hardware}[0]->{gotoHardwareChecksum}; @@ -145,12 +145,6 @@ sub detected_hardware { &main::daemon_log("$session_id ERROR: no mac address found for client $address", 1); return; } - # Build LDAP connection - my $ldap_handle = &main::get_ldap_handle($session_id); - if( not defined $ldap_handle ) { - &main::daemon_log("$session_id ERROR: cannot connect to ldap: $ldap_uri", 1); - return; - } # Perform search $mesg = $ldap_handle->search( -- 2.30.2