]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix lua tests on macOS
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 12 Apr 2019 13:24:43 +0000 (15:24 +0200)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 12 Apr 2019 13:24:43 +0000 (15:24 +0200)
src/lib/server/dl.c
src/lib/server/dl.h
src/modules/rlm_lua/lua.c
src/modules/rlm_lua/lua.h
src/modules/rlm_lua/util.c

index 5e33f48e8a15bb4833d81a4875678ddcb486a7b8..eea9ace15d4f4d25e018750e099642234b12c4a3 100644 (file)
@@ -48,14 +48,6 @@ RCSID("$Id$")
 #  define RTLD_LOCAL (0)
 #endif
 
-#ifdef __APPLE__
-#  define DL_EXTENSION ".dylib"
-#elif defined (WIN32)
-#  define DL_EXTENSION ".dll"
-#else
-#  define DL_EXTENSION ".so"
-#endif
-
 #define DL_INIT_CHECK rad_assert(dl_loader)
 
 /** Symbol dependent initialisation callback
@@ -530,6 +522,28 @@ static void dl_instance_data_alloc(TALLOC_CTX *ctx, void **data, dl_t const *mod
        }
 }
 
+/** Return current library path
+ *
+ */
+char const *dl_search_path(void)
+{
+       char            *env;
+       char const      *search_path;
+
+       /*
+        *      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 = dl_loader->lib_dir;
+       }
+
+       return search_path;
+}
+
 /** Search for a module's shared object in various locations
  *
  * @param name of module to load.
@@ -539,8 +553,8 @@ void *dl_by_name(char const *name)
        int             flags = RTLD_NOW;
        void            *handle;
        char            buffer[2048];
-       char            *env;
        char const      *search_path;
+       char const      *env;
 
        DL_INIT_CHECK;
 
@@ -570,16 +584,7 @@ void *dl_by_name(char const *name)
         */
        flags |= RTLD_NOW;
 
-       /*
-        *      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 = dl_loader->lib_dir;
-       }
+       search_path = dl_search_path();
 
        /*
         *      Prefer loading our libraries by absolute path.
index f10748709c08d561cd88fab45b90e6104f751aea..1ec5d408be75e55164e188babd9101b6050658dd 100644 (file)
@@ -38,6 +38,14 @@ RCSIDH(dl_h, "$Id$")
 extern "C" {
 #endif
 
+#ifdef __APPLE__
+#  define DL_EXTENSION ".dylib"
+#elif defined (WIN32)
+#  define DL_EXTENSION ".dll"
+#else
+#  define DL_EXTENSION ".so"
+#endif
+
 /** Stop people using different module/library/server versions together
  *
  */
@@ -181,6 +189,8 @@ int                 dl_symbol_free_cb_register(unsigned int priority, char const *symbol,
 
 void                   dl_symbol_free_cb_unregister(char const *symbol, dl_free_t func);
 
+char const             *dl_search_path(void);
+
 void                   *dl_by_name(char const *name);
 
 dl_t const             *dl_module(CONF_SECTION *conf, dl_t const *parent, char const *name, dl_type_t type);
index 57524d061e50f2c8701d046522d822d58a2a3960..5c6dcffb2e8611260e6e7a6611d6b2316018eab0 100644 (file)
@@ -331,7 +331,7 @@ static int fr_lua_unmarshall(VALUE_PAIR **out,
  */
 static int _lua_pair_get(lua_State *L)
 {
-       REQUEST                 *request = fr_lua_aux_get_request();
+       REQUEST                 *request = fr_lua_util_get_request();
 
        fr_cursor_t             cursor;
        fr_dict_attr_t const    *da;
@@ -372,8 +372,8 @@ static int _lua_pair_get(lua_State *L)
  */
 static int _lua_pair_set(lua_State *L)
 {
-       rlm_lua_t const         *inst = fr_lua_aux_get_inst();
-       REQUEST                 *request = fr_lua_aux_get_request();
+       rlm_lua_t const         *inst = fr_lua_util_get_inst();
+       REQUEST                 *request = fr_lua_util_get_request();
        fr_cursor_t             cursor;
        fr_dict_attr_t const    *da;
        VALUE_PAIR              *vp = NULL, *new;
@@ -428,7 +428,7 @@ static int _lua_pair_set(lua_State *L)
 
 static int _lua_pair_iterator(lua_State *L)
 {
-       REQUEST                 *request = fr_lua_aux_get_request();
+       REQUEST                 *request = fr_lua_util_get_request();
 
        fr_cursor_t             *cursor;
        VALUE_PAIR              *vp;
@@ -457,7 +457,7 @@ static int _lua_pair_iterator(lua_State *L)
 
 static int _lua_pair_iterator_init(lua_State *L)
 {
-       REQUEST                 *request = fr_lua_aux_get_request();
+       REQUEST                 *request = fr_lua_util_get_request();
 
        fr_cursor_t             *cursor;
        fr_dict_attr_t const    *da;
@@ -486,7 +486,7 @@ static int _lua_pair_iterator_init(lua_State *L)
 
 static int _lua_list_iterator(lua_State *L)
 {
-       REQUEST                 *request = fr_lua_aux_get_request();
+       REQUEST                 *request = fr_lua_util_get_request();
 
        fr_cursor_t             *cursor;
        VALUE_PAIR              *vp;
@@ -517,7 +517,7 @@ static int _lua_list_iterator(lua_State *L)
  */
 static int _lua_list_iterator_init(lua_State *L)
 {
-       REQUEST                 *request = fr_lua_aux_get_request();
+       REQUEST                 *request = fr_lua_util_get_request();
        fr_cursor_t             *cursor;
 
        cursor = (fr_cursor_t*) lua_newuserdata(L, sizeof(fr_cursor_t));
@@ -539,7 +539,7 @@ static int _lua_list_iterator_init(lua_State *L)
  */
 static int _lua_pair_accessor_init(lua_State *L)
 {
-       REQUEST                 *request = fr_lua_aux_get_request();
+       REQUEST                 *request = fr_lua_util_get_request();
        char const              *attr;
        fr_dict_attr_t const    *da;
        fr_dict_attr_t          *up;
@@ -762,8 +762,8 @@ int fr_lua_run(rlm_lua_t const *inst, rlm_lua_thread_t *thread, REQUEST *request
        lua_State       *L = thread->interpreter;
        int             ret = RLM_MODULE_OK;
 
-       fr_lua_aux_set_inst(inst);
-       fr_lua_aux_set_request(request);
+       fr_lua_util_set_inst(inst);
+       fr_lua_util_set_request(request);
 
        RDEBUG2("Calling %s() in interpreter %p", funcname, L);
 
@@ -774,8 +774,8 @@ int fr_lua_run(rlm_lua_t const *inst, rlm_lua_thread_t *thread, REQUEST *request
         */
        if (fr_lua_get_field(L, request, funcname) < 0) {
 error:
-               fr_lua_aux_set_inst(NULL);
-               fr_lua_aux_set_request(NULL);
+               fr_lua_util_set_inst(NULL);
+               fr_lua_util_set_request(NULL);
 
                return RLM_MODULE_FAIL;
        }
@@ -819,8 +819,8 @@ error:
        }
 
 done:
-       fr_lua_aux_set_inst(NULL);
-       fr_lua_aux_set_request(NULL);
+       fr_lua_util_set_inst(NULL);
+       fr_lua_util_set_request(NULL);
 
        return ret;
 }
@@ -830,7 +830,7 @@ done:
  */
 static int _lua_rcode_table_newindex(UNUSED lua_State *L)
 {
-       REQUEST *request = fr_lua_aux_get_request();
+       REQUEST *request = fr_lua_util_get_request();
 
        RWDEBUG("You can't modify the table 'fr.rcode.{}' (read-only)");
 
@@ -902,7 +902,7 @@ int fr_lua_init(lua_State **out, rlm_lua_t const *instance)
        rlm_lua_t const         *inst = instance;
        lua_State               *L;
 
-       fr_lua_aux_set_inst(inst);
+       fr_lua_util_set_inst(inst);
 
        L = luaL_newstate();
        if (!L) {
@@ -920,7 +920,7 @@ int fr_lua_init(lua_State **out, rlm_lua_t const *instance)
 
        error:
                *out = NULL;
-               fr_lua_aux_set_inst(NULL);
+               fr_lua_util_set_inst(NULL);
                lua_close(L);
                return -1;
        }
@@ -934,17 +934,17 @@ int fr_lua_init(lua_State **out, rlm_lua_t const *instance)
        /*
         *      Setup "fr.{}"
         */
-       fr_lua_aux_fr_register(L);
+       fr_lua_util_fr_register(L);
 
        /*
         *      Setup "fr.log.{}"
         */
        if (inst->jit) {
                DEBUG4("Initialised new LuaJIT interpreter %p", L);
-               if (fr_lua_aux_jit_log_register(inst, L) < 0) goto error;
+               if (fr_lua_util_jit_log_register(inst, L) < 0) goto error;
        } else {
                DEBUG4("Initialised new Lua interpreter %p", L);
-               if (fr_lua_aux_log_register(inst, L) < 0) goto error;
+               if (fr_lua_util_log_register(inst, L) < 0) goto error;
        }
 
        /*
index 17cb39a8c4c4541a0e1f73877e9a92324363449f..1e7bd3e9a007ac6d6d12552d8f4c0460ce3d1cfe 100644 (file)
@@ -81,16 +81,16 @@ int         fr_lua_run(rlm_lua_t const *inst, rlm_lua_thread_t *thread, REQUEST *reques
 bool           fr_lua_isjit(lua_State *L);
 char const     *fr_lua_version(lua_State *L);
 
-/* aux.c */
-void           fr_lua_aux_jit_log_debug(char const *msg);
-void           fr_lua_aux_jit_log_info(char const *msg);
-void           fr_lua_aux_jit_log_warn(char const *msg);
-void           fr_lua_aux_jit_log_error(char const *msg);
+/* util.c */
+void           fr_lua_util_jit_log_debug(char const *msg);
+void           fr_lua_util_jit_log_info(char const *msg);
+void           fr_lua_util_jit_log_warn(char const *msg);
+void           fr_lua_util_jit_log_error(char const *msg);
 
-int            fr_lua_aux_jit_log_register(rlm_lua_t const *inst, lua_State *L);
-int            fr_lua_aux_log_register(rlm_lua_t const *inst, lua_State *L);
-void           fr_lua_aux_set_inst(rlm_lua_t const *inst);
-rlm_lua_t const        *fr_lua_aux_get_inst(void);
-void           fr_lua_aux_set_request(REQUEST *request);
-REQUEST                *fr_lua_aux_get_request(void);
-void           fr_lua_aux_fr_register(lua_State *L);
+int            fr_lua_util_jit_log_register(rlm_lua_t const *inst, lua_State *L);
+int            fr_lua_util_log_register(rlm_lua_t const *inst, lua_State *L);
+void           fr_lua_util_set_inst(rlm_lua_t const *inst);
+rlm_lua_t const        *fr_lua_util_get_inst(void);
+void           fr_lua_util_set_request(REQUEST *request);
+REQUEST                *fr_lua_util_get_request(void);
+void           fr_lua_util_fr_register(lua_State *L);
index e301b51b81e7175188f50ee32d1bfe7ac729161c..2878da976fad1131a3f8033144edfb00cffa1009 100644 (file)
@@ -38,7 +38,7 @@ RCSID("$Id$")
 static _Thread_local REQUEST *fr_lua_request;
 static _Thread_local rlm_lua_t const *fr_lua_inst;
 
-void fr_lua_aux_fr_register(lua_State *L)
+void fr_lua_util_fr_register(lua_State *L)
 {
        /* fr.{} */
        lua_newtable(L);
@@ -53,7 +53,7 @@ void fr_lua_aux_fr_register(lua_State *L)
  * @param L Lua interpreter.
  * @return 0 (no arguments)
  */
-static int _aux_log_debug(lua_State *L)
+static int _util_log_debug(lua_State *L)
 {
        rlm_lua_t const         *inst = fr_lua_inst;
        REQUEST                 *request = fr_lua_request;
@@ -77,7 +77,7 @@ static int _aux_log_debug(lua_State *L)
  * @param L Lua interpreter.
  * @return 0 (no arguments)
  */
-static int _aux_log_info(lua_State *L)
+static int _util_log_info(lua_State *L)
 {
        rlm_lua_t const         *inst = fr_lua_inst;
        REQUEST                 *request = fr_lua_request;
@@ -102,7 +102,7 @@ static int _aux_log_info(lua_State *L)
  * @param L Lua interpreter.
  * @return 0 (no arguments)
  */
-static int _aux_log_warn(lua_State *L)
+static int _util_log_warn(lua_State *L)
 {
        rlm_lua_t const         *inst = fr_lua_inst;
        REQUEST                 *request = fr_lua_request;
@@ -126,7 +126,7 @@ static int _aux_log_warn(lua_State *L)
  * @param L Lua interpreter.
  * @return 0 (no arguments)
  */
-static int _aux_log_error(lua_State *L)
+static int _util_log_error(lua_State *L)
 {
        rlm_lua_t const         *inst = fr_lua_inst;
        REQUEST                 *request = fr_lua_request;
@@ -143,9 +143,9 @@ static int _aux_log_error(lua_State *L)
        return 0;
 }
 
-static int _aux_log_newindex(UNUSED lua_State *L)
+static int _util_log_newindex(UNUSED lua_State *L)
 {
-       REQUEST *request = fr_lua_aux_get_request();
+       REQUEST *request = fr_lua_util_get_request();
 
        RWDEBUG("fr.log.$func() is read-only");
 
@@ -156,7 +156,7 @@ static int _aux_log_newindex(UNUSED lua_State *L)
  *
  * @param msg  to be printed.
  */
-void fr_lua_aux_jit_log_debug(char const *msg)
+void fr_lua_util_jit_log_debug(char const *msg)
 {
        rlm_lua_t const         *inst = fr_lua_inst;
        REQUEST                 *request = fr_lua_request;
@@ -168,7 +168,7 @@ void fr_lua_aux_jit_log_debug(char const *msg)
  *
  * @param msg  to be printed.
  */
-void fr_lua_aux_jit_log_info(char const *msg)
+void fr_lua_util_jit_log_info(char const *msg)
 {
        rlm_lua_t const         *inst = fr_lua_inst;
        REQUEST                 *request = fr_lua_request;
@@ -180,7 +180,7 @@ void fr_lua_aux_jit_log_info(char const *msg)
  *
  * @param msg  to be printed.
  */
-void fr_lua_aux_jit_log_warn(char const *msg)
+void fr_lua_util_jit_log_warn(char const *msg)
 {
        rlm_lua_t const         *inst = fr_lua_inst;
        REQUEST                 *request = fr_lua_request;
@@ -192,7 +192,7 @@ void fr_lua_aux_jit_log_warn(char const *msg)
  *
  * @param msg  to be printed.
  */
-void fr_lua_aux_jit_log_error(char const *msg)
+void fr_lua_util_jit_log_error(char const *msg)
 {
        rlm_lua_t const         *inst = fr_lua_inst;
        REQUEST                 *request = fr_lua_request;
@@ -209,29 +209,34 @@ void fr_lua_aux_jit_log_error(char const *msg)
  * @param L Lua interpreter.
  * @return 0 (no arguments).
  */
-int fr_lua_aux_jit_log_register(rlm_lua_t const *inst, lua_State *L)
+int fr_lua_util_jit_log_register(rlm_lua_t const *inst, lua_State *L)
 {
-       if (luaL_dostring(L,"\
+       char const *search_path;
+       char *lua_str;
+       int ret;
+
+       search_path = dl_search_path();
+       lua_str = talloc_asprintf(NULL, "\
                ffi = require(\"ffi\")\
                ffi.cdef [[\
-                       void fr_lua_aux_jit_log_debug(char const *msg);\
-                       void fr_lua_aux_jit_log_info(char const *msg);\
-                       void fr_lua_aux_jit_log_warn(char const *msg);\
-                       void fr_lua_aux_jit_log_error(char const *msg);\
+                       void fr_lua_util_jit_log_debug(char const *msg);\
+                       void fr_lua_util_jit_log_info(char const *msg);\
+                       void fr_lua_util_jit_log_warn(char const *msg);\
+                       void fr_lua_util_jit_log_error(char const *msg);\
                ]]\
-               fr_lua = ffi.load(\"freeradius-lua\")\
+               fr_lua = ffi.load(\"%s%clibfreeradius-lua%s\")\
                _fr_log = {}\
                _fr_log.debug = function(msg)\
-                       fr_lua.fr_lua_aux_jit_log_debug(msg)\
+                       fr_lua.fr_lua_util_jit_log_debug(msg)\
                end\
                _fr_log.info = function(msg)\
-                       fr_lua.fr_lua_aux_jit_log_info(msg)\
+                       fr_lua.fr_lua_util_jit_log_info(msg)\
                end\
                _fr_log.warn = function(msg)\
-                       fr_lua.fr_lua_aux_jit_log_warn(msg)\
+                       fr_lua.fr_lua_util_jit_log_warn(msg)\
                end\
                _fr_log.error = function(msg)\
-                       fr_lua.fr_lua_aux_jit_log_error(msg)\
+                       fr_lua.fr_lua_util_jit_log_error(msg)\
                end\
                function _ro_log(table) \
                        return setmetatable({}, { \
@@ -243,22 +248,26 @@ int fr_lua_aux_jit_log_register(rlm_lua_t const *inst, lua_State *L)
                        }); \
                end\
                fr.log = _ro_log(_fr_log)\
-               ") != 0) {
+               ", search_path, FR_DIR_SEP, DL_EXTENSION);
+       ret = luaL_dostring(L, lua_str);
+       talloc_free(lua_str);
+       if (ret != 0) {
                ERROR("Failed setting up FFI: %s",
                      lua_gettop(L) ? lua_tostring(L, -1) : "Unknown error");
+
                return -1;
        }
 
        return 0;
 }
 
-/** Register auxiliary functions in the lua environment
+/** Register utililiary functions in the lua environment
  *
  * @param inst Current instance of the fr_lua module.
  * @param L Lua interpreter.
  * @return 0 (no arguments).
  */
-int fr_lua_aux_log_register(UNUSED rlm_lua_t const *inst, lua_State *L)
+int fr_lua_util_log_register(UNUSED rlm_lua_t const *inst, lua_State *L)
 {
        /* fr.{} */
        lua_getglobal(L, "fr");
@@ -272,20 +281,20 @@ int fr_lua_aux_log_register(UNUSED rlm_lua_t const *inst, lua_State *L)
                        lua_pushvalue(L, -1);
                        lua_setfield(L, -2, "__index");
 
-                       lua_pushcfunction(L, _aux_log_newindex);
+                       lua_pushcfunction(L, _util_log_newindex);
                        lua_setfield(L, -2, "__newindex");
                }
 
-               lua_pushcfunction(L, _aux_log_debug);
+               lua_pushcfunction(L, _util_log_debug);
                lua_setfield(L, -2, "debug");
 
-               lua_pushcfunction(L, _aux_log_info);
+               lua_pushcfunction(L, _util_log_info);
                lua_setfield(L, -2, "info");
 
-               lua_pushcfunction(L, _aux_log_warn);
+               lua_pushcfunction(L, _util_log_warn);
                lua_setfield(L, -2, "warn");
 
-               lua_pushcfunction(L, _aux_log_error);
+               lua_pushcfunction(L, _util_log_error);
                lua_setfield(L, -2, "error");
        }
 
@@ -299,7 +308,7 @@ int fr_lua_aux_log_register(UNUSED rlm_lua_t const *inst, lua_State *L)
  *
  * @param[in] inst     all helper and C functions callable from Lua should use.
  */
-void fr_lua_aux_set_inst(rlm_lua_t const *inst)
+void fr_lua_util_set_inst(rlm_lua_t const *inst)
 {
        fr_lua_inst = inst;
 }
@@ -308,7 +317,7 @@ void fr_lua_aux_set_inst(rlm_lua_t const *inst)
  *
  * @return inst all helper and C functions callable from Lua should use.
  */
-rlm_lua_t const *fr_lua_aux_get_inst(void)
+rlm_lua_t const *fr_lua_util_get_inst(void)
 {
        return fr_lua_inst;
 }
@@ -317,7 +326,7 @@ rlm_lua_t const *fr_lua_aux_get_inst(void)
  *
  * @param[in] request  all helper and C functions callable from Lua should use.
  */
-void fr_lua_aux_set_request(REQUEST *request)
+void fr_lua_util_set_request(REQUEST *request)
 {
        fr_lua_request = request;
 }
@@ -326,7 +335,7 @@ void fr_lua_aux_set_request(REQUEST *request)
  *
  * @return request all helper and C functions callable from Lua should use.
  */
-REQUEST *fr_lua_aux_get_request(void)
+REQUEST *fr_lua_util_get_request(void)
 {
        return fr_lua_request;
 }