summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/lib/ldb/pyldb_util.c81
-rw-r--r--source4/lib/ldb/wscript11
2 files changed, 88 insertions, 4 deletions
diff --git a/source4/lib/ldb/pyldb_util.c b/source4/lib/ldb/pyldb_util.c
new file mode 100644
index 0000000000..fb06946161
--- /dev/null
+++ b/source4/lib/ldb/pyldb_util.c
@@ -0,0 +1,81 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ Python interface to ldb - utility functions.
+
+ Copyright (C) 2007-2010 Jelmer Vernooij <jelmer@samba.org>
+
+ ** NOTE! The following LGPL license applies to the ldb
+ ** library. This does NOT imply that all of Samba is released
+ ** under the LGPL
+
+ 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 "replace.h"
+#include "pyldb.h"
+#include <ldb.h>
+
+static PyObject *ldb_module = NULL;
+
+/* There's no Py_ssize_t in 2.4, apparently */
+#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5
+typedef int Py_ssize_t;
+typedef inquiry lenfunc;
+typedef intargfunc ssizeargfunc;
+#endif
+
+#ifndef Py_RETURN_NONE
+#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
+#endif
+
+/**
+ * Obtain a ldb DN from a Python object.
+ *
+ * @param mem_ctx Memory context
+ * @param object Python object
+ * @param ldb_ctx LDB context
+ * @return Whether or not the conversion succeeded
+ */
+bool PyObject_AsDn(TALLOC_CTX *mem_ctx, PyObject *object,
+ struct ldb_context *ldb_ctx, struct ldb_dn **dn)
+{
+ struct ldb_dn *odn;
+ PyObject *PyLdb_Dn_Type;
+
+ if (ldb_ctx != NULL && PyString_Check(object)) {
+ odn = ldb_dn_new(mem_ctx, ldb_ctx, PyString_AsString(object));
+ *dn = odn;
+ return true;
+ }
+
+ if (ldb_module == NULL) {
+ ldb_module = PyImport_ImportModule("ldb");
+ if (ldb_module == NULL)
+ return false;
+ }
+
+ PyLdb_Dn_Type = PyObject_GetAttrString(ldb_module, "Dn");
+ if (PyLdb_Dn_Type == NULL)
+ return false;
+
+ if (PyObject_TypeCheck(object, PyLdb_Dn_Type)) {
+ *dn = PyLdbDn_AsDn(object);
+ return true;
+ }
+
+ PyErr_SetString(PyExc_TypeError, "Expected DN");
+ return false;
+}
diff --git a/source4/lib/ldb/wscript b/source4/lib/ldb/wscript
index a1eca78268..3f76bebce8 100644
--- a/source4/lib/ldb/wscript
+++ b/source4/lib/ldb/wscript
@@ -150,17 +150,20 @@ def build(bld):
bld.env.PACKAGE_VERSION = VERSION
bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
- ldb_deps = 'tevent LIBLDB'
if s4_build:
abi_file='ABI/ldb-samba4-%s.sigs' % VERSION
else:
abi_file='ABI/ldb-%s.sigs' % VERSION
+ bld.SAMBA_PYTHON('pyldb_util',
+ deps='ldb LIBPYTHON',
+ source='pyldb_util.c')
+
if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
bld.SAMBA_LIBRARY('ldb',
COMMON_SRC + ' ' + LDB_MAP_SRC,
- deps=ldb_deps,
+ deps='tevent LIBLDB',
includes='include',
public_headers='include/ldb.h include/ldb_errors.h '\
'include/ldb_module.h',
@@ -172,13 +175,13 @@ def build(bld):
is_bundled=not bld.env.standalone_ldb)
bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
- deps='ldb',
+ deps='ldb pyldb_util',
realname='ldb.so')
extra_cmdline_deps = ''
if s4_build:
extra_cmdline_deps += ' LDBSAMBA POPT_SAMBA POPT_CREDENTIALS ' \
- 'LIBCMDLINE_CREDENTIALS gensec'
+ 'LIBCMDLINE_CREDENTIALS gensec'
bld.SAMBA_SUBSYSTEM('LIBLDB_CMDLINE',
'tools/ldbutil.c tools/cmdline.c',