Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

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

    r414 r740  
    1818*/
    1919
    20 #include <stdint.h>
    21 #include <stdbool.h>
    22 
     20#include <Python.h>
    2321#include "includes.h"
    2422#include "param/param.h"
    2523#include "param/loadparm.h"
    26 #include <Python.h>
    27 #include "pytalloc.h"
     24#include "lib/talloc/pytalloc.h"
     25#include "dynconfig/dynconfig.h"
    2826
    2927/* There's no Py_ssize_t in 2.4, apparently */
     
    3331#endif
    3432
    35 #ifndef Py_RETURN_NONE
    36 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
    37 #endif
    38 
    3933#define PyLoadparmContext_AsLoadparmContext(obj) py_talloc_get_type(obj, struct loadparm_context)
    40 
    41 PyAPI_DATA(PyTypeObject) PyLoadparmContext;
    42 PyAPI_DATA(PyTypeObject) PyLoadparmService;
     34#define PyLoadparmService_AsLoadparmService(obj) py_talloc_get_type(obj, struct loadparm_service)
     35
     36extern PyTypeObject PyLoadparmContext;
     37extern PyTypeObject PyLoadparmService;
    4338
    4439PyObject *PyLoadparmService_FromService(struct loadparm_service *service)
     
    4944static PyObject *py_lp_ctx_get_helper(struct loadparm_context *lp_ctx, const char *service_name, const char *param_name)
    5045{
    51     struct parm_struct *parm = NULL;
    52     void *parm_ptr = NULL;
    53     int i;
    54 
    55     if (service_name != NULL) {
    56         struct loadparm_service *service;
    57         /* its a share parameter */
    58         service = lp_service(lp_ctx, service_name);
    59         if (service == NULL) {
    60             return NULL;
    61         }
    62         if (strchr(param_name, ':')) {
    63             /* its a parametric option on a share */
    64             const char *type = talloc_strndup(lp_ctx,
    65                               param_name,
    66                               strcspn(param_name, ":"));
    67             const char *option = strchr(param_name, ':') + 1;
    68             const char *value;
    69             if (type == NULL || option == NULL) {
    70                 return NULL;
    71             }
    72             value = lp_get_parametric(lp_ctx, service, type, option);
    73             if (value == NULL) {
    74                 return NULL;
    75             }
    76             return PyString_FromString(value);
    77         }
    78 
    79         parm = lp_parm_struct(param_name);
    80         if (parm == NULL || parm->pclass == P_GLOBAL) {
    81             return NULL;
    82         }
    83         parm_ptr = lp_parm_ptr(lp_ctx, service, parm);
     46        struct parm_struct *parm = NULL;
     47        void *parm_ptr = NULL;
     48        int i;
     49
     50        if (service_name != NULL && strwicmp(service_name, GLOBAL_NAME) &&
     51                strwicmp(service_name, GLOBAL_NAME2)) {
     52                struct loadparm_service *service;
     53                /* its a share parameter */
     54                service = lpcfg_service(lp_ctx, service_name);
     55                if (service == NULL) {
     56                        return NULL;
     57                }
     58                if (strchr(param_name, ':')) {
     59                        /* its a parametric option on a share */
     60                        const char *type = talloc_strndup(lp_ctx, param_name,
     61                                                                                          strcspn(param_name, ":"));
     62                        const char *option = strchr(param_name, ':') + 1;
     63                        const char *value;
     64                        if (type == NULL || option == NULL) {
     65                        return NULL;
     66                        }
     67                        value = lpcfg_get_parametric(lp_ctx, service, type, option);
     68                        if (value == NULL) {
     69                        return NULL;
     70                        }
     71                        return PyString_FromString(value);
     72                }
     73
     74                parm = lpcfg_parm_struct(param_name);
     75                if (parm == NULL || parm->pclass == P_GLOBAL) {
     76                        return NULL;
     77                }
     78                parm_ptr = lpcfg_parm_ptr(lp_ctx, service, parm);
    8479    } else if (strchr(param_name, ':')) {
    85         /* its a global parametric option */
    86         const char *type = talloc_strndup(lp_ctx,
    87                           param_name, strcspn(param_name, ":"));
    88         const char *option = strchr(param_name, ':') + 1;
    89         const char *value;
    90         if (type == NULL || option == NULL) {
    91             return NULL;
    92         }
    93         value = lp_get_parametric(lp_ctx, NULL, type, option);
    94         if (value == NULL)
    95             return NULL;
    96         return PyString_FromString(value);
    97     } else {
    98         /* its a global parameter */
    99         parm = lp_parm_struct(param_name);
    100         if (parm == NULL) {
    101             return NULL;
    102         }
    103         parm_ptr = lp_parm_ptr(lp_ctx, NULL, parm);
    104     }
    105 
    106     if (parm == NULL || parm_ptr == NULL) {
    107         return NULL;
     80                /* its a global parametric option */
     81                const char *type = talloc_strndup(lp_ctx,
     82                                  param_name, strcspn(param_name, ":"));
     83                const char *option = strchr(param_name, ':') + 1;
     84                const char *value;
     85                if (type == NULL || option == NULL) {
     86                        return NULL;
     87                }
     88                value = lpcfg_get_parametric(lp_ctx, NULL, type, option);
     89                if (value == NULL)
     90                        return NULL;
     91                return PyString_FromString(value);
     92        } else {
     93                /* its a global parameter */
     94                parm = lpcfg_parm_struct(param_name);
     95                if (parm == NULL) {
     96                        return NULL;
     97                }
     98                parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, parm);
     99        }
     100
     101        if (parm == NULL || parm_ptr == NULL) {
     102                return NULL;
    108103    }
    109104
     
    126121        }
    127122        return NULL;
     123    case P_CMDLIST:
    128124    case P_LIST:
    129125        {
     
    156152                return NULL;
    157153
    158         ret = lp_load(PyLoadparmContext_AsLoadparmContext(self), filename);
     154        ret = lpcfg_load(PyLoadparmContext_AsLoadparmContext(self), filename);
    159155
    160156        if (!ret) {
     
    168164{
    169165        bool ret;
    170         ret = lp_load_default(PyLoadparmContext_AsLoadparmContext(self));
     166        ret = lpcfg_load_default(PyLoadparmContext_AsLoadparmContext(self));
    171167
    172168        if (!ret) {
     
    182178        char *section_name = NULL;
    183179        PyObject *ret;
    184         if (!PyArg_ParseTuple(args, "s|s", &param_name, &section_name))
     180        if (!PyArg_ParseTuple(args, "s|z", &param_name, &section_name))
    185181                return NULL;
    186182
     
    197193                return NULL;
    198194
    199         return PyBool_FromLong(lp_is_myname(PyLoadparmContext_AsLoadparmContext(self), name));
     195        return PyBool_FromLong(lpcfg_is_myname(PyLoadparmContext_AsLoadparmContext(self), name));
    200196}
    201197
     
    206202                return NULL;
    207203
    208         return PyBool_FromLong(lp_is_mydomain(PyLoadparmContext_AsLoadparmContext(self), name));
     204        return PyBool_FromLong(lpcfg_is_mydomain(PyLoadparmContext_AsLoadparmContext(self), name));
    209205}
    210206
     
    216212                return NULL;
    217213
    218         ret = lp_set_cmdline(PyLoadparmContext_AsLoadparmContext(self), name, value);
     214        ret = lpcfg_set_cmdline(PyLoadparmContext_AsLoadparmContext(self), name, value);
    219215        if (!ret) {
    220216                PyErr_SetString(PyExc_RuntimeError, "Unable to set parameter");
     
    244240        PyObject *ret;
    245241        int i;
    246         ret = PyList_New(lp_numservices(lp_ctx));
    247         for (i = 0; i < lp_numservices(lp_ctx); i++) {
    248                 struct loadparm_service *service = lp_servicebynum(lp_ctx, i);
     242        ret = PyList_New(lpcfg_numservices(lp_ctx));
     243        for (i = 0; i < lpcfg_numservices(lp_ctx); i++) {
     244                struct loadparm_service *service = lpcfg_servicebynum(lp_ctx, i);
    249245                if (service != NULL) {
    250                         PyList_SetItem(ret, i, PyString_FromString(lp_servicename(service)));
     246                        PyList_SetItem(ret, i, PyString_FromString(lpcfg_servicename(service)));
    251247                }
    252248        }
    253249        return ret;
    254250}
     251
     252static PyObject *py_lp_dump(PyObject *self, PyObject *args)
     253{
     254        PyObject *py_stream;
     255        bool show_defaults = false;
     256        FILE *f;
     257        struct loadparm_context *lp_ctx = PyLoadparmContext_AsLoadparmContext(self);
     258
     259        if (!PyArg_ParseTuple(args, "O|b", &py_stream, &show_defaults))
     260                return NULL;
     261
     262        f = PyFile_AsFile(py_stream);
     263        if (f == NULL) {
     264                PyErr_SetString(PyExc_TypeError, "Not a file stream");
     265                return NULL;
     266        }
     267
     268        lpcfg_dump(lp_ctx, f, show_defaults, lpcfg_numservices(lp_ctx));
     269
     270        Py_RETURN_NONE;
     271}
     272
    255273
    256274static PyMethodDef py_lp_ctx_methods[] = {
     
    277295        { "services", (PyCFunction)py_lp_ctx_services, METH_NOARGS,
    278296                "S.services() -> list" },
     297        { "dump", (PyCFunction)py_lp_dump, METH_VARARGS,
     298                "S.dump(stream, show_defaults=False)" },
    279299        { NULL }
    280300};
     
    282302static PyObject *py_lp_ctx_default_service(py_talloc_Object *self, void *closure)
    283303{
    284         return PyLoadparmService_FromService(lp_default_service(PyLoadparmContext_AsLoadparmContext(self)));
     304        return PyLoadparmService_FromService(lpcfg_default_service(PyLoadparmContext_AsLoadparmContext(self)));
    285305}
    286306
    287307static PyObject *py_lp_ctx_config_file(py_talloc_Object *self, void *closure)
    288308{
    289         const char *configfile = lp_configfile(PyLoadparmContext_AsLoadparmContext(self));
     309        const char *configfile = lpcfg_configfile(PyLoadparmContext_AsLoadparmContext(self));
    290310        if (configfile == NULL)
    291311                Py_RETURN_NONE;
     
    313333                return NULL;
    314334        }
    315         ret->ptr = loadparm_init(ret->talloc_ctx);
     335        ret->ptr = loadparm_init_global(false);
    316336        return (PyObject *)ret;
    317337}
     
    319339static Py_ssize_t py_lp_ctx_len(py_talloc_Object *self)
    320340{
    321         return lp_numservices(PyLoadparmContext_AsLoadparmContext(self));
     341        return lpcfg_numservices(PyLoadparmContext_AsLoadparmContext(self));
    322342}
    323343
     
    329349                return NULL;
    330350        }
    331         service = lp_service(PyLoadparmContext_AsLoadparmContext(self), PyString_AsString(name));
     351        service = lpcfg_service(PyLoadparmContext_AsLoadparmContext(self), PyString_AsString(name));
    332352        if (service == NULL) {
    333353                PyErr_SetString(PyExc_KeyError, "No such section");
     
    345365        .tp_name = "LoadParm",
    346366        .tp_basicsize = sizeof(py_talloc_Object),
    347         .tp_dealloc = py_talloc_dealloc,
    348367        .tp_getset = py_lp_ctx_getset,
    349368        .tp_methods = py_lp_ctx_methods,
     
    353372};
    354373
     374static PyObject *py_lp_service_dump(PyObject *self, PyObject *args)
     375{
     376        PyObject *py_stream;
     377        bool show_defaults = false;
     378        FILE *f;
     379        struct loadparm_service *service = PyLoadparmService_AsLoadparmService(self);
     380        struct loadparm_service *default_service;
     381        PyObject *py_default_service;
     382
     383        if (!PyArg_ParseTuple(args, "OO|b", &py_stream, &py_default_service,
     384                                                  &show_defaults))
     385                return NULL;
     386
     387        f = PyFile_AsFile(py_stream);
     388        if (f == NULL) {
     389                PyErr_SetString(PyExc_TypeError, "Not a file stream");
     390                return NULL;
     391        }
     392
     393        if (!PyObject_TypeCheck(py_default_service, &PyLoadparmService)) {
     394                PyErr_SetNone(PyExc_TypeError);
     395                return NULL;
     396        }
     397
     398        default_service = PyLoadparmService_AsLoadparmService(py_default_service);
     399
     400        lpcfg_dump_one(f, show_defaults, service, default_service);
     401
     402        Py_RETURN_NONE;
     403}
     404
     405static PyMethodDef py_lp_service_methods[] = {
     406        { "dump", (PyCFunction)py_lp_service_dump, METH_VARARGS,
     407                "S.dump(f, default_service, show_defaults=False)" },
     408        { NULL }
     409};
     410
    355411PyTypeObject PyLoadparmService = {
    356412        .tp_name = "LoadparmService",
    357         .tp_dealloc = py_talloc_dealloc,
    358413        .tp_basicsize = sizeof(py_talloc_Object),
     414        .tp_methods = py_lp_service_methods,
    359415        .tp_flags = Py_TPFLAGS_DEFAULT,
    360416};
     
    363419{
    364420    return PyString_FromString(lp_default_path());
     421}
     422
     423static PyObject *py_setup_dir(PyObject *self)
     424{
     425    return PyString_FromString(dyn_SETUPDIR);
    365426}
    366427
     
    368429    { "default_path", (PyCFunction)py_default_path, METH_NOARGS,
    369430        "Returns the default smb.conf path." },
     431    { "setup_dir", (PyCFunction)py_setup_dir, METH_NOARGS,
     432        "Returns the compiled in location of provision tempates." },
    370433    { NULL }
    371434};
     
    374437{
    375438        PyObject *m;
     439        PyTypeObject *talloc_type = PyTalloc_GetObjectType();
     440        if (talloc_type == NULL)
     441                return;
     442
     443        PyLoadparmContext.tp_base = talloc_type;
     444        PyLoadparmService.tp_base = talloc_type;
    376445
    377446        if (PyType_Ready(&PyLoadparmContext) < 0)
     447                return;
     448
     449        if (PyType_Ready(&PyLoadparmService) < 0)
    378450                return;
    379451
Note: See TracChangeset for help on using the changeset viewer.