From 42bc778c0c1de91f0d8dc695dfee4e5aea4cc1f0 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Mar 15 2017 18:12:17 +0000 Subject: Python 3: Fix session storage ctypes can only handle bytes, not text. Encode and decode all incoming and outgoing text from UTF-8 to bytes. Signed-off-by: Christian Heimes Reviewed-By: Simo Sorce --- diff --git a/ipapython/session_storage.py b/ipapython/session_storage.py index 7fe17fb..bcf0947 100644 --- a/ipapython/session_storage.py +++ b/ipapython/session_storage.py @@ -104,6 +104,13 @@ def store_data(princ_name, key, value): """ Stores the session cookie in a hidden ccache entry. """ + if not isinstance(princ_name, bytes): + princ_name = princ_name.encode('utf-8') + if not isinstance(key, bytes): + key = key.encode('ascii') + if not isinstance(value, bytes): + value = value.encode('utf-8') + context = krb5_context() principal = krb5_principal() ccache = krb5_ccache() @@ -136,6 +143,11 @@ def get_data(princ_name, key): """ Gets the session cookie in a hidden ccache entry. """ + if not isinstance(princ_name, bytes): + princ_name = princ_name.encode('utf-8') + if not isinstance(key, bytes): + key = key.encode('utf-8') + context = krb5_context() principal = krb5_principal() ccache = krb5_ccache() @@ -152,7 +164,7 @@ def get_data(princ_name, key): krb5_cc_get_config(context, ccache, principal, key, ctypes.byref(data)) - return str(data.data) + return data.data.decode('utf-8') finally: if principal: @@ -169,6 +181,11 @@ def remove_data(princ_name, key): """ Removes the hidden ccache entry with the session cookie. """ + if not isinstance(princ_name, bytes): + princ_name = princ_name.encode('utf-8') + if not isinstance(key, bytes): + key = key.encode('utf-8') + context = krb5_context() principal = krb5_principal() ccache = krb5_ccache()