sssd/0080-PYTHON-Define-constants-as-bytes-instead-of-strings.patch
2017-09-01 21:34:35 +02:00

50 lines
2.0 KiB
Diff

From 9375eae59550437c85ada9212be430a4242b25a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
Date: Wed, 30 Aug 2017 14:13:51 +0200
Subject: [PATCH 80/93] PYTHON: Define constants as bytes instead of strings
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
When using python3 getsidbyname() and getnamebysid() expect the key as
bytes instead of strings, and currently those are defined as strings.
So, in order to avoid people working around this by doing
`pysss_nss_idmap.SID_KEY.encode('utf-8')` let's make their life easier
and properly have those constants defined as bytes.
Resolves: https://pagure.io/SSSD/sssd/issue/3491
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Michal Židek <mzidek@redhat.com>
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
---
src/python/pysss_nss_idmap.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/python/pysss_nss_idmap.c b/src/python/pysss_nss_idmap.c
index 2e5851c7a6e48629fd93e428aada499fcbe36ebb..be7fa297edf99674505b44820e36c9126dee61da 100644
--- a/src/python/pysss_nss_idmap.c
+++ b/src/python/pysss_nss_idmap.c
@@ -533,10 +533,17 @@ initpysss_nss_idmap(void)
PyModule_AddIntConstant(module, "ID_GROUP", SSS_ID_TYPE_GID);
PyModule_AddIntConstant(module, "ID_BOTH", SSS_ID_TYPE_BOTH);
+#ifdef IS_PY3K
+ PyModule_AddObject(module, "SID_KEY", PyBytes_FromString(SSS_SID_KEY));
+ PyModule_AddObject(module, "NAME_KEY", PyBytes_FromString(SSS_NAME_KEY));
+ PyModule_AddObject(module, "ID_KEY", PyBytes_FromString(SSS_ID_KEY));
+ PyModule_AddObject(module, "TYPE_KEY", PyBytes_FromString(SSS_TYPE_KEY));
+#else
PyModule_AddStringConstant(module, "SID_KEY", SSS_SID_KEY);
PyModule_AddStringConstant(module, "NAME_KEY", SSS_NAME_KEY);
PyModule_AddStringConstant(module, "ID_KEY", SSS_ID_KEY);
PyModule_AddStringConstant(module, "TYPE_KEY", SSS_TYPE_KEY);
+#endif
#ifdef IS_PY3K
return module;
--
2.14.1