Changeset 740 for vendor/current/source4/param/pyparam.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source4/param/pyparam.c
r414 r740 18 18 */ 19 19 20 #include <stdint.h> 21 #include <stdbool.h> 22 20 #include <Python.h> 23 21 #include "includes.h" 24 22 #include "param/param.h" 25 23 #include "param/loadparm.h" 26 #include <Python.h>27 #include " pytalloc.h"24 #include "lib/talloc/pytalloc.h" 25 #include "dynconfig/dynconfig.h" 28 26 29 27 /* There's no Py_ssize_t in 2.4, apparently */ … … 33 31 #endif 34 32 35 #ifndef Py_RETURN_NONE36 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None37 #endif38 39 33 #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 36 extern PyTypeObject PyLoadparmContext; 37 extern PyTypeObject PyLoadparmService; 43 38 44 39 PyObject *PyLoadparmService_FromService(struct loadparm_service *service) … … 49 44 static PyObject *py_lp_ctx_get_helper(struct loadparm_context *lp_ctx, const char *service_name, const char *param_name) 50 45 { 51 52 53 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 67 68 69 70 return NULL;71 72 value = lp_get_parametric(lp_ctx, service, type, option);73 74 return NULL;75 76 77 }78 79 parm = lp_parm_struct(param_name);80 if (parm == NULL || parm->pclass == P_GLOBAL) {81 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); 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;89 const char *value;90 if (type == NULL || option == NULL) {91 92 }93 value = lp_get_parametric(lp_ctx, NULL, type, option);94 if (value == NULL)95 96 return PyString_FromString(value);97 98 /* its a global parameter */99 parm = lp_parm_struct(param_name);100 if (parm == NULL) {101 102 }103 parm_ptr = lp_parm_ptr(lp_ctx, NULL, parm);104 105 106 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; 108 103 } 109 104 … … 126 121 } 127 122 return NULL; 123 case P_CMDLIST: 128 124 case P_LIST: 129 125 { … … 156 152 return NULL; 157 153 158 ret = lp _load(PyLoadparmContext_AsLoadparmContext(self), filename);154 ret = lpcfg_load(PyLoadparmContext_AsLoadparmContext(self), filename); 159 155 160 156 if (!ret) { … … 168 164 { 169 165 bool ret; 170 ret = lp _load_default(PyLoadparmContext_AsLoadparmContext(self));166 ret = lpcfg_load_default(PyLoadparmContext_AsLoadparmContext(self)); 171 167 172 168 if (!ret) { … … 182 178 char *section_name = NULL; 183 179 PyObject *ret; 184 if (!PyArg_ParseTuple(args, "s| s", ¶m_name, §ion_name))180 if (!PyArg_ParseTuple(args, "s|z", ¶m_name, §ion_name)) 185 181 return NULL; 186 182 … … 197 193 return NULL; 198 194 199 return PyBool_FromLong(lp _is_myname(PyLoadparmContext_AsLoadparmContext(self), name));195 return PyBool_FromLong(lpcfg_is_myname(PyLoadparmContext_AsLoadparmContext(self), name)); 200 196 } 201 197 … … 206 202 return NULL; 207 203 208 return PyBool_FromLong(lp _is_mydomain(PyLoadparmContext_AsLoadparmContext(self), name));204 return PyBool_FromLong(lpcfg_is_mydomain(PyLoadparmContext_AsLoadparmContext(self), name)); 209 205 } 210 206 … … 216 212 return NULL; 217 213 218 ret = lp _set_cmdline(PyLoadparmContext_AsLoadparmContext(self), name, value);214 ret = lpcfg_set_cmdline(PyLoadparmContext_AsLoadparmContext(self), name, value); 219 215 if (!ret) { 220 216 PyErr_SetString(PyExc_RuntimeError, "Unable to set parameter"); … … 244 240 PyObject *ret; 245 241 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); 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))); 251 247 } 252 248 } 253 249 return ret; 254 250 } 251 252 static 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 255 273 256 274 static PyMethodDef py_lp_ctx_methods[] = { … … 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)" }, 279 299 { NULL } 280 300 }; … … 282 302 static PyObject *py_lp_ctx_default_service(py_talloc_Object *self, void *closure) 283 303 { 284 return PyLoadparmService_FromService(lp _default_service(PyLoadparmContext_AsLoadparmContext(self)));304 return PyLoadparmService_FromService(lpcfg_default_service(PyLoadparmContext_AsLoadparmContext(self))); 285 305 } 286 306 287 307 static PyObject *py_lp_ctx_config_file(py_talloc_Object *self, void *closure) 288 308 { 289 const char *configfile = lp _configfile(PyLoadparmContext_AsLoadparmContext(self));309 const char *configfile = lpcfg_configfile(PyLoadparmContext_AsLoadparmContext(self)); 290 310 if (configfile == NULL) 291 311 Py_RETURN_NONE; … … 313 333 return NULL; 314 334 } 315 ret->ptr = loadparm_init (ret->talloc_ctx);335 ret->ptr = loadparm_init_global(false); 316 336 return (PyObject *)ret; 317 337 } … … 319 339 static Py_ssize_t py_lp_ctx_len(py_talloc_Object *self) 320 340 { 321 return lp _numservices(PyLoadparmContext_AsLoadparmContext(self));341 return lpcfg_numservices(PyLoadparmContext_AsLoadparmContext(self)); 322 342 } 323 343 … … 329 349 return NULL; 330 350 } 331 service = lp _service(PyLoadparmContext_AsLoadparmContext(self), PyString_AsString(name));351 service = lpcfg_service(PyLoadparmContext_AsLoadparmContext(self), PyString_AsString(name)); 332 352 if (service == NULL) { 333 353 PyErr_SetString(PyExc_KeyError, "No such section"); … … 345 365 .tp_name = "LoadParm", 346 366 .tp_basicsize = sizeof(py_talloc_Object), 347 .tp_dealloc = py_talloc_dealloc,348 367 .tp_getset = py_lp_ctx_getset, 349 368 .tp_methods = py_lp_ctx_methods, … … 353 372 }; 354 373 374 static 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 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)" }, 408 { NULL } 409 }; 410 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, 360 416 }; … … 363 419 { 364 420 return PyString_FromString(lp_default_path()); 421 } 422 423 static PyObject *py_setup_dir(PyObject *self) 424 { 425 return PyString_FromString(dyn_SETUPDIR); 365 426 } 366 427 … … 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." }, 370 433 { NULL } 371 434 }; … … 374 437 { 375 438 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; 376 445 377 446 if (PyType_Ready(&PyLoadparmContext) < 0) 447 return; 448 449 if (PyType_Ready(&PyLoadparmService) < 0) 378 450 return; 379 451
Note:
See TracChangeset
for help on using the changeset viewer.