From: Douglas Bagnall Date: Tue, 5 Mar 2024 23:57:15 +0000 (+0000) Subject: pyldb: py_ldb_init() uses py_ldb_connect() for connecting X-Git-Tag: tdb-1.4.11~1408 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ce132cea930a22c9468ecd9061e9cacace9ff0b;p=thirdparty%2Fsamba.git pyldb: py_ldb_init() uses py_ldb_connect() for connecting To avoid all the same logic, subtly different. Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index 5067f3436a0..86f96e4b305 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -1205,43 +1205,33 @@ static const char **PyList_AsStrList(TALLOC_CTX *mem_ctx, PyObject *list, return ret; } +static PyObject *py_ldb_connect(PyLdbObject *self, PyObject *args, PyObject *kwargs); + static int py_ldb_init(PyLdbObject *self, PyObject *args, PyObject *kwargs) { const char * const kwnames[] = { "url", "flags", "options", NULL }; char *url = NULL; - PyObject *py_options = Py_None; - const char **options; + PyObject *py_options = NULL; unsigned int flags = 0; - int ret; - struct ldb_context *ldb; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|zIO:Ldb.__init__", discard_const_p(char *, kwnames), - &url, &flags, &py_options)) + &url, &flags, &py_options)) { return -1; - - ldb = pyldb_Ldb_AS_LDBCONTEXT(self); - - if (py_options == Py_None) { - options = NULL; - } else { - options = PyList_AsStrList(ldb, py_options, "options"); - if (options == NULL) - return -1; } if (url != NULL) { - ret = ldb_connect(ldb, url, flags, options); - if (ret != LDB_SUCCESS) { - PyErr_SetLdbError(PyExc_LdbError, ret, ldb); - talloc_free(options); + /* py_ldb_connect returns py_None on success, NULL on error */ + PyObject *result = py_ldb_connect(self, args, kwargs); + if (result == NULL) { return -1; } + Py_DECREF(result); } else { + struct ldb_context *ldb = pyldb_Ldb_AS_LDBCONTEXT(self); ldb_set_flags(ldb, flags); } - talloc_free(options); return 0; }