]> err.no Git - yubikey-personalization/commitdiff
fix a case where we would fail to recognize a YubiKey
authorKlas Lindfors <klas@yubico.com>
Wed, 19 Dec 2012 11:43:10 +0000 (12:43 +0100)
committerKlas Lindfors <klas@yubico.com>
Wed, 19 Dec 2012 11:43:10 +0000 (12:43 +0100)
if the first device found is from yubico (vid 1050) but not
a YubiKey we will fail on that instead of trying later devices.

ykcore/ykcore_libusb-1.0.c
ykcore/ykcore_libusb.c
ykcore/ykcore_windows.c

index e6e04b5750f727c06cbf9d48ab197f95c05686e6..8c6e9744f7921a408506398776eecca1dfa47280 100644 (file)
@@ -180,20 +180,18 @@ void *_ykusb_open_device(int vendor_id, int *product_ids, size_t pids_len)
                                        break;
                                }
                        }
-                       if (j == pids_len) {
+                       if (j != pids_len) {
+                               rc = YK_EUSBERR;
+                               ykl_errno = libusb_open(dev, &h);
+                               if (ykl_errno != 0)
+                                       goto done;
+                               ykl_errno = libusb_detach_kernel_driver(h, 0);
+                               if (ykl_errno != 0)
+                                       goto done;
+                               /* This is needed for yubikey-personalization to work inside virtualbox virtualization. */
+                               ykl_errno = libusb_set_configuration(h, 1);
                                goto done;
                        }
-
-                       rc = YK_EUSBERR;
-                       ykl_errno = libusb_open(dev, &h);
-                       if (ykl_errno != 0)
-                               goto done;
-                       ykl_errno = libusb_detach_kernel_driver(h, 0);
-                       if (ykl_errno != 0)
-                               goto done;
-                       /* This is needed for yubikey-personalization to work inside virtualbox virtualization. */
-                       ykl_errno = libusb_set_configuration(h, 1);
-                       goto done;
                }
        }
  done:
index cfb9acf354f8a0eccd4a8d0879b61539badc4088..0141a88366da12564c5e139608d35cda07fcf5b2 100644 (file)
@@ -162,20 +162,18 @@ void *_ykusb_open_device(int vendor_id, int *product_ids, size_t pids_len)
                                                break;
                                        }
                                }
-                               if(j == pids_len) {
-                                       goto done;
-                               }
-
-                               rc = YK_EUSBERR;
-                               h = usb_open(dev);
+                               if(j != pids_len) {
+                                       rc = YK_EUSBERR;
+                                       h = usb_open(dev);
 #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
-                               if (h != NULL)
-                                       usb_detach_kernel_driver_np(h, 0);
+                                       if (h != NULL)
+                                               usb_detach_kernel_driver_np(h, 0);
 #endif
-                               /* This is needed for yubikey-personalization to work inside virtualbox virtualization. */
-                               if (h != NULL)
-                                       usb_set_configuration(h, 1);
-                               goto done;
+                                       /* This is needed for yubikey-personalization to work inside virtualbox virtualization. */
+                                       if (h != NULL)
+                                               usb_set_configuration(h, 1);
+                                       goto done;
+                               }
                        }
        }
  done:
index 64f16694163d7bfa032414cd67de380abca1b1ca..c82ae8507c8b9fcf3b6b00468a9e353b0b89c232 100644 (file)
@@ -99,13 +99,11 @@ void * _ykusb_open_device(int vendor_id, int *product_ids, size_t pids_len)
                                                                break;
                                                        }
                                                }
-                                               if (j == pids_len) {
+                                               if (j != pids_len) {
+                                                       ret_handle = m_handle;
+                                                       free (pi);
                                                        goto done;
                                                }
-
-                                               ret_handle = m_handle;
-                                               free (pi);
-                                               goto done;
                                        }
                                }
                        }