From: Douglas Bagnall Date: Wed, 25 Oct 2023 02:56:30 +0000 (+1300) Subject: s4/librpc/py_security: add SDDLValueError X-Git-Tag: talloc-2.4.2~897 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=054725440f2d5452219fbbaa868feb2fe862c3ba;p=thirdparty%2Fsamba.git s4/librpc/py_security: add SDDLValueError This will soon be raised for SDDL parsing errors. It would have been nice to have it as a subclass of ValueError, meaning that all existing callers would continue to catch this error as before, but it turns out that that is quite difficult. Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/source4/librpc/ndr/py_security.c b/source4/librpc/ndr/py_security.c index 9c292c39234..14228c79ab4 100644 --- a/source4/librpc/ndr/py_security.c +++ b/source4/librpc/ndr/py_security.c @@ -22,6 +22,11 @@ #include "libcli/security/sddl.h" #include "libcli/security/security.h" + +/* Set up in py_mod_security_patch() */ +static PyObject *PyExc_SDDLValueError = NULL; + + static void PyType_AddMethods(PyTypeObject *type, PyMethodDef *methods) { PyObject *dict; @@ -576,6 +581,21 @@ static bool py_mod_security_patch(PyObject *m) return false; } } + /* + * I wanted to make this a subclass of ValueError, but it + * seems there isn't an easy way to do that using the API. + * (c.f. SimpleExtendsException in cpython:Objects/exceptions.c) + */ + PyExc_SDDLValueError = PyErr_NewException("security.SDDLValueError", + NULL, NULL); + + if (PyExc_SDDLValueError == NULL) { + return false; + } + ret = PyModule_AddObject(m, "SDDLValueError", PyExc_SDDLValueError); + if (ret != 0) { + return false; + } return true; }