- sec_attr and prop_attr are now dynamically allocated in
struct sc_file git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@404 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
88530c8dba
commit
7ddcb3d692
|
@ -340,7 +340,7 @@ static int miocos_select_file(struct sc_card *card,
|
|||
struct sc_file **file)
|
||||
{
|
||||
int r;
|
||||
|
||||
|
||||
r = iso_ops->select_file(card, in_path, file);
|
||||
if (r)
|
||||
return r;
|
||||
|
|
|
@ -148,8 +148,7 @@ static int setcos_create_file(struct sc_card *card, struct sc_file *file)
|
|||
for (i = 0; i < 6; i++)
|
||||
buf[i] = acl_to_byte(file->acl[idx[i]]);
|
||||
|
||||
memcpy(file->sec_attr, buf, 6);
|
||||
file->sec_attr_len = 6;
|
||||
sc_file_set_sec_attr(file, buf, 6);
|
||||
}
|
||||
|
||||
return iso_ops->create_file(card, file);
|
||||
|
|
|
@ -76,16 +76,6 @@ struct _sc_ctx_options {
|
|||
int ccount;
|
||||
};
|
||||
|
||||
static void set_defaults(struct sc_context *ctx, struct _sc_ctx_options *opts)
|
||||
{
|
||||
ctx->debug = 0;
|
||||
if (ctx->debug_file)
|
||||
fclose(ctx->debug_file);
|
||||
ctx->debug_file = NULL;
|
||||
ctx->log_errors = 1;
|
||||
ctx->error_file = stderr;
|
||||
ctx->forced_driver = NULL;
|
||||
}
|
||||
|
||||
static void del_drvs(struct _sc_ctx_options *opts, int type)
|
||||
{
|
||||
|
@ -145,6 +135,21 @@ static void add_internal_drvs(struct _sc_ctx_options *opts, int type)
|
|||
}
|
||||
}
|
||||
|
||||
static void set_defaults(struct sc_context *ctx, struct _sc_ctx_options *opts)
|
||||
{
|
||||
ctx->debug = 0;
|
||||
if (ctx->debug_file && ctx->debug_file != stdout)
|
||||
fclose(ctx->debug_file);
|
||||
ctx->debug_file = stdout;
|
||||
ctx->log_errors = 1;
|
||||
if (ctx->error_file && ctx->error_file != stderr)
|
||||
fclose(ctx->error_file);
|
||||
ctx->error_file = stderr;
|
||||
ctx->forced_driver = NULL;
|
||||
add_internal_drvs(opts, 0);
|
||||
add_internal_drvs(opts, 1);
|
||||
}
|
||||
|
||||
static int load_parameters(struct sc_context *ctx, scconf_block *block,
|
||||
struct _sc_ctx_options *opts)
|
||||
{
|
||||
|
@ -173,10 +178,7 @@ static int load_parameters(struct sc_context *ctx, scconf_block *block,
|
|||
ctx->error_file = stderr;
|
||||
}
|
||||
list = scconf_find_list(block, "reader_drivers");
|
||||
if (list == NULL) {
|
||||
if (opts->rcount == 0) /* Add the internal drivers */
|
||||
add_internal_drvs(opts, 0);
|
||||
} else
|
||||
if (list != NULL)
|
||||
del_drvs(opts, 0);
|
||||
while (list != NULL) {
|
||||
if (strcmp(list->data, s_internal) == 0)
|
||||
|
@ -187,10 +189,7 @@ static int load_parameters(struct sc_context *ctx, scconf_block *block,
|
|||
}
|
||||
|
||||
list = scconf_find_list(block, "card_drivers");
|
||||
if (list == NULL) {
|
||||
if (opts->ccount == 0) /* Add the internal drivers */
|
||||
add_internal_drvs(opts, 1);
|
||||
} else
|
||||
if (list != NULL)
|
||||
del_drvs(opts, 1);
|
||||
while (list != NULL) {
|
||||
if (strcmp(list->data, s_internal) == 0)
|
||||
|
|
|
@ -354,20 +354,17 @@ static void process_fci(struct sc_context *ctx, struct sc_file *file,
|
|||
debug(ctx, "File name: %s\n", name);
|
||||
}
|
||||
tag = sc_asn1_find_tag(ctx, p, len, 0x85, &taglen);
|
||||
if (tag != NULL && taglen && taglen <= SC_MAX_PROP_ATTR_SIZE) {
|
||||
memcpy(file->prop_attr, tag, taglen);
|
||||
file->prop_attr_len = taglen;
|
||||
if (tag != NULL && taglen) {
|
||||
sc_file_set_prop_attr(file, tag, taglen);
|
||||
} else
|
||||
file->prop_attr_len = 0;
|
||||
tag = sc_asn1_find_tag(ctx, p, len, 0xA5, &taglen);
|
||||
if (tag != NULL && taglen && taglen <= SC_MAX_PROP_ATTR_SIZE) {
|
||||
memcpy(file->prop_attr, tag, taglen);
|
||||
file->prop_attr_len = taglen;
|
||||
if (tag != NULL && taglen) {
|
||||
sc_file_set_prop_attr(file, tag, taglen);
|
||||
}
|
||||
tag = sc_asn1_find_tag(ctx, p, len, 0x86, &taglen);
|
||||
if (tag != NULL && taglen && taglen <= SC_MAX_SEC_ATTR_SIZE) {
|
||||
memcpy(file->sec_attr, tag, taglen);
|
||||
file->sec_attr_len = taglen;
|
||||
if (tag != NULL && taglen) {
|
||||
sc_file_set_sec_attr(file, tag, taglen);
|
||||
}
|
||||
file->magic = SC_FILE_MAGIC;
|
||||
}
|
||||
|
|
|
@ -160,8 +160,6 @@ extern "C" {
|
|||
#define SC_MAX_PATH_SIZE 16
|
||||
#define SC_MAX_PIN_SIZE 16
|
||||
#define SC_MAX_ATR_SIZE 33
|
||||
#define SC_MAX_SEC_ATTR_SIZE 20
|
||||
#define SC_MAX_PROP_ATTR_SIZE 16
|
||||
#define SC_MAX_OBJECT_ID_OCTETS 16
|
||||
#define SC_MAX_AID_SIZE 16
|
||||
/* Beware: the following needs to be a mutiple of 4
|
||||
|
@ -210,9 +208,9 @@ struct sc_file {
|
|||
int record_length; /* In case of fixed-length or cyclic EF */
|
||||
int record_count; /* Valid, if not transparent EF or DF */
|
||||
|
||||
u8 sec_attr[SC_MAX_SEC_ATTR_SIZE];
|
||||
u8 *sec_attr;
|
||||
size_t sec_attr_len;
|
||||
u8 prop_attr[SC_MAX_PROP_ATTR_SIZE];
|
||||
u8 *prop_attr;
|
||||
size_t prop_attr_len;
|
||||
unsigned int magic;
|
||||
};
|
||||
|
@ -745,6 +743,11 @@ const struct sc_acl_entry * sc_file_get_acl_entry(const struct sc_file *file,
|
|||
unsigned int operation);
|
||||
void sc_file_clear_acl_entries(struct sc_file *file, unsigned int operation);
|
||||
|
||||
int sc_file_set_sec_attr(struct sc_file *file, const u8 *sec_attr,
|
||||
size_t sec_attr_len);
|
||||
int sc_file_set_prop_attr(struct sc_file *file, const u8 *prop_attr,
|
||||
size_t prop_attr_len);
|
||||
|
||||
void sc_format_path(const char *path_in, struct sc_path *path_out);
|
||||
int sc_append_path(struct sc_path *dest, const struct sc_path *src);
|
||||
int sc_append_path_id(struct sc_path *dest, const u8 *id, size_t idlen);
|
||||
|
|
|
@ -345,6 +345,10 @@ void sc_file_free(struct sc_file *file)
|
|||
file->magic = 0;
|
||||
for (i = 0; i < SC_MAX_AC_OPS; i++)
|
||||
sc_file_clear_acl_entries(file, i);
|
||||
if (file->sec_attr)
|
||||
free(file->sec_attr);
|
||||
if (file->prop_attr)
|
||||
free(file->prop_attr);
|
||||
free(file);
|
||||
}
|
||||
|
||||
|
@ -370,6 +374,52 @@ void sc_file_dup(struct sc_file **dest, const struct sc_file *src)
|
|||
}
|
||||
}
|
||||
|
||||
int sc_file_set_sec_attr(struct sc_file *file, const u8 *sec_attr,
|
||||
size_t sec_attr_len)
|
||||
{
|
||||
assert(sc_file_valid(file));
|
||||
|
||||
if (sec_attr == NULL) {
|
||||
if (file->sec_attr != NULL)
|
||||
free(file->sec_attr);
|
||||
file->sec_attr = NULL;
|
||||
file->sec_attr_len = 0;
|
||||
return 0;
|
||||
}
|
||||
file->sec_attr = realloc(file->sec_attr, sec_attr_len);
|
||||
if (file->sec_attr == NULL) {
|
||||
file->sec_attr_len = 0;
|
||||
return SC_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy(file->sec_attr, sec_attr, sec_attr_len);
|
||||
file->sec_attr_len = sec_attr_len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sc_file_set_prop_attr(struct sc_file *file, const u8 *prop_attr,
|
||||
size_t prop_attr_len)
|
||||
{
|
||||
assert(sc_file_valid(file));
|
||||
|
||||
if (prop_attr == NULL) {
|
||||
if (file->prop_attr != NULL)
|
||||
free(file->prop_attr);
|
||||
file->prop_attr = NULL;
|
||||
file->prop_attr_len = 0;
|
||||
return 0;
|
||||
}
|
||||
file->prop_attr = realloc(file->prop_attr, prop_attr_len);
|
||||
if (file->prop_attr == NULL) {
|
||||
file->prop_attr_len = 0;
|
||||
return SC_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy(file->prop_attr, prop_attr, prop_attr_len);
|
||||
file->prop_attr_len = prop_attr_len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int sc_file_valid(const struct sc_file *file) {
|
||||
#ifndef NDEBUG
|
||||
assert(file != NULL);
|
||||
|
|
Loading…
Reference in New Issue