From 708a9cb5a4dd80b7dac47dcdab936b9dd8abce7b Mon Sep 17 00:00:00 2001 From: Klas Lindfors Date: Tue, 4 Feb 2014 17:17:31 +0100 Subject: [PATCH] pcsc for platforms fixes --- Makefile.am | 5 ++-- configure.ac | 67 ++++++++++++++++++++++++++++++++++++++++++++++- yubico-piv-tool.c | 9 ++++--- 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/Makefile.am b/Makefile.am index b8bc1cb..c9a89c7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,14 +25,15 @@ # for the parts of OpenSSL used as well as that of the covered work. AM_CFLAGS = $(WERROR_CFLAGS) $(WARN_CFLAGS) -AM_CPPFLAGS = $(PCSC_CFLAGS) $(OPENSSL_CFLAGS) +AM_CPPFLAGS = $(OPENSSL_CFLAGS) $(PCSC_CFLAGS) ACLOCAL_AMFLAGS = -I m4 bin_PROGRAMS = yubico-piv-tool yubico_piv_tool_SOURCES = yubico-piv-tool.c yubico_piv_tool_SOURCES += cmdline.ggo cmdline.c cmdline.h -yubico_piv_tool_LDADD = $(PCSC_LIBS) $(OPENSSL_LIBS) +yubico_piv_tool_LDADD = $(OPENSSL_LIBS) $(PCSC_LIBS) +yubico_piv_tool_LDADD += $(LTLIBWINSCARD) $(PCSC_MACOSX_LIBS) cmdline.c cmdline.h: cmdline.ggo Makefile.am gengetopt --input $^ diff --git a/configure.ac b/configure.ac index f90f63a..3669902 100644 --- a/configure.ac +++ b/configure.ac @@ -37,9 +37,74 @@ AC_PROG_LIBTOOL AM_MISSING_PROG(HELP2MAN, help2man, $missing_dir) PKG_PROG_PKG_CONFIG -PKG_CHECK_MODULES(PCSC, libpcsclite) PKG_CHECK_MODULES(OPENSSL, openssl) +AC_ARG_WITH([backend], + [AS_HELP_STRING([--with-backend=ARG], + [use specific backend/linkage; 'pcsc', 'macscard' or 'winscard'])], + [], + [with_backend=check]) + +case "$with_backend$host" in + check*-darwin*) + AC_MSG_NOTICE([Detected Mac: selecting macscard backend]) + AC_MSG_NOTICE([use --with-backend to override]) + with_backend=macscard ;; + check*-mingw*) + AC_MSG_NOTICE([Detected Windows: selecting winscard backend]) + AC_MSG_NOTICE([use --with-backend to override]) + with_backend=winscard ;; +esac + +if test "x$with_backend" = xcheck || test "x$with_backend" = xpcsc; then + PKG_CHECK_MODULES([PCSC], [libpcsclite], + [with_backend=pcsc], [:]) +fi + +if test "x$with_backend" = xcheck; then + AC_CHECK_HEADERS([PCSC/winscard.h]) + AC_MSG_CHECKING([between Mac/Windows winscard]) + if test "x$ac_cv_header_PCSC_winscard_h" = xyes; then + with_backend=macscard + AC_MSG_RESULT([Mac]) + else + with_backend=winscard + AC_MSG_RESULT([Windows]) + fi +fi + +if test "x$with_backend" = xwinscard; then + AC_MSG_NOTICE([checking for winscard with Windows linkage]) + AC_LIB_HAVE_LINKFLAGS(winscard,, [#include ], + [SCardBeginTransaction(0)]) + if test "x$ac_cv_libwinscard" != xyes; then + AC_MSG_ERROR([cannot find Windows winscard library/headers]) + fi +fi + +if test "x$with_backend" = xmacscard; then + AC_MSG_NOTICE([checking for PCSC with Mac linkage]) + AC_CHECK_HEADERS([PCSC/winscard.h]) + PCSC_MACOSX_LIBS="-Wl,-framework -Wl,PCSC" + save_LIBS="$LIBS" + LIBS="$LIBS $PCSC_MACOSX_LIBS" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include + #include ]], + [[SCardBeginTransaction(0)]])], + [AC_SUBST([PCSC_MACOSX_LIBS])], + [AC_MSG_ERROR([cannot find Mac PCSC library/headers])]) + LIBS="$save_LIBS" +fi + +if test "x$with_backend" = xpcsc || test "x$with_backend" = xwinscard \ + || test "x$with_backend" = xmacscard; then + AC_DEFINE([BACKEND_PCSC], 1, [Define to 1 if you the PCSC backend.]) +else + AC_MSG_ERROR([cannot find PCSC/winscard library/headers]) +fi + + + AC_ARG_ENABLE([gcc-warnings], [AS_HELP_STRING([--enable-gcc-warnings], [turn on lots of GCC warnings (for developers)])], diff --git a/yubico-piv-tool.c b/yubico-piv-tool.c index 6f55647..695c730 100644 --- a/yubico-piv-tool.c +++ b/yubico-piv-tool.c @@ -36,10 +36,13 @@ #include #include -#ifdef __APPLE__ -#include +#if BACKEND_PCSC +#if defined HAVE_PCSC_WINSCARD_H +# include +# include #else -#include +# include +#endif #endif #include "cmdline.h"