[pve-devel] [PATCH RFC 03/21] setup_sshd_config: restructure code so that we can add more settings in future

Dietmar Maurer dietmar at proxmox.com
Mon Nov 28 08:08:55 CET 2016


Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 data/PVE/Cluster.pm | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index 00b4a0c..76e0e9f 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -1131,15 +1131,19 @@ sub setup_sshd_config {
     my ($start_sshd) = @_;
 
     my $conf = PVE::Tools::file_get_contents($sshd_config_fn);
-    
-    return if $conf =~ m/^PermitRootLogin\s+yes\s*$/m;
 
-    if ($conf !~ s/^#?PermitRootLogin.*$/PermitRootLogin yes/m) {
+    my $changes = 0;
+
+    if ($conf !~ m/^PermitRootLogin\s+yes\s*$/m) {
 	chomp $conf;
-	$conf .= "\nPermitRootLogin yes\n";
-    } 
+	$changes = 1;
+	if (!($conf =~ s/^#?PermitRootLogin.*$/PermitRootLogin yes/m)) {
+	    chomp $conf;
+	    $conf .= "\nPermitRootLogin yes\n";
+	}
+    }
 
-    PVE::Tools::file_set_contents($sshd_config_fn, $conf);
+    PVE::Tools::file_set_contents($sshd_config_fn, $conf) if $changes;
 
     my $cmd = $start_sshd ? 'reload-or-restart' : 'reload-or-try-restart';
     PVE::Tools::run_command(['systemctl', $cmd, 'sshd']);
-- 
2.1.4




More information about the pve-devel mailing list