From 6a54146bc0902e768a659e68394e454ba3993a0b Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Feb 07 2018 16:27:11 +0000 Subject: Decode ODS commands ODS commands are ASCII strings, but socket.recv() returns bytes and socket.send() expects bytes. Encode/decode values properly. Signed-off-by: Christian Heimes Reviewed-By: Stanislav Laznicka --- diff --git a/daemons/dnssec/ipa-ods-exporter b/daemons/dnssec/ipa-ods-exporter index 748bce4..d00dab9 100755 --- a/daemons/dnssec/ipa-ods-exporter +++ b/daemons/dnssec/ipa-ods-exporter @@ -17,19 +17,21 @@ Purpose of this replacement is to upload keys generated by OpenDNSSEC to LDAP. from __future__ import print_function from datetime import datetime -import dateutil.tz -import dns.dnssec -from gssapi.exceptions import GSSError import logging import os import socket import select import sys -import systemd.daemon -import systemd.journal import sqlite3 import traceback +import dateutil.tz +import dns.dnssec +from gssapi.exceptions import GSSError +import six +import systemd.daemon +import systemd.journal + import ipalib from ipalib.constants import SOFTHSM_DNSSEC_TOKEN_LABEL from ipalib.install.kinit import kinit_keytab @@ -470,8 +472,11 @@ def receive_systemd_command(): # this implements cmdhandler_handle_cmd() logic cmd = conn.recv(ODS_SE_MAXLINE).strip() + # ODS uses an ASCII protocol + if not isinstance(cmd, six.text_type): + cmd = cmd.decode('ascii') logger.debug('received command "%s" from systemd socket', cmd) - return (cmd, conn) + return cmd, conn def parse_command(cmd): """Parse command to (exit code, message, zone_name) tuple. @@ -516,7 +521,9 @@ def parse_command(cmd): def send_systemd_reply(conn, reply): # Reply & close connection early. # This is necessary to let Enforcer to unlock the ODS DB. - conn.send(reply + '\n') + if isinstance(reply, six.text_type): + reply = reply.encode('ascii') + conn.send(reply + b'\n') conn.shutdown(socket.SHUT_RDWR) conn.close()