From 1f40ad5813679a979f110f4b5346abd2a7516b39 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 30 Oct 2002 11:52:36 +0000 Subject: Add initial vesion of new module system (This used to be commit b5d05d3ec6808465d27e15db2a9ff48804e2e78e) --- source3/lib/module.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 source3/lib/module.c (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c new file mode 100644 index 0000000000..e4d22e0bb7 --- /dev/null +++ b/source3/lib/module.c @@ -0,0 +1,63 @@ +/* + Unix SMB/CIFS implementation. + module loading system + + Copyright (C) Jelmer Vernooij 2002 + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#ifdef HAVE_DLOPEN +NTSTATUS smb_load_module(const char *module_name) +{ + void *handle; + init_module_function *init; + + /* Always try to use LAZY symbol resolving; if the plugin has + * backwards compatibility, there might be symbols in the + * plugin referencing to old (removed) functions + */ + handle = dlopen(module_name, RTLD_LAZY | RTLD_GLOBAL); + + if(!handle) { + DEBUG(0, ("Error loading module '%s': %s\n", module_name, sys_dlerror())); + return NT_STATUS_UNSUCCESSFUL; + } + + init = sys_dlsym(handle, "init_module"); + + if(!init) { + DEBUG(0, ("Error trying to resolve symbol 'init_module' in %s: %s\n", module_name, sys_dlerror())); + return NT_STATUS_UNSUCCESSFUL; + } + + init(); + + DEBUG(2, ("Module '%s' loaded\n", module_name)); + + return NT_STATUS_OK; +} + +#else /* HAVE_DLOPEN */ + +NTSTATUS smb_load_module(const char *module_name) +{ + DEBUG(0,("This samba executable has not been build with plugin support")); + return NT_STATUS_NOT_SUPPORTED; +} + +#endif /* HAVE_DLOPEN */ -- cgit From 04d21551e17a871f3d71d0bc66b9a8d25cecc2fb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 30 Oct 2002 12:07:49 +0000 Subject: - Remove RTLD_GLOBAL - make smb_load_module() return the return value of init_module() (This used to be commit a8d2dd8d009797486105188f8fdb898a65bb25b0) --- source3/lib/module.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index e4d22e0bb7..0953f53ad3 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -26,12 +26,13 @@ NTSTATUS smb_load_module(const char *module_name) { void *handle; init_module_function *init; + NTSTATUS nt_status; /* Always try to use LAZY symbol resolving; if the plugin has * backwards compatibility, there might be symbols in the * plugin referencing to old (removed) functions */ - handle = dlopen(module_name, RTLD_LAZY | RTLD_GLOBAL); + handle = dlopen(module_name, RTLD_LAZY); if(!handle) { DEBUG(0, ("Error loading module '%s': %s\n", module_name, sys_dlerror())); @@ -45,11 +46,11 @@ NTSTATUS smb_load_module(const char *module_name) return NT_STATUS_UNSUCCESSFUL; } - init(); + nt_status = init(); DEBUG(2, ("Module '%s' loaded\n", module_name)); - return NT_STATUS_OK; + return nt_status; } #else /* HAVE_DLOPEN */ -- cgit From 9dcba819338e9abb45162fb7d534df80390c624e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 30 Oct 2002 17:50:36 +0000 Subject: use sys_dlopen instead of dlopen (thanks to jra for noticing) (This used to be commit 86eb0a25b1df8ca25872f9846a74d0f13a4ad045) --- source3/lib/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 0953f53ad3..f05a68b493 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -32,7 +32,7 @@ NTSTATUS smb_load_module(const char *module_name) * backwards compatibility, there might be symbols in the * plugin referencing to old (removed) functions */ - handle = dlopen(module_name, RTLD_LAZY); + handle = sys_dlopen(module_name, RTLD_LAZY); if(!handle) { DEBUG(0, ("Error loading module '%s': %s\n", module_name, sys_dlerror())); -- cgit From fb6c6ec09ef2203eba93e90336d225265c4a7d9f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 31 Oct 2002 18:08:45 +0000 Subject: add smb_load_modules() to load a list of modules - does this function look ok ? (This used to be commit a82dbb3c22e6cb2096efb87c12a6006642806aac) --- source3/lib/module.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index f05a68b493..2d8bd7459f 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -53,6 +53,22 @@ NTSTATUS smb_load_module(const char *module_name) return nt_status; } +/* Load all modules in list and return number of + * modules that has been successfully loaded */ +int smb_load_modules(const char **modules) +{ + int i; + int success = 0; + + for(i = 0; modules[i]; i++){ + if(NT_STATUS_IS_OK(smb_load_module(modules[i]))) { + success++; + } + } + + return success; +} + #else /* HAVE_DLOPEN */ NTSTATUS smb_load_module(const char *module_name) @@ -61,4 +77,10 @@ NTSTATUS smb_load_module(const char *module_name) return NT_STATUS_NOT_SUPPORTED; } +int smb_load_modules(const char **modules) +{ + DEBUG(0,("This samba executable has not been build with plugin support")); + return -1; +} + #endif /* HAVE_DLOPEN */ -- cgit From 5988d5e92a123d7c1b509ecafe8d14db47c01b30 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 13 Nov 2002 13:47:12 +0000 Subject: Add a DEBUG() that gives the number of successfully loaded modules - useful for debugging (This used to be commit 612ea35ab016c56e6ad9886283901bc7b417337a) --- source3/lib/module.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 2d8bd7459f..5ad6485806 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -66,6 +66,8 @@ int smb_load_modules(const char **modules) } } + DEBUG(2, ("%d modules successfully loaded\n", success)); + return success; } -- cgit From 1793c8f1432d152848adce7a0b255b6f431bbc31 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 17 Jan 2003 21:23:14 +0000 Subject: dlsym() can return NULL validly, so we can't use that as the error test. dlerror() is the correct way to test. (This used to be commit 41b1be15bac271116a7096e511cc029685013e1f) --- source3/lib/module.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 5ad6485806..6febe8a9f1 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -27,6 +27,7 @@ NTSTATUS smb_load_module(const char *module_name) void *handle; init_module_function *init; NTSTATUS nt_status; + const char *error; /* Always try to use LAZY symbol resolving; if the plugin has * backwards compatibility, there might be symbols in the @@ -41,8 +42,11 @@ NTSTATUS smb_load_module(const char *module_name) init = sys_dlsym(handle, "init_module"); - if(!init) { - DEBUG(0, ("Error trying to resolve symbol 'init_module' in %s: %s\n", module_name, sys_dlerror())); + /* 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 NT_STATUS_UNSUCCESSFUL; } -- cgit From 7859c7df44bb6934bec06d8095c49f2f85c7b9eb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 20 Feb 2003 19:14:55 +0000 Subject: Merge in smb_load_module() function from HEAD (This used to be commit 6cb124247d10de86bdf6a98f3dd703b3a9eb1d35) --- source3/lib/module.c | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 6febe8a9f1..2498f6de2c 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -57,24 +57,6 @@ NTSTATUS smb_load_module(const char *module_name) return nt_status; } -/* Load all modules in list and return number of - * modules that has been successfully loaded */ -int smb_load_modules(const char **modules) -{ - int i; - int success = 0; - - for(i = 0; modules[i]; i++){ - if(NT_STATUS_IS_OK(smb_load_module(modules[i]))) { - success++; - } - } - - DEBUG(2, ("%d modules successfully loaded\n", success)); - - return success; -} - #else /* HAVE_DLOPEN */ NTSTATUS smb_load_module(const char *module_name) @@ -83,10 +65,4 @@ NTSTATUS smb_load_module(const char *module_name) return NT_STATUS_NOT_SUPPORTED; } -int smb_load_modules(const char **modules) -{ - DEBUG(0,("This samba executable has not been build with plugin support")); - return -1; -} - #endif /* HAVE_DLOPEN */ -- cgit From 7fcbdf00f6bba44d44e560176468605311e81d67 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Apr 2003 22:23:02 +0000 Subject: Add some more functions for the modules (backport from HEAD): - init_modules() - smb_probe_module() (This used to be commit b3328dab2fa069af300b4076695bf6c359501111) --- source3/lib/module.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 88 insertions(+), 9 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 2498f6de2c..763a5c2b2d 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -22,11 +22,11 @@ #include "includes.h" #ifdef HAVE_DLOPEN -NTSTATUS smb_load_module(const char *module_name) +int smb_load_module(const char *module_name) { void *handle; init_module_function *init; - NTSTATUS nt_status; + int status; const char *error; /* Always try to use LAZY symbol resolving; if the plugin has @@ -37,7 +37,7 @@ NTSTATUS smb_load_module(const char *module_name) if(!handle) { DEBUG(0, ("Error loading module '%s': %s\n", module_name, sys_dlerror())); - return NT_STATUS_UNSUCCESSFUL; + return False; } init = sys_dlsym(handle, "init_module"); @@ -47,22 +47,101 @@ NTSTATUS smb_load_module(const char *module_name) error = sys_dlerror(); if (error) { DEBUG(0, ("Error trying to resolve symbol 'init_module' in %s: %s\n", module_name, error)); - return NT_STATUS_UNSUCCESSFUL; + return False; } - nt_status = init(); + status = init(); DEBUG(2, ("Module '%s' loaded\n", module_name)); - return nt_status; + return status; +} + +/* Load all modules in list and return number of + * modules that has been successfully loaded */ +int smb_load_modules(const char **modules) +{ + int i; + int success = 0; + + for(i = 0; modules[i]; i++){ + if(smb_load_module(modules[i])) { + success++; + } + } + + DEBUG(2, ("%d modules successfully loaded\n", success)); + + return success; +} + +int smb_probe_module(const char *subsystem, const char *module) +{ + pstring full_path; + + /* Check for absolute path */ + if(strchr_m(module, '/'))return smb_load_module(module); + + pstrcpy(full_path, lib_path(subsystem)); + pstrcat(full_path, "/"); + pstrcat(full_path, module); + pstrcat(full_path, "."); + pstrcat(full_path, shlib_ext()); + + DEBUG(5, ("Probing module %s: Trying to load from %s\n", module, full_path)); + + return smb_load_module(full_path); } #else /* HAVE_DLOPEN */ -NTSTATUS smb_load_module(const char *module_name) +int smb_load_module(const char *module_name) +{ + DEBUG(0,("This samba executable has not been built with plugin support")); + return False; +} + +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 build with plugin support")); - return NT_STATUS_NOT_SUPPORTED; + DEBUG(0,("This samba executable has not been built with plugin support, not probing")); + return False; } #endif /* HAVE_DLOPEN */ + +void init_modules(void) +{ + /* FIXME: This can cause undefined symbol errors : + * smb_register_vfs() isn't available in nmbd, for example */ + if(lp_preload_modules()) + smb_load_modules(lp_preload_modules()); +} + + +/************************************************************************* + * This functions /path/to/foobar.so -> foobar + ************************************************************************/ +void module_path_get_name(const char *path, pstring name) +{ + char *s; + + /* First, make the path relative */ + s = strrchr(path, '/'); + if(s) pstrcpy(name, s+1); + else pstrcpy(name, path); + + if (dyn_SHLIBEXT && *dyn_SHLIBEXT && strlen(dyn_SHLIBEXT) < strlen(name)) { + int n = strlen(name) - strlen(dyn_SHLIBEXT); + + /* Remove extension if necessary */ + if (name[n-1] == '.' && !strcmp(name+n, dyn_SHLIBEXT)) { + name[n-1] = '\0'; + } + } +} -- cgit From c7a6388e7ebd8ed1957b6157157a559bbb6814c0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 24 Apr 2003 19:47:37 +0000 Subject: Check for absolute paths by only checking the first character of the module name. Don't use strchr_m, which caused race conditions. (This used to be commit 69ec6be90f889686641b997d3d5cd616e1d0db6d) --- source3/lib/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 763a5c2b2d..53223cfebe 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -80,7 +80,7 @@ int smb_probe_module(const char *subsystem, const char *module) pstring full_path; /* Check for absolute path */ - if(strchr_m(module, '/'))return smb_load_module(module); + if(module[0] == '/')return smb_load_module(module); pstrcpy(full_path, lib_path(subsystem)); pstrcat(full_path, "/"); -- cgit From 17a3acafa89bfc6090b0767d05a00a7505003fcc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 28 Apr 2003 17:48:48 +0000 Subject: Use NTSTATUS as return value for smb_register_*() functions and init_module() function. Patch by metze with some minor modifications. (This used to be commit bc4b51bcb2daa7271c884cb83bf8bdba6d3a9b6d) --- source3/lib/module.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 53223cfebe..087c964d3c 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -22,11 +22,11 @@ #include "includes.h" #ifdef HAVE_DLOPEN -int smb_load_module(const char *module_name) +NTSTATUS smb_load_module(const char *module_name) { void *handle; init_module_function *init; - int status; + NTSTATUS status; const char *error; /* Always try to use LAZY symbol resolving; if the plugin has @@ -37,7 +37,7 @@ 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"); @@ -47,7 +47,7 @@ int smb_load_module(const char *module_name) 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 +65,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,7 +75,7 @@ int smb_load_modules(const char **modules) return success; } -int smb_probe_module(const char *subsystem, const char *module) +NTSTATUS smb_probe_module(const char *subsystem, const char *module) { pstring full_path; @@ -95,22 +95,22 @@ int smb_probe_module(const char *subsystem, const char *module) #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; + 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; + return -1; } -int smb_probe_module(const char *subsystem, const char *module) +NTSTATUS 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; + return NT_STATUS_NOT_SUPPORTED; } #endif /* HAVE_DLOPEN */ -- cgit From 24ee1418054e60e60f36009a1845b4b616ee63a1 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 3 May 2003 04:34:13 +0000 Subject: Add a comment about the use of string functions in the modules code, and add \n to the end of the non-dlopen case DEBUGs. Andrew Bartlett (This used to be commit ce4ff4cc8e5f5d461797e42b2148b2827c058380) --- source3/lib/module.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 087c964d3c..6b0309026b 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -80,7 +80,12 @@ NTSTATUS smb_probe_module(const char *subsystem, const char *module) pstring full_path; /* Check for absolute path */ - if(module[0] == '/')return smb_load_module(module); + + /* if we make any 'samba multibyte string' + calls here, we break + for loading string modules */ + if (module[0] == '/') + return smb_load_module(module); pstrcpy(full_path, lib_path(subsystem)); pstrcat(full_path, "/"); @@ -97,19 +102,19 @@ NTSTATUS smb_probe_module(const char *subsystem, const char *module) NTSTATUS smb_load_module(const char *module_name) { - DEBUG(0,("This samba executable has not been built with plugin support")); + 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")); + DEBUG(0,("This samba executable has not been built with plugin support\n")); return -1; } NTSTATUS smb_probe_module(const char *subsystem, const char *module) { - DEBUG(0,("This samba executable has not been built with plugin support, not probing")); + DEBUG(0,("This samba executable has not been built with plugin support, not probing\n")); return NT_STATUS_NOT_SUPPORTED; } -- cgit From 06551c644c75ab2aa14a3cc3c4afbcbb08369133 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 6 May 2003 02:34:59 +0000 Subject: Patch from metze to add exit and interval events. Useful for modules (This used to be commit 3033a63cefb5f28d4460885f7f4e4ecaed95443c) --- source3/lib/module.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 6b0309026b..c47ca96dcc 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -2,7 +2,8 @@ Unix SMB/CIFS implementation. module loading system - Copyright (C) Jelmer Vernooij 2002 + Copyright (C) Jelmer Vernooij 2002-2003 + Copyright (C) Stefan (metze) Metzmacher 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 @@ -150,3 +151,111 @@ void module_path_get_name(const char *path, pstring name) } } } + + +/*************************************************************************** + * This Function registers a idle event + * + * the registered funtions are run periodically + * and maybe shutdown idle connections (e.g. to an LDAP server) + ***************************************************************************/ +static smb_idle_event_struct *smb_idle_event_list = NULL; +NTSTATUS smb_register_idle_event(smb_idle_event_struct *idle_event) +{ + smb_idle_event_struct *tmp_event = smb_idle_event_list; + + if (!idle_event) { + return NT_STATUS_INVALID_PARAMETER; + } + + idle_event->last_run = 0; + + DLIST_ADD(smb_idle_event_list,idle_event); + + return NT_STATUS_OK; +} + +NTSTATUS smb_unregister_idle_event(smb_idle_event_struct *idle_event) +{ + if (!idle_event) { + return NT_STATUS_INVALID_PARAMETER; + } + + DLIST_REMOVE(smb_idle_event_list,idle_event); + + return NT_STATUS_OK; +} + +void smb_run_idle_events(time_t now) +{ + smb_idle_event_struct *tmp_event = smb_idle_event_list; + + while (tmp_event) { + time_t interval; + + if (tmp_event->fn) { + if (tmp_event->interval >= SMB_IDLE_EVENT_MIN_INTERVAL) { + interval = tmp_event->interval; + } else { + interval = SMB_IDLE_EVENT_DEFAULT_INTERVAL; + } + if (now >(tmp_event->last_run+interval)) { + tmp_event->fn(&tmp_event,now); + tmp_event->last_run = now; + } + } + + tmp_event = tmp_event->next; + } + + return; +} + +/*************************************************************************** + * This Function registers a exit event + * + * the registered funtions are run on exit() + * and maybe shutdown idle connections (e.g. to an LDAP server) + ***************************************************************************/ +static smb_exit_event_struct *smb_exit_event_list = NULL; +NTSTATUS smb_register_exit_event(smb_exit_event_struct *exit_event) +{ + smb_exit_event_struct *tmp_event = smb_exit_event_list; + + if (!exit_event) { + return NT_STATUS_INVALID_PARAMETER; + } + + DLIST_ADD(smb_exit_event_list,exit_event); + + return NT_STATUS_OK; +} + +NTSTATUS smb_unregister_exit_event(smb_exit_event_struct *exit_event) +{ + if (!exit_event) { + return NT_STATUS_INVALID_PARAMETER; + } + + DLIST_REMOVE(smb_exit_event_list,exit_event); + + return NT_STATUS_OK; +} + +void smb_run_exit_events(void) +{ + smb_exit_event_struct *tmp_event = smb_exit_event_list; + + while (tmp_event) { + if (tmp_event->fn) { + tmp_event->fn(&tmp_event); + } + tmp_event = tmp_event->next; + } + + /* run exit_events only once */ + smb_exit_event_list = NULL; + + return; +} + -- cgit From ecbd2b5d1e891472aab2d1ebd2cbadef0db86060 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 6 May 2003 02:35:33 +0000 Subject: Remove unused variables (This used to be commit 2f631769f836baeec669456f786ecb38c81d9a23) --- source3/lib/module.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index c47ca96dcc..811efae311 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -162,8 +162,6 @@ void module_path_get_name(const char *path, pstring name) static smb_idle_event_struct *smb_idle_event_list = NULL; NTSTATUS smb_register_idle_event(smb_idle_event_struct *idle_event) { - smb_idle_event_struct *tmp_event = smb_idle_event_list; - if (!idle_event) { return NT_STATUS_INVALID_PARAMETER; } @@ -220,8 +218,6 @@ void smb_run_idle_events(time_t now) static smb_exit_event_struct *smb_exit_event_list = NULL; NTSTATUS smb_register_exit_event(smb_exit_event_struct *exit_event) { - smb_exit_event_struct *tmp_event = smb_exit_event_list; - if (!exit_event) { return NT_STATUS_INVALID_PARAMETER; } -- cgit From e731ec1ed6e92f9a088e1bdfaca5491c90277ae1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 29 May 2003 14:40:55 +0000 Subject: Get the events API right. Patch from metze with some minor modifications. (This used to be commit 2aad5736256968f27c42a6f94bdbc7a22c236c19) --- source3/lib/module.c | 154 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 103 insertions(+), 51 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 811efae311..4437d085f9 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -159,51 +159,76 @@ void module_path_get_name(const char *path, pstring name) * the registered funtions are run periodically * and maybe shutdown idle connections (e.g. to an LDAP server) ***************************************************************************/ -static smb_idle_event_struct *smb_idle_event_list = NULL; -NTSTATUS smb_register_idle_event(smb_idle_event_struct *idle_event) +static smb_event_id_t smb_idle_event_id = 1; + +struct smb_idle_list_ent { + struct smb_idle_list_ent *prev,*next; + smb_event_id_t id; + smb_idle_event_fn *fn; + void *data; + time_t interval; + time_t lastrun; +}; + +static struct smb_idle_list_ent *smb_idle_event_list = NULL; + +smb_event_id_t smb_register_idle_event(smb_idle_event_fn *fn, void *data, time_t interval) { - if (!idle_event) { - return NT_STATUS_INVALID_PARAMETER; + struct smb_idle_list_ent *event; + + if (!fn) { + return SMB_EVENT_ID_INVALID; } - idle_event->last_run = 0; + event = (struct smb_idle_list_ent *)malloc(sizeof(struct smb_idle_list_ent)); + if (!event) { + DEBUG(0,("malloc() failed!\n")); + return SMB_EVENT_ID_INVALID; + } + event->fn = fn; + event->data = data; + event->interval = interval; + event->lastrun = 0; + event->id = smb_idle_event_id++; - DLIST_ADD(smb_idle_event_list,idle_event); + DLIST_ADD(smb_idle_event_list,event); - return NT_STATUS_OK; + return event->id; } -NTSTATUS smb_unregister_idle_event(smb_idle_event_struct *idle_event) +BOOL smb_unregister_idle_event(smb_event_id_t id) { - if (!idle_event) { - return NT_STATUS_INVALID_PARAMETER; + struct smb_idle_list_ent *event = smb_idle_event_list; + + while(event) { + if (event->id == id) { + DLIST_REMOVE(smb_idle_event_list,event); + SAFE_FREE(event); + return True; + } + event = event->next; } - - DLIST_REMOVE(smb_idle_event_list,idle_event); - - return NT_STATUS_OK; + + return False; } void smb_run_idle_events(time_t now) { - smb_idle_event_struct *tmp_event = smb_idle_event_list; + struct smb_idle_list_ent *event = smb_idle_event_list; - while (tmp_event) { + while (event) { time_t interval; - if (tmp_event->fn) { - if (tmp_event->interval >= SMB_IDLE_EVENT_MIN_INTERVAL) { - interval = tmp_event->interval; - } else { - interval = SMB_IDLE_EVENT_DEFAULT_INTERVAL; - } - if (now >(tmp_event->last_run+interval)) { - tmp_event->fn(&tmp_event,now); - tmp_event->last_run = now; - } + if (event->interval >= SMB_IDLE_EVENT_MIN_INTERVAL) { + interval = event->interval; + } else { + interval = SMB_IDLE_EVENT_MIN_INTERVAL; } - - tmp_event = tmp_event->next; + if (now >(event->lastrun+interval)) { + event->fn(&event->data,&event->interval,now); + event->lastrun = now; + } + event = event->next; } return; @@ -212,46 +237,73 @@ void smb_run_idle_events(time_t now) /*************************************************************************** * This Function registers a exit event * - * the registered funtions are run on exit() + * the registered functions are run on exit() * and maybe shutdown idle connections (e.g. to an LDAP server) ***************************************************************************/ -static smb_exit_event_struct *smb_exit_event_list = NULL; -NTSTATUS smb_register_exit_event(smb_exit_event_struct *exit_event) + +struct smb_exit_list_ent { + struct smb_exit_list_ent *prev,*next; + smb_event_id_t id; + smb_exit_event_fn *fn; + void *data; +}; + +static struct smb_exit_list_ent *smb_exit_event_list = NULL; + +smb_event_id_t smb_register_exit_event(smb_exit_event_fn *fn, void *data) { - if (!exit_event) { - return NT_STATUS_INVALID_PARAMETER; + struct smb_exit_list_ent *event; + static smb_event_id_t smb_exit_event_id = 1; + + if (!fn) { + return SMB_EVENT_ID_INVALID; } - DLIST_ADD(smb_exit_event_list,exit_event); + event = (struct smb_exit_list_ent *)malloc(sizeof(struct smb_exit_list_ent)); + if (!event) { + DEBUG(0,("malloc() failed!\n")); + return SMB_EVENT_ID_INVALID; + } + event->fn = fn; + event->data = data; + event->id = smb_exit_event_id++; - return NT_STATUS_OK; + DLIST_ADD(smb_exit_event_list,event); + + return event->id; } -NTSTATUS smb_unregister_exit_event(smb_exit_event_struct *exit_event) +BOOL smb_unregister_exit_event(smb_event_id_t id) { - if (!exit_event) { - return NT_STATUS_INVALID_PARAMETER; + struct smb_exit_list_ent *event = smb_exit_event_list; + + while(event) { + if (event->id == id) { + DLIST_REMOVE(smb_exit_event_list,event); + SAFE_FREE(event); + return True; + } + event = event->next; } - - DLIST_REMOVE(smb_exit_event_list,exit_event); - - return NT_STATUS_OK; + + return False; } void smb_run_exit_events(void) { - smb_exit_event_struct *tmp_event = smb_exit_event_list; - - while (tmp_event) { - if (tmp_event->fn) { - tmp_event->fn(&tmp_event); - } - tmp_event = tmp_event->next; + struct smb_exit_list_ent *event = smb_exit_event_list; + struct smb_exit_list_ent *tmp = NULL; + + while (event) { + event->fn(&event->data); + tmp = event; + event = event->next; + /* exit event should only run one time :-)*/ + SAFE_FREE(tmp); } - /* run exit_events only once */ + /* the list is empty now...*/ smb_exit_event_list = NULL; return; } - -- cgit From ff0a111d37e6da352f6a00a45aee3231c737af64 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 30 May 2003 16:36:38 +0000 Subject: Remove module_path_get_name() - it's not used anywhere anymore and was a bad idea anyway. (This used to be commit b45a67e7a9d0fab5b4af701a9fd483cc4897ab7f) --- source3/lib/module.c | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 4437d085f9..ac4fe57a2c 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -130,29 +130,6 @@ void init_modules(void) } -/************************************************************************* - * This functions /path/to/foobar.so -> foobar - ************************************************************************/ -void module_path_get_name(const char *path, pstring name) -{ - char *s; - - /* First, make the path relative */ - s = strrchr(path, '/'); - if(s) pstrcpy(name, s+1); - else pstrcpy(name, path); - - if (dyn_SHLIBEXT && *dyn_SHLIBEXT && strlen(dyn_SHLIBEXT) < strlen(name)) { - int n = strlen(name) - strlen(dyn_SHLIBEXT); - - /* Remove extension if necessary */ - if (name[n-1] == '.' && !strcmp(name+n, dyn_SHLIBEXT)) { - name[n-1] = '\0'; - } - } -} - - /*************************************************************************** * This Function registers a idle event * -- cgit From aa39cc37dab9c4f8c3295d872bb8cc143890b378 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Fri, 15 Aug 2003 04:42:05 +0000 Subject: get rid of more compiler warnings (This used to be commit 398bd14fc6e2f8ab2f34211270e179b8928a6669) --- source3/lib/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index ac4fe57a2c..d860cba819 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -41,7 +41,7 @@ NTSTATUS smb_load_module(const char *module_name) 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 */ -- cgit From fb638ddf99897fe846250d07d40e60fbe2a688c9 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 4 Sep 2003 02:02:26 +0000 Subject: Quieten level 0 debug when probing for modules. We shouldn't display so loud an error when a smb_probe_module() fails. Also tidy up debugs a bit. Bug 375. (This used to be commit 24a1720472f1340778dea76a88770520dca26f12) --- source3/lib/module.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index d860cba819..e2c6f6dcf5 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -23,7 +23,11 @@ #include "includes.h" #ifdef HAVE_DLOPEN -NTSTATUS smb_load_module(const char *module_name) + +/* Load a dynamic module. Only log a level 0 error if we are not checking + for the existence of a module (probling). */ + +static NTSTATUS do_smb_load_module(const char *module_name, BOOL is_probe) { void *handle; init_module_function *init; @@ -37,7 +41,10 @@ NTSTATUS smb_load_module(const char *module_name) handle = sys_dlopen(module_name, RTLD_LAZY); if(!handle) { - DEBUG(0, ("Error loading module '%s': %s\n", module_name, sys_dlerror())); + int level = is_probe ? 2 : 0; + DEBUG(level, ("Error loading module '%s': %s\n", module_name, + sys_dlerror())); + return NT_STATUS_UNSUCCESSFUL; } @@ -47,7 +54,8 @@ NTSTATUS smb_load_module(const char *module_name) 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)); + DEBUG(0, ("Error trying to resolve symbol 'init_module' in %s: %s\n", + module_name, error)); return NT_STATUS_UNSUCCESSFUL; } @@ -58,6 +66,11 @@ NTSTATUS smb_load_module(const char *module_name) return status; } +NTSTATUS smb_load_module(const char *module_name) +{ + return do_smb_load_module(module_name, False); +} + /* Load all modules in list and return number of * modules that has been successfully loaded */ int smb_load_modules(const char **modules) @@ -85,8 +98,11 @@ NTSTATUS smb_probe_module(const char *subsystem, const char *module) /* if we make any 'samba multibyte string' calls here, we break for loading string modules */ + + DEBUG(5, ("Probing module '%s'\n", module)); + if (module[0] == '/') - return smb_load_module(module); + return do_smb_load_module(module, True); pstrcpy(full_path, lib_path(subsystem)); pstrcat(full_path, "/"); @@ -94,9 +110,9 @@ NTSTATUS smb_probe_module(const char *subsystem, const char *module) pstrcat(full_path, "."); pstrcat(full_path, shlib_ext()); - DEBUG(5, ("Probing module %s: Trying to load from %s\n", module, full_path)); + DEBUG(5, ("Probing module '%s': Trying to load from %s\n", module, full_path)); - return smb_load_module(full_path); + return do_smb_load_module(full_path, True); } #else /* HAVE_DLOPEN */ -- cgit From 1d7e64e091573d34427585b36e88f815799c30f3 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 15 Sep 2003 00:19:25 +0000 Subject: For some reason testparm runs at debug level 2 which causes the module probe functions to display verbose debugs. Increase the probe debugs to level 3. (This used to be commit d71a7470d721be05ecde44010cf278e8de08d9d3) --- source3/lib/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index e2c6f6dcf5..941a6cfbe3 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -41,7 +41,7 @@ static NTSTATUS do_smb_load_module(const char *module_name, BOOL is_probe) handle = sys_dlopen(module_name, RTLD_LAZY); if(!handle) { - int level = is_probe ? 2 : 0; + int level = is_probe ? 3 : 0; DEBUG(level, ("Error loading module '%s': %s\n", module_name, sys_dlerror())); -- cgit From 6fc85b32339a6bc543fbf5c5be97bd2b7a570b6a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 17 Sep 2003 23:36:55 +0000 Subject: Unregister event fix from metze. Jeremy. (This used to be commit 0aee73d45733a8eca437954e0c9fd54884bbe770) --- source3/lib/module.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 941a6cfbe3..38fcf0f329 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -210,18 +210,21 @@ void smb_run_idle_events(time_t now) struct smb_idle_list_ent *event = smb_idle_event_list; while (event) { + struct smb_idle_list_ent *next = event->next; time_t interval; - if (event->interval >= SMB_IDLE_EVENT_MIN_INTERVAL) { + if (event->interval <= 0) { + interval = SMB_IDLE_EVENT_DEFAULT_INTERVAL; + } else if (event->interval >= SMB_IDLE_EVENT_MIN_INTERVAL) { interval = event->interval; } else { interval = SMB_IDLE_EVENT_MIN_INTERVAL; } if (now >(event->lastrun+interval)) { - event->fn(&event->data,&event->interval,now); event->lastrun = now; + event->fn(&event->data,&event->interval,now); } - event = event->next; + event = next; } return; -- cgit From 8614cc504e0ae85168b6e82c0be83d9bc79f4b84 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 19 Nov 2003 22:57:56 +0000 Subject: Look at error before using it in debug statement. Jeremy. (This used to be commit 69550332f33496b0a513914e2290fdb256bc2958) --- source3/lib/module.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 38fcf0f329..2abe918ef4 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -42,9 +42,8 @@ static NTSTATUS do_smb_load_module(const char *module_name, BOOL is_probe) if(!handle) { int level = is_probe ? 3 : 0; - DEBUG(level, ("Error loading module '%s': %s\n", module_name, - sys_dlerror())); - + error = sys_dlerror(); + DEBUG(level, ("Error loading module '%s': %s\n", module_name, error ? error : "")); return NT_STATUS_UNSUCCESSFUL; } -- cgit From 93435b50961018c1710f4ce1acb715dc2b1a6dcb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 30 Nov 2004 01:01:43 +0000 Subject: r4009: Fix from Timur Bakeyev for bugid #2100, change the way we check for errors after a dlopen (which may set internal warnings which get picked up by mistake in dlsym). Jeremy (This used to be commit 6711cb8b02f96d04af82d30b1274f76dc5461dc2) --- source3/lib/module.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 2abe918ef4..e469b1da42 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -40,9 +40,12 @@ static NTSTATUS do_smb_load_module(const char *module_name, BOOL is_probe) */ handle = sys_dlopen(module_name, RTLD_LAZY); + /* This call should reset any possible non-fatal errors that + occured since last call to dl* functions */ + error = sys_dlerror(); + if(!handle) { int level = is_probe ? 3 : 0; - error = sys_dlerror(); DEBUG(level, ("Error loading module '%s': %s\n", module_name, error ? error : "")); return NT_STATUS_UNSUCCESSFUL; } -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/lib/module.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index e469b1da42..49121d12ca 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -175,7 +175,7 @@ smb_event_id_t smb_register_idle_event(smb_idle_event_fn *fn, void *data, time_t return SMB_EVENT_ID_INVALID; } - event = (struct smb_idle_list_ent *)malloc(sizeof(struct smb_idle_list_ent)); + event = SMB_MALLOC_P(struct smb_idle_list_ent); if (!event) { DEBUG(0,("malloc() failed!\n")); return SMB_EVENT_ID_INVALID; @@ -257,7 +257,7 @@ smb_event_id_t smb_register_exit_event(smb_exit_event_fn *fn, void *data) return SMB_EVENT_ID_INVALID; } - event = (struct smb_exit_list_ent *)malloc(sizeof(struct smb_exit_list_ent)); + event = SMB_MALLOC_P(struct smb_exit_list_ent); if (!event) { DEBUG(0,("malloc() failed!\n")); return SMB_EVENT_ID_INVALID; -- cgit From 54abd2aa66069e6baf7769c496f46d9dba18db39 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 30 Sep 2005 17:13:37 +0000 Subject: r10656: BIG merge from trunk. Features not copied over * \PIPE\unixinfo * winbindd's {group,alias}membership new functions * winbindd's lookupsids() functionality * swat (trunk changes to be reverted as per discussion with Deryck) (This used to be commit 939c3cb5d78e3a2236209b296aa8aba8bdce32d3) --- source3/lib/module.c | 74 ---------------------------------------------------- 1 file changed, 74 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 49121d12ca..885faf8d80 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -231,77 +231,3 @@ void smb_run_idle_events(time_t now) return; } - -/*************************************************************************** - * This Function registers a exit event - * - * the registered functions are run on exit() - * and maybe shutdown idle connections (e.g. to an LDAP server) - ***************************************************************************/ - -struct smb_exit_list_ent { - struct smb_exit_list_ent *prev,*next; - smb_event_id_t id; - smb_exit_event_fn *fn; - void *data; -}; - -static struct smb_exit_list_ent *smb_exit_event_list = NULL; - -smb_event_id_t smb_register_exit_event(smb_exit_event_fn *fn, void *data) -{ - struct smb_exit_list_ent *event; - static smb_event_id_t smb_exit_event_id = 1; - - if (!fn) { - return SMB_EVENT_ID_INVALID; - } - - event = SMB_MALLOC_P(struct smb_exit_list_ent); - if (!event) { - DEBUG(0,("malloc() failed!\n")); - return SMB_EVENT_ID_INVALID; - } - event->fn = fn; - event->data = data; - event->id = smb_exit_event_id++; - - DLIST_ADD(smb_exit_event_list,event); - - return event->id; -} - -BOOL smb_unregister_exit_event(smb_event_id_t id) -{ - struct smb_exit_list_ent *event = smb_exit_event_list; - - while(event) { - if (event->id == id) { - DLIST_REMOVE(smb_exit_event_list,event); - SAFE_FREE(event); - return True; - } - event = event->next; - } - - return False; -} - -void smb_run_exit_events(void) -{ - struct smb_exit_list_ent *event = smb_exit_event_list; - struct smb_exit_list_ent *tmp = NULL; - - while (event) { - event->fn(&event->data); - tmp = event; - event = event->next; - /* exit event should only run one time :-)*/ - SAFE_FREE(tmp); - } - - /* the list is empty now...*/ - smb_exit_event_list = NULL; - - return; -} -- cgit From 89c6f04df04a6fb1efb0f73fad7963f497a93409 Mon Sep 17 00:00:00 2001 From: James Peach Date: Wed, 17 May 2006 00:51:42 +0000 Subject: r15655: Log the result of module initialisation if it fails. (This used to be commit 3446ee5c00e114fd6697b2d70888d55ad79e63f9) --- source3/lib/module.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 885faf8d80..092a68cd68 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -61,10 +61,14 @@ static NTSTATUS do_smb_load_module(const char *module_name, BOOL is_probe) return NT_STATUS_UNSUCCESSFUL; } - status = init(); - DEBUG(2, ("Module '%s' loaded\n", module_name)); + status = init(); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("Module '%s' initialization failed: %s\n", + module_name, get_friendly_nt_error_msg(status))); + } + return status; } -- cgit From 0d91334fe799f6b50a8265f9dc097411c3a29e18 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 11 Mar 2007 16:49:16 +0000 Subject: r21784: Replace smb_register_idle_event() with event_add_timed(). This fixes winbind who did not run the idle events to drop ldap connections. Volker (This used to be commit af3308ce5a21220ff4c510de356dbaa6cf9ff997) --- source3/lib/module.c | 85 ---------------------------------------------------- 1 file changed, 85 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 092a68cd68..96a37ae6b5 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -150,88 +150,3 @@ void init_modules(void) if(lp_preload_modules()) smb_load_modules(lp_preload_modules()); } - - -/*************************************************************************** - * This Function registers a idle event - * - * the registered funtions are run periodically - * and maybe shutdown idle connections (e.g. to an LDAP server) - ***************************************************************************/ -static smb_event_id_t smb_idle_event_id = 1; - -struct smb_idle_list_ent { - struct smb_idle_list_ent *prev,*next; - smb_event_id_t id; - smb_idle_event_fn *fn; - void *data; - time_t interval; - time_t lastrun; -}; - -static struct smb_idle_list_ent *smb_idle_event_list = NULL; - -smb_event_id_t smb_register_idle_event(smb_idle_event_fn *fn, void *data, time_t interval) -{ - struct smb_idle_list_ent *event; - - if (!fn) { - return SMB_EVENT_ID_INVALID; - } - - event = SMB_MALLOC_P(struct smb_idle_list_ent); - if (!event) { - DEBUG(0,("malloc() failed!\n")); - return SMB_EVENT_ID_INVALID; - } - event->fn = fn; - event->data = data; - event->interval = interval; - event->lastrun = 0; - event->id = smb_idle_event_id++; - - DLIST_ADD(smb_idle_event_list,event); - - return event->id; -} - -BOOL smb_unregister_idle_event(smb_event_id_t id) -{ - struct smb_idle_list_ent *event = smb_idle_event_list; - - while(event) { - if (event->id == id) { - DLIST_REMOVE(smb_idle_event_list,event); - SAFE_FREE(event); - return True; - } - event = event->next; - } - - return False; -} - -void smb_run_idle_events(time_t now) -{ - struct smb_idle_list_ent *event = smb_idle_event_list; - - while (event) { - struct smb_idle_list_ent *next = event->next; - time_t interval; - - if (event->interval <= 0) { - interval = SMB_IDLE_EVENT_DEFAULT_INTERVAL; - } else if (event->interval >= SMB_IDLE_EVENT_MIN_INTERVAL) { - interval = event->interval; - } else { - interval = SMB_IDLE_EVENT_MIN_INTERVAL; - } - if (now >(event->lastrun+interval)) { - event->lastrun = now; - event->fn(&event->data,&event->interval,now); - } - event = next; - } - - return; -} -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/lib/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 96a37ae6b5..eaf96babb9 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -7,7 +7,7 @@ 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 2 of the License, or + 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, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/lib/module.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index eaf96babb9..1bf305ea3f 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -16,8 +16,7 @@ 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 3aaca8028e09db58381076f199a43680f81f04ac Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 14 Sep 2007 22:03:41 +0000 Subject: r25170: Remove pstring limits from ms_fnmatch and module load. Jeremy. (This used to be commit 764574ee05ea4f13cdd30c0a0668ffeb81756989) --- source3/lib/module.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 1bf305ea3f..beb9bc9b92 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -76,7 +76,7 @@ NTSTATUS smb_load_module(const char *module_name) return do_smb_load_module(module_name, False); } -/* Load all modules in list and return number of +/* Load all modules in list and return number of * modules that has been successfully loaded */ int smb_load_modules(const char **modules) { @@ -96,28 +96,38 @@ int smb_load_modules(const char **modules) NTSTATUS smb_probe_module(const char *subsystem, const char *module) { - pstring full_path; - + char *full_path = NULL; + TALLOC_CTX *ctx = talloc_stackframe(); + NTSTATUS status; + /* Check for absolute path */ - /* if we make any 'samba multibyte string' - calls here, we break + /* if we make any 'samba multibyte string' + calls here, we break for loading string modules */ DEBUG(5, ("Probing module '%s'\n", module)); if (module[0] == '/') return do_smb_load_module(module, True); - - pstrcpy(full_path, lib_path(subsystem)); - pstrcat(full_path, "/"); - pstrcat(full_path, module); - pstrcat(full_path, "."); - pstrcat(full_path, shlib_ext()); - - DEBUG(5, ("Probing module '%s': Trying to load from %s\n", module, full_path)); - - return do_smb_load_module(full_path, True); + + full_path = talloc_asprintf(ctx, + "%s/%s.%s", + lib_path(subsystem), + module, + shlib_ext()); + if (!full_path) { + TALLOC_FREE(ctx); + return NT_STATUS_NO_MEMORY; + } + + DEBUG(5, ("Probing module '%s': Trying to load from %s\n", + module, full_path)); + + status = do_smb_load_module(full_path, True); + + TALLOC_FREE(ctx); + return status; } #else /* HAVE_DLOPEN */ -- cgit From f0653fd572bbc7f924767f76853432fc29861a1c Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 25 Sep 2007 22:43:42 +0000 Subject: r25326: Free the context from the talloc_stackframe. Guenther (This used to be commit 0719835c4d979c91d11b139e5b424b5e0dc2a2c2) --- source3/lib/module.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index beb9bc9b92..57b4c38edc 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -108,8 +108,11 @@ NTSTATUS smb_probe_module(const char *subsystem, const char *module) DEBUG(5, ("Probing module '%s'\n", module)); - if (module[0] == '/') - return do_smb_load_module(module, True); + if (module[0] == '/') { + status = do_smb_load_module(module, True); + TALLOC_FREE(ctx); + return status; + } full_path = talloc_asprintf(ctx, "%s/%s.%s", -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/lib/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 57b4c38edc..fa06d14b49 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -26,7 +26,7 @@ /* Load a dynamic module. Only log a level 0 error if we are not checking for the existence of a module (probling). */ -static NTSTATUS do_smb_load_module(const char *module_name, BOOL is_probe) +static NTSTATUS do_smb_load_module(const char *module_name, bool is_probe) { void *handle; init_module_function *init; -- cgit From 360673e80e8d46167afb6c393773895b369ff290 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 12 Jan 2008 00:15:46 -0800 Subject: CID 458. Don't leak dlopen handles on failing to load module. Jeremy. (This used to be commit 8809eaeb154ea12543455f589e31172dc905d83a) --- source3/lib/module.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index fa06d14b49..285bd9c4c0 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -57,6 +57,7 @@ static NTSTATUS do_smb_load_module(const char *module_name, bool is_probe) if (error) { DEBUG(0, ("Error trying to resolve symbol 'init_module' in %s: %s\n", module_name, error)); + sys_dlclose(handle); return NT_STATUS_UNSUCCESSFUL; } @@ -66,6 +67,7 @@ static NTSTATUS do_smb_load_module(const char *module_name, bool is_probe) if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("Module '%s' initialization failed: %s\n", module_name, get_friendly_nt_error_msg(status))); + sys_dlclose(handle); } return status; -- cgit From 3cf5395ad56bc32974de9f7284e9584825df2704 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 20 Jun 2008 14:30:02 +0200 Subject: Use "init_shared_module" instead of "init_module" for initializing .so's (This used to be commit 0c2fd687b25e32d446ef799927db6933bc61223d) --- source3/lib/module.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 285bd9c4c0..dee0623094 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -49,14 +49,14 @@ static NTSTATUS do_smb_load_module(const char *module_name, bool is_probe) return NT_STATUS_UNSUCCESSFUL; } - init = (init_module_function *)sys_dlsym(handle, "init_module"); + init = (init_module_function *)sys_dlsym(handle, "init_shared_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)); + DEBUG(0, ("Error trying to resolve symbol 'init_shared_module' " + "in %s: %s\n", module_name, error)); sys_dlclose(handle); return NT_STATUS_UNSUCCESSFUL; } -- cgit From 993d80fd22b7c0a6e2eec5ab899f51e077c529cb Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 23 Jun 2008 07:14:46 +0200 Subject: init_shared_module -> init_samba_module (This used to be commit 9b174871a87677f7dfbd897a80e526f203906bea) --- source3/lib/module.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index dee0623094..2e56e8e8b9 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -49,13 +49,13 @@ static NTSTATUS do_smb_load_module(const char *module_name, bool is_probe) return NT_STATUS_UNSUCCESSFUL; } - init = (init_module_function *)sys_dlsym(handle, "init_shared_module"); + init = (init_module_function *)sys_dlsym(handle, "init_samba_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_shared_module' " + DEBUG(0, ("Error trying to resolve symbol 'init_samba_module' " "in %s: %s\n", module_name, error)); sys_dlclose(handle); return NT_STATUS_UNSUCCESSFUL; -- cgit From 26c34534071db15d6b89c08bfe9207723b338aa5 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 15 Aug 2008 00:47:30 +0200 Subject: Use module_path() instead of lib_path() for loading shared modules. Michael (This used to be commit 22fb3ef1bb4abb33b49d275f9a5d85a1924c22ea) --- source3/lib/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/module.c') diff --git a/source3/lib/module.c b/source3/lib/module.c index 2e56e8e8b9..76983387ff 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -118,7 +118,7 @@ NTSTATUS smb_probe_module(const char *subsystem, const char *module) full_path = talloc_asprintf(ctx, "%s/%s.%s", - lib_path(subsystem), + modules_path(subsystem), module, shlib_ext()); if (!full_path) { -- cgit