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

« back to all changes in this revision

Viewing changes to source4/lib/registry/pyregistry.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:
2
2
   Unix SMB/CIFS implementation.
3
3
   Samba utility functions
4
4
   Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
 
5
   Copyright (C) Wilco Baan Hofman <wilco@baanhofman.nl> 2010
5
6
   
6
7
   This program is free software; you can redistribute it and/or modify
7
8
   it under the terms of the GNU General Public License as published by
17
18
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
*/
19
20
 
 
21
#include <Python.h>
20
22
#include "includes.h"
21
 
#include <tevent.h>
22
 
#include <Python.h>
23
23
#include "libcli/util/pyerrors.h"
24
24
#include "lib/registry/registry.h"
25
 
#include "scripting/python/modules.h" /* for py_iconv_convenience() */
26
 
#include <pytalloc.h>
 
25
#include "lib/talloc/pytalloc.h"
 
26
#include "lib/events/events.h"
27
27
#include "auth/credentials/pycredentials.h"
28
28
#include "param/pyparam.h"
29
29
 
30
 
#ifndef Py_RETURN_NONE
31
 
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
32
 
#endif
33
 
 
34
 
PyAPI_DATA(PyTypeObject) PyRegistryKey;
35
 
PyAPI_DATA(PyTypeObject) PyRegistry;
36
 
PyAPI_DATA(PyTypeObject) PyHiveKey;
 
30
extern PyTypeObject PyRegistryKey;
 
31
extern PyTypeObject PyRegistry;
 
32
extern PyTypeObject PyHiveKey;
37
33
 
38
34
/*#define PyRegistryKey_AsRegistryKey(obj) py_talloc_get_type(obj, struct registry_key)*/
39
35
#define PyRegistry_AsRegistryContext(obj) ((struct registry_context *)py_talloc_get_ptr(obj))
95
91
        if (!PyArg_ParseTuple(args, "s", &filename))
96
92
                return NULL;
97
93
 
98
 
        result = reg_diff_apply(ctx, py_iconv_convenience(NULL), filename);
 
94
        result = reg_diff_apply(ctx, filename);
99
95
        PyErr_WERROR_IS_ERR_RAISE(result);
100
96
 
101
97
        Py_RETURN_NONE; 
163
159
        .tp_methods = registry_methods,
164
160
        .tp_new = registry_new,
165
161
        .tp_basicsize = sizeof(py_talloc_Object),
166
 
        .tp_dealloc = py_talloc_dealloc,
167
162
        .tp_flags = Py_TPFLAGS_DEFAULT,
168
163
};
169
164
 
176
171
        if (!PyArg_ParseTuple(args, "s", &name))
177
172
                return NULL;
178
173
 
179
 
        result = hive_key_del(key, name);
 
174
        result = hive_key_del(NULL, key, name);
180
175
 
181
176
        PyErr_WERROR_IS_ERR_RAISE(result);
182
177
 
203
198
        if (!PyArg_ParseTuple(args, "s", &name))
204
199
                return NULL;
205
200
 
206
 
        result = hive_key_del_value(key, name);
 
201
        result = hive_key_del_value(NULL, key, name);
207
202
 
208
203
        PyErr_WERROR_IS_ERR_RAISE(result);
209
204
 
224
219
        if (value.data != NULL)
225
220
                result = hive_key_set_value(key, name, type, value);
226
221
        else
227
 
                result = hive_key_del_value(key, name);
 
222
                result = hive_key_del_value(NULL, key, name);
228
223
 
229
224
        PyErr_WERROR_IS_ERR_RAISE(result);
230
225
 
243
238
        { NULL }
244
239
};
245
240
 
246
 
static PyObject *hive_open(PyTypeObject *type, PyObject *args, PyObject *kwargs)
 
241
static PyObject *hive_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) {
 
242
        Py_RETURN_NONE;
 
243
}
 
244
 
 
245
static PyObject *py_open_hive(PyTypeObject *type, PyObject *args, PyObject *kwargs)
247
246
{
248
 
        /* reg_open_hive */
249
 
        Py_RETURN_NONE;
 
247
        const char *kwnames[] = { "location", "lp_ctx", "session_info", "credentials", NULL };
 
248
        WERROR result;
 
249
        struct loadparm_context *lp_ctx;
 
250
        PyObject *py_lp_ctx, *py_session_info, *py_credentials;
 
251
        struct auth_session_info *session_info;
 
252
        struct cli_credentials *credentials;
 
253
        char *location;
 
254
        struct hive_key *hive_key;
 
255
        TALLOC_CTX *mem_ctx;
 
256
 
 
257
        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO",
 
258
                                         discard_const_p(char *, kwnames),
 
259
                                         &location,
 
260
                                         &py_lp_ctx, &py_session_info,
 
261
                                         &py_credentials))
 
