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/lib/registry/pyregistry.c

    r414 r745  
    33   Samba utility functions
    44   Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
     5   Copyright (C) Wilco Baan Hofman <wilco@baanhofman.nl> 2010
    56   
    67   This program is free software; you can redistribute it and/or modify
     
    1819*/
    1920
     21#include <Python.h>
    2022#include "includes.h"
    21 #include <tevent.h>
    22 #include <Python.h>
    2323#include "libcli/util/pyerrors.h"
    2424#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"
    2727#include "auth/credentials/pycredentials.h"
    2828#include "param/pyparam.h"
    2929
    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;
     30extern PyTypeObject PyRegistryKey;
     31extern PyTypeObject PyRegistry;
     32extern PyTypeObject PyHiveKey;
    3733
    3834/*#define PyRegistryKey_AsRegistryKey(obj) py_talloc_get_type(obj, struct registry_key)*/
     
    9692                return NULL;
    9793
    98         result = reg_diff_apply(ctx, py_iconv_convenience(NULL), filename);
     94        result = reg_diff_apply(ctx, filename);
    9995        PyErr_WERROR_IS_ERR_RAISE(result);
    10096
     
    164160        .tp_new = registry_new,
    165161        .tp_basicsize = sizeof(py_talloc_Object),
    166         .tp_dealloc = py_talloc_dealloc,
    167162        .tp_flags = Py_TPFLAGS_DEFAULT,
    168163};
     
    177172                return NULL;
    178173
    179         result = hive_key_del(key, name);
     174        result = hive_key_del(NULL, key, name);
    180175
    181176        PyErr_WERROR_IS_ERR_RAISE(result);
     
    204199                return NULL;
    205200
    206         result = hive_key_del_value(key, name);
     201        result = hive_key_del_value(NULL, key, name);
    207202
    208203        PyErr_WERROR_IS_ERR_RAISE(result);
     
    225220                result = hive_key_set_value(key, name, type, value);
    226221        else
    227                 result = hive_key_del_value(key, name);
     222                result = hive_key_del_value(NULL, key, name);
    228223
    229224        PyErr_WERROR_IS_ERR_RAISE(result);
     
    244239};
    245240
    246 static PyObject *hive_open(PyTypeObject *type, PyObject *args, PyObject *kwargs)
    247 {
    248         /* reg_open_hive */
     241static PyObject *hive_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) {
    249242        Py_RETURN_NONE;
     243}
     244
     245static PyObject *py_open_hive(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     246{
     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);
    250292}
    251293
     
    253295        .tp_name = "HiveKey",
    254296        .tp_methods = hive_key_methods,
    255         .tp_new = hive_open,
     297        .tp_new = hive_new,
    256298        .tp_basicsize = sizeof(py_talloc_Object),
    257         .tp_dealloc = py_talloc_dealloc,
    258299        .tp_flags = Py_TPFLAGS_DEFAULT,
    259300};
     
    262303        .tp_name = "RegistryKey",
    263304        .tp_basicsize = sizeof(py_talloc_Object),
    264         .tp_dealloc = py_talloc_dealloc,
    265305        .tp_flags = Py_TPFLAGS_DEFAULT,
    266306};
     
    271311        struct registry_context *reg_ctx;
    272312        WERROR result;
    273     struct loadparm_context *lp_ctx;
     313        struct loadparm_context *lp_ctx;
    274314        PyObject *py_lp_ctx, *py_session_info, *py_credentials;
    275315        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) {
    283333                PyErr_SetString(PyExc_TypeError, "Expected loadparm context");
    284                 return NULL;
    285     }
     334                talloc_free(mem_ctx);
     335                return NULL;
     336        }
    286337
    287338        credentials = cli_credentials_from_py_object(py_credentials);
    288339        if (credentials == NULL) {
    289340                PyErr_SetString(PyExc_TypeError, "Expected credentials");
     341                talloc_free(mem_ctx);
    290342                return NULL;
    291343        }
     
    295347        result = reg_open_samba(NULL, &reg_ctx, NULL,
    296348                                lp_ctx, session_info, credentials);
     349        talloc_free(mem_ctx);
    297350        if (!W_ERROR_IS_OK(result)) {
    298351                PyErr_SetWERROR(result);
    299352                return NULL;
    300353        }
    301        
     354
    302355        return py_talloc_steal(&PyRegistry, reg_ctx);
    303356}
     
    339392        WERROR result;
    340393        char *location;
    341     struct loadparm_context *lp_ctx;
    342     struct cli_credentials *credentials;
     394        struct loadparm_context *lp_ctx;
     395        struct cli_credentials *credentials;
    343396        struct hive_key *key;
    344397        struct auth_session_info *session_info;
     398        TALLOC_CTX *mem_ctx;
    345399
    346400        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) {
    355414                PyErr_SetString(PyExc_TypeError, "Expected loadparm context");
    356                 return NULL;
    357     }
     415                talloc_free(mem_ctx);
     416                return NULL;
     417        }
    358418
    359419        credentials = cli_credentials_from_py_object(py_credentials);
    360420        if (credentials == NULL) {
    361421                PyErr_SetString(PyExc_TypeError, "Expected credentials");
     422                talloc_free(mem_ctx);
    362423                return NULL;
    363424        }
     
    366427
    367428        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);
    369431        PyErr_WERROR_IS_ERR_RAISE(result);
    370432
     
    401463        { "create_directory", py_create_directory, METH_VARARGS, "create_dir(location) -> key" },
    402464        { "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" },
    403466        { "str_regtype", py_str_regtype, METH_VARARGS, "str_regtype(int) -> str" },
    404467        { "get_predef_name", py_get_predef_name, METH_VARARGS, "get_predef_name(hkey) -> str" },
     
    409472{
    410473        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;
    411482
    412483        if (PyType_Ready(&PyHiveKey) < 0)
Note: See TracChangeset for help on using the changeset viewer.