]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix dlopen wrapper so it produces proper error messages
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 30 Jun 2015 16:26:49 +0000 (12:26 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 30 Jun 2015 16:41:03 +0000 (12:41 -0400)
src/main/modules.c
src/modules/rlm_eap/eap.c
src/modules/rlm_sql/rlm_sql.c

index 355adf6b72faeede007e2879a05b6a7b45bc281b..dae684cf3bc4ccd460d45eb5dbce6ecca9b92650 100644 (file)
@@ -138,10 +138,10 @@ static int check_module_magic(CONF_SECTION *cs, module_t const *module)
 
 lt_dlhandle lt_dlopenext(char const *name)
 {
-       int flags = RTLD_NOW;
-       void *handle;
-       char buffer[2048];
-       char *env;
+       int     flags = RTLD_NOW;
+       void    *handle;
+       char    buffer[2048];
+       char    *env;
 
 #ifdef RTLD_GLOBAL
        if (strcmp(name, "rlm_perl") == 0) {
@@ -159,31 +159,42 @@ lt_dlhandle lt_dlopenext(char const *name)
        /*
         *      Prefer loading our libraries by absolute path.
         */
-       snprintf(buffer, sizeof(buffer), "%s/%s%s", radlib_dir, name, LT_SHREXT);
+       if (radlib_dir) {
+               char *error;
 
-       DEBUG4("Loading library using absolute path \"%s\"", name);
+               snprintf(buffer, sizeof(buffer), "%s/%s%s", radlib_dir, name, LT_SHREXT);
 
-       handle = dlopen(buffer, flags);
-       if (handle) return handle;
+               DEBUG4("Loading library using absolute path \"%s\"", buffer);
 
-       /*
-        *      Because dlopen produces really shitty and inaccurate error messages
-        */
-       if (access(name, R_OK) < 0) switch (errno) {
-       case EACCES:
-               WARN("Library file found, but we don't have permission to read it");
-               break;
-
-       case ENOENT:
-               DEBUG4("Library file not found");
-               break;
-
-       default:
-               DEBUG4("Issue accessing library file: %s", fr_syserror(errno));
-               break;
+               handle = dlopen(buffer, flags);
+               if (handle) return handle;
+               error = dlerror();
+
+               fr_strerror_printf("%s", error);
+               DEBUG4("Failed with error: %s", error);
+
+               /*
+                *      Because dlopen (on OSX at least) produces really
+                *      shitty and inaccurate error messages
+                */
+               if (access(buffer, R_OK) < 0) {
+                       switch (errno) {
+                       case EACCES:
+                               WARN("Library file found, but we don't have permission to read it");
+                               break;
+
+                       case ENOENT:
+                               DEBUG4("Library file not found");
+                               break;
+
+                       default:
+                               DEBUG4("Issue accessing library file: %s", fr_syserror(errno));
+                               break;
+                       }
+               }
        }
 
-       DEBUG4("Falling back to linker search path(s)");
+       DEBUG4("Loading library using linker search path(s)");
        if (DEBUG_ENABLED4) {
 #ifdef __APPLE__
                env = getenv("LD_LIBRARY_PATH");
@@ -217,7 +228,21 @@ lt_dlhandle lt_dlopenext(char const *name)
         */
        strlcat(buffer, LT_SHREXT, sizeof(buffer));
 
-       return dlopen(buffer, flags);
+       handle = dlopen(buffer, flags);
+       if (!handle) {
+               char *error = dlerror();
+
+               DEBUG4("Failed with error: %s", error);
+               /*
+                *      Don't overwrite the previous message
+                *      It's likely to contain a better error.
+                */
+               if (!radlib_dir) {
+                       fr_strerror_printf("%s", dlerror());
+               }
+               return NULL;
+       }
+       return handle;
 }
 
 void *lt_dlsym(lt_dlhandle handle, char const *symbol)
@@ -462,7 +487,7 @@ static module_entry_t *module_dlopen(CONF_SECTION *cs, char const *module_name)
         */
        handle = lt_dlopenext(module_name);
        if (!handle) {
-               cf_log_err_cs(cs, "Failed to link to module '%s': %s", module_name, dlerror());
+               cf_log_err_cs(cs, "Failed to link to module '%s': %s", module_name, fr_strerror());
                return NULL;
        }
 
index ff46b7c04cbb46b251260d4470ff44310e379cbb..1d6ee2e4e8ed2ba3ae67b54e3711bea26d0d3943 100644 (file)
@@ -132,7 +132,7 @@ int eap_module_instantiate(rlm_eap_t *inst, eap_module_t **m_inst, eap_type_t nu
         */
        method->handle = lt_dlopenext(mod_name);
        if (!method->handle) {
-               ERROR("rlm_eap (%s): Failed to link %s: %s", inst->xlat_name, mod_name, lt_dlerror());
+               ERROR("rlm_eap (%s): Failed to link %s: %s", inst->xlat_name, mod_name, fr_strerror());
 
                return -1;
        }
index 8beedd79470f1217d74adb9c49b3033e2e593ba4..56df54be656b4767ab8a2a0b4cbb0fc320ea1b8f 100644 (file)
@@ -827,7 +827,7 @@ static int mod_bootstrap(CONF_SECTION *conf, void *instance)
         */
        inst->handle = lt_dlopenext(inst->config->sql_driver_name);
        if (!inst->handle) {
-               ERROR("Could not link driver %s: %s", inst->config->sql_driver_name, dlerror());
+               ERROR("Could not link driver %s: %s", inst->config->sql_driver_name, fr_strerror());
                ERROR("Make sure it (and all its dependent libraries!) are in the search path of your system's ld");
                return -1;
        }