Code

Added Mac formatting rule.
[gosa.git] / gosa-si / gosa-si-client
index b261e3d8c4ccd51f2eac29388a1bef2c75db35eb..efb794374354ee2b95792330008da34b7e2f61c3 100755 (executable)
@@ -41,7 +41,7 @@ use GOSA::GosaSupportDaemon;
 my ($cfg_file, %cfg_defaults, $foreground, $verbose, $pid_file, $procid, $pid, $log_file);
 my ($server_address, $server_ip, $server_port, $server_domain, $server_passwd, $server_cipher, $server_timeout);
 my ($client_address, $client_ip, $client_port, $client_mac_address, $ldap_config, $pam_config, $nss_config);
-my ($input_socket, $rbits, $wbits, $ebits, $xml, $known_hosts);
+my ($input_socket, $rbits, $wbits, $ebits, $xml, $known_hosts, $ldap_enabled);
 my (@events);
 
 # default variables
@@ -55,6 +55,7 @@ $foreground = 0 ;
     },
 "client" => 
     {"client_port" => [\$client_port, "20083"],
+     "ldap" => [\$ldap_enabled, 1],
      "ldap_config" => [\$ldap_config, "/etc/ldap/ldap.conf"],
      "pam_config" => [\$pam_config, "/etc/pam_ldap.conf"],
      "nss_config" => [\$nss_config, "/etc/libnss_ldap.conf"],
@@ -858,9 +859,7 @@ sub process_incoming_msg {
     close(DIR);
     daemon_log("could not assign the msg $header to an event", 5);
     
-
-
-    if ($header eq 'new_ldap_config') { &new_ldap_config($msg_hash)}
+    if ($header eq 'new_ldap_config') { if ($ldap_enabled == 1) {&new_ldap_config($msg_hash)}}
     elsif ($header eq 'ping') { &got_ping($msg_hash) }
     elsif ($header eq 'wake_up') { &execute_event($msg_hash)}
     elsif ($header eq 'new_passwd') { &new_passwd()}
@@ -935,6 +934,8 @@ sub new_ldap_config {
     my @ldap_options;
     my @pam_options;
     my @nss_options;
+    my $goto_admin;
+    my $goto_secret;
 
     # Transform input into array
     while ( my ($key, $value) = each(%$msg_hash) ) {
@@ -951,63 +952,81 @@ sub new_ldap_config {
                        $ldap_base= $element;
                        next;
                }
-               if ($key =~ /^ldap_/) {
-                       my $post =~ s/^ldap_//;
-                       push (@ldap_options, "$post $element");
+               if ($key =~ /^goto_admin$/) {
+                       $goto_admin= $element;
+                       next;
+               }
+               if ($key =~ /^goto_secret$/) {
+                       $goto_secret= $element;
                        next;
                }
-               if ($key =~ /^pam_/) {
-                       my $post =~ s/^pam_//;
-                       push (@pam_options, "$post $element");
+               if ($key =~ /^ldap_cfg$/) {
+                       push (@ldap_options, "$element");
                        next;
                }
-               if ($key =~ /^nss_/) {
-                       my $post =~ s/^nss_//;
-                       push (@nss_options, "$post $element");
+               if ($key =~ /^pam_cfg$/) {
+                       push (@pam_options, "$element");
+                       next;
+               }
+               if ($key =~ /^nss_cfg$/) {
+                       push (@nss_options, "$element");
                        next;
                }
        }
     }
 
     # Setup ldap.conf
-    my $file;
+    my $file1;
     my $file2;
-    open(file, "> $ldap_config");
-    print file "# This file was automatically generated by gosa-si-client. Do not change.\n";
-    print file "URI";
+    open(file1, "> $ldap_config");
+    print file1 "# This file was automatically generated by gosa-si-client. Do not change.\n";
+    print file1 "URI";
     foreach $element (@ldap_uris) {
-       print file " $element";
+       print file1 " $element";
     }
-    print file "\nBASE $ldap_base\n";
+    print file1 "\nBASE $ldap_base\n";
     foreach $element (@ldap_options) {
-       print file "$element";
+       print file1 "$element\n";
     }
-    close (file);
+    close (file1);
     daemon_log("wrote $ldap_config", 5);
 
     # Setup pam_ldap.conf / libnss_ldap.conf
-    open(file, "> $pam_config");
+    open(file1, "> $pam_config");
     open(file2, "> $nss_config");
-    print file "# This file was automatically generated by gosa-si-client. Do not change.\n";
+    print file1 "# This file was automatically generated by gosa-si-client. Do not change.\n";
     print file2 "# This file was automatically generated by gosa-si-client. Do not change.\n";
-    print file "uri";
+    print file1 "uri";
     print file2 "uri";
     foreach $element (@ldap_uris) {
-       print file " $element";
+       print file1 " $element";
        print file2 " $element";
     }
-    print file "\nbase $ldap_base\n";
+    print file1 "\nbase $ldap_base\n";
+    print file2 "\nbase $ldap_base\n";
     foreach $element (@pam_options) {
-       print file "$element";
+       print file1 "$element\n";
     }
     foreach $element (@nss_options) {
-       print file2 "$element";
+       print file2 "$element\n";
     }
     close (file2);
     daemon_log("wrote $nss_config", 5);
-    close (file);
+    close (file1);
     daemon_log("wrote $pam_config", 5);
 
+    # Create goto.secrets if told so
+    if (defined $goto_admin){
+           open(file1, "> /etc/goto/secret");
+           close(file1);
+           chown(0,0, "/etc/goto/secret");
+           chmod(0600, "/etc/goto/secret");
+           open(file1, "> /etc/goto/secret");
+           print file1 $goto_admin.":".$goto_secret."\n";
+           close(file1);
+           daemon_log("wrote /etc/goto/secret", 5);
+    }
+
     return;
 
 }