From 6d139d6b0f3d38be395626a7fb4e8d02151102ab Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Fri, 12 Aug 2011 15:48:03 +1000 Subject: [PATCH] s3-param: Add python wrapper for s3 parameters This provids a get_context() method to return s3 context as s4 context type. Pair-Programmed-With: Andrew Bartlett --- source3/param/pyparam.c | 87 +++++++++++++++++++++++++++++++++++++++++ source3/wscript_build | 7 ++++ 2 files changed, 94 insertions(+) create mode 100644 source3/param/pyparam.c diff --git a/source3/param/pyparam.c b/source3/param/pyparam.c new file mode 100644 index 00000000000..ff234ac918d --- /dev/null +++ b/source3/param/pyparam.c @@ -0,0 +1,87 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Amitay Isaacs 2011 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include "includes.h" +#include "param/param.h" +#include "param/loadparm.h" +#include "lib/talloc/pytalloc.h" + +static PyTypeObject *loadparm_Type = NULL; + +void initparam(void); + +static PyObject *py_get_context(PyObject *self) +{ + PyObject *py_loadparm; + const struct loadparm_s3_context *s3_context; + const struct loadparm_context *s4_context; + TALLOC_CTX *mem_ctx; + + mem_ctx = talloc_new(NULL); + if (mem_ctx == NULL) { + PyErr_NoMemory(); + return NULL; + } + + s3_context = loadparm_s3_context(); + + s4_context = loadparm_init_s3(mem_ctx, s3_context); + if (s4_context == NULL) { + PyErr_NoMemory(); + return NULL; + } + + py_loadparm = pytalloc_steal(loadparm_Type, discard_const_p(struct loadparm_context, s4_context)); + if (py_loadparm == NULL) { + talloc_free(mem_ctx); + PyErr_NoMemory(); + return NULL; + } + + talloc_free(mem_ctx); + + return py_loadparm; +} + +static PyMethodDef pyparam_methods[] = { + { "get_context", (PyCFunction)py_get_context, METH_NOARGS, + "Returns LoadParm context." }, + { NULL } +}; + +void initparam(void) +{ + PyObject *m, *mod; + + m = Py_InitModule3("param", pyparam_methods, "Parsing and writing Samba3 configuration files."); + if (m == NULL) + return; + + mod = PyImport_ImportModule("samba.param"); + if (mod == NULL) { + return; + } + + loadparm_Type = (PyTypeObject *)PyObject_GetAttrString(mod, "LoadParm"); + Py_DECREF(mod); + if (loadparm_Type == NULL) { + return; + } +} diff --git a/source3/wscript_build b/source3/wscript_build index 2ad6e8d3792..b5d3f1efeb8 100755 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -753,6 +753,13 @@ bld.SAMBA3_SUBSYSTEM('param', source=PARAM_WITHOUT_REG_SRC, deps='samba-util PARAM_UTIL smbd_conn ldap lber LOADPARM_CTX samba3core smbconf param_local_h param/param_global_h''') +if bld.env.toplevel_build: + bld.SAMBA3_PYTHON('pys3param', + source='param/pyparam.c', + deps='param', + public_deps='samba-hostconfig pytalloc talloc', + realname='samba/samba3/param.so') + bld.SAMBA3_SUBSYSTEM('param_service', source='param/service.c', deps = 'USER_UTIL param USER_UTIL PRINTING')