From fe2b04b4bba6585ee5377d44b8e2627d32d404c4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 23 Apr 2009 01:20:20 +0200 Subject: python: Move helper functions for using param into a separate file rather than linking against the python module. --- source4/auth/config.mk | 2 +- source4/auth/credentials/config.mk | 2 +- source4/lib/registry/config.mk | 2 +- source4/librpc/config.mk | 34 ++++++++++++------------ source4/param/pyparam.c | 24 ----------------- source4/param/pyparam_util.c | 54 ++++++++++++++++++++++++++++++++++++++ source4/scripting/python/config.mk | 2 +- 7 files changed, 75 insertions(+), 45 deletions(-) create mode 100644 source4/param/pyparam_util.c (limited to 'source4') diff --git a/source4/auth/config.mk b/source4/auth/config.mk index 97916023c3..573f1972bc 100644 --- a/source4/auth/config.mk +++ b/source4/auth/config.mk @@ -45,7 +45,7 @@ $(eval $(call proto_header_template,$(authsrcdir)/auth_sam_reply.h,$(auth_sam_re [PYTHON::pyauth] LIBRARY_REALNAME = samba/auth.$(SHLIBEXT) PUBLIC_DEPENDENCIES = auth_system_session -PRIVATE_DEPENDENCIES = SAMDB PYTALLOC param +PRIVATE_DEPENDENCIES = SAMDB PYTALLOC pyparam_util pyauth_OBJ_FILES = $(authsrcdir)/pyauth.o diff --git a/source4/auth/credentials/config.mk b/source4/auth/credentials/config.mk index 2402c732b3..6b051ef46c 100644 --- a/source4/auth/credentials/config.mk +++ b/source4/auth/credentials/config.mk @@ -15,6 +15,6 @@ PUBLIC_HEADERS += $(authsrcdir)/credentials/credentials.h [PYTHON::pycredentials] LIBRARY_REALNAME = samba/credentials.$(SHLIBEXT) -PUBLIC_DEPENDENCIES = CREDENTIALS LIBCMDLINE_CREDENTIALS PYTALLOC param +PUBLIC_DEPENDENCIES = CREDENTIALS LIBCMDLINE_CREDENTIALS PYTALLOC pyparam_util pycredentials_OBJ_FILES = $(authsrcdir)/credentials/pycredentials.o diff --git a/source4/lib/registry/config.mk b/source4/lib/registry/config.mk index a566042cf2..adf26b275f 100644 --- a/source4/lib/registry/config.mk +++ b/source4/lib/registry/config.mk @@ -105,6 +105,6 @@ $(eval $(call proto_header_template,$(libregistrysrcdir)/tests/proto.h,$(torture [PYTHON::py_registry] LIBRARY_REALNAME = samba/registry.$(SHLIBEXT) -PUBLIC_DEPENDENCIES = registry PYTALLOC pycredentials param +PUBLIC_DEPENDENCIES = registry PYTALLOC pycredentials pyparam_util py_registry_OBJ_FILES = $(libregistrysrcdir)/pyregistry.o diff --git a/source4/librpc/config.mk b/source4/librpc/config.mk index 64a4750ab7..52c7f3e2d1 100644 --- a/source4/librpc/config.mk +++ b/source4/librpc/config.mk @@ -631,7 +631,7 @@ PUBLIC_HEADERS += $(addprefix $(librpcsrcdir)/, rpc/dcerpc.h) \ [PYTHON::python_dcerpc] LIBRARY_REALNAME = samba/dcerpc/base.$(SHLIBEXT) -PUBLIC_DEPENDENCIES = LIBCLI_SMB LIBSAMBA-UTIL LIBSAMBA-HOSTCONFIG dcerpc_samr RPC_NDR_LSA DYNCONFIG pycredentials param +PUBLIC_DEPENDENCIES = LIBCLI_SMB LIBSAMBA-UTIL LIBSAMBA-HOSTCONFIG dcerpc_samr RPC_NDR_LSA DYNCONFIG pycredentials pyparam_util python_dcerpc_OBJ_FILES = $(dcerpcsrcdir)/pyrpc.o @@ -640,31 +640,31 @@ $(eval $(call python_py_module_template,samba/dcerpc/__init__.py,$(dcerpcsrcdir) [PYTHON::python_echo] LIBRARY_REALNAME = samba/dcerpc/echo.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_ECHO PYTALLOC param pycredentials python_dcerpc +PRIVATE_DEPENDENCIES = RPC_NDR_ECHO PYTALLOC pyparam_util pycredentials python_dcerpc python_echo_OBJ_FILES = ../librpc/gen_ndr/py_echo.o [PYTHON::python_winreg] LIBRARY_REALNAME = samba/dcerpc/winreg.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_WINREG PYTALLOC param pycredentials python_dcerpc +PRIVATE_DEPENDENCIES = RPC_NDR_WINREG PYTALLOC pyparam_util pycredentials python_dcerpc python_winreg_OBJ_FILES = ../librpc/gen_ndr/py_winreg.o [PYTHON::python_dcerpc_misc] LIBRARY_REALNAME = samba/dcerpc/misc.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = PYTALLOC python_dcerpc +PRIVATE_DEPENDENCIES = PYTALLOC python_dcerpc NDR_MISC NDR_KRB5PAC python_dcerpc_misc_OBJ_FILES = ../librpc/gen_ndr/py_misc.o [PYTHON::python_initshutdown] LIBRARY_REALNAME = samba/dcerpc/initshutdown.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_INITSHUTDOWN PYTALLOC param pycredentials python_dcerpc +PRIVATE_DEPENDENCIES = RPC_NDR_INITSHUTDOWN PYTALLOC pyparam_util pycredentials python_dcerpc python_initshutdown_OBJ_FILES = ../librpc/gen_ndr/py_initshutdown.o [PYTHON::python_epmapper] LIBRARY_REALNAME = samba/dcerpc/epmapper.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = dcerpc PYTALLOC param pycredentials python_dcerpc +PRIVATE_DEPENDENCIES = dcerpc PYTALLOC pyparam_util pycredentials python_dcerpc python_epmapper_OBJ_FILES = ../librpc/gen_ndr/py_epmapper.o @@ -676,67 +676,67 @@ python_mgmt_OBJ_FILES = ../librpc/gen_ndr/py_mgmt.o [PYTHON::python_atsvc] LIBRARY_REALNAME = samba/dcerpc/atsvc.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = dcerpc_atsvc PYTALLOC param pycredentials python_dcerpc +PRIVATE_DEPENDENCIES = dcerpc_atsvc PYTALLOC pyparam_util pycredentials python_dcerpc python_atsvc_OBJ_FILES = ../librpc/gen_ndr/py_atsvc.o [PYTHON::python_dcerpc_nbt] LIBRARY_REALNAME = samba/dcerpc/nbt.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = NDR_NBT PYTALLOC param pycredentials python_dcerpc +PRIVATE_DEPENDENCIES = NDR_NBT PYTALLOC pyparam_util pycredentials python_dcerpc python_dcerpc_nbt_OBJ_FILES = ../librpc/gen_ndr/py_nbt.o [PYTHON::python_samr] LIBRARY_REALNAME = samba/dcerpc/samr.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = dcerpc_samr PYTALLOC pycredentials param python_dcerpc +PRIVATE_DEPENDENCIES = dcerpc_samr PYTALLOC pycredentials pyparam_util python_dcerpc python_samr_OBJ_FILES = ../librpc/gen_ndr/py_samr.o [PYTHON::python_svcctl] LIBRARY_REALNAME = samba/dcerpc/svcctl.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_SVCCTL PYTALLOC param pycredentials python_dcerpc +PRIVATE_DEPENDENCIES = RPC_NDR_SVCCTL PYTALLOC pyparam_util pycredentials python_dcerpc python_svcctl_OBJ_FILES = ../librpc/gen_ndr/py_svcctl.o [PYTHON::python_lsa] LIBRARY_REALNAME = samba/dcerpc/lsa.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_LSA PYTALLOC param pycredentials python_dcerpc +PRIVATE_DEPENDENCIES = RPC_NDR_LSA PYTALLOC pyparam_util pycredentials python_dcerpc python_lsa_OBJ_FILES = ../librpc/gen_ndr/py_lsa.o [PYTHON::python_wkssvc] LIBRARY_REALNAME = samba/dcerpc/wkssvc.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_WKSSVC PYTALLOC param pycredentials python_dcerpc +PRIVATE_DEPENDENCIES = RPC_NDR_WKSSVC PYTALLOC pyparam_util pycredentials python_dcerpc python_wkssvc_OBJ_FILES = ../librpc/gen_ndr/py_wkssvc.o [PYTHON::python_dfs] LIBRARY_REALNAME = samba/dcerpc/dfs.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_DFS PYTALLOC param pycredentials python_dcerpc +PRIVATE_DEPENDENCIES = RPC_NDR_DFS PYTALLOC pyparam_util pycredentials python_dcerpc python_dfs_OBJ_FILES = ../librpc/gen_ndr/py_dfs.o [PYTHON::python_unixinfo] LIBRARY_REALNAME = samba/dcerpc/unixinfo.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_UNIXINFO PYTALLOC param pycredentials python_dcerpc +PRIVATE_DEPENDENCIES = RPC_NDR_UNIXINFO PYTALLOC pyparam_util pycredentials python_dcerpc python_unixinfo_OBJ_FILES = ../librpc/gen_ndr/py_unixinfo.o [PYTHON::python_irpc] LIBRARY_REALNAME = samba/dcerpc/irpc.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_IRPC PYTALLOC param pycredentials python_dcerpc +PRIVATE_DEPENDENCIES = RPC_NDR_IRPC PYTALLOC pyparam_util pycredentials python_dcerpc python_irpc_OBJ_FILES = $(gen_ndrsrcdir)/py_irpc.o [PYTHON::python_drsuapi] LIBRARY_REALNAME = samba/dcerpc/drsuapi.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_DRSUAPI PYTALLOC param pycredentials python_dcerpc +PRIVATE_DEPENDENCIES = RPC_NDR_DRSUAPI PYTALLOC pyparam_util pycredentials python_dcerpc python_drsuapi_OBJ_FILES = ../librpc/gen_ndr/py_drsuapi.o [PYTHON::python_dcerpc_security] LIBRARY_REALNAME = samba/dcerpc/security.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = PYTALLOC python_dcerpc_misc python_dcerpc +PRIVATE_DEPENDENCIES = PYTALLOC python_dcerpc_misc python_dcerpc NDR_SECURITY python_dcerpc_security_OBJ_FILES = ../librpc/gen_ndr/py_security.o diff --git a/source4/param/pyparam.c b/source4/param/pyparam.c index efaedf7b41..e32cfa0523 100644 --- a/source4/param/pyparam.c +++ b/source4/param/pyparam.c @@ -325,30 +325,6 @@ PyTypeObject PyLoadparmService = { .tp_flags = Py_TPFLAGS_DEFAULT, }; -_PUBLIC_ struct loadparm_context *lp_from_py_object(PyObject *py_obj) -{ - struct loadparm_context *lp_ctx; - if (PyString_Check(py_obj)) { - lp_ctx = loadparm_init(NULL); - if (!lp_load(lp_ctx, PyString_AsString(py_obj))) { - talloc_free(lp_ctx); - PyErr_Format(PyExc_RuntimeError, - "Unable to load %s", PyString_AsString(py_obj)); - return NULL; - } - return lp_ctx; - } - - if (py_obj == Py_None) { - lp_ctx = loadparm_init(NULL); - /* We're not checking that loading the file succeeded *on purpose */ - lp_load_default(lp_ctx); - return lp_ctx; - } - - return PyLoadparmContext_AsLoadparmContext(py_obj); -} - struct loadparm_context *py_default_loadparm_context(TALLOC_CTX *mem_ctx) { struct loadparm_context *ret; diff --git a/source4/param/pyparam_util.c b/source4/param/pyparam_util.c new file mode 100644 index 0000000000..0dc7c7fd13 --- /dev/null +++ b/source4/param/pyparam_util.c @@ -0,0 +1,54 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij 2007-2008 + + 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 + +#include "includes.h" +#include "param/param.h" +#include "param/loadparm.h" +#include +#include "pytalloc.h" + +#define PyLoadparmContext_AsLoadparmContext(obj) py_talloc_get_type(obj, struct loadparm_context) + +_PUBLIC_ struct loadparm_context *lp_from_py_object(PyObject *py_obj) +{ + struct loadparm_context *lp_ctx; + + if (PyString_Check(py_obj)) { + lp_ctx = loadparm_init(NULL); + if (!lp_load(lp_ctx, PyString_AsString(py_obj))) { + talloc_free(lp_ctx); + PyErr_Format(PyExc_RuntimeError, "Unable to load %s", + PyString_AsString(py_obj)); + return NULL; + } + return lp_ctx; + } + + if (py_obj == Py_None) { + lp_ctx = loadparm_init(NULL); + /* We're not checking that loading the file succeeded *on purpose */ + lp_load_default(lp_ctx); + return lp_ctx; + } + + return PyLoadparmContext_AsLoadparmContext(py_obj); +} diff --git a/source4/scripting/python/config.mk b/source4/scripting/python/config.mk index ba624ee163..f485ca8bfb 100644 --- a/source4/scripting/python/config.mk +++ b/source4/scripting/python/config.mk @@ -17,7 +17,7 @@ python_uuid_OBJ_FILES = $(pyscriptsrcdir)/uuidmodule.o [PYTHON::python_glue] LIBRARY_REALNAME = samba/glue.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = LIBNDR LIBLDB SAMDB CREDENTIALS pyldb python_dcerpc_misc python_dcerpc_security pyauth +PRIVATE_DEPENDENCIES = LIBNDR LIBLDB SAMDB CREDENTIALS pyldb python_dcerpc_misc python_dcerpc_security pyauth pyldb_util pyparam_util python_glue_OBJ_FILES = $(pyscriptsrcdir)/pyglue.o -- cgit