- Increase SC_MAX_READER_DRIVERS / SC_MAX_CARD_DRIVERS
- Some cleanups before future commits git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2191 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
118c1f914a
commit
b80890d49c
@ -139,7 +139,7 @@ app default {
|
||||
#
|
||||
# Default: autodetect
|
||||
#
|
||||
# force_card_driver = miocos;
|
||||
# force_card_driver = customcos;
|
||||
|
||||
# Below are the framework specific configuration blocks.
|
||||
|
||||
@ -148,33 +148,34 @@ app default {
|
||||
# Whether to use the cache files in the user's
|
||||
# home directory.
|
||||
#
|
||||
# At the moment you have to 'teach' the card to the
|
||||
# system by:
|
||||
# pkcs15-tool -L
|
||||
# At the moment you have to 'teach' the card
|
||||
# to the system by running command: pkcs15-tool -L
|
||||
#
|
||||
# WARNING: Caching shouldn't be used in setuid root
|
||||
# applications.
|
||||
# Default: false
|
||||
#
|
||||
use_caching = true;
|
||||
# Enable pkcs15 emulation
|
||||
# Enable pkcs15 emulation.
|
||||
# Default: yes
|
||||
enable_pkcs15_emulation = yes;
|
||||
# Try pkcs15 emulation code first (before the normal
|
||||
# pkcs15 processing).
|
||||
# Prefer pkcs15 emulation code before
|
||||
# the normal pkcs15 processing.
|
||||
# Default: no
|
||||
try_emulation_first = no;
|
||||
# Enable builtin emulators
|
||||
# Enable builtin emulators.
|
||||
# Default: yes
|
||||
enable_builtin_emulation = yes;
|
||||
# list of the builtin pkcs15 emulators to test
|
||||
# possible values: esteid, openpgp, netkey, netkey,
|
||||
# starcert, infocamere, postecert
|
||||
builtin_emulators = esteid, openpgp, netkey, netkey, starcert, infocamere, postecert;
|
||||
|
||||
# additional pkcs15 emulators (dynamic or builtin with
|
||||
# a different atr etc.)
|
||||
# emulate foo {
|
||||
# additional settings per driver
|
||||
#
|
||||
# For pkcs15 emulators loaded from an external shared library/DLL,
|
||||
# you need to specify the path name of the module
|
||||
#
|
||||
# emulate custom {
|
||||
# The location of the driver library
|
||||
# module = builtin;
|
||||
# atr = 11:22:33:44;
|
||||
# }
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <opensc/scdl.h>
|
||||
|
||||
/* Default value for apdu_masquerade option */
|
||||
@ -45,62 +44,60 @@ int _sc_add_reader(struct sc_context *ctx, struct sc_reader *reader)
|
||||
ctx->reader[ctx->reader_count] = reader;
|
||||
ctx->reader_count++;
|
||||
|
||||
return 0;
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
||||
struct _sc_driver_entry {
|
||||
char *name;
|
||||
void *func;
|
||||
char *libpath;
|
||||
};
|
||||
|
||||
static const struct _sc_driver_entry internal_card_drivers[] = {
|
||||
{ "etoken", (void *) sc_get_etoken_driver, NULL },
|
||||
{ "flex", (void *) sc_get_cryptoflex_driver, NULL },
|
||||
{ "cyberflex", (void *) sc_get_cyberflex_driver, NULL },
|
||||
{ "etoken", (void *) sc_get_etoken_driver },
|
||||
{ "flex", (void *) sc_get_cryptoflex_driver },
|
||||
{ "cyberflex", (void *) sc_get_cyberflex_driver },
|
||||
#ifdef HAVE_OPENSSL
|
||||
{ "gpk", (void *) sc_get_gpk_driver, NULL },
|
||||
{ "gpk", (void *) sc_get_gpk_driver },
|
||||
#endif
|
||||
{ "miocos", (void *) sc_get_miocos_driver, NULL },
|
||||
{ "mcrd", (void *) sc_get_mcrd_driver, NULL },
|
||||
{ "setcos", (void *) sc_get_setcos_driver, NULL },
|
||||
{ "starcos", (void *) sc_get_starcos_driver, NULL },
|
||||
{ "tcos", (void *) sc_get_tcos_driver, NULL },
|
||||
{ "opengpg", (void *) sc_get_openpgp_driver, NULL },
|
||||
{ "jcop", (void *) sc_get_jcop_driver, NULL },
|
||||
{ "miocos", (void *) sc_get_miocos_driver },
|
||||
{ "mcrd", (void *) sc_get_mcrd_driver },
|
||||
{ "setcos", (void *) sc_get_setcos_driver },
|
||||
{ "starcos", (void *) sc_get_starcos_driver },
|
||||
{ "tcos", (void *) sc_get_tcos_driver },
|
||||
{ "opengpg", (void *) sc_get_openpgp_driver },
|
||||
{ "jcop", (void *) sc_get_jcop_driver },
|
||||
#ifdef HAVE_OPENSSL
|
||||
{ "oberthur", (void *) sc_get_oberthur_driver, NULL },
|
||||
{ "oberthur", (void *) sc_get_oberthur_driver },
|
||||
#endif
|
||||
{ "belpic", (void *) sc_get_belpic_driver, NULL },
|
||||
{ "emv", (void *) sc_get_emv_driver, NULL },
|
||||
{ "belpic", (void *) sc_get_belpic_driver },
|
||||
{ "emv", (void *) sc_get_emv_driver },
|
||||
/* The default driver should be last, as it handles all the
|
||||
* unrecognized cards. */
|
||||
{ "default", (void *) sc_get_default_driver, NULL },
|
||||
{ NULL, NULL, NULL }
|
||||
{ "default", (void *) sc_get_default_driver },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static const struct _sc_driver_entry internal_reader_drivers[] = {
|
||||
#if defined(HAVE_PCSC)
|
||||
{ "pcsc", (void *) sc_get_pcsc_driver, NULL },
|
||||
{ "pcsc", (void *) sc_get_pcsc_driver },
|
||||
#endif
|
||||
{ "ctapi", (void *) sc_get_ctapi_driver, NULL },
|
||||
{ "ctapi", (void *) sc_get_ctapi_driver },
|
||||
#ifndef _WIN32
|
||||
#ifdef HAVE_OPENCT
|
||||
{ "openct", (void *) sc_get_openct_driver, NULL },
|
||||
{ "openct", (void *) sc_get_openct_driver },
|
||||
#endif
|
||||
#endif
|
||||
{ NULL, NULL, NULL }
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
struct _sc_ctx_options {
|
||||
struct _sc_driver_entry rdrv[16];
|
||||
struct _sc_driver_entry rdrv[SC_MAX_READER_DRIVERS];
|
||||
int rcount;
|
||||
struct _sc_driver_entry cdrv[16];
|
||||
struct _sc_driver_entry cdrv[SC_MAX_CARD_DRIVERS];
|
||||
int ccount;
|
||||
char *forced_card_driver;
|
||||
};
|
||||
|
||||
|
||||
static void del_drvs(struct _sc_ctx_options *opts, int type)
|
||||
{
|
||||
struct _sc_driver_entry *lst;
|
||||
@ -115,8 +112,6 @@ static void del_drvs(struct _sc_ctx_options *opts, int type)
|
||||
}
|
||||
for (i = 0; i < *cp; i++) {
|
||||
free(lst[i].name);
|
||||
if (lst[i].libpath)
|
||||
free(lst[i].libpath);
|
||||
}
|
||||
*cp = 0;
|
||||
}
|
||||
@ -124,16 +119,18 @@ static void del_drvs(struct _sc_ctx_options *opts, int type)
|
||||
static void add_drv(struct _sc_ctx_options *opts, int type, const char *name)
|
||||
{
|
||||
struct _sc_driver_entry *lst;
|
||||
int *cp, i;
|
||||
int *cp, max, i;
|
||||
|
||||
if (type == 0) {
|
||||
lst = opts->rdrv;
|
||||
cp = &opts->rcount;
|
||||
max = SC_MAX_READER_DRIVERS;
|
||||
} else {
|
||||
lst = opts->cdrv;
|
||||
cp = &opts->ccount;
|
||||
max = SC_MAX_CARD_DRIVERS;
|
||||
}
|
||||
if (*cp == 16) /* No space for more drivers... */
|
||||
if (*cp == max) /* No space for more drivers... */
|
||||
return;
|
||||
for (i = 0; i < *cp; i++)
|
||||
if (strcmp(name, lst[i].name) == 0)
|
||||
@ -179,8 +176,7 @@ static int load_parameters(struct sc_context *ctx, scconf_block *block,
|
||||
{
|
||||
int err = 0;
|
||||
const scconf_list *list;
|
||||
const char *val;
|
||||
const char *s_internal = "internal";
|
||||
const char *val, *s_internal = "internal";
|
||||
|
||||
ctx->debug = scconf_get_int(block, "debug", ctx->debug);
|
||||
val = scconf_get_str(block, "debug_file", NULL);
|
||||
@ -328,7 +324,9 @@ static const char *find_library(struct sc_context *ctx, const char *name, int ty
|
||||
* that returns a pointer to the function _sc_get_xxxx_driver()
|
||||
* used to initialize static modules
|
||||
* Also, an exported "char *sc_module_version" variable should exist in module
|
||||
* type=1 -> carddriver Type=0 -> readerdriver
|
||||
*
|
||||
* type == 0 -> reader driver
|
||||
* type == 1 -> card driver
|
||||
*/
|
||||
static void *load_dynamic_driver(struct sc_context *ctx, void **dll,
|
||||
const char *name, int type)
|
||||
@ -409,7 +407,7 @@ static int load_reader_drivers(struct sc_context *ctx,
|
||||
ctx->reader_drivers[drv_count] = driver;
|
||||
drv_count++;
|
||||
}
|
||||
return 0;
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
||||
static int load_card_driver_options(struct sc_context *ctx,
|
||||
@ -439,8 +437,7 @@ static int load_card_driver_options(struct sc_context *ctx,
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
||||
static int load_card_drivers(struct sc_context *ctx,
|
||||
@ -481,7 +478,7 @@ static int load_card_drivers(struct sc_context *ctx,
|
||||
load_card_driver_options(ctx, ctx->card_drivers[drv_count]);
|
||||
drv_count++;
|
||||
}
|
||||
return 0;
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
||||
static void process_config_file(struct sc_context *ctx, struct _sc_ctx_options *opts)
|
||||
@ -572,7 +569,7 @@ int sc_establish_context(struct sc_context **ctx_out, const char *app_name)
|
||||
return SC_ERROR_NO_READERS_FOUND;
|
||||
}
|
||||
*ctx_out = ctx;
|
||||
return 0;
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
||||
int sc_release_context(struct sc_context *ctx)
|
||||
@ -616,7 +613,7 @@ int sc_release_context(struct sc_context *ctx)
|
||||
free(ctx->app_name);
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
free(ctx);
|
||||
return 0;
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
||||
int sc_set_card_driver(struct sc_context *ctx, const char *short_name)
|
||||
@ -640,7 +637,7 @@ int sc_set_card_driver(struct sc_context *ctx, const char *short_name)
|
||||
sc_mutex_unlock(ctx->mutex);
|
||||
if (match == 0)
|
||||
return SC_ERROR_OBJECT_NOT_FOUND; /* FIXME: invent error */
|
||||
return 0;
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
||||
int sc_get_cache_dir(struct sc_context *ctx, char *buf, size_t bufsize)
|
||||
@ -668,7 +665,7 @@ int sc_get_cache_dir(struct sc_context *ctx, char *buf, size_t bufsize)
|
||||
return SC_ERROR_INTERNAL;
|
||||
if (snprintf(buf, bufsize, "%s/%s", homedir, cache_dir) < 0)
|
||||
return SC_ERROR_BUFFER_TOO_SMALL;
|
||||
return 0;
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
||||
int sc_make_cache_dir(struct sc_context *ctx)
|
||||
@ -701,7 +698,7 @@ int sc_make_cache_dir(struct sc_context *ctx)
|
||||
if (mkdir(dirname, 0700) < 0)
|
||||
goto failed;
|
||||
}
|
||||
return 0;
|
||||
return SC_SUCCESS;
|
||||
|
||||
/* for lack of a better return code */
|
||||
failed: sc_error(ctx, "failed to create cache directory\n");
|
||||
|
@ -40,11 +40,13 @@ extern "C" {
|
||||
#define SC_CTX_MAGIC 0x0A550335
|
||||
|
||||
struct sc_atr_table {
|
||||
char *atr; /* The atr fields are required to
|
||||
be in aa:bb:cc hex format. */
|
||||
char *atrmask; /* The atrmask is logically AND'd with an
|
||||
card atr prior to comparison with the
|
||||
atr reference value above. */
|
||||
/* The atr fields are required to
|
||||
* be in aa:bb:cc hex format. */
|
||||
char *atr;
|
||||
/* The atrmask is logically AND'd with an
|
||||
* card atr prior to comparison with the
|
||||
* atr reference value above. */
|
||||
char *atrmask;
|
||||
char *name;
|
||||
int type;
|
||||
unsigned long flags;
|
||||
|
@ -107,10 +107,10 @@ extern "C" {
|
||||
#define SC_RECORD_CURRENT 0
|
||||
|
||||
/* various maximum values */
|
||||
#define SC_MAX_CARD_DRIVERS 16
|
||||
#define SC_MAX_READER_DRIVERS 4
|
||||
#define SC_MAX_CARD_DRIVER_SNAME_SIZE 16
|
||||
#define SC_MAX_READER_DRIVERS 6
|
||||
#define SC_MAX_READERS 16
|
||||
#define SC_MAX_CARD_DRIVERS 32
|
||||
#define SC_MAX_CARD_DRIVER_SNAME_SIZE 16
|
||||
#define SC_MAX_SLOTS 4
|
||||
#define SC_MAX_CARD_APPS 8
|
||||
#define SC_MAX_APDU_BUFFER_SIZE 258
|
||||
@ -427,16 +427,21 @@ void sc_mutex_free(struct sc_mutex *p);
|
||||
/*
|
||||
* Card capabilities
|
||||
*/
|
||||
/* SC_CARD_APDU_EXT: Card can handle large (> 256 bytes) buffers in
|
||||
* calls to read_binary, write_binary and update_binary; if not,
|
||||
* several successive calls to the corresponding function is made. */
|
||||
|
||||
/* Card can handle large (> 256 bytes) buffers in calls to
|
||||
* read_binary, write_binary and update_binary; if not,
|
||||
* several successive calls to the corresponding function
|
||||
* is made. */
|
||||
#define SC_CARD_CAP_APDU_EXT 0x00000001
|
||||
/* SC_CARD_CAP_EMV: Card can handle operations specified in the
|
||||
|
||||
/* Card can handle operations specified in the
|
||||
* EMV 4.0 standard. */
|
||||
#define SC_CARD_CAP_EMV 0x00000002
|
||||
/* SC_CARD_CAP_RNG: Card has on-board random number source */
|
||||
|
||||
/* Card has on-board random number source. */
|
||||
#define SC_CARD_CAP_RNG 0x00000004
|
||||
/* The card doesn't return any File Control Info */
|
||||
|
||||
/* Card doesn't return any File Control Info. */
|
||||
#define SC_CARD_CAP_NO_FCI 0x00000008
|
||||
|
||||
struct sc_card {
|
||||
@ -615,13 +620,13 @@ struct sc_context {
|
||||
FILE *debug_file, *error_file;
|
||||
char *preferred_language;
|
||||
|
||||
const struct sc_reader_driver *reader_drivers[SC_MAX_READER_DRIVERS+1];
|
||||
const struct sc_reader_driver *reader_drivers[SC_MAX_READER_DRIVERS];
|
||||
void *reader_drv_data[SC_MAX_READER_DRIVERS];
|
||||
|
||||
struct sc_reader *reader[SC_MAX_READERS];
|
||||
int reader_count;
|
||||
|
||||
struct sc_card_driver *card_drivers[SC_MAX_CARD_DRIVERS+1];
|
||||
struct sc_card_driver *card_drivers[SC_MAX_CARD_DRIVERS];
|
||||
struct sc_card_driver *forced_driver;
|
||||
|
||||
sc_mutex_t *mutex;
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <opensc/scdl.h>
|
||||
|
||||
extern int sc_pkcs15emu_openpgp_init_ex(sc_pkcs15_card_t *,
|
||||
@ -71,10 +70,9 @@ sc_pkcs15_bind_synthetic(sc_pkcs15_card_t *p15card)
|
||||
int i, r = SC_ERROR_WRONG_CARD;
|
||||
|
||||
SC_FUNC_CALLED(ctx, 1);
|
||||
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
|
||||
conf_block = NULL;
|
||||
|
||||
for (i = 0; ctx->conf_blocks[i] != NULL; i++) {
|
||||
blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i],
|
||||
"framework", "pkcs15");
|
||||
@ -96,6 +94,7 @@ sc_pkcs15_bind_synthetic(sc_pkcs15_card_t *p15card)
|
||||
} else {
|
||||
/* we have a conf file => let's use it */
|
||||
const scconf_list *list, *item;
|
||||
|
||||
/* find out if the internal drivers should be used */
|
||||
i = scconf_get_bool(conf_block, "enable_builtin_emulation", 1);
|
||||
if (i) {
|
||||
@ -115,10 +114,10 @@ sc_pkcs15_bind_synthetic(sc_pkcs15_card_t *p15card)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* search for 'emulate foo { ... }' entries in the conf file */
|
||||
sc_debug(ctx, "searching for 'emulate foo { ... }' blocks\n");
|
||||
blocks = scconf_find_blocks(ctx->conf, conf_block, "emulate", NULL);
|
||||
|
||||
for (i = 0; (blk = blocks[i]) != NULL; i++) {
|
||||
const char *name = blk->name->data;
|
||||
sc_debug(ctx, "trying %s\n", name);
|
||||
@ -187,28 +186,27 @@ static int parse_emu_block(sc_pkcs15_card_t *p15card, scconf_block *conf)
|
||||
int (*init_func)(sc_pkcs15_card_t *);
|
||||
int (*init_func_ex)(sc_pkcs15_card_t *, sc_pkcs15emu_opt_t *);
|
||||
int r;
|
||||
const char *module_name;
|
||||
const char *driver, *module_name;
|
||||
|
||||
driver = conf->name->data;
|
||||
r = emu_detect_card(card, conf);
|
||||
if (!r)
|
||||
return SC_ERROR_WRONG_CARD;
|
||||
|
||||
init_func = NULL;
|
||||
init_func_ex = NULL;
|
||||
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
opts.blk = conf;
|
||||
opts.flags = SC_PKCS15EMU_FLAGS_NO_CHECK;
|
||||
|
||||
module_name = scconf_get_str(conf, "module", builtin_name);
|
||||
|
||||
if (!strcmp(module_name, "builtin")) {
|
||||
int i;
|
||||
|
||||
/* This function is built into libopensc itself.
|
||||
* Look it up in the table of emulators */
|
||||
if (!conf->name)
|
||||
return SC_ERROR_INTERNAL;
|
||||
|
||||
module_name = conf->name->data;
|
||||
module_name = driver;
|
||||
for (i = 0; builtin_emulators[i].name; i++) {
|
||||
if (!strcmp(builtin_emulators[i].name, module_name)) {
|
||||
init_func_ex = builtin_emulators[i].handler;
|
||||
|
Loading…
Reference in New Issue
Block a user