- Minor cleanups to build process

- Add header check for dlfcn.h
- Add internal functions sc_module_{open,close,get_address}
- Use environ instead __environ for scldap_search, should be
  more portable.
- Fix compiler warnings noticed by Tru64 / AIX cc


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@401 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
aet 2002-03-27 13:13:54 +00:00
parent 86a47efdec
commit 8f6ffee6a9
15 changed files with 142 additions and 58 deletions

View File

@ -140,7 +140,7 @@ dnl Automatically update the libtool script if it becomes out-of-date.
dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([errno.h fcntl.h malloc.h stdlib.h string.h sys/time.h unistd.h libgen.h utmp.h getopt.h security/pam_appl.h security/_pam_macros.h readline/readline.h])
AC_CHECK_HEADERS([errno.h fcntl.h malloc.h stdlib.h string.h sys/time.h unistd.h libgen.h utmp.h getopt.h dlfcn.h security/pam_appl.h security/_pam_macros.h readline/readline.h])
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST

View File

@ -17,8 +17,8 @@ INCLUDES = $(PCSC_FLAGS)
bin_SCRIPTS = opensc-config
lib_LTLIBRARIES = libopensc.la
libopensc_la_SOURCES = sc.c ctx.c asn1.c base64.c sec.c log.c \
card.c iso7816.c dir.c \
libopensc_la_SOURCES = sc.c ctx.c module.c asn1.c log.c base64.c \
sec.c card.c iso7816.c dir.c \
pkcs15.c pkcs15-cert.c pkcs15-pin.c \
pkcs15-prkey.c pkcs15-pubkey.c pkcs15-sec.c \
pkcs15-cache.c $(PCSC_SRC) reader-ctapi.c \

View File

