Re: [Freeipa-devel] [PATCH] 302 Do not corrupt sshd_config in client install when trailing newline is missing

2014-06-26 Thread Martin Kosek
On 06/18/2014 03:56 PM, Jan Cholasta wrote:
 Hi,
 
 the attached patch fixes https://fedorahosted.org/freeipa/ticket/4373.
 
 Honza

Works fine, tested with
# perl -i -pe 'chomp if eof' /etc/ssh/sshd_config
trick.

ACK, pushed to master.

Martin

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


Re: [Freeipa-devel] [PATCH] 302 Do not corrupt sshd_config in client install when trailing newline is missing

2014-06-26 Thread Petr Viktorin

On 06/26/2014 12:18 PM, Martin Kosek wrote:

On 06/18/2014 03:56 PM, Jan Cholasta wrote:

Hi,

the attached patch fixes https://fedorahosted.org/freeipa/ticket/4373.

Honza


Works fine, tested with
# perl -i -pe 'chomp if eof' /etc/ssh/sshd_config
trick.

ACK, pushed to master.

Martin



It would be really nice to have some tests for this function.

--
PetrĀ³

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


Re: [Freeipa-devel] [PATCH] 302 Do not corrupt sshd_config in client install when trailing newline is missing

2014-06-26 Thread Jan Cholasta

On 26.6.2014 12:43, Petr Viktorin wrote:

On 06/26/2014 12:18 PM, Martin Kosek wrote:

On 06/18/2014 03:56 PM, Jan Cholasta wrote:

Hi,

the attached patch fixes https://fedorahosted.org/freeipa/ticket/4373.

Honza


Works fine, tested with
# perl -i -pe 'chomp if eof' /etc/ssh/sshd_config
trick.

ACK, pushed to master.

Martin



It would be really nice to have some tests for this function.



It would be even nicer to use Augeas to handle this.

--
Jan Cholasta

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


[Freeipa-devel] [PATCH] 302 Do not corrupt sshd_config in client install when trailing newline is missing

2014-06-18 Thread Jan Cholasta

Hi,

the attached patch fixes https://fedorahosted.org/freeipa/ticket/4373.

Honza

--
Jan Cholasta
From c933fa17a556ccc7ce142f81c6d6aaac15d0931d Mon Sep 17 00:00:00 2001
From: Jan Cholasta jchol...@redhat.com
Date: Wed, 18 Jun 2014 15:26:17 +0200
Subject: [PATCH] Do not corrupt sshd_config in client install when trailing
 newline is missing.

https://fedorahosted.org/freeipa/ticket/4373
---
 ipa-client/ipa-install/ipa-client-install | 42 +--
 1 file changed, 17 insertions(+), 25 deletions(-)

diff --git a/ipa-client/ipa-install/ipa-client-install b/ipa-client/ipa-install/ipa-client-install
index c20ad1a..307b593 100755
--- a/ipa-client/ipa-install/ipa-client-install
+++ b/ipa-client/ipa-install/ipa-client-install
@@ -1259,7 +1259,7 @@ def configure_sssd_conf(fstore, cli_realm, cli_domain, cli_server, options, clie
 return 0
 
 def change_ssh_config(filename, changes, sections):
-if len(changes) == 0:
+if not changes:
 return True
 
 try:
@@ -1268,38 +1268,30 @@ def change_ssh_config(filename, changes, sections):
 root_logger.error(Failed to open '%s': %s, filename, str(e))
 return False
 
+change_keys = tuple(key.lower() for key in changes)
+section_keys = tuple(key.lower() for key in sections)
+
 lines = []
-in_section = False
 for line in f:
-if in_section:
-lines.append(line)
-continue
+line = line.rstrip('\n')
 pline = line.strip()
-if len(pline) == 0 or pline.startswith('#'):
+if not pline or pline.startswith('#'):
 lines.append(line)
 continue
-parts = pline.split()
-option = parts[0].lower()
-for key in sections:
-if key.lower() == option:
-in_section = True
-break
-if in_section:
-break
-for opt in changes:
-if opt.lower() == option:
-line = None
-break
-if line is not None:
+option = pline.split()[0].lower()
+if option in section_keys:
 lines.append(line)
-for opt in changes:
-if changes[opt] is not None:
-lines.append('%s %s\n' % (opt, changes[opt]))
-lines.append('\n')
-if in_section:
+break
+if option in change_keys:
+line = '#' + line
 lines.append(line)
+for option, value in changes.items():
+if value is not None:
+lines.append('%s %s' % (option, value))
 for line in f:
+line = line.rstrip('\n')
 lines.append(line)
+lines.append('')
 
 f.close()
 
@@ -1309,7 +1301,7 @@ def change_ssh_config(filename, changes, sections):
 root_logger.error(Failed to open '%s': %s, filename, str(e))
 return False
 
-f.write(''.join(lines))
+f.write('\n'.join(lines))
 
 f.close()
 
-- 
1.9.0

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel