From: rettenbe Date: Thu, 20 Mar 2008 15:06:33 +0000 (+0000) Subject: change handling of ladp connection X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d85e06e6826defb93de1f1c494d4bedf090c1c78;p=gosa.git change handling of ladp connection git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9956 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index d3328ea86..fc71afdc8 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -752,6 +752,7 @@ sub register_at_gosa_si_server { $client_address= "$client_ip:$client_port"; $client_mac_address = $local_mac; $client_dnsname = $dnsname; + last; # delivery of registration msg failed } else { diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 75d9e340d..cb759af22 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -58,7 +58,7 @@ use lib "/usr/lib/gosa-si/modules"; # - ist es nicht vorhanden, wird es erzeugt, im heap für spätere ldap anfragen gespeichert und zurückgegeben # - sessions die kein ldap handle brauchen, sollen auch keins haben # - wird eine session geschlossen, muss das ldap verbindung vorher beendet werden -#our $global_kernel; +our $global_kernel; my (%cfg_defaults, $foreground, $verbose, $ping_timeout); my ($bus_activ, $bus, $msg_to_bus, $bus_cipher); @@ -90,7 +90,8 @@ our $no_arp; our $verbose; our $forground; our $cfg_file; -our ($ldap_handle, $ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $ldap_server_dn); +#our ($ldap_handle, $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); # specifies the verbosity of the daemon_log @@ -429,9 +430,11 @@ sub import_modules { sub sig_int_handler { my ($signal) = @_; - if (defined($ldap_handle)) { - $ldap_handle->disconnect; - } +# if (defined($ldap_handle)) { +# $ldap_handle->disconnect; +# } + # TODO alle verbliebenden ldap verbindungen aus allen heaps beenden + daemon_log("shutting down gosa-si-server", 1); system("killall gosa-si-server"); @@ -1053,6 +1056,7 @@ sub process_task { if(( !$msg ) || ( !$msg_hash ) || ( !$module )){ # if an incoming msg could not be decrypted (maybe a wrong key), send client a ping. If the client # could not understand a msg from its server the client cause a re-registering process + daemon_log("$session_id INFO cannot understand incoming msg, send 'ping'-msg to all host with ip '".$heap->{remote_ip}."' to cause a re-registering of the client if necessary", 5); my $sql_statement = "SELECT * FROM $main::known_clients_tn WHERE (hostname LIKE '".$heap->{'remote_ip'}."%')"; my $query_res = $known_clients_db->select_dbentry( $sql_statement ); while( my ($hit_num, $hit) = each %{ $query_res } ) { @@ -1290,71 +1294,34 @@ sub get_ldap_handle { my ($session_id) = @_; my $heap; my $ldap_handle; - - if (not defined $session_id) { - daemon_log("0 DEBUG: need a session_id to fetch the correct ldap handle", 7); - return; - } - - 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; - } - - if (not exists $heap->{ldap_handle}) { - # create new ldap handle - my $ldap_handle = Net::LDAP->new( $ldap_uri ); - # add ldap handle to heap - $heap->{ldap_handle} = $ldap_handle; - } - - $ldap_handle = $heap->{ldap_handle}; + if (not defined $session_id ) { $session_id = 0 }; - return \$ldap_handle; -} + 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 ); + } else { + my $session_reference = $global_kernel->ID_id_to_session($session_id); + if( defined $session_reference ) { + $heap = $session_reference->get_heap(); + } -sub refresh_ldap_handle { - my ($session_id) = @_ ; - if (not defined $session_id) { $session_id = 0; } - - my $mesg; - - daemon_log("$session_id DEBUG: Trying to create a connection to URI '$ldap_uri'", 7); - # Get an ldap handle, if we don't have one - if( ! defined $ldap_handle ){ - $ldap_handle = Net::LDAP->new( $ldap_uri ); - } - # Still not defined? - if( ! defined $ldap_handle ) { - daemon_log( "$session_id ERROR: ch $$: Net::LDAP constructor failed: $!\n" ); - return 0; - } + if (not defined $heap) { + daemon_log("$session_id DEBUG: cannot get heap for session_id '$session_id'", 7); + return; + } - # Bind to ldap server - eventually authenticate - if( defined $ldap_admin_dn ) { - if( defined $ldap_admin_password ) { - $mesg = $ldap_handle->bind( $ldap_admin_dn, password => $ldap_admin_password ); - } else { - $mesg = $ldap_handle->bind( $ldap_admin_dn ); + if (not exists $heap->{ldap_handle}) { + # create new ldap handle + $ldap_handle = Net::LDAP->new( $ldap_uri ); + # add ldap handle to heap + $heap->{ldap_handle} = $ldap_handle; + } } - } else { - $mesg = $ldap_handle->bind(); - } - if( 0 != $mesg->code ) { - undef( $ldap_handle ) if( 81 == $mesg->code ); - daemon_log( "$session_id ERROR: ch $$: LDAP bind: error (". $mesg->code . ') - ' . $mesg->error . "\n", 1); - return 0; - } - daemon_log("$session_id DEBUG: create a new connection to URI '$ldap_uri'", 7); - return 1; + + return $ldap_handle; } @@ -1382,8 +1349,7 @@ sub change_fai_state { my $state= $mapActions{ $st }; - &refresh_ldap_handle(); -# my $ldap_handle = get_ldap_handle($session_id); + my $ldap_handle = get_ldap_handle($session_id); if( defined($ldap_handle) ) { # Build search filter for hosts @@ -1443,6 +1409,7 @@ sub change_fai_state { } else { daemon_log("$session_id ERROR: no LDAP handle defined for update FAIstate", 1); } + } @@ -1453,7 +1420,7 @@ sub change_goto_state { # Switch on or off? my $state= $st eq 'active' ? 'active': 'locked'; - &refresh_ldap_handle(); + my $ldap_handle = &get_ldap_handle($session_id); if( defined($ldap_handle) ) { # Build search filter for hosts @@ -1504,7 +1471,7 @@ sub change_goto_state { sub create_fai_server_db { my ($table_name, $kernel) = @_; my $result; - + my $ldap_handle = &get_ldap_handle(); if(defined($ldap_handle)) { daemon_log("INFO: create_fai_server_db: start", 5); my $mesg= $ldap_handle->search( @@ -1536,9 +1503,10 @@ sub create_fai_server_db { daemon_log("INFO: create_fai_server_db: finished", 5); # TODO: Find a way to post the 'create_packages_list_db' event - &create_packages_list_db(); + &create_packages_list_db($ldap_handle); } - + + $ldap_handle->disconnect; return $result; } @@ -1560,6 +1528,7 @@ sub create_fai_release_db { my ($table_name) = @_; my $result; + my $ldap_handle = &get_ldap_handle(); if(defined($ldap_handle)) { daemon_log("INFO: create_fai_release_db: start",5); my $mesg= $ldap_handle->search( @@ -1574,7 +1543,7 @@ sub create_fai_release_db { my @sql_list; my $timestamp= &get_time(); foreach my $ou (@{$mesg->{entries}}) { - my $tmp_classes= resolve_fai_classes($ou->dn); + my $tmp_classes= resolve_fai_classes($ou->dn, $ldap_handle); if(defined($tmp_classes) && ref($tmp_classes) eq 'HASH') { my @tmp_array=get_fai_release_entries($tmp_classes); if(@tmp_array) { @@ -1603,7 +1572,7 @@ sub create_fai_release_db { } daemon_log("INFO: create_fai_release_db: finished",5); } - + $ldap_handle->disconnect; return $result; } sub run_create_fai_release_db { @@ -1653,8 +1622,8 @@ sub get_fai_state { } sub resolve_fai_classes { + my ($fai_base, $ldap_handle) = @_; my $result; - my $fai_base= shift; my @possible_fai_classes= ("FAIscript", "FAIhook", "FAIpartitionTable", "FAItemplate", "FAIvariable", "FAIprofile", "FAIpackageList"); my $fai_filter= "(|(&(objectClass=FAIclass)(|(objectClass=".join(")(objectClass=", @possible_fai_classes).")))(objectClass=FAIbranch))"; my $fai_classes; @@ -1858,6 +1827,7 @@ sub session_run_done { } sub create_sources_list { + my ($ldap_handle) = @_; my $result="/tmp/gosa_si_tmp_sources_list"; # Remove old file @@ -1890,7 +1860,16 @@ sub create_sources_list { } sub create_packages_list_db { - my ($sources_file) = @_ || &create_sources_list; + my ($ldap_handle, $sources_file) = @_ ; + + if (not defined $ldap_handle) { + daemon_log("0 ERROR: no ldap_handle available to create_packages_list_db", 1); + return; + } + if (not defined $sources_file) { + $sources_file = &create_sources_list($ldap_handle); + } + my $line; daemon_log("INFO: create_packages_list_db: start", 5); diff --git a/gosa-si/modules/ArpHandler.pm b/gosa-si/modules/ArpHandler.pm index e920e6230..d6da11d4b 100644 --- a/gosa-si/modules/ArpHandler.pm +++ b/gosa-si/modules/ArpHandler.pm @@ -94,13 +94,13 @@ sub get_module_info { &main::daemon_log("Loading OUI cache file suceeded!", 6); } } + my $ldap_handle = &main::get_ldap_handle(); if(defined($ldap_uri) && length($ldap_uri)>0) { - &main::refresh_ldap_handle(); - if (!$main::ldap_handle) { + if (!$ldap_handle) { &main::daemon_log("Could not connect to LDAP Server at $ldap_uri!\n$@", 1); } } else { - $main::ldap_handle= undef; + $ldap_handle= undef; } # When interface is not configured (or 'all'), start arpwatch on all possible interfaces @@ -177,7 +177,8 @@ sub got_packet { my $capture_device = sprintf "%s", $kernel->alias_list($sender) =~ /^arp_watch_(.*)$/; - if(!exists($hosts_database->{$packet->{source_haddr}})) { + my $ldap_handle = &main::get_ldap_handle(); + if(!exists($hosts_database->{$packet->{source_haddr}})) { my $dnsname= gethostbyaddr(inet_aton($packet->{source_ipaddr}), AF_INET) || $packet->{source_ipaddr}; my $ldap_result=&get_host_from_ldap($packet->{source_haddr}); if(exists($ldap_result->{dn})) { @@ -209,7 +210,7 @@ sub got_packet { ": ".$hosts_database->{$packet->{source_haddr}}->{ipHostNumber}. "/".$hosts_database->{$packet->{source_haddr}}->{macAddress},4); &add_ldap_entry( - $main::ldap_handle, + $ldap_handle, $ldap_base, $hosts_database->{$packet->{source_haddr}}->{macAddress}, 'new-system', @@ -226,7 +227,7 @@ sub got_packet { "->".$packet->{source_ipaddr}, 4); $hosts_database->{$packet->{source_haddr}}->{ipHostNumber}= $packet->{source_ipaddr}; &change_ldap_entry( - $main::ldap_handle, + $ldap_handle, $ldap_base, $hosts_database->{$packet->{source_haddr}}->{macAddress}, 'ip-changed', @@ -242,9 +243,10 @@ sub get_host_from_ldap { my $mac=shift; my $result={}; - if(defined($main::ldap_handle)) { + my $ladp_handle = &get_ldap_handle(); + if(defined($ldap_handle)) { my $ldap_result= &search_ldap_entry( - $main::ldap_handle, + $ldap_handle, $ldap_base, "(|(macAddress=$mac)(dhcpHWAddress=ethernet $mac))" ); @@ -440,7 +442,7 @@ sub change_ldap_entry { if (defined($ip)) { $replace->{'ipHostNumber'} = $ip; } - my $result = $main::ldap_handle->modify( $dn, replace => $replace ); + my $result = $ldap_tree->modify( $dn, replace => $replace ); # for $result->code constants please look at Net::LDAP::Constant if($result->code == 32) { # entry doesnt exists diff --git a/gosa-si/modules/SIPackages.pm b/gosa-si/modules/SIPackages.pm index daaa161e1..265b72416 100644 --- a/gosa-si/modules/SIPackages.pm +++ b/gosa-si/modules/SIPackages.pm @@ -70,11 +70,12 @@ $main::server_mac_address= &get_mac($network_interface); # Unit tag can be defined in config if((not defined($main::gosa_unit_tag)) || length($main::gosa_unit_tag) == 0) { # Read gosaUnitTag from LDAP - &main::refresh_ldap_handle(); - if( defined($main::ldap_handle) ) { + + my $ldap_handle = &main::get_ldap_handle(); + if( defined($ldap_handle) ) { &main::daemon_log("INFO: Searching for servers gosaUnitTag with mac address $main::server_mac_address",5); # Perform search for Unit Tag - $mesg = $main::ldap_handle->search( + $mesg = $ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['gosaUnitTag'], @@ -94,7 +95,7 @@ if((not defined($main::gosa_unit_tag)) || length($main::gosa_unit_tag) == 0) { my $hostname= `hostname -f`; chomp($hostname); &main::daemon_log("INFO: Searching for servers gosaUnitTag with hostname $hostname",5); - $mesg = $main::ldap_handle->search( + $mesg = $ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['gosaUnitTag'], @@ -113,7 +114,7 @@ if((not defined($main::gosa_unit_tag)) || length($main::gosa_unit_tag) == 0) { $hostname= `hostname -s`; chomp($hostname); &main::daemon_log("INFO: Searching for servers gosaUnitTag with hostname $hostname",5); - $mesg = $main::ldap_handle->search( + $mesg = $ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['gosaUnitTag'], @@ -689,14 +690,14 @@ sub new_ldap_config { } # Build LDAP connection - &main::refresh_ldap_handle(); - if( not defined $main::ldap_handle ) { + 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 = $main::ldap_handle->search( base => $ldap_base, + $mesg = $ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['dn', 'gotoLdapServer', 'gosaUnitTag', 'FAIclass'], filter => "(&(objectClass=GOhard)(macaddress=$macaddress)(gotoLdapServer=*))"); @@ -733,7 +734,7 @@ sub new_ldap_config { # Do we need to look at an object class? if (length(@servers) < 1){ - $mesg = $main::ldap_handle->search( base => $ldap_base, + $mesg = $ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['dn', 'gotoLdapServer', 'FAIclass'], filter => "(&(objectClass=gosaGroupOfNames)(member=$dn))"); @@ -796,7 +797,7 @@ sub new_ldap_config { if (defined $unit_tag){ # Find admin base and department name - $mesg = $main::ldap_handle->search( base => $ldap_base, + $mesg = $ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['dn', 'ou'], filter => "(&(objectClass=gosaAdministrativeUnit)(gosaUnitTag=$unit_tag))"); @@ -854,14 +855,14 @@ sub hardware_config { } # Build LDAP connection - &main::refresh_ldap_handle(); - if( not defined $main::ldap_handle ) { + my $ldap_handle = &main::get_ldap_handle($session_id); + if( not defined $ldap_handle ) { &main::daemon_log("ERROR: cannot connect to ldap: $ldap_uri", 1); return; } # Perform search - $mesg = $main::ldap_handle->search( + $mesg = $ldap_handle->search( base => $ldap_base, scope => 'sub', filter => "(&(objectClass=GOhard)(|(macAddress=$macaddress)(dhcpHWaddress=ethernet $macaddress)))" @@ -891,7 +892,7 @@ sub hardware_config { if (defined($entry->get_value("gotoHardwareChecksum"))) { if (! $entry->get_value("gotoHardwareChecksum") eq $gotoHardwareChecksum) { $entry->replace(gotoHardwareChecksum => $gotoHardwareChecksum); - if($entry->update($main::ldap_handle)) { + if($entry->update($ldap_handle)) { &main::daemon_log("$session_id INFO: Hardware changed! Detection triggered.", 5); } } else { diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 7c15ab22b..b95f0d5c9 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -86,17 +86,17 @@ sub send_user_msg { } + my $ldap_handle = &main::get_ldap_handle($session_id); # resolve groups to users if( @group_list ) { # build ldap connection - &main::refresh_ldap_handle(); - if( not defined $main::ldap_handle ) { + if( not defined $ldap_handle ) { &main::daemon_log("ERROR: cannot connect to ldap", 1); return (); } foreach my $group (@group_list) { # Perform search - my $mesg = $main::ldap_handle->search( + my $mesg = $ldap_handle->search( base => $main::ldap_base, scope => 'sub', attrs => ['memberUid'], diff --git a/gosa-si/server/events/siTriggered.pm b/gosa-si/server/events/siTriggered.pm index 53ae3d58f..104cd8f1f 100644 --- a/gosa-si/server/events/siTriggered.pm +++ b/gosa-si/server/events/siTriggered.pm @@ -141,14 +141,14 @@ sub detected_hardware { return; } # Build LDAP connection - &main::refresh_ldap_handle(); - if( not defined $main::ldap_handle ) { + my $ldap_handle = &main::get_ldap_handle($session_id); + if( not defined $ldap_handle ) { &main::daemon_log("ERROR: cannot connect to ldap: $ldap_uri", 1); return; } # Perform search - $mesg = $main::ldap_handle->search( + $mesg = $ldap_handle->search( base => $ldap_base, scope => 'sub', filter => "(&(objectClass=GOhard)(|(macAddress=$macaddress)(dhcpHWaddress=ethernet $macaddress)))" @@ -183,14 +183,14 @@ sub detected_hardware { $entry->add("objectClass" => "gosaAdministrativeUnitTag"); $entry->add("gosaUnitTag" => $main::gosa_unit_tag); } - my $res=$entry->update($main::ldap_handle); + my $res=$entry->update($ldap_handle); if(defined($res->{'errorMessage'}) && length($res->{'errorMessage'}) >0) { &main::daemon_log("ERROR: can not add entries to LDAP: ".$res->{'errorMessage'}, 1); return; } else { # Fill $mesg again - $mesg = $main::ldap_handle->search( + $mesg = $ldap_handle->search( base => $ldap_base, scope => 'sub', filter => "(&(objectClass=GOhard)(|(macAddress=$macaddress)(dhcpHWaddress=ethernet $macaddress)))" @@ -227,7 +227,7 @@ sub detected_hardware { } } - my $res=$entry->update($main::ldap_handle); + my $res=$entry->update($ldap_handle); if(defined($res->{'errorMessage'}) && length($res->{'errorMessage'}) >0) { &main::daemon_log("ERROR: can not add entries to LDAP: ".$res->{'errorMessage'}, 1); diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 6bf855f16..5b81853b0 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -28,7 +28,7 @@ if($sock->connected()){ #$data = "
gosa_gen_smb_hash
GOSAGOSAtester
"; # Reload ldap config -#$data = "
gosa_trigger_reload_ldap_config
GOSA00:01:6c:9d:b9:fa
"; +$data = "
gosa_trigger_reload_ldap_config
GOSA00:01:6c:9d:b9:fa
"; # jobdb update #$data = "
gosa_update_status_jobdb_entry
GOSA GOSA 1 19700101000000
"; @@ -58,7 +58,7 @@ if($sock->connected()){ #$data = "
gosa_new_key_for_client
00:01:6c:9d:b9:fa 10.89.1.31:20081
"; #$data = "
job_trigger_action_wake
00:01:6c:9d:b9:fa GOSA 19700101000000
"; #$data = "
gosa_trigger_action_faireboot
00:01:6c:9d:b9:fa GOSA
"; -$data = "
job_trigger_action_reinstall
GOSA 00:01:6c:9d:b9:fa 00:01:6c:9d:b9:fa 19700101000000
"; +#$data = "
job_trigger_action_reinstall
GOSA 00:01:6c:9d:b9:fa 00:01:6c:9d:b9:fa 19700101000000
"; #$data = "
job_trigger_action_instant_update
00:01:6c:9d:b9:fa GOSA 19700101000000
"; #$data = "
gosa_ping
00:01:6c:9d:b9:fa GOSA
";