@ -47,26 +47,26 @@ struct _sc_driver_entry {
};
static const struct _sc_driver_entry internal_card_drivers[] = {
{ "setcos", sc_get_setcos_driver },
{ "miocos", sc_get_miocos_driver },
{ "flex", sc_get_flex_driver },
{ "tcos", sc_get_tcos_driver },
{ "emv", sc_get_emv_driver },
{ "setcos", (void *) sc_get_setcos_driver, NULL },
{ "miocos", (void *) sc_get_miocos_driver, NULL },
{ "flex", (void *) sc_get_flex_driver, NULL },
{ "tcos", (void *) sc_get_tcos_driver, NULL },
{ "emv", (void *) sc_get_emv_driver, NULL },
#ifdef HAVE_OPENSSL
{ "gpk", sc_get_gpk_driver },
{ "gpk", (void *) sc_get_gpk_driver, NULL },
#endif
/* The default driver should be last, as it handles all the
* unrecognized cards. */
{ "default", sc_get_default_driver },
{ NULL }
{ "default", (void *) sc_get_default_driver, NULL },
{ NULL, NULL, NULL }
};
static const struct _sc_driver_entry internal_reader_drivers[] = {
#ifdef HAVE_LIBPCSCLITE
{ "pcsc", sc_get_pcsc_driver },
{ "pcsc", (void *) sc_get_pcsc_driver, NULL },
#endif
{ "ctapi", sc_get_ctapi_driver },
{ NULL }
{ "ctapi", (void *) sc_get_ctapi_driver, NULL },
{ NULL, NULL, NULL }
};
struct _sc_ctx_options {
@ -219,7 +219,7 @@ static int load_reader_drivers(struct sc_context *ctx,
ent = &opts->rdrv[i];
for (j = 0; internal_reader_drivers[j].name != NULL; j++)
if (strcmp(ent->name, internal_reader_drivers[j].name) == 0) {
func = internal_reader_drivers[j].func;
func = (const struct sc_reader_driver * (*)(void)) internal_reader_drivers[j].func;
break;
}
if (func == NULL) {
@ -252,7 +252,7 @@ static int load_card_drivers(struct sc_context *ctx,
ent = &opts->cdrv[i];
for (j = 0; internal_card_drivers[j].name != NULL; j++)
if (strcmp(ent->name, internal_card_drivers[j].name) == 0) {
func = internal_card_drivers[j].func;
func = (const struct sc_card_driver * (*)(void)) internal_card_drivers[j].func;
break;
}
if (func == NULL) {

View File

@ -56,4 +56,8 @@ int _sc_card_add_rsa_alg(struct sc_card *card, unsigned int key_length,
struct sc_algorithm_info * _sc_card_find_rsa_alg(struct sc_card *card,
unsigned int key_length);
int sc_module_open(struct sc_context *ctx, void **mod_handle, const char *filename);
int sc_module_close(struct sc_context *ctx, void **mod_handle);
int sc_module_get_address(struct sc_context *ctx, void *mod_handle, void **sym_address, const char *sym_name);
#endif

100
src/libopensc/module.c Normal file
View File

@ -0,0 +1,100 @@
/*
* module.c: Dynamic linking loader
*
* Copyright (C) 2002 Antti Tapaninen <aet@cc.hut.fi>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "sc-internal.h"
#include "sc-log.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#endif
int sc_module_open(struct sc_context *ctx, void **mod_handle, const char *filename)
{
const char *error;
assert(ctx != NULL);
if (!filename)
return SC_ERROR_UNKNOWN;
*mod_handle = NULL;
*mod_handle = dlopen(filename, RTLD_LAZY);
if ((error = dlerror()) != NULL) {
if (ctx->debug)
debug(ctx, "sc_module_open: %s", error);
return SC_ERROR_UNKNOWN;
}
return SC_SUCCESS;
}
int sc_module_close(struct sc_context *ctx, void **mod_handle)
{
const char *error;
assert(ctx != NULL);
if (!*mod_handle)
return SC_ERROR_UNKNOWN;
dlclose(*mod_handle);
*mod_handle = NULL;
if ((error = dlerror()) != NULL) {
if (ctx->debug)
debug(ctx, "sc_module_close: %s", error);
return SC_ERROR_UNKNOWN;
}
return SC_SUCCESS;
}
int sc_module_get_address(struct sc_context *ctx, void *mod_handle, void **sym_address, const char *sym_name)
{
const char *error;
char name[256];
assert(ctx != NULL);
if (!mod_handle || !sym_name)
return SC_ERROR_UNKNOWN;
/* Some platforms might need a leading underscore for the symbol */
name[0] = '_';
strncpy(&name[1], sym_name, sizeof(name) - 1);
*sym_address = NULL;
*sym_address = dlsym(mod_handle, name);
/* Failed? Try again without the leading underscore */
if (*sym_address == NULL)
*sym_address = dlsym(mod_handle, sym_name);
if ((error = dlerror()) != NULL) {
if (ctx->debug)
debug(ctx, "sc_module_get_address: %s", error);
return SC_ERROR_UNKNOWN;
}
return SC_SUCCESS;
}

View File

@ -24,7 +24,6 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#define GET_SLOT_PTR(s, i) (&(s)->slot[(i)])
#define GET_PRIV_DATA(r) ((struct ctapi_private_data *) (r)->drv_data)
@ -57,6 +56,7 @@ struct ctapi_private_data {
};
struct ctapi_slot_data {
void *filler;
};
static int refresh_slot_attributes(struct sc_reader *reader,
@ -243,21 +243,21 @@ static int ctapi_load_module(struct sc_context *ctx,
}
val = conf->name->data;
dlh = dlopen(val, RTLD_LAZY);
if (dlh == NULL) {
r = sc_module_open(ctx, &dlh, val);
if (r != SC_SUCCESS) {
error(ctx, "Unable to open shared library '%s'\n", val);
return -1;
}
func = dlsym(dlh, "CT_init");
if (func == NULL)
r = sc_module_get_address(ctx, dlh, &func, "CT_init");
if (r != SC_SUCCESS)
goto symerr;
funcs.CT_init = func;
func = dlsym(dlh, "CT_close");
if (func == NULL)
r = sc_module_get_address(ctx, dlh, &func, "CT_close");
if (r != SC_SUCCESS)
goto symerr;
funcs.CT_close = func;
func = dlsym(dlh, "CT_data");
if (func == NULL)
r = sc_module_get_address(ctx, dlh, &func, "CT_data");
if (r != SC_SUCCESS)
goto symerr;
funcs.CT_data = func;
mod = add_module(gpriv, val, dlh);
@ -310,7 +310,7 @@ static int ctapi_load_module(struct sc_context *ctx,
return 0;
symerr:
error(ctx, "Unable to resolve CT-API symbols.\n");
dlclose(dlh);
sc_module_close(ctx, &dlh);
return -1;
}

View File

@ -56,4 +56,8 @@ int _sc_card_add_rsa_alg(struct sc_card *card, unsigned int key_length,
struct sc_algorithm_info * _sc_card_find_rsa_alg(struct sc_card *card,
unsigned int key_length);
int sc_module_open(struct sc_context *ctx, void **mod_handle, const char *filename);
int sc_module_close(struct sc_context *ctx, void **mod_handle);
int sc_module_get_address(struct sc_context *ctx, void *mod_handle, void **sym_address, const char *sym_name);
#endif

View File

@ -7,8 +7,6 @@ EXTRA_DIST = openssh-3.0.2p1-patch.diff
if HAVE_SSL
bin_PROGRAMS = opensc-ssh
else
bin_PROGRAMS =
endif
opensc_ssh_SOURCES = opensc-ssh.c

View File

@ -11,9 +11,6 @@ SRC = pam_opensc.c pam_support.c pam_support.h
if HAVE_PAM
lib_LTLIBRARIES = pam_opensc.la
noinst_PROGRAMS = pam_opensc-test
else
lib_LTLIBRARIES =
noinst_PROGRAMS =
endif
pam_opensc_la_SOURCES = $(SRC)

View File

@ -4,36 +4,24 @@ INCLUDES = @CFLAGS_PCSC@ @CFLAGS_OPENSC@ -I../scrandom -I../scldap
if HAVE_PAM
PAM = libpamscam.la
else
PAM =
endif
if HAVE_SIA
SIA = libsiascam.la
else
SIA =
endif
lib_LTLIBRARIES = $(PAM) $(SIA)
if HAVE_LDAP
LDAP_LTLIBS = @LIBSCLDAP@
else
LDAP_LTLIBS =
endif
if HAVE_SSL
SSL_LTLIBS = @LIBCRYPTO@
else
SSL_LTLIBS =
endif
# Temporary
if HAVE_SCIDI
SCIDI_LTLIBS = @LIBSSP@
SCIDI_SRC = ../../../scam/sp.c
SCIDI_INC = @CFLAGS_SSP@
else
SCIDI_LTLIBS =
SCIDI_SRC =
SCIDI_INC =
endif
LDFLAGS = @LIBOPENSC@ @LIBSCRANDOM@ $(LDAP_LTLIBS) $(SSL_LTLIBS) $(SCIDI_LTLIBS)

View File

@ -5,9 +5,6 @@ include_HEADERS = scldap.h
if HAVE_LDAP
LDAP_LTLIB = libscldap.la
LDAP_PROGRAM = test-ldap
else
LDAP_LTLIB =
LDAP_PROGRAM =
endif
lib_LTLIBRARIES = $(LDAP_LTLIB)

View File

@ -42,6 +42,8 @@
#endif
#include "scldap.h"
extern char **environ;
static void scldap_parse_block(scldap_context * ctx, scconf_block * block, const char *cardprefix)
{
scconf_block **blocks = NULL;
@ -760,7 +762,7 @@ int scldap_search(scldap_context * ctx, const char *entry,
scldap_result *_result = *result;
int rc, entrynum = -1;
char *pattern = NULL;
char **env = NULL;
char **keepenv = NULL;
if (_result || !ctx) {
return -1;
@ -772,14 +774,14 @@ int scldap_search(scldap_context * ctx, const char *entry,
if (!ctx->entry[entrynum].ldaphost) {
return -1;
}
env = __environ;
__environ = NULL;
keepenv = environ;
environ = NULL;
if ((ld = ldap_init(ctx->entry[entrynum].ldaphost, ctx->entry[entrynum].ldapport)) == NULL) {
__environ = env;
environ = keepenv;
perror("ldap_init");
return -1;
}
__environ = env;
environ = keepenv;
if (ldap_bind_s(ld, ctx->entry[entrynum].binddn, ctx->entry[entrynum].passwd, LDAP_AUTH_SIMPLE) != LDAP_SUCCESS) {
ldap_perror(ld, "ldap_bind");
ldap_unbind(ld);

View File

@ -4,8 +4,6 @@ include_HEADERS = scrandom.h
if HAVE_SSL
SSL_LTLIB = @LIBCRYPTO@
else
SSL_LTLIB =
endif
lib_LTLIBRARIES = libscrandom.la

View File

@ -11,9 +11,6 @@ SRC = sia_opensc.c sia_support.c sia_support.h
if HAVE_SIA
lib_LTLIBRARIES = libsia_opensc.la
noinst_PROGRAMS = test-sia
else
lib_LTLIBRARIES =
noinst_PROGRAMS =
endif
libsia_opensc_la_SOURCES = $(SRC)

View File

@ -7,10 +7,9 @@ EXTRA_DIST = testprog.c
INCLUDES = @CFLAGS_OPENSC@ @CFLAGS_ASSUAN@
plugindir = $(PLUGINDIR)
if HAVE_SSL
plugin_LTLIBRARIES = opensc-signer.la
else
plugin_LTLIBRARIES =
endif
opensc_signer_la_LDFLAGS = -module -avoid-version