diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2010-04-04 01:48:35 +0200 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2010-04-06 13:12:43 +0200 |
commit | 099fc00b601fe7775f5fdb18d8473031b8a7ce27 (patch) | |
tree | 1e58cec0b405f809fb5c25dd21c460f5575d11b3 | |
parent | badc255748aa71f98c99c4c47343011286c8445d (diff) | |
download | samba-099fc00b601fe7775f5fdb18d8473031b8a7ce27.tar.gz samba-099fc00b601fe7775f5fdb18d8473031b8a7ce27.tar.bz2 samba-099fc00b601fe7775f5fdb18d8473031b8a7ce27.zip |
Add C-based Samba-specific subclass of Ldb.
-rw-r--r-- | source4/lib/ldb-samba/config.mk | 6 | ||||
-rw-r--r-- | source4/lib/ldb-samba/pyldb.c | 89 | ||||
-rw-r--r-- | source4/lib/ldb/pyldb.c | 12 | ||||
-rw-r--r-- | source4/param/pyparam.h | 2 | ||||
-rw-r--r-- | source4/scripting/python/pyglue.c | 24 | ||||
-rw-r--r-- | source4/scripting/python/samba/__init__.py | 8 |
6 files changed, 105 insertions, 36 deletions
diff --git a/source4/lib/ldb-samba/config.mk b/source4/lib/ldb-samba/config.mk index ceacf277e4..1bd1be40a8 100644 --- a/source4/lib/ldb-samba/config.mk +++ b/source4/lib/ldb-samba/config.mk @@ -9,3 +9,9 @@ PRIVATE_DEPENDENCIES = LIBSECURITY SAMDB_SCHEMA LIBNDR NDR_DRSBLOBS LDBSAMBA_OBJ_FILES = $(ldb_sambasrcdir)/ldif_handlers.o $(eval $(call proto_header_template,$(ldb_sambasrcdir)/ldif_handlers_proto.h,$(LDBSAMBA_OBJ_FILES:.o=.c))) + +[PYTHON::python_samba__ldb] +LIBRARY_REALNAME = samba/_ldb.$(SHLIBEXT) +PRIVATE_DEPENDENCIES = LDBSAMBA pyparam_util + +python_samba__ldb_OBJ_FILES = $(ldb_sambasrcdir)/pyldb.o diff --git a/source4/lib/ldb-samba/pyldb.c b/source4/lib/ldb-samba/pyldb.c new file mode 100644 index 0000000000..662bfbaa76 --- /dev/null +++ b/source4/lib/ldb-samba/pyldb.c @@ -0,0 +1,89 @@ +/* + Unix SMB/CIFS implementation. + + Python interface to ldb, Samba-specific functions + + Copyright (C) 2007-2010 Jelmer Vernooij <jelmer@samba.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include <Python.h> +#include "includes.h" +#include <ldb.h> +#include "lib/ldb/pyldb.h" +#include "param/pyparam.h" + +static PyObject *pyldb_module; +staticforward PyTypeObject PySambaLdb; + +static PyObject *py_ldb_set_loadparm(PyObject *self, PyObject *args) +{ + PyObject *py_lp_ctx; + struct loadparm_context *lp_ctx; + struct ldb_context *ldb; + + if (!PyArg_ParseTuple(args, "O", &py_lp_ctx)) + return NULL; + + lp_ctx = lp_from_py_object(py_lp_ctx); + if (lp_ctx == NULL) { + PyErr_SetString(PyExc_TypeError, "Expected loadparm object"); + return NULL; + } + + ldb = PyLdb_AsLdbContext(self); + + ldb_set_opaque(ldb, "loadparm", lp_ctx); + + 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" + "Set loadparm context to use when connecting." }, + { NULL }, +}; + +static PyTypeObject PySambaLdb = { + .tp_name = "samba.Ldb", + .tp_doc = "Connection to a LDB database.", + .tp_methods = py_samba_ldb_methods, + .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, +}; + + +void init_ldb(void) +{ + PyObject *m; + + pyldb_module = PyImport_ImportModule("ldb"); + if (pyldb_module == NULL) + return; + + PySambaLdb.tp_base = (PyTypeObject *)PyObject_GetAttrString(pyldb_module, "Ldb"); + if (PySambaLdb.tp_base == NULL) + return; + + if (PyType_Ready(&PySambaLdb) < 0) + return; + + m = Py_InitModule3("_ldb", NULL, "Samba-specific LDB python bindings"); + if (m == NULL) + return; + + Py_INCREF(&PySambaLdb); + PyModule_AddObject(m, "Ldb", (PyObject *)&PySambaLdb); +} diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index 285373219f..4ff56b4e2b 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -410,7 +410,7 @@ static void py_ldb_dn_dealloc(PyLdbDnObject *self) } PyTypeObject PyLdbDn = { - .tp_name = "Dn", + .tp_name = "ldb.Dn", .tp_methods = py_ldb_dn_methods, .tp_str = (reprfunc)py_ldb_dn_get_linearized, .tp_repr = (reprfunc)py_ldb_dn_repr, @@ -1380,7 +1380,7 @@ static void py_ldb_dealloc(PyLdbObject *self) } PyTypeObject PyLdb = { - .tp_name = "Ldb", + .tp_name = "ldb.Ldb", .tp_methods = py_ldb_methods, .tp_repr = (reprfunc)py_ldb_repr, .tp_new = py_ldb_new, @@ -1574,7 +1574,7 @@ static void py_ldb_module_dealloc(PyLdbModuleObject *self) } PyTypeObject PyLdbModule = { - .tp_name = "LdbModule", + .tp_name = "ldb.LdbModule", .tp_methods = py_ldb_module_methods, .tp_repr = (reprfunc)py_ldb_module_repr, .tp_str = (reprfunc)py_ldb_module_str, @@ -1851,7 +1851,7 @@ static void py_ldb_msg_element_dealloc(PyLdbMessageElementObject *self) } PyTypeObject PyLdbMessageElement = { - .tp_name = "MessageElement", + .tp_name = "ldb.MessageElement", .tp_basicsize = sizeof(PyLdbMessageElementObject), .tp_dealloc = (destructor)py_ldb_msg_element_dealloc, .tp_repr = (reprfunc)py_ldb_msg_element_repr, @@ -2105,7 +2105,7 @@ static void py_ldb_msg_dealloc(PyLdbMessageObject *self) } PyTypeObject PyLdbMessage = { - .tp_name = "Message", + .tp_name = "ldb.Message", .tp_methods = py_ldb_msg_methods, .tp_getset = py_ldb_msg_getset, .tp_as_mapping = &py_ldb_msg_mapping, @@ -2139,7 +2139,7 @@ static void py_ldb_tree_dealloc(PyLdbTreeObject *self) } PyTypeObject PyLdbTree = { - .tp_name = "Tree", + .tp_name = "ldb.Tree", .tp_basicsize = sizeof(PyLdbTreeObject), .tp_dealloc = (destructor)py_ldb_tree_dealloc, .tp_flags = Py_TPFLAGS_DEFAULT, diff --git a/source4/param/pyparam.h b/source4/param/pyparam.h index 48885c053b..1a06730f38 100644 --- a/source4/param/pyparam.h +++ b/source4/param/pyparam.h @@ -20,6 +20,8 @@ #ifndef _PYPARAM_H_ #define _PYPARAM_H_ +#include "param/param.h" + _PUBLIC_ struct loadparm_context *lp_from_py_object(PyObject *py_obj); _PUBLIC_ struct loadparm_context *py_default_loadparm_context(TALLOC_CTX *mem_ctx); diff --git a/source4/scripting/python/pyglue.c b/source4/scripting/python/pyglue.c index b75d7d3782..e4a20f8d19 100644 --- a/source4/scripting/python/pyglue.c +++ b/source4/scripting/python/pyglue.c @@ -159,27 +159,6 @@ static PyObject *py_ldb_set_credentials(PyObject *self, PyObject *args) Py_RETURN_NONE; } -static PyObject *py_ldb_set_loadparm(PyObject *self, PyObject *args) -{ - PyObject *py_lp_ctx, *py_ldb; - struct loadparm_context *lp_ctx; - struct ldb_context *ldb; - if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_lp_ctx)) - return NULL; - - PyErr_LDB_OR_RAISE(py_ldb, ldb); - - lp_ctx = lp_from_py_object(py_lp_ctx); - if (lp_ctx == NULL) { - PyErr_SetString(PyExc_TypeError, "Expected loadparm object"); - return NULL; - } - - ldb_set_opaque(ldb, "loadparm", lp_ctx); - - Py_RETURN_NONE; -} - static PyObject *py_ldb_set_utf8_casefold(PyObject *self, PyObject *args) { PyObject *py_ldb; @@ -542,9 +521,6 @@ static PyMethodDef py_misc_methods[] = { { "ldb_set_credentials", (PyCFunction)py_ldb_set_credentials, METH_VARARGS, "ldb_set_credentials(ldb, credentials)\n" "Set credentials to use when connecting." }, - { "ldb_set_loadparm", (PyCFunction)py_ldb_set_loadparm, METH_VARARGS, - "ldb_set_loadparm(ldb, session_info)\n" - "Set loadparm context to use when connecting." }, { "samdb_set_domain_sid", (PyCFunction)py_samdb_set_domain_sid, METH_VARARGS, "samdb_set_domain_sid(samdb, sid)\n" "Set SID of domain to use." }, diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py index cb2405a3f9..80c6df626a 100644 --- a/source4/scripting/python/samba/__init__.py +++ b/source4/scripting/python/samba/__init__.py @@ -44,10 +44,9 @@ else: import ldb import dsdb import glue +from samba._ldb import Ldb - - -class Ldb(ldb.Ldb): +class Ldb(Ldb): """Simple Samba-specific LDB subclass that takes care of setting up the modules dir, credentials pointers, etc. @@ -117,9 +116,6 @@ class Ldb(ldb.Ldb): def set_credentials(self, credentials): glue.ldb_set_credentials(self, credentials) - def set_loadparm(self, lp_ctx): - glue.ldb_set_loadparm(self, lp_ctx) - def set_create_perms(self, perms=0600): # we usually want Samba databases to be private. If we later find we # need one public, we will have to change this here |