summaryrefslogtreecommitdiff
path: root/source4/scripting/python
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2007-12-18 02:21:14 +0100
committerStefan Metzmacher <metze@samba.org>2007-12-21 05:51:31 +0100
commit63f53094efa29b76eb4136cddf19d9c5d325fc5f (patch)
tree2e7ca7c80aaccfcfaed427682854c16bef3ed33c /source4/scripting/python
parentcad1e11959a3468875500fffac0ce562bc785249 (diff)
downloadsamba-63f53094efa29b76eb4136cddf19d9c5d325fc5f.tar.gz
samba-63f53094efa29b76eb4136cddf19d9c5d325fc5f.tar.bz2
samba-63f53094efa29b76eb4136cddf19d9c5d325fc5f.zip
r26520: More Python updates.
(This used to be commit a8b1fe15ac853082961132ede061fe1556ae29f7)
Diffstat (limited to 'source4/scripting/python')
-rw-r--r--source4/scripting/python/misc.i3
-rw-r--r--source4/scripting/python/misc.py2
-rw-r--r--source4/scripting/python/misc_wrap.c73
-rw-r--r--source4/scripting/python/samba/__init__.py4
-rw-r--r--source4/scripting/python/samba/provision.py13
-rw-r--r--source4/scripting/python/samba/samdb.py8
6 files changed, 96 insertions, 7 deletions
diff --git a/source4/scripting/python/misc.i b/source4/scripting/python/misc.i
index a0519644b8..3af10dfce9 100644
--- a/source4/scripting/python/misc.i
+++ b/source4/scripting/python/misc.i
@@ -23,6 +23,7 @@
#include "ldb.h"
#include "param/param.h"
#include "dsdb/samdb/samdb.h"
+#include "lib/ldb-samba/ldif_handlers.h"
%}
%import "stdint.i"
@@ -62,3 +63,5 @@ WERROR dsdb_attach_schema_from_ldif_file(struct ldb_context *ldb, const char *pf
%rename(version) samba_version_string;
const char *samba_version_string(void);
+int dsdb_set_global_schema(struct ldb_context *ldb);
+int ldb_register_samba_handlers(struct ldb_context *ldb);
diff --git a/source4/scripting/python/misc.py b/source4/scripting/python/misc.py
index 228ab24dbf..ae900a1f62 100644
--- a/source4/scripting/python/misc.py
+++ b/source4/scripting/python/misc.py
@@ -68,5 +68,7 @@ ldb_set_loadparm = _misc.ldb_set_loadparm
samdb_set_domain_sid = _misc.samdb_set_domain_sid
dsdb_attach_schema_from_ldif_file = _misc.dsdb_attach_schema_from_ldif_file
version = _misc.version
+dsdb_set_global_schema = _misc.dsdb_set_global_schema
+ldb_register_samba_handlers = _misc.ldb_register_samba_handlers
diff --git a/source4/scripting/python/misc_wrap.c b/source4/scripting/python/misc_wrap.c
index effabdecef..dc1203e2f0 100644
--- a/source4/scripting/python/misc_wrap.c
+++ b/source4/scripting/python/misc_wrap.c
@@ -2531,6 +2531,7 @@ static swig_module_info swig_module = {swig_types, 27, 0, 0, 0, 0};
#include "ldb.h"
#include "param/param.h"
#include "dsdb/samdb/samdb.h"
+#include "lib/ldb-samba/ldif_handlers.h"
SWIGINTERN int
@@ -2782,6 +2783,16 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
+
+ #define SWIG_From_long PyInt_FromLong
+
+
+SWIGINTERNINLINE PyObject *
+SWIG_From_int (int value)
+{
+ return SWIG_From_long (value);
+}
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -3051,6 +3062,66 @@ fail:
}
+SWIGINTERN PyObject *_wrap_dsdb_set_global_schema(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
+ PyObject *resultobj = 0;
+ struct ldb_context *arg1 = (struct ldb_context *) 0 ;
+ int result;
+ void *argp1 = 0 ;
+ int res1 = 0 ;
+ PyObject * obj0 = 0 ;
+ char * kwnames[] = {
+ (char *) "ldb", NULL
+ };
+
+ if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O:dsdb_set_global_schema",kwnames,&obj0)) 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 '" "dsdb_set_global_schema" "', argument " "1"" of type '" "struct ldb_context *""'");
+ }
+ arg1 = (struct ldb_context *)(argp1);
+ {
+ if (arg1 == NULL)
+ SWIG_exception(SWIG_ValueError,
+ "ldb context must be non-NULL");
+ }
+ result = (int)dsdb_set_global_schema(arg1);
+ resultobj = SWIG_From_int((int)(result));
+ return resultobj;
+fail:
+ return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_ldb_register_samba_handlers(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
+ PyObject *resultobj = 0;
+ struct ldb_context *arg1 = (struct ldb_context *) 0 ;
+ int result;
+ void *argp1 = 0 ;
+ int res1 = 0 ;
+ PyObject * obj0 = 0 ;
+ char * kwnames[] = {
+ (char *) "ldb", NULL
+ };
+
+ if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O:ldb_register_samba_handlers",kwnames,&obj0)) 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_register_samba_handlers" "', argument " "1"" of type '" "struct ldb_context *""'");
+ }
+ arg1 = (struct ldb_context *)(argp1);
+ {
+ if (arg1 == NULL)
+ SWIG_exception(SWIG_ValueError,
+ "ldb context must be non-NULL");
+ }
+ result = (int)ldb_register_samba_handlers(arg1);
+ resultobj = SWIG_From_int((int)(result));
+ 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},
@@ -3059,6 +3130,8 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"samdb_set_domain_sid", (PyCFunction) _wrap_samdb_set_domain_sid, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"dsdb_attach_schema_from_ldif_file", (PyCFunction) _wrap_dsdb_attach_schema_from_ldif_file, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"version", (PyCFunction)_wrap_version, METH_NOARGS, NULL},
+ { (char *)"dsdb_set_global_schema", (PyCFunction) _wrap_dsdb_set_global_schema, METH_VARARGS | METH_KEYWORDS, NULL},
+ { (char *)"ldb_register_samba_handlers", (PyCFunction) _wrap_ldb_register_samba_handlers, 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 f89ac39ac7..8e0eff3011 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -78,6 +78,10 @@ class Ldb(ldb.Ldb):
if url:
self.connect(url)
+ def msg(l,text):
+ print text
+ #self.set_debug(msg)
+
set_credentials = misc.ldb_set_credentials
set_session_info = misc.ldb_set_session_info
set_loadparm = misc.ldb_set_loadparm
diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py
index d9863420b6..0a3c183fcc 100644
--- a/source4/scripting/python/samba/provision.py
+++ b/source4/scripting/python/samba/provision.py
@@ -306,7 +306,7 @@ def setup_name_mappings(subobj, ldb):
["objectSid"])
assert len(res) == 1
assert "objectSid" in res[0]
- sid = list(res[0]["objectSid"])[0]
+ sid = str(list(res[0]["objectSid"])[0])
# add some foreign sids if they are not present already
ldb.add_foreign(subobj.domaindn, "S-1-5-7", "Anonymous")
@@ -419,12 +419,12 @@ def provision(lp, setup_dir, subobj, message, blank, paths, session_info,
message("Setting up registry")
reg = registry.Registry()
- hive = registry.Hive(paths.hklm, session_info=session_info,
- credentials=credentials, lp_ctx=lp)
- reg.mount_hive(hive, registry.HKEY_LOCAL_MACHINE, [])
+ #hive = registry.Hive(paths.hklm, session_info=session_info,
+ # credentials=credentials, lp_ctx=lp)
+ #reg.mount_hive(hive, "HKEY_LOCAL_MACHINE")
provision_reg = os.path.join(setup_dir, "provision.reg")
assert os.path.exists(provision_reg)
- reg.apply_patchfile(provision_reg)
+ #reg.apply_patchfile(provision_reg)
message("Setting up templates into %s" % paths.templates)
setup_ldb(setup_dir, "provision_templates.ldif", session_info,
@@ -434,7 +434,8 @@ def provision(lp, setup_dir, subobj, message, blank, paths, session_info,
setup_ldb(setup_dir, "provision_partitions.ldif", session_info,
credentials, subobj, lp, paths.samdb)
- samdb = open_ldb(session_info, credentials, lp, paths.samdb)
+ samdb = SamDB(paths.samdb, session_info=session_info,
+ credentials=credentials, lp=lp)
samdb.transaction_start()
try:
message("Setting up sam.ldb attributes")
diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py
index 73426121a6..ce06efa3de 100644
--- a/source4/scripting/python/samba/samdb.py
+++ b/source4/scripting/python/samba/samdb.py
@@ -22,8 +22,14 @@
import samba
import misc
+import ldb
class SamDB(samba.Ldb):
+ def __init__(self, *args, **kwargs):
+ super(SamDB, self).__init__(*args, **kwargs)
+ misc.dsdb_set_global_schema(self)
+ misc.ldb_register_samba_handlers(self)
+
def add_foreign(self, domaindn, sid, desc):
"""Add a foreign security principle."""
add = """
@@ -39,7 +45,7 @@ description: %s
def setup_name_mapping(self, domaindn, sid, unixname):
"""Setup a mapping between a sam name and a unix name."""
- res = self.search(Dn(ldb, domaindn), SCOPE_SUBTREE,
+ res = self.search(ldb.Dn(self, domaindn), ldb.SCOPE_SUBTREE,
"objectSid=%s" % sid, ["dn"])
assert len(res) == 1, "Failed to find record for objectSid %s" % sid