summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/ldb/pyldb.c18
-rw-r--r--source4/lib/ldb/pyldb_util.c29
2 files changed, 29 insertions, 18 deletions
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index b60f4fc3ee..57407ba0b6 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -357,24 +357,6 @@ static PyObject *py_ldb_dn_new(PyTypeObject *type, PyObject *args, PyObject *kwa
return (PyObject *)py_ret;
}
-PyObject *PyLdbDn_FromDn(struct ldb_dn *dn)
-{
- PyLdbDnObject *py_ret;
-
- if (dn == NULL) {
- Py_RETURN_NONE;
- }
-
- py_ret = (PyLdbDnObject *)PyLdbDn.tp_alloc(&PyLdbDn, 0);
- if (py_ret == NULL) {
- PyErr_NoMemory();
- return NULL;
- }
- py_ret->mem_ctx = talloc_new(NULL);
- py_ret->dn = talloc_reference(py_ret->mem_ctx, dn);
- return (PyObject *)py_ret;
-}
-
static void py_ldb_dn_dealloc(PyLdbDnObject *self)
{
talloc_free(self->mem_ctx);
diff --git a/source4/lib/ldb/pyldb_util.c b/source4/lib/ldb/pyldb_util.c
index 41bcb55bd1..170c291698 100644
--- a/source4/lib/ldb/pyldb_util.c
+++ b/source4/lib/ldb/pyldb_util.c
@@ -79,3 +79,32 @@ bool PyObject_AsDn(TALLOC_CTX *mem_ctx, PyObject *object,
PyErr_SetString(PyExc_TypeError, "Expected DN");
return false;
}
+
+PyObject *PyLdbDn_FromDn(struct ldb_dn *dn)
+{
+ PyLdbDnObject *py_ret;
+ PyTypeObject *PyLdb_Dn_Type;
+
+ if (dn == NULL) {
+ Py_RETURN_NONE;
+ }
+
+ if (ldb_module == NULL) {
+ ldb_module = PyImport_ImportModule("ldb");
+ if (ldb_module == NULL)
+ return NULL;
+ }
+
+ PyLdb_Dn_Type = (PyTypeObject *)PyObject_GetAttrString(ldb_module, "Dn");
+ if (PyLdb_Dn_Type == NULL)
+ return NULL;
+
+ py_ret = (PyLdbDnObject *)PyLdb_Dn_Type->tp_alloc(PyLdb_Dn_Type, 0);
+ if (py_ret == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ py_ret->mem_ctx = talloc_new(NULL);
+ py_ret->dn = talloc_reference(py_ret->mem_ctx, dn);
+ return (PyObject *)py_ret;
+}