diff options
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/ldb/pyldb.c | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index f1b73a96fb..b60f4fc3ee 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -898,18 +898,33 @@ static PyObject *py_ldb_rename(PyLdbObject *self, PyObject *args) int ret; struct ldb_context *ldb; TALLOC_CTX *mem_ctx; + PyObject *py_controls = Py_None; + struct ldb_control **parsed_controls; + struct ldb_context *ldb_ctx; + struct ldb_request *req; - if (!PyArg_ParseTuple(args, "OO", &py_dn1, &py_dn2)) + ldb_ctx = PyLdb_AsLdbContext(self); + + if (!PyArg_ParseTuple(args, "OO|O", &py_dn1, &py_dn2, &py_controls)) return NULL; + mem_ctx = talloc_new(NULL); if (mem_ctx == NULL) { PyErr_NoMemory(); return NULL; } - ldb = PyLdb_AsLdbContext(self); + if (py_controls == Py_None) { + parsed_controls = NULL; + } else { + const char **controls = PyList_AsStringList(mem_ctx, py_controls, "controls"); + parsed_controls = ldb_parse_control_strings(ldb_ctx, mem_ctx, controls); + talloc_free(controls); + } + + if (!PyObject_AsDn(mem_ctx, py_dn1, ldb, &dn1)) { talloc_free(mem_ctx); return NULL; @@ -920,9 +935,40 @@ static PyObject *py_ldb_rename(PyLdbObject *self, PyObject *args) return NULL; } - ret = ldb_rename(ldb, dn1, dn2); + ret = ldb_build_rename_req(&req, ldb_ctx, mem_ctx, dn1, dn2, parsed_controls, + NULL, ldb_op_default_callback, NULL); + if (ret != LDB_SUCCESS) { + PyErr_SetString(PyExc_TypeError, "failed to build request"); + talloc_free(mem_ctx); + return NULL; + } + + /* do request and autostart a transaction */ + /* Then let's LDB handle the message error in case of pb as they are meaningful */ + + ret = ldb_transaction_start(ldb_ctx); + if (ret != LDB_SUCCESS) { + talloc_free(mem_ctx); + PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, ldb_ctx); + } + + ret = ldb_request(ldb_ctx, req); + if (ret == LDB_SUCCESS) { + ret = ldb_wait(req->handle, LDB_WAIT_ALL); + } + + if (ret == LDB_SUCCESS) { + ret = ldb_transaction_commit(ldb_ctx); + } else { + ldb_transaction_cancel(ldb_ctx); + if (ldb_ctx->err_string == NULL) { + /* no error string was setup by the backend */ + ldb_asprintf_errstring(ldb_ctx, "%s (%d)", ldb_strerror(ret), ret); + } + } + talloc_free(mem_ctx); - PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, ldb); + PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, ldb_ctx); Py_RETURN_NONE; } |