summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3111de6)
raw | patch | inline | side by side (parent: 3111de6)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 11 Mar 2009 13:45:58 +0000 (13:45 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 11 Mar 2009 13:45:58 +0000 (13:45 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13528 594d385d-05f5-0310-b6e9-bd551577e9d8
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 2b0c4c1a4b58ed042d8c7e41e44b6b2e01d87b86..17483bb6973b6a7a773404e37d7529eceb31b94f 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
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;
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;
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;
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;
"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'],
}
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;
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};
}
}
}
-
+ &release_ldap_handle($ldap_handle);
close (DIR);
}
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 {
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);
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});
attrs => ['memberUid'],
filter => "cn=$group_name",
);
+ &release_ldap_handle($ldap_handle);
if ($mesg->count) {
my @entries = $mesg->entries;
foreach my $entry (@entries) {
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) = @_;
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)";
return;
}
+ my $ldap_handle = &get_ldap_handle($session_id);
# Perform search for Unit Tag
my $mesg = $ldap_handle->search(
base => $ldap_base,
} 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;
}
}
}
+ &release_ldap_handle($ldap_handle);
+ return;
}
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(
# 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(
}
daemon_log("$session_id INFO: create_fai_release_db: finished",5);
}
- $ldap_handle->disconnect;
+ #&release_ldap_handle($ldap_handle);
return $result;
}
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
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)}) {
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",
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
}
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);
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";
index f44d72976fddba51a982ef0c72a96017d87a79e9..03a55ec9a5408f2c25eb4d1a93a2eb2073cececd 100644 (file)
}
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
&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') {
index 7ae02e44dd302cce9f0e2f91827f5822bf0be326..b746316cbe528db5cd7e568c6f6e8f2abde9e3a8 100644 (file)
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;
} else {
&main::daemon_log("0 INFO: Using gosaUnitTag from config-file: $main::gosa_unit_tag",5);
}
+ &main::release_ldap_handle($ldap_handle);
}
# 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;
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 {
# 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];
# 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/){
}
# 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);
}
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',
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',
# 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 );
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',
# 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];
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,
index 3e1b0745c840fc92d13498183e35ab8b83b51cdb..1677bf942d8b94c83c695b01c26b1f8ae711f13e 100644 (file)
# 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;
&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);
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;
# 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 {
sub process_job_msg {
- my ($msg, $msg_hash, $session_id)= @_ ;
+ my ($msg, $msg_hash, $session_id, $ldap_handle)= @_ ;
my $out_msg;
my $error = 0;
}
} 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");
}
}
index d6aafa43f1f3a821bc7cde046a4ffb957a37159a..9b156820c668603b9f14062caa752249ee32c4b2 100644 (file)
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") {
index 8e230173842a89cc22199e23a55b7f18dd822cfe..15120393f2dabf4339fe645b3380de6f80d2a90d 100644 (file)
# @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];
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,
# @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];
}
# 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 = ();
# @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];
return;
}
- # Fetch ldap handle
- my $ldap_handle = &main::get_ldap_handle();
-
# Get system info
my $ldap_mesg= $ldap_handle->search(
base => $main::ldap_base,
# @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];
# 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
index 8742aec166f18e1ee7ba6854a05dda85dcde8924..50ff10f89b301af46f54110267146245bcee3771 100644 (file)
}
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];
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;
index 7de3c5a7c430304f2838c0601e268f3cc21aa674..d4ec0c668911a0871c2b426a466a6d8c4426af3d 100644 (file)
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};
&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(