1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00

s4-pydsdb: Use local memory context in py_dsdb_get_oid_from_attid()

This version reverts changes from commit b974966cc2
and is what Matthieu Patou had commited in d784ecec55
with added reference to the schema cache.

I think referencing schema here is the right thing to be done
as thus we garantee that schema cache will stay in memory
for the time our function is executed

Autobuild-User: Kamen Mazdrashki <kamenim@samba.org>
Autobuild-Date: Mon Dec 20 12:01:53 CET 2010 on sn-devel-104
This commit is contained in:
Kamen Mazdrashki 2010-12-20 11:39:26 +02:00
parent e1d3de3e17
commit 33a57db3a5

View File

@ -249,25 +249,37 @@ static PyObject *py_dsdb_get_oid_from_attid(PyObject *self, PyObject *args)
const char *oid;
PyObject *ret;
WERROR status;
TALLOC_CTX *mem_ctx;
if (!PyArg_ParseTuple(args, "Oi", &py_ldb, &attid))
return NULL;
PyErr_LDB_OR_RAISE(py_ldb, ldb);
schema = dsdb_get_schema(ldb, NULL);
mem_ctx = talloc_new(NULL);
if (!mem_ctx) {
PyErr_NoMemory();
return NULL;
}
schema = dsdb_get_schema(ldb, mem_ctx);
if (!schema) {
PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb \n");
talloc_free(mem_ctx);
return NULL;
}
status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attid,
NULL, &oid);
PyErr_WERROR_IS_ERR_RAISE(status);
mem_ctx, &oid);
if (!W_ERROR_IS_OK(status)) {
PyErr_SetWERROR(status);
talloc_free(mem_ctx);
return NULL;
}
ret = PyString_FromString(oid);
talloc_free(discard_const_p(char, oid));
talloc_free(mem_ctx);
return ret;
}