Code

fast bugfix: plainname = 'none', to be updated later
[gosa.git] / gosa-si / server / events / siTriggered.pm
index 798dcb1dec575cd29f6c5817f91a3a41d1bba158..2ae7a78bd3e2d54881f4e9ab86a7c6c51c22c5e5 100644 (file)
@@ -13,7 +13,6 @@ use strict;
 use warnings;
 use GOSA::GosaSupportDaemon;
 use Socket;
-use Net::hostent;
 
 
 BEGIN {}
@@ -48,7 +47,7 @@ sub read_configfile {
     my ($cfg_file, %cfg_defaults) = @_;
     my $cfg;
 
-    if( defined( $cfg_file) && ( length($cfg_file) > 0 )) {
+    if( defined( $cfg_file) && ( (-s $cfg_file) > 0 )) {
         if( -r $cfg_file ) {
             $cfg = Config::IniFiles->new( -file => $cfg_file );
         } else {
@@ -71,7 +70,7 @@ sub reload_ldap_config {
     my $header = @{$msg_hash->{header}}[0];
     my $target = @{$msg_hash->{$header}}[0];
 
-    my $out_msg = &SIPackages::new_ldap_config($target);
+    my $out_msg = &SIPackages::new_ldap_config($target, $session_id);
     my @out_msg_l = ( $out_msg );
     return @out_msg_l;
 }
@@ -130,7 +129,7 @@ sub detected_hardware {
        # check hit
        my $hit_counter = keys %{$res};
        if( not $hit_counter == 1 ) {
-               &main::daemon_log("ERROR: more or no hit found in known_clients_db by query by '$address'", 1);
+               &main::daemon_log("$session_id ERROR: more or no hit found in known_clients_db by query by '$address'", 1);
                return;
        }
 
@@ -138,18 +137,18 @@ sub detected_hardware {
        my $hostkey = $res->{1}->{hostkey};
 
        if (not defined $macaddress) {
-               &main::daemon_log("ERROR: no mac address found for client $address", 1);
+               &main::daemon_log("$session_id ERROR: no mac address found for client $address", 1);
                return;
        }
        # Build LDAP connection
-       &main::refresh_ldap_handle();
-       if( not defined $main::ldap_handle ) {
-               &main::daemon_log("ERROR: cannot connect to ldap: $ldap_uri", 1);
+    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(
+       $mesg = $ldap_handle->search(
                base   => $ldap_base,
                scope  => 'sub',
                filter => "(&(objectClass=GOhard)(|(macAddress=$macaddress)(dhcpHWaddress=ethernet $macaddress)))"
@@ -184,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)))"
@@ -228,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);
@@ -245,7 +244,7 @@ sub trigger_wake {
     my ($msg, $msg_hash, $session_id) = @_ ;
 
     foreach (@{$msg_hash->{macAddress}}){
-        &main::daemon_log("INFO: trigger wake for $_", 5);
+        &main::daemon_log("$session_id INFO: trigger wake for $_", 5);
         my $host    = $_;
         my $ipaddr  = '255.255.255.255';
         my $port    = getservbyname('discard', 'udp');
@@ -256,20 +255,9 @@ sub trigger_wake {
         # get the hardware address (ethernet address)
         $hwaddr_re = join(':', ('[0-9A-Fa-f]{1,2}') x 6);
         if ($host =~ m/^$hwaddr_re$/) {
-                $hwaddr = $host;
+          $hwaddr = $host;
         } else {
-                # $host is not a hardware address, try to resolve it
-                my $ip_re = join('\.', ('([0-9]|[1-9][0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))') x 4);
-                my $ip_addr;
-                if ($host =~ m/^$ip_re$/) {
-                        $ip_addr = $host;
-                } else {
-                        my $h;
-                        unless ($h = gethost($host)) {
-                                return undef;
-                        }
-                        $ip_addr = inet_ntoa($h->addr);
-                }
+          &main::daemon_log("$session_id ERROR: trigger_wake called with non mac address", 1);
         }
 
         # Generate magic sequence
@@ -280,7 +268,7 @@ sub trigger_wake {
 
         # Allocate socket and send packet
 
-        $raddr = gethostbyname($ipaddr)->addr;
+        $raddr = gethostbyname($ipaddr);
         $them = pack_sockaddr_in($port, $raddr);
         $proto = getprotobyname('udp');