~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source4/param/provision.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
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)
40
34
{
44
38
        return PyImport_Import(name);
45
39
}
46
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;
 
75
}
 
76
 
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)
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();
61
90
 
87
116
                settings->ntds_dn_str,
88
117
                settings->invocation_id == NULL?"None":GUID_string(mem_ctx, settings->invocation_id)));
89
118
 
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();
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", 
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")));
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
193
 
162
 
extern void initldb(void);
163
 
 
164
194
static PyObject *py_dom_sid_FromSid(struct dom_sid *sid)
165
195
{
166
196
        PyObject *mod_security, *dom_sid_Type;
190
220
        }
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
196
226
                        = talloc_asprintf(mem_ctx, 
209
239
                return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
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
 
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));
 
281
        }
254
282
        PyDict_SetItemString(parameters, "machinepass", 
255
283
                             PyString_FromString(settings->machine_password));
256
284
        PyDict_SetItemString(parameters, "netbiosname", 
300
328
        PyErr_Clear();
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
}