[PATCH 08/18] usbip: Handle usbip being started as user

From: Maximilian Eschenbacher
Date: Tue Sep 16 2014 - 18:08:38 EST


usbip now prints an error message when started as user and requiring
root access. Also, some debug messages are changed to error messages so
the command line utilities now print less confusing (and more verbose)
error messages when not used correctly.

Signed-off-by: Maximilian Eschenbacher <maximilian@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Fjodor Schelichow <fjodor.schelichow@xxxxxxxxxxx>
Signed-off-by: Johannes Stadlinger <johannes.stadlinger@xxxxxx>
Signed-off-by: Dominik Paulus <dominik.paulus@xxxxxx>
Signed-off-by: Tobias Polzer <tobias.polzer@xxxxxx>
---
tools/usb/usbip/src/usbip_attach.c | 3 +++
tools/usb/usbip/src/usbip_bind.c | 9 ++++++---
2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/tools/usb/usbip/src/usbip_attach.c b/tools/usb/usbip/src/usbip_attach.c
index 51c67a2..fcc3efb 100644
--- a/tools/usb/usbip/src/usbip_attach.c
+++ b/tools/usb/usbip/src/usbip_attach.c
@@ -210,6 +210,9 @@ int usbip_attach(int argc, char *argv[])
int opt;
int ret = -1;

+ if (geteuid() != 0)
+ err("not running as root?");
+
for (;;) {
opt = getopt_long(argc, argv, "r:b:", opts, NULL);

diff --git a/tools/usb/usbip/src/usbip_bind.c b/tools/usb/usbip/src/usbip_bind.c
index 3f8c7a3..6f5d3c2 100644
--- a/tools/usb/usbip/src/usbip_bind.c
+++ b/tools/usb/usbip/src/usbip_bind.c
@@ -102,19 +102,19 @@ static int unbind_other(char *busid)
/* Get the device. */
dev = udev_device_new_from_subsystem_sysname(udev, "usb", busid);
if (!dev) {
- dbg("unable to find device with bus ID %s", busid);
+ err("unable to find device with bus ID %s", busid);
goto err_close_busid_dev;
}

/* Check what kind of device it is. */
bDevClass = udev_device_get_sysattr_value(dev, "bDeviceClass");
if (!bDevClass) {
- dbg("unable to get bDevClass device attribute");
+ err("unable to get bDevClass device attribute");
goto err_close_busid_dev;
}

if (!strncmp(bDevClass, "09", strlen(bDevClass))) {
- dbg("skip unbinding of hub");
+ err("skip unbinding of hub");
goto err_close_busid_dev;
}

@@ -212,6 +212,9 @@ int usbip_bind(int argc, char *argv[])

allow[0] = 0;

+ if (geteuid() != 0)
+ err("not running as root?");
+
for (;;) {
opt = getopt_long(argc, argv, "a:b:", opts, NULL);

--
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/