[SCM] Samba Shared Repository - branch master updated
Jelmer Vernooij
jelmer at samba.org
Tue Apr 6 05:13:02 MDT 2010
The branch, master has been updated
via 449bdf3... s4-python: Move set_session_info to PySambaLdb.
via 55b98e9... s4-python: Move register_samba_handlers to PySambaLdb.
via e9c3f2e... s4-python: Move ldb_set_utf8_casefold to pyldb-samba.
via ae97613... s4-python: Move set_opaque_integer to pyldb.
via b72a5c0... Move glue.set_credentials hack to samba.Ldb.
via 099fc00... Add C-based Samba-specific subclass of Ldb.
from badc255... s4-build: remove any 'makefile' that may have been left by the waf build
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 449bdf35432230b060387856637759e2fe7022d6
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Apr 4 02:20:52 2010 +0200
s4-python: Move set_session_info to PySambaLdb.
commit 55b98e9768cb2a1ae4b9cc83e3d5f33b51b22e8f
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Apr 4 02:07:46 2010 +0200
s4-python: Move register_samba_handlers to PySambaLdb.
commit e9c3f2ef13f62eb583bd7c5dfb6b94a0a8a0fc4f
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Apr 4 02:01:47 2010 +0200
s4-python: Move ldb_set_utf8_casefold to pyldb-samba.
commit ae9761349904ac9c4c2745018903d8c2fcc2abf1
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Apr 4 01:54:57 2010 +0200
s4-python: Move set_opaque_integer to pyldb.
commit b72a5c033670a84423d1099aedbcfa5047ac47e6
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Apr 4 01:51:04 2010 +0200
Move glue.set_credentials hack to samba.Ldb.
commit 099fc00b601fe7775f5fdb18d8473031b8a7ce27
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Apr 4 01:48:35 2010 +0200
Add C-based Samba-specific subclass of Ldb.
-----------------------------------------------------------------------
Summary of changes:
source4/auth/pyauth.c | 3 +-
source4/auth/pyauth.h | 1 -
source4/dsdb/pydsdb.c | 66 -------
source4/lib/ldb-samba/config.mk | 6 +
source4/lib/ldb-samba/pyldb.c | 271 +++++++++++++++++++++++++++
source4/lib/ldb/pyldb.c | 12 +-
source4/lib/ldb/tests/python/deletetest.py | 1 -
source4/param/pyparam.h | 2 +
source4/scripting/python/pyglue.c | 109 -----------
source4/scripting/python/samba/__init__.py | 26 +---
source4/scripting/python/samba/provision.py | 8 +-
11 files changed, 295 insertions(+), 210 deletions(-)
create mode 100644 source4/lib/ldb-samba/pyldb.c
Changeset truncated at 500 lines:
diff --git a/source4/auth/pyauth.c b/source4/auth/pyauth.c
index 865609e..f81b449 100644
--- a/source4/auth/pyauth.c
+++ b/source4/auth/pyauth.c
@@ -107,7 +107,8 @@ void initauth(void)
if (PyType_Ready(&PyAuthSession) < 0)
return;
- m = Py_InitModule3("auth", py_auth_methods, "Authentication and authorization support.");
+ m = Py_InitModule3("auth", py_auth_methods,
+ "Authentication and authorization support.");
if (m == NULL)
return;
diff --git a/source4/auth/pyauth.h b/source4/auth/pyauth.h
index f3c9cea..2d0379e 100644
--- a/source4/auth/pyauth.h
+++ b/source4/auth/pyauth.h
@@ -23,7 +23,6 @@
#include "lib/talloc/pytalloc.h"
#include "auth/session.h"
-PyAPI_DATA(PyTypeObject) PyAuthSession;
#define PyAuthSession_AsSession(obj) py_talloc_get_type(obj, struct auth_session_info)
#define PyAuthSession_Check(obj) PyObject_TypeCheck(obj, &PyAuthSession)
struct auth_session_info *PyObject_AsSession(PyObject *obj);
diff --git a/source4/dsdb/pydsdb.c b/source4/dsdb/pydsdb.c
index 6e3e50a..ac9b93c 100644
--- a/source4/dsdb/pydsdb.c
+++ b/source4/dsdb/pydsdb.c
@@ -57,70 +57,6 @@ static PyObject *py_samdb_server_site_name(PyObject *self, PyObject *args)
return result;
}
-/* XXX: This function really should be in pyldb.c */
-static PyObject *py_dsdb_set_opaque_integer(PyObject *self, PyObject *args)
-{
- PyObject *py_ldb;
- int value;
- int *old_val, *new_val;
- char *py_opaque_name, *opaque_name_talloc;
- struct ldb_context *ldb;
- TALLOC_CTX *tmp_ctx;
-
- if (!PyArg_ParseTuple(args, "Osi", &py_ldb, &py_opaque_name, &value))
- return NULL;
-
- PyErr_LDB_OR_RAISE(py_ldb, ldb);
-
- /* see if we have a cached copy */
- old_val = (int *)ldb_get_opaque(ldb, py_opaque_name);
- /* XXX: We shouldn't just blindly assume that the value that is
- * already present has the size of an int and is not shared
- * with other code that may rely on it not changing.
- * JRV 20100403 */
-
- if (old_val) {
- *old_val = value;
- Py_RETURN_NONE;
- }
-
- tmp_ctx = talloc_new(ldb);
- if (tmp_ctx == NULL) {
- PyErr_NoMemory();
- return NULL;
- }
-
- new_val = talloc(tmp_ctx, int);
- if (new_val == NULL) {
- talloc_free(tmp_ctx);
- PyErr_NoMemory();
- return NULL;
- }
-
- opaque_name_talloc = talloc_strdup(tmp_ctx, py_opaque_name);
- if (opaque_name_talloc == NULL) {
- talloc_free(tmp_ctx);
- PyErr_NoMemory();
- return NULL;
- }
-
- *new_val = value;
-
- /* cache the domain_sid in the ldb */
- if (ldb_set_opaque(ldb, opaque_name_talloc, new_val) != LDB_SUCCESS) {
- talloc_free(tmp_ctx);
- PyErr_SetString(PyExc_RuntimeError,
- "Failed to set opaque integer into the ldb");
- return NULL;
- }
-
- talloc_steal(ldb, new_val);
- talloc_steal(ldb, opaque_name_talloc);
- talloc_free(tmp_ctx);
-
- Py_RETURN_NONE;
-}
-
static PyObject *py_dsdb_convert_schema_to_openldap(PyObject *self,
PyObject *args)
{
@@ -150,8 +86,6 @@ static PyObject *py_dsdb_convert_schema_to_openldap(PyObject *self,
static PyMethodDef py_dsdb_methods[] = {
{ "samdb_server_site_name", (PyCFunction)py_samdb_server_site_name,
METH_VARARGS, "Get the server site name as a string"},
- { "dsdb_set_opaque_integer", (PyCFunction)py_dsdb_set_opaque_integer,
- METH_VARARGS, NULL },
{ "dsdb_convert_schema_to_openldap",
(PyCFunction)py_dsdb_convert_schema_to_openldap, METH_VARARGS,
"dsdb_convert_schema_to_openldap(ldb, target_str, mapping) -> str\n"
diff --git a/source4/lib/ldb-samba/config.mk b/source4/lib/ldb-samba/config.mk
index ceacf27..1bd1be4 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 0000000..084afb7
--- /dev/null
+++ b/source4/lib/ldb-samba/pyldb.c
@@ -0,0 +1,271 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ Python interface to ldb, Samba-specific functions
+
+ Copyright (C) 2007-2010 Jelmer Vernooij <jelmer at 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"
+#include "auth/credentials/pycredentials.h"
+#include "ldb_wrap.h"
+#include "lib/ldb-samba/ldif_handlers.h"
+#include "auth/pyauth.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;
+ 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 PyObject *py_ldb_set_credentials(PyObject *self, PyObject *args)
+{
+ PyObject *py_creds;
+ struct cli_credentials *creds;
+ struct ldb_context *ldb;
+
+ if (!PyArg_ParseTuple(args, "O", &py_creds))
+ return NULL;
+
+ creds = cli_credentials_from_py_object(py_creds);
+ if (creds == NULL) {
+ PyErr_SetString(PyExc_TypeError, "Expected credentials object");
+ return NULL;
+ }
+
+ ldb = PyLdb_AsLdbContext(self);
+
+ ldb_set_opaque(ldb, "credentials", creds);
+
+ Py_RETURN_NONE;
+}
+
+/* XXX: This function really should be in libldb's pyldb.c */
+static PyObject *py_ldb_set_opaque_integer(PyObject *self, PyObject *args)
+{
+ int value;
+ 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))
+ return NULL;
+
+ ldb = PyLdb_AsLdbContext(self);
+
+ /* see if we have a cached copy */
+ old_val = (int *)ldb_get_opaque(ldb, py_opaque_name);
+ /* XXX: We shouldn't just blindly assume that the value that is
+ * already present has the size of an int and is not shared
+ * with other code that may rely on it not changing.
+ * JRV 20100403 */
+
+ if (old_val) {
+ *old_val = value;
+ Py_RETURN_NONE;
+ }
+
+ tmp_ctx = talloc_new(ldb);
+ if (tmp_ctx == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ new_val = talloc(tmp_ctx, int);
+ if (new_val == NULL) {
+ talloc_free(tmp_ctx);
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ opaque_name_talloc = talloc_strdup(tmp_ctx, py_opaque_name);
+ if (opaque_name_talloc == NULL) {
+ talloc_free(tmp_ctx);
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ *new_val = value;
+
+ /* cache the domain_sid in the ldb */
+ ret = ldb_set_opaque(ldb, opaque_name_talloc, new_val);
+
+ if (ret != LDB_SUCCESS) {
+ talloc_free(tmp_ctx);
+ PyErr_SetLdbError(py_ldb_error, ret, ldb);
+ return NULL;
+ }
+
+ talloc_steal(ldb, new_val);
+ talloc_steal(ldb, opaque_name_talloc);
+ talloc_free(tmp_ctx);
+
+ Py_RETURN_NONE;
+}
+
+static PyObject *py_ldb_set_utf8_casefold(PyObject *self)
+{
+ struct ldb_context *ldb;
+
+ ldb = PyLdb_AsLdbContext(self);
+
+ ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
+
+ Py_RETURN_NONE;
+}
+
+static PyObject *py_ldb_set_session_info(PyObject *self, PyObject *args)
+{
+ PyObject *py_session_info;
+ struct auth_session_info *info;
+ struct ldb_context *ldb;
+ PyObject *mod_samba_auth;
+ PyObject *PyAuthSession_Type;
+ bool ret;
+
+ mod_samba_auth = PyImport_ImportModule("samba.auth");
+ if (mod_samba_auth == NULL)
+ return NULL;
+
+ PyAuthSession_Type = PyObject_GetAttrString(mod_samba_auth, "AuthSession");
+ if (PyAuthSession_Type == NULL)
+ return NULL;
+
+ ret = PyArg_ParseTuple(args, "O!", PyAuthSession_Type, &py_session_info);
+
+ Py_DECREF(PyAuthSession_Type);
+ Py_DECREF(mod_samba_auth);
+
+ if (!ret)
+ return NULL;
+
+ ldb = PyLdb_AsLdbContext(self);
+
+ info = PyAuthSession_AsSession(py_session_info);
+
+ ldb_set_opaque(ldb, "sessionInfo", info);
+
+ 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(session_info)\n"
+ "Set loadparm context to use when connecting." },
+ { "set_credentials", (PyCFunction)py_ldb_set_credentials, METH_VARARGS,
+ "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()\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." },
+ { "set_session_info", (PyCFunction)py_ldb_set_session_info, METH_VARARGS,
+ "set_session_info(session_info)\n"
+ "Set session info 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;
+
+ py_ldb_error = PyObject_GetAttrString(pyldb_module, "LdbError");
+
+ 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 2853732..4ff56b4 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/lib/ldb/tests/python/deletetest.py b/source4/lib/ldb/tests/python/deletetest.py
index eff92c5..55f34fa 100755
--- a/source4/lib/ldb/tests/python/deletetest.py
+++ b/source4/lib/ldb/tests/python/deletetest.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-import getopt
import optparse
import sys
import os
diff --git a/source4/param/pyparam.h b/source4/param/pyparam.h
index 48885c0..1a06730 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 b75d7d3..8639958 100644
--- a/source4/scripting/python/pyglue.c
+++ b/source4/scripting/python/pyglue.c
@@ -117,84 +117,6 @@ static PyObject *py_set_debug_level(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
-static PyObject *py_ldb_set_session_info(PyObject *self, PyObject *args)
-{
- PyObject *py_session_info, *py_ldb;
- struct auth_session_info *info;
- struct ldb_context *ldb;
- if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_session_info))
- return NULL;
-
--
Samba Shared Repository
More information about the samba-cvs
mailing list