1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-27 22:50:26 +03:00

r12494: Support loading modules from .so files for most subsystems.

We now use a different system for initializing the modules for a subsystem.
Most subsystems now have an init function that looks something like this:

	init_module_fn static_init[] = STATIC_AUTH_MODULES;
	init_module_fn *shared_init = load_samba_modules(NULL, "auth");

	run_init_functions(static_init);
	run_init_functions(shared_init);

	talloc_free(shared_init);

I hope to eliminate the other init functions later on (the
init_programname_subsystems; defines).
(This used to be commit b6d2ad4ce0a91c4be790dd258820c492ff1787ea)
This commit is contained in:
Jelmer Vernooij 2005-12-26 16:46:55 +00:00 committed by Gerald (Jerry) Carter
parent ee10fb1a12
commit 448483199f
28 changed files with 207 additions and 41 deletions

View File

@ -334,5 +334,13 @@ const struct auth_critical_sizes *auth_interface_version(void)
NTSTATUS server_service_auth_init(void)
{
init_module_fn static_init[] = STATIC_AUTH_MODULES;
init_module_fn *shared_init = load_samba_modules(NULL, "auth");
run_init_functions(static_init);
run_init_functions(shared_init);
talloc_free(shared_init);
return NT_STATUS_OK;
}

View File

@ -942,5 +942,13 @@ const struct gensec_critical_sizes *gensec_interface_version(void)
*/
NTSTATUS gensec_init(void)
{
init_module_fn static_init[] = STATIC_GENSEC_MODULES;
init_module_fn *shared_init = load_samba_modules(NULL, "gensec");
run_init_functions(static_init);
run_init_functions(shared_init);
talloc_free(shared_init);
return NT_STATUS_OK;
}

View File

@ -7,6 +7,10 @@
(in Samba or other projects) can use the same (3rd) library.
- add register function to smbtorture
- init functions per shared library / binary
- add init functions + use lists of function pointers
- rpc_ndr
- list not automatically generated
- utility function for 'init mutex'
- install shared modules
- call load_modules() from subsystems/libraries/binaries with modules
- remove smb_build.h include from includes.h and INIT_OBJ_FILES. Replace

View File

@ -49,6 +49,10 @@ sub check_module($$$)
die("Module $mod->{NAME} does not have a SUBSYSTEM set") if not defined($mod->{SUBSYSTEM});
my $use_default = 0;
if (not exists($INPUT->{$mod->{SUBSYSTEM}}{INIT_FUNCTIONS})) {
$INPUT->{$mod->{SUBSYSTEM}}{INIT_FUNCTIONS} = [];
}
if (!(defined($INPUT->{$mod->{SUBSYSTEM}}))) {
$mod->{ENABLE} = "NO";
@ -68,12 +72,12 @@ sub check_module($$$)
$mod->{OUTPUT_TYPE} = $default_ot;
}
if ($mod->{OUTPUT_TYPE} eq "SHARED_LIBRARY" or
$mod->{OUTPUT_TYPE} eq "STATIC_LIBRARY") {
if ($mod->{OUTPUT_TYPE} eq "SHARED_LIBRARY") {
$mod->{INSTALLDIR} = "LIBDIR/$mod->{SUBSYSTEM}";
push (@{$mod->{REQUIRED_SUBSYSTEMS}}, $mod->{SUBSYSTEM});
} else {
push (@{$INPUT->{$mod->{SUBSYSTEM}}{REQUIRED_SUBSYSTEMS}}, $mod->{NAME});
push (@{$INPUT->{$mod->{SUBSYSTEM}}{INIT_FUNCTIONS}}, $mod->{INIT_FUNCTION}) if defined($mod->{INIT_FUNCTION});
}
}

View File

@ -70,6 +70,7 @@ BINDIR = $self->{config}->{bindir}
SBINDIR = $self->{config}->{sbindir}
datadir = $self->{config}->{datadir}
LIBDIR = $self->{config}->{libdir}
MODULESDIR = $self->{config}->{libdir}
INCLUDEDIR = $self->{config}->{includedir}
CONFIGDIR = $self->{config}->{configdir}
localstatedir = $self->{config}->{localstatedir}

