18
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
21
24
#include "includes.h"
22
#include "auth/auth.h"
23
#include "lib/ldb_wrap.h"
24
#include "ldb/include/ldb.h"
25
#include "ldb_errors.h"
26
#include "libcli/raw/libcliraw.h"
27
25
#include "librpc/ndr/libndr.h"
29
#include "param/param.h"
30
26
#include "param/provision.h"
31
27
#include "param/secrets.h"
33
28
#include "lib/talloc/pytalloc.h"
34
#include "librpc/rpc/pyrpc.h"
35
29
#include "scripting/python/modules.h"
36
#include "lib/ldb/pyldb.h"
37
30
#include "param/pyparam.h"
31
#include "dynconfig/dynconfig.h"
39
33
static PyObject *provision_module(void)
44
38
return PyImport_Import(name);
41
static PyObject *schema_module(void)
43
PyObject *name = PyString_FromString("samba.schema");
46
return PyImport_Import(name);
49
static PyObject *ldb_module(void)
51
PyObject *name = PyString_FromString("ldb");
54
return PyImport_Import(name);
57
static PyObject *PyLdb_FromLdbContext(struct ldb_context *ldb_ctx)
60
PyObject *ldb_mod = ldb_module();
61
PyTypeObject *ldb_ctx_type;
65
ldb_ctx_type = (PyTypeObject *)PyObject_GetAttrString(ldb_mod, "Ldb");
67
ret = (PyLdbObject *)ldb_ctx_type->tp_alloc(ldb_ctx_type, 0);
72
ret->mem_ctx = talloc_new(NULL);
73
ret->ldb_ctx = talloc_reference(ret->mem_ctx, ldb_ctx);
74
return (PyObject *)ret;
47
77
NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
48
78
struct provision_settings *settings,
49
79
struct provision_result *result)
51
81
const char *configfile;
52
PyObject *provision_mod, *provision_dict, *provision_fn, *py_result, *parameters;
82
PyObject *provision_mod, *provision_dict, *provision_fn, *py_result, *parameters, *py_lp_ctx;
54
84
DEBUG(0,("Provision for Become-DC test using python\n"));
56
py_load_samba_modules();
58
py_update_path("bin"); /* FIXME: Can't assume this is always the case */
87
py_update_path(); /* Put the samba path at the start of sys.path */
60
89
provision_mod = provision_module();
87
116
settings->ntds_dn_str,
88
117
settings->invocation_id == NULL?"None":GUID_string(mem_ctx, settings->invocation_id)));
90
DEBUG(0,("Pathes under targetdir[%s]\n",
119
DEBUG(0,("Paths under targetdir[%s]\n",
91
120
settings->targetdir));
92
121
parameters = PyDict_New();
94
configfile = lp_configfile(lp_ctx);
123
configfile = lpcfg_configfile(lp_ctx);
95
124
if (configfile != NULL) {
96
125
PyDict_SetItemString(parameters, "smbconf",
97
126
PyString_FromString(configfile));
102
131
if (settings->targetdir != NULL)
103
132
PyDict_SetItemString(parameters, "targetdir",
104
133
PyString_FromString(settings->targetdir));
105
PyDict_SetItemString(parameters, "setup_dir",
106
PyString_FromString("setup"));
107
134
PyDict_SetItemString(parameters, "hostname",
108
135
PyString_FromString(settings->netbios_name));
109
136
PyDict_SetItemString(parameters, "domain",
153
180
result->domaindn = talloc_strdup(mem_ctx, PyString_AsString(PyObject_GetAttrString(py_result, "domaindn")));
155
182
/* FIXME paths */
156
result->lp_ctx = lp_from_py_object(PyObject_GetAttrString(py_result, "lp"));
183
py_lp_ctx = PyObject_GetAttrString(py_result, "lp");
184
if (py_lp_ctx == NULL) {
185
DEBUG(0, ("Missing 'lp' attribute"));
186
return NT_STATUS_UNSUCCESSFUL;
188
result->lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
157
189
result->samdb = PyLdb_AsLdbContext(PyObject_GetAttrString(py_result, "samdb"));
159
191
return NT_STATUS_OK;
162
extern void initldb(void);
164
194
static PyObject *py_dom_sid_FromSid(struct dom_sid *sid)
166
196
PyObject *mod_security, *dom_sid_Type;
192
222
/* Open the secrets database */
193
ldb = secrets_db_connect(tmp_mem, event_ctx, lp_ctx);
223
ldb = secrets_db_connect(tmp_mem, lp_ctx);
196
226
= talloc_asprintf(mem_ctx,
209
239
return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
212
py_load_samba_modules();
214
py_update_path("bin"); /* FIXME: Can't assume this is always the case */
243
py_update_path(); /* Put the samba path at the start of sys.path */
216
244
provision_mod = provision_module();
218
246
if (provision_mod == NULL) {
247
275
PyLdb_FromLdbContext(ldb));
248
276
PyDict_SetItemString(parameters, "domain",
249
277
PyString_FromString(settings->domain_name));
250
PyDict_SetItemString(parameters, "domain",
251
PyString_FromString(settings->domain_name));
252
PyDict_SetItemString(parameters, "realm",
253
PyString_FromString(settings->realm));
278
if (settings->realm != NULL) {
279
PyDict_SetItemString(parameters, "realm",
280
PyString_FromString(settings->realm));
254
282
PyDict_SetItemString(parameters, "machinepass",
255
283
PyString_FromString(settings->machine_password));
256
284
PyDict_SetItemString(parameters, "netbiosname",
301
329
return NT_STATUS_UNSUCCESSFUL;
333
struct ldb_context *provision_get_schema(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
334
DATA_BLOB *override_prefixmap)
336
PyObject *schema_mod, *schema_dict, *schema_fn, *py_result, *parameters;
339
py_update_path(); /* Put the samba path at the start of sys.path */
341
schema_mod = schema_module();
343
if (schema_mod == NULL) {
345
DEBUG(0, ("Unable to import schema Python module.\n"));
349
schema_dict = PyModule_GetDict(schema_mod);
351
if (schema_dict == NULL) {
352
DEBUG(0, ("Unable to get dictionary for schema module\n"));
356
schema_fn = PyDict_GetItemString(schema_dict, "ldb_with_schema");
357
if (schema_fn == NULL) {
359
DEBUG(0, ("Unable to get schema_get_ldb function\n"));
363
parameters = PyDict_New();
365
if (override_prefixmap) {
366
PyDict_SetItemString(parameters, "override_prefixmap",
367
PyString_FromStringAndSize((const char *)override_prefixmap->data,
368
override_prefixmap->length));
371
py_result = PyEval_CallObjectWithKeywords(schema_fn, NULL, parameters);
373
Py_DECREF(parameters);
375
if (py_result == NULL) {
381
return PyLdb_AsLdbContext(PyObject_GetAttrString(py_result, "ldb"));