262
                return NULL;
 
263
 
 
264
        mem_ctx = talloc_new(NULL);
 
265
        if (mem_ctx == NULL) {
 
266
                PyErr_NoMemory();
 
267
                return NULL;
 
268
        }
 
269
 
 
270
        lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
 
271
        if (lp_ctx == NULL) {
 
272
                PyErr_SetString(PyExc_TypeError, "Expected loadparm context");
 
273
                talloc_free(mem_ctx);
 
274
                return NULL;
 
275
        }
 
276
 
 
277
        credentials = cli_credentials_from_py_object(py_credentials);
 
278
        if (credentials == NULL) {
 
279
                PyErr_SetString(PyExc_TypeError, "Expected credentials");
 
280
                talloc_free(mem_ctx);
 
281
                return NULL;
 
282
        }
 
283
        session_info = NULL;
 
284
 
 
285
        result = reg_open_hive(NULL, location, session_info, credentials,
 
286
                               tevent_context_init(NULL),
 
287
                               lp_ctx, &hive_key);
 
288
        talloc_free(mem_ctx);
 
289
        PyErr_WERROR_IS_ERR_RAISE(result);
 
290
 
 
291
        return py_talloc_steal(&PyHiveKey, hive_key);
250
292
}
251
293
 
252
294
PyTypeObject PyHiveKey = {
253
295
        .tp_name = "HiveKey",
254
296
        .tp_methods = hive_key_methods,
255
 
        .tp_new = hive_open,
 
297
        .tp_new = hive_new,
256
298
        .tp_basicsize = sizeof(py_talloc_Object),
257
 
        .tp_dealloc = py_talloc_dealloc,
258
299
        .tp_flags = Py_TPFLAGS_DEFAULT,
259
300
};
260
301
 
261
302
PyTypeObject PyRegistryKey = {
262
303
        .tp_name = "RegistryKey",
263
304
        .tp_basicsize = sizeof(py_talloc_Object),
264
 
        .tp_dealloc = py_talloc_dealloc,
265
305
        .tp_flags = Py_TPFLAGS_DEFAULT,
266
306
};
267
307
 
270
310
        const char *kwnames[] = { "lp_ctx", "session_info", NULL };
271
311
        struct registry_context *reg_ctx;
272
312
        WERROR result;
273
 
    struct loadparm_context *lp_ctx;
 
313
        struct loadparm_context *lp_ctx;
274
314
        PyObject *py_lp_ctx, *py_session_info, *py_credentials;
275
315
        struct auth_session_info *session_info;
276
 
    struct cli_credentials *credentials;
277
 
        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOO", discard_const_p(char *, kwnames),
278
 
                                         &py_lp_ctx, &py_session_info, &py_credentials))
279
 
                return NULL;
280
 
 
281
 
    lp_ctx = lp_from_py_object(py_lp_ctx);
282
 
    if (lp_ctx == NULL) {
 
316
        struct cli_credentials *credentials;
 
317
        TALLOC_CTX *mem_ctx;
 
318
 
 
319
        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOO",
 
320
                                         discard_const_p(char *, kwnames),
 
321
                                         &py_lp_ctx, &py_session_info,
 
322
                                         &py_credentials))
 
323
                return NULL;
 
324
 
 
325
        mem_ctx = talloc_new(NULL);
 
326
        if (mem_ctx == NULL) {
 
327
                PyErr_NoMemory();
 
328
                return NULL;
 
329
        }
 
330
 
 
331
        lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
 
332
        if (lp_ctx == NULL) {
283
333
                PyErr_SetString(PyExc_TypeError, "Expected loadparm context");
 
334
                talloc_free(mem_ctx);
284
335
                return NULL;
285
 
    }
 
336
        }
286
337
 
287
338
        credentials = cli_credentials_from_py_object(py_credentials);
288
339
        if (credentials == NULL) {
289
340
                PyErr_SetString(PyExc_TypeError, "Expected credentials");
 
341
                talloc_free(mem_ctx);
290
342
                return NULL;
291
343
        }
292
344
 
294
346
 
