From a846e592058726b670e40505493a4668bd856186 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 25 Nov 2003 03:15:26 +0000 Subject: CVS: ---------------------------------------------------------------------- CVS: Enter Log. Lines beginning with `CVS:' are removed automatically CVS: CVS: Committing in . CVS: CVS: Modified Files: CVS: Makefile.in configure.in include/includes.h include/ntvfs.h CVS: include/smb.h lib/iconv.c lib/module.c ntvfs/ntvfs_base.c CVS: ntvfs/cifs/vfs_cifs.c ntvfs/ipc/vfs_ipc.c CVS: ntvfs/posix/vfs_posix.c ntvfs/print/vfs_print.c CVS: ntvfs/reference/vfs_ref.c ntvfs/simple/vfs_simple.c CVS: passdb/pdb_interface.c CVS: Added Files: CVS: include/module.h CVS: ---------------------------------------------------------------------- Update to the modules system. Fixed: - get rid of smb_probe_module - merge older updates from 3.0 - introduced register_subsystem() and register_backend() functions - adapt ntvfs and charset to use new register functions - made smb_load_modules() work recursively (e.g. 'preload modules = /usr/lib/samba') - got rid of some old remains Things that still need work: - Did I break tankFS? I don't think so, but I can't test it here :-( - Add 'postload modules = ' (for modules that need to be loaded after fork() in smbd, if applicable) - Convert RPC, auth, passdb, etc to use new register_{subsystem,backend}() functions - Accept wildcards in 'preload modules' option, instead of loading recursively (This used to be commit 7512b9ab1a8b3103f7a6c13f736353c46a26b668) --- source4/lib/module.c | 110 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 43 deletions(-) (limited to 'source4/lib/module.c') diff --git a/source4/lib/module.c b/source4/lib/module.c index 152e893100..d45f99473e 100644 --- a/source4/lib/module.c +++ b/source4/lib/module.c @@ -2,7 +2,7 @@ Unix SMB/CIFS implementation. module loading system - Copyright (C) Jelmer Vernooij 2002 + Copyright (C) Jelmer Vernooij 2002-2003 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 @@ -22,12 +22,32 @@ #include "includes.h" #ifdef HAVE_DLOPEN -int smb_load_module(const char *module_name) + +/* Load module (or directory with modules) recursively. + * Includes running the init_module() function */ +NTSTATUS smb_load_module(const char *module_name) { void *handle; - init_module_function *init; - int status; + init_module_function init; + NTSTATUS status; const char *error; + struct stat st; + DIR *dir; + struct dirent *dirent; + + stat(module_name, &st); + + /* If the argument is a directory, recursively load all files / + * directories in it */ + + /* How about symlinks pointing to themselves - wouldn't we rather + * want to use wildcards here? */ + if(S_ISDIR(st.st_mode)) { + dir = opendir(module_name); + while(dirent = readdir(dir)) { + smb_load_module(dirent->d_name); + } + } /* Always try to use LAZY symbol resolving; if the plugin has * backwards compatibility, there might be symbols in the @@ -37,17 +57,17 @@ int smb_load_module(const char *module_name) if(!handle) { DEBUG(0, ("Error loading module '%s': %s\n", module_name, sys_dlerror())); - return False; + return NT_STATUS_UNSUCCESSFUL; } - init = sys_dlsym(handle, "init_module"); + init = (init_module_function)sys_dlsym(handle, "init_module"); /* we must check sys_dlerror() to determine if it worked, because sys_dlsym() can validly return NULL */ error = sys_dlerror(); if (error) { DEBUG(0, ("Error trying to resolve symbol 'init_module' in %s: %s\n", module_name, error)); - return False; + return NT_STATUS_UNSUCCESSFUL; } status = init(); @@ -65,7 +85,7 @@ int smb_load_modules(const char **modules) int success = 0; for(i = 0; modules[i]; i++){ - if(smb_load_module(modules[i])) { + if(NT_STATUS_IS_OK(smb_load_module(modules[i]))) { success++; } } @@ -75,47 +95,18 @@ int smb_load_modules(const char **modules) return success; } -int smb_probe_module(const char *subsystem, const char *module) -{ - char *full_path; - int rc; - TALLOC_CTX *mem_ctx; - - /* Check for absolute path */ - if(module[0] == '/')return smb_load_module(module); - - mem_ctx = talloc_init("smb_probe_module"); - if (!mem_ctx) { - DEBUG(0,("No memory for loading modules\n")); - return False; - } - full_path = talloc_strdup(mem_ctx, lib_path(mem_ctx, subsystem)); - full_path = talloc_asprintf(mem_ctx, "%s/%s.%s", - full_path, module, shlib_ext()); - - rc = smb_load_module(full_path); - talloc_destroy(mem_ctx); - return rc; -} - #else /* HAVE_DLOPEN */ -int smb_load_module(const char *module_name) +NTSTATUS smb_load_module(const char *module_name) { - DEBUG(0,("This samba executable has not been built with plugin support")); - return False; + DEBUG(0,("This samba executable has not been built with plugin support\n")); + return NT_STATUS_NOT_SUPPORTED; } int smb_load_modules(const char **modules) { - DEBUG(0,("This samba executable has not been built with plugin support")); - return False; -} - -int smb_probe_module(const char *subsystem, const char *module) -{ - DEBUG(0,("This samba executable has not been built with plugin support, not probing")); - return False; + DEBUG(0,("This samba executable has not been built with plugin support\n")); + return -1; } #endif /* HAVE_DLOPEN */ @@ -124,5 +115,38 @@ void init_modules(void) { if(lp_preload_modules()) smb_load_modules(lp_preload_modules()); - /* FIXME: load static modules */ +} + +struct subsystem { + char *name; + register_backend_function callback; + struct subsystem *prev, *next; +}; + +struct subsystem *subsystems = NULL; + +void register_subsystem(const char *name, register_backend_function callback) +{ + struct subsystem *s; + + s = smb_xmalloc(sizeof(struct subsystem)); + + s->name = smb_xstrdup(name); + s->callback = callback; + s->prev = s->next = NULL; + + DLIST_ADD(subsystems, s); +} + +NTSTATUS register_backend(const char *subsystem, void *args) +{ + /* Find the specified subsystem */ + struct subsystem *s = subsystems; + + while(s) { + if(!strcmp(subsystem, s->name)) return s->callback(args); + s = s->next; + } + + return NT_STATUS_NOT_IMPLEMENTED; } -- cgit