mirror of
https://github.com/samba-team/samba.git
synced 2025-01-13 13:18:06 +03:00
Support parsing sddl for security descriptors.
This commit is contained in:
parent
8f68a716fd
commit
fc50f7ecba
@ -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):
|
||||
|
@ -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 }
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user