From: Klas Lindfors Date: Wed, 19 Dec 2012 11:43:10 +0000 (+0100) Subject: fix a case where we would fail to recognize a YubiKey X-Git-Tag: v1.11.1~3 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c0e1568b3721da4162f18e771005df34bd2e9bd;p=yubikey-personalization 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. --- 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; } } }