Code

- Cleanup of code for new_ldap function in corefunctions.pm
authoropensides <opensides@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 18 May 2010 08:54:59 +0000 (08:54 +0000)
committeropensides <opensides@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 18 May 2010 08:54:59 +0000 (08:54 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18526 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-si/client/events/corefunctions.pm
gosa-si/modules/ClientPackages.pm
gosa-si/server/events/clMessages.pm

index c157003549480987b00d09e6a4c266696551eb3f..fadd579f4f67813fc2141739a1f6aadb289378b6 100644 (file)
@@ -189,9 +189,9 @@ sub new_syslog_config {
        }
        
        # Substitute existing server with new syslog server
-       open (my $FILE, "<","$syslog_file");
-       my @file = <$FILE>;
-       close($FILE);
+       open (my $syslog, "<","$syslog_file");
+       my @file = <$syslog>;
+       close($syslog);
        my $syslog_server_line = "*.*\t@".$syslog_server."\n"; 
        foreach my $line (@file) {
                if ($line =~ /^\*\.\*\s+@/) {
@@ -207,9 +207,9 @@ sub new_syslog_config {
        }
        
        # Write changes to file and close it
-       open (my $FILE, "+>","$syslog_file");
-       print $FILE join("", @file); 
-       close($FILE);
+       open (my $new_syslog, "+>","$syslog_file");
+       print $new_syslog join("", @file);
+       close($new_syslog);
        &main::daemon_log("INFO: Wrote new configuration file: $syslog_file", 5);
 
        # Restart syslog deamon
@@ -246,9 +246,9 @@ sub new_ntp_config {
        }
 
        # Substitute existing server with new ntp server
-       open (my $FILE, "<","$chrony_file");
-       my @file = <$FILE>;
-       close($FILE);
+       open (my $ntp, "<","$chrony_file");
+       my @file = <$ntp>;
+       close($ntp);
        my @new_file;
        foreach my $line (@file) {
                if ($line =~ /^server\s+/) {
@@ -269,9 +269,9 @@ sub new_ntp_config {
        }
 
        # Write changes to file and close it
-       open (my $FILE, ">","$chrony_file");
-       print $FILE join("", @new_file); 
-       close($FILE);
+       open (my $new_ntp, ">","$chrony_file");
+       print $new_ntp join("", @new_file);
+       close($new_ntp);
        &main::daemon_log("INFO: Wrote new configuration file: $chrony_file", 5);
 
        # Restart chrony deamon
@@ -301,7 +301,18 @@ sub new_ldap_config {
        my $department= "";
        my $release= "";
        my $unit_tag;
-
+       my $ldap_file;
+       my $pam_file;
+       my $nss_file;
+       my $goto_file;
+       my $goto_secret_file;
+       my $ldap_offline_file;
+       my $ldap_shell_file;
+       
+       my $ldap_shell_config = "/etc/ldap/ldap-shell.conf";
+       my $ldap_offline_config = "/etc/ldap/ldap-offline.conf";
+       my $goto_secret_config = "/etc/goto/secret";
+       
        # Transform input into array
        while ( my ($key, $value) = each(%$msg_hash) ) {
                if ($key =~ /^(source|target|header)$/) {
@@ -364,97 +375,107 @@ sub new_ldap_config {
        }
 
        # Setup ldap.conf
-       my $file1;
-       my $file2;
-       open(my $file1, ">","$ldap_config");
-       print $file1 "# This file was automatically generated by gosa-si-client. Do not change.\n";
-       print $file1 "URI";
+       open($ldap_file, ">","$ldap_config");
+       print $ldap_file "# This file was automatically generated by gosa-si-client. Do not change.\n";
+       print $ldap_file "URI";
+       
        foreach $element (@ldap_uris) {
-               print $file1 " $element";
+               print $ldap_file " $element";
        }
-       print $file1 "\nBASE $ldap_base\n";
+       
+       print $ldap_file "\nBASE $ldap_base\n";
        foreach $element (@ldap_options) {
-               print $file1 "$element\n";
+               print $ldap_file "$element\n";
        }
-       close ($file1);
+       
+       close ($ldap_file);
        daemon_log("INFO: Wrote $ldap_config", 5);
 
        # Setup pam_ldap.conf / libnss-ldap.conf
-       open(my $file1, ">","$pam_config");
-       open(my $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";
+       open($pam_file, ">","$pam_config");
+       open($nss_file, ">","$nss_config");
+       print $pam_file "# This file was automatically generated by gosa-si-client. Do not change.\n";
+       print $nss_file "# This file was automatically generated by gosa-si-client. Do not change.\n";
+       print $pam_file "uri";
+       print $nss_file "uri";
+       
        foreach $element (@ldap_uris) {
-               print $file1 " $element";
-               print $file2 " $element";
+               print $pam_file " $element";
+               print $nss_file " $element";
        }
-       print $file1 "\nbase $ldap_base\n";
-       print $file2 "\nbase $ldap_base\n";
+       
+       print $pam_file "\nbase $ldap_base\n";
+       print $nss_file "\nbase $ldap_base\n";
+       
        foreach $element (@pam_options) {
-               print $file1 "$element\n";
+               print $pam_file "$element\n";
        }
+       
        foreach $element (@nss_options) {
-               print $file2 "$element\n";
+               print $nss_file "$element\n";
        }
-       close ($file2);
+       
+       close ($nss_file);
        daemon_log("INFO: Wrote $nss_config", 5);
-       close ($file1);
+       close ($pam_file);
        daemon_log("INFO: Wrote $pam_config", 5);
 
        # Create goto.secrets if told so - for compatibility reasons
        if (defined $goto_admin){
-               open(my $file1, ">","/etc/goto/secret");
-                       close($file1);
-                       chown(0,0, "/etc/goto/secret");
-                       chmod(0600, "/etc/goto/secret");
-               open(my $file1, ">","/etc/goto/secret");
-                       print $file1 "GOTOADMIN=\"$goto_admin\"\nGOTOSECRET=\"$goto_secret\"\n";
-                       close($file1);
-                       daemon_log("INFO: Wrote /etc/goto/secret", 5);
+               open($goto_file, ">",$goto_secret_config);
+               print $goto_file "GOTOADMIN=\"$goto_admin\"\nGOTOSECRET=\"$goto_secret\"\n";
+               close($goto_file);
+               chown(0,0, $goto_file);
+               chmod(0600, $goto_file);
+               daemon_log("INFO: Wrote $goto_secret_config", 5);
        }
 
        # Write shell based config
-       my $cfg_name= "/etc/ldap/ldap-shell.conf";
 
     # Get first LDAP server
     my $ldap_server= $ldap_uris[0];
     $ldap_server=~ s/^ldap:\/\/([^:]+).*$/$1/;
 
-    open(my $file1, ">","$cfg_name");
-    print $file1 "LDAP_BASE=\"$ldap_base\"\n";
-    print $file1 "LDAP_SERVER=\"$ldap_server\"\n";
-    print $file1 "LDAP_URIS=\"@ldap_uris\"\n";
-    print $file1 "ADMIN_BASE=\"$admin_base\"\n";
-    print $file1 "DEPARTMENT=\"$department\"\n";
-    print $file1 "RELEASE=\"$release\"\n";
-    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("INFO: Wrote $cfg_name", 5);
+    open($ldap_shell_file, ">","$ldap_shell_config");
+    print $ldap_shell_file "LDAP_BASE=\"$ldap_base\"\n";
+    print $ldap_shell_file "LDAP_SERVER=\"$ldap_server\"\n";
+    print $ldap_shell_file "LDAP_URIS=\"@ldap_uris\"\n";
+    print $ldap_shell_file "ADMIN_BASE=\"$admin_base\"\n";
+    print $ldap_shell_file "DEPARTMENT=\"$department\"\n";
+    print $ldap_shell_file "RELEASE=\"$release\"\n";
+    print $ldap_shell_file "UNIT_TAG=\"".(defined $unit_tag ? "$unit_tag" : "")."\"\n";
+    print $ldap_shell_file "UNIT_TAG_FILTER=\"".(defined $unit_tag ? "(gosaUnitTag=$unit_tag)" : "")."\"\n";
+    close($ldap_shell_file);
+
+               # Set permissions and ownership structure of
+               chown(0, 0, $ldap_shell_file);
+               chmod(0644, $ldap_shell_file);
+                       
+    daemon_log("INFO: Wrote $ldap_shell_config", 5);
 
     # Write offline config
     if ($offline_enabled){
-           $cfg_name= "/etc/ldap/ldap-offline.conf";
 
            # Get first LDAP server
-           open(my $file1, ">","$cfg_name");
-           print $file1 "LDAP_BASE=\"$ldap_base\"\n";
-           print $file1 "LDAP_SERVER=\"127.0.0.1\"\n";
-           print $file1 "LDAP_URIS=\"ldap://127.0.0.1\"\n";
-           print $file1 "ADMIN_BASE=\"$admin_base\"\n";
-           print $file1 "DEPARTMENT=\"$department\"\n";
-           print $file1 "RELEASE=\"$release\"\n";
-           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("INFO: Wrote $cfg_name", 5);
+           open( $ldap_offline_file, ">","$ldap_offline_config");
+           print $ldap_offline_file "LDAP_BASE=\"$ldap_base\"\n";
+           print $ldap_offline_file "LDAP_SERVER=\"127.0.0.1\"\n";
+           print $ldap_offline_file "LDAP_URIS=\"ldap://127.0.0.1\"\n";
+           print $ldap_offline_file "ADMIN_BASE=\"$admin_base\"\n";
+           print $ldap_offline_file "DEPARTMENT=\"$department\"\n";
+           print $ldap_offline_file "RELEASE=\"$release\"\n";
+           print $ldap_offline_file "UNIT_TAG=\"".(defined $unit_tag ? "$unit_tag" : "")."\"\n";
+           print $ldap_offline_file "UNIT_TAG_FILTER=\"".(defined $unit_tag ? "(gosaUnitTag=$unit_tag)" : "")."\"\n";
+           close($ldap_offline_file);
+
+                       # Set permissions and ownership structure of
+                       chown(0, 0, $ldap_offline_file);
+                       chmod(0644, $ldap_offline_file);
+                       
+           daemon_log("INFO: Wrote $ldap_offline_config", 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) {
index 1f91d053bc5c94cf2e29cfdcc97dd226ff8dd3f0..ad94ee2f0e3d45918a1dd7a4b844efde95bc0adf 100644 (file)
@@ -566,7 +566,7 @@ sub here_i_am {
     if($ldap_res->code) {
             &main::daemon_log("$session_id ERROR: LDAP Entry for client with mac address $mac_address not found: ".$ldap_res->error, 1);
     } elsif ($ldap_res->count != 1) {
-            &main::daemon_log("$session_id ERROR: client with mac address $mac_address not found/unique/active - not updating ldap entry".
+            &main::daemon_log("$session_id WARNING: client with mac address $mac_address not found/unique/active - not updating ldap entry".
                             "\n\tbase: $ldap_base".
                             "\n\tscope: sub".
                             "\n\tattrs: ipHostNumber".
@@ -666,7 +666,7 @@ sub new_syslog_config {
 
        # Sanity check
        if ($ldap_res->count != 1) {
-               &main::daemon_log("$session_id ERROR: client with mac address $mac_address not found/unique/active - not sending syslog config".
+               &main::daemon_log("$session_id WARNING: client with mac address $mac_address not found/unique/active - not sending syslog config".
                 "\n\tbase: $ldap_base".
                 "\n\tscope: sub".
                 "\n\tattrs: gotoSyslogServer".
@@ -882,7 +882,7 @@ sub new_ldap_config {
 
                # Sanity check
         if ($mesg->count != 1) {
-            &main::daemon_log("$session_id ERROR: new_ldap_config: client with mac address $macaddress not found/unique/active - not sending ldap config".
+            &main::daemon_log("$session_id WARNING: new_ldap_config: client with mac address $macaddress not found/unique/active - not sending ldap config".
                     "\n\tbase: $ldap_base".
                     "\n\tscope: sub".
                     "\n\tattrs: dn, gotoLdapServer, FAIclass".
index 89ab1f78581cd9f20443b01a8173aefde1b78bdc..dc57144ea224d54567b16b71df731c1bb30bf5d5 100644 (file)
@@ -337,7 +337,7 @@ sub set_last_system {
                                                );
                # Sanity check of user search
                if ($ldap_mesg->count == 0) {
-                       &main::daemon_log("$session_id ERROR: no user with uid='$user' was found in base '".
+                       &main::daemon_log("$session_id WARNING: no user with uid='$user' was found in base '".
                                                        $main::ldap_base."', setting of 'gotoLastSystem' and 'gotoLastSystemLogin' stopped!", 1);
 
                # Set gotoLastSystem and gotoLastSystemLogin