- Fix a potential segfault for the new sc_establish_context

- Keep the variable names in opensc.conf the same as they
  are in code structs.

Always try to parse app default { } first, then upgrade
the settings with the application specific configuration block.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@381 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
aet 2002-03-24 16:57:39 +00:00
parent 0cad904c86
commit 21aae9c4d0
2 changed files with 42 additions and 20 deletions

View File

@ -1,9 +1,17 @@
# Configuration file for OpenSC
# Example configuration file
debuglevel = 0
#debugfile = /tmp/opensc-debug.log
#errorfile = /tmp/opensc-errors.log
# Default values for any application
# These can be overrided by the application
# specific configuration block.
app "pam_pkcs15" {
app default {
debug = 0
#debug_file = /tmp/opensc-debug.log
#error_file = /tmp/opensc-errors.log
}
# For applications that use SCAM (pam_opensc, sia_opensc)
app scam {
use_cache = false;
}

View File

@ -152,28 +152,38 @@ static void set_defaults(struct sc_context *ctx)
ctx->error_file = stderr;
}
static int load_parameters(struct sc_context *ctx, scconf_block *block)
static int load_parameters(struct sc_context *ctx, const char *app)
{
scconf_block **blocks = NULL;
const char *val;
unsigned int i;
val = scconf_find_value_first(block, "debuglevel");
sscanf(val, "%d", &ctx->debug);
val = scconf_find_value_first(block, "debugfile");
if (ctx->debug_file)
fclose(ctx->debug_file);
if (strcmp(val, "stdout") == 0)
ctx->debug_file = fopen(val, "a");
val = scconf_find_value_first(block, "errorfile");
if (ctx->error_file)
fclose(ctx->error_file);
if (strcmp(val, "stderr") != 0)
ctx->error_file = fopen(val, "a");
blocks = scconf_find_blocks(ctx->conf, NULL, "app");
for (i = 0; blocks[i]; i++) {
scconf_block *block = blocks[i];
if (!block->name && strcmp(block->name->data, app))
continue;
val = scconf_find_value_first(block, "debug");
sscanf(val, "%d", &ctx->debug);
val = scconf_find_value_first(block, "debug_file");
if (ctx->debug_file)
fclose(ctx->debug_file);
if (strcmp(val, "stdout") == 0)
ctx->debug_file = fopen(val, "a");
val = scconf_find_value_first(block, "error_file");
if (ctx->error_file)
fclose(ctx->error_file);
if (strcmp(val, "stderr") != 0)
ctx->error_file = fopen(val, "a");
}
free(blocks);
return 0;
}
int sc_establish_context(struct sc_context **ctx_out, const char *app_name)
{
const char *default_app = "default";
struct sc_context *ctx;
int i, r;
@ -183,15 +193,19 @@ int sc_establish_context(struct sc_context **ctx_out, const char *app_name)
return SC_ERROR_OUT_OF_MEMORY;
memset(ctx, 0, sizeof(struct sc_context));
set_defaults(ctx);
ctx->app_name = strdup(app_name);
ctx->app_name = app_name ? strdup(app_name) : strdup(default_app);
ctx->conf = scconf_init(OPENSC_CONF_PATH);
if (ctx->conf != NULL) {
r = scconf_parse(ctx->conf);
if (scconf_parse(ctx->conf) < 1) {
scconf_deinit(ctx->conf);
ctx->conf = NULL;
} else
load_parameters(ctx, ctx->conf->root);
} else {
load_parameters(ctx, default_app);
if (strcmp(default_app, ctx->app_name)) {
load_parameters(ctx, ctx->app_name);
}
}
}
#ifdef HAVE_PTHREAD
pthread_mutex_init(&ctx->mutex, NULL);