summaryrefslogtreecommitdiff
path: root/source4/librpc
diff options
context:
space:
mode:
authorLumir Balhar <lbalhar@redhat.com>2016-12-20 10:53:23 +0100
committerAndrew Bartlett <abartlet@samba.org>2017-03-10 07:31:11 +0100
commita40d7f18dd9e6a83d07731c409aa865f5e0e9aaf (patch)
treee14a0955f485f7bc09fc5bc39a5ae2d3c0f196e6 /source4/librpc
parente481aed28da8687812ad2aed6efaaba26c65d500 (diff)
downloadsamba-a40d7f18dd9e6a83d07731c409aa865f5e0e9aaf.tar.gz
python: samba.dcerpc: Port security module to Python 3 comp. form
Signed-off-by: Lumir Balhar <lbalhar@redhat.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Diffstat (limited to 'source4/librpc')
-rw-r--r--source4/librpc/ndr/py_security.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/source4/librpc/ndr/py_security.c b/source4/librpc/ndr/py_security.c
index 47d8c9a3133..4cc25664996 100644
--- a/source4/librpc/ndr/py_security.c
+++ b/source4/librpc/ndr/py_security.c
@@ -18,6 +18,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Python.h>
+#include "py3compat.h"
#include "libcli/security/security.h"
static void PyType_AddMethods(PyTypeObject *type, PyMethodDef *methods)
@@ -65,6 +66,32 @@ static PyObject *py_dom_sid_split(PyObject *py_self, PyObject *args)
return Py_BuildValue("(OI)", py_domain_sid, rid);
}
+#if PY_MAJOR_VERSION >= 3
+static PyObject *py_dom_sid_richcmp(PyObject *py_self, PyObject *py_other, int op)
+{
+ struct dom_sid *self = pytalloc_get_ptr(py_self), *other;
+ int val;
+
+ other = pytalloc_get_ptr(py_other);
+ if (other == NULL) {
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+
+ val = dom_sid_compare(self, other);
+
+ switch (op) {
+ case Py_EQ: if (val == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+ case Py_NE: if (val != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+ case Py_LT: if (val < 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+ case Py_GT: if (val > 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+ case Py_LE: if (val <= 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+ case Py_GE: if (val >= 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+ }
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+}
+#else
static int py_dom_sid_cmp(PyObject *py_self, PyObject *py_other)
{
struct dom_sid *self = pytalloc_get_ptr(py_self), *other;
@@ -82,12 +109,13 @@ static int py_dom_sid_cmp(PyObject *py_self, PyObject *py_other)
}
return 0;
}
+#endif
static PyObject *py_dom_sid_str(PyObject *py_self)
{
struct dom_sid *self = pytalloc_get_ptr(py_self);
char *str = dom_sid_string(NULL, self);
- PyObject *ret = PyString_FromString(str);
+ PyObject *ret = PyStr_FromString(str);
talloc_free(str);
return ret;
}
@@ -96,7 +124,7 @@ static PyObject *py_dom_sid_repr(PyObject *py_self)
{
struct dom_sid *self = pytalloc_get_ptr(py_self);
char *str = dom_sid_string(NULL, self);
- PyObject *ret = PyString_FromFormat("dom_sid('%s')", str);
+ PyObject *ret = PyStr_FromFormat("dom_sid('%s')", str);
talloc_free(str);
return ret;
}
@@ -131,7 +159,11 @@ static void py_dom_sid_patch(PyTypeObject *type)
type->tp_init = py_dom_sid_init;
type->tp_str = py_dom_sid_str;
type->tp_repr = py_dom_sid_repr;
+#if PY_MAJOR_VERSION >= 3
+ type->tp_richcompare = py_dom_sid_richcmp;
+#else
type->tp_compare = py_dom_sid_cmp;
+#endif
PyType_AddMethods(type, py_dom_sid_extra_methods);
}
@@ -246,7 +278,7 @@ static PyObject *py_descriptor_as_sddl(PyObject *self, PyObject *args)
text = sddl_encode(NULL, desc, sid);
- ret = PyString_FromString(text);
+ ret = PyStr_FromString(text);
talloc_free(text);
@@ -395,7 +427,7 @@ static PyObject *py_privilege_name(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i", &priv))
return NULL;
- return PyString_FromString(sec_privilege_name(priv));
+ return PyStr_FromString(sec_privilege_name(priv));
}
static PyObject *py_privilege_id(PyObject *self, PyObject *args)