Changeset 745 for trunk/server/source4/param/pyparam_util.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source4/param/pyparam_util.c
r414 r745 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" 28 25 29 26 #define PyLoadparmContext_AsLoadparmContext(obj) py_talloc_get_type(obj, struct loadparm_context) 30 27 31 _PUBLIC_ struct loadparm_context *lp _from_py_object(PyObject *py_obj)28 _PUBLIC_ struct loadparm_context *lpcfg_from_py_object(TALLOC_CTX *mem_ctx, PyObject *py_obj) 32 29 { 33 struct loadparm_context *lp_ctx; 30 struct loadparm_context *lp_ctx; 31 PyObject *param_mod; 32 PyTypeObject *lp_type; 33 bool is_lpobj; 34 34 35 if (PyString_Check(py_obj)) { 36 lp_ctx = loadparm_init(NULL); 37 if (!lp_load(lp_ctx, PyString_AsString(py_obj))) { 38 talloc_free(lp_ctx); 35 if (PyString_Check(py_obj)) { 36 lp_ctx = loadparm_init_global(false); 37 if (!lpcfg_load(lp_ctx, PyString_AsString(py_obj))) { 39 38 PyErr_Format(PyExc_RuntimeError, "Unable to load %s", 40 41 42 43 44 39 PyString_AsString(py_obj)); 40 return NULL; 41 } 42 return lp_ctx; 43 } 45 44 46 if (py_obj == Py_None) { 47 lp_ctx = loadparm_init(NULL); 48 /* We're not checking that loading the file succeeded *on purpose */ 49 lp_load_default(lp_ctx); 50 return lp_ctx; 51 } 45 if (py_obj == Py_None) { 46 return loadparm_init_global(true); 47 } 52 48 53 return PyLoadparmContext_AsLoadparmContext(py_obj); 49 param_mod = PyImport_ImportModule("samba.param"); 50 if (param_mod == NULL) { 51 return NULL; 52 } 53 54 lp_type = (PyTypeObject *)PyObject_GetAttrString(param_mod, "LoadParm"); 55 Py_DECREF(param_mod); 56 if (lp_type == NULL) { 57 PyErr_SetString(PyExc_RuntimeError, "Unable to import LoadParm"); 58 return NULL; 59 } 60 61 is_lpobj = PyObject_TypeCheck(py_obj, lp_type); 62 Py_DECREF(lp_type); 63 if (is_lpobj) { 64 return talloc_reference(mem_ctx, PyLoadparmContext_AsLoadparmContext(py_obj)); 65 } 66 67 PyErr_SetNone(PyExc_TypeError); 68 return NULL; 54 69 } 55 70 56 71 struct loadparm_context *py_default_loadparm_context(TALLOC_CTX *mem_ctx) 57 72 { 58 struct loadparm_context *ret; 59 ret = loadparm_init(mem_ctx); 60 if (!lp_load_default(ret)) 61 return NULL; 62 return ret; 73 return loadparm_init_global(true); 63 74 } 64 75
Note:
See TracChangeset
for help on using the changeset viewer.