summaryrefslogtreecommitdiffstats
path: root/usr.sbin/usbconfig
diff options
context:
space:
mode:
authorthompsa <thompsa@FreeBSD.org>2009-02-27 17:27:16 +0000
committerthompsa <thompsa@FreeBSD.org>2009-02-27 17:27:16 +0000
commit1f16c7700d04a735aa3df3ed26ab236e680c21ad (patch)
tree799ccaf32ee5b67a3fd075acab472e59c72735d8 /usr.sbin/usbconfig
parent03a6b7577d94c2fbc97da1c5539e0bcae374f497 (diff)
downloadFreeBSD-src-1f16c7700d04a735aa3df3ed26ab236e680c21ad.zip
FreeBSD-src-1f16c7700d04a735aa3df3ed26ab236e680c21ad.tar.gz
Change USB over to make_dev() for all device nodes, previously it hooked into
the devfs clone handler to open the (invisible) devices on the fly. The /dev entries are layed out as follows, /dev/usbctl = master device /dev/usb/0.1.0.5 = usb device, (<bus>.<dev>.<iface>.<endpoint>) /dev/ugen0.1 -> usb/0.1.0.0 = ugen link to ctrl endpoint This also removes the custom permissions model from USB. Bump __FreeBSD_version to 800066. Submitted by: rink (earlier version)
Diffstat (limited to 'usr.sbin/usbconfig')
-rw-r--r--usr.sbin/usbconfig/dump.c101
-rw-r--r--usr.sbin/usbconfig/dump.h3
-rw-r--r--usr.sbin/usbconfig/usbconfig.c139
3 files changed, 7 insertions, 236 deletions
diff --git a/usr.sbin/usbconfig/dump.c b/usr.sbin/usbconfig/dump.c
index 01c55d2..6a2fd02 100644
--- a/usr.sbin/usbconfig/dump.c
+++ b/usr.sbin/usbconfig/dump.c
@@ -263,107 +263,6 @@ dump_be_dev_quirks(struct libusb20_backend *pbe)
}
void
-dump_be_access(struct libusb20_backend *pbe)
-{
- struct group *gr;
- struct passwd *pw;
- const char *owner;
- const char *group;
- uid_t uid;
- gid_t gid;
- mode_t mode;
-
- if (libusb20_be_get_owner(pbe, &uid, &gid)) {
- err(1, "could not get owner");
- }
- if (libusb20_be_get_perm(pbe, &mode)) {
- err(1, "could not get permission");
- }
- owner = (pw = getpwuid(uid)) ? pw->pw_name : "UNKNOWN";
- group = (gr = getgrgid(gid)) ? gr->gr_name : "UNKNOWN";
-
- if (mode || 1) {
- printf("Global Access: %s:%s 0%o\n", owner, group, mode);
- } else {
- printf("Global Access: <not set>\n");
- }
- return;
-}
-
-void
-dump_device_access(struct libusb20_device *pdev, uint8_t iface)
-{
- struct group *gr;
- struct passwd *pw;
- const char *owner;
- const char *group;
- uid_t uid;
- gid_t gid;
- mode_t mode;
-
- if (libusb20_dev_get_owner(pdev, &uid, &gid)) {
- err(1, "could not get owner");
- }
- if (libusb20_dev_get_perm(pdev, &mode)) {
- err(1, "could not get permission");
- }
- if (mode) {
- owner = (pw = getpwuid(uid)) ? pw->pw_name : "UNKNOWN";
- group = (gr = getgrgid(gid)) ? gr->gr_name : "UNKNOWN";
-
- printf(" " "Device Access: %s:%s 0%o\n", owner, group, mode);
-
- } else {
- printf(" " "Device Access: <not set>\n");
- }
-
- if (iface == 0xFF) {
- for (iface = 0; iface != 0xFF; iface++) {
- if (dump_device_iface_access(pdev, iface)) {
- break;
- }
- }
- } else {
- if (dump_device_iface_access(pdev, iface)) {
- err(1, "could not get interface access info");
- }
- }
- return;
-}
-
-int
-dump_device_iface_access(struct libusb20_device *pdev, uint8_t iface)
-{
- struct group *gr;
- struct passwd *pw;
- const char *owner;
- const char *group;
- uid_t uid;
- gid_t gid;
- mode_t mode;
- int error;
-
- if ((error = libusb20_dev_get_iface_owner(pdev, iface, &uid, &gid))) {
- return (error);
- }
- if ((error = libusb20_dev_get_iface_perm(pdev, iface, &mode))) {
- return (error);
- }
- if (mode) {
-
- owner = (pw = getpwuid(uid)) ? pw->pw_name : "UNKNOWN";
- group = (gr = getgrgid(gid)) ? gr->gr_name : "UNKNOWN";
-
- printf(" " "Interface %u Access: %s:%s 0%o\n",
- iface, owner, group, mode);
- } else {
- printf(" " "Interface %u Access: <not set>\n", iface);
- }
-
- return (0);
-}
-
-void
dump_device_desc(struct libusb20_device *pdev)
{
struct LIBUSB20_DEVICE_DESC_DECODED *ddesc;
diff --git a/usr.sbin/usbconfig/dump.h b/usr.sbin/usbconfig/dump.h
index 87e9a4d..7fafdfd 100644
--- a/usr.sbin/usbconfig/dump.h
+++ b/usr.sbin/usbconfig/dump.h
@@ -28,10 +28,7 @@ const char *dump_mode(uint8_t value);
const char *dump_speed(uint8_t value);
const char *dump_power_mode(uint8_t value);
void dump_device_info(struct libusb20_device *pdev, uint8_t show_drv);
-void dump_be_access(struct libusb20_backend *pbe);
void dump_be_quirk_names(struct libusb20_backend *pbe);
void dump_be_dev_quirks(struct libusb20_backend *pbe);
-void dump_device_access(struct libusb20_device *pdev, uint8_t iface);
-int dump_device_iface_access(struct libusb20_device *pdev, uint8_t iface);
void dump_device_desc(struct libusb20_device *pdev);
void dump_config(struct libusb20_device *pdev, uint8_t all_cfg);
diff --git a/usr.sbin/usbconfig/usbconfig.c b/usr.sbin/usbconfig/usbconfig.c
index 8a4ac1d..5227544 100644
--- a/usr.sbin/usbconfig/usbconfig.c
+++ b/usr.sbin/usbconfig/usbconfig.c
@@ -64,8 +64,6 @@ struct options {
uint8_t got_iface:1;
uint8_t got_set_config:1;
uint8_t got_set_alt:1;
- uint8_t got_set_owner:1;
- uint8_t got_set_perm:1;
uint8_t got_set_template:1;
uint8_t got_get_template:1;
uint8_t got_suspend:1;
@@ -80,7 +78,6 @@ struct options {
uint8_t got_dump_curr_config:1;
uint8_t got_dump_all_config:1;
uint8_t got_dump_info:1;
- uint8_t got_dump_access:1;
uint8_t got_show_iface_driver:1;
uint8_t got_remove_device_quirk:1;
uint8_t got_add_device_quirk:1;
@@ -100,8 +97,6 @@ enum {
T_IFACE,
T_SET_CONFIG,
T_SET_ALT,
- T_SET_OWNER,
- T_SET_PERM,
T_SET_TEMPLATE,
T_GET_TEMPLATE,
T_ADD_DEVICE_QUIRK,
@@ -113,7 +108,6 @@ enum {
T_DUMP_CURR_CONFIG_DESC,
T_DUMP_ALL_CONFIG_DESC,
T_DUMP_STRING,
- T_DUMP_ACCESS,
T_DUMP_INFO,
T_SUSPEND,
T_RESUME,
@@ -133,8 +127,6 @@ static const struct token token[] = {
{"-i", T_IFACE, 1},
{"set_config", T_SET_CONFIG, 1},
{"set_alt", T_SET_ALT, 1},
- {"set_owner", T_SET_OWNER, 1},
- {"set_perm", T_SET_PERM, 1},
{"set_template", T_SET_TEMPLATE, 1},
{"get_template", T_GET_TEMPLATE, 0},
{"add_dev_quirk_vplh", T_ADD_DEVICE_QUIRK, 5},
@@ -145,7 +137,6 @@ static const struct token token[] = {
{"dump_curr_config_desc", T_DUMP_CURR_CONFIG_DESC, 0},
{"dump_all_config_desc", T_DUMP_ALL_CONFIG_DESC, 0},
{"dump_string", T_DUMP_STRING, 1},
- {"dump_access", T_DUMP_ACCESS, 0},
{"dump_info", T_DUMP_INFO, 0},
{"show_ifdrv", T_SHOW_IFACE_DRIVER, 0},
{"suspend", T_SUSPEND, 0},
@@ -238,43 +229,19 @@ num_id(const char *name, const char *type)
return (val);
}
-static gid_t
-a_gid(const char *s)
+static int
+get_int(const char *s)
{
- struct group *gr;
-
- if (*s == '\0') {
- /* empty group ID */
- return ((gid_t)-1);
- }
- return ((gr = getgrnam(s)) ? gr->gr_gid : num_id(s, "group"));
-}
-
-static uid_t
-a_uid(const char *s)
-{
- struct passwd *pw;
-
- if (*s == '\0') {
- /* empty user ID */
- return ((uid_t)-1);
- }
- return ((pw = getpwnam(s)) ? pw->pw_uid : num_id(s, "user"));
-}
-
-static mode_t
-a_mode(const char *s)
-{
- uint16_t val;
+ int val;
char *ep;
errno = 0;
- val = strtoul(s, &ep, 8);
+ val = strtoul(s, &ep, 0);
if (errno) {
err(1, "%s", s);
}
if (*ep != '\0') {
- errx(1, "illegal permissions: %s", s);
+ errx(1, "illegal number: %s", s);
}
return val;
}
@@ -288,8 +255,6 @@ usage(void)
"commands:" "\n"
" set_config <cfg_index>" "\n"
" set_alt <alt_index>" "\n"
- " set_owner <user:group>" "\n"
- " set_perm <mode>" "\n"
" set_template <template>" "\n"
" get_template" "\n"
" add_dev_quirk_vplh <vid> <pid> <lo_rev> <hi_rev> <quirk>" "\n"
@@ -300,7 +265,6 @@ usage(void)
" dump_curr_config_desc" "\n"
" dump_all_config_desc" "\n"
" dump_string <index>" "\n"
- " dump_access" "\n"
" dump_info" "\n"
" show_ifdrv" "\n"
" suspend" "\n"
@@ -345,10 +309,6 @@ flush_command(struct libusb20_backend *pbe, struct options *opt)
"'power_save', 'power_on' and 'power_off' "
"at the same time!");
}
- if (opt->got_dump_access) {
- opt->got_any--;
- dump_be_access(pbe);
- }
if (opt->got_dump_quirk_names) {
opt->got_any--;
dump_be_quirk_names(pbe);
@@ -400,62 +360,6 @@ flush_command(struct libusb20_backend *pbe, struct options *opt)
}
matches++;
- /* do owner and permissions first */
-
- if (opt->got_bus && opt->got_addr && opt->got_iface) {
- if (opt->got_set_owner) {
- if (libusb20_dev_set_iface_owner(pdev,
- opt->iface, opt->uid, opt->gid)) {
- err(1, "setting owner and group failed\n");
- }
- }
- if (opt->got_set_perm) {
- if (libusb20_dev_set_iface_perm(pdev,
- opt->iface, opt->mode)) {
- err(1, "setting mode failed\n");
- }
- }
- } else if (opt->got_bus && opt->got_addr) {
- if (opt->got_set_owner) {
- if (libusb20_dev_set_owner(pdev,
- opt->uid, opt->gid)) {
- err(1, "setting owner and group failed\n");
- }
- }
- if (opt->got_set_perm) {
- if (libusb20_dev_set_perm(pdev,
- opt->mode)) {
- err(1, "setting mode failed\n");
- }
- }
- } else if (opt->got_bus) {
- if (opt->got_set_owner) {
- if (libusb20_bus_set_owner(pbe, opt->bus,
- opt->uid, opt->gid)) {
- err(1, "setting owner and group failed\n");
- }
- }
- if (opt->got_set_perm) {
- if (libusb20_bus_set_perm(pbe, opt->bus,
- opt->mode)) {
- err(1, "setting mode failed\n");
- }
- }
- } else {
- if (opt->got_set_owner) {
- if (libusb20_be_set_owner(pbe,
- opt->uid, opt->gid)) {
- err(1, "setting owner and group failed\n");
- }
- }
- if (opt->got_set_perm) {
- if (libusb20_be_set_perm(pbe,
- opt->mode)) {
- err(1, "setting mode failed\n");
- }
- }
- }
-
if (libusb20_dev_open(pdev, 0)) {
err(1, "could not open device");
}
@@ -558,18 +462,12 @@ flush_command(struct libusb20_backend *pbe, struct options *opt)
(opt->got_dump_device_desc ||
opt->got_dump_curr_config ||
opt->got_dump_all_config ||
- opt->got_dump_info ||
- opt->got_dump_access);
+ opt->got_dump_info);
if (opt->got_list || dump_any) {
dump_device_info(pdev,
opt->got_show_iface_driver);
}
- if (opt->got_dump_access) {
- printf("\n");
- dump_device_access(pdev, opt->got_iface ?
- opt->iface : 0xFF);
- }
if (opt->got_dump_device_desc) {
printf("\n");
dump_device_desc(pdev);
@@ -695,27 +593,8 @@ main(int argc, char **argv)
opt->got_any++;
n++;
break;
- case T_SET_OWNER:
- cp = argv[n + 1];
- cp = strchr(cp, ':');
- if (cp == NULL) {
- err(1, "missing colon in '%s'!", argv[n + 1]);
- }
- *(cp++) = '\0';
- opt->gid = a_gid(cp);
- opt->uid = a_uid(argv[n + 1]);
- opt->got_set_owner = 1;
- opt->got_any++;
- n++;
- break;
- case T_SET_PERM:
- opt->mode = a_mode(argv[n + 1]);
- opt->got_set_perm = 1;
- opt->got_any++;
- n++;
- break;
case T_SET_TEMPLATE:
- opt->template = a_mode(argv[n + 1]);
+ opt->template = get_int(argv[n + 1]);
opt->got_set_template = 1;
opt->got_any++;
n++;
@@ -749,10 +628,6 @@ main(int argc, char **argv)
opt->got_any++;
n++;
break;
- case T_DUMP_ACCESS:
- opt->got_dump_access = 1;
- opt->got_any += 2;
- break;
case T_SUSPEND:
opt->got_suspend = 1;
opt->got_any++;
OpenPOWER on IntegriCloud