summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2003-11-25 03:15:26 +0000
committerJelmer Vernooij <jelmer@samba.org>2003-11-25 03:15:26 +0000
commita846e592058726b670e40505493a4668bd856186 (patch)
treeef949e82c7bbd5e58dffb11f75ecababcf10d369 /source4/lib
parent97dbe926ecbc71a8b0f423c07b09140f44647598 (diff)
downloadsamba-a846e592058726b670e40505493a4668bd856186.tar.gz
samba-a846e592058726b670e40505493a4668bd856186.tar.bz2
samba-a846e592058726b670e40505493a4668bd856186.zip
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)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/iconv.c11
-rw-r--r--source4/lib/module.c110
2 files changed, 74 insertions, 47 deletions
diff --git a/source4/lib/iconv.c b/source4/lib/iconv.c
index 8f85e29c2e..2a0b013257 100644
--- a/source4/lib/iconv.c
+++ b/source4/lib/iconv.c
@@ -63,8 +63,9 @@ static struct charset_functions builtin_functions[] = {
static struct charset_functions *charsets = NULL;
-BOOL smb_register_charset(struct charset_functions *funcs)
+static NTSTATUS charset_register_backend(void *_funcs)
{
+ struct charset_functions *funcs = (struct charset_functions *)_funcs;
struct charset_functions *c = charsets;
DEBUG(5, ("Attempting to register new charset %s\n", funcs->name));
@@ -72,7 +73,7 @@ BOOL smb_register_charset(struct charset_functions *funcs)
while(c) {
if(!strcasecmp(c->name, funcs->name)){
DEBUG(2, ("Duplicate charset %s, not registering\n", funcs->name));
- return False;
+ return NT_STATUS_OBJECT_NAME_COLLISION;
}
c = c->next;
}
@@ -80,7 +81,7 @@ BOOL smb_register_charset(struct charset_functions *funcs)
funcs->next = funcs->prev = NULL;
DEBUG(5, ("Registered charset %s\n", funcs->name));
DLIST_ADD(charsets, funcs);
- return True;
+ return NT_STATUS_OK;
}
static void lazy_initialize_iconv(void)
@@ -90,8 +91,10 @@ static void lazy_initialize_iconv(void)
if (!initialized) {
initialized = True;
+ register_subsystem("charset", charset_register_backend);
+
for(i = 0; builtin_functions[i].name; i++)
- smb_register_charset(&builtin_functions[i]);
+ register_backend("charset", &builtin_functions[i]);
}
}
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;
}