patch from upstream From 1c872a3e9c4cbf3cbd485168a7e98b589bbad57a Mon Sep 17 00:00:00 2001 From: alonbl Date: Wed, 14 Dec 2011 10:46:45 +0000 Subject: [PATCH] Remove ltdl usage Use native POSIX/Windows git-svn-id: http://www.opensc-project.org/svn/libp11/trunk@202 6d86ddd8-19ff-0310-a323-aa2ba648d307 --- configure.ac | 23 +++++------------------ src/Makefile.am | 4 ++-- src/Makefile.mak | 7 ++----- src/libpkcs11.c | 52 +++++++++++++++++++++++++++++++++++++++------------- 4 files changed, 48 insertions(+), 38 deletions(-) diff --git a/configure.ac b/configure.ac index 679b8da..9fa96bf 100644 --- a/configure.ac +++ b/configure.ac @@ -180,25 +180,14 @@ if test "${svn_checkout}" = "yes"; then fi fi -AC_ARG_VAR([LTLIB_CFLAGS], [C compiler flags for libltdl]) -AC_ARG_VAR([LTLIB_LIBS], [linker flags for libltdl]) -if test -z "${LTLIB_LIBS}"; then +if test "${WIN32}" != "yes"; then AC_CHECK_LIB( - [ltdl], - [lt_dlopen], - [LTLIB_LIBS="-lltdl"], - [AC_MSG_ERROR([ltdl not found, please install libltdl and/or libtool])] + [dl], + [dlopen], + , + [AC_MSG_ERROR([libdl required])] ) - fi -saved_CFLAGS="${CFLAGS}" -CFLAGS="${CFLAGS} ${LTLIB_CFLAGS}" -AC_CHECK_HEADER( - [ltdl.h], - , - [AC_MSG_ERROR([ltdl.h not found, please install libltdl and/or libtool])] -) -CFLAGS="${saved_CFLAGS}" PKG_CHECK_MODULES( [OPENSSL], @@ -273,8 +262,6 @@ Compiler flags: ${CFLAGS} Linker flags: ${LDFLAGS} Libraries: ${LIBS} -LTLIB_CFLAGS: ${LTLIB_CFLAGS} -LTLIB_LIBS: ${LTLIB_LIBS} OPENSSL_CFLAGS: ${OPENSSL_CFLAGS} OPENSSL_LIBS: ${OPENSSL_LIBS} diff --git a/src/Makefile.am b/src/Makefile.am index c66a8cd..0910f44 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,8 +16,8 @@ libp11_la_SOURCES += versioninfo.rc else dist_noinst_DATA = versioninfo.rc endif -libp11_la_CFLAGS = $(AM_CFLAGS) $(OPENSSL_CFLAGS) $(LTLIB_CFLAGS) -libp11_la_LIBADD = $(OPENSSL_LIBS) $(LTLIB_LIBS) +libp11_la_CFLAGS = $(AM_CFLAGS) $(OPENSSL_CFLAGS) +libp11_la_LIBADD = $(OPENSSL_LIBS) libp11_la_LDFLAGS = $(AM_LDFLAGS) \ -version-info @LIBP11_LT_CURRENT@:@LIBP11_LT_REVISION@:@LIBP11_LT_AGE@ \ -export-symbols "$(srcdir)/libp11.exports" \ diff --git a/src/Makefile.mak b/src/Makefile.mak index 73b5428..fa0809c 100644 --- a/src/Makefile.mak +++ b/src/Makefile.mak @@ -1,10 +1,7 @@ -LIBLTDL_INC = # E.g. /IC:\libtool-1.5.8-lib\include -LIBLTDL_LIB = # E.g. C:\libtool-1.5.8-lib\lib\libltdl.lib - OPENSSL_INC = /IC:\openssl\include OPENSSL_LIB = C:\openssl\out32dll\libeay32.lib -COPTS = /Zi /MD /nologo /I..\ /I. $(OPENSSL_INC) $(LIBLTDL_INC) /D_WIN32_WINNT=0x0400 /DWIN32 /DWIN32_LEAN_AND_MEAN +COPTS = /Zi /MD /nologo /I..\ /I. $(OPENSSL_INC) /D_WIN32_WINNT=0x0400 /DWIN32 /DWIN32_LEAN_AND_MEAN LINKFLAGS = /DEBUG /NOLOGO /INCREMENTAL:NO /MACHINE:IX86 TARGET = libp11.dll @@ -28,6 +25,6 @@ $(TARGET): $(OBJECTS) versioninfo.res echo EXPORTS >> $*.def type $*.exports >> $*.def link $(LINKFLAGS) /dll /def:$*.def /implib:$*.lib /out:$(TARGET) \ - $(OBJECTS) $(OPENSSL_LIB) $(LIBLTDL_LIB) versioninfo.res + $(OBJECTS) $(OPENSSL_LIB) versioninfo.res if EXIST $*.dll.manifest mt -manifest $*.dll.manifest -outputresource:$*.dll;2 diff --git a/src/libpkcs11.c b/src/libpkcs11.c index a146361..93584d9 100644 --- a/src/libpkcs11.c +++ b/src/libpkcs11.c @@ -27,14 +27,18 @@ #include #include #include -#include +#ifdef WIN32 +#include +#else +#include +#endif #include "libp11-int.h" #define MAGIC 0xd00bed00 struct sc_pkcs11_module { unsigned int _magic; - lt_dlhandle handle; + void *handle; }; typedef struct sc_pkcs11_module sc_pkcs11_module_t; @@ -52,19 +56,40 @@ C_LoadModule(const char *mspec, CK_FUNCTION_LIST_PTR_PTR funcs) if (mspec == NULL) return NULL; - if (lt_dlinit() != 0) - return NULL; - mod = (sc_pkcs11_module_t *) calloc(1, sizeof(*mod)); mod->_magic = MAGIC; - mod->handle = lt_dlopen(mspec); +#ifdef WIN32 + mod->handle = LoadLibraryA(mspec); +#else + mod->handle = dlopen(mspec, RTLD_NOW); +#endif + if (mod->handle == NULL) goto failed; - /* Get the list of function pointers */ - c_get_function_list = (CK_RV (*)(CK_FUNCTION_LIST_PTR_PTR)) - lt_dlsym(mod->handle, "C_GetFunctionList"); +#ifdef WIN32 + c_get_function_list = (CK_C_GetFunctionList)GetProcAddress ( + mod->handle, + "C_GetFunctionList" + ); +#else + { + /* + * Make compiler happy! + */ + void *p = dlsym( + mod->handle, + "C_GetFunctionList" + ); + memmove( + &c_get_function_list, + &p, + sizeof(void *) + ); + } +#endif + if (!c_get_function_list) goto failed; rv = c_get_function_list(funcs); @@ -89,13 +114,14 @@ C_UnloadModule(void *module) if (!mod || mod->_magic != MAGIC) return CKR_ARGUMENTS_BAD; - if (lt_dlclose(mod->handle) < 0) - return CKR_FUNCTION_FAILED; +#ifdef WIN32 + FreeLibrary(mod->handle); +#else + dlclose(mod->handle); +#endif memset(mod, 0, sizeof(*mod)); free(mod); - lt_dlexit(); - return CKR_OK; } -- 1.7.6.1