295
347
        result = reg_open_samba(NULL, &reg_ctx, NULL, 
296
348
                                lp_ctx, session_info, credentials);
 
349
        talloc_free(mem_ctx);
297
350
        if (!W_ERROR_IS_OK(result)) {
298
351
                PyErr_SetWERROR(result);
299
352
                return NULL;
300
353
        }
301
 
        
 
354
 
302
355
        return py_talloc_steal(&PyRegistry, reg_ctx);
303
356
}
304
357
 
338
391
        PyObject *py_session_info = Py_None, *py_credentials = Py_None, *py_lp_ctx = Py_None;
339
392
        WERROR result;
340
393
        char *location;
341
 
    struct loadparm_context *lp_ctx;
342
 
    struct cli_credentials *credentials;
 
394
        struct loadparm_context *lp_ctx;
 
395
        struct cli_credentials *credentials;
343
396
        struct hive_key *key;
344
397
        struct auth_session_info *session_info;
 
398
        TALLOC_CTX *mem_ctx;
345
399
 
346
400
        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO", 
347
 
                                                                         discard_const_p(char *, kwnames), 
348
 
                                                                         &location, 
349
 
                                                                         &py_session_info, &py_credentials,
350
 
                                                                         &py_lp_ctx))
351
 
                return NULL;
352
 
 
353
 
    lp_ctx = lp_from_py_object(py_lp_ctx);
354
 
    if (lp_ctx == NULL) {
 
401
                                         discard_const_p(char *, kwnames),
 
402
                                         &location, &py_session_info,
 
403
                                         &py_credentials, &py_lp_ctx))
 
404
                return NULL;
 
405
 
 
406
        mem_ctx = talloc_new(NULL);
 
407
        if (mem_ctx == NULL) {
 
408
                PyErr_NoMemory();
 
409
                return NULL;
 
410
        }
 
411
 
 
412
        lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
 
413
        if (lp_ctx == NULL) {
355
414
                PyErr_SetString(PyExc_TypeError, "Expected loadparm context");
 
415
                talloc_free(mem_ctx);
356
416
                return NULL;
357
 
    }
 
417
        }
358
418
 
359
419
        credentials = cli_credentials_from_py_object(py_credentials);
360
420
        if (credentials == NULL) {
361
421
                PyErr_SetString(PyExc_TypeError, "Expected credentials");
 
422
                talloc_free(mem_ctx);
362
423
                return NULL;
363
424
        }
364
425
 
365
426
        session_info = NULL; /* FIXME */
366
427
 
367
428
        result = reg_open_ldb_file(NULL, location, session_info, credentials,
368
 
                                                           tevent_context_init(NULL), lp_ctx, &key);
 
429
                                   s4_event_context_init(NULL), lp_ctx, &key);
 
430
        talloc_free(mem_ctx);
369
431
        PyErr_WERROR_IS_ERR_RAISE(result);
370
432
 
371
433
        return py_talloc_steal(&PyHiveKey, key);
400
462
        { "open_directory", py_open_directory, METH_VARARGS, "open_dir(location) -> key" },
401
463
        { "create_directory", py_create_directory, METH_VARARGS, "create_dir(location) -> key" },
402
464
        { "open_ldb", (PyCFunction)py_open_ldb_file, METH_VARARGS|METH_KEYWORDS, "open_ldb(location, session_info=None, credentials=None, loadparm_context=None) -> key" },
 
465
        { "open_hive", (PyCFunction)py_open_hive, METH_VARARGS|METH_KEYWORDS, "open_hive(location, session_info=None, credentials=None, loadparm_context=None) -> key" },
403
466
        { "str_regtype", py_str_regtype, METH_VARARGS, "str_regtype(int) -> str" },
404
467
        { "get_predef_name", py_get_predef_name, METH_VARARGS, "get_predef_name(hkey) -> str" },
405
468
        { NULL }
408
471
void initregistry(void)
409
472
{
410
473
        PyObject *m;
 
474
        PyTypeObject *talloc_type = PyTalloc_GetObjectType();
 
475
 
 
476
        if (talloc_type == NULL)
 
477
                return;
 
478
 
 
479
        PyHiveKey.tp_base = talloc_type;
 
480
        PyRegistry.tp_base = talloc_type;
 
481
        PyRegistryKey.tp_base = talloc_type;
411
482
 
412
483
        if (PyType_Ready(&PyHiveKey) < 0)
413
484
                return;