Janitorial duties to make autogen.sh portable.
[Samba/gebeck_regimport.git] / source3 / lib / module.c
blob2498f6de2c54cbc8681d37a9d0c6ffe72b4ba7bf
1 /*
2 Unix SMB/CIFS implementation.
3 module loading system
5 Copyright (C) Jelmer Vernooij 2002
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
24 #ifdef HAVE_DLOPEN
25 NTSTATUS smb_load_module(const char *module_name)
27 void *handle;
28 init_module_function *init;
29 NTSTATUS nt_status;
30 const char *error;
32 /* Always try to use LAZY symbol resolving; if the plugin has
33 * backwards compatibility, there might be symbols in the
34 * plugin referencing to old (removed) functions
36 handle = sys_dlopen(module_name, RTLD_LAZY);
38 if(!handle) {
39 DEBUG(0, ("Error loading module '%s': %s\n", module_name, sys_dlerror()));
40 return NT_STATUS_UNSUCCESSFUL;
43 init = sys_dlsym(handle, "init_module");
45 /* we must check sys_dlerror() to determine if it worked, because
46 sys_dlsym() can validly return NULL */
47 error = sys_dlerror();
48 if (error) {
49 DEBUG(0, ("Error trying to resolve symbol 'init_module' in %s: %s\n", module_name, error));
50 return NT_STATUS_UNSUCCESSFUL;
53 nt_status = init();
55 DEBUG(2, ("Module '%s' loaded\n", module_name));
57 return nt_status;
60 #else /* HAVE_DLOPEN */
62 NTSTATUS smb_load_module(const char *module_name)
64 DEBUG(0,("This samba executable has not been build with plugin support"));
65 return NT_STATUS_NOT_SUPPORTED;
68 #endif /* HAVE_DLOPEN */