| | 823 | |
| | 824 | *reader_data = gpriv; |
| | 825 | gpriv = NULL; |
| | 826 | ret = SC_SUCCESS; |
| | 827 | |
| | 828 | out: |
| | 829 | if (ret != SC_SUCCESS) { |
| | 830 | if (gpriv->pcsc_ctx != 0) |
| | 831 | gpriv->SCardReleaseContext(gpriv->pcsc_ctx); |
| | 832 | if (gpriv->dlhandle != NULL) |
| | 833 | lt_dlclose(gpriv->dlhandle); |
| | 834 | if (gpriv != NULL) |
| | 835 | free(gpriv); |
| | 836 | } |
| | 837 | |
| | 838 | return 0; |
| | 839 | } |
| | 840 | |
| | 841 | static int pcsc_finish(sc_context_t *ctx, void *prv_data) |
| | 842 | { |
| | 843 | struct pcsc_global_private_data *priv = (struct pcsc_global_private_data *) prv_data; |
| | 844 | |
| | 845 | if (priv) { |
| | 846 | priv->SCardReleaseContext(priv->pcsc_ctx); |
| | 847 | lt_dlclose(priv->dlhandle); |
| | 848 | free(priv); |
| | 849 | } |
| | 850 | |
| | 851 | return 0; |
| | 852 | } |
| | 853 | |
| | 854 | static int pcsc_detect_readers(sc_context_t *ctx, void *prv_data) |
| | 855 | { |
| | 856 | struct pcsc_global_private_data *gpriv = (struct pcsc_global_private_data *) prv_data; |
| | 857 | LONG rv; |
| | 858 | DWORD reader_buf_size; |
| | 859 | char *reader_buf = NULL, *p; |
| | 860 | const char *mszGroups = NULL; |
| | 861 | int ret = SC_ERROR_INTERNAL; |
| | 862 | |
| 845 | | p = reader_buf; |
| 846 | | do { |
| 847 | | sc_reader_t *reader = (sc_reader_t *) calloc(1, sizeof(sc_reader_t)); |
| 848 | | struct pcsc_private_data *priv = (struct pcsc_private_data *) malloc(sizeof(struct pcsc_private_data)); |
| 849 | | struct pcsc_slot_data *pslot = (struct pcsc_slot_data *) malloc(sizeof(struct pcsc_slot_data)); |
| 850 | | sc_slot_info_t *slot; |
| 851 | | |
| 852 | | if (reader == NULL || priv == NULL || pslot == NULL) { |
| 853 | | if (reader) |
| 854 | | free(reader); |
| 855 | | if (priv) |
| 856 | | free(priv); |
| 857 | | if (pslot) |
| 858 | | free(pslot); |
| 859 | | break; |
| | 881 | for (p = reader_buf; *p != '\x0'; p += strlen (p) + 1) { |
| | 882 | sc_reader_t *reader = NULL; |
| | 883 | struct pcsc_private_data *priv = NULL; |
| | 884 | struct pcsc_slot_data *pslot = NULL; |
| | 885 | sc_slot_info_t *slot = NULL; |
| | 886 | int i; |
| | 887 | int found = 0; |
| | 888 | |
| | 889 | for (i=0;i < sc_ctx_get_reader_count (ctx) && !found;i++) { |
| | 890 | sc_reader_t *reader = sc_ctx_get_reader (ctx, i); |
| | 891 | if (reader == NULL) { |
| | 892 | ret = SC_ERROR_INTERNAL; |
| | 893 | goto err1; |
| | 894 | } |
| | 895 | if (reader->ops == &pcsc_ops && !strcmp (reader->name, p)) { |
| | 896 | found = 1; |
| | 897 | } |
| | 898 | } |
| | 899 | |
| | 900 | /* Reader already available, skip */ |
| | 901 | if (found) { |
| | 902 | continue; |
| | 903 | } |
| | 904 | |
| | 905 | if ((reader = (sc_reader_t *) calloc(1, sizeof(sc_reader_t))) == NULL) { |
| | 906 | ret = SC_ERROR_OUT_OF_MEMORY; |
| | 907 | goto err1; |
| | 908 | } |
| | 909 | if ((priv = (struct pcsc_private_data *) malloc(sizeof(struct pcsc_private_data))) == NULL) { |
| | 910 | ret = SC_ERROR_OUT_OF_MEMORY; |
| | 911 | goto err1; |
| | 912 | } |
| | 913 | if ((pslot = (struct pcsc_slot_data *) malloc(sizeof(struct pcsc_slot_data))) == NULL) { |
| | 914 | ret = SC_ERROR_OUT_OF_MEMORY; |
| | 915 | goto err1; |
| 892 | | if (ret != SC_SUCCESS) { |
| 893 | | if (gpriv->pcsc_ctx != 0) |
| 894 | | gpriv->SCardReleaseContext(gpriv->pcsc_ctx); |
| 895 | | if (reader_buf != NULL) |
| 896 | | free(reader_buf); |
| 897 | | if (gpriv->dlhandle != NULL) |
| 898 | | lt_dlclose(gpriv->dlhandle); |
| 899 | | if (gpriv != NULL) |
| 900 | | free(gpriv); |
| 901 | | } |
| 902 | | |
| 903 | | return 0; |
| 904 | | } |
| 905 | | |
| 906 | | static int pcsc_finish(sc_context_t *ctx, void *prv_data) |
| 907 | | { |
| 908 | | struct pcsc_global_private_data *priv = (struct pcsc_global_private_data *) prv_data; |
| 909 | | |
| 910 | | if (priv) { |
| 911 | | priv->SCardReleaseContext(priv->pcsc_ctx); |
| 912 | | lt_dlclose(priv->dlhandle); |
| 913 | | free(priv); |
| 914 | | } |
| 915 | | |
| 916 | | return 0; |
| | 963 | |
| | 964 | if (reader_buf != NULL) |
| | 965 | free (reader_buf); |
| | 966 | |
| | 967 | return ret; |