Code

- Added patch from LHM commit r15601 Closes: #849
[gosa.git] / gosa-si / client / events / corefunctions.pm
index 04cb8a8bfe32549c5167e28d2c311842dc149029..f1a8935cc128c6c4bc9ef4bda18c42e159e2b905 100644 (file)
@@ -22,7 +22,7 @@ use Fcntl;
 use GOSA::GosaSupportDaemon;
 use File::Basename;
 
-my ($ldap_enabled, $offline_enabled, $ldap_config, $pam_config, $nss_config, $fai_logpath);
+my ($ldap_enabled, $offline_enabled, $ldap_config, $pam_config, $nss_config, $fai_logpath, $ldap_config_exit_hook);
 
 my $chrony_file = "/etc/chrony/chrony.conf";
 my $syslog_file = "/etc/syslog.conf";
@@ -35,6 +35,7 @@ my %cfg_defaults = (
                "pam-config" => [\$pam_config, "/etc/pam_ldap.conf"],
                "nss-config" => [\$nss_config, "/etc/libnss-ldap.conf"],
                "fai-logpath" => [\$fai_logpath, "/var/log/fai/fai.log"],
+               "ldap-config-exit-hook" => [\$ldap_config_exit_hook, undef],
        },
 );
 
@@ -106,10 +107,11 @@ sub registered {
        $main::client_address = $target;
 
        # set registration_flag to true 
-       my $out_hash = &create_xml_hash("registered", $main::client_address, $main::server_address);
-        # Write the MAC address to file
+       &main::_setREGISTERED(1);
+
+       # Write the MAC address to file
        if(stat($main::opts_file)) { 
-                       unlink($main::opts_file);
+               unlink($main::opts_file);
        }
 
        my $opts_file_FH;
@@ -132,8 +134,7 @@ sub registered {
        }
        close($opts_file_FH);
         
-       my $out_msg = &create_xml_string($out_hash);
-       return $out_msg;
+       return;
 }
 
 sub server_leaving {
@@ -201,7 +202,7 @@ sub new_syslog_config {
        open (FILE, "+>$syslog_file");
        print FILE join("", @file); 
        close FILE;
-       &main::daemon_log("INFO: wrote new configuration file: $syslog_file", 5);
+       &main::daemon_log("INFO: Wrote new configuration file: $syslog_file", 5);
 
        # Restart syslog deamon
        my $res = qx(/etc/init.d/sysklogd restart);
@@ -263,7 +264,7 @@ sub new_ntp_config {
        open (FILE, ">$chrony_file");
        print FILE join("", @new_file); 
        close FILE;
-       &main::daemon_log("INFO: wrote new configuration file: $chrony_file", 5);
+       &main::daemon_log("INFO: Wrote new configuration file: $chrony_file", 5);
 
        # Restart chrony deamon
        my $res = qx(/etc/init.d/chrony force-reload);
@@ -368,7 +369,7 @@ sub new_ldap_config {
                print file1 "$element\n";
        }
        close (file1);
-       daemon_log("wrote $ldap_config", 5);
+       daemon_log("INFO: Wrote $ldap_config", 5);
 
        # Setup pam_ldap.conf / libnss-ldap.conf
        open(file1, "> $pam_config");
@@ -390,9 +391,9 @@ sub new_ldap_config {
                print file2 "$element\n";
        }
        close (file2);
-       daemon_log("wrote $nss_config", 5);
+       daemon_log("INFO: Wrote $nss_config", 5);
        close (file1);
-       daemon_log("wrote $pam_config", 5);
+       daemon_log("INFO: Wrote $pam_config", 5);
 
        # Create goto.secrets if told so - for compatibility reasons
        if (defined $goto_admin){
@@ -403,7 +404,7 @@ sub new_ldap_config {
                open(file1, "> /etc/goto/secret");
                        print file1 "GOTOADMIN=\"$goto_admin\"\nGOTOSECRET=\"$goto_secret\"\n";
                        close(file1);
-                       daemon_log("wrote /etc/goto/secret", 5);
+                       daemon_log("INFO: Wrote /etc/goto/secret", 5);
        }
 
        # Write shell based config
@@ -423,7 +424,7 @@ sub new_ldap_config {
     print file1 "UNIT_TAG=\"".(defined $unit_tag ? "$unit_tag" : "")."\"\n";
     print file1 "UNIT_TAG_FILTER=\"".(defined $unit_tag ? "(gosaUnitTag=$unit_tag)" : "")."\"\n";
     close(file1);
-    daemon_log("wrote $cfg_name", 5);
+    daemon_log("INFO: Wrote $cfg_name", 5);
 
     # Write offline config
     if ($offline_enabled){
@@ -440,36 +441,45 @@ sub new_ldap_config {
            print file1 "UNIT_TAG=\"".(defined $unit_tag ? "$unit_tag" : "")."\"\n";
            print file1 "UNIT_TAG_FILTER=\"".(defined $unit_tag ? "(gosaUnitTag=$unit_tag)" : "")."\"\n";
            close(file1);
-           daemon_log("wrote $cfg_name", 5);
+           daemon_log("INFO: Wrote $cfg_name", 5);
     }
 
        # Set permissions and ownership structure of 
        chown(0, 0, $cfg_name);
        chmod(0644, $cfg_name);
 
+    # Allow custom scripts to be executed
+    if (defined $ldap_config_exit_hook) {
+        system($ldap_config_exit_hook);
+        daemon_log("executed hook $ldap_config_exit_hook", 5);
+    }
+
     return;
 }
 
 
 sub new_key {
-    # my ($msg_hash) = @_ ;
+       # Create new key
     my $new_server_key = &main::create_passwd();
 
-    my $out_hash = &create_xml_hash("new_key", $main::client_address, $main::server_address, $new_server_key);    
-    my $out_msg = &create_xml_string($out_hash);
+       # Send new_key message to server
+    my $errSend = &main::send_msg_hash_to_target(
+               &main::create_xml_hash("new_key", $main::client_address, $main::server_address, $new_server_key),
+               $main::server_address, 
+               $main::server_key,
+       );
 
-    # set global $NEW_KEY_FLAG, gosa-si-client cause a reregistering process if no 'confirm_new_key'-msg 
-    # comes from gosa-si-server within a given time
-    
+       # Set global key
+       if (not $errSend) {
+               $main::server_key = $new_server_key;
+       }
 
-    return $out_msg
+    return; 
 }
 
 
 sub confirm_new_key {
     my ($msg, $msg_hash) = @_ ;
-    my $header = @{$msg_hash->{'header'}}[0];
-    my $target = @{$msg_hash->{'target'}}[0];
     my $source = @{$msg_hash->{'source'}}[0];
 
     &main::daemon_log("confirm new key from $source", 5);