r26477: Allow setting loadparm context for a ldb context in python, plus some other...
authorJelmer Vernooij <jelmer@samba.org>
Sun, 16 Dec 2007 16:17:37 +0000 (17:17 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 21 Dec 2007 04:50:36 +0000 (05:50 +0100)
(This used to be commit d88527a9d6435203faa8273347d5aa41937e5395)

source4/auth/config.mk
source4/scripting/python/misc.i
source4/scripting/python/misc.py
source4/scripting/python/misc_wrap.c
source4/scripting/python/samba/__init__.py

index 04a9fb58f647d3cbb0c7cba41d9f1cdb92bd4c28..dc0865333d1a42d549b335afa2ce7c68bd6e6049 100644 (file)
@@ -11,7 +11,7 @@ PUBLIC_PROTO_HEADER = session_proto.h
 [SUBSYSTEM::auth_system_session]
 OBJ_FILES = system_session.o
 PUBLIC_PROTO_HEADER = system_session_proto.h
-PRIVATE_DEPENDENCIES = auth_session LIBSAMBA-UTIL
+PRIVATE_DEPENDENCIES = auth_session LIBSAMBA-UTIL LIBSECURITY
 
 [SUBSYSTEM::auth_sam]
 PRIVATE_PROTO_HEADER = auth_sam.h
index 3d886a25bc2e490185ef5b7462d8575b673748d2..b2a7ad8ee8358048b1ba8fd7a30841c9c7141529 100644 (file)
@@ -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);
+}
 %}
index 94b341ba728a2d62b47b50ef5f97551f0ed8e76a..8a8ff801071602145b5244864c977a67f947113f 100644 (file)
@@ -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
 
 
index 1f34d7f3ace9ea7554ea953823436e4a611ed53f..af0f32fcb250d195a9c260a584d79e64a220c3f7 100644 (file)
@@ -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 }
 };
 
index 29d322e2fc4a1f46b6a70f320e11fbf45484e5aa..08a262eec8ec1dff32f0b216ff0f780eb2baedd5 100644 (file)
 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