From 78a6fac1b17361844b75ad1bbae55fc590a327cf Mon Sep 17 00:00:00 2001 From: cajus Date: Wed, 27 Feb 2008 08:03:50 +0000 Subject: [PATCH] Updated git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9145 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 31 ++++++++---------- gosa-si/modules/ArpHandler.pm | 22 +++++-------- gosa-si/modules/SIPackages.pm | 49 +++++++++------------------- gosa-si/server/events/siTriggered.pm | 16 ++++----- 4 files changed, 44 insertions(+), 74 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index aac8b3c99..ddaae29b6 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -76,6 +76,7 @@ our $no_arp; our $verbose; our $forground; our $cfg_file; +our $ldap_handle; # specifies the verbosity of the daemon_log $verbose = 0 ; @@ -1120,7 +1121,7 @@ sub watch_for_new_jobs { } -sub get_ldap_handle { +sub refresh_ldap_handle { my $mesg; # Get an ldap handle, if we don't have one @@ -1138,20 +1139,18 @@ sub get_ldap_handle { if( defined $ldap_admin_password ) { $mesg = $ldap_handle->bind( $ldap_admin_dn, password => $ldap_admin_password ); } else { - $mesg = $ldap_handle->bind( $ldap_admin_dn );# + $mesg = $ldap_handle->bind( $ldap_admin_dn ); } - } - else { + } else { $mesg = $ldap_handle->bind(); } if( 0 != $mesg->code ) { undef( $ldap_handle ) if( 81 == $mesg->code ); - daemon_log( "ch $$: LDAP bind: error (" - . $mesg->code . ') - ' . $mesg->error . "\n" ); + daemon_log( "ch $$: LDAP bind: error (". $mesg->code . ') - ' . $mesg->error . "\n", 1); return 0; } - #HIER IST EIN FEHLER..... + return 1; } @@ -1164,16 +1163,14 @@ sub create_fai_server_db { # # ################################################################### - - - $fai_server_db->add_dbentry( { - table => $fai_server_tn, - primkey => [], - server => "dummyserver", - release => "kleinkind", - tag => "imwachstum", - } ); - return; + $fai_server_db->add_dbentry( { + table => $fai_server_tn, + primkey => [], + server => "dummyserver", + release => "kleinkind", + tag => "imwachstum", + } ); + return; } diff --git a/gosa-si/modules/ArpHandler.pm b/gosa-si/modules/ArpHandler.pm index 9a4b6657a..d81ef57d5 100644 --- a/gosa-si/modules/ArpHandler.pm +++ b/gosa-si/modules/ArpHandler.pm @@ -96,14 +96,12 @@ sub get_module_info { } } if(defined($ldap_uri) && length($ldap_uri)>0) { - $ldap = Net::LDAP->new($ldap_uri); - if (!$ldap) { + &main::refresh_ldap_handle(); + if (!$main::ldap_handle) { &main::daemon_log("Could not connect to LDAP Server at $ldap_uri!\n$@", 1); - } else { - $ldap->bind($ldap_admin_dn, password => $ldap_admin_password); } } else { - $ldap=undef; + $main::ldap_handle= undef; } # When interface is not configured (or 'all'), start arpwatch on all possible interfaces @@ -124,8 +122,6 @@ sub get_module_info { &start(@_,$device); }, _stop => sub { - $ldap->unbind if (defined($ldap)); - $ldap->disconnect if (defined($ldap)); $_[KERNEL]->post( sprintf("arp_watch_$device") => 'shutdown' ) }, got_packet => \&got_packet, @@ -142,8 +138,6 @@ sub get_module_info { &start(@_,$device); }, _stop => sub { - $ldap->unbind if (defined($ldap)); - $ldap->disconnect if (defined($ldap)); $_[KERNEL]->post( sprintf("arp_watch_$device") => 'shutdown' ) }, got_packet => \&got_packet, @@ -217,7 +211,7 @@ sub got_packet { ": ".$hosts_database->{$packet->{source_haddr}}->{ipHostNumber}. "/".$hosts_database->{$packet->{source_haddr}}->{macAddress},4); &add_ldap_entry( - $ldap, + $main::ldap_handle, $ldap_base, $hosts_database->{$packet->{source_haddr}}->{macAddress}, 'new-system', @@ -234,7 +228,7 @@ sub got_packet { "->".$packet->{source_ipaddr}, 4); $hosts_database->{$packet->{source_haddr}}->{ipHostNumber}= $packet->{source_ipaddr}; &change_ldap_entry( - $ldap, + $main::ldap_handle, $ldap_base, $hosts_database->{$packet->{source_haddr}}->{macAddress}, 'ip-changed', @@ -250,9 +244,9 @@ sub get_host_from_ldap { my $mac=shift; my $result={}; - if(defined($ldap)) { + if(defined($main::ldap_handle)) { my $ldap_result= &search_ldap_entry( - $ldap, + $main::ldap_handle, $ldap_base, "(|(macAddress=$mac)(dhcpHWAddress=ethernet $mac))" ); @@ -448,7 +442,7 @@ sub change_ldap_entry { if (defined($ip)) { $replace->{'ipHostNumber'} = $ip; } - my $result = $ldap->modify( $dn, replace => $replace ); + my $result = $main::ldap_handle->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 50efa409c..19a4dfcac 100644 --- a/gosa-si/modules/SIPackages.pm +++ b/gosa-si/modules/SIPackages.pm @@ -32,6 +32,7 @@ my $event_hash; my $network_interface; my $no_bus; my (@ldap_cfg, @pam_cfg, @nss_cfg, $goto_admin, $goto_secret); +my $mesg; my %cfg_defaults = ( "bus" => { @@ -71,12 +72,11 @@ $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 - my $tmp_ldap= Net::LDAP->new($ldap_uri); - if( defined($tmp_ldap) ) { + &main::refresh_ldap_handle(); + if( defined($main::ldap_handle) ) { &main::daemon_log("INFO: Searching for servers gosaUnitTag with mac address $server_mac_address",5); - my $mesg= $tmp_ldap->bind($ldap_admin_dn, password => $ldap_admin_password); # Perform search for Unit Tag - $mesg = $tmp_ldap->search( + $mesg = $main::ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['gosaUnitTag'], @@ -95,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 = $tmp_ldap->search( + $mesg = $main::ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['gosaUnitTag'], @@ -113,7 +113,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 = $tmp_ldap->search( + $mesg = $main::ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['gosaUnitTag'], @@ -131,7 +131,6 @@ if((not defined($main::gosa_unit_tag)) || length($main::gosa_unit_tag) == 0) { } } } - $tmp_ldap->unbind; } else { &main::daemon_log("INFO: Using gosaUnitTag from config-file: $main::gosa_unit_tag",5); } @@ -673,18 +672,14 @@ sub new_ldap_config { } # Build LDAP connection - my $ldap = Net::LDAP->new($ldap_uri); - if( not defined $ldap ) { + &main::refresh_ldap_handle(); + if( not defined $main::ldap_handle ) { &main::daemon_log("ERROR: cannot connect to ldap: $ldap_uri", 1); return; } - - # Bind to a directory with dn and password - my $mesg= $ldap->bind($ldap_admin_dn, password => $ldap_admin_password); - # Perform search - $mesg = $ldap->search( base => $ldap_base, + $mesg = $main::ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['dn', 'gotoLdapServer', 'gosaUnitTag', 'FAIclass'], filter => "(&(objectClass=GOhard)(macaddress=$macaddress))"); @@ -721,7 +716,7 @@ sub new_ldap_config { # Do we need to look at an object class? if (length(@servers) < 1){ - $mesg = $ldap->search( base => $ldap_base, + $mesg = $main::ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['dn', 'gotoLdapServer', 'FAIclass'], filter => "(&(objectClass=gosaGroupOfNames)(member=$dn))"); @@ -782,7 +777,7 @@ sub new_ldap_config { if (defined $unit_tag){ # Find admin base and department name - $mesg = $ldap->search( base => $ldap_base, + $mesg = $main::ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['dn', 'ou'], filter => "(&(objectClass=gosaAdministrativeUnit)(gosaUnitTag=$unit_tag))"); @@ -806,14 +801,6 @@ sub new_ldap_config { $data{'unit_tag'}= $unit_tag; } - - # Unbind - $mesg = $ldap->unbind; - if($mesg->code) { - &main::daemon_log($mesg->error, 1); - return; - } - # Send information return &build_msg("new_ldap_config", $server_address, $address, \%data); } @@ -846,17 +833,14 @@ sub hardware_config { } # Build LDAP connection - my $ldap = Net::LDAP->new($ldap_uri); - if( not defined $ldap ) { + &main::refresh_ldap_handle(); + if( not defined $main::ldap_handle ) { &main::daemon_log("ERROR: cannot connect to ldap: $ldap_uri", 1); return; } - # Bind to a directory with dn and password - my $mesg= $ldap->bind($ldap_admin_dn, password => $ldap_admin_password); - # Perform search - $mesg = $ldap->search( + $mesg = $main::ldap_handle->search( base => $ldap_base, scope => 'sub', filter => "(&(objectClass=GOhard)(|(macAddress=$macaddress)(dhcpHWaddress=ethernet $macaddress)))" @@ -870,7 +854,7 @@ sub hardware_config { if(defined($entry->get_value("gotoHardwareChecksum"))) { if(! $entry->get_value("gotoHardwareChecksum") eq $gotoHardwareChecksum) { $entry->replace(gotoHardwareChecksum => $gotoHardwareChecksum); - if($entry->update($ldap)) { + if($entry->update($main::ldap_handle)) { &main::daemon_log("Hardware changed! Detection triggered.", 4); } } else { @@ -889,9 +873,6 @@ sub hardware_config { $data{'goto_secret'}= $goto_secret; } - # Unbind - $mesg = $ldap->unbind; - &main::daemon_log("Send detect_hardware message to $address", 4); # Send information diff --git a/gosa-si/server/events/siTriggered.pm b/gosa-si/server/events/siTriggered.pm index 297b91f1d..fe3a373f9 100644 --- a/gosa-si/server/events/siTriggered.pm +++ b/gosa-si/server/events/siTriggered.pm @@ -25,6 +25,7 @@ my $ldap_uri; my $ldap_base; my $ldap_admin_dn; my $ldap_admin_password; +my $mesg; my %cfg_defaults = ( "server" => { @@ -140,17 +141,14 @@ sub detected_hardware { return; } # Build LDAP connection - my $ldap = Net::LDAP->new($ldap_uri); - if( not defined $ldap ) { + &main::refresh_ldap_handle(); + if( not defined $main::ldap_handle ) { &main::daemon_log("ERROR: cannot connect to ldap: $ldap_uri", 1); return; } - # Bind to a directory with dn and password - my $mesg= $ldap->bind($ldap_admin_dn, password => $ldap_admin_password); - # Perform search - $mesg = $ldap->search( + $mesg = $main::ldap_handle->search( base => $ldap_base, scope => 'sub', filter => "(&(objectClass=GOhard)(|(macAddress=$macaddress)(dhcpHWaddress=ethernet $macaddress)))" @@ -177,14 +175,14 @@ sub detected_hardware { $entry->add("objectClass" => "gosaAdministrativeUnitTag"); $entry->add("gosaUnitTag" => $main::gosa_unit_tag); } - my $res=$entry->update($ldap); + my $res=$entry->update($main::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 = $ldap->search( + $mesg = $main::ldap_handle->search( base => $ldap_base, scope => 'sub', filter => "(&(objectClass=GOhard)(|(macAddress=$macaddress)(dhcpHWaddress=ethernet $macaddress)))" @@ -221,7 +219,7 @@ sub detected_hardware { } } - my $res=$entry->update($ldap); + my $res=$entry->update($main::ldap_handle); if(defined($res->{'errorMessage'}) && length($res->{'errorMessage'}) >0) { &main::daemon_log("ERROR: can not add entries to LDAP: ".$res->{'errorMessage'}, 1); -- 2.30.2