]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
build: libdl usage
authorAlon Bar-Lev <alon.barlev@gmail.com>
Wed, 29 Feb 2012 20:12:02 +0000 (22:12 +0200)
committerDavid Sommerseth <davids@redhat.com>
Thu, 22 Mar 2012 21:17:26 +0000 (22:17 +0100)
1. properly detect.
2. Link only required components.
3. No way we don't have LoadLibrary on Windows.
4. ENABLE_PLUGIN should be controlled in autoconf.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Acked-by: Adriaan de Jong <dejong@fox-it.com>
Acked-by: David Sommerseth <davids@redhat.com>
Signed-off-by: David Sommerseth <davids@redhat.com>
configure.ac
src/openvpn/Makefile.am
src/openvpn/plugin.c
src/openvpn/plugin.h
src/openvpn/syshead.h

index ed984640d9c9e0b3437683bca957c9b20a98cc6a..a0dc4624ac23cea74fd56717105b1edbe0cad3e5 100644 (file)
@@ -395,7 +395,7 @@ AC_CHECK_HEADERS([ \
        stdio.h stdarg.h \
        time.h errno.h fcntl.h io.h direct.h \
        ctype.h sys/types.h sys/socket.h \
-       signal.h unistd.h \
+       signal.h unistd.h dlfcn.h \
        netinet/in.h netinet/in_systm.h \
        netinet/tcp.h arpa/inet.h netdb.h \
        windows.h winsock2.h ws2tcpip.h \
@@ -606,6 +606,13 @@ else
        AC_CHECK_FUNCS(SOCKET_OPT_FUNCS)
 fi
 
+AC_CHECK_LIB(
+       [dl],
+       [dlopen],
+       [DL_LIBS="-ldl"]
+)
+AC_SUBST([DL_LIBS])
+
 case "${with_mem_check}" in
        valgrind)
                AC_CHECK_HEADER(
@@ -657,38 +664,6 @@ case "${with_mem_check}" in
                ;;
 esac
 
-dnl
-dnl Check for dlopen -- first try libc then libdl.
-dnl
-if test "${WIN32}" != "yes" -a "${enable_plugins}" = "yes"; then
-       AC_CHECK_HEADER(
-               [dlfcn.h],
-               [AC_CHECK_FUNC(
-                       [dlopen],
-                       [AC_DEFINE(USE_LIBDL, 1, [Use libdl for dynamic library loading])],
-                       [AC_CHECK_LIB(
-                               [dl],
-                               [dlopen],
-                               [
-                                       LIBS="${LIBS} -ldl"
-                                       AC_DEFINE(USE_LIBDL, 1, [Use libdl for dynamic library loading])
-                               ],
-                               [AC_MSG_RESULT([libdl library not found.])]
-                       )],
-               )],
-       )
-       if test "${enable_eurephia}" = "yes"; then
-               AC_DEFINE([ENABLE_EUREPHIA], [1], [Enable support for the eurephia plug-in])
-       fi
-fi
-
-dnl
-dnl Check if LoadLibrary exists on Windows
-dnl
-if test "${WIN32}" = "yes"; then
-       AC_DEFINE(USE_LOAD_LIBRARY, 1, [Use LoadLibrary to load DLLs on Windows])
-fi
-
 dnl
 dnl check for LZO library
 dnl
@@ -898,6 +873,13 @@ test "${enable_strict_options}" = "yes" && AC_DEFINE([ENABLE_STRICT_OPTIONS_CHEC
 test "${enable_password_save}" = "yes" && AC_DEFINE([ENABLE_PASSWORD_SAVE], [1], [Allow --askpass and --auth-user-pass passwords to be read from a file])
 test "${enable_systemd}" = "yes" && AC_DEFINE([ENABLE_SYSTEMD], [1], [Enable systemd support])
 
+if test "${enable_plugins}" = "yes"; then
+       test "${WIN32}" != "yes" -a -z "${DL_LIBS}" && AC_MSG_ERROR([libdl is required for plugins])
+       OPTIONAL_DL_LIBS="${DL_LIBS}"
+       AC_DEFINE([ENABLE_PLUGIN], [1], [Enable systemd support])
+       test "${enable_eurephia}" = "yes" && AC_DEFINE([ENABLE_EUREPHIA], [1], [Enable support for the eurephia plug-in])
+fi
+
 if test "${enable_iproute2}" = "yes"; then
        test -z "${IPROUTE}" && AC_MSG_ERROR([ip utility is required but missing])
        AC_DEFINE([ENABLE_IPROUTE], [1], [enable iproute2 support])
@@ -933,6 +915,8 @@ AC_SUBST([TAP_WIN_COMPONENT_ID])
 AC_SUBST([TAP_WIN_MIN_MAJOR])
 AC_SUBST([TAP_WIN_MIN_MINOR])
 
+AC_SUBST([OPTIONAL_DL_LIBS])
+
 AM_CONDITIONAL([WIN32], [test "${WIN32}" = "yes"])
 
 AC_CONFIG_FILES([
index a509bba25dc403ae6d0c26592ed6bf7e8633799c..c7626c86d6e39230a10bd08c041d446c19880f50 100644 (file)
@@ -95,7 +95,9 @@ openvpn_SOURCES = \
        tun.c tun.h \
        win32.h win32.c \
        cryptoapi.h cryptoapi.c
+openvpn_LDADD = \
+       $(OPTIONAL_DL_LIBS)
 if WIN32
 openvpn_SOURCES += openvpn_win32_resources.rc
-openvpn_LDADD = -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lshell32
+openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lshell32
 endif
index 4cc9c369b07c28c8f20c41b2d055dccdf645570c..3f379ddc8b49432b75f52c1dc9172db042794338 100644 (file)
 
 #ifdef ENABLE_PLUGIN
 
+#ifdef HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
 #include "buffer.h"
 #include "error.h"
 #include "misc.h"
@@ -160,7 +164,7 @@ plugin_option_list_print (const struct plugin_option_list *list, int msglevel)
 }
 #endif
 
-#if defined(USE_LIBDL)
+#ifndef WIN32
 
 static void
 libdl_resolve_symbol (void *handle, void **dest, const char *symbol, const char *plugin_name, const unsigned int flags)
@@ -170,7 +174,7 @@ libdl_resolve_symbol (void *handle, void **dest, const char *symbol, const char
     msg (M_FATAL, "PLUGIN: could not find required symbol '%s' in plugin shared object %s: %s", symbol, plugin_name, dlerror());
 }
 
-#elif defined(USE_LOAD_LIBRARY)
+#else
 
 static void
 dll_resolve_symbol (HMODULE module, void **dest, const char *symbol, const char *plugin_name, const unsigned int flags)
@@ -191,7 +195,7 @@ plugin_init_item (struct plugin *p, const struct plugin_option *o)
   p->so_pathname = o->so_pathname;
   p->plugin_type_mask = plugin_supported_types ();
 
-#if defined(USE_LIBDL)
+#ifndef WIN32
 
   p->handle = NULL;
 #if defined(PLUGIN_LIBDIR)
@@ -220,7 +224,7 @@ plugin_init_item (struct plugin *p, const struct plugin_option *o)
 
 # define PLUGIN_SYM(var, name, flags) libdl_resolve_symbol (p->handle, (void*)&p->var, name, p->so_pathname, flags)
 
-#elif defined(USE_LOAD_LIBRARY)
+#else
 
   rel = !absolute_pathname (p->so_pathname);
   p->module = LoadLibraryW (wide_string (p->so_pathname, &gc));
@@ -427,10 +431,10 @@ plugin_close_item (struct plugin *p)
       if (p->plugin_handle)
        (*p->close)(p->plugin_handle);
 
-#if defined(USE_LIBDL)
+#ifndef WIN32
       if (dlclose (p->handle))
        msg (M_WARN, "PLUGIN_CLOSE: dlclose() failed on plugin: %s", p->so_pathname);
-#elif defined(USE_LOAD_LIBRARY)
+#elif defined(WIN32)
       if (!FreeLibrary (p->module))
        msg (M_WARN, "PLUGIN_CLOSE: FreeLibrary() failed on plugin: %s", p->so_pathname);
 #endif
index 6f75e27fdec0e42944cc843c10870e3d9341e34e..4c0a1fde8021c02836804382e8c3f88d3f5e9457 100644 (file)
@@ -59,9 +59,9 @@ struct plugin {
   unsigned int plugin_type_mask;
   int requested_initialization_point;
 
-#if defined(USE_LIBDL)
+#ifndef WIN32
   void *handle;
-#elif defined(USE_LOAD_LIBRARY)
+#else
   HMODULE module;
 #endif
 
index b30566031727aade0e173a66a0c19c962e8d4d77..1ad81d8975f9469b8a0949f7b9fa290f4dad7bdb 100644 (file)
 #include <grp.h>
 #endif
 
-#ifdef USE_LIBDL
-#include <dlfcn.h>
-#endif
-
 #ifdef HAVE_NETDB_H
 #include <netdb.h>
 #endif
@@ -506,13 +502,6 @@ socket_defined (const socket_descriptor_t sd)
 #define PORT_SHARE 0
 #endif
 
-/*
- * Do we have a plug-in capability?
- */
-#if defined(USE_LIBDL) || defined(USE_LOAD_LIBRARY)
-#define ENABLE_PLUGIN
-#endif
-
 /*
  * Enable deferred authentication?
  */