Give unique aliases for smartcards with the same name, so that two readers do not...
authorbjcollins <bcollins@trustedcs.com>
Wed, 2 Sep 2015 17:11:47 +0000 (12:11 -0500)
committerbjcollins <bcollins@trustedcs.com>
Wed, 2 Sep 2015 17:11:47 +0000 (12:11 -0500)
winpr/libwinpr/smartcard/smartcard_pcsc.c

index a361b82..5256828 100644 (file)
@@ -673,6 +673,7 @@ char* PCSC_ConvertReaderNameToWinSCard(const char* name)
        char* p, *q;
        char* tokens[64][2];
        char* nameWinSCard;
+       char *checkAliasName;
        /**
         * pcsc-lite reader name format:
         * name [interface] (serial) index slot
@@ -796,10 +797,20 @@ char* PCSC_ConvertReaderNameToWinSCard(const char* name)
        /**
         * pcsc-lite appears to use an index number based on all readers,
         * while WinSCard uses an index number based on readers of the same name.
-        * Force an index number of 0 for now, fix later.
+        * Set index for this reader by checking if index is already used by another reader
+        * and incrementing until available index found.
         */
        index = 0;
        sprintf_s(nameWinSCard, size, "%.*s %d", length, p, index);
+
+       checkAliasName = PCSC_GetReaderNameFromAlias(nameWinSCard);
+       while ((checkAliasName != NULL) && (strcmp(checkAliasName, name) != 0))
+       {
+               index++;
+               sprintf_s(nameWinSCard, size, "%.*s %d", length, p, index);
+               checkAliasName = PCSC_GetReaderNameFromAlias(nameWinSCard);
+       }
+
        return nameWinSCard;
 }