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

s4-python: Move register_samba_handlers to PySambaLdb.

This commit is contained in:
Jelmer Vernooij 2010-04-04 02:07:46 +02:00
parent e9c3f2ef13
commit 55b98e9768
3 changed files with 44 additions and 27 deletions

View File

@ -29,8 +29,21 @@
#include "lib/ldb-samba/ldif_handlers.h"
static PyObject *pyldb_module;
static PyObject *py_ldb_error;
staticforward PyTypeObject PySambaLdb;
static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
{
if (ret == LDB_ERR_PYTHON_EXCEPTION)
return; /* Python exception should already be set, just keep that */
PyErr_SetObject(error,
Py_BuildValue(discard_const_p(char, "(i,s)"), ret,
ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx)));
}
static PyObject *py_ldb_set_loadparm(PyObject *self, PyObject *args)
{
PyObject *py_lp_ctx;
@ -82,6 +95,7 @@ static PyObject *py_ldb_set_opaque_integer(PyObject *self, PyObject *args)
int *old_val, *new_val;
char *py_opaque_name, *opaque_name_talloc;
struct ldb_context *ldb;
int ret;
TALLOC_CTX *tmp_ctx;
if (!PyArg_ParseTuple(args, "si", &py_opaque_name, &value))
@ -124,10 +138,11 @@ static PyObject *py_ldb_set_opaque_integer(PyObject *self, PyObject *args)
*new_val = value;
/* cache the domain_sid in the ldb */
if (ldb_set_opaque(ldb, opaque_name_talloc, new_val) != LDB_SUCCESS) {
ret = ldb_set_opaque(ldb, opaque_name_talloc, new_val);
if (ret != LDB_SUCCESS) {
talloc_free(tmp_ctx);
PyErr_SetString(PyExc_RuntimeError,
"Failed to set opaque integer into the ldb");
PyErr_SetLdbError(py_ldb_error, ret, ldb);
return NULL;
}
@ -138,7 +153,7 @@ static PyObject *py_ldb_set_opaque_integer(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
static PyObject *py_ldb_set_utf8_casefold(PyObject *self, PyObject *args)
static PyObject *py_ldb_set_utf8_casefold(PyObject *self)
{
struct ldb_context *ldb;
@ -149,19 +164,38 @@ static PyObject *py_ldb_set_utf8_casefold(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
static PyObject *py_ldb_register_samba_handlers(PyObject *self)
{
struct ldb_context *ldb;
int ret;
/* XXX: Perhaps call this from PySambaLdb's init function ? */
ldb = PyLdb_AsLdbContext(self);
ret = ldb_register_samba_handlers(ldb);
PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_error, ret, ldb);
Py_RETURN_NONE;
}
static PyMethodDef py_samba_ldb_methods[] = {
{ "set_loadparm", (PyCFunction)py_ldb_set_loadparm, METH_VARARGS,
"ldb_set_loadparm(ldb, session_info)\n"
"ldb_set_loadparm(session_info)\n"
"Set loadparm context to use when connecting." },
{ "set_credentials", (PyCFunction)py_ldb_set_credentials, METH_VARARGS,
"ldb_set_credentials(ldb, credentials)\n"
"ldb_set_credentials(credentials)\n"
"Set credentials to use when connecting." },
{ "set_opaque_integer", (PyCFunction)py_ldb_set_opaque_integer,
METH_VARARGS, NULL },
{ "set_utf8_casefold", (PyCFunction)py_ldb_set_utf8_casefold,
METH_NOARGS,
"ldb_set_utf8_casefold(ldb)\n"
"ldb_set_utf8_casefold()\n"
"Set the right Samba casefolding function for UTF8 charset." },
{ "register_samba_handlers", (PyCFunction)py_ldb_register_samba_handlers,
METH_NOARGS,
"register_samba_handlers()\n"
"Register Samba-specific LDB modules and schemas." },
{ NULL },
};
@ -185,6 +219,8 @@ void init_ldb(void)
if (PySambaLdb.tp_base == NULL)
return;
py_ldb_error = PyObject_GetAttrString(pyldb_module, "LdbError");
if (PyType_Ready(&PySambaLdb) < 0)
return;

View File

@ -184,22 +184,6 @@ static PyObject *py_samdb_get_domain_sid(PyLdbObject *self, PyObject *args)
return ret;
}
static PyObject *py_ldb_register_samba_handlers(PyObject *self, PyObject *args)
{
PyObject *py_ldb;
struct ldb_context *ldb;
int ret;
if (!PyArg_ParseTuple(args, "O", &py_ldb))
return NULL;
PyErr_LDB_OR_RAISE(py_ldb, ldb);
ret = ldb_register_samba_handlers(ldb);
PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
Py_RETURN_NONE;
}
static PyObject *py_dsdb_set_ntds_invocation_id(PyObject *self, PyObject *args)
{
PyObject *py_ldb, *py_guid;
@ -488,9 +472,6 @@ static PyMethodDef py_misc_methods[] = {
{ "samdb_get_domain_sid", (PyCFunction)py_samdb_get_domain_sid, METH_VARARGS,
"samdb_get_domain_sid(samdb)\n"
"Get SID of domain in use." },
{ "ldb_register_samba_handlers", (PyCFunction)py_ldb_register_samba_handlers, METH_VARARGS,
"ldb_register_samba_handlers(ldb)\n"
"Register Samba-specific LDB modules and schemas." },
{ "dsdb_set_ntds_invocation_id", (PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
NULL },
{ "dsdb_set_global_schema", (PyCFunction)py_dsdb_set_global_schema, METH_VARARGS,

View File

@ -90,7 +90,7 @@ class Ldb(_Ldb):
# This must be done before we load the schema, as these handlers for
# objectSid and objectGUID etc must take precedence over the 'binary
# attribute' declaration in the schema
glue.ldb_register_samba_handlers(self)
self.register_samba_handlers()
# TODO set debug
def msg(l,text):