From 3ed54c52b1ece08eae21774fbac50a5cc16bae93 Mon Sep 17 00:00:00 2001 From: Nathan Hjelm Date: Sat, 7 Aug 2021 23:02:16 -0600 Subject: [PATCH] darwin: fix USB capture for root This commit restores the ability to capture-open a USB device when running as root. Signed-off-by: Nathan Hjelm --- libusb/os/darwin_usb.c | 29 ++++++++++++++--------------- libusb/version_nano.h | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c index 319289b..5d31088 100644 --- a/libusb/os/darwin_usb.c +++ b/libusb/os/darwin_usb.c @@ -2439,22 +2439,21 @@ static int darwin_detach_kernel_driver (struct libusb_device_handle *dev_handle, if (dpriv->capture_count == 0) { usbi_dbg (ctx, "attempting to detach kernel driver from device"); - if (!darwin_has_capture_entitlements ()) { - usbi_info (ctx, "no capture entitlements. can not detach the kernel driver for this device"); - return LIBUSB_ERROR_NOT_SUPPORTED; - } - - /* request authorization */ - kresult = IOServiceAuthorize (dpriv->service, kIOServiceInteractionAllowed); - if (kresult != kIOReturnSuccess) { - usbi_warn (ctx, "IOServiceAuthorize: %s", darwin_error_str(kresult)); - return darwin_to_libusb (kresult); - } + if (darwin_has_capture_entitlements ()) { + /* request authorization */ + kresult = IOServiceAuthorize (dpriv->service, kIOServiceInteractionAllowed); + if (kresult != kIOReturnSuccess) { + usbi_warn (ctx, "IOServiceAuthorize: %s", darwin_error_str(kresult)); + return darwin_to_libusb (kresult); + } - /* we need start() to be called again for authorization status to refresh */ - err = darwin_reload_device (dev_handle); - if (err != LIBUSB_SUCCESS) { - return err; + /* we need start() to be called again for authorization status to refresh */ + err = darwin_reload_device (dev_handle); + if (err != LIBUSB_SUCCESS) { + return err; + } + } else { + usbi_info (ctx, "no capture entitlements. may not be able to detach the kernel driver for this device"); } /* reset device to release existing drivers */ diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 94aba9b..981f704 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11647 +#define LIBUSB_NANO 11648 -- 2.7.4