Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source4/param/pyparam.c

    r740 r988  
    2222#include "param/param.h"
    2323#include "param/loadparm.h"
    24 #include "lib/talloc/pytalloc.h"
     24#include <pytalloc.h>
    2525#include "dynconfig/dynconfig.h"
    2626
    27 /* There's no Py_ssize_t in 2.4, apparently */
    28 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5
    29 typedef int Py_ssize_t;
    30 typedef inquiry lenfunc;
    31 #endif
    32 
    33 #define PyLoadparmContext_AsLoadparmContext(obj) py_talloc_get_type(obj, struct loadparm_context)
    34 #define PyLoadparmService_AsLoadparmService(obj) py_talloc_get_type(obj, struct loadparm_service)
     27void initparam(void);
     28
     29#define PyLoadparmContext_AsLoadparmContext(obj) pytalloc_get_type(obj, struct loadparm_context)
     30#define PyLoadparmService_AsLoadparmService(obj) pytalloc_get_type(obj, struct loadparm_service)
    3531
    3632extern PyTypeObject PyLoadparmContext;
    3733extern PyTypeObject PyLoadparmService;
    3834
    39 PyObject *PyLoadparmService_FromService(struct loadparm_service *service)
    40 {
    41         return py_talloc_reference(&PyLoadparmService, service);
     35static PyObject *PyLoadparmService_FromService(struct loadparm_service *service)
     36{
     37        return pytalloc_reference(&PyLoadparmService, service);
    4238}
    4339
     
    7268                }
    7369
    74                 parm = lpcfg_parm_struct(param_name);
    75                 if (parm == NULL || parm->pclass == P_GLOBAL) {
     70                parm = lpcfg_parm_struct(lp_ctx, param_name);
     71                if (parm == NULL || parm->p_class == P_GLOBAL) {
    7672                        return NULL;
    7773                }
     
    9288        } else {
    9389                /* its a global parameter */
    94                 parm = lpcfg_parm_struct(param_name);
     90                parm = lpcfg_parm_struct(lp_ctx, param_name);
    9591                if (parm == NULL) {
    9692                        return NULL;
     
    105101    /* construct and return the right type of python object */
    106102    switch (parm->type) {
     103    case P_CHAR:
     104        return PyString_FromFormat("%c", *(char *)parm_ptr);
    107105    case P_STRING:
    108106    case P_USTRING:
     
    110108    case P_BOOL:
    111109        return PyBool_FromLong(*(bool *)parm_ptr);
     110    case P_BOOLREV:
     111        return PyBool_FromLong(!(*(bool *)parm_ptr));
    112112    case P_INTEGER:
    113113    case P_OCTAL:
     
    138138            return pylist;
    139139        }
    140 
    141         break;
    142140    }
    143141    return NULL;
     
    145143}
    146144
    147 static PyObject *py_lp_ctx_load(py_talloc_Object *self, PyObject *args)
     145static PyObject *py_lp_ctx_load(PyObject *self, PyObject *args)
    148146{
    149147        char *filename;
     
    161159}
    162160
    163 static PyObject *py_lp_ctx_load_default(py_talloc_Object *self)
     161static PyObject *py_lp_ctx_load_default(PyObject *self, PyObject *unused)
    164162{
    165163        bool ret;
     
    173171}
    174172
    175 static PyObject *py_lp_ctx_get(py_talloc_Object *self, PyObject *args)
     173static PyObject *py_lp_ctx_get(PyObject *self, PyObject *args)
    176174{
    177175        char *param_name;
     
    187185}
    188186
    189 static PyObject *py_lp_ctx_is_myname(py_talloc_Object *self, PyObject *args)
     187static PyObject *py_lp_ctx_is_myname(PyObject *self, PyObject *args)
    190188{
    191189        char *name;
     
    196194}
    197195
    198 static PyObject *py_lp_ctx_is_mydomain(py_talloc_Object *self, PyObject *args)
     196static PyObject *py_lp_ctx_is_mydomain(PyObject *self, PyObject *args)
    199197{
    200198        char *name;
     
    205203}
    206204
    207 static PyObject *py_lp_ctx_set(py_talloc_Object *self, PyObject *args)
     205static PyObject *py_lp_ctx_set(PyObject *self, PyObject *args)
    208206{
    209207        char *name, *value;
     
    221219}
    222220
    223 static PyObject *py_lp_ctx_private_path(py_talloc_Object *self, PyObject *args)
     221static PyObject *py_lp_ctx_private_path(PyObject *self, PyObject *args)
    224222{
    225223        char *name, *path;
     
    228226                return NULL;
    229227
    230         path = private_path(NULL, PyLoadparmContext_AsLoadparmContext(self), name);
     228        path = lpcfg_private_path(NULL, PyLoadparmContext_AsLoadparmContext(self), name);
    231229        ret = PyString_FromString(path);
    232230        talloc_free(path);
     
    235233}
    236234
    237 static PyObject *py_lp_ctx_services(py_talloc_Object *self)
     235static PyObject *py_lp_ctx_services(PyObject *self, PyObject *unused)
    238236{
    239237        struct loadparm_context *lp_ctx = PyLoadparmContext_AsLoadparmContext(self);
     
    250248}
    251249
     250static PyObject *py_lp_ctx_server_role(PyObject *self, PyObject *unused)
     251{
     252        struct loadparm_context *lp_ctx = PyLoadparmContext_AsLoadparmContext(self);
     253        uint32_t role;
     254        const char *role_str;
     255
     256        role = lpcfg_server_role(lp_ctx);
     257        role_str = server_role_str(role);
     258
     259        return PyString_FromString(role_str);
     260}
     261
    252262static PyObject *py_lp_dump(PyObject *self, PyObject *args)
    253263{
     
    262272        f = PyFile_AsFile(py_stream);
    263273        if (f == NULL) {
    264                 PyErr_SetString(PyExc_TypeError, "Not a file stream");
    265274                return NULL;
    266275        }
     
    271280}
    272281
     282static PyObject *py_lp_dump_a_parameter(PyObject *self, PyObject *args)
     283{
     284        PyObject *py_stream;
     285        char *param_name;
     286        const char *section_name = NULL;
     287        FILE *f;
     288        struct loadparm_context *lp_ctx = PyLoadparmContext_AsLoadparmContext(self);
     289        struct loadparm_service *service;
     290        bool ret;
     291
     292        if (!PyArg_ParseTuple(args, "Os|z", &py_stream, &param_name, &section_name))
     293                return NULL;
     294
     295        f = PyFile_AsFile(py_stream);
     296        if (f == NULL) {
     297                return NULL;
     298        }
     299
     300        if (section_name != NULL && strwicmp(section_name, GLOBAL_NAME) &&
     301                strwicmp(section_name, GLOBAL_NAME2)) {
     302                /* it's a share parameter */
     303                service = lpcfg_service(lp_ctx, section_name);
     304                if (service == NULL) {
     305                        PyErr_Format(PyExc_RuntimeError, "Unknown section %s", section_name);
     306                        return NULL;
     307                }
     308        } else {
     309                /* it's global */
     310                service = NULL;
     311                section_name = "global";
     312        }
     313
     314        ret = lpcfg_dump_a_parameter(lp_ctx, service, param_name, f);
     315
     316        if (!ret) {
     317                PyErr_Format(PyExc_RuntimeError, "Parameter %s unknown for section %s", param_name, section_name);
     318                return NULL;
     319        }
     320
     321        Py_RETURN_NONE;
     322
     323}
     324
     325static PyObject *py_samdb_url(PyObject *self, PyObject *unused)
     326{
     327        struct loadparm_context *lp_ctx = PyLoadparmContext_AsLoadparmContext(self);
     328        return PyString_FromFormat("tdb://%s/sam.ldb", lpcfg_private_dir(lp_ctx));
     329}
     330
    273331
    274332static PyMethodDef py_lp_ctx_methods[] = {
    275         { "load", (PyCFunction)py_lp_ctx_load, METH_VARARGS,
     333        { "load", py_lp_ctx_load, METH_VARARGS,
    276334                "S.load(filename) -> None\n"
    277335                "Load specified file." },
    278         { "load_default", (PyCFunction)py_lp_ctx_load_default, METH_NOARGS,
     336        { "load_default", py_lp_ctx_load_default, METH_NOARGS,
    279337                "S.load_default() -> None\n"
    280338                "Load default smb.conf file." },
    281         { "is_myname", (PyCFunction)py_lp_ctx_is_myname, METH_VARARGS,
     339        { "is_myname", py_lp_ctx_is_myname, METH_VARARGS,
    282340                "S.is_myname(name) -> bool\n"
    283341                "Check whether the specified name matches one of our netbios names." },
    284         { "is_mydomain", (PyCFunction)py_lp_ctx_is_mydomain, METH_VARARGS,
     342        { "is_mydomain", py_lp_ctx_is_mydomain, METH_VARARGS,
    285343                "S.is_mydomain(name) -> bool\n"
    286344                "Check whether the specified name matches our domain name." },
    287         { "get", (PyCFunction)py_lp_ctx_get, METH_VARARGS,
     345        { "get", py_lp_ctx_get, METH_VARARGS,
    288346                "S.get(name, service_name) -> value\n"
    289347                "Find specified parameter." },
    290         { "set", (PyCFunction)py_lp_ctx_set, METH_VARARGS,
     348        { "set", py_lp_ctx_set, METH_VARARGS,
    291349                "S.set(name, value) -> bool\n"
    292350                "Change a parameter." },
    293         { "private_path", (PyCFunction)py_lp_ctx_private_path, METH_VARARGS,
     351        { "private_path", py_lp_ctx_private_path, METH_VARARGS,
    294352                "S.private_path(name) -> path\n" },
    295         { "services", (PyCFunction)py_lp_ctx_services, METH_NOARGS,
     353        { "services", py_lp_ctx_services, METH_NOARGS,
    296354                "S.services() -> list" },
    297         { "dump", (PyCFunction)py_lp_dump, METH_VARARGS,
     355        { "server_role", py_lp_ctx_server_role, METH_NOARGS,
     356                "S.server_role() -> value\n"
     357                "Get the server role." },
     358        { "dump", py_lp_dump, METH_VARARGS,
    298359                "S.dump(stream, show_defaults=False)" },
     360        { "dump_a_parameter", py_lp_dump_a_parameter, METH_VARARGS,
     361                "S.dump_a_parameter(stream, name, service_name)" },
     362        { "samdb_url", py_samdb_url, METH_NOARGS,
     363                "S.samdb_url() -> string\n"
     364                "Returns the current URL for sam.ldb." },
    299365        { NULL }
    300366};
    301367
    302 static PyObject *py_lp_ctx_default_service(py_talloc_Object *self, void *closure)
     368static PyObject *py_lp_ctx_default_service(PyObject *self, void *closure)
    303369{
    304370        return PyLoadparmService_FromService(lpcfg_default_service(PyLoadparmContext_AsLoadparmContext(self)));
    305371}
    306372
    307 static PyObject *py_lp_ctx_config_file(py_talloc_Object *self, void *closure)
     373static PyObject *py_lp_ctx_config_file(PyObject *self, void *closure)
    308374{
    309375        const char *configfile = lpcfg_configfile(PyLoadparmContext_AsLoadparmContext(self));
     
    323389static PyObject *py_lp_ctx_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
    324390{
    325         py_talloc_Object *ret = (py_talloc_Object *)type->tp_alloc(type, 0);
    326         if (ret == NULL) {
    327                 PyErr_NoMemory();
    328                 return NULL;
    329         }
    330         ret->talloc_ctx = talloc_new(NULL);
    331         if (ret->talloc_ctx == NULL) {
    332                 PyErr_NoMemory();
    333                 return NULL;
    334         }
    335         ret->ptr = loadparm_init_global(false);
    336         return (PyObject *)ret;
    337 }
    338 
    339 static Py_ssize_t py_lp_ctx_len(py_talloc_Object *self)
     391        return pytalloc_reference(type, loadparm_init_global(false));
     392}
     393
     394static Py_ssize_t py_lp_ctx_len(PyObject *self)
    340395{
    341396        return lpcfg_numservices(PyLoadparmContext_AsLoadparmContext(self));
    342397}
    343398
    344 static PyObject *py_lp_ctx_getitem(py_talloc_Object *self, PyObject *name)
     399static PyObject *py_lp_ctx_getitem(PyObject *self, PyObject *name)
    345400{
    346401        struct loadparm_service *service;
     
    363418
    364419PyTypeObject PyLoadparmContext = {
    365         .tp_name = "LoadParm",
    366         .tp_basicsize = sizeof(py_talloc_Object),
     420        .tp_name = "param.LoadParm",
    367421        .tp_getset = py_lp_ctx_getset,
    368422        .tp_methods = py_lp_ctx_methods,
     
    387441        f = PyFile_AsFile(py_stream);
    388442        if (f == NULL) {
    389                 PyErr_SetString(PyExc_TypeError, "Not a file stream");
    390443                return NULL;
    391444        }
     
    410463
    411464PyTypeObject PyLoadparmService = {
    412         .tp_name = "LoadparmService",
    413         .tp_basicsize = sizeof(py_talloc_Object),
     465        .tp_name = "param.LoadparmService",
    414466        .tp_methods = py_lp_service_methods,
    415467        .tp_flags = Py_TPFLAGS_DEFAULT,
     
    418470static PyObject *py_default_path(PyObject *self)
    419471{
    420     return PyString_FromString(lp_default_path());
     472        return PyString_FromString(lp_default_path());
    421473}
    422474
    423475static PyObject *py_setup_dir(PyObject *self)
    424476{
    425     return PyString_FromString(dyn_SETUPDIR);
     477        return PyString_FromString(dyn_SETUPDIR);
     478}
     479
     480static PyObject *py_modules_dir(PyObject *self)
     481{
     482        return PyString_FromString(dyn_MODULESDIR);
     483}
     484
     485static PyObject *py_bin_dir(PyObject *self)
     486{
     487        return PyString_FromString(dyn_BINDIR);
     488}
     489
     490static PyObject *py_sbin_dir(PyObject *self)
     491{
     492        return PyString_FromString(dyn_SBINDIR);
    426493}
    427494
    428495static PyMethodDef pyparam_methods[] = {
    429     { "default_path", (PyCFunction)py_default_path, METH_NOARGS,
    430         "Returns the default smb.conf path." },
    431     { "setup_dir", (PyCFunction)py_setup_dir, METH_NOARGS,
    432         "Returns the compiled in location of provision tempates." },
    433     { NULL }
     496        { "default_path", (PyCFunction)py_default_path, METH_NOARGS,
     497                "Returns the default smb.conf path." },
     498        { "setup_dir", (PyCFunction)py_setup_dir, METH_NOARGS,
     499                "Returns the compiled in location of provision tempates." },
     500        { "modules_dir", (PyCFunction)py_modules_dir, METH_NOARGS,
     501                "Returns the compiled in location of modules." },
     502        { "bin_dir", (PyCFunction)py_bin_dir, METH_NOARGS,
     503                "Returns the compiled in BINDIR." },
     504        { "sbin_dir", (PyCFunction)py_sbin_dir, METH_NOARGS,
     505                "Returns the compiled in SBINDIR." },
     506        { NULL }
    434507};
    435508
     
    437510{
    438511        PyObject *m;
    439         PyTypeObject *talloc_type = PyTalloc_GetObjectType();
    440         if (talloc_type == NULL)
     512
     513        if (pytalloc_BaseObject_PyType_Ready(&PyLoadparmContext) < 0)
    441514                return;
    442515
    443         PyLoadparmContext.tp_base = talloc_type;
    444         PyLoadparmService.tp_base = talloc_type;
    445 
    446         if (PyType_Ready(&PyLoadparmContext) < 0)
    447                 return;
    448 
    449         if (PyType_Ready(&PyLoadparmService) < 0)
     516        if (pytalloc_BaseObject_PyType_Ready(&PyLoadparmService) < 0)
    450517                return;
    451518
Note: See TracChangeset for help on using the changeset viewer.