adtrustinstance: write the conf as a string

Since ipautil.template_file() returns a string, we should not try
to write it as bytes.

https://pagure.io/freeipa/issue/4985

Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
Stanislav Laznicka 2017-06-07 08:18:32 +02:00 committed by Martin Basti
parent a83b2583ab
commit 8311069d18

View File

@ -509,23 +509,17 @@ class ADTRUSTInstance(service.Service):
self.print_msg(UPGRADE_ERROR % dict(dn=targets_dn)) self.print_msg(UPGRADE_ERROR % dict(dn=targets_dn))
def __write_smb_registry(self): def __write_smb_registry(self):
template = os.path.join(paths.USR_SHARE_IPA_DIR, "smb.conf.template")
conf = ipautil.template_file(template, self.sub_dict)
[tmp_fd, tmp_name] = tempfile.mkstemp()
os.write(tmp_fd, conf)
os.close(tmp_fd)
# Workaround for: https://fedorahosted.org/freeipa/ticket/5687 # Workaround for: https://fedorahosted.org/freeipa/ticket/5687
# We make sure that paths.SMB_CONF file exists, hence touch it # We make sure that paths.SMB_CONF file exists, hence touch it
with open(paths.SMB_CONF, 'a'): with open(paths.SMB_CONF, 'a'):
os.utime(paths.SMB_CONF, None) os.utime(paths.SMB_CONF, None)
args = [paths.NET, "conf", "import", tmp_name] template = os.path.join(paths.USR_SHARE_IPA_DIR, "smb.conf.template")
conf = ipautil.template_file(template, self.sub_dict)
try: with tempfile.NamedTemporaryFile(mode='w') as tmp_conf:
ipautil.run(args) tmp_conf.write(conf)
finally: tmp_conf.flush()
os.remove(tmp_name) ipautil.run([paths.NET, "conf", "import", tmp_conf.name])
def __setup_group_membership(self): def __setup_group_membership(self):
# Add the CIFS and host principals to the 'adtrust agents' group # Add the CIFS and host principals to the 'adtrust agents' group