]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pyldb: py_ldb_init() uses py_ldb_connect() for connecting
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Tue, 5 Mar 2024 23:57:15 +0000 (23:57 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 20 Mar 2024 23:42:34 +0000 (23:42 +0000)
To avoid all the same logic, subtly different.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/pyldb.c

index 5067f3436a0a03fad2242364db1fd2341306337b..86f96e4b305ac997d8264b14f75fd5d5cfdafe55 100644 (file)
@@ -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;
 }