]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pyldb: Remove unused and broken Python access to LDB module API
authorAndrew Bartlett <abartlet@samba.org>
Tue, 14 Nov 2023 06:12:02 +0000 (19:12 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 3 Mar 2024 22:33:35 +0000 (22:33 +0000)
These exposed the private LDB modules API to python, and was
untested and broken since LDB was made async internally as
it never called ldb_wait() on the result.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
WHATSNEW.txt
lib/ldb/pyldb.c
lib/ldb/pyldb.h
lib/ldb/tests/python/api.py
python/samba/tests/segfault.py

index cad6e08815a4a4dbba701be63f81133df5a4d3b4..bdd296909d38e0877bc8970ddb9f0b7610d3b397 100644 (file)
@@ -37,6 +37,15 @@ building Samba and LDB is this way.
 As part of this work, the pyldb-util public library, not known to be
 used by any other software, is made private to Samba.
 
+LDB Module API Python bindings removed
+--------------------------------------
+
+The LDB Modules API, which we do not promise a stable ABI or API for,
+was wrapped in python in early LDB development.  However that wrapping
+never took into account later changes, and so has not worked for a
+number of years.  Samba 4.21 and LDB 2.10 removes this unused and
+broken feature.
+
 REMOVED FEATURES
 ================
 
index 61e50f1b0c32b1f68e54814ebf30c304a4791e8d..deaf2a0e7f48d2a769d6e316ea135f6aa8122e00 100644 (file)
@@ -66,7 +66,6 @@ static PyTypeObject PyLdbResult;
 static PyTypeObject PyLdbSearchIterator;
 static PyTypeObject PyLdbMessage;
 #define PyLdbMessage_Check(ob) PyObject_TypeCheck(ob, &PyLdbMessage)
-static PyTypeObject PyLdbModule;
 static PyTypeObject PyLdbDn;
 #define pyldb_Dn_Check(ob) PyObject_TypeCheck(ob, &PyLdbDn)
 static PyTypeObject PyLdb;
@@ -74,8 +73,6 @@ static PyTypeObject PyLdbMessageElement;
 #define pyldb_MessageElement_Check(ob) PyObject_TypeCheck(ob, &PyLdbMessageElement)
 
 static PyTypeObject PyLdbTree;
-static PyObject *PyLdb_FromLdbContext(struct ldb_context *ldb_ctx);
-static PyObject *PyLdbModule_FromModule(struct ldb_module *mod);
 static struct ldb_message_element *PyObject_AsMessageElement(
                                                      TALLOC_CTX *mem_ctx,
                                                      PyObject *set_obj,
@@ -458,54 +455,6 @@ static PyObject *PyLdbResult_FromResult(struct ldb_result *result)
        return (PyObject *)ret;
 }
 
-/**
- * Create a LDB Result from a Python object.
- * If conversion fails, NULL will be returned and a Python exception set.
- *
- * Note: the result object only includes the messages at the moment; extended
- * result, controls and referrals are ignored.
- *
- * @param mem_ctx Memory context in which to allocate the LDB Result
- * @param obj Python object to convert
- * @return a ldb_result, or NULL if the conversion failed
- */
-static struct ldb_result *PyLdbResult_AsResult(TALLOC_CTX *mem_ctx, 
-                                              PyObject *obj)
-{
-       struct ldb_result *res;
-       Py_ssize_t i;
-
-       if (obj == Py_None)
-               return NULL;
-
-       if (!PyList_Check(obj)) {
-               PyErr_SetString(PyExc_ValueError, "Expected list of LDB results");
-               return NULL;
-       }
-
-       res = talloc_zero(mem_ctx, struct ldb_result);
-       if (res == NULL) {
-               PyErr_NoMemory();
-               return NULL;
-       }
-       res->count = PyList_Size(obj);
-       res->msgs = talloc_array(res, struct ldb_message *, res->count);
-       if (res->msgs == NULL) {
-               talloc_free(res);
-               PyErr_NoMemory();
-               return NULL;
-       }
-       for (i = 0; i < res->count; i++) {
-               PyObject *item = PyList_GetItem(obj, i);
-               if (item == NULL) {
-                       talloc_free(res);
-                       return NULL;
-               }
-               res->msgs[i] = pyldb_Message_AsMessage(item);
-       }
-       return res;
-}
-
 static PyObject *py_ldb_dn_validate(PyLdbDnObject *self,
                PyObject *Py_UNUSED(ignored))
 {
@@ -2485,36 +2434,6 @@ static PyObject *py_ldb_set_opaque(PyLdbObject *self, PyObject *args)
        Py_RETURN_NONE;
 }
 
-static PyObject *py_ldb_modules(PyLdbObject *self,
-               PyObject *Py_UNUSED(ignored))
-{
-       struct ldb_context *ldb = pyldb_Ldb_AS_LDBCONTEXT(self);
-       PyObject *ret = PyList_New(0);
-       struct ldb_module *mod;
-
-       if (ret == NULL) {
-               return PyErr_NoMemory();
-       }
-       for (mod = ldb->modules; mod; mod = mod->next) {
-               PyObject *item = PyLdbModule_FromModule(mod);
-               int res = 0;
-               if (item == NULL) {
-                       PyErr_SetString(PyExc_RuntimeError,
-                               "Failed to load LdbModule");
-                       Py_CLEAR(ret);
-                       return NULL;
-               }
-               res = PyList_Append(ret, item);
-               Py_CLEAR(item);
-               if (res == -1) {
-                       Py_CLEAR(ret);
-                       return NULL;
-               }
-       }
-
-       return ret;
-}
-
 static PyObject *py_ldb_sequence_number(PyLdbObject *self, PyObject *args)
 {
        struct ldb_context *ldb = pyldb_Ldb_AS_LDBCONTEXT(self);
@@ -2688,9 +2607,6 @@ static PyMethodDef py_ldb_methods[] = {
                "S.set_opaque(name, value) -> None\n"
                "Set an opaque value on this LDB connection. \n"
                ":note: Passing incorrect values may cause crashes." },
-       { "modules", (PyCFunction)py_ldb_modules, METH_NOARGS,
-               "S.modules() -> list\n"
-               "Return the list of modules on this LDB connection " },
        { "sequence_number", (PyCFunction)py_ldb_sequence_number, METH_VARARGS,
                "S.sequence_number(type) -> value\n"
                "Return the value of the sequence according to the requested type" },
@@ -2706,51 +2622,6 @@ static PyMethodDef py_ldb_methods[] = {
        {0},
 };
 
-static PyObject *PyLdbModule_FromModule(struct ldb_module *mod)
-{
-       TALLOC_CTX *mem_ctx = NULL;
-       struct ldb_module *mod_ref = NULL;
-       PyLdbModuleObject *ret;
-
-       mem_ctx = talloc_new(NULL);
-       if (mem_ctx == NULL) {
-               return PyErr_NoMemory();
-       }
-
-       mod_ref = talloc_reference(mem_ctx, mod);
-       if (mod_ref == NULL) {
-               talloc_free(mem_ctx);
-               return PyErr_NoMemory();
-       }
-
-       ret = (PyLdbModuleObject *)PyLdbModule.tp_alloc(&PyLdbModule, 0);
-       if (ret == NULL) {
-               talloc_free(mem_ctx);
-               PyErr_NoMemory();
-               return NULL;
-       }
-       ret->mem_ctx = mem_ctx;
-       ret->mod = mod_ref;
-       return (PyObject *)ret;
-}
-
-static PyObject *py_ldb_get_firstmodule(PyLdbObject *self, void *closure)
-{
-       struct ldb_module *mod = pyldb_Ldb_AS_LDBCONTEXT(self)->modules;
-       if (mod == NULL) {
-               Py_RETURN_NONE;
-       }
-       return PyLdbModule_FromModule(mod);
-}
-
-static PyGetSetDef py_ldb_getset[] = {
-       {
-               .name = discard_const_p(char, "firstmodule"),
-               .get  = (getter)py_ldb_get_firstmodule,
-       },
-       { .name = NULL },
-};
-
 static int py_ldb_contains(PyLdbObject *self, PyObject *obj)
 {
        struct ldb_context *ldb_ctx = pyldb_Ldb_AS_LDBCONTEXT(self);
@@ -2789,34 +2660,6 @@ static PySequenceMethods py_ldb_seq = {
        .sq_contains = (objobjproc)py_ldb_contains,
 };
 
-static PyObject *PyLdb_FromLdbContext(struct ldb_context *ldb_ctx)
-{
-       TALLOC_CTX *mem_ctx = NULL;
-       struct ldb_context *ldb_ctx_ref = NULL;
-       PyLdbObject *ret;
-
-       mem_ctx = talloc_new(NULL);
-       if (mem_ctx == NULL) {
-               return PyErr_NoMemory();
-       }
-
-       ldb_ctx_ref = talloc_reference(mem_ctx, ldb_ctx);
-       if (ldb_ctx_ref == NULL) {
-               talloc_free(mem_ctx);
-               return PyErr_NoMemory();
-       }
-
-       ret = (PyLdbObject *)PyLdb.tp_alloc(&PyLdb, 0);
-       if (ret == NULL) {
-               talloc_free(mem_ctx);
-               PyErr_NoMemory();
-               return NULL;
-       }
-       ret->mem_ctx = mem_ctx;
-       ret->ldb_ctx = ldb_ctx_ref;
-       return (PyObject *)ret;
-}
-
 static void py_ldb_dealloc(PyLdbObject *self)
 {
        talloc_free(self->mem_ctx);
@@ -2830,7 +2673,6 @@ static PyTypeObject PyLdb = {
        .tp_new = py_ldb_new,
        .tp_init = (initproc)py_ldb_init,
        .tp_dealloc = (destructor)py_ldb_dealloc,
-       .tp_getset = py_ldb_getset,
        .tp_getattro = PyObject_GenericGetAttr,
        .tp_basicsize = sizeof(PyLdbObject),
        .tp_doc = "Connection to a LDB database.",
@@ -3079,225 +2921,6 @@ static PyTypeObject PyLdbSearchIterator = {
        .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
 };
 
-static PyObject *py_ldb_module_repr(PyLdbModuleObject *self)
-{
-       return PyUnicode_FromFormat("<ldb module '%s'>",
-               pyldb_Module_AsModule(self)->ops->name);
-}
-
-static PyObject *py_ldb_module_str(PyLdbModuleObject *self)
-{
-       return PyUnicode_FromString(pyldb_Module_AsModule(self)->ops->name);
-}
-
-static PyObject *py_ldb_module_start_transaction(PyLdbModuleObject *self,
-               PyObject *Py_UNUSED(ignored))
-{
-       pyldb_Module_AsModule(self)->ops->start_transaction(pyldb_Module_AsModule(self));
-       Py_RETURN_NONE;
-}
-
-static PyObject *py_ldb_module_end_transaction(PyLdbModuleObject *self,
-               PyObject *Py_UNUSED(ignored))
-{
-       pyldb_Module_AsModule(self)->ops->end_transaction(pyldb_Module_AsModule(self));
-       Py_RETURN_NONE;
-}
-
-static PyObject *py_ldb_module_del_transaction(PyLdbModuleObject *self,
-               PyObject *Py_UNUSED(ignored))
-{
-       pyldb_Module_AsModule(self)->ops->del_transaction(pyldb_Module_AsModule(self));
-       Py_RETURN_NONE;
-}
-
-static PyObject *py_ldb_module_search(PyLdbModuleObject *self, PyObject *args, PyObject *kwargs)
-{
-       PyObject *py_base, *py_tree, *py_attrs, *py_ret;
-       int ret, scope;
-       struct ldb_request *req;
-       const char * const kwnames[] = { "base", "scope", "tree", "attrs", NULL };
-       struct ldb_module *mod;
-       const char * const*attrs;
-
-       /* type "int" rather than "enum" for "scope" is intentional */
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!iOO",
-                                        discard_const_p(char *, kwnames),
-                                        &PyLdbDn, &py_base, &scope, &py_tree, &py_attrs))
-               return NULL;
-
-       mod = self->mod;
-
-       if (py_attrs == Py_None) {
-               attrs = NULL;
-       } else {
-               attrs = PyList_AsStrList(NULL, py_attrs, "attrs");
-               if (attrs == NULL)
-                       return NULL;
-       }
-
-       ret = ldb_build_search_req(&req, mod->ldb, NULL, pyldb_Dn_AS_DN(py_base),
-                            scope, NULL /* expr */, attrs,
-                            NULL /* controls */, NULL, NULL, NULL);
-
-       talloc_steal(req, attrs);
-
-       PyErr_LDB_ERROR_IS_ERR_RAISE_FREE(PyExc_LdbError, ret, mod->ldb, req);
-
-       req->op.search.res = NULL;
-
-       ret = mod->ops->search(mod, req);
-
-       PyErr_LDB_ERROR_IS_ERR_RAISE_FREE(PyExc_LdbError, ret, mod->ldb, req);
-
-       py_ret = PyLdbResult_FromResult(req->op.search.res);
-
-       talloc_free(req);
-
-       return py_ret;
-}
-
-
-static PyObject *py_ldb_module_add(PyLdbModuleObject *self, PyObject *args)
-{
-       struct ldb_request *req;
-       PyObject *py_message;
-       int ret;
-       struct ldb_module *mod;
-
-       if (!PyArg_ParseTuple(args, "O!", &PyLdbMessage, &py_message))
-               return NULL;
-
-       req = talloc_zero(NULL, struct ldb_request);
-       if (req == NULL) {
-               PyErr_NoMemory();
-               return NULL;
-       }
-       req->operation = LDB_ADD;
-       req->op.add.message = pyldb_Message_AsMessage(py_message);
-
-       mod = pyldb_Module_AsModule(self);
-       ret = mod->ops->add(mod, req);
-
-       PyErr_LDB_ERROR_IS_ERR_RAISE_FREE(PyExc_LdbError, ret, mod->ldb, req);
-
-       TALLOC_FREE(req);
-       Py_RETURN_NONE;
-}
-
-static PyObject *py_ldb_module_modify(PyLdbModuleObject *self, PyObject *args) 
-{
-       int ret;
-       struct ldb_request *req;
-       PyObject *py_message;
-       struct ldb_module *mod;
-
-       if (!PyArg_ParseTuple(args, "O!", &PyLdbMessage, &py_message))
-               return NULL;
-
-       req = talloc_zero(NULL, struct ldb_request);
-       if (req == NULL) {
-               PyErr_NoMemory();
-               return NULL;
-       }
-
-       req->operation = LDB_MODIFY;
-       req->op.mod.message = pyldb_Message_AsMessage(py_message);
-
-       mod = pyldb_Module_AsModule(self);
-       ret = mod->ops->modify(mod, req);
-
-       PyErr_LDB_ERROR_IS_ERR_RAISE_FREE(PyExc_LdbError, ret, mod->ldb, req);
-
-       TALLOC_FREE(req);
-       Py_RETURN_NONE;
-}
-
-static PyObject *py_ldb_module_delete(PyLdbModuleObject *self, PyObject *args) 
-{
-       int ret;
-       struct ldb_request *req;
-       PyObject *py_dn;
-
-       if (!PyArg_ParseTuple(args, "O!", &PyLdbDn, &py_dn))
-               return NULL;
-
-       req = talloc_zero(NULL, struct ldb_request);
-       if (req == NULL) {
-               PyErr_NoMemory();
-               return NULL;
-       }
-       req->operation = LDB_DELETE;
-       req->op.del.dn = pyldb_Dn_AS_DN(py_dn);
-
-       ret = pyldb_Module_AsModule(self)->ops->del(pyldb_Module_AsModule(self), req);
-
-       PyErr_LDB_ERROR_IS_ERR_RAISE_FREE(PyExc_LdbError, ret, NULL, req);
-
-       TALLOC_FREE(req);
-
-       Py_RETURN_NONE;
-}
-
-static PyObject *py_ldb_module_rename(PyLdbModuleObject *self, PyObject *args)
-{
-       int ret;
-       struct ldb_request *req;
-       PyObject *py_dn1, *py_dn2;
-
-       if (!PyArg_ParseTuple(args, "O!O!", &PyLdbDn, &py_dn1, &PyLdbDn, &py_dn2))
-               return NULL;
-
-       req = talloc_zero(NULL, struct ldb_request);
-       if (req == NULL) {
-               PyErr_NoMemory();
-               return NULL;
-       }
-
-       req->operation = LDB_RENAME;
-       req->op.rename.olddn = pyldb_Dn_AS_DN(py_dn1);
-       req->op.rename.newdn = pyldb_Dn_AS_DN(py_dn2);
-
-       ret = pyldb_Module_AsModule(self)->ops->rename(pyldb_Module_AsModule(self), req);
-
-       PyErr_LDB_ERROR_IS_ERR_RAISE_FREE(PyExc_LdbError, ret, NULL, req);
-
-       TALLOC_FREE(req);
-
-       Py_RETURN_NONE;
-}
-
-static PyMethodDef py_ldb_module_methods[] = {
-       { "search", PY_DISCARD_FUNC_SIG(PyCFunction, py_ldb_module_search),
-               METH_VARARGS|METH_KEYWORDS, NULL },
-       { "add", (PyCFunction)py_ldb_module_add, METH_VARARGS, NULL },
-       { "modify", (PyCFunction)py_ldb_module_modify, METH_VARARGS, NULL },
-       { "rename", (PyCFunction)py_ldb_module_rename, METH_VARARGS, NULL },
-       { "delete", (PyCFunction)py_ldb_module_delete, METH_VARARGS, NULL },
-       { "start_transaction", (PyCFunction)py_ldb_module_start_transaction, METH_NOARGS, NULL },
-       { "end_transaction", (PyCFunction)py_ldb_module_end_transaction, METH_NOARGS, NULL },
-       { "del_transaction", (PyCFunction)py_ldb_module_del_transaction, METH_NOARGS, NULL },
-       {0},
-};
-
-static void py_ldb_module_dealloc(PyLdbModuleObject *self)
-{
-       talloc_free(self->mem_ctx);
-       PyObject_Del(self);
-}
-
-static PyTypeObject PyLdbModule = {
-       .tp_name = "ldb.LdbModule",
-       .tp_methods = py_ldb_module_methods,
-       .tp_repr = (reprfunc)py_ldb_module_repr,
-       .tp_str = (reprfunc)py_ldb_module_str,
-       .tp_basicsize = sizeof(PyLdbModuleObject),
-       .tp_dealloc = (destructor)py_ldb_module_dealloc,
-       .tp_flags = Py_TPFLAGS_DEFAULT,
-       .tp_doc = "LDB module (extension)",
-};
-
-
 /**
  * Create a ldb_message_element from a Python object.
  *
@@ -4350,35 +3973,6 @@ static PyTypeObject PyLdbMessage = {
        .tp_doc = "A LDB Message",
 };
 
-static PyObject *PyLdbTree_FromTree(struct ldb_parse_tree *tree)
-{
-       TALLOC_CTX *mem_ctx = NULL;
-       struct ldb_parse_tree *tree_ref = NULL;
-       PyLdbTreeObject *ret;
-
-       mem_ctx = talloc_new(NULL);
-       if (mem_ctx == NULL) {
-               return PyErr_NoMemory();
-       }
-
-       tree_ref = talloc_reference(mem_ctx, tree);
-       if (tree_ref == NULL) {
-               talloc_free(mem_ctx);
-               return PyErr_NoMemory();
-       }
-
-       ret = (PyLdbTreeObject *)PyLdbTree.tp_alloc(&PyLdbTree, 0);
-       if (ret == NULL) {
-               talloc_free(mem_ctx);
-               PyErr_NoMemory();
-               return NULL;
-       }
-
-       ret->mem_ctx = mem_ctx;
-       ret->tree = tree_ref;
-       return (PyObject *)ret;
-}
-
 static void py_ldb_tree_dealloc(PyLdbTreeObject *self)
 {
        talloc_free(self->mem_ctx);
@@ -4393,367 +3987,6 @@ static PyTypeObject PyLdbTree = {
        .tp_doc = "A search tree",
 };
 
-/* Ldb_module */
-static int py_module_search(struct ldb_module *mod, struct ldb_request *req)
-{
-       PyObject *py_ldb = (PyObject *)mod->private_data;
-       PyObject *py_result, *py_base, *py_attrs, *py_tree;
-
-       py_base = pyldb_Dn_FromDn(req->op.search.base);
-
-       if (py_base == NULL)
-               return LDB_ERR_OPERATIONS_ERROR;
-
-       py_tree = PyLdbTree_FromTree(req->op.search.tree);
-
-       if (py_tree == NULL) {
-               Py_DECREF(py_base);
-               return LDB_ERR_OPERATIONS_ERROR;
-       }
-
-       if (req->op.search.attrs == NULL) {
-               py_attrs = Py_None;
-       } else {
-               int i, len;
-               for (len = 0; req->op.search.attrs[len]; len++);
-               py_attrs = PyList_New(len);
-               if (py_attrs == NULL) {
-                       Py_DECREF(py_tree);
-                       Py_DECREF(py_base);
-                       return LDB_ERR_OPERATIONS_ERROR;
-               }
-               for (i = 0; i < len; i++) {
-                       PyObject *py_attr = NULL;
-                       int ret;
-
-                       py_attr = PyUnicode_FromString(req->op.search.attrs[i]);
-                       if (py_attr == NULL) {
-                               Py_DECREF(py_tree);
-                               Py_DECREF(py_base);
-                               Py_DECREF(py_attrs);
-                               return LDB_ERR_OPERATIONS_ERROR;
-                       }
-
-                       ret = PyList_SetItem(py_attrs, i, py_attr);
-                       if (ret) {
-                               Py_DECREF(py_attr);
-                               Py_DECREF(py_tree);
-                               Py_DECREF(py_base);
-                               Py_DECREF(py_attrs);
-                               return LDB_ERR_OPERATIONS_ERROR;
-                       }
-               }
-       }
-
-       py_result = PyObject_CallMethod(py_ldb, discard_const_p(char, "search"),
-                                       discard_const_p(char, "OiOO"),
-                                       py_base, req->op.search.scope, py_tree, py_attrs);
-
-       Py_DECREF(py_attrs);
-       Py_DECREF(py_tree);
-       Py_DECREF(py_base);
-
-       if (py_result == NULL) {
-               return LDB_ERR_PYTHON_EXCEPTION;
-       }
-
-       req->op.search.res = PyLdbResult_AsResult(NULL, py_result);
-       if (req->op.search.res == NULL) {
-               Py_DECREF(py_result);
-               return LDB_ERR_PYTHON_EXCEPTION;
-       }
-
-       Py_DECREF(py_result);
-
-       return LDB_SUCCESS;
-}
-
-static int py_module_add(struct ldb_module *mod, struct ldb_request *req)
-{
-       PyObject *py_ldb = (PyObject *)mod->private_data;
-       PyObject *py_result, *py_msg;
-
-       py_msg = PyLdbMessage_FromMessage(discard_const_p(struct ldb_message, req->op.add.message));
-
-       if (py_msg == NULL) {
-               return LDB_ERR_OPERATIONS_ERROR;
-       }
-
-       py_result = PyObject_CallMethod(py_ldb, discard_const_p(char, "add"),
-                                       discard_const_p(char, "O"),
-                                       py_msg);
-
-       Py_DECREF(py_msg);
-
-       if (py_result == NULL) {
-               return LDB_ERR_PYTHON_EXCEPTION;
-       }
-
-       Py_DECREF(py_result);
-
-       return LDB_SUCCESS;
-}
-
-static int py_module_modify(struct ldb_module *mod, struct ldb_request *req)
-{
-       PyObject *py_ldb = (PyObject *)mod->private_data;
-       PyObject *py_result, *py_msg;
-
-       py_msg = PyLdbMessage_FromMessage(discard_const_p(struct ldb_message, req->op.mod.message));
-
-       if (py_msg == NULL) {
-               return LDB_ERR_OPERATIONS_ERROR;
-       }
-
-       py_result = PyObject_CallMethod(py_ldb, discard_const_p(char, "modify"),
-                                       discard_const_p(char, "O"),
-                                       py_msg);
-
-       Py_DECREF(py_msg);
-
-       if (py_result == NULL) {
-               return LDB_ERR_PYTHON_EXCEPTION;
-       }
-
-       Py_DECREF(py_result);
-
-       return LDB_SUCCESS;
-}
-
-static int py_module_del(struct ldb_module *mod, struct ldb_request *req)
-{
-       PyObject *py_ldb = (PyObject *)mod->private_data;
-       PyObject *py_result, *py_dn;
-
-       py_dn = pyldb_Dn_FromDn(req->op.del.dn);
-
-       if (py_dn == NULL)
-               return LDB_ERR_OPERATIONS_ERROR;
-
-       py_result = PyObject_CallMethod(py_ldb, discard_const_p(char, "delete"),
-                                       discard_const_p(char, "O"),
-                                       py_dn);
-       Py_DECREF(py_dn);
-
-       if (py_result == NULL) {
-               return LDB_ERR_PYTHON_EXCEPTION;
-       }
-
-       Py_DECREF(py_result);
-
-       return LDB_SUCCESS;
-}
-
-static int py_module_rename(struct ldb_module *mod, struct ldb_request *req)
-{
-       PyObject *py_ldb = (PyObject *)mod->private_data;
-       PyObject *py_result, *py_olddn, *py_newdn;
-
-       py_olddn = pyldb_Dn_FromDn(req->op.rename.olddn);
-
-       if (py_olddn == NULL)
-               return LDB_ERR_OPERATIONS_ERROR;
-
-       py_newdn = pyldb_Dn_FromDn(req->op.rename.newdn);
-
-       if (py_newdn == NULL) {
-               Py_DECREF(py_olddn);
-               return LDB_ERR_OPERATIONS_ERROR;
-       }
-
-       py_result = PyObject_CallMethod(py_ldb, discard_const_p(char, "rename"),
-                                       discard_const_p(char, "OO"),
-                                       py_olddn, py_newdn);
-
-       Py_DECREF(py_olddn);
-       Py_DECREF(py_newdn);
-
-       if (py_result == NULL) {
-               return LDB_ERR_PYTHON_EXCEPTION;
-       }
-
-       Py_DECREF(py_result);
-
-       return LDB_SUCCESS;
-}
-
-static int py_module_request(struct ldb_module *mod, struct ldb_request *req)
-{
-       PyObject *py_ldb = (PyObject *)mod->private_data;
-       PyObject *py_result;
-
-       py_result = PyObject_CallMethod(py_ldb, discard_const_p(char, "request"),
-                                       discard_const_p(char, ""));
-
-       Py_XDECREF(py_result);
-
-       return LDB_ERR_OPERATIONS_ERROR;
-}
-
-static int py_module_extended(struct ldb_module *mod, struct ldb_request *req)
-{
-       PyObject *py_ldb = (PyObject *)mod->private_data;
-       PyObject *py_result;
-
-       py_result = PyObject_CallMethod(py_ldb, discard_const_p(char, "extended"),
-                                       discard_const_p(char, ""));
-
-       Py_XDECREF(py_result);
-
-       return LDB_ERR_OPERATIONS_ERROR;
-}
-
-static int py_module_start_transaction(struct ldb_module *mod)
-{
-       PyObject *py_ldb = (PyObject *)mod->private_data;
-       PyObject *py_result;
-
-       py_result = PyObject_CallMethod(py_ldb, discard_const_p(char, "start_transaction"),
-                                       discard_const_p(char, ""));
-
-       if (py_result == NULL) {
-               return LDB_ERR_PYTHON_EXCEPTION;
-       }
-
-       Py_DECREF(py_result);
-
-       return LDB_SUCCESS;
-}
-
-static int py_module_end_transaction(struct ldb_module *mod)
-{
-       PyObject *py_ldb = (PyObject *)mod->private_data;
-       PyObject *py_result;
-
-       py_result = PyObject_CallMethod(py_ldb, discard_const_p(char, "end_transaction"),
-                                       discard_const_p(char, ""));
-
-       if (py_result == NULL) {
-               return LDB_ERR_PYTHON_EXCEPTION;
-       }
-
-       Py_DECREF(py_result);
-
-       return LDB_SUCCESS;
-}
-
-static int py_module_del_transaction(struct ldb_module *mod)
-{
-       PyObject *py_ldb = (PyObject *)mod->private_data;
-       PyObject *py_result;
-
-       py_result = PyObject_CallMethod(py_ldb, discard_const_p(char, "del_transaction"),
-                                       discard_const_p(char, ""));
-
-       if (py_result == NULL) {
-               return LDB_ERR_PYTHON_EXCEPTION;
-       }
-
-       Py_DECREF(py_result);
-
-       return LDB_SUCCESS;
-}
-
-static int py_module_destructor(struct ldb_module *mod)
-{
-       Py_CLEAR(mod->private_data);
-       return 0;
-}
-
-static int py_module_init(struct ldb_module *mod)
-{
-       PyObject *py_class = (PyObject *)mod->ops->private_data;
-       PyObject *py_result, *py_next, *py_ldb;
-
-       py_ldb = PyLdb_FromLdbContext(mod->ldb);
-
-       if (py_ldb == NULL)
-               return LDB_ERR_OPERATIONS_ERROR;
-
-       py_next = PyLdbModule_FromModule(mod->next);
-
-       if (py_next == NULL) {
-               Py_DECREF(py_ldb);
-               return LDB_ERR_OPERATIONS_ERROR;
-       }
-
-       py_result = PyObject_CallFunction(py_class, discard_const_p(char, "OO"),
-                                         py_ldb, py_next);
-
-       Py_DECREF(py_next);
-       Py_DECREF(py_ldb);
-
-       if (py_result == NULL) {
-               return LDB_ERR_PYTHON_EXCEPTION;
-       }
-
-       mod->private_data = py_result;
-
-       talloc_set_destructor(mod, py_module_destructor);
-
-       return ldb_next_init(mod);
-}
-
-static PyObject *py_register_module(PyObject *module, PyObject *args)
-{
-       int ret;
-       struct ldb_module_ops *ops;
-       PyObject *input;
-       PyObject *tmp = NULL;
-       const char *name = NULL;
-
-       if (!PyArg_ParseTuple(args, "O", &input))
-               return NULL;
-
-       ops = talloc_zero(NULL, struct ldb_module_ops);
-       if (ops == NULL) {
-               PyErr_NoMemory();
-               return NULL;
-       }
-
-       tmp = PyObject_GetAttrString(input, discard_const_p(char, "name"));
-       if (tmp == NULL) {
-               TALLOC_FREE(ops);
-               return NULL;
-       }
-       name = PyUnicode_AsUTF8(tmp);
-       if (name == NULL) {
-               Py_DECREF(tmp);
-               TALLOC_FREE(ops);
-               return NULL;
-       }
-
-       ops->name = talloc_strdup(ops, name);
-       Py_XDECREF(tmp);
-       if (ops->name == NULL) {
-               TALLOC_FREE(ops);
-               return PyErr_NoMemory();
-       }
-       Py_INCREF(input);
-       ops->private_data = input;
-       ops->init_context = py_module_init;
-       ops->search = py_module_search;
-       ops->add = py_module_add;
-       ops->modify = py_module_modify;
-       ops->del = py_module_del;
-       ops->rename = py_module_rename;
-       ops->request = py_module_request;
-       ops->extended = py_module_extended;
-       ops->start_transaction = py_module_start_transaction;
-       ops->end_transaction = py_module_end_transaction;
-       ops->del_transaction = py_module_del_transaction;
-
-       ret = ldb_register_module(ops);
-       if (ret != LDB_SUCCESS) {
-               Py_DECREF(input);
-               TALLOC_FREE(ops);
-       }
-
-       PyErr_LDB_ERROR_IS_ERR_RAISE_FREE(PyExc_LdbError, ret, NULL, ops);
-
-       Py_RETURN_NONE;
-}
-
 static PyObject *py_timestring(PyObject *module, PyObject *args)
 {
        /* most times "time_t" is a signed integer type with 32 or 64 bit:
@@ -4848,9 +4081,6 @@ static PyObject *py_binary_decode(PyObject *self, PyObject *args)
 }
 
 static PyMethodDef py_ldb_global_methods[] = {
-       { "register_module", py_register_module, METH_VARARGS, 
-               "S.register_module(module) -> None\n\n"
-               "Register a LDB module."},
        { "timestring", py_timestring, METH_VARARGS, 
                "S.timestring(int) -> string\n\n"
                "Generate a LDAP time string from a UNIX timestamp" },
@@ -4900,9 +4130,6 @@ static PyObject* module_init(void)
        if (PyType_Ready(&PyLdb) < 0)
                return NULL;
 
-       if (PyType_Ready(&PyLdbModule) < 0)
-               return NULL;
-
        if (PyType_Ready(&PyLdbTree) < 0)
                return NULL;
 
@@ -5006,7 +4233,6 @@ static PyObject* module_init(void)
 
        Py_INCREF(&PyLdb);
        Py_INCREF(&PyLdbDn);
-       Py_INCREF(&PyLdbModule);
        Py_INCREF(&PyLdbMessage);
        Py_INCREF(&PyLdbMessageElement);
        Py_INCREF(&PyLdbTree);
@@ -5017,7 +4243,6 @@ static PyObject* module_init(void)
        PyModule_AddObject(m, "Dn", (PyObject *)&PyLdbDn);
        PyModule_AddObject(m, "Message", (PyObject *)&PyLdbMessage);
        PyModule_AddObject(m, "MessageElement", (PyObject *)&PyLdbMessageElement);
-       PyModule_AddObject(m, "Module", (PyObject *)&PyLdbModule);
        PyModule_AddObject(m, "Tree", (PyObject *)&PyLdbTree);
        PyModule_AddObject(m, "Result", (PyObject *)&PyLdbResult);
        PyModule_AddObject(m, "Control", (PyObject *)&PyLdbControl);
index b4904d8f5703f2a31c4ce8d0d2bfc7eca6b6a2eb..6c8dfd1b51ab55ff123982820cba5bb80ccc8357 100644 (file)
@@ -75,13 +75,6 @@ typedef struct {
 } PyLdbMessageObject;
 #define pyldb_Message_AsMessage(pyobj) ((PyLdbMessageObject *)pyobj)->msg
 
-typedef struct {
-       PyObject_HEAD
-       TALLOC_CTX *mem_ctx;
-       struct ldb_module *mod;
-} PyLdbModuleObject;
-#define pyldb_Module_AsModule(pyobj) ((PyLdbModuleObject *)pyobj)->mod
-
 /*
  * NOTE: el (and so the return value of
  * pyldb_MessageElement_AsMessageElement()) may not be a valid talloc
index 77d848937ee39423605d54b280e2bd0ad2a199c7..e38f9dc37a163dd0889a9e67f1be32b1ce8150ed 100755 (executable)
@@ -132,23 +132,6 @@ class SimpleLdb(LdbBaseTest):
         x = ldb.Ldb()
         x.set_create_perms(0o600)
 
-    def test_modules_none(self):
-        x = ldb.Ldb()
-        self.assertEqual([], x.modules())
-
-    def test_modules_tdb(self):
-        x = ldb.Ldb(self.url(), flags=self.flags())
-        self.assertEqual("[<ldb module 'tdb'>]", repr(x.modules()))
-
-    def test_firstmodule_none(self):
-        x = ldb.Ldb()
-        self.assertEqual(x.firstmodule, None)
-
-    def test_firstmodule_tdb(self):
-        x = ldb.Ldb(self.url(), flags=self.flags())
-        mod = x.firstmodule
-        self.assertEqual(repr(mod), "<ldb module 'tdb'>")
-
     def test_search(self):
         l = ldb.Ldb(self.url(), flags=self.flags())
         self.assertEqual(len(l.search()), 0)
@@ -3380,47 +3363,6 @@ class MessageElementTests(TestCase):
         self.assertRaises(UnicodeDecodeError, el.text.__getitem__, 0)
 
 
-class ModuleTests(TestCase):
-
-    def setUp(self):
-        super(ModuleTests, self).setUp()
-        self.testdir = tempdir()
-        self.filename = os.path.join(self.testdir, "test.ldb")
-        self.ldb = ldb.Ldb(self.filename)
-
-    def tearDown(self):
-        shutil.rmtree(self.testdir)
-        super(ModuleTests, self).setUp()
-
-    def test_register_module(self):
-        class ExampleModule:
-            name = "example"
-        ldb.register_module(ExampleModule)
-
-    def test_use_module(self):
-        ops = []
-
-        class ExampleModule:
-            name = "bla"
-
-            def __init__(self, ldb, next):
-                ops.append("init")
-                self.next = next
-
-            def search(self, *args, **kwargs):
-                return self.next.search(*args, **kwargs)
-
-            def request(self, *args, **kwargs):
-                pass
-
-        ldb.register_module(ExampleModule)
-        l = ldb.Ldb(self.filename)
-        l.add({"dn": "@MODULES", "@LIST": "bla"})
-        self.assertEqual([], ops)
-        l = ldb.Ldb(self.filename)
-        self.assertEqual(["init"], ops)
-
-
 class LdbResultTests(LdbBaseTest):
 
     def setUp(self):
index faf858e45c510ec883e7ddc460665aeec77fcb28..6c01088e5f8adf11e78c25ff352fc7577e786c91 100644 (file)
@@ -154,10 +154,6 @@ class SegfaultTests(samba.tests.TestCase):
             pass
         str(m)
 
-    @segfault_detector
-    def test_ldb_register_module(self):
-        ldb.register_module('')
-
     @segfault_detector
     def test_messaging_deregister(self):
         messaging.deregister('s', 's', 's', False)