View File

@ -137,8 +137,8 @@ sub create_output($)
push(@{$part->{DEPEND_LIST}}, $elem->{TARGET}) if defined($elem->{TARGET});
}
push(@{$part->{SUBSYSTEM_INIT_FUNCTIONS}}, $elem->{INIT_FUNCTION}) if
#$part->{OUTPUT_TYPE} eq "BINARY" and
defined($elem->{INIT_FUNCTION}) and
$elem->{TYPE} ne "MODULE" and
$part->{OUTPUT_TYPE} ne "SHARED_LIBRARY";
}
}

View File

@ -24,6 +24,8 @@ sub _prepare_smb_build_h($)
{
my $depend = shift;
my @defines = ();
my %declared = ();
my $output = "";
#
# loop over all binaries
@ -42,7 +44,9 @@ sub _prepare_smb_build_h($)
$DEFINE->{KEY} = $name . "_init_subsystems";
$DEFINE->{VAL} = "do { \\\n";
foreach my $subkey (@{$key->{SUBSYSTEM_INIT_FUNCTIONS}}) {
$DEFINE->{VAL} .= "\t\textern NTSTATUS $subkey(void); \\\n";
next if defined($declared{$subkey});
$output .= "NTSTATUS $subkey(void);\n";
$declared{$subkey} = 1;
}
foreach my $subkey (@{$key->{SUBSYSTEM_INIT_FUNCTIONS}}) {
@ -53,6 +57,24 @@ sub _prepare_smb_build_h($)
push(@defines,$DEFINE);
}
foreach my $key (values %{$depend}) {
my $DEFINE = ();
next if ($key->{TYPE} ne "LIBRARY" and $key->{TYPE} ne "SUBSYSTEM");
next unless defined($key->{INIT_FUNCTIONS});
$DEFINE->{COMMENT} = "$key->{TYPE} $key->{NAME} INIT";
$DEFINE->{KEY} = "STATIC_$key->{NAME}_MODULES";
$DEFINE->{VAL} = "{ \\\n";
foreach (@{$key->{INIT_FUNCTIONS}}) {
$DEFINE->{VAL} .= "\t$_, \\\n";
$output .= "NTSTATUS $_(void);\n";
}
$DEFINE->{VAL} .= "\tNULL \\\n }";
push(@defines,$DEFINE);
}
#
# Shared modules
#
@ -78,10 +100,7 @@ sub _prepare_smb_build_h($)
#
# loop over all SMB_BUILD_H define sections
#
my $output = "";
foreach my $key (@defines) {
$output .= _add_define_section($key);
}
foreach (@defines) { $output .= _add_define_section($_); }
return $output;
}
@ -98,15 +117,12 @@ sub _prepare_smb_build_h($)
sub create_smb_build_h($$)
{
my ($CTX, $file) = @_;
my $output = "/* autogenerated by build/smb_build/main.pl */\n";
$output .= _prepare_smb_build_h($CTX);
open(SMB_BUILD_H,">$file") || die ("Can't open `$file'\n");
print SMB_BUILD_H $output;
print SMB_BUILD_H "/* autogenerated by build/smb_build/main.pl */\n";
print SMB_BUILD_H _prepare_smb_build_h($CTX);
close(SMB_BUILD_H);
print __FILE__.": creating $file\n";
return;
}
1;

View File

@ -59,6 +59,8 @@ const char *dyn_LMHOSTSFILE = LMHOSTSFILE;
/** Samba library directory. */
const char *dyn_LIBDIR = LIBDIR;
const char *dyn_MODULESDIR = MODULESDIR;
/** Shared library extension */
const char *dyn_SHLIBEXT = SHLIBEXT;

View File

@ -31,6 +31,7 @@ extern const char *dyn_NCALRPCDIR;
extern const char *dyn_LOGFILEBASE;
extern const char *dyn_LMHOSTSFILE;
extern const char *dyn_LIBDIR;
extern const char *dyn_MODULESDIR;
extern const char *dyn_SHLIBEXT;
extern const char *dyn_LOCKDIR;
extern const char *dyn_PIDDIR;

View File

