Implement as_sddl.
authorJelmer Vernooij <jelmer@samba.org>
Thu, 22 Jan 2009 13:49:51 +0000 (14:49 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 22 Jan 2009 13:49:51 +0000 (14:49 +0100)
source4/libcli/security/tests/bindings.py
source4/librpc/ndr/py_security.c

index f556a23e01893d6a7c7bbf1e15ebfd4e3ae9d84f..24ee01c37fb244d8d360fb0ea3258121d4fab3ee 100644 (file)
@@ -57,6 +57,16 @@ class SecurityDescriptorTests(unittest.TestCase):
         self.assertEquals(desc.sacl, None)
         self.assertEquals(desc.type, 0x8004)
 
+    def test_as_sddl(self):
+        text = "O:AOG:DAD:(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-0-0)"
+        dom = security.dom_sid("S-2-0-0")
+        desc1 = security.descriptor.from_sddl(text, dom)
+        desc2 = security.descriptor.from_sddl(desc1.as_sddl(dom), dom)
+        self.assertEquals(desc1.group_sid, desc2.group_sid)
+        self.assertEquals(desc1.owner_sid, desc2.owner_sid)
+        self.assertEquals(desc1.sacl, desc2.sacl)
+        self.assertEquals(desc1.type, desc2.type)
+
 
 class DomSidTests(unittest.TestCase):
     def test_parse_sid(self):
index e1b50def1d40e668f2f14da644f75ce29164db07..93e4a093f3d02ceb8b67720b764123bb69b132e2 100644 (file)
@@ -33,7 +33,7 @@ static void PyType_AddMethods(PyTypeObject *type, PyMethodDef *methods)
        for (i = 0; methods[i].ml_name; i++) {
                PyObject *descr;
                if (methods[i].ml_flags & METH_CLASS) 
-                       descr = PyCFunction_New(&methods[i], type);
+                       descr = PyCFunction_New(&methods[i], (PyObject *)type);
                else 
                        descr = PyDescr_NewMethod(type, &methods[i]);
                PyDict_SetItemString(dict, methods[i].ml_name, 
@@ -187,6 +187,22 @@ static PyObject *py_descriptor_from_sddl(PyObject *self, PyObject *args)
        return py_talloc_import((PyTypeObject *)self, secdesc);
 }
 
+static PyObject *py_descriptor_as_sddl(PyObject *self, PyObject *py_sid)
+{
+       struct dom_sid *sid = py_talloc_get_ptr(py_sid);
+       struct security_descriptor *desc = py_talloc_get_ptr(self);
+       char *text;
+       PyObject *ret;
+
+       text = sddl_encode(NULL, desc, sid);
+
+       ret = PyString_FromString(text);
+
+       talloc_free(text);
+
+       return ret;
+}
+
 static PyMethodDef py_descriptor_extra_methods[] = {
        { "sacl_add", (PyCFunction)py_descriptor_sacl_add, METH_VARARGS,
                "S.sacl_add(ace) -> None\n"
@@ -199,6 +215,8 @@ static PyMethodDef py_descriptor_extra_methods[] = {
                NULL },
        { "from_sddl", (PyCFunction)py_descriptor_from_sddl, METH_VARARGS|METH_CLASS, 
                NULL },
+       { "as_sddl", (PyCFunction)py_descriptor_as_sddl, METH_O,
+               NULL },
        { NULL }
 };