49
44
static PyObject *py_lp_ctx_get_helper(struct loadparm_context *lp_ctx, const char *service_name, const char *param_name)
51
struct parm_struct *parm = NULL;
52
void *parm_ptr = NULL;
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) {
62
if (strchr(param_name, ':')) {
63
/* its a parametric option on a share */
64
const char *type = talloc_strndup(lp_ctx,
66
strcspn(param_name, ":"));
67
const char *option = strchr(param_name, ':') + 1;
69
if (type == NULL || option == NULL) {
72
value = lp_get_parametric(lp_ctx, service, type, option);
76
return PyString_FromString(value);
79
parm = lp_parm_struct(param_name);
80
if (parm == NULL || parm->pclass == P_GLOBAL) {
83
parm_ptr = lp_parm_ptr(lp_ctx, service, parm);
46
struct parm_struct *parm = NULL;
47
void *parm_ptr = NULL;
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) {
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;
64
if (type == NULL || option == NULL) {
67
value = lpcfg_get_parametric(lp_ctx, service, type, option);
71
return PyString_FromString(value);
74
parm = lpcfg_parm_struct(param_name);
75
if (parm == NULL || parm->pclass == P_GLOBAL) {
78
parm_ptr = lpcfg_parm_ptr(lp_ctx, service, parm);
84
79
} 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;
90
if (type == NULL || option == NULL) {
93
value = lp_get_parametric(lp_ctx, NULL, type, option);
96
return PyString_FromString(value);
98
/* its a global parameter */
99
parm = lp_parm_struct(param_name);
103
parm_ptr = lp_parm_ptr(lp_ctx, NULL, parm);
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;
85
if (type == NULL || option == NULL) {
88
value = lpcfg_get_parametric(lp_ctx, NULL, type, option);
91
return PyString_FromString(value);
93
/* its a global parameter */
94
parm = lpcfg_parm_struct(param_name);
98
parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, parm);
106
if (parm == NULL || parm_ptr == NULL) {
101
if (parm == NULL || parm_ptr == NULL) {
110
105
/* construct and return the right type of python object */
243
239
struct loadparm_context *lp_ctx = PyLoadparmContext_AsLoadparmContext(self);
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);
249
245
if (service != NULL) {
250
PyList_SetItem(ret, i, PyString_FromString(lp_servicename(service)));
246
PyList_SetItem(ret, i, PyString_FromString(lpcfg_servicename(service)));
252
static PyObject *py_lp_dump(PyObject *self, PyObject *args)
255
bool show_defaults = false;
257
struct loadparm_context *lp_ctx = PyLoadparmContext_AsLoadparmContext(self);
259
if (!PyArg_ParseTuple(args, "O|b", &py_stream, &show_defaults))
262
f = PyFile_AsFile(py_stream);
264
PyErr_SetString(PyExc_TypeError, "Not a file stream");
268
lpcfg_dump(lp_ctx, f, show_defaults, lpcfg_numservices(lp_ctx));
256
274
static PyMethodDef py_lp_ctx_methods[] = {
257
275
{ "load", (PyCFunction)py_lp_ctx_load, METH_VARARGS,
258
276
"S.load(filename) -> None\n"
276
294
"S.private_path(name) -> path\n" },
277
295
{ "services", (PyCFunction)py_lp_ctx_services, METH_NOARGS,
278
296
"S.services() -> list" },
297
{ "dump", (PyCFunction)py_lp_dump, METH_VARARGS,
298
"S.dump(stream, show_defaults=False)" },
282
302
static PyObject *py_lp_ctx_default_service(py_talloc_Object *self, void *closure)
284
return PyLoadparmService_FromService(lp_default_service(PyLoadparmContext_AsLoadparmContext(self)));
304
return PyLoadparmService_FromService(lpcfg_default_service(PyLoadparmContext_AsLoadparmContext(self)));
287
307
static PyObject *py_lp_ctx_config_file(py_talloc_Object *self, void *closure)
289
const char *configfile = lp_configfile(PyLoadparmContext_AsLoadparmContext(self));
309
const char *configfile = lpcfg_configfile(PyLoadparmContext_AsLoadparmContext(self));
290
310
if (configfile == NULL)
352
371
.tp_flags = Py_TPFLAGS_DEFAULT,
374
static PyObject *py_lp_service_dump(PyObject *self, PyObject *args)
377
bool show_defaults = false;
379
struct loadparm_service *service = PyLoadparmService_AsLoadparmService(self);
380
struct loadparm_service *default_service;
381
PyObject *py_default_service;
383
if (!PyArg_ParseTuple(args, "OO|b", &py_stream, &py_default_service,
387
f = PyFile_AsFile(py_stream);
389
PyErr_SetString(PyExc_TypeError, "Not a file stream");
393
if (!PyObject_TypeCheck(py_default_service, &PyLoadparmService)) {
394
PyErr_SetNone(PyExc_TypeError);
398
default_service = PyLoadparmService_AsLoadparmService(py_default_service);
400
lpcfg_dump_one(f, show_defaults, service, default_service);
405
static PyMethodDef py_lp_service_methods[] = {
406
{ "dump", (PyCFunction)py_lp_service_dump, METH_VARARGS,
407
"S.dump(f, default_service, show_defaults=False)" },
355
411
PyTypeObject PyLoadparmService = {
356
412
.tp_name = "LoadparmService",
357
.tp_dealloc = py_talloc_dealloc,
358
413
.tp_basicsize = sizeof(py_talloc_Object),
414
.tp_methods = py_lp_service_methods,
359
415
.tp_flags = Py_TPFLAGS_DEFAULT,
364
420
return PyString_FromString(lp_default_path());
423
static PyObject *py_setup_dir(PyObject *self)
425
return PyString_FromString(dyn_SETUPDIR);
367
428
static PyMethodDef pyparam_methods[] = {
368
429
{ "default_path", (PyCFunction)py_default_path, METH_NOARGS,
369
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." },
373
436
void initparam(void)
439
PyTypeObject *talloc_type = PyTalloc_GetObjectType();
440
if (talloc_type == NULL)
443
PyLoadparmContext.tp_base = talloc_type;
444
PyLoadparmService.tp_base = talloc_type;
377
446
if (PyType_Ready(&PyLoadparmContext) < 0)
449
if (PyType_Ready(&PyLoadparmService) < 0)
380
452
m = Py_InitModule3("param", pyparam_methods, "Parsing and writing Samba configuration files.");