From e644cdd28ed8992d041c260537e4ebafe696ef20 Mon Sep 17 00:00:00 2001 From: opensides Date: Tue, 18 May 2010 08:54:59 +0000 Subject: [PATCH] - Cleanup of code for new_ldap function in corefunctions.pm git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18526 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/client/events/corefunctions.pm | 163 ++++++++++++++----------- gosa-si/modules/ClientPackages.pm | 6 +- gosa-si/server/events/clMessages.pm | 2 +- 3 files changed, 96 insertions(+), 75 deletions(-) diff --git a/gosa-si/client/events/corefunctions.pm b/gosa-si/client/events/corefunctions.pm index c15700354..fadd579f4 100644 --- a/gosa-si/client/events/corefunctions.pm +++ b/gosa-si/client/events/corefunctions.pm @@ -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) { diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index 1f91d053b..ad94ee2f0 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -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". diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index 89ab1f785..dc57144ea 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -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 -- 2.30.2