Code

Added Mac formatting rule.
[gosa.git] / gosa-si / gosa-si-client
index 141aa3e1d80b3262db6ebd05e912a4db76c92cea..efb794374354ee2b95792330008da34b7e2f61c3 100755 (executable)
@@ -3,7 +3,7 @@
 #
 #         FILE:  gosa-server
 #
-#        USAGE:  ./gosasc
+#        USAGE:  gosa-si-client
 #
 #  DESCRIPTION:
 #
@@ -40,12 +40,12 @@ 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);
-my ($input_socket, $rbits, $wbits, $ebits, $xml, $known_hosts);
+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, $ldap_enabled);
 my (@events);
 
 # default variables
-my $event_dir = "/etc/gosac/events";
+my $event_dir = "/etc/gosa-si/client/events";
 $known_hosts = {};
 $foreground = 0 ;
 %cfg_defaults =
@@ -55,6 +55,10 @@ $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"],
     },
 "server" =>
     {"server_ip" => [\$server_ip, ""],
@@ -306,7 +310,7 @@ sub register_at_server {
 
     # detect all client accepted events
     opendir(DIR, $event_dir) 
-        or daemon_log("cannot find directory $event_dir!\ngosac starts without any accepting events!", 1);
+        or daemon_log("cannot find directory $event_dir!\ngosa-si-client starts without any accepting events!", 1);
     my $file_name;
     @events = ();
     while(defined($file_name = readdir(DIR))){
@@ -855,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()}
@@ -926,10 +928,104 @@ sub got_ping {
 
 sub new_ldap_config {
     my ($msg_hash) = @_ ;
+    my $element;
+    my @ldap_uris;
+    my $ldap_base;
+    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) ) {
+       if ($key =~ /^(source|target|header)$/) {
+               next;
+       }
+
+       foreach $element (@$value) {
+               if ($key =~ /^ldap_uri$/) {
+                       push (@ldap_uris, $element);
+                       next;
+               }
+               if ($key =~ /^ldap_base$/) {
+                       $ldap_base= $element;
+                       next;
+               }
+               if ($key =~ /^goto_admin$/) {
+                       $goto_admin= $element;
+                       next;
+               }
+               if ($key =~ /^goto_secret$/) {
+                       $goto_secret= $element;
+                       next;
+               }
+               if ($key =~ /^ldap_cfg$/) {
+                       push (@ldap_options, "$element");
+                       next;
+               }
+               if ($key =~ /^pam_cfg$/) {
+                       push (@pam_options, "$element");
+                       next;
+               }
+               if ($key =~ /^nss_cfg$/) {
+                       push (@nss_options, "$element");
+                       next;
+               }
+       }
+    }
 
-    my @gotoLdapServer = &get_content_from_xml_hash($msg_hash, "new_ldap_config");
-    print Dumper @gotoLdapServer;
-
+    # Setup ldap.conf
+    my $file1;
+    my $file2;
+    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 file1 " $element";
+    }
+    print file1 "\nBASE $ldap_base\n";
+    foreach $element (@ldap_options) {
+       print file1 "$element\n";
+    }
+    close (file1);
+    daemon_log("wrote $ldap_config", 5);
+
+    # Setup pam_ldap.conf / libnss_ldap.conf
+    open(file1, "> $pam_config");
+    open(file2, "> $nss_config");
+    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 file1 "uri";
+    print file2 "uri";
+    foreach $element (@ldap_uris) {
+       print file1 " $element";
+       print file2 " $element";
+    }
+    print file1 "\nbase $ldap_base\n";
+    print file2 "\nbase $ldap_base\n";
+    foreach $element (@pam_options) {
+       print file1 "$element\n";
+    }
+    foreach $element (@nss_options) {
+       print file2 "$element\n";
+    }
+    close (file2);
+    daemon_log("wrote $nss_config", 5);
+    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;
 
@@ -938,7 +1034,7 @@ sub new_ldap_config {
 
 sub execute_event {
     my ($msg_hash)= @_;
-    my $configdir= '/etc/gosac/events/';
+    my $configdir= '/etc/gosa-si/client/events/';
     my $result;
 
     my $header = &get_content_from_xml_hash($msg_hash, 'header');
@@ -949,7 +1045,7 @@ sub execute_event {
     if((not defined $source)
             && (not defined $target)
             && (not defined $header)) {
-        daemon_log("ERROR: Entries missing in XML msg for gosa events under /etc/gosac/events");
+        daemon_log("ERROR: Entries missing in XML msg for gosa events under $configdir");
     } else {
         my $parameters="";
         my @params = &get_content_from_xml_hash($msg_hash, $header);