URL: https://github.com/freeipa/freeipa/pull/587 Author: tiran Title: #587: Python 3: Fix session storage Action: opened
PR body: """ 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 <chei...@redhat.com> """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/587/head:pr587 git checkout pr587
From cd4540662d5ca2e41239a26c08effff8e4889714 Mon Sep 17 00:00:00 2001 From: Christian Heimes <chei...@redhat.com> Date: Tue, 14 Mar 2017 18:20:13 +0100 Subject: [PATCH] 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 <chei...@redhat.com> --- ipapython/session_storage.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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()
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code