Code

wrong if-clause
[gosa.git] / gosa-si / server / events / siTriggered.pm
index 53ae3d58fc916564ea2bf1fb035105d9ed7f644d..544e2e6ab9c96ab9ac2c0b604781c585976c65fa 100644 (file)
@@ -47,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 {
@@ -70,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, $session_id);
+    my $out_msg = &ClientPackages::new_ldap_config($target, $session_id);
     my @out_msg_l = ( $out_msg );
     return @out_msg_l;
 }
@@ -129,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;
        }
 
@@ -137,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)))"
@@ -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)))"
@@ -208,7 +208,7 @@ sub detected_hardware {
                        if(defined($msg_hash->{detected_hardware}[0]->{$attribute}) &&
                                length($msg_hash->{detected_hardware}[0]->{$attribute}) >0 ) {
                                if(defined($entry->get_value($attribute))) {
-                                       $entry->delete($attribute);
+                                       $entry->delete($attribute => []);
                                }
                                &main::daemon_log("INFO: Adding attribute $attribute with value ".$msg_hash->{detected_hardware}[0]->{$attribute},5);
                                $entry->add($attribute => $msg_hash->{detected_hardware}[0]->{$attribute});     
@@ -219,15 +219,15 @@ sub detected_hardware {
                        if(defined($msg_hash->{detected_hardware}[0]->{$attribute}) &&
                                length($msg_hash->{detected_hardware}[0]->{$attribute}) >0 ) {
                                if(defined($entry->get_value($attribute))) {
-                                       $entry->delete($attribute);
+                                       $entry->delete($attribute => []);
                                }
-                               foreach my $array_entry (@{$msg_hash->{detected_hardware}[0]->{$attribute}}) {
+                               foreach my $array_entry (keys %{{map { $_ => 1 } sort(@{$msg_hash->{detected_hardware}[0]->{$attribute}}) }}) {
                                        $entry->add($attribute => $array_entry);
                                }
                        }
                }
 
-               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);