summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
Diffstat (limited to 'source4/scripting')
-rw-r--r--source4/scripting/python/misc.i14
-rw-r--r--source4/scripting/python/misc.py1
-rw-r--r--source4/scripting/python/misc_wrap.c57
-rw-r--r--source4/scripting/python/samba/__init__.py31
4 files changed, 96 insertions, 7 deletions
diff --git a/source4/scripting/python/misc.i b/source4/scripting/python/misc.i
index 3d886a25bc..b2a7ad8ee8 100644
--- a/source4/scripting/python/misc.i
+++ b/source4/scripting/python/misc.i
@@ -21,6 +21,7 @@
%{
#include "includes.h"
#include "ldb.h"
+#include "param/param.h"
%}
%import "stdint.i"
@@ -28,6 +29,7 @@
%import "../../lib/talloc/talloc.i"
%import "../../lib/ldb/ldb.i"
%import "../../auth/credentials/credentials.i"
+%import "../../param/param.i"
%rename(random_password) generate_random_str;
char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len);
@@ -37,4 +39,16 @@ void ldb_set_credentials(struct ldb_context *ldb, struct cli_credentials *creds)
{
ldb_set_opaque(ldb, "credentials", creds);
}
+
+#if 0 /* Fails to link.. */
+void ldb_set_session_info(struct ldb_context *ldb, struct auth_session_info *session_info)
+{
+ ldb_set_opaque(ldb, "sessionInfo", session_info);
+}
+#endif
+
+void ldb_set_loadparm(struct ldb_context *ldb, struct loadparm_context *lp_ctx)
+{
+ ldb_set_opaque(ldb, "loadparm", lp_ctx);
+}
%}
diff --git a/source4/scripting/python/misc.py b/source4/scripting/python/misc.py
index 94b341ba72..8a8ff80107 100644
--- a/source4/scripting/python/misc.py
+++ b/source4/scripting/python/misc.py
@@ -62,5 +62,6 @@ import credentials
import param
random_password = _misc.random_password
ldb_set_credentials = _misc.ldb_set_credentials
+ldb_set_loadparm = _misc.ldb_set_loadparm
diff --git a/source4/scripting/python/misc_wrap.c b/source4/scripting/python/misc_wrap.c
index 1f34d7f3ac..af0f32fcb2 100644
--- a/source4/scripting/python/misc_wrap.c
+++ b/source4/scripting/python/misc_wrap.c
@@ -2524,6 +2524,7 @@ static swig_module_info swig_module = {swig_types, 22, 0, 0, 0, 0};
#include "includes.h"
#include "ldb.h"
+#include "param/param.h"
SWIGINTERN int
@@ -2702,6 +2703,18 @@ void ldb_set_credentials(struct ldb_context *ldb, struct cli_credentials *creds)
ldb_set_opaque(ldb, "credentials", creds);
}
+#if 0 /* Fails to link.. */
+void ldb_set_session_info(struct ldb_context *ldb, struct auth_session_info *session_info)
+{
+ ldb_set_opaque(ldb, "sessionInfo", session_info);
+}
+#endif
+
+void ldb_set_loadparm(struct ldb_context *ldb, struct loadparm_context *lp_ctx)
+{
+ ldb_set_opaque(ldb, "loadparm", lp_ctx);
+}
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -2777,9 +2790,53 @@ fail:
}
+SWIGINTERN PyObject *_wrap_ldb_set_loadparm(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
+ PyObject *resultobj = 0;
+ struct ldb_context *arg1 = (struct ldb_context *) 0 ;
+ struct loadparm_context *arg2 = (struct loadparm_context *) 0 ;
+ void *argp1 = 0 ;
+ int res1 = 0 ;
+ void *argp2 = 0 ;
+ int res2 = 0 ;
+ PyObject * obj0 = 0 ;
+ PyObject * obj1 = 0 ;
+ char * kwnames[] = {
+ (char *) "Ldb",(char *) "lp_ctx", NULL
+ };
+
+ {
+ arg2 = loadparm_init(NULL);
+ }
+ if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O|O:ldb_set_loadparm",kwnames,&obj0,&obj1)) SWIG_fail;
+ res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 );
+ if (!SWIG_IsOK(res1)) {
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_set_loadparm" "', argument " "1"" of type '" "struct ldb_context *""'");
+ }
+ arg1 = (struct ldb_context *)(argp1);
+ if (obj1) {
+ res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_loadparm_context, 0 | 0 );
+ if (!SWIG_IsOK(res2)) {
+ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_set_loadparm" "', argument " "2"" of type '" "struct loadparm_context *""'");
+ }
+ arg2 = (struct loadparm_context *)(argp2);
+ }
+ {
+ if (arg1 == NULL)
+ SWIG_exception(SWIG_ValueError,
+ "ldb context must be non-NULL");
+ }
+ ldb_set_loadparm(arg1,arg2);
+ resultobj = SWIG_Py_Void();
+ return resultobj;
+fail:
+ return NULL;
+}
+
+
static PyMethodDef SwigMethods[] = {
{ (char *)"random_password", (PyCFunction) _wrap_random_password, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"ldb_set_credentials", (PyCFunction) _wrap_ldb_set_credentials, METH_VARARGS | METH_KEYWORDS, NULL},
+ { (char *)"ldb_set_loadparm", (PyCFunction) _wrap_ldb_set_loadparm, METH_VARARGS | METH_KEYWORDS, NULL},
{ NULL, NULL, 0, NULL }
};
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index 29d322e2fc..08a262eec8 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -21,21 +21,33 @@
import os
def _in_source_tree():
+ """Check whether the script is being run from the source dir. """
return os.path.exists("%s/../../../samba4-skip" % os.path.dirname(__file__))
+
# When running, in-tree, make sure bin/python is in the PYTHONPATH
if _in_source_tree():
import sys
- dir = os.path.dirname(__file__)
- sys.path.append("%s/../../../bin/python" % os.path.dirname(__file__))
+ srcdir = "%s/../../.." % os.path.dirname(__file__)
+ sys.path.append("%s/bin/python" % srcdir)
+ default_ldb_modules_dir = "%s/bin/modules/ldb" % srcdir
+
import misc
import ldb
ldb.ldb.set_credentials = misc.ldb_set_credentials
+#FIXME: ldb.ldb.set_session_info = misc.ldb_set_session_info
+ldb.ldb.set_loadparm = misc.ldb_set_loadparm
-def Ldb(url, session_info=None, credentials=None, modules_dir=None):
+def Ldb(url, session_info=None, credentials=None, modules_dir=None, lp=None):
"""Open a Samba Ldb file.
+ :param url: LDB Url to open
+ :param session_info: Optional session information
+ :param credentials: Optional credentials, defaults to anonymous.
+ :param modules_dir: Modules directory, automatically set if not specified.
+ :param lp: Loadparm object, optional.
+
This is different from a regular Ldb file in that the Samba-specific
modules-dir is used by default and that credentials and session_info
can be passed through (required by some modules).
@@ -43,12 +55,17 @@ def Ldb(url, session_info=None, credentials=None, modules_dir=None):
import ldb
ret = ldb.Ldb()
if modules_dir is None:
- modules_dir = os.path.join(os.getcwd(), "bin", "modules", "ldb")
- ret.set_modules_dir(modules_dir)
+ modules_dir = default_ldb_modules_dir
+ if modules_dir is not None:
+ ret.set_modules_dir(modules_dir)
def samba_debug(level,text):
print "%d %s" % (level, text)
- ldb_set_opaque("credentials", credentials)
- ret.set_opaque("sessionInfo", session_info)
+ if credentials is not None:
+ ldb.set_credentials(credentials)
+ if session_info is not None:
+ ldb.set_session_info(session_info)
+ if lp is not None:
+ ldb.set_loadparm(lp)
#ret.set_debug(samba_debug)
ret.connect(url)
return ret