From a0b6643fa770e2bf797e87c14f51b4b4576d0dd3 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Sat, 14 Jul 2018 04:16:39 +0200 Subject: [PATCH] Use hard coded default SM module (path) - avoids the need to set this default in opensc.conf - fixes loading of (unknown) local library - removes some unused defines from config.h --- configure.ac | 17 +++++------------ etc/opensc.conf.example.in | 12 ++++++------ src/libopensc/Makefile.am | 2 ++ src/libopensc/card.c | 14 ++++++++++---- src/tools/Makefile.am | 2 +- win32/winconfig.h.in | 7 +++++++ 6 files changed, 31 insertions(+), 23 deletions(-) diff --git a/configure.ac b/configure.ac index c655e764..a0212891 100644 --- a/configure.ac +++ b/configure.ac @@ -123,9 +123,6 @@ case "${host}" in PROFILE_DIR_DEFAULT="\$(pkgdatadir)" ;; esac -AC_DEFINE_UNQUOTED([DEBUG_FILE], ["${DEBUG_FILE}"], [Debug file]) -AC_DEFINE_UNQUOTED([PROFILE_DIR], ["${PROFILE_DIR}"], [Directory of profiles]) -AC_DEFINE_UNQUOTED([PROFILE_DIR_DEFAULT], ["${PROFILE_DIR_DEFAULT}"], [Default directory of profiles]) case "${host}" in *-mingw*) @@ -347,7 +344,6 @@ AC_MSG_RESULT([${xslstylesheetsdir}]) AC_MSG_CHECKING([git checkout]) GIT_CHECKOUT="no" if test -n "${GIT}" -a -d "${srcdir}/.git"; then - AC_DEFINE([HAVE_CONFIG_VERSION_H], [1], [extra version available in config-version.h]) GIT_CHECKOUT="yes" fi AC_MSG_RESULT([${GIT_CHECKOUT}]) @@ -881,26 +877,23 @@ if test "${enable_sm}" = "yes"; then DEFAULT_SM_MODULE="${LIB_PRE}smm-local${DYN_LIB_EXT}" case "${host}" in *-mingw*|*-winnt*|*-cygwin*) - DEFAULT_SM_MODULE_PATH="\# module_path = \"\";" + DEFAULT_SM_MODULE_PATH="%PROGRAMFILES%\\\OpenSC Project\\\OpenSC\\\tools" ;; *) - DEFAULT_SM_MODULE_PATH="module_path = \$(libdir);" + DEFAULT_SM_MODULE_PATH="${libdir}" ;; esac - AC_DEFINE_UNQUOTED([DEFAULT_SM_MODULE], ["${DEFAULT_SM_MODULE}"], [Default SM module]) - AC_DEFINE_UNQUOTED([DEFAULT_SM_MODULE_PATH], ["${DEFAULT_SM_MODULE_PATH}"], [Default SM module path]) fi if test "${with_pkcs11_provider}" = "detect"; then if test "${WIN32}" != "yes"; then - DEFAULT_PKCS11_PROVIDER="opensc-pkcs11${DYN_LIB_EXT}" + DEFAULT_PKCS11_PROVIDER="${libdir}/opensc-pkcs11${DYN_LIB_EXT}" else DEFAULT_PKCS11_PROVIDER="%PROGRAMFILES%\\\OpenSC Project\\\OpenSC\\\pkcs11\\\opensc-pkcs11.dll" fi else DEFAULT_PKCS11_PROVIDER="${with_pkcs11_provider}" fi -AC_DEFINE_UNQUOTED([DEFAULT_PKCS11_PROVIDER], ["${DEFAULT_PKCS11_PROVIDER}"], [Default PKCS11 provider]) if test "${enable_man}" = "detect"; then if test "${WIN32}" = "yes"; then @@ -1129,13 +1122,13 @@ CT-API support: ${enable_ctapi} minidriver support: ${enable_minidriver} SM support: ${enable_sm} SM default module: ${DEFAULT_SM_MODULE} +SM default path: $(eval eval eval echo "${DEFAULT_SM_MODULE_PATH}") DNIe UI support: ${enable_dnie_ui} Notification support: ${enable_notify} Build tests: ${enable_tests} -Debug file: ${DEBUG_FILE} PC/SC default provider: ${DEFAULT_PCSC_PROVIDER} -PKCS11 default provider: ${DEFAULT_PKCS11_PROVIDER} +PKCS11 default provider: $(eval eval eval echo "${DEFAULT_PKCS11_PROVIDER}") Host: ${host} Compiler: ${CC} diff --git a/etc/opensc.conf.example.in b/etc/opensc.conf.example.in index b7fd7d63..8ba5e4dd 100644 --- a/etc/opensc.conf.example.in +++ b/etc/opensc.conf.example.in @@ -797,8 +797,8 @@ app default { # name of external SM module # module_name = @DEFAULT_SM_MODULE@; # directory with external SM module - # Default: defined by windows register - @DEFAULT_SM_MODULE_PATH@ + # Default: @DEFAULT_SM_MODULE_PATH@ + # module_path = @DEFAULT_SM_MODULE_PATH@; # specific data to tune the module initialization # module_data = "Here can be your SM module init data"; @@ -821,7 +821,7 @@ app default { secure_messaging local_gemalto_iam { module_name = @DEFAULT_SM_MODULE@; - @DEFAULT_SM_MODULE_PATH@ + # module_path = @DEFAULT_SM_MODULE_PATH@; # module_data = ""; type = acl; # transmit, acl @@ -840,7 +840,7 @@ app default { secure_messaging local_amos { module_name = @DEFAULT_SM_MODULE@; - @DEFAULT_SM_MODULE_PATH@ + # module_path = @DEFAULT_SM_MODULE_PATH@; # module_data = ""; mode = acl; ifd_serial = "11:22:33:44:55:66:77:88"; @@ -850,7 +850,7 @@ app default { secure_messaging local_amos_eid { module_name = @DEFAULT_SM_MODULE@; - @DEFAULT_SM_MODULE_PATH@ + # module_path = @DEFAULT_SM_MODULE_PATH@; # module_data = ""; mode = acl; ifd_serial = "11:22:33:44:55:66:77:88"; @@ -860,7 +860,7 @@ app default { secure_messaging local_adele { module_name = @DEFAULT_SM_MODULE@; - @DEFAULT_SM_MODULE_PATH@ + # module_path = @DEFAULT_SM_MODULE_PATH@; # module_data = ""; type = acl; # transmit, acl diff --git a/src/libopensc/Makefile.am b/src/libopensc/Makefile.am index 01533ba0..ad259690 100644 --- a/src/libopensc/Makefile.am +++ b/src/libopensc/Makefile.am @@ -15,6 +15,8 @@ noinst_HEADERS = cards.h ctbcs.h internal.h esteid.h muscle.h muscle-filesystem. jpki.h sc-ossl-compat.h card-npa.h ccid-types.h reader-tr03119.h AM_CPPFLAGS = -DOPENSC_CONF_PATH=\"$(sysconfdir)/opensc.conf\" \ + -DDEFAULT_SM_MODULE_PATH=\"$(DEFAULT_SM_MODULE_PATH)\" \ + -DDEFAULT_SM_MODULE=\"$(DEFAULT_SM_MODULE)\" \ -I$(top_srcdir)/src AM_CFLAGS = $(OPENPACE_CFLAGS) $(OPTIONAL_OPENSSL_CFLAGS) $(OPTIONAL_OPENCT_CFLAGS) \ $(OPTIONAL_PCSC_CFLAGS) $(OPTIONAL_ZLIB_CFLAGS) diff --git a/src/libopensc/card.c b/src/libopensc/card.c index 99b8da61..6bd0ef2f 100644 --- a/src/libopensc/card.c +++ b/src/libopensc/card.c @@ -1347,6 +1347,8 @@ sc_card_sm_load(struct sc_card *card, const char *module_path, const char *in_mo char temp_path[PATH_MAX]; size_t temp_len; const char path_delim = '\\'; + char expanded_val[PATH_MAX]; + DWORD expanded_len; #else const char path_delim = '/'; #endif @@ -1360,16 +1362,20 @@ sc_card_sm_load(struct sc_card *card, const char *module_path, const char *in_mo return sc_card_sm_unload(card); #ifdef _WIN32 - if (!module_path) { + if (!module_path || strlen(module_path) == 0) { temp_len = PATH_MAX; rv = sc_ctx_win32_get_config_value(NULL, "SmDir", "Software\\OpenSC Project\\OpenSC", temp_path, &temp_len); if (rv == SC_SUCCESS) module_path = temp_path; } + expanded_len = PATH_MAX; + expanded_len = ExpandEnvironmentStringsA(module_path, expanded_val, expanded_len); + if (0 < expanded_len && expanded_len < sizeof expanded_val) + module_path = expanded_val; #endif sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "SM module '%s' located in '%s'", in_module, module_path); - if (module_path) { + if (module_path && strlen(module_path) > 0) { int sz = strlen(in_module) + strlen(module_path) + 3; module = malloc(sz); if (module) @@ -1475,8 +1481,8 @@ sc_card_sm_check(struct sc_card *card) LOG_TEST_RET(ctx, SC_ERROR_INCONSISTENT_CONFIGURATION, "SM configuration block not preset"); /* check if an external SM module has to be used */ - module_path = scconf_get_str(sm_conf_block, "module_path", NULL); - module_name = scconf_get_str(sm_conf_block, "module_name", NULL); + module_path = scconf_get_str(sm_conf_block, "module_path", DEFAULT_SM_MODULE_PATH); + module_name = scconf_get_str(sm_conf_block, "module_name", DEFAULT_SM_MODULE); sc_log(ctx, "SM module '%s' in '%s'", module_name, module_path); if (!module_name) LOG_TEST_RET(ctx, SC_ERROR_INCONSISTENT_CONFIGURATION, "Invalid SM configuration: module not defined"); diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am index 63cafb48..a3300ab9 100644 --- a/src/tools/Makefile.am +++ b/src/tools/Makefile.am @@ -39,7 +39,7 @@ endif # compile with $(PTHREAD_CFLAGS) to allow debugging with gdb AM_CFLAGS = $(OPTIONAL_OPENSSL_CFLAGS) $(OPTIONAL_READLINE_CFLAGS) $(PTHREAD_CFLAGS) -AM_CPPFLAGS = -I$(top_srcdir)/src +AM_CPPFLAGS = -I$(top_srcdir)/src -DDEFAULT_PKCS11_PROVIDER=\"$(DDEFAULT_PKCS11_PROVIDER)\" LIBS = \ $(top_builddir)/src/libopensc/libopensc.la \ $(top_builddir)/src/common/libscdl.la \ diff --git a/win32/winconfig.h.in b/win32/winconfig.h.in index 3aa2beec..09842209 100644 --- a/win32/winconfig.h.in +++ b/win32/winconfig.h.in @@ -99,6 +99,13 @@ #define DEFAULT_PKCS11_PROVIDER "@DEFAULT_PKCS11_PROVIDER@" #endif +#ifndef DEFAULT_SM_MODULE +#define DEFAULT_SM_MODULE "@DEFAULT_SM_MODULE@" +#endif +#ifndef DEFAULT_SM_MODULE_PATH +#define DEFAULT_SM_MODULE_PATH "@DEFAULT_SM_MODULE_PATH@" +#endif + #ifndef OPENSC_SCM_REVISION #define OPENSC_SCM_REVISION "@OPENSC_SCM_REVISION@" #endif