| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 | module loading system
|
|---|
| 4 |
|
|---|
| 5 | Copyright (C) Jelmer Vernooij 2002-2003
|
|---|
| 6 | Copyright (C) Stefan (metze) Metzmacher 2003
|
|---|
| 7 |
|
|---|
| 8 | This program is free software; you can redistribute it and/or modify
|
|---|
| 9 | it under the terms of the GNU General Public License as published by
|
|---|
| 10 | the Free Software Foundation; either version 3 of the License, or
|
|---|
| 11 | (at your option) any later version.
|
|---|
| 12 |
|
|---|
| 13 | This program is distributed in the hope that it will be useful,
|
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 16 | GNU General Public License for more details.
|
|---|
| 17 |
|
|---|
| 18 | You should have received a copy of the GNU General Public License
|
|---|
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 | #include "includes.h"
|
|---|
| 23 |
|
|---|
| 24 | #ifdef HAVE_DLOPEN
|
|---|
| 25 |
|
|---|
| 26 | /* Load a dynamic module. Only log a level 0 error if we are not checking
|
|---|
| 27 | for the existence of a module (probling). */
|
|---|
| 28 |
|
|---|
| 29 | static NTSTATUS do_smb_load_module(const char *module_name, bool is_probe)
|
|---|
| 30 | {
|
|---|
| 31 | void *handle;
|
|---|
| 32 | init_module_function *init;
|
|---|
| 33 | NTSTATUS status;
|
|---|
| 34 | const char *error;
|
|---|
| 35 |
|
|---|
| 36 | /* Always try to use LAZY symbol resolving; if the plugin has
|
|---|
| 37 | * backwards compatibility, there might be symbols in the
|
|---|
| 38 | * plugin referencing to old (removed) functions
|
|---|
| 39 | */
|
|---|
| 40 | handle = dlopen(module_name, RTLD_LAZY);
|
|---|
| 41 |
|
|---|
| 42 | /* This call should reset any possible non-fatal errors that
|
|---|
| 43 | occured since last call to dl* functions */
|
|---|
| 44 | error = dlerror();
|
|---|
| 45 |
|
|---|
| 46 | if(!handle) {
|
|---|
| 47 | int level = is_probe ? 3 : 0;
|
|---|
| 48 | DEBUG(level, ("Error loading module '%s': %s\n", module_name, error ? error : ""));
|
|---|
| 49 | return NT_STATUS_UNSUCCESSFUL;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | init = (init_module_function *)dlsym(handle, "init_samba_module");
|
|---|
| 53 |
|
|---|
| 54 | /* we must check dlerror() to determine if it worked, because
|
|---|
| 55 | dlsym() can validly return NULL */
|
|---|
| 56 | error = dlerror();
|
|---|
| 57 | if (error) {
|
|---|
| 58 | DEBUG(0, ("Error trying to resolve symbol 'init_samba_module' "
|
|---|
| 59 | "in %s: %s\n", module_name, error));
|
|---|
| 60 | dlclose(handle);
|
|---|
| 61 | return NT_STATUS_UNSUCCESSFUL;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | DEBUG(2, ("Module '%s' loaded\n", module_name));
|
|---|
| 65 |
|
|---|
| 66 | status = init();
|
|---|
| 67 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 68 | DEBUG(0, ("Module '%s' initialization failed: %s\n",
|
|---|
| 69 | module_name, get_friendly_nt_error_msg(status)));
|
|---|
| 70 | dlclose(handle);
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | return status;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | NTSTATUS smb_load_module(const char *module_name)
|
|---|
| 77 | {
|
|---|
| 78 | return do_smb_load_module(module_name, False);
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | /* Load all modules in list and return number of
|
|---|
| 82 | * modules that has been successfully loaded */
|
|---|
| 83 | int smb_load_modules(const char **modules)
|
|---|
| 84 | {
|
|---|
| 85 | int i;
|
|---|
|
|---|