On Tuesday 21 June 2011 17:14:15 Denys Vlasenko wrote:
> On Mon, Jun 20, 2011 at 10:58 PM, Tito <[email protected]> wrote:
> > Hi,
> > just for fun one improved version of your groups patch:
> >
> > pros: accepts username on the commandline
> > uses id.c directly
> > contras: Denys will say its obfuscated ;-)
> >
> > Ciao,
> > Tito
> >
> > --- coreutils/id.c.original 2011-06-14 01:18:56.000000000 +0200
> > +++ coreutils/id.c 2011-06-20 22:42:04.000000000 +0200
> > @@ -33,6 +33,14 @@
> > //usage: "$ id\n"
> > //usage: "uid=1000(andersen) gid=1000(andersen)\n"
> >
> > +//usage:#define groups_trivial_usage
> > +//usage: "[USER]"
> > +//usage:#define groups_full_usage "\n\n"
> > +//usage: "Print the group memberships of USER or for the current
> > process"
> > +//usage:#define groups_example_usage
> > +//usage: "$ groups\n"
> > +//usage: "andersen lp dialout cdrom floppy\n"
> > +
> > #include "libbb.h"
> >
> > /* This is a NOEXEC applet. Be very careful! */
> > @@ -140,7 +148,12 @@
> > /* Don't allow more than one username */
> > opt_complementary = "?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG"
> > IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G");
> > - opt = getopt32(argv, "rnugG" IF_SELINUX("Z"));
> > +
> > + if (ENABLE_GROUPS && applet_name[0] == 'g') {
> > + option_mask32 = opt = getopt32(argv, "") | JUST_ALL_GROUPS
> > | NAME_NOT_NUMBER;
> > + } else {
> > + opt = getopt32(argv, "rnugG" IF_SELINUX("Z"));
> > + }
> >
> > username = argv[optind];
> > if (username) {
> > --- coreutils/Config.src.original 2011-06-20 22:43:30.000000000 +0200
> > +++ coreutils/Config.src 2011-06-20 22:46:34.000000000 +0200
> > @@ -269,6 +269,12 @@
> > help
> > This enables the head options (-c, -q, and -v).
> >
> > +config GROUPS
> > + bool "groups"
> > + default y
> > + help
> > + Print the group names associated with username or with the
> > current user id
> > +
> > config HOSTID
> > bool "hostid"
> > default y
> > --- coreutils/Kbuild.src.original 2011-06-20 22:48:27.000000000 +0200
> > +++ coreutils/Kbuild.src 2011-06-20 21:38:35.000000000 +0200
> > @@ -44,6 +44,7 @@
> > lib-$(CONFIG_LOGNAME) += logname.o
> > lib-$(CONFIG_LS) += ls.o
> > lib-$(CONFIG_FTPD) += ls.o
> > +lib-$(CONFIG_GROUPS) += id.o
> > lib-$(CONFIG_MD5SUM) += md5_sha1_sum.o
> > lib-$(CONFIG_MKDIR) += mkdir.o
> > lib-$(CONFIG_MKFIFO) += mkfifo.o
> > --- include/applets.src.h.original 2011-06-20 22:49:38.000000000 +0200
> > +++ include/applets.src.h 2011-06-20 21:45:41.000000000 +0200
> > @@ -170,6 +170,7 @@
> > IF_GETOPT(APPLET(getopt, BB_DIR_BIN, BB_SUID_DROP))
> > IF_GETSEBOOL(APPLET(getsebool, BB_DIR_USR_SBIN, BB_SUID_DROP))
> > IF_GETTY(APPLET(getty, BB_DIR_SBIN, BB_SUID_DROP))
> > +IF_GROUPS(APPLET_ODDNAME(groups, id, BB_DIR_USR_BIN, BB_SUID_DROP, groups))
> > IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP))
> > IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP))
> > IF_HD(APPLET_NOEXEC(hd, hexdump, BB_DIR_USR_BIN, BB_SUID_DROP, hd))
>
> Applied, thanks!
Hi Denys,
i suspect that:
opt_complementary = "?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG"
should be before
if (ENABLE_GROUPS && (!ENABLE_ID || applet_name[0] == 'g')) {
option_mask32 = opt = getopt32(argv, "") | JUST_ALL_GROUPS | NAME_NOT_NUMBER;
} else {
as else the max args (= 1) statement is not enforced for groups.
At least something like this is needed:
if (ENABLE_GROUPS && (!ENABLE_ID || applet_name[0] == 'g')) {
+opt_complementary = "?1";
option_mask32 = opt = getopt32(argv, "") | JUST_ALL_GROUPS | NAME_NOT_NUMBER;
} else {
or like this:
+ opt_complementary = "?1"IF_ID(":u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG");
if (ENABLE_GROUPS && (!ENABLE_ID || applet_name[0] == 'g')) {
option_mask32 = opt = getopt32(argv, "") | JUST_ALL_GROUPS |
NAME_NOT_NUMBER;
} else {
/* Don't allow -n -r -nr -ug -rug -nug -rnug -uZ -gZ -GZ*/
/* Don't allow more than one username */
- opt_complementary = "?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG"
IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G");
opt = getopt32(argv, "rnugG" IF_SELINUX("Z"));
}
Ciao,
Tito
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox