Changeset 745 for trunk/server/source4/param/provision.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source4/param/provision.c
r414 r745 19 19 */ 20 20 21 #include <Python.h> 22 #include <ldb.h> 23 #include <pyldb.h> 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" 28 29 #include "param/param.h"30 26 #include "param/provision.h" 31 27 #include "param/secrets.h" 32 #include <Python.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" 38 32 39 33 static PyObject *provision_module(void) … … 43 37 return NULL; 44 38 return PyImport_Import(name); 39 } 40 41 static PyObject *schema_module(void) 42 { 43 PyObject *name = PyString_FromString("samba.schema"); 44 if (name == NULL) 45 return NULL; 46 return PyImport_Import(name); 47 } 48 49 static PyObject *ldb_module(void) 50 { 51 PyObject *name = PyString_FromString("ldb"); 52 if (name == NULL) 53 return NULL; 54 return PyImport_Import(name); 55 } 56 57 static PyObject *PyLdb_FromLdbContext(struct ldb_context *ldb_ctx) 58 { 59 PyLdbObject *ret; 60 PyObject *ldb_mod = ldb_module(); 61 PyTypeObject *ldb_ctx_type; 62 if (ldb_mod == NULL) 63 return NULL; 64 65 ldb_ctx_type = (PyTypeObject *)PyObject_GetAttrString(ldb_mod, "Ldb"); 66 67 ret = (PyLdbObject *)ldb_ctx_type->tp_alloc(ldb_ctx_type, 0); 68 if (ret == NULL) { 69 PyErr_NoMemory(); 70 return NULL; 71 } 72 ret->mem_ctx = talloc_new(NULL); 73 ret->ldb_ctx = talloc_reference(ret->mem_ctx, ldb_ctx); 74 return (PyObject *)ret; 45 75 } 46 76 … … 50 80 { 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; 53 83 54 84 DEBUG(0,("Provision for Become-DC test using python\n")); 55 85 56 py_load_samba_modules();57 86 Py_Initialize(); 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 */ 59 88 60 89 provision_mod = provision_module(); … … 88 117 settings->invocation_id == NULL?"None":GUID_string(mem_ctx, settings->invocation_id))); 89 118 90 DEBUG(0,("Path es under targetdir[%s]\n",119 DEBUG(0,("Paths under targetdir[%s]\n", 91 120 settings->targetdir)); 92 121 parameters = PyDict_New(); 93 122 94 configfile = lp _configfile(lp_ctx);123 configfile = lpcfg_configfile(lp_ctx); 95 124 if (configfile != NULL) { 96 125 PyDict_SetItemString(parameters, "smbconf", … … 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)); … … 154 181 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; 187 } 188 result->lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx); 157 189 result->samdb = PyLdb_AsLdbContext(PyObject_GetAttrString(py_result, "samdb")); 158 190 159 191 return NT_STATUS_OK; 160 192 } 161 162 extern void initldb(void);163 193 164 194 static PyObject *py_dom_sid_FromSid(struct dom_sid *sid) … … 191 221 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); 194 224 if (!ldb) { 195 225 *error_string … … 210 240 } 211 241 212 py_load_samba_modules();213 242 Py_Initialize(); 214 py_update_path("bin"); /* FIXME: Can't assume this is always the case */ 215 initldb(); 243 py_update_path(); /* Put the samba path at the start of sys.path */ 216 244 provision_mod = provision_module(); 217 245 … … 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)); 281 } 254 282 PyDict_SetItemString(parameters, "machinepass", 255 283 PyString_FromString(settings->machine_password)); … … 301 329 return NT_STATUS_UNSUCCESSFUL; 302 330 } 331 332 333 struct ldb_context *provision_get_schema(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, 334 DATA_BLOB *override_prefixmap) 335 { 336 PyObject *schema_mod, *schema_dict, *schema_fn, *py_result, *parameters; 337 338 Py_Initialize(); 339 py_update_path(); /* Put the samba path at the start of sys.path */ 340 341 schema_mod = schema_module(); 342 343 if (schema_mod == NULL) { 344 PyErr_Print(); 345 DEBUG(0, ("Unable to import schema Python module.\n")); 346 return NULL; 347 } 348 349 schema_dict = PyModule_GetDict(schema_mod); 350 351 if (schema_dict == NULL) { 352 DEBUG(0, ("Unable to get dictionary for schema module\n")); 353 return NULL; 354 } 355 356 schema_fn = PyDict_GetItemString(schema_dict, "ldb_with_schema"); 357 if (schema_fn == NULL) { 358 PyErr_Print(); 359 DEBUG(0, ("Unable to get schema_get_ldb function\n")); 360 return NULL; 361 } 362 363 parameters = PyDict_New(); 364 365 if (override_prefixmap) { 366 PyDict_SetItemString(parameters, "override_prefixmap", 367 PyString_FromStringAndSize((const char *)override_prefixmap->data, 368 override_prefixmap->length)); 369 } 370 371 py_result = PyEval_CallObjectWithKeywords(schema_fn, NULL, parameters); 372 373 Py_DECREF(parameters); 374 375 if (py_result == NULL) { 376 PyErr_Print(); 377 PyErr_Clear(); 378 return NULL; 379 } 380 381 return PyLdb_AsLdbContext(PyObject_GetAttrString(py_result, "ldb")); 382 }
Note:
See TracChangeset
for help on using the changeset viewer.