mirror of
https://github.com/samba-team/samba.git
synced 2025-01-18 06:04:06 +03:00
r26576: Allow the static module loading code to be used for the Python modules.
Simplify the way module initialization functions are handled. (This used to be commit ba8be2dfc0de4434c798663336b81f7f95cde520)
This commit is contained in:
parent
1ab5bcfb93
commit
be33f4c611
@ -516,7 +516,7 @@ NTSTATUS auth_init(void)
|
||||
{
|
||||
static bool initialized = false;
|
||||
|
||||
init_module_fn static_init[] = STATIC_auth_MODULES;
|
||||
init_module_fn static_init[] = { STATIC_auth_MODULES, NULL };
|
||||
|
||||
if (initialized) return NT_STATUS_OK;
|
||||
initialized = true;
|
||||
|
@ -92,6 +92,6 @@ PRIVATE_DEPENDENCIES = LIBSAMBA-UTIL
|
||||
#######################
|
||||
|
||||
[PYTHON::swig_auth]
|
||||
PUBLIC_DEPENDENCIES = auth_system_session LIBPYTHON
|
||||
PUBLIC_DEPENDENCIES = auth_system_session
|
||||
PRIVATE_DEPENDENCIES = SAMDB
|
||||
SWIG_FILE = auth.i
|
||||
|
@ -14,5 +14,5 @@ PRIVATE_DEPENDENCIES = \
|
||||
SECRETS
|
||||
|
||||
[PYTHON::swig_credentials]
|
||||
PUBLIC_DEPENDENCIES = CREDENTIALS LIBPYTHON
|
||||
PUBLIC_DEPENDENCIES = CREDENTIALS
|
||||
SWIG_FILE = credentials.i
|
||||
|
@ -1268,7 +1268,7 @@ NTSTATUS gensec_init(struct loadparm_context *lp_ctx)
|
||||
{
|
||||
static bool initialized = false;
|
||||
|
||||
init_module_fn static_init[] = STATIC_gensec_MODULES;
|
||||
init_module_fn static_init[] = { STATIC_gensec_MODULES, NULL };
|
||||
init_module_fn *shared_init;
|
||||
|
||||
if (initialized) return NT_STATUS_OK;
|
||||
|
@ -25,9 +25,11 @@ sub generate($$$)
|
||||
|
||||
foreach my $part (values %{$depend}) {
|
||||
next if (defined($only) and not contains($only,$part->{NAME}));
|
||||
foreach my $elem (@{$part->{PUBLIC_DEPENDENCIES}},
|
||||
@{$part->{PRIVATE_DEPENDENCIES}}) {
|
||||
$res .= "\t\"$part->{NAME}\" -> \"$elem\";\n";
|
||||
foreach my $elem (@{$part->{PUBLIC_DEPENDENCIES}}) {
|
||||
$res .= "\t\"$part->{NAME}\" -> \"$elem\"; /* public */\n";
|
||||
}
|
||||
foreach my $elem (@{$part->{PRIVATE_DEPENDENCIES}}) {
|
||||
$res .= "\t\"$part->{NAME}\" -> \"$elem\"; /* private */\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,16 +39,18 @@ sub _prepare_build_h($)
|
||||
$name =~ s/-/_/g;
|
||||
$DEFINE->{COMMENT} = "$key->{TYPE} $key->{NAME} INIT";
|
||||
$DEFINE->{KEY} = "STATIC_$name\_MODULES";
|
||||
$DEFINE->{VAL} = "{ \\\n";
|
||||
$DEFINE->{VAL} = "\\\n";
|
||||
foreach (@{$key->{INIT_FUNCTIONS}}) {
|
||||
$DEFINE->{VAL} .= "\t$_, \\\n";
|
||||
my $fn = $key->{INIT_FUNCTION_TYPE};
|
||||
unless(defined($fn)) { $fn = "NTSTATUS (*) (void)"; }
|
||||
$fn =~ s/\(\*\)/$_/;
|
||||
$output .= "$fn;\n";
|
||||
unless (/{/) {
|
||||
my $fn = $key->{INIT_FUNCTION_TYPE};
|
||||
unless(defined($fn)) { $fn = "NTSTATUS (*) (void)"; }
|
||||
$fn =~ s/\(\*\)/$_/;
|
||||
$output .= "$fn;\n";
|
||||
}
|
||||
}
|
||||
|
||||
$DEFINE->{VAL} .= "\tNULL \\\n }";
|
||||
$DEFINE->{VAL} =~ s/, \\\n$//g; # Remove the last comma
|
||||
|
||||
push(@defines,$DEFINE);
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ sub check_module($$$)
|
||||
my $sane_subsystem = lc($mod->{SUBSYSTEM});
|
||||
$sane_subsystem =~ s/^lib//;
|
||||
$mod->{INSTALLDIR} = "MODULESDIR/$sane_subsystem";
|
||||
push (@{$mod->{PRIVATE_DEPENDENCIES}}, $mod->{SUBSYSTEM});
|
||||
push (@{$mod->{PUBLIC_DEPENDENCIES}}, $mod->{SUBSYSTEM});
|
||||
}
|
||||
if (grep(/INTEGRATED/, @{$mod->{OUTPUT_TYPE}})) {
|
||||
push (@{$INPUT->{$mod->{SUBSYSTEM}}{INIT_FUNCTIONS}}, $mod->{INIT_FUNCTION}) if defined($mod->{INIT_FUNCTION});
|
||||
@ -147,14 +147,14 @@ sub check_library($$$)
|
||||
add_libreplace($lib);
|
||||
}
|
||||
|
||||
sub check_python($$)
|
||||
sub check_python($$$)
|
||||
{
|
||||
my ($INPUT, $python) = @_;
|
||||
my ($INPUT, $python, $default_ot) = @_;
|
||||
|
||||
return if ($INPUT->{LIBPYTHON}{ENABLE} ne "YES");
|
||||
|
||||
$python->{INSTALLDIR} = "PYTHONDIR";
|
||||
push (@{$python->{PUBLIC_DEPENDENCIES}}, "LIBPYTHON");
|
||||
unless (defined($python->{CFLAGS})) { $python->{CFLAGS} = []; }
|
||||
if (defined($python->{SWIG_FILE})) {
|
||||
my $dirname = dirname($python->{SWIG_FILE});
|
||||
my $basename = basename($python->{SWIG_FILE}, ".i");
|
||||
@ -165,18 +165,20 @@ sub check_python($$)
|
||||
$python->{OBJ_FILES} = ["$dirname$basename\_wrap.o"];
|
||||
$python->{LIBRARY_REALNAME} = "_$basename.\$(SHLIBEXT)";
|
||||
$python->{PYTHON_FILES} = ["$dirname$basename.py"];
|
||||
unless (defined($python->{CFLAGS})) { $python->{CFLAGS} = []; }
|
||||
push (@{$python->{CFLAGS}}, $config::config{CFLAG_NO_UNUSED_MACROS});
|
||||
push (@{$python->{CFLAGS}}, $config::config{CFLAG_NO_CAST_QUAL});
|
||||
$python->{INIT_FUNCTION} = "{ (char *)\"_$basename\", init_$basename }";
|
||||
} else {
|
||||
my $basename = $python->{NAME};
|
||||
$basename =~ s/^python_//g;
|
||||
$python->{LIBRARY_REALNAME} = "$basename.\$(SHLIBEXT)";
|
||||
$python->{INIT_FUNCTION} = "{ (char *)\"$basename\", init$basename }";
|
||||
}
|
||||
push (@{$python->{CFLAGS}}, @{$INPUT->{EXT_LIB_PYTHON}->{CFLAGS}});
|
||||
|
||||
$python->{SUBSYSTEM} = "LIBPYTHON";
|
||||
|
||||
check_module($INPUT, $python, ["SHARED_LIBRARY"]);
|
||||
check_module($INPUT, $python, $default_ot);
|
||||
}
|
||||
|
||||
sub check_binary($$)
|
||||
@ -204,7 +206,8 @@ sub import_integrated($$)
|
||||
|
||||
push (@{$lib->{FULL_OBJ_LIST}}, "\$($mod->{TYPE}_$mod->{NAME}_FULL_OBJ_LIST)");
|
||||
push (@{$lib->{LINK_FLAGS}}, "\$($mod->{TYPE}_$mod->{NAME}_LINK_FLAGS)");
|
||||
push (@{$lib->{PRIVATE_DEPENDENCIES}}, @{$mod->{PUBLIC_DEPENDENCIES}}) if defined($mod->{PUBLIC_DEPENDENCIES});
|
||||
push (@{$lib->{CFLAGS}}, @{$mod->{CFLAGS}}) if defined($mod->{CFLAGS});
|
||||
push (@{$lib->{PUBLIC_DEPENDENCIES}}, @{$mod->{PUBLIC_DEPENDENCIES}}) if defined($mod->{PUBLIC_DEPENDENCIES});
|
||||
push (@{$lib->{PRIVATE_DEPENDENCIES}}, @{$mod->{PRIVATE_DEPENDENCIES}}) if defined($mod->{PRIVATE_DEPENDENCIES});
|
||||
|
||||
$mod->{ENABLE} = "NO";
|
||||
@ -288,7 +291,7 @@ sub check($$$$$)
|
||||
} elsif ($part->{TYPE} eq "BINARY") {
|
||||
check_binary($INPUT, $part);
|
||||
} elsif ($part->{TYPE} eq "PYTHON") {
|
||||
check_python($INPUT, $part);
|
||||
check_python($INPUT, $part, $module_ot);
|
||||
} elsif ($part->{TYPE} eq "EXT_LIB") {
|
||||
} else {
|
||||
die("Unknown type $part->{TYPE}");
|
||||
|
@ -102,7 +102,7 @@ void event_set_default_backend(const char *backend)
|
||||
static void event_backend_init(void)
|
||||
{
|
||||
#if _SAMBA_BUILD_
|
||||
init_module_fn static_init[] = STATIC_LIBEVENTS_MODULES;
|
||||
init_module_fn static_init[] = { STATIC_LIBEVENTS_MODULES, NULL };
|
||||
init_module_fn *shared_init;
|
||||
if (event_backends) return;
|
||||
shared_init = load_samba_modules(NULL, global_loadparm, "events");
|
||||
|
@ -168,7 +168,7 @@ static const struct ldb_module_ops *ldb_find_module_ops(const char *name)
|
||||
|
||||
int ldb_global_init(void)
|
||||
{
|
||||
int (*static_init_fns[])(void) = STATIC_LIBLDB_MODULES;
|
||||
int (*static_init_fns[])(void) = { STATIC_LIBLDB_MODULES, NULL };
|
||||
|
||||
static int initialized = 0;
|
||||
int ret = 0, i;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#######################
|
||||
# Start LIBRARY swig_ldb
|
||||
[PYTHON::swig_ldb]
|
||||
PUBLIC_DEPENDENCIES = LIBLDB LIBPYTHON
|
||||
PUBLIC_DEPENDENCIES = LIBLDB
|
||||
SWIG_FILE = ldb.i
|
||||
# End LIBRARY swig_ldb
|
||||
#######################
|
||||
|
@ -102,6 +102,6 @@ OBJ_FILES = \
|
||||
tests/registry.o
|
||||
|
||||
[PYTHON::swig_registry]
|
||||
PUBLIC_DEPENDENCIES = registry LIBPYTHON
|
||||
PUBLIC_DEPENDENCIES = registry
|
||||
SWIG_FILE = registry.i
|
||||
|
||||
|
@ -71,7 +71,7 @@ NTSTATUS ntptr_register(const void *_ops)
|
||||
|
||||
NTSTATUS ntptr_init(struct loadparm_context *lp_ctx)
|
||||
{
|
||||
init_module_fn static_init[] = STATIC_ntptr_MODULES;
|
||||
init_module_fn static_init[] = { STATIC_ntptr_MODULES, NULL };
|
||||
init_module_fn *shared_init = load_samba_modules(NULL, lp_ctx, "ntptr");
|
||||
|
||||
run_init_functions(static_init);
|
||||
|
@ -202,7 +202,7 @@ NTSTATUS ntvfs_init_connection(TALLOC_CTX *mem_ctx, struct share_config *scfg, e
|
||||
NTSTATUS ntvfs_init(struct loadparm_context *lp_ctx)
|
||||
{
|
||||
static bool initialized = false;
|
||||
init_module_fn static_init[] = STATIC_ntvfs_MODULES;
|
||||
init_module_fn static_init[] = { STATIC_ntvfs_MODULES, NULL };
|
||||
init_module_fn *shared_init;
|
||||
|
||||
if (initialized) return NT_STATUS_OK;
|
||||
|
@ -125,7 +125,7 @@ _PUBLIC_ NTSTATUS sys_notify_init(void)
|
||||
{
|
||||
static bool initialized = false;
|
||||
|
||||
init_module_fn static_init[] = STATIC_sys_notify_MODULES;
|
||||
init_module_fn static_init[] = { STATIC_sys_notify_MODULES, NULL };
|
||||
init_module_fn *shared_init;
|
||||
|
||||
if (initialized) return NT_STATUS_OK;
|
||||
|
@ -186,7 +186,7 @@ typedef struct param_context {
|
||||
struct param_opt *opt = param_get_add($self, parameter, section_name);
|
||||
|
||||
talloc_free(opt->value);
|
||||
opt->value = talloc_strdup(opt, PyObject_Str(ob));
|
||||
opt->value = talloc_strdup(opt, PyString_AsString(PyObject_Str(ob)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -2747,7 +2747,7 @@ SWIGINTERN int param_set(param *self,char const *parameter,PyObject *ob,char con
|
||||
struct param_opt *opt = param_get_add(self, parameter, section_name);
|
||||
|
||||
talloc_free(opt->value);
|
||||
opt->value = talloc_strdup(opt, PyObject_Str(ob));
|
||||
opt->value = talloc_strdup(opt, PyString_AsString(PyObject_Str(ob)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ NTSTATUS share_get_context_by_name(TALLOC_CTX *mem_ctx, const char *backend_name
|
||||
*/
|
||||
NTSTATUS share_init(void)
|
||||
{
|
||||
init_module_fn static_init[] = STATIC_share_MODULES;
|
||||
init_module_fn static_init[] = { STATIC_share_MODULES, NULL };
|
||||
|
||||
run_init_functions(static_init);
|
||||
|
||||
|
@ -467,7 +467,7 @@ static NTSTATUS dcesrv_init(struct event_context *event_context,
|
||||
|
||||
NTSTATUS server_service_rpc_init(void)
|
||||
{
|
||||
init_module_fn static_init[] = STATIC_dcerpc_server_MODULES;
|
||||
init_module_fn static_init[] = { STATIC_dcerpc_server_MODULES, NULL };
|
||||
init_module_fn *shared_init = load_samba_modules(NULL, global_loadparm, "dcerpc_server");
|
||||
|
||||
run_init_functions(static_init);
|
||||
|
@ -173,7 +173,7 @@ _PUBLIC_ void ejs_exception(const char *reason)
|
||||
*/
|
||||
void smb_setup_ejs_functions(void (*exception_handler)(const char *))
|
||||
{
|
||||
init_module_fn static_init[] = STATIC_smbcalls_MODULES;
|
||||
init_module_fn static_init[] = { STATIC_smbcalls_MODULES, NULL };
|
||||
init_module_fn *shared_init;
|
||||
|
||||
ejs_exception_handler = exception_handler;
|
||||
|
@ -24,7 +24,7 @@ fi
|
||||
PYTHON_LDFLAGS=`$PYTHON_CONFIG --ldflags`
|
||||
PYTHON_CFLAGS=`$PYTHON_CONFIG --cflags`
|
||||
|
||||
SMB_EXT_LIB(LIBPYTHON, [$PYTHON_LDFLAGS], [$PYTHON_CFLAGS])
|
||||
SMB_EXT_LIB(EXT_LIB_PYTHON, [$PYTHON_LDFLAGS], [$PYTHON_CFLAGS])
|
||||
|
||||
AC_MSG_CHECKING(working python module support)
|
||||
if test x$working_python = xyes
|
||||
@ -40,10 +40,12 @@ then
|
||||
],[
|
||||
Py_InitModule(NULL, NULL);
|
||||
],[
|
||||
SMB_ENABLE(LIBPYTHON,YES)
|
||||
SMB_ENABLE(EXT_LIB_PYTHON,YES)
|
||||
SMB_ENABLE(smbpython,YES)
|
||||
SMB_ENABLE(LIBPYTHON,YES)
|
||||
AC_MSG_RESULT([yes])
|
||||
],[
|
||||
SMB_ENABLE(EXT_LIB_PYTHON,NO)
|
||||
SMB_ENABLE(LIBPYTHON,NO)
|
||||
SMB_ENABLE(smbpython,NO)
|
||||
AC_MSG_RESULT([no])
|
||||
@ -52,7 +54,8 @@ then
|
||||
LIBS="$ac_save_LIBS"
|
||||
CFLAGS="$ac_save_CFLAGS"
|
||||
else
|
||||
SMB_ENABLE(LIBPYTHON,NO)
|
||||
SMB_ENABLE(EXT_LIB_PYTHON,NO)
|
||||
SMB_ENABLE(LIBPYTHONyy,NO)
|
||||
SMB_ENABLE(smbpython,NO)
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
|
@ -1,7 +1,10 @@
|
||||
[BINARY::smbpython]
|
||||
PRIVATE_DEPENDENCIES = LIBPYTHON
|
||||
OBJ_FILES = \
|
||||
smbpython.o
|
||||
OBJ_FILES = smbpython.o
|
||||
|
||||
[SUBSYSTEM::LIBPYTHON]
|
||||
PUBLIC_DEPENDENCIES = EXT_LIB_PYTHON
|
||||
OBJ_FILES = modules.o
|
||||
|
||||
[PYTHON::python_uuid]
|
||||
PRIVATE_DEPENDENCIES = LIBNDR
|
||||
|
45
source4/scripting/python/modules.c
Normal file
45
source4/scripting/python/modules.c
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
Samba utility functions
|
||||
Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include <Python.h>
|
||||
#include "build.h"
|
||||
|
||||
extern void init_ldb(void);
|
||||
extern void init_security(void);
|
||||
extern void init_registry(void);
|
||||
extern void init_param(void);
|
||||
extern void init_misc(void);
|
||||
extern void init_ldb(void);
|
||||
extern void init_auth(void);
|
||||
extern void init_credentials(void);
|
||||
extern void init_tdb(void);
|
||||
extern void init_dcerpc(void);
|
||||
extern void init_events(void);
|
||||
extern void inituuid(void);
|
||||
|
||||
static struct _inittab py_modules[] = { STATIC_LIBPYTHON_MODULES };
|
||||
|
||||
void py_load_samba_modules(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < ARRAY_SIZE(py_modules); i++) {
|
||||
PyImport_ExtendInittab(&py_modules[i]);
|
||||
}
|
||||
}
|
@ -20,6 +20,10 @@
|
||||
#include "includes.h"
|
||||
#include <Python.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
void py_load_samba_modules(void);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
py_load_samba_modules();
|
||||
return Py_Main(argc,argv);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ static PyObject *uuid_random(PyObject *self, PyObject *args)
|
||||
struct GUID guid;
|
||||
char *str;
|
||||
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
if (!PyArg_ParseTuple(args, (char *)""))
|
||||
return NULL;
|
||||
|
||||
guid = GUID_random();
|
||||
@ -51,7 +51,7 @@ PyDoc_STRVAR(param_doc, "UUID helper routines");
|
||||
|
||||
PyMODINIT_FUNC inituuid(void)
|
||||
{
|
||||
PyObject *mod = Py_InitModule3("uuid", methods, param_doc);
|
||||
PyObject *mod = Py_InitModule3((char *)"uuid", methods, param_doc);
|
||||
if (mod == NULL)
|
||||
return;
|
||||
}
|
||||
|
1
source4/selftest/env/Samba4.pm
vendored
1
source4/selftest/env/Samba4.pm
vendored
@ -640,6 +640,7 @@ nogroup:x:65534:nobody
|
||||
push (@provision_options, "NSS_WRAPPER_PASSWD=\"$nsswrap_passwd\"");
|
||||
push (@provision_options, "NSS_WRAPPER_GROUP=\"$nsswrap_group\"");
|
||||
if (defined($ENV{PROVISION_PYTHON})) {
|
||||
push (@provision_options, "$self->{bindir}/smbpython");
|
||||
push (@provision_options, "$self->{setupdir}/provision.py");
|
||||
} else {
|
||||
push (@provision_options, "$self->{bindir}/smbscript");
|
||||
|
@ -82,7 +82,7 @@ _PUBLIC_ NTSTATUS register_process_model(const void *_ops)
|
||||
|
||||
NTSTATUS process_model_init(struct loadparm_context *lp_ctx)
|
||||
{
|
||||
init_module_fn static_init[] = STATIC_process_model_MODULES;
|
||||
init_module_fn static_init[] = { STATIC_process_model_MODULES, NULL };
|
||||
init_module_fn *shared_init = load_samba_modules(NULL, lp_ctx, "process_model");
|
||||
|
||||
run_init_functions(static_init);
|
||||
|
@ -187,7 +187,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
|
||||
bool opt_interactive = false;
|
||||
int opt;
|
||||
poptContext pc;
|
||||
init_module_fn static_init[] = STATIC_service_MODULES;
|
||||
init_module_fn static_init[] = { STATIC_service_MODULES, NULL };
|
||||
init_module_fn *shared_init;
|
||||
struct event_context *event_ctx;
|
||||
NTSTATUS status;
|
||||
|
@ -64,7 +64,7 @@ struct torture_context *torture_context_init(TALLOC_CTX *mem_ctx,
|
||||
|
||||
int torture_init(void)
|
||||
{
|
||||
init_module_fn static_init[] = STATIC_torture_MODULES;
|
||||
init_module_fn static_init[] = { STATIC_torture_MODULES, NULL };
|
||||
init_module_fn *shared_init = load_samba_modules(NULL, cmdline_lp_ctx, "torture");
|
||||
|
||||
run_init_functions(static_init);
|
||||
|
Loading…
x
Reference in New Issue
Block a user