From: Volker Lendecke Date: Fri, 16 Apr 2021 15:22:12 +0000 (+0200) Subject: librpc: Add py_descriptor_richcmp() equality function X-Git-Tag: tevent-0.11.0~1080 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=439b7ccdc1b1c91c66c1a7c83e340fa044c26377;p=thirdparty%2Fsamba.git librpc: Add py_descriptor_richcmp() equality function Only a python3 version. Do we still need the python2 flavor? Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source4/librpc/ndr/py_security.c b/source4/librpc/ndr/py_security.c index 7e260ae2157..f3cc9d13a7f 100644 --- a/source4/librpc/ndr/py_security.c +++ b/source4/librpc/ndr/py_security.c @@ -309,9 +309,46 @@ static PyMethodDef py_descriptor_extra_methods[] = { {0} }; +static PyObject *py_descriptor_richcmp( + PyObject *py_self, PyObject *py_other, int op) +{ + struct security_descriptor *self = pytalloc_get_ptr(py_self); + struct security_descriptor *other = pytalloc_get_ptr(py_other); + bool eq; + + if (other == NULL) { + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; + } + + eq = security_descriptor_equal(self, other); + + switch(op) { + case Py_EQ: + if (eq) { + Py_RETURN_TRUE; + } else { + Py_RETURN_FALSE; + } + break; + case Py_NE: + if (eq) { + Py_RETURN_FALSE; + } else { + Py_RETURN_TRUE; + } + break; + default: + break; + } + + return Py_NotImplemented; +} + static void py_descriptor_patch(PyTypeObject *type) { type->tp_new = py_descriptor_new; + type->tp_richcompare = py_descriptor_richcmp; PyType_AddMethods(type, py_descriptor_extra_methods); }