From 1c0e1568b3721da4162f18e771005df34bd2e9bd Mon Sep 17 00:00:00 2001 From: Klas Lindfors Date: Wed, 19 Dec 2012 12:43:10 +0100 Subject: [PATCH] fix a case where we would fail to recognize a YubiKey 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 | 22 ++++++++++------------ ykcore/ykcore_libusb.c | 22 ++++++++++------------ ykcore/ykcore_windows.c | 8 +++----- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/ykcore/ykcore_libusb-1.0.c b/ykcore/ykcore_libusb-1.0.c index e6e04b5..8c6e974 100644 --- a/ykcore/ykcore_libusb-1.0.c +++ b/ykcore/ykcore_libusb-1.0.c @@ -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: diff --git a/ykcore/ykcore_libusb.c b/ykcore/ykcore_libusb.c index cfb9acf..0141a88 100644 --- a/ykcore/ykcore_libusb.c +++ b/ykcore/ykcore_libusb.c @@ -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: diff --git a/ykcore/ykcore_windows.c b/ykcore/ykcore_windows.c index 64f1669..c82ae85 100644 --- a/ykcore/ykcore_windows.c +++ b/ykcore/ykcore_windows.c @@ -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; } } } -- 2.39.5