lib/util: Add smb_load_module that returns DEBUG(0) errors on failure
authorAndrew Bartlett <abartlet@samba.org>
Tue, 3 Apr 2012 03:22:41 +0000 (13:22 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 3 Apr 2012 04:25:12 +0000 (14:25 +1000)
These errors are very important when trying to work out why a module
does not load, and this rework allows them to be shown when loading
vfs modules.

Andrew Bartlett

lib/util/modules.c
lib/util/samba_modules.h

index 52a04be457468d2aa38f52b69e11d8b401b3f833..05d1dac50f9bd2294fdf5f60a2cc089813437adb 100644 (file)
@@ -159,13 +159,42 @@ init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem)
 /* 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 *subsystem,
+                                  const char *module_name, bool is_probe)
 {
        void *handle;
        init_module_fn init;
        NTSTATUS status;
 
-       init = load_module(module_name, is_probe, &handle);
+       char *full_path = NULL;
+       TALLOC_CTX *ctx = talloc_stackframe();
+
+       /* Check for absolute path */
+
+       /* if we make any 'samba multibyte string'
+          calls here, we break
+          for loading string modules */
+
+       DEBUG(5, ("%s module '%s'\n", is_probe ? "Probing" : "Loading", module_name));
+
+       if (subsystem && module_name[0] != '/') {
+               full_path = talloc_asprintf(ctx,
+                                           "%s/%s.%s",
+                                           modules_path(ctx, subsystem),
+                                           module_name,
+                                           shlib_ext());
+               if (!full_path) {
+                       TALLOC_FREE(ctx);
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               DEBUG(5, ("%s module '%s': Trying to load from %s\n",
+                         is_probe ? "Probing": "Loading", module_name, full_path));
+               init = load_module(full_path, is_probe, &handle);
+       } else {
+               init = load_module(module_name, is_probe, &handle);
+       }
+
        if (!init) {
                return NT_STATUS_UNSUCCESSFUL;
        }
@@ -175,7 +204,7 @@ static NTSTATUS do_smb_load_module(const char *module_name, bool is_probe)
        status = init();
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("Module '%s' initialization failed: %s\n",
-                           module_name, get_friendly_nt_error_msg(status)));
+                         module_name, get_friendly_nt_error_msg(status)));
                dlclose(handle);
        }
 
@@ -190,7 +219,7 @@ int smb_load_modules(const char **modules)
        int success = 0;
 
        for(i = 0; modules[i]; i++){
-               if(NT_STATUS_IS_OK(do_smb_load_module(modules[i], false))) {
+               if(NT_STATUS_IS_OK(do_smb_load_module(NULL, modules[i], false))) {
                        success++;
                }
        }
@@ -202,39 +231,10 @@ int smb_load_modules(const char **modules)
 
 NTSTATUS smb_probe_module(const char *subsystem, const char *module)
 {
-       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
-          for loading string modules */
-
-       DEBUG(5, ("Probing module '%s'\n", module));
-
-       if (module[0] == '/') {
-               status = do_smb_load_module(module, true);
-               TALLOC_FREE(ctx);
-               return status;
-       }
-
-       full_path = talloc_asprintf(ctx,
-                                   "%s/%s.%s",
-                                   modules_path(ctx, 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);
+       return do_smb_load_module(subsystem, module, true);
+}
 
-       TALLOC_FREE(ctx);
-       return status;
+NTSTATUS smb_load_module(const char *subsystem, const char *module)
+{
+       return do_smb_load_module(subsystem, module, false);
 }
index 5eb2a0dd1cfa3a305928ecbede402aff7927d01f..2f4081192952efa5abaf9b11dcdbdcca3a0fdb46 100644 (file)
@@ -55,5 +55,6 @@ init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem);
 
 int smb_load_modules(const char **modules);
 NTSTATUS smb_probe_module(const char *subsystem, const char *module);
+NTSTATUS smb_load_module(const char *subsystem, const char *module);
 
 #endif /* _SAMBA_MODULES_H */