provision/pyldb: Avoid linking in static python ldb module.
authorJelmer Vernooij <jelmer@samba.org>
Sun, 20 Dec 2009 17:31:27 +0000 (18:31 +0100)
committerJelmer Vernooij <jelmer@ganieda.vernstok.nl>
Mon, 21 Dec 2009 22:40:12 +0000 (23:40 +0100)
source4/lib/ldb/pyldb.c
source4/lib/ldb/pyldb.h
source4/param/config.mk
source4/param/provision.c

index 0ba69e1c4845cf2a8488d1d778fa86c5f6b7204a..a19768d41b6e56c897440ada037ba3edf32b6b44 100644 (file)
@@ -61,6 +61,8 @@ PyAPI_DATA(PyTypeObject) PyLdb;
 PyAPI_DATA(PyTypeObject) PyLdbMessageElement;
 PyAPI_DATA(PyTypeObject) PyLdbTree;
 
+static PyObject *PyLdb_FromLdbContext(struct ldb_context *ldb_ctx);
+
 static PyObject *PyObject_FromLdbValue(struct ldb_context *ldb_ctx, 
                                                           struct ldb_message_element *el, 
                                                           struct ldb_val *val)
@@ -1357,7 +1359,7 @@ static PySequenceMethods py_ldb_seq = {
        .sq_contains = (objobjproc)py_ldb_contains,
 };
 
-PyObject *PyLdb_FromLdbContext(struct ldb_context *ldb_ctx)
+static PyObject *PyLdb_FromLdbContext(struct ldb_context *ldb_ctx)
 {
        PyLdbObject *ret;
 
index a0954158bd63b2b1d8189be372231a0edbe651ab..289159c5b3f49f4bd50d90fe2279b69ffcf7d4ee 100644 (file)
@@ -35,7 +35,6 @@ typedef struct {
        TALLOC_CTX *mem_ctx;
 } PyLdbObject;
 
-PyObject *PyLdb_FromLdbContext(struct ldb_context *ldb_ctx);
 #define PyLdb_AsLdbContext(pyobj) ((PyLdbObject *)pyobj)->ldb_ctx
 #define PyLdb_Check(ob) PyObject_TypeCheck(ob, &PyLdb)
 
index 6e5290b64d96aaf77eaa3c444fd37e3d77079a7e..02bbdd5677712dd8a7a7c20d1db28dfb6c13eb05 100644 (file)
@@ -13,7 +13,7 @@ PUBLIC_HEADERS += param/param.h
 PC_FILES += $(paramsrcdir)/samba-hostconfig.pc
 
 [SUBSYSTEM::PROVISION]
-PRIVATE_DEPENDENCIES = LIBPYTHON pyldb pyparam_util
+PRIVATE_DEPENDENCIES = LIBPYTHON pyparam_util
 
 PROVISION_OBJ_FILES = $(paramsrcdir)/provision.o $(param_OBJ_FILES)
 
index 8c6e1c0f684b61f6ed89713f9bf2e0c7559462df..7bd10ca522cd0efc18adc4a5053660aa3a2aff3b 100644 (file)
@@ -52,6 +52,34 @@ static PyObject *schema_module(void)
        return PyImport_Import(name);
 }
 
+static PyObject *ldb_module(void)
+{
+       PyObject *name = PyString_FromString("ldb");
+       if (name == NULL)
+               return NULL;
+       return PyImport_Import(name);
+}
+
+static PyObject *PyLdb_FromLdbContext(struct ldb_context *ldb_ctx)
+{
+       PyLdbObject *ret;
+       PyObject *ldb_mod = ldb_module();
+       PyTypeObject *ldb_ctx_type;
+       if (ldb_mod == NULL)
+               return NULL;
+
+       ldb_ctx_type = PyObject_GetAttrString(ldb_mod, "Ldb");
+
+       ret = (PyLdbObject *)ldb_ctx_type->tp_alloc(ldb_ctx_type, 0);
+       if (ret == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+       ret->mem_ctx = talloc_new(NULL);
+       ret->ldb_ctx = talloc_reference(ret->mem_ctx, ldb_ctx);
+       return (PyObject *)ret;
+}
+
 NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
                        struct provision_settings *settings, 
                        struct provision_result *result)
@@ -167,8 +195,6 @@ NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
        return NT_STATUS_OK;
 }
 
-extern void initldb(void);
-
 static PyObject *py_dom_sid_FromSid(struct dom_sid *sid)
 {
        PyObject *mod_security, *dom_sid_Type;
@@ -220,7 +246,6 @@ NTSTATUS provision_store_self_join(TALLOC_CTX *mem_ctx, struct loadparm_context
        py_load_samba_modules();
        Py_Initialize();
        py_update_path("bin"); /* FIXME: Can't assume this is always the case */
-       initldb();
        provision_mod = provision_module();
 
        if (provision_mod == NULL) {