summaryrefslogtreecommitdiff
path: root/source4/param
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2009-11-10 15:18:52 +1100
committerAndrew Bartlett <abartlet@samba.org>2009-11-12 16:34:11 +1100
commit6b0b3fed3127dd2da15a79eabea62708e82cc941 (patch)
tree7bc041c52d39d0525d15ed8b966d3287f9a2dd43 /source4/param
parent6437c38aeb5880b18728e65e1c19edf08ac5e4e9 (diff)
downloadsamba-6b0b3fed3127dd2da15a79eabea62708e82cc941.tar.gz
samba-6b0b3fed3127dd2da15a79eabea62708e82cc941.tar.bz2
samba-6b0b3fed3127dd2da15a79eabea62708e82cc941.zip
s4:provision Add C binding to get at the generate schema
This will allow us to do local tests against that schema
Diffstat (limited to 'source4/param')
-rw-r--r--source4/param/provision.c61
-rw-r--r--source4/param/provision.h2
2 files changed, 63 insertions, 0 deletions
diff --git a/source4/param/provision.c b/source4/param/provision.c
index 2f5f78abe6..8c6e1c0f68 100644
--- a/source4/param/provision.c
+++ b/source4/param/provision.c
@@ -44,6 +44,14 @@ static PyObject *provision_module(void)
return PyImport_Import(name);
}
+static PyObject *schema_module(void)
+{
+ PyObject *name = PyString_FromString("samba.schema");
+ if (name == NULL)
+ return NULL;
+ return PyImport_Import(name);
+}
+
NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
struct provision_settings *settings,
struct provision_result *result)
@@ -298,3 +306,56 @@ failure:
PyErr_Clear();
return NT_STATUS_UNSUCCESSFUL;
}
+
+
+struct ldb_context *provision_get_schema(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
+{
+ const char *setupdir;
+ PyObject *schema_mod, *schema_dict, *schema_fn, *py_result, *parameters;
+
+ DEBUG(0,("Schema for DRS tests using python\n"));
+
+ py_load_samba_modules();
+ Py_Initialize();
+ py_update_path("bin"); /* FIXME: Can't assume this is always the case */
+
+ schema_mod = schema_module();
+
+ if (schema_mod == NULL) {
+ PyErr_Print();
+ DEBUG(0, ("Unable to import schema Python module.\n"));
+ return NULL;
+ }
+
+ schema_dict = PyModule_GetDict(schema_mod);
+
+ if (schema_dict == NULL) {
+ DEBUG(0, ("Unable to get dictionary for schema module\n"));
+ return NULL;
+ }
+
+ schema_fn = PyDict_GetItemString(schema_dict, "ldb_with_schema");
+ if (schema_fn == NULL) {
+ PyErr_Print();
+ DEBUG(0, ("Unable to get schema_get_ldb function\n"));
+ return NULL;
+ }
+
+ parameters = PyDict_New();
+
+ setupdir = lp_setupdir(lp_ctx);
+ PyDict_SetItemString(parameters, "setup_dir",
+ PyString_FromString(setupdir));
+
+ py_result = PyEval_CallObjectWithKeywords(schema_fn, NULL, parameters);
+
+ Py_DECREF(parameters);
+
+ if (py_result == NULL) {
+ PyErr_Print();
+ PyErr_Clear();
+ return NULL;
+ }
+
+ return PyLdb_AsLdbContext(PyObject_GetAttrString(py_result, "ldb"));
+}
diff --git a/source4/param/provision.h b/source4/param/provision.h
index c3b3bb88d8..b8277c358d 100644
--- a/source4/param/provision.h
+++ b/source4/param/provision.h
@@ -64,4 +64,6 @@ NTSTATUS provision_store_self_join(TALLOC_CTX *mem_ctx, struct loadparm_context
struct provision_store_self_join_settings *settings,
const char **error_string);
+struct ldb_context *provision_get_schema(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx);
+
#endif /* _PROVISION_H_ */