1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

pyldb: expose PyLdbDn_FromDn()

This is needed by the dsdb python interface

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Andrew Tridgell 2010-09-09 17:59:40 +10:00
parent c44bdbc01d
commit c95c3863df
2 changed files with 29 additions and 18 deletions

View File

@ -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);

View File

@ -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;
}