darwin: fix USB capture for root
authorNathan Hjelm <hjelmn@google.com>
Sun, 8 Aug 2021 05:02:16 +0000 (23:02 -0600)
committerNathan Hjelm <hjelmn@google.com>
Sun, 8 Aug 2021 05:10:52 +0000 (23:10 -0600)
This commit restores the ability to capture-open a USB device when running as root.

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
libusb/os/darwin_usb.c
libusb/version_nano.h

index 319289b..5d31088 100644 (file)
@@ -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 */
index 94aba9b..981f704 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11647
+#define LIBUSB_NANO 11648