RFC: Experimental patch against libESMTP 0.8.8 to eliminate libltdl



(Oops finger trouble - forgot to add CCs to the first copy of this)

Hi all,

I pretty much get the impression that libltdl causes more problems for some
people than it solves.  I've done a quick patch against libESMTP 0.8.8 which
replaces the lt_dlxxx functions with the more conventional dlxxx ones supplied
by glibc and some other platforms.  It has had next to no testing yet but any
feedback on it is appreciated.

The objective of this patch is to use dlopen() etc directly on systems that
provide it and only to fall back to libltdl for others.  I'd like to eliminate
libltdl from the tarball (the patch does this) as it saves bloat (about 70K
off the bz2 and faster configure!).

Key things I'd like to know.

Dlopen() related:
Is using dlopen() and friends good enough for most people?
What libraries might dlopen() ... live in if not -libdl.so?
What header files might be used if not <dlfcn.h>?
Is ".so" always the correct extension for these?

Shm_XXX related
Do I need to implement the shm_xxx() stuff or is dlxxx() sufficiently portable?
... or would someone like to supply me with a man page for these functions or
contribute some code?
What is the correct extension for the shared object/libs?

LTDL related
Does it cause problems if libltdl is not distributed in the tarball? (instead
relying either on the ltdl distributed with the system or forcing the user to
download it seperately)

Should ltdl be supported in any form at all?

If I can resolve these issues in the next few weeks or so, they will be
incorporated into the next libESMTP release.

Cheers,
Brian Stafford

diff -rub libesmtp-0.8.8/Makefile.am libesmtp/Makefile.am
--- libesmtp-0.8.8/Makefile.am	Fri Oct 19 09:06:34 2001
+++ libesmtp/Makefile.am	Wed Dec 12 14:30:15 2001
@@ -1,7 +1,7 @@
 ## Process this file with automake to produce Makefile.in
 AUTOMAKE_OPTIONS = gnu dist-bzip2
 
-INCLUDES = -I$(srcdir) $(VERSION_FLAGS) $(INCLTDL)
+INCLUDES = -I$(srcdir) $(VERSION_FLAGS)
 SUBDIRS = @subdirs@ @SASL_PLUGINS@
 CFLAGS = @CFLAGS@ @EXTRA_CFLAGS@
 
@@ -18,7 +18,7 @@
 		      getaddrinfo.h gethostbyname.h
 libesmtp_la_LIBADD = @LTLIBOBJS@
 
-libesmtp_la_LDFLAGS = $(LIBLTDL) -export-dynamic \
+libesmtp_la_LDFLAGS = -export-dynamic \
 		      -version-info $(LIBESMTP_VERSION)
 
 include_HEADERS = libesmtp.h auth-client.h auth-plugin.h 
diff -rub libesmtp-0.8.8/auth-client.c libesmtp/auth-client.c
--- libesmtp-0.8.8/auth-client.c	Wed Oct 17 08:16:54 2001
+++ libesmtp/auth-client.c	Wed Dec 12 15:14:47 2001
@@ -29,7 +29,24 @@
 #ifdef USE_PTHREADS
 #include <pthread.h>
 #endif
-#include <ltdl.h>
+
+#if HAVE_DLSYM
+# include <dlfcn.h>
+# ifndef DLEXT
+#  define DLEXT ".so"
+# endif
+typedef void *dlhandle_t;
+#elif WITH_LTDL
+# include <ltdl.h>
+# ifndef DLEXT
+#  define DLEXT ""
+# endif
+typedef lt_dlhandle dlhandle_t;
+# define dlopen(n,f)	lt_dlopenext((n))
+# define dlsym(h,s)	lt_dlsym((h),(s))
+# define dlclose(h)	lt_dlclose((h))
+#endif
+
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
@@ -45,7 +62,7 @@
 struct auth_plugin
   {
     struct auth_plugin *next;
-    lt_dlhandle module;
+    dlhandle_t module;
     const struct auth_client_plugin *info;
   };
 static struct auth_plugin *client_plugins, *end_client_plugins;
