summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Heimes <cheimes@redhat.com>2017-03-14 18:20:13 +0100
committerMartin Basti <mbasti@redhat.com>2017-03-15 19:12:17 +0100
commit42bc778c0c1de91f0d8dc695dfee4e5aea4cc1f0 (patch)
tree65172188c5b8a8ba0d362f33961d7d505d29646a
parent602b395cf19b0ae0b8ade1c13ddaf09175ed7291 (diff)
downloadfreeipa-42bc778c0c1de91f0d8dc695dfee4e5aea4cc1f0.tar.gz
freeipa-42bc778c0c1de91f0d8dc695dfee4e5aea4cc1f0.tar.xz
freeipa-42bc778c0c1de91f0d8dc695dfee4e5aea4cc1f0.zip
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 <cheimes@redhat.com> Reviewed-By: Simo Sorce <ssorce@redhat.com>
-rw-r--r--ipapython/session_storage.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/ipapython/session_storage.py b/ipapython/session_storage.py
index 7fe17fb23..bcf094733 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()