diff options
Diffstat (limited to 'source4/lib/ldb/pyldb_util.c')
-rw-r--r-- | source4/lib/ldb/pyldb_util.c | 29 |
1 files changed, 29 insertions, 0 deletions
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; +} |