diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2009-01-22 14:37:59 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2009-01-22 14:37:59 +0100 |
commit | fc50f7ecbab4bf273697f2114a723eae917251bb (patch) | |
tree | a1d8d0b4e2fac1502ca83c1a6ba5995578a90e03 /source4 | |
parent | 8f68a716fdefb153811d7d930fdd73df9963246a (diff) | |
download | samba-fc50f7ecbab4bf273697f2114a723eae917251bb.tar.gz samba-fc50f7ecbab4bf273697f2114a723eae917251bb.tar.bz2 samba-fc50f7ecbab4bf273697f2114a723eae917251bb.zip |
Support parsing sddl for security descriptors.
Diffstat (limited to 'source4')
-rw-r--r-- | source4/libcli/security/tests/bindings.py | 8 | ||||
-rw-r--r-- | source4/librpc/ndr/py_security.c | 31 |
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 } }; |