]> git.proxmox.com Git - pve-cluster.git/commitdiff
preserve authorized_key key order
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 30 Aug 2012 05:05:57 +0000 (07:05 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 30 Aug 2012 05:27:51 +0000 (07:27 +0200)
And identify double keys by key and not by comment. Original patch from Stefan Priebe <s.priebe@profihost.ag> contains white space errors - I removed that.

data/PVE/Cluster.pm

index a877d41115358e9d9244fe6dbe40852a7cc66d08..cd9d192499c56013d563e792ee5aac2e808c4d7c 100644 (file)
@@ -1015,16 +1015,14 @@ sub ssh_merge_keys {
 
     my $newdata = "";
     my $vhash = {};
-    while ($data && $data =~ s/^((.*?)(\n|$))//) {
-       my $line = "$2\n";
-       if ($line =~ m/^ssh-rsa\s+\S+\s+(\S+)$/) {
-           $vhash->{$1} = $line;
-       } else {
-           $newdata .= $line;
+    my @lines = split(/\n/, $data);
+    foreach my $line (@lines) {
+       if ($line =~ m/^ssh-rsa\s+(\S+)\s+\S+$/) {
+            next if $vhash->{$1};
+            $vhash->{$1} = 1;
        }
+       $newdata .= "$line\n";
     }
-    
-    $newdata .= join("", values(%$vhash));
 
     PVE::Tools::file_set_contents($sshauthkeys, $newdata, 0600);
 }