opensc bug report #21

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

opensc bug report #21

Nils Larsch
Hi Richard,

attached is a modified version of your patch. Unfortunately
we can't assume that every card os supporting record files
have an APPEND RECORD command, hence this patch first tries
an sc_append_record and if it's not implemented opensc
tries an UPDATE RECORD on the next best record index.
Please test.

Nils

Index: src/libopensc/dir.c
===================================================================
--- src/libopensc/dir.c (Revision 2372)
+++ src/libopensc/dir.c (Arbeitskopie)
@@ -344,7 +344,29 @@
  r = encode_dir_record(card->ctx, app, &rec, &rec_size);
  if (r)
  return r;
- r = sc_update_record(card, (unsigned int)app->rec_nr, rec, rec_size, 0);
+ if (app->rec_nr > 0)
+ r = sc_update_record(card, (unsigned int)app->rec_nr, rec, rec_size, SC_RECORD_BY_REC_NR);
+ else if (app->rec_nr == 0) {
+ /* create new record entry */
+ card->ctx->suppress_errors++;
+ r = sc_append_record(card, rec, rec_size, 0);
+ card->ctx->suppress_errors--;
+ if (r == SC_ERROR_NOT_SUPPORTED) {
+ /* if the card doesn't support APPEND RECORD we try a
+ * UPDATE RECORD on the next unused record (and hope
+ * that there is a record with this index).
+ */
+ int rec_nr = 0, i;
+ for(i = 0; i < card->app_count; i++)
+ if (card->app[i]->rec_nr > rec_nr)
+ rec_nr = card->app[i]->rec_nr;
+ rec_nr++;
+ r = sc_update_record(card, (unsigned int)rec_nr, rec, rec_size, SC_RECORD_BY_REC_NR);
+ }
+ } else {
+ sc_error(card->ctx, "invalid record number\n");
+ r = SC_ERROR_INTERNAL;
+ }
  free(rec);
  SC_TEST_RET(card->ctx, r, "Unable to update EF(DIR) record");
  return 0;

_______________________________________________
opensc-devel mailing list
[hidden email]
http://www.opensc.org/cgi-bin/mailman/listinfo/opensc-devel
Reply | Threaded
Open this post in threaded view
|

Re: opensc bug report #21

Nils Larsch
Nils Larsch wrote:
> Hi Richard,
>
> attached is a modified version of your patch. Unfortunately
> we can't assume that every card os supporting record files
> have an APPEND RECORD command, hence this patch first tries
> an sc_append_record and if it's not implemented opensc
> tries an UPDATE RECORD on the next best record index.
> Please test.

patch committed, case closed.

Thanks,
Nils
_______________________________________________
opensc-devel mailing list
[hidden email]
http://www.opensc.org/cgi-bin/mailman/listinfo/opensc-devel