summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/libcli/security/tests/bindings.py8
-rw-r--r--source4/librpc/ndr/py_security.c31
2 files changed, 37 insertions, 2 deletions
diff --git a/source4/libcli/security/tests/bindings.py b/source4/libcli/security/tests/bindings.py
index 2b23ecf05f..f556a23e01 100644
--- a/source4/libcli/security/tests/bindings.py
+++ b/source4/libcli/security/tests/bindings.py
@@ -49,6 +49,14 @@ class SecurityDescriptorTests(unittest.TestCase):
def setUp(self):
self.descriptor = security.descriptor()
+ def test_from_sddl(self):
+ desc = security.descriptor.from_sddl("O:AOG:DAD:(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-0-0)", security.dom_sid("S-2-0-0"))
+ self.assertEquals(desc.group_sid, security.dom_sid('S-2-0-0-512'))
+ self.assertEquals(desc.owner_sid, security.dom_sid('S-1-5-32-548'))
+ self.assertEquals(desc.revision, 1)
+ self.assertEquals(desc.sacl, None)
+ self.assertEquals(desc.type, 0x8004)
+
class DomSidTests(unittest.TestCase):
def test_parse_sid(self):
diff --git a/source4/librpc/ndr/py_security.c b/source4/librpc/ndr/py_security.c
index 08542640b9..e1b50def1d 100644
--- a/source4/librpc/ndr/py_security.c
+++ b/source4/librpc/ndr/py_security.c
@@ -31,7 +31,11 @@ static void PyType_AddMethods(PyTypeObject *type, PyMethodDef *methods)
type->tp_dict = PyDict_New();
dict = type->tp_dict;
for (i = 0; methods[i].ml_name; i++) {
- PyObject *descr = PyDescr_NewMethod(type, &methods[i]);
+ PyObject *descr;
+ if (methods[i].ml_flags & METH_CLASS)
+ descr = PyCFunction_New(&methods[i], type);
+ else
+ descr = PyDescr_NewMethod(type, &methods[i]);
PyDict_SetItemString(dict, methods[i].ml_name,
descr);
}
@@ -160,7 +164,28 @@ static PyObject *py_descriptor_sacl_del(PyObject *self, PyObject *args)
static PyObject *py_descriptor_new(PyTypeObject *self, PyObject *args, PyObject *kwargs)
{
return py_talloc_import(self, security_descriptor_initialise(NULL));
-}
+}
+
+static PyObject *py_descriptor_from_sddl(PyObject *self, PyObject *args)
+{
+ struct security_descriptor *secdesc;
+ char *sddl;
+ PyObject *py_sid;
+ struct dom_sid *sid;
+
+ if (!PyArg_ParseTuple(args, "sO", &sddl, &py_sid))
+ return NULL;
+
+ sid = py_talloc_get_ptr(py_sid);
+
+ secdesc = sddl_decode(NULL, sddl, sid);
+ if (secdesc == NULL) {
+ PyErr_SetString(PyExc_TypeError, "Unable to parse SDDL");
+ return NULL;
+ }
+
+ return py_talloc_import((PyTypeObject *)self, secdesc);
+}
static PyMethodDef py_descriptor_extra_methods[] = {
{ "sacl_add", (PyCFunction)py_descriptor_sacl_add, METH_VARARGS,
@@ -172,6 +197,8 @@ static PyMethodDef py_descriptor_extra_methods[] = {
NULL },
{ "sacl_del", (PyCFunction)py_descriptor_sacl_del, METH_VARARGS,
NULL },
+ { "from_sddl", (PyCFunction)py_descriptor_from_sddl, METH_VARARGS|METH_CLASS,
+ NULL },
{ NULL }
};