Code

fixed bug: new clients get ldap information now
authorrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 7 Jan 2008 14:02:48 +0000 (14:02 +0000)
committerrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 7 Jan 2008 14:02:48 +0000 (14:02 +0000)
modified: ServerPackages: new_ldap_config
modified: GosaSupportDaemon: send_msg

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8236 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-si/gosa-si-server
gosa-si/modules/GosaSupportDaemon.pm
gosa-si/modules/ServerPackages.pm

index c60c5e2887cc82197ff00627dc2971fa924381b7..24295fba0798bae5eb3474e77a8012f9c7eff25a 100755 (executable)
@@ -93,7 +93,7 @@ our $job_queue_table_name = 'jobs';
 our $job_db;
 
 # holds all other gosa-sd as well as the gosa-sd-bus
-our $known_server;
+our $known_server_db;
 our $known_daemons = {};
 our $shmda = tie($known_daemons, 'IPC::Shareable', undef, {create => 1, 
                                                             exclusive => 1, 
@@ -101,7 +101,7 @@ our $shmda = tie($known_daemons, 'IPC::Shareable', undef, {create => 1,
                                                             destroy => 1,
                                                             });
 # holds all registrated clients
-our $known_clients;
+our $known_clients_db;
 #our $known_clients = {};
 #our $shmcl = tie($known_clients, 'IPC::Shareable', undef, {create => 1, 
 #                                                            exclusive => 1, 
@@ -1166,6 +1166,7 @@ while(1) {
     
     #my $res = $job_db->select_dbentry( { table=>$job_queue_table_name, status=>'waiting', timestamp=>'$timestamp'} );
     my $res = $job_db->select_dbentry( { table=>$job_queue_table_name, status=>'waiting', timestamp=>'2007010709014800'} );
+
     while( my ($id, $hit) = each %{$res} ) {         
 
         my $jobdb_id = $hit->{ROWID};
index 670bb8e27a391268d29804b9dfe97f78f6dacf90..46f3d09040902d77fc41a7c79e8b01f2839f6a31 100644 (file)
@@ -343,8 +343,8 @@ sub get_time {
 #                        package
 #      RETURNS:  nothing
 #===============================================================================
-sub send_msg ($$$$) {
-       my ($header, $from, $to, $data) = @_;
+sub send_msg ($$$$$) {
+       my ($header, $from, $to, $data, $hostkey) = @_;
 
        my $out_hash = &create_xml_hash($header, $from, $to);
 
@@ -356,7 +356,7 @@ sub send_msg ($$$$) {
                }
        }
 
-       &send_msg_hash2address($out_hash, $to);
+       &send_msg_hash2address($out_hash, $to, $hostkey);
 }
 
 1;
index e810ffb0e47aeda5026bcb918cf0b08a39adb095..7797dc404d0d23d05ded81969dc896aab4534448 100644 (file)
@@ -84,7 +84,7 @@ if($server_activ eq "on"){
 }
 
 # connect to known_clients_db
-my $known_clients_db = GOSA::DBsqlite->new($known_clients_file_name);
+#my $known_clients_db = GOSA::DBsqlite->new($known_clients_file_name);
 
 
 # register at bus
@@ -447,7 +447,7 @@ sub here_i_am {
     my $out_hash;
 
     # number of known clients
-    my $nu_clients = keys %{$known_clients_db->select_dbentry( {table=>'known_clients'} )};
+    my $nu_clients = keys %{$main::known_clients_db->select_dbentry( {table=>'known_clients'} )};
 
     # check wether client address or mac address is already known
     if (exists $main::known_clients->{$source}) {
@@ -477,7 +477,7 @@ sub here_i_am {
     my $events = @{$msg_hash->{events}}[0];
     
     # add entry to known_clients_db
-    my $res = $known_clients_db->add_dbentry( {table=>'known_clients', 
+    my $res = $main::known_clients_db->add_dbentry( {table=>'known_clients', 
                                                 primkey=>'hostname',
                                                 hostname=>$source,
                                                 events=>$events,
@@ -487,7 +487,7 @@ sub here_i_am {
                                                 timestamp=>&get_time,
                                                 } );
     if ($res == 3) {
-        $res = $known_clients_db->update_dbentry( {table=>'known_clients', 
+        $res = $main::known_clients_db->update_dbentry( {table=>'known_clients', 
                                                 where=>'hostname',
                                                 hostname=>$source,
                                                 events=>$events,
@@ -573,13 +573,19 @@ sub who_has_i_do {
 sub new_ldap_config {
     my ($address) = @_ ;
     
-    if (not exists $main::known_clients->{$address}) {
-        &main::daemon_log("ERROR: $address does not exist in known_clients, cannot send him his ldap config", 1);
-        return;
+    my $res = $main::known_clients_db->select_dbentry( { table=>'known_clients', hostname=>$address } );
+
+    # 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);
+        my $tmp = print Dumer $res;
     }
-    
-    my $mac_address = $main::known_clients->{$address}->{"mac_address"};
-    if (not defined $mac_address) {
+
+    my $macaddress = $res->{1}->{macaddress};
+    my $hostkey = $res->{1}->{hostkey};
+
+    if (not defined $macaddress) {
         &main::daemon_log("ERROR: no mac address found for client $address", 1);
         return;
     }
@@ -595,12 +601,12 @@ sub new_ldap_config {
     $mesg = $ldap->search( base   => $ldap_base,
                    scope  => 'sub',
                    attrs => ['dn', 'gotoLdapServer'],
-                   filter => "(&(objectClass=GOhard)(macaddress=$mac_address))");
+                   filter => "(&(objectClass=GOhard)(macaddress=$macaddress))");
     $mesg->code && die $mesg->error;
 
     # Sanity check
     if ($mesg->count != 1) {
-           &main::daemon_log("WARNING: client mac address $mac_address not found/not unique", 1);
+           &main::daemon_log("WARNING: client mac address $macaddress not found/not unique", 1);
            return;
     }
 
@@ -621,7 +627,7 @@ sub new_ldap_config {
 
             # Sanity check
            if ($mesg->count != 1) {
-                   &main::daemon_log("WARNING: no LDAP information found for client mac $mac_address", 1);
+                   &main::daemon_log("WARNING: no LDAP information found for client mac $macaddress", 1);
                    return;
            }
 
@@ -653,7 +659,7 @@ sub new_ldap_config {
     }
 
     # Send information
-    send_msg("new_ldap_config", $server_address, $address, \%data);
+    send_msg("new_ldap_config", $server_address, $address, \%data, $hostkey);
 
     return;
 }