2 Unix SMB/CIFS implementation.
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.
25 int smb_load_module(const char *module_name
)
28 init_module_function
*init
;
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
);
39 DEBUG(0, ("Error loading module '%s': %s\n", module_name
, sys_dlerror()));
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();
49 DEBUG(0, ("Error trying to resolve symbol 'init_module' in %s: %s\n", module_name
, error
));
55 DEBUG(2, ("Module '%s' loaded\n", module_name
));
60 /* Load all modules in list and return number of
61 * modules that has been successfully loaded */
62 int smb_load_modules(const char **modules
)
67 for(i
= 0; modules
[i
]; i
++){
68 if(smb_load_module(modules
[i
])) {
73 DEBUG(2, ("%d modules successfully loaded\n", success
));
78 int smb_probe_module(const char *subsystem
, const char *module
)
82 /* Check for absolute path */
83 if(strchr_m(module
, '/'))return smb_load_module(module
);
85 pstrcpy(full_path
, lib_path(subsystem
));
86 pstrcat(full_path
, "/");
87 pstrcat(full_path
, module
);
88 pstrcat(full_path
, ".");
89 pstrcat(full_path
, shlib_ext());
91 DEBUG(5, ("Probing module %s: Trying to load from %s\n", module
, full_path
));
93 return smb_load_module(full_path
);
96 #else /* HAVE_DLOPEN */
98 int smb_load_module(const char *module_name
)
100 DEBUG(0,("This samba executable has not been built with plugin support"));
104 int smb_load_modules(const char **modules
)
106 DEBUG(0,("This samba executable has not been built with plugin support"));
110 int smb_probe_module(const char *subsystem
, const char *module
)
112 DEBUG(0,("This samba executable has not been built with plugin support, not probing"));
116 #endif /* HAVE_DLOPEN */
118 void init_modules(void)
120 /* FIXME: This can cause undefined symbol errors :
121 * smb_register_vfs() isn't available in nmbd, for example */
122 if(lp_preload_modules())
123 smb_load_modules(lp_preload_modules());
127 /*************************************************************************
128 * This functions /path/to/foobar.so -> foobar
129 ************************************************************************/
130 void module_path_get_name(const char *path
, pstring name
)
134 /* First, make the path relative */
135 s
= strrchr(path
, '/');
136 if(s
) pstrcpy(name
, s
+1);
137 else pstrcpy(name
, path
);
139 if (dyn_SHLIBEXT
&& *dyn_SHLIBEXT
&& strlen(dyn_SHLIBEXT
) < strlen(name
)) {
140 int n
= strlen(name
) - strlen(dyn_SHLIBEXT
);
142 /* Remove extension if necessary */
143 if (name
[n
-1] == '.' && !strcmp(name
+n
, dyn_SHLIBEXT
)) {