]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4/librpc/py_security: add SDDLValueError
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 25 Oct 2023 02:56:30 +0000 (15:56 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 1 Nov 2023 20:10:46 +0000 (20:10 +0000)
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 <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/librpc/ndr/py_security.c

index 9c292c39234a8f9460d13da96a95d147182f281d..14228c79ab41e796b8c72954fb6703a61dec4384 100644 (file)
 #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;
 }