summaryrefslogtreecommitdiff
path: root/source4/param/provision.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/param/provision.c')
-rw-r--r--source4/param/provision.c136
1 files changed, 108 insertions, 28 deletions
diff --git a/source4/param/provision.c b/source4/param/provision.c
index cb74f96820..7b6e6e74b3 100644
--- a/source4/param/provision.c
+++ b/source4/param/provision.c
@@ -18,23 +18,17 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <Python.h>
+#include <ldb.h>
+#include <pyldb.h>
#include "includes.h"
-#include "auth/auth.h"
-#include "lib/ldb_wrap.h"
-#include "ldb/include/ldb.h"
-#include "ldb_errors.h"
-#include "libcli/raw/libcliraw.h"
#include "librpc/ndr/libndr.h"
-
-#include "param/param.h"
#include "param/provision.h"
#include "param/secrets.h"
-#include <Python.h>
#include "lib/talloc/pytalloc.h"
-#include "librpc/rpc/pyrpc.h"
#include "scripting/python/modules.h"
-#include "lib/ldb/pyldb.h"
#include "param/pyparam.h"
+#include "dynconfig/dynconfig.h"
static PyObject *provision_module(void)
{
@@ -44,18 +38,53 @@ 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);
+}
+
+static PyObject *ldb_module(void)
+{
+ PyObject *name = PyString_FromString("ldb");
+ if (name == NULL)
+ return NULL;
+ return PyImport_Import(name);
+}
+
+static PyObject *PyLdb_FromLdbContext(struct ldb_context *ldb_ctx)
+{
+ PyLdbObject *ret;
+ PyObject *ldb_mod = ldb_module();
+ PyTypeObject *ldb_ctx_type;
+ if (ldb_mod == NULL)
+ return NULL;
+
+ ldb_ctx_type = (PyTypeObject *)PyObject_GetAttrString(ldb_mod, "Ldb");
+
+ ret = (PyLdbObject *)ldb_ctx_type->tp_alloc(ldb_ctx_type, 0);
+ if (ret == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ ret->mem_ctx = talloc_new(NULL);
+ ret->ldb_ctx = talloc_reference(ret->mem_ctx, ldb_ctx);
+ return (PyObject *)ret;
+}
+
NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
struct provision_settings *settings,
struct provision_result *result)
{
const char *configfile;
- PyObject *provision_mod, *provision_dict, *provision_fn, *py_result, *parameters;
+ PyObject *provision_mod, *provision_dict, *provision_fn, *py_result, *parameters, *py_lp_ctx;
DEBUG(0,("Provision for Become-DC test using python\n"));
- py_load_samba_modules();
Py_Initialize();
- py_update_path("bin"); /* FIXME: Can't assume this is always the case */
+ py_update_path(); /* Put the samba path at the start of sys.path */
provision_mod = provision_module();
@@ -87,11 +116,11 @@ NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
settings->ntds_dn_str,
settings->invocation_id == NULL?"None":GUID_string(mem_ctx, settings->invocation_id)));
- DEBUG(0,("Pathes under targetdir[%s]\n",
+ DEBUG(0,("Paths under targetdir[%s]\n",
settings->targetdir));
parameters = PyDict_New();
- configfile = lp_configfile(lp_ctx);
+ configfile = lpcfg_configfile(lp_ctx);
if (configfile != NULL) {
PyDict_SetItemString(parameters, "smbconf",
PyString_FromString(configfile));
@@ -102,8 +131,6 @@ NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
if (settings->targetdir != NULL)
PyDict_SetItemString(parameters, "targetdir",
PyString_FromString(settings->targetdir));
- PyDict_SetItemString(parameters, "setup_dir",
- PyString_FromString("setup"));
PyDict_SetItemString(parameters, "hostname",
PyString_FromString(settings->netbios_name));
PyDict_SetItemString(parameters, "domain",
@@ -153,14 +180,17 @@ NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
result->domaindn = talloc_strdup(mem_ctx, PyString_AsString(PyObject_GetAttrString(py_result, "domaindn")));
/* FIXME paths */
- result->lp_ctx = lp_from_py_object(PyObject_GetAttrString(py_result, "lp"));
+ py_lp_ctx = PyObject_GetAttrString(py_result, "lp");
+ if (py_lp_ctx == NULL) {
+ DEBUG(0, ("Missing 'lp' attribute"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+ result->lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
result->samdb = PyLdb_AsLdbContext(PyObject_GetAttrString(py_result, "samdb"));
return NT_STATUS_OK;
}
-extern void initldb(void);
-
static PyObject *py_dom_sid_FromSid(struct dom_sid *sid)
{
PyObject *mod_security, *dom_sid_Type;
@@ -190,7 +220,7 @@ NTSTATUS provision_store_self_join(TALLOC_CTX *mem_ctx, struct loadparm_context
}
/* Open the secrets database */
- ldb = secrets_db_connect(tmp_mem, event_ctx, lp_ctx);
+ ldb = secrets_db_connect(tmp_mem, lp_ctx);
if (!ldb) {
*error_string
= talloc_asprintf(mem_ctx,
@@ -209,10 +239,8 @@ NTSTATUS provision_store_self_join(TALLOC_CTX *mem_ctx, struct loadparm_context
return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
}
- py_load_samba_modules();
Py_Initialize();
- py_update_path("bin"); /* FIXME: Can't assume this is always the case */
- initldb();
+ py_update_path(); /* Put the samba path at the start of sys.path */
provision_mod = provision_module();
if (provision_mod == NULL) {
@@ -247,10 +275,10 @@ NTSTATUS provision_store_self_join(TALLOC_CTX *mem_ctx, struct loadparm_context
PyLdb_FromLdbContext(ldb));
PyDict_SetItemString(parameters, "domain",
PyString_FromString(settings->domain_name));
- PyDict_SetItemString(parameters, "domain",
- PyString_FromString(settings->domain_name));
- PyDict_SetItemString(parameters, "realm",
- PyString_FromString(settings->realm));
+ if (settings->realm != NULL) {
+ PyDict_SetItemString(parameters, "realm",
+ PyString_FromString(settings->realm));
+ }
PyDict_SetItemString(parameters, "machinepass",
PyString_FromString(settings->machine_password));
PyDict_SetItemString(parameters, "netbiosname",
@@ -300,3 +328,55 @@ failure:
PyErr_Clear();
return NT_STATUS_UNSUCCESSFUL;
}
+
+
+struct ldb_context *provision_get_schema(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
+ DATA_BLOB *override_prefixmap)
+{
+ PyObject *schema_mod, *schema_dict, *schema_fn, *py_result, *parameters;
+
+ Py_Initialize();
+ py_update_path(); /* Put the samba path at the start of sys.path */
+
+ 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();
+
+ if (override_prefixmap) {
+ PyDict_SetItemString(parameters, "override_prefixmap",
+ PyString_FromStringAndSize((const char *)override_prefixmap->data,
+ override_prefixmap->length));
+ }
+
+ 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"));
+}