Code

Add option to execute custom scripts after LDAP config file generation (#4125).
[gosa.git] / trunk / gosa-si / client / events / corefunctions.pm
index 7e19a8b18dcdbd1f0e37d3e2f8dd2b0e94cddc56..e640c87a756f2d82e082519470f167ea95c4e7b0 100644 (file)
@@ -23,7 +23,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";
@@ -36,6 +36,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],
     },
 );
 
@@ -117,8 +118,8 @@ sub registered {
     my $hostname= $main::client_dnsname;
     $hostname =~ s/\..*$//;
     $hostname =~ tr/A-Z/a-z/;
-    open($opts_file_FH, ">$main::opts_file");
-    print $opts_file_FH "MAC=\"$main::client_mac_address\"\n";
+       sysopen($opts_file_FH, $main::opts_file, O_RDWR | O_CREAT | O_TRUNC , 0644);
+       print $opts_file_FH "MAC=\"$main::client_mac_address\"\n";
     print $opts_file_FH "IPADDRESS=\"$main::client_ip\"\n";
     print $opts_file_FH "HOSTNAME=\"$hostname\"\n";
     print $opts_file_FH "FQDN=\"$main::client_dnsname\"\n";
@@ -444,6 +445,16 @@ sub new_ldap_config {
            daemon_log("wrote $cfg_name", 5);
     }
 
+    # Set permissions and ownership structure
+    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;
 }