1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-28 01:58:17 +03:00

ldb:python bindings - some small cleanup & improvements in "py_ldb_add"

Also to make it similar to "py_ldb_delete".
This commit is contained in:
Matthias Dieter Wallnöfer 2010-06-18 22:08:58 +02:00
parent 2aeea4bb4d
commit ca34ffaaac

View File

@ -710,14 +710,19 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "O|O", &py_msg, &py_controls ))
return NULL;
ldb_ctx = PyLdb_AsLdbContext(self);
mem_ctx = talloc_new(NULL);
if (mem_ctx == NULL) {
PyErr_NoMemory();
return NULL;
}
ldb_ctx = PyLdb_AsLdbContext(self);
if (py_controls == Py_None) {
parsed_controls = NULL;
} else {
const char **controls = PyList_AsStringList(ldb_ctx, py_controls, "controls");
parsed_controls = ldb_parse_control_strings(ldb_ctx, ldb_ctx, controls);
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 (PyDict_Check(py_msg)) {
@ -770,13 +775,8 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args)
return NULL;
}
ret = ldb_build_add_req(&req, ldb_ctx, ldb_ctx,
msg,
parsed_controls,
NULL,
ldb_op_default_callback,
NULL);
ret = ldb_build_add_req(&req, ldb_ctx, mem_ctx, msg, parsed_controls,
NULL, ldb_op_default_callback, NULL);
if (ret != LDB_SUCCESS) {
PyErr_SetString(PyExc_TypeError, "failed to build request");
talloc_free(mem_ctx);
@ -788,9 +788,8 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args)
ret = ldb_transaction_start(ldb_ctx);
if (ret != LDB_SUCCESS) {
talloc_free(req);
talloc_free(mem_ctx);
PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, PyLdb_AsLdbContext(self));
PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, ldb_ctx);
}
ret = ldb_request(ldb_ctx, req);
@ -807,9 +806,9 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args)
ldb_asprintf_errstring(ldb_ctx, "%s (%d)", ldb_strerror(ret), ret);
}
}
talloc_free(req);
talloc_free(mem_ctx);
PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, PyLdb_AsLdbContext(self));
PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, ldb_ctx);
Py_RETURN_NONE;
}