diff options
author | Christian Heimes <cheimes@redhat.com> | 2016-11-16 11:11:13 +0100 |
---|---|---|
committer | Martin Basti <mbasti@redhat.com> | 2016-11-16 23:37:46 +0100 |
commit | 9fbd29cc106660865bc6cda225d6a8a338a78d31 (patch) | |
tree | f7e9be977aa5514d1961fd1d924d550b675a66a2 | |
parent | 64af88fee4a482b3f393d38ff2c7f9494e689a7b (diff) | |
download | freeipa-9fbd29cc106660865bc6cda225d6a8a338a78d31.tar.gz freeipa-9fbd29cc106660865bc6cda225d6a8a338a78d31.tar.xz freeipa-9fbd29cc106660865bc6cda225d6a8a338a78d31.zip |
Use xml.etree in ipa-client-automount script
The ipa-client-automount script used lxml.etree to modify
/etc/autofs_ldap_auth.conf.
Signed-off-by: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Martin Basti <mbasti@redhat.com>
-rwxr-xr-x | client/ipa-client-automount | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/client/ipa-client-automount b/client/ipa-client-automount index fc619d0c1..b4aa7e81b 100755 --- a/client/ipa-client-automount +++ b/client/ipa-client-automount @@ -29,6 +29,11 @@ import time import tempfile import gssapi +try: + from xml.etree import cElementTree as etree +except ImportError: + from xml.etree import ElementTree as etree + import SSSDConfig # pylint: disable=import-error from six.moves.urllib.parse import urlsplit @@ -94,40 +99,34 @@ def wait_for_sssd(): print("This may mean that sssd didn't re-start properly after the configuration changes.") def configure_xml(fstore): - from lxml import etree - - fstore.backup_file(paths.AUTOFS_LDAP_AUTH_CONF) + authconf = paths.AUTOFS_LDAP_AUTH_CONF + fstore.backup_file(authconf) try: - f = open(paths.AUTOFS_LDAP_AUTH_CONF, 'r') - lines = f.read() - f.close() - - saslconf = etree.fromstring(lines) - element = saslconf.xpath('//autofs_ldap_sasl_conf') - root = saslconf.getroottree() + tree = etree.parse(authconf) except IOError as e: root_logger.debug('Unable to open file %s' % e) root_logger.debug('Creating new from template') - element = [etree.Element('autofs_ldap_sasl_conf')] - root = element[0].getroottree() + tree = etree.ElementTree( + element=etree.Element('autofs_ldap_sasl_conf') + ) - if len(element) != 1: - raise RuntimeError('Unable to parse %s' % paths.AUTOFS_LDAP_AUTH_CONF) + element = tree.getroot() + if element.tag != 'autofs_ldap_sasl_conf': + raise RuntimeError('Invalid XML root in file %s' % authconf) - element[0].set('usetls', 'no') - element[0].set('tlsrequired', 'no') - element[0].set('authrequired', 'yes') - element[0].set('authtype', 'GSSAPI') - element[0].set('clientprinc', 'host/%s@%s' % (api.env.host, api.env.realm)) + element.set('usetls', 'no') + element.set('tlsrequired', 'no') + element.set('authrequired', 'yes') + element.set('authtype', 'GSSAPI') + element.set('clientprinc', 'host/%s@%s' % (api.env.host, api.env.realm)) - newconf = open(paths.AUTOFS_LDAP_AUTH_CONF, 'w') try: - root.write(newconf, pretty_print=True, xml_declaration=True, encoding='UTF-8') - newconf.close() + tree.write(authconf, xml_declaration=True, encoding='UTF-8') except IOError as e: - print("Unable to write %s: %s" % (paths.AUTOFS_LDAP_AUTH_CONF, e)) - print("Configured %s" % paths.AUTOFS_LDAP_AUTH_CONF) + print("Unable to write %s: %s" % (authconf, e)) + else: + print("Configured %s" % authconf) def configure_nsswitch(fstore, options): """ |