diff options
author | Jan Cholasta <jcholast@redhat.com> | 2014-06-18 15:26:17 +0200 |
---|---|---|
committer | Martin Kosek <mkosek@redhat.com> | 2014-06-26 12:00:29 +0200 |
commit | 3e0245f28fe3f294f21b8d0cc298b1901119921d (patch) | |
tree | 99c11729eb6f7c0ba3b025903e13e8b1830a1557 /ipa-client/ipa-install | |
parent | 6b92fb2a963defeefee572374ca136a7f630c8c6 (diff) | |
download | freeipa-3e0245f28fe3f294f21b8d0cc298b1901119921d.tar.gz freeipa-3e0245f28fe3f294f21b8d0cc298b1901119921d.tar.xz freeipa-3e0245f28fe3f294f21b8d0cc298b1901119921d.zip |
Do not corrupt sshd_config in client install when trailing newline is missing.
https://fedorahosted.org/freeipa/ticket/4373
Reviewed-By: Martin Kosek <mkosek@redhat.com>
Diffstat (limited to 'ipa-client/ipa-install')
-rwxr-xr-x | ipa-client/ipa-install/ipa-client-install | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/ipa-client/ipa-install/ipa-client-install b/ipa-client/ipa-install/ipa-client-install index 4e2519bce..73c564818 100755 --- a/ipa-client/ipa-install/ipa-client-install +++ b/ipa-client/ipa-install/ipa-client-install @@ -1257,7 +1257,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: @@ -1266,38 +1266,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() @@ -1307,7 +1299,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() |