@@ -64,25 +81,33 @@
 #define mechanism_disabled(p,a,f)		\
 	  (((p)->flags & AUTH_PLUGIN_##f) && !((a)->flags & AUTH_PLUGIN_##f))
 
+#if !WITH_LTDL && defined AUTHPLUGINDIR
+# define PLUGIN_DIR AUTHPLUGINDIR "/"
+#else
+# define PLUGIN_DIR
+#endif
+
 static const char *
 plugin_name (char *buf, size_t buflen, const char *str)
 {
   char *p;
-  static const char prefix[] = "sasl-";
+  static const char prefix[] = PLUGIN_DIR "sasl-";
 
-  assert (buf != NULL && buflen > sizeof prefix && str != NULL);
+  assert (buf != NULL
+          && str != NULL
+          && buflen > sizeof prefix + strlen (str) + sizeof DLEXT);
 
   strcpy (buf, prefix);
   p = buf + sizeof prefix - 1;
   buflen -= sizeof prefix;
   while (*str != '\0' && buflen-- > 0)
     *p++ = tolower (*str++);
-  *p = '\0';
+  strcpy (p, DLEXT);
   return buf;
 }
 
 static int
-append_plugin (lt_dlhandle module, const struct auth_client_plugin *info)
+append_plugin (dlhandle_t module, const struct auth_client_plugin *info)
 {
   struct auth_plugin *auth_plugin;
 
@@ -108,7 +133,7 @@
 static const struct auth_client_plugin *
 load_client_plugin (auth_context_t context, const char *name)
 {
-  lt_dlhandle module;
+  dlhandle_t module;
   char buf[32];
   const char *plugin;
   const struct auth_client_plugin *info;
@@ -117,14 +142,14 @@
 
   /* Try searching for a plugin. */
   plugin = plugin_name (buf, sizeof buf, name);
-  module = lt_dlopenext (plugin);
+  module = dlopen (plugin, RTLD_NOW);
   if (module == NULL)
     return NULL;
 
-  info = lt_dlsym (module, "sasl_client");
+  info = dlsym (module, "sasl_client");
   if (info == NULL || info->response == NULL)
     {
-      lt_dlclose (module);
+      dlclose (module);
       return NULL;
     }
 
@@ -135,7 +160,7 @@
       || mechanism_disabled (info, context, ANONYMOUS)
       || mechanism_disabled (info, context, PLAIN))
     {
-      lt_dlclose (module);
+      dlclose (module);
       return NULL;
     }
 
@@ -143,7 +168,7 @@
    */
   if (!append_plugin (module, info))
     {
-      lt_dlclose (module);
+      dlclose (module);
       return NULL;
     }
 
@@ -153,6 +178,7 @@
 void
 auth_client_init (void)
 {
+#if WITH_LTDL
 #ifdef USE_PTHREADS
   pthread_mutex_lock (&plugin_mutex);
 #endif
@@ -164,6 +190,7 @@
 #ifdef USE_PTHREADS
   pthread_mutex_unlock (&plugin_mutex);
 #endif
+#endif
 }
 
 void
@@ -171,7 +198,7 @@
 {
   struct auth_plugin *plugin, *next;
 
-  /* Scan the auth_plugin array and lt_dlclose() the modules */
+  /* Scan the auth_plugin array and dlclose() the modules */
 #ifdef USE_PTHREADS
   pthread_mutex_lock (&plugin_mutex);
 #endif
@@ -179,11 +206,13 @@
     {
       next = plugin->next;
       if (plugin->module != NULL)
-	lt_dlclose (plugin->module);
+	dlclose (plugin->module);
       free (plugin);
     }
   client_plugins = end_client_plugins = NULL;
+#if WITH_LTDL
   lt_dlexit ();
+#endif
 #ifdef USE_PTHREADS
   pthread_mutex_unlock (&plugin_mutex);
 #endif
diff -rub libesmtp-0.8.8/configure.in libesmtp/configure.in
--- libesmtp-0.8.8/configure.in	Thu Nov 29 12:39:33 2001
+++ libesmtp/configure.in	Wed Dec 12 15:01:52 2001
@@ -42,6 +42,7 @@
 
 LIBESMTP_VERSION="$LIB_CURRENT:$LIB_REVISION:$LIB_AGE"
 AC_SUBST(LIBESMTP_VERSION)
+subdirs=
 
 dnl #########################################################################
 dnl Miscellaneous stuff
@@ -102,6 +103,7 @@
 AC_PROG_INSTALL
 AC_PROG_LN_S
 AC_PROG_MAKE_SET
+AM_PROG_LIBTOOL
 
 dnl #########################################################################
 dnl Checks for libraries and options.
@@ -111,16 +113,34 @@
               ,
               enable_all=no)
 
-AC_ARG_ENABLE([ltdl-install],ACX_HELP_STRING([--enable-ltdl-install],[install libltdl]))
-AC_LIBLTDL_INSTALLABLE
-dnl When the installable (or installed) libltdl is used, programs linked
-dnl with -lesmtp also need -lltdl
-LIBADD_LTDL=-lltdl
-
-AC_LTDL_DLLIB
-AC_LIBTOOL_DLOPEN
-AM_PROG_LIBTOOL
-AC_CONFIG_SUBDIRS(libltdl)
+AC_ARG_WITH([ltdl],ACX_HELP_STRING([--with-ltdl=DIR], [use ltdl in preference to dl]),
+              ,
+              with_ltdl=no)
+have_dl=no
+if test x$with_ltdl = xno ; then
+	AC_SEARCH_LIBS(dlsym, dl svdl, [
+		AC_DEFINE([HAVE_DLSYM],1,[the dlsym() function is available])
+		have_dl=yes
+	])
+	dnl
+	dnl FIXME: try shm_load() or whatever if no dlopen() ...
+	dnl
+else
+dnl # WARNING: I don't know what libraries ltdl depends on.  I just assume
+dnl #          that if the punter asks for it, then it must be installed and
+dnl #          the dynamic linker will sort the dependencies at link time.
+	if test x$with_ltdl != xyes ; then
+		CPPFLAGS="-I${with_ltdl}/include $CPPFLAGS"
+		LDFLAGS="-L${with_ltdl}/lib $LDFLAGS"
+	fi
+	LIBS="$LIBS -lltdl"
+	AC_DEFINE([WITH_LTDL],1,[the ltdl library is used])
+	with_ltdl=yes
+	have_dl=yes
+fi
+if test x$have_dl = xno ; then
+	AC_MSG_ERROR([No runtime dynamic loader found.  Hint: try --with-ltdl])
+fi
 
 dnl #########################################################################
 dnl Check if using Posix Threads
@@ -131,17 +151,6 @@
   	      ,
   	      enable_pthreads=auto)
  
-dnl if test x"$enable_pthreads" != xno ; then
-dnl 	AC_SEARCH_LIBS(pthread_create, pthread pthreads c_r cr,
-dnl 		       enable_pthreads=yes,
-dnl 		       if test x"$enable_pthreads" = xyes ; then
-dnl 		       		AC_MSG_ERROR([Cannot find the pthread library.])
-dnl 		       else
-dnl 		       		enable_pthreads=no
-dnl 		       fi
-dnl 	)
-dnl fi
-
 if test x"$enable_pthreads" != xno ; then
 	ACX_PTHREAD(enable_pthreads=yes,
 		       if test x"$enable_pthreads" = xyes ; then
@@ -526,9 +535,6 @@
 
 AC_SUBST(SASL_PLUGINS)
 AC_SUBST(LIBTOOL_DEPS)
-AC_SUBST(INCLTDL)
-AC_SUBST(LIBLTDL)
-AC_SUBST(LIBADD_LTDL)
 AC_SUBST(LIBS)
 AC_SUBST(CFLAGS)
 AC_SUBST(EXTRA_CFLAGS)
diff -rub libesmtp-0.8.8/crammd5/Makefile.in libesmtp/crammd5/Makefile.in
--- libesmtp-0.8.8/crammd5/Makefile.in	Tue Dec  4 10:51:00 2001
+++ libesmtp/crammd5/Makefile.in	Wed Dec 12 15:03:08 2001
@@ -68,12 +68,8 @@
 ECHO = @ECHO@
 EXEEXT = @EXEEXT@
 EXTRA_CFLAGS = @EXTRA_CFLAGS@
-INCLTDL = @INCLTDL@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
-LIBADD_DL = @LIBADD_DL@
-LIBADD_LTDL = @LIBADD_LTDL@
 LIBESMTP_VERSION = @LIBESMTP_VERSION@
-LIBLTDL = @LIBLTDL@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
 LIBTOOL_DEPS = @LIBTOOL_DEPS@
diff -rub libesmtp-0.8.8/libesmtp-config.in libesmtp/libesmtp-config.in
--- libesmtp-0.8.8/libesmtp-config.in	Mon Nov 12 14:59:17 2001
+++ libesmtp/libesmtp-config.in	Wed Dec 12 14:30:37 2001
@@ -69,7 +69,7 @@
        	;;
 
     --libs)
-       	echo @PTHREAD_LDFLAGS@ -L@libdir@ -lesmtp @LIBS@ @LIBADD_LTDL@ @LIBADD_DL@ @PTHREAD_LIBS@
+       	echo @PTHREAD_LDFLAGS@ -L@libdir@ -lesmtp @LIBS@ @PTHREAD_LIBS@
        	;;
 
     --plugindir)
diff -rub libesmtp-0.8.8/login/Makefile.in libesmtp/login/Makefile.in
--- libesmtp-0.8.8/login/Makefile.in	Tue Dec  4 10:51:01 2001
+++ libesmtp/login/Makefile.in	Wed Dec 12 15:03:00 2001
@@ -68,12 +68,8 @@
 ECHO = @ECHO@
 EXEEXT = @EXEEXT@
 EXTRA_CFLAGS = @EXTRA_CFLAGS@
-INCLTDL = @INCLTDL@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
-LIBADD_DL = @LIBADD_DL@
-LIBADD_LTDL = @LIBADD_LTDL@
 LIBESMTP_VERSION = @LIBESMTP_VERSION@
-LIBLTDL = @LIBLTDL@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
 LIBTOOL_DEPS = @LIBTOOL_DEPS@
diff -rub libesmtp-0.8.8/plain/Makefile.in libesmtp/plain/Makefile.in
--- libesmtp-0.8.8/plain/Makefile.in	Tue Dec  4 10:51:01 2001
+++ libesmtp/plain/Makefile.in	Wed Dec 12 15:03:04 2001
@@ -68,12 +68,8 @@
 ECHO = @ECHO@
 EXEEXT = @EXEEXT@
 EXTRA_CFLAGS = @EXTRA_CFLAGS@
-INCLTDL = @INCLTDL@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
-LIBADD_DL = @LIBADD_DL@
-LIBADD_LTDL = @LIBADD_LTDL@
 LIBESMTP_VERSION = @LIBESMTP_VERSION@
-LIBLTDL = @LIBLTDL@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
 LIBTOOL_DEPS = @LIBTOOL_DEPS@


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]