@ -23,7 +23,6 @@
#ifndef NO_CONFIG_H /* for some tests */
#include "config.h"
#include "smb_build.h"
#endif
#include "local.h"
@ -114,6 +113,10 @@ struct ipv4_addr {
#include "cli_context.h"
#include "auth/credentials/credentials.h"
#ifndef NO_CONFIG_H
#include "smb_build.h"
#endif
/***** automatically generated prototypes *****/
#define _PRINTF_ATTRIBUTE(a1, a2) PRINTF_ATTRIBUTE(a1, a2)
#include "include/proto.h"

View File

@ -608,5 +608,6 @@ enum brl_type {READ_LOCK, WRITE_LOCK, PENDING_READ_LOCK, PENDING_WRITE_LOCK};
#define FS_ATTR_ENCRYPTION 0x00020000
#define FS_ATTR_NAMED_STREAMS 0x00040000
typedef NTSTATUS (*init_module_fn) (void);
#endif /* _SMB_H */

View File

@ -1,4 +1,5 @@
[SUBSYSTEM::COM]
INIT_FUNCTION = com_init
INIT_OBJ_FILES = \
tables.o \
rot.o \

View File

@ -24,7 +24,7 @@
#include "lib/events/events.h"
#include "librpc/gen_ndr/com_dcom.h"
WERROR com_init(struct com_context **ctx, struct event_context *event_ctx)
WERROR com_init_ctx(struct com_context **ctx, struct event_context *event_ctx)
{
*ctx = talloc(NULL, struct com_context);
if (event_ctx == NULL) {
@ -88,3 +88,16 @@ WERROR com_get_class_object(struct com_context *ctx, struct GUID *clsid, struct
return IUnknown_QueryInterface(iu, ctx, iid, ip);
}
NTSTATUS com_init(void)
{
init_module_fn static_init[] = STATIC_COM_MODULES;
init_module_fn *shared_init = load_samba_modules(NULL, "com");
run_init_functions(static_init);
run_init_functions(shared_init);
talloc_free(shared_init);
return NT_STATUS_OK;
}

View File

@ -21,65 +21,77 @@
#include "includes.h"
#include "system/dir.h"
static BOOL load_module(TALLOC_CTX *mem_ctx, const char *dir, const char *name)
static void *load_module(TALLOC_CTX *mem_ctx, const char *dir, const char *name)
{
char *path;
void *handle;
BOOL (*init_module_fn) (void);
BOOL ret;
void *init_fn;
path = talloc_asprintf(mem_ctx, "%s/%s", dir, name);
handle = dlopen(path, RTLD_NOW);
if (handle == NULL) {
DEBUG(0, ("Unable to open %s: %s\n", path, dlerror()));
return False;
talloc_free(path);
return NULL;
}
init_module_fn = dlsym(handle, "init_module");
init_fn = dlsym(handle, "init_module");
if (init_module_fn == NULL) {
if (init_fn == NULL) {
DEBUG(0, ("Unable to find init_module() in %s: %s\n", path, dlerror()));
return False;
}
ret = init_module_fn();
if (!ret) {
DEBUG(1, ("Loading module '%s' failed\n", path));
dlclose(handle);
talloc_free(path);
return NULL;
}
dlclose(handle);
talloc_free(path);
return ret;
return init_fn;
}
BOOL load_modules(const char *path)
init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path)
{
DIR *dir;
struct dirent *entry;
BOOL ret = True;
TALLOC_CTX *mem_ctx;
mem_ctx = talloc_init(NULL);
int success = 0;
init_module_fn *ret = talloc_array(mem_ctx, init_module_fn, 2);
ret[0] = NULL;
dir = opendir(path);
if (dir == NULL) {
talloc_free(mem_ctx);
return False;
talloc_free(ret);
return NULL;
}
while((entry = readdir(dir))) {
if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
continue;
ret &= load_module(mem_ctx, path, entry->d_name);
ret[success] = load_module(mem_ctx, path, entry->d_name);
if (ret[success]) {
ret = talloc_realloc(mem_ctx, ret, init_module_fn, success+2);
success++;
ret[success] = NULL;
}
}
closedir(dir);
talloc_free(mem_ctx);
return ret;
}
BOOL run_init_functions(NTSTATUS (**fns) (void))
{
int i;
BOOL ret;
if (fns == NULL)
return True;
for (i = 0; fns[i]; i++) { ret &= NT_STATUS_IS_OK(fns[i]()); }
return ret;
}

View File

@ -64,6 +64,19 @@ static struct reg_init_function_entry *reg_find_backend_entry(const char *name)
return NULL;
}
NTSTATUS registry_init(void)
{
init_module_fn static_init[] = STATIC_REGISTRY_MODULES;
init_module_fn *shared_init = load_samba_modules(NULL, "registry");
run_init_functions(static_init);
run_init_functions(shared_init);
talloc_free(shared_init);
return NT_STATUS_OK;
}
/* Check whether a certain backend is present */
BOOL reg_has_backend(const char *backend)
{

View File

@ -81,6 +81,7 @@ REQUIRED_SUBSYSTEMS = \
[LIBRARY::REGISTRY]
MAJOR_VERSION = 0
MINOR_VERSION = 0
INIT_FUNCTION = registry_init
DESCRIPTION = Windows-style registry library
RELEASE_VERSION = 1
INIT_OBJ_FILES = \

View File

@ -690,6 +690,23 @@ char *smbd_tmp_path(TALLOC_CTX *mem_ctx, const char *name)
return fname;
}
char *modules_path(TALLOC_CTX* mem_ctx, const char *name)
{
return talloc_asprintf(mem_ctx, "%s/%s", dyn_MODULESDIR, name);
}
init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem)
{
char *path = modules_path(mem_ctx, subsystem);
init_module_fn *ret;
ret = load_modules(mem_ctx, path);
talloc_free(path);
return ret;
}
void dump_data_pw(const char *msg, const uint8_t * data, size_t len)
{
#ifdef DEBUG_PASSWORD

View File

@ -42,6 +42,7 @@ showlayout:
@echo " bindir: $(BINDIR)"
@echo " sbindir: $(SBINDIR)"
@echo " libdir: $(LIBDIR)"
@echo " modulesdir: $(MODULESDIR)"
@echo " includedir: $(INCLUDEDIR)"
@echo " vardir: $(VARDIR)"
@echo " privatedir: $(PRIVATEDIR)"
@ -74,7 +75,8 @@ PATH_FLAGS = -DCONFIGFILE=\"$(CONFIGFILE)\" -DSBINDIR=\"$(SBINDIR)\" \
-DLOCKDIR=\"$(LOCKDIR)\" -DPIDDIR=\"$(PIDDIR)\" -DLIBDIR=\"$(LIBDIR)\" \
-DLOGFILEBASE=\"$(LOGFILEBASE)\" -DSHLIBEXT=\"$(SHLIBEXT)\" \
-DCONFIGDIR=\"$(CONFIGDIR)\" -DNCALRPCDIR=\"$(NCALRPCDIR)\" \
-DSWATDIR=\"$(SWATDIR)\" -DPRIVATE_DIR=\"$(PRIVATEDIR)\"
-DSWATDIR=\"$(SWATDIR)\" -DPRIVATE_DIR=\"$(PRIVATEDIR)\" \
-DMODULESDIR=\"$(MODULESDIR)\"
install: showlayout installbin installdat installswat installmisc installlib \
installheader installpc

View File

@ -15,6 +15,7 @@ REQUIRED_SUBSYSTEMS = \
################################################
# Start SUBSYSTEM NTPTR
[SUBSYSTEM::NTPTR]
INIT_FUNCTION = ntptr_init
INIT_OBJ_FILES = \
ntptr_base.o
ADD_OBJ_FILES = \

View File

@ -69,6 +69,19 @@ NTSTATUS ntptr_register(const void *_ops)
return NT_STATUS_OK;
}
NTSTATUS ntptr_init(void)
{
init_module_fn static_init[] = STATIC_NTPTR_MODULES;
init_module_fn *shared_init = load_samba_modules(NULL, "ntptr");
run_init_functions(static_init);
run_init_functions(shared_init);
talloc_free(shared_init);
return NT_STATUS_OK;
}
/*
return the operations structure for a named backend

View File

@ -77,6 +77,7 @@ ADD_OBJ_FILES = \
PUBLIC_HEADERS = ntvfs.h
MAJOR_VERSION = 0
MINOR_VERSION = 0
INIT_FUNCTION = ntvfs_init
DESCRIPTION = Virtual File System with NTFS semantics
RELEASE_VERSION = 1
INIT_OBJ_FILES = \

View File

@ -158,3 +158,16 @@ NTSTATUS ntvfs_init_connection(struct smbsrv_request *req, enum ntvfs_type type)
return NT_STATUS_OK;
}
NTSTATUS ntvfs_init(void)
{
init_module_fn static_init[] = STATIC_NTVFS_MODULES;
init_module_fn *shared_init = load_samba_modules(NULL, "ntvfs");
run_init_functions(static_init);
run_init_functions(shared_init);
talloc_free(shared_init);
return NT_STATUS_OK;
}

View File

@ -1338,5 +1338,13 @@ static NTSTATUS dcesrv_init(struct event_context *event_context, const struct mo
NTSTATUS server_service_rpc_init(void)
{
init_module_fn static_init[] = STATIC_DCERPC_MODULES;
init_module_fn *shared_init = load_samba_modules(NULL, "rpc_server");
run_init_functions(static_init);
run_init_functions(shared_init);
talloc_free(shared_init);
return register_server_service("rpc", dcesrv_init);
}

View File

@ -117,7 +117,7 @@ sub process_file($$$)
next unless ( $line =~ /
^void|^BOOL|^int|^struct|^char|^const|^\w+_[tT]\s|^uint|^unsigned|^long|
^NTSTATUS|^ADS_STATUS|^enum\s.*\(|^DATA_BLOB|^WERROR|^XFILE|^FILE|^DIR|
^double|^TDB_CONTEXT|^TDB_DATA|^TALLOC_CTX|^NTTIME|^FN_|^REG_KEY|^REG_HANDLE|^REG_VAL|
^double|^TDB_CONTEXT|^TDB_DATA|^TALLOC_CTX|^NTTIME|^FN_|^init_module|
^GtkWidget|^GType|^smb_ucs2_t
/xo);

View File

@ -80,6 +80,19 @@ NTSTATUS register_process_model(const void *_ops)
return NT_STATUS_OK;
}
NTSTATUS process_model_init(void)
{
init_module_fn static_init[] = STATIC_PROCESS_MODEL_MODULES;
init_module_fn *shared_init = load_samba_modules(NULL, "process_model");
run_init_functions(static_init);
run_init_functions(shared_init);
talloc_free(shared_init);
return NT_STATUS_OK;
}
/*
return the operations structure for a named backend of the specified type
*/

View File

@ -34,6 +34,7 @@ REQUIRED_SUBSYSTEMS = EXT_LIB_PTHREAD
################################################
# Start SUBSYSTEM PROCESS_MODEL
[SUBSYSTEM::PROCESS_MODEL]
INIT_FUNCTION = process_model_init
INIT_OBJ_FILES = \
process_model.o
#

View File

@ -154,6 +154,8 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
BOOL interactive = False;
int opt;
poptContext pc;
init_module_fn static_init[] = STATIC_SERVER_SERVICE_MODULES;
init_module_fn *shared_init;
struct event_context *event_ctx;
NTSTATUS status;
const char *model = "standard";
@ -214,6 +216,13 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
smbd_init_subsystems;
shared_init = load_samba_modules(NULL, "service");
run_init_functions(static_init);
run_init_functions(shared_init);
talloc_free(shared_init);
/* the event context is the top level structure in smbd. Everything else
should hang off that */
event_ctx = event_context_init(NULL);

View File

@ -38,7 +38,7 @@ static BOOL test_readwrite(TALLOC_CTX *mem_ctx, const char *host)
char test_data[5];
int i;
com_init(&ctx, NULL);
com_init_ctx(&ctx, NULL);
dcom_client_init(ctx, cmdline_credentials);
GUID_from_string(COM_ISTREAM_UUID, &IID[0]);