]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix tests on macs running in rootless mode
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 7 Oct 2015 02:34:12 +0000 (22:34 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 7 Oct 2015 23:20:12 +0000 (19:20 -0400)
Die Apple die...

Make.inc.in
Makefile
src/main/modules.c
src/main/radiusd.c
src/main/radwho.c
src/main/unittest.c

index a06a044bc28099958193cbb12328bc75cfd883f7..a69a2538d2815d2152c35d79372befb0040726e3 100644 (file)
@@ -163,7 +163,7 @@ ANALYZE.c       := @clang_path@
 #
 ifeq "$(USE_SHARED_LIBS)" "yes"
        TESTBINDIR = ./$(BUILD_DIR)/bin/local
-       TESTBIN    = $(JLIBTOOL) --quiet --mode=execute $(TESTBINDIR)
+       TESTBIN    =  FR_LIBRARY_PATH=./build/lib/.libs $(JLIBTOOL) --quiet --mode=execute $(TESTBINDIR)
 else
        TESTBINDIR = ./$(BUILD_DIR)/bin
        TESTBIN    = ./$(BUILD_DIR)/bin
index bc0150f6e0b26f3797412c21e220537d7101220a..219e55d4335a6baebc2c4817b49cc625f3064e9b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -42,7 +42,7 @@ raddb/test.conf:
 $(BUILD_DIR)/tests/radiusd-c: raddb/test.conf ${BUILD_DIR}/bin/radiusd | build.raddb
        @$(MAKE) -C raddb/certs
        @printf "radiusd -C... "
-       @if ! ./build/make/jlibtool --mode=execute ./build/bin/radiusd -XCMd ./raddb -D ./share -n test > $(BUILD_DIR)/tests/radiusd.config.log; then \
+       @if ! FR_LIBRARY_PATH=./build/lib/local/.libs/ ./build/make/jlibtool --mode=execute ./build/bin/radiusd -XCMd ./raddb -D ./share -n test > $(BUILD_DIR)/tests/radiusd.config.log; then \
                rm -f raddb/test.conf; \
                cat $(BUILD_DIR)/tests/radiusd.config.log; \
                echo "fail"; \
@@ -59,7 +59,7 @@ test: ${BUILD_DIR}/bin/radiusd ${BUILD_DIR}/bin/radclient tests.unit tests.xlat
 #  the above tests
 ifneq "$(findstring travis,${prefix})" ""
 travis-test: raddb/test.conf test
-       @./build/make/jlibtool --mode=execute ./build/bin/radiusd -xxxv -n test
+       @FR_LIBRARY_PATH=./build/lib/local/.libs/ ./build/make/jlibtool --mode=execute ./build/bin/radiusd -xxxv -n test
        @rm -f raddb/test.conf
        @$(MAKE) install
        @perl -p -i -e 's/allow_vulnerable_openssl = no/allow_vulnerable_openssl = yes/' ${raddbdir}/radiusd.conf
index 6053e0e9e80298fc5622bd61794b86e98ed12810..b21ee8943e66cc7ea0a9f0747782244a064dd293 100644 (file)
@@ -30,6 +30,11 @@ RCSID("$Id$")
 #include <freeradius-devel/parser.h>
 #include <freeradius-devel/rad_assert.h>
 
+/** Path to search for modules in
+ *
+ */
+char const *radlib_dir = NULL;
+
 typedef struct indexed_modcallable {
        rlm_components_t        comp;
        int                     idx;
@@ -152,11 +157,11 @@ 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;
+       char const      *search_path;
 #ifdef RTLD_GLOBAL
        if (strcmp(name, "rlm_perl") == 0) {
                flags |= RTLD_GLOBAL;
@@ -170,42 +175,53 @@ lt_dlhandle lt_dlopenext(char const *name)
         */
        flags |= RTLD_NOW;
 #endif
+
+       /*
+        *      Apple removed support for DYLD_LIBRARY_PATH in rootless mode.
+        */
+       env = getenv("FR_LIBRARY_PATH");
+       if (env) {
+               DEBUG3("Ignoring libdir as FR_LIBRARY_PATH set.  Module search path will be: %s", env);
+               search_path = env;
+       } else {
+               search_path = radlib_dir;
+       }
+
        /*
         *      Prefer loading our libraries by absolute path.
         */
-       if (radlib_dir) {
+       if (search_path) {
                char *error;
+               char *ctx, *paths, *path;
+               char *p;
 
-               snprintf(buffer, sizeof(buffer), "%s/%s%s", radlib_dir, name, LT_SHREXT);
+               fr_strerror();
 
-               DEBUG4("Loading library using absolute path \"%s\"", buffer);
+               ctx = paths = talloc_strdup(NULL, search_path);
+               while ((path = strsep(&paths, ":")) != NULL) {
+                       /*
+                        *      Trim the trailing slash
+                        */
+                       p = strrchr(path, '/');
+                       if (p && ((p[1] == '\0') || (p[1] == ':'))) *p = '\0';
 
-               handle = dlopen(buffer, flags);
-               if (handle) return handle;
-               error = dlerror();
+                       path = talloc_asprintf(ctx, "%s/%s%s", path, name, LT_SHREXT);
 
-               fr_strerror_printf("%s", error);
-               DEBUG4("Failed with error: %s", error);
+                       DEBUG4("Loading %s with path: %s", name, path);
 
-               /*
-                *      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;
+                       handle = dlopen(path, flags);
+                       if (handle) {
+                               talloc_free(ctx);
+                               return handle;
                        }
+                       error = dlerror();
+
+                       fr_strerror_printf("%s%s\n", fr_strerror(), error);
+                       DEBUG4("Loading %s failed: %s - %s", name, error,
+                              (access(buffer, R_OK) < 0) ? fr_syserror(errno) : "No access errors");
+                       talloc_free(path);
                }
+               talloc_free(ctx);
        }
 
        DEBUG4("Loading library using linker search path(s)");
index 99ee4b5d2cd3af39a2604bec99febdbd84b2611e..fc29e28f3534c41133f1bb4a9aad619f931fc5dc 100644 (file)
@@ -57,7 +57,7 @@ RCSID("$Id$")
 char const     *progname = NULL;
 char const     *radacct_dir = NULL;
 char const     *radlog_dir = NULL;
-char const     *radlib_dir = NULL;
+
 bool           log_stripped_names;
 
 char const *radiusd_version = "FreeRADIUS Version " RADIUSD_VERSION_STRING
index 29c1a34d797af2aec7b1fdb32d0cf724115caa89..3cfff2902b6b8d55073d1d71ce7a2ed8a3266c0e 100644 (file)
@@ -53,7 +53,6 @@ static char const *raddb_dir = RADDBDIR;
 static char const *dict_dir = DICTDIR;
 
 char const *radacct_dir = NULL;
-char const *radlib_dir = NULL;
 
 bool log_stripped_names;
 
index 9952a8ad699c49ec4a2aa45d74745818e51077dd..e0a301b71f6f511c5d7f96be0affa5d73c07b84a 100644 (file)
@@ -40,7 +40,6 @@ RCSID("$Id$")
 char const *progname = NULL;
 char const *radacct_dir = NULL;
 char const *radlog_dir = NULL;
-char const *radlib_dir = NULL;
 bool log_stripped_names = false;
 
 static bool memory_report = false;