Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source4/param/provision.c

    r414 r745  
    1919*/
    2020
     21#include <Python.h>
     22#include <ldb.h>
     23#include <pyldb.h>
    2124#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"
    2725#include "librpc/ndr/libndr.h"
    28 
    29 #include "param/param.h"
    3026#include "param/provision.h"
    3127#include "param/secrets.h"
    32 #include <Python.h>
    3328#include "lib/talloc/pytalloc.h"
    34 #include "librpc/rpc/pyrpc.h"
    3529#include "scripting/python/modules.h"
    36 #include "lib/ldb/pyldb.h"
    3730#include "param/pyparam.h"
     31#include "dynconfig/dynconfig.h"
    3832
    3933static PyObject *provision_module(void)
     
    4337                return NULL;
    4438        return PyImport_Import(name);
     39}
     40
     41static 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
     49static 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
     57static 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;
    4575}
    4676
     
    5080{
    5181        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;
    5383       
    5484        DEBUG(0,("Provision for Become-DC test using python\n"));
    5585
    56         py_load_samba_modules();
    5786        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 */
    5988
    6089        provision_mod = provision_module();
     
    88117                settings->invocation_id == NULL?"None":GUID_string(mem_ctx, settings->invocation_id)));
    89118
    90         DEBUG(0,("Pathes under targetdir[%s]\n",
     119        DEBUG(0,("Paths under targetdir[%s]\n",
    91120                 settings->targetdir));
    92121        parameters = PyDict_New();
    93122
    94         configfile = lp_configfile(lp_ctx);
     123        configfile = lpcfg_configfile(lp_ctx);
    95124        if (configfile != NULL) {
    96125                PyDict_SetItemString(parameters, "smbconf",
     
    103132                PyDict_SetItemString(parameters, "targetdir",
    104133                                                         PyString_FromString(settings->targetdir));
    105         PyDict_SetItemString(parameters, "setup_dir",
    106                              PyString_FromString("setup"));
    107134        PyDict_SetItemString(parameters, "hostname",
    108135                                                 PyString_FromString(settings->netbios_name));
     
    154181
    155182        /* 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);
    157189        result->samdb = PyLdb_AsLdbContext(PyObject_GetAttrString(py_result, "samdb"));
    158190
    159191        return NT_STATUS_OK;
    160192}
    161 
    162 extern void initldb(void);
    163193
    164194static PyObject *py_dom_sid_FromSid(struct dom_sid *sid)
     
    191221
    192222        /* Open the secrets database */
    193         ldb = secrets_db_connect(tmp_mem, event_ctx, lp_ctx);
     223        ldb = secrets_db_connect(tmp_mem, lp_ctx);
    194224        if (!ldb) {
    195225                *error_string
     
    210240        }
    211241
    212         py_load_samba_modules();
    213242        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 */
    216244        provision_mod = provision_module();
    217245
     
    248276        PyDict_SetItemString(parameters, "domain",
    249277                             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        }
    254282        PyDict_SetItemString(parameters, "machinepass",
    255283                             PyString_FromString(settings->machine_password));
     
    301329        return NT_STATUS_UNSUCCESSFUL;
    302330}
     331
     332
     